hf.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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-03-26 Frees also hdr->parsed for Route & Record-Route (janakj)
  30. * 2003-04-26 ZSW (jiri)
  31. * 2003-08-05 free the parsed part of Accept header (bogdan)
  32. * 2007-01-26 HDR_DATE_T, HDR_IDENTITY_T, HDR_IDENTITY_INFO_T added (gergo)
  33. * 2007-07-27 added HDR_RETRY_AFTER_T (andrei)
  34. */
  35. /** Parser :: parse header files
  36. * @file
  37. * @ingroup parser
  38. */
  39. #include "hf.h"
  40. #include "parse_via.h"
  41. #include "parse_to.h"
  42. #include "parse_cseq.h"
  43. #include "parse_date.h"
  44. #include "parse_identity.h"
  45. #include "parse_identityinfo.h"
  46. #include "../dprint.h"
  47. #include "../mem/mem.h"
  48. #include "parse_def.h"
  49. #include "digest/digest.h" /* free_credentials */
  50. #include "parse_event.h"
  51. #include "parse_expires.h"
  52. #include "parse_sipifmatch.h"
  53. #include "parse_rr.h"
  54. #include "parse_subscription_state.h"
  55. #include "contact/parse_contact.h"
  56. #include "parse_disposition.h"
  57. #include "parse_allow.h"
  58. #include "../ut.h"
  59. /** Frees a hdr_field structure.
  60. * WARNING: it frees only parsed (and not name.s, body.s)
  61. */
  62. void clean_hdr_field(struct hdr_field* hf)
  63. {
  64. void** h_parsed;
  65. if (hf->parsed){
  66. h_parsed=&hf->parsed; /* strict aliasing warnings workarround */
  67. switch(hf->type){
  68. /* headers with pkg alloc for parsed structure (alphabetic order) */
  69. case HDR_ACCEPT_T:
  70. pkg_free(hf->parsed);
  71. break;
  72. case HDR_ALLOW_T:
  73. free_allow_header(hf);
  74. break;
  75. case HDR_AUTHORIZATION_T:
  76. free_credentials((auth_body_t**)h_parsed);
  77. break;
  78. case HDR_CONTACT_T:
  79. free_contact((contact_body_t**)h_parsed);
  80. break;
  81. case HDR_CONTENTDISPOSITION_T:
  82. free_disposition( ((struct disposition**)h_parsed));
  83. break;
  84. case HDR_CSEQ_T:
  85. free_cseq(hf->parsed);
  86. break;
  87. case HDR_DATE_T:
  88. free_date(hf->parsed);
  89. break;
  90. case HDR_DIVERSION_T:
  91. free_to(hf->parsed);
  92. break;
  93. case HDR_EVENT_T:
  94. free_event((event_t**)h_parsed);
  95. break;
  96. case HDR_EXPIRES_T:
  97. free_expires((exp_body_t**)h_parsed);
  98. break;
  99. case HDR_FROM_T:
  100. free_to(hf->parsed);
  101. break;
  102. case HDR_IDENTITY_INFO_T:
  103. free_identityinfo(hf->parsed);
  104. break;
  105. case HDR_IDENTITY_T:
  106. free_identity(hf->parsed);
  107. break;
  108. case HDR_PAI_T:
  109. free_to(hf->parsed);
  110. break;
  111. case HDR_PPI_T:
  112. free_to(hf->parsed);
  113. break;
  114. case HDR_PROXYAUTH_T:
  115. free_credentials((auth_body_t**)h_parsed);
  116. break;
  117. case HDR_RECORDROUTE_T:
  118. free_rr((rr_t**)h_parsed);
  119. break;
  120. case HDR_REFER_TO_T:
  121. free_to(hf->parsed);
  122. break;
  123. case HDR_ROUTE_T:
  124. free_rr((rr_t**)h_parsed);
  125. break;
  126. case HDR_RPID_T:
  127. free_to(hf->parsed);
  128. break;
  129. case HDR_SESSIONEXPIRES_T:
  130. hdr_free_parsed(h_parsed);
  131. break;
  132. case HDR_SIPIFMATCH_T:
  133. free_sipifmatch((str **)h_parsed);
  134. break;
  135. case HDR_SUBSCRIPTION_STATE_T:
  136. free_subscription_state((subscription_state_t**)h_parsed);
  137. break;
  138. case HDR_SUPPORTED_T:
  139. hdr_free_parsed(h_parsed);
  140. break;
  141. case HDR_TO_T:
  142. free_to(hf->parsed);
  143. break;
  144. case HDR_VIA_T:
  145. free_via_list(hf->parsed);
  146. break;
  147. /* headers with no alloc for parsed structure */
  148. case HDR_CALLID_T:
  149. case HDR_MAXFORWARDS_T:
  150. case HDR_CONTENTTYPE_T:
  151. case HDR_CONTENTLENGTH_T:
  152. case HDR_RETRY_AFTER_T:
  153. case HDR_REQUIRE_T:
  154. case HDR_PROXYREQUIRE_T:
  155. case HDR_UNSUPPORTED_T:
  156. case HDR_ACCEPTLANGUAGE_T:
  157. case HDR_ORGANIZATION_T:
  158. case HDR_PRIORITY_T:
  159. case HDR_SUBJECT_T:
  160. case HDR_USERAGENT_T:
  161. case HDR_SERVER_T:
  162. case HDR_MIN_SE_T:
  163. case HDR_ACCEPTCONTACT_T:
  164. case HDR_ALLOWEVENTS_T:
  165. case HDR_CONTENTENCODING_T:
  166. case HDR_REFERREDBY_T:
  167. case HDR_REJECTCONTACT_T:
  168. case HDR_REQUESTDISPOSITION_T:
  169. case HDR_WWW_AUTHENTICATE_T:
  170. case HDR_PROXY_AUTHENTICATE_T:
  171. case HDR_PATH_T:
  172. case HDR_PRIVACY_T:
  173. case HDR_REASON_T:
  174. break;
  175. default:
  176. LOG(L_CRIT, "BUG: clean_hdr_field: unknown header type %d\n",
  177. hf->type);
  178. break;
  179. }
  180. }
  181. }
  182. /** Frees a hdr_field list.
  183. * WARNING: frees only ->parsed and ->next*/
  184. void free_hdr_field_lst(struct hdr_field* hf)
  185. {
  186. struct hdr_field* foo;
  187. while(hf) {
  188. foo=hf;
  189. hf=hf->next;
  190. clean_hdr_field(foo);
  191. pkg_free(foo);
  192. }
  193. }
  194. /* print the content of hdr_field */
  195. void dump_hdr_field( struct hdr_field* hf )
  196. {
  197. LOG(L_ERR, "DEBUG: dump_hdr_field: type=%d, name=%.*s, "
  198. "body=%.*s, parsed=%p, next=%p\n",
  199. hf->type, hf->name.len, ZSW(hf->name.s),
  200. hf->body.len, ZSW(hf->body.s),
  201. hf->parsed, hf->next );
  202. }
  203. /**
  204. * free hdr parsed structure using inner free function
  205. * - hdr parsed struct must have as first file a free function,
  206. * so it can be caseted to hf_parsed_t
  207. */
  208. void hdr_free_parsed(void **h_parsed)
  209. {
  210. if(h_parsed==NULL || *h_parsed==NULL)
  211. return;
  212. if(((hf_parsed_t*)(*h_parsed))->hfree) {
  213. ((hf_parsed_t*)(*h_parsed))->hfree(*h_parsed);
  214. }
  215. *h_parsed = 0;
  216. }