hf.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 FhG Fokus
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * ser is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * For a license to use the ser software under conditions
  14. * other than those described here, or to purchase support for this
  15. * software, please contact iptel.org by e-mail at the following addresses:
  16. * [email protected]
  17. *
  18. * ser is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. *
  27. * History:
  28. * ---------
  29. * 2003-02-28 scratchpad compatibility abandoned (jiri)
  30. * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
  31. * 2003-05-01 HDR_ACCEPT added (janakj)
  32. * 2005-02-14 hdr_flags_t && hdr_flags_f defined, split HDR_xxx into
  33. * HDR_xxx_F & HDR_xxx_T [WARNING: don't mix them!] (andrei)
  34. */
  35. #ifndef HF_H
  36. #define HF_H
  37. #include "../str.h"
  38. #include "../comp_defs.h"
  39. /* header type enum
  40. * if you add a new type:
  41. * - make sure it's not greater than 63
  42. * - make sure you add the corresponding flag to the hdr_flags_t defs below
  43. * - update clean_hdr_field (in hf.c)
  44. * - update sip_msg_cloner (modules/tm/sip_msg.c)
  45. * - update parse_headers (msg_parser.c)
  46. */
  47. enum _hdr_types_t {
  48. HDR_ERROR_T = -1 /* Error while parsing */,
  49. HDR_OTHER_T = 0 /* Some other header field */,
  50. HDR_VIA_T = 1 /* Via header field */,
  51. HDR_VIA1_T = 1 /* First Via header field */,
  52. HDR_VIA2_T = 2 /* only used as flag */,
  53. HDR_TO_T /* To header field */,
  54. HDR_FROM_T /* From header field */,
  55. HDR_CSEQ_T /* CSeq header field */,
  56. HDR_CALLID_T /* Call-Id header field */,
  57. HDR_CONTACT_T /* Contact header field */,
  58. HDR_MAXFORWARDS_T /* MaxForwards header field */,
  59. HDR_ROUTE_T /* Route header field */,
  60. HDR_RECORDROUTE_T /* Record-Route header field */,
  61. HDR_CONTENTTYPE_T /* Content-Type header field */,
  62. HDR_CONTENTLENGTH_T /* Content-Length header field */,
  63. HDR_AUTHORIZATION_T /* Authorization header field */,
  64. HDR_EXPIRES_T /* Expires header field */,
  65. HDR_PROXYAUTH_T /* Proxy-Authorization hdr field */,
  66. HDR_SUPPORTED_T /* Supported header field */,
  67. HDR_PROXYREQUIRE_T /* Proxy-Require header field */,
  68. HDR_UNSUPPORTED_T /* Unsupported header field */,
  69. HDR_ALLOW_T /* Allow header field */,
  70. HDR_EVENT_T /* Event header field */,
  71. HDR_ACCEPT_T /* Accept header field */,
  72. HDR_ACCEPTLANGUAGE_T /* Accept-Language header field */,
  73. HDR_ORGANIZATION_T /* Organization header field */,
  74. HDR_PRIORITY_T /* Priority header field */,
  75. HDR_SUBJECT_T /* Subject header field */,
  76. HDR_USERAGENT_T /* User-Agent header field */,
  77. HDR_ACCEPTDISPOSITION_T /* Accept-Disposition hdr field */,
  78. HDR_CONTENTDISPOSITION_T /* Content-Disposition hdr field */,
  79. HDR_DIVERSION_T /* Diversion header field */,
  80. HDR_RPID_T /* Remote-Party-ID header field */,
  81. HDR_REFER_TO_T /* Refer-To header fiels */,
  82. HDR_EOH_T /* Some other header field */
  83. };
  84. typedef unsigned long long hdr_flags_t;
  85. /* type to flag conversion
  86. * WARNING: HDR_ERROR_T has no corresponding FLAG ! */
  87. #define HDR_T2F(type) \
  88. (((type)!=HDR_EOH_T)?((hdr_flags_t)1<<(type)):(~(hdr_flags_t)0))
  89. /* helper macro for easy defining and keeping in sync. the flags enum */
  90. #define HDR_F_DEF(name) HDR_T2F(HDR_##name##_T)
  91. /* flags definitions
  92. * (enum won't work with all the compiler (e.g. icc) due to the 64bit size) */
  93. #define HDR_EOH_F HDR_F_DEF(EOH)
  94. #define HDR_VIA_F HDR_F_DEF(VIA)
  95. #define HDR_VIA1_F HDR_F_DEF(VIA1)
  96. #define HDR_VIA2_F HDR_F_DEF(VIA2)
  97. #define HDR_TO_F HDR_F_DEF(TO)
  98. #define HDR_FROM_F HDR_F_DEF(FROM)
  99. #define HDR_CSEQ_F HDR_F_DEF(CSEQ)
  100. #define HDR_CALLID_F HDR_F_DEF(CALLID)
  101. #define HDR_CONTACT_F HDR_F_DEF(CONTACT)
  102. #define HDR_MAXFORWARDS_F HDR_F_DEF(MAXFORWARDS)
  103. #define HDR_ROUTE_F HDR_F_DEF(ROUTE)
  104. #define HDR_RECORDROUTE_F HDR_F_DEF(RECORDROUTE)
  105. #define HDR_CONTENTTYPE_F HDR_F_DEF(CONTENTTYPE)
  106. #define HDR_CONTENTLENGTH_F HDR_F_DEF(CONTENTLENGTH)
  107. #define HDR_AUTHORIZATION_F HDR_F_DEF(AUTHORIZATION)
  108. #define HDR_EXPIRES_F HDR_F_DEF(EXPIRES)
  109. #define HDR_PROXYAUTH_F HDR_F_DEF(PROXYAUTH)
  110. #define HDR_SUPPORTED_F HDR_F_DEF(SUPPORTED)
  111. #define HDR_PROXYREQUIRE_F HDR_F_DEF(PROXYREQUIRE)
  112. #define HDR_UNSUPPORTED_F HDR_F_DEF(UNSUPPORTED)
  113. #define HDR_ALLOW_F HDR_F_DEF(ALLOW)
  114. #define HDR_EVENT_F HDR_F_DEF(EVENT)
  115. #define HDR_ACCEPT_F HDR_F_DEF(ACCEPT)
  116. #define HDR_ACCEPTLANGUAGE_F HDR_F_DEF(ACCEPTLANGUAGE)
  117. #define HDR_ORGANIZATION_F HDR_F_DEF(ORGANIZATION)
  118. #define HDR_PRIORITY_F HDR_F_DEF(PRIORITY)
  119. #define HDR_SUBJECT_F HDR_F_DEF(SUBJECT)
  120. #define HDR_USERAGENT_F HDR_F_DEF(USERAGENT)
  121. #define HDR_ACCEPTDISPOSITION_F HDR_F_DEF(ACCEPTDISPOSITION)
  122. #define HDR_CONTENTDISPOSITION_F HDR_F_DEF(CONTENTDISPOSITION)
  123. #define HDR_DIVERSION_F HDR_F_DEF(DIVERSION)
  124. #define HDR_RPID_F HDR_F_DEF(RPID)
  125. #define HDR_REFER_TO_F HDR_F_DEF(REFER_TO)
  126. #define HDR_OTHER_F HDR_F_DEF(OTHER)
  127. typedef enum _hdr_types_t hdr_types_t;
  128. /*
  129. * Format: name':' body
  130. */
  131. struct hdr_field {
  132. hdr_types_t type; /* Header field type */
  133. str name; /* Header field name */
  134. str body; /* Header field body (may not include CRLF) */
  135. int len; /* length from hdr start until EoHF (incl.CRLF) */
  136. void* parsed; /* Parsed data structures */
  137. struct hdr_field* next; /* Next header field in the list */
  138. };
  139. /* returns true if the header links allocated memory on parse field */
  140. static inline int hdr_allocs_parse(struct hdr_field* hdr)
  141. {
  142. switch(hdr->type){
  143. case HDR_VIA_T:
  144. case HDR_TO_T:
  145. case HDR_FROM_T:
  146. case HDR_CONTACT_T:
  147. case HDR_ROUTE_T:
  148. case HDR_RECORDROUTE_T:
  149. case HDR_AUTHORIZATION_T:
  150. case HDR_EXPIRES_T:
  151. case HDR_PROXYAUTH_T:
  152. case HDR_EVENT_T:
  153. case HDR_ACCEPT_T:
  154. case HDR_CONTENTDISPOSITION_T:
  155. case HDR_DIVERSION_T:
  156. case HDR_RPID_T:
  157. case HDR_REFER_TO_T:
  158. return 1;
  159. default:
  160. return 0;
  161. }
  162. }
  163. /* frees a hdr_field structure,
  164. * WARNING: it frees only parsed (and not name.s, body.s)
  165. */
  166. void clean_hdr_field(struct hdr_field* hf);
  167. /* frees a hdr_field list,
  168. * WARNING: frees only ->parsed and ->next
  169. */
  170. void free_hdr_field_lst(struct hdr_field* hf);
  171. void dump_hdr_field( struct hdr_field* hf );
  172. #endif /* HF_H */