hf.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. * Copyright (C) 2001-2003 FhG Fokus
  3. *
  4. * This file is part of ser, a free SIP server.
  5. *
  6. * ser is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version
  10. *
  11. * For a license to use the ser software under conditions
  12. * other than those described here, or to purchase support for this
  13. * software, please contact iptel.org by e-mail at the following addresses:
  14. * [email protected]
  15. *
  16. * ser is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * History:
  26. * -------
  27. * 2003-03-26 Frees also hdr->parsed for Route & Record-Route (janakj)
  28. * 2003-04-26 ZSW (jiri)
  29. * 2003-08-05 free the parsed part of Accept header (bogdan)
  30. * 2007-01-26 HDR_DATE_T, HDR_IDENTITY_T, HDR_IDENTITY_INFO_T added (gergo)
  31. * 2007-07-27 added HDR_RETRY_AFTER_T (andrei)
  32. */
  33. /** Parser :: parse header files
  34. * @file
  35. * @ingroup parser
  36. */
  37. #include "hf.h"
  38. #include "parse_via.h"
  39. #include "parse_to.h"
  40. #include "parse_cseq.h"
  41. #include "parse_date.h"
  42. #include "parse_identity.h"
  43. #include "parse_identityinfo.h"
  44. #include "../dprint.h"
  45. #include "../mem/mem.h"
  46. #include "parse_def.h"
  47. #include "digest/digest.h" /* free_credentials */
  48. #include "parse_event.h"
  49. #include "parse_expires.h"
  50. #include "parse_sipifmatch.h"
  51. #include "parse_rr.h"
  52. #include "parse_subscription_state.h"
  53. #include "contact/parse_contact.h"
  54. #include "parse_disposition.h"
  55. #include "parse_allow.h"
  56. #include "../ut.h"
  57. #include "parse_ppi_pai.h"
  58. /** Frees a hdr_field structure.
  59. * WARNING: it frees only parsed (and not name.s, body.s)
  60. */
  61. void clean_hdr_field(struct hdr_field* const hf)
  62. {
  63. void** h_parsed;
  64. if (hf->parsed){
  65. h_parsed=&hf->parsed; /* strict aliasing warnings workarround */
  66. switch(hf->type){
  67. /* headers with pkg alloc for parsed structure (alphabetic order) */
  68. case HDR_ACCEPT_T:
  69. pkg_free(hf->parsed);
  70. break;
  71. case HDR_ALLOW_T:
  72. free_allow_header(hf);
  73. break;
  74. case HDR_AUTHORIZATION_T:
  75. free_credentials((auth_body_t**)h_parsed);
  76. break;
  77. case HDR_CONTACT_T:
  78. free_contact((contact_body_t**)h_parsed);
  79. break;
  80. case HDR_CONTENTDISPOSITION_T:
  81. free_disposition( ((struct disposition**)h_parsed));
  82. break;
  83. case HDR_CSEQ_T:
  84. free_cseq(hf->parsed);
  85. break;
  86. case HDR_DATE_T:
  87. free_date(hf->parsed);
  88. break;
  89. case HDR_DIVERSION_T:
  90. free_to(hf->parsed);
  91. break;
  92. case HDR_EVENT_T:
  93. free_event((event_t**)h_parsed);
  94. break;
  95. case HDR_EXPIRES_T:
  96. free_expires((exp_body_t**)h_parsed);
  97. break;
  98. case HDR_FROM_T:
  99. free_to(hf->parsed);
  100. break;
  101. case HDR_IDENTITY_INFO_T:
  102. free_identityinfo(hf->parsed);
  103. break;
  104. case HDR_IDENTITY_T:
  105. free_identity(hf->parsed);
  106. break;
  107. case HDR_PAI_T:
  108. free_pai_ppi_body(hf->parsed);
  109. break;
  110. case HDR_PPI_T:
  111. free_pai_ppi_body(hf->parsed);
  112. break;
  113. case HDR_PROXYAUTH_T:
  114. free_credentials((auth_body_t**)h_parsed);
  115. break;
  116. case HDR_RECORDROUTE_T:
  117. free_rr((rr_t**)h_parsed);
  118. break;
  119. case HDR_REFER_TO_T:
  120. free_to(hf->parsed);
  121. break;
  122. case HDR_ROUTE_T:
  123. free_rr((rr_t**)h_parsed);
  124. break;
  125. case HDR_RPID_T:
  126. free_to(hf->parsed);
  127. break;
  128. case HDR_SESSIONEXPIRES_T:
  129. hdr_free_parsed(h_parsed);
  130. break;
  131. case HDR_SIPIFMATCH_T:
  132. free_sipifmatch((str **)h_parsed);
  133. break;
  134. case HDR_SUBSCRIPTION_STATE_T:
  135. free_subscription_state((subscription_state_t**)h_parsed);
  136. break;
  137. case HDR_SUPPORTED_T:
  138. hdr_free_parsed(h_parsed);
  139. break;
  140. case HDR_TO_T:
  141. free_to(hf->parsed);
  142. break;
  143. case HDR_VIA_T:
  144. free_via_list(hf->parsed);
  145. break;
  146. /* headers with no alloc for parsed structure */
  147. case HDR_CALLID_T:
  148. case HDR_MAXFORWARDS_T:
  149. case HDR_CONTENTTYPE_T:
  150. case HDR_CONTENTLENGTH_T:
  151. case HDR_RETRY_AFTER_T:
  152. case HDR_REQUIRE_T:
  153. case HDR_PROXYREQUIRE_T:
  154. case HDR_UNSUPPORTED_T:
  155. case HDR_ACCEPTLANGUAGE_T:
  156. case HDR_ORGANIZATION_T:
  157. case HDR_PRIORITY_T:
  158. case HDR_SUBJECT_T:
  159. case HDR_USERAGENT_T:
  160. case HDR_SERVER_T:
  161. case HDR_MIN_SE_T:
  162. case HDR_ACCEPTCONTACT_T:
  163. case HDR_ALLOWEVENTS_T:
  164. case HDR_CONTENTENCODING_T:
  165. case HDR_REFERREDBY_T:
  166. case HDR_REJECTCONTACT_T:
  167. case HDR_REQUESTDISPOSITION_T:
  168. case HDR_WWW_AUTHENTICATE_T:
  169. case HDR_PROXY_AUTHENTICATE_T:
  170. case HDR_PATH_T:
  171. case HDR_PRIVACY_T:
  172. case HDR_REASON_T:
  173. break;
  174. default:
  175. LOG(L_CRIT, "BUG: clean_hdr_field: unknown header type %d\n",
  176. hf->type);
  177. break;
  178. }
  179. }
  180. }
  181. /** Frees a hdr_field list.
  182. * WARNING: frees only ->parsed and ->next*/
  183. void free_hdr_field_lst(struct hdr_field* hf)
  184. {
  185. struct hdr_field* foo;
  186. while(hf) {
  187. foo=hf;
  188. hf=hf->next;
  189. clean_hdr_field(foo);
  190. pkg_free(foo);
  191. }
  192. }
  193. /* print the content of hdr_field */
  194. void dump_hdr_field(struct hdr_field const* const hf )
  195. {
  196. LOG(L_ERR, "DEBUG: dump_hdr_field: type=%d, name=%.*s, "
  197. "body=%.*s, parsed=%p, next=%p\n",
  198. hf->type, hf->name.len, ZSW(hf->name.s),
  199. hf->body.len, ZSW(hf->body.s),
  200. hf->parsed, hf->next );
  201. }
  202. /**
  203. * free hdr parsed structure using inner free function
  204. * - hdr parsed struct must have as first file a free function,
  205. * so it can be caseted to hf_parsed_t
  206. */
  207. void hdr_free_parsed(void **h_parsed)
  208. {
  209. if(h_parsed==NULL || *h_parsed==NULL)
  210. return;
  211. if(((hf_parsed_t*)(*h_parsed))->hfree) {
  212. ((hf_parsed_t*)(*h_parsed))->hfree(*h_parsed);
  213. }
  214. *h_parsed = 0;
  215. }