/src/opensips/parser/hf.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2001-2003 FhG Fokus |
3 | | * |
4 | | * This file is part of opensips, a free SIP server. |
5 | | * |
6 | | * opensips 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 | | * opensips is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program; if not, write to the Free Software |
18 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | | * |
20 | | * History: |
21 | | * ------- |
22 | | * 2006-02-17 Session-Expires, Min-SE (dhsueh@somanetworks.com) |
23 | | */ |
24 | | |
25 | | /** |
26 | | * \file parser/hf.c |
27 | | * \brief Helper functions for SIP headers. |
28 | | * |
29 | | * Memory management and debugging functions for SIP headers. |
30 | | */ |
31 | | |
32 | | |
33 | | #include "hf.h" |
34 | | #include "parse_via.h" |
35 | | #include "parse_to.h" |
36 | | #include "parse_cseq.h" |
37 | | #include "../dprint.h" |
38 | | #include "../mem/mem.h" |
39 | | #include "parse_def.h" |
40 | | #include "digest/digest.h" /* free_credentials */ |
41 | | #include "parse_event.h" |
42 | | #include "parse_expires.h" |
43 | | #include "parse_rr.h" |
44 | | #include "contact/parse_contact.h" |
45 | | #include "parse_disposition.h" |
46 | | #include "../ut.h" |
47 | | #include "parse_supported.h" |
48 | | #include "parse_allow.h" |
49 | | #include "parse_sst.h" |
50 | | #include "parse_content.h" |
51 | | #include "parse_call_info.h" |
52 | | #include "parse_authenticate.h" |
53 | | #include "parse_fcaps.h" |
54 | | #include "parse_security.h" |
55 | | |
56 | | |
57 | | /* |
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* hf) |
62 | 1.38M | { |
63 | 1.38M | if (hf->parsed){ |
64 | 277k | switch(hf->type){ |
65 | 133k | case HDR_VIA_T: |
66 | 133k | free_via_list(hf->parsed); |
67 | 133k | hf->parsed = NULL; |
68 | 133k | break; |
69 | | |
70 | 57.9k | case HDR_TO_T: |
71 | 57.9k | free_to(hf->parsed); |
72 | 57.9k | hf->parsed = NULL; |
73 | 57.9k | break; |
74 | | |
75 | 168 | case HDR_FROM_T: |
76 | 168 | free_to(hf->parsed); |
77 | 168 | hf->parsed = NULL; |
78 | 168 | break; |
79 | | |
80 | 79.8k | case HDR_CSEQ_T: |
81 | 79.8k | free_cseq(hf->parsed); |
82 | 79.8k | hf->parsed = NULL; |
83 | 79.8k | break; |
84 | | |
85 | 0 | case HDR_CALLID_T: |
86 | 0 | break; |
87 | | |
88 | 544 | case HDR_CONTACT_T: |
89 | 544 | free_contact((contact_body_t**)(void*)(&(hf->parsed))); |
90 | 544 | break; |
91 | | |
92 | 0 | case HDR_MAXFORWARDS_T: |
93 | 0 | break; |
94 | | |
95 | 0 | case HDR_ROUTE_T: |
96 | 0 | free_rr((rr_t**)(void*)(&hf->parsed)); |
97 | 0 | break; |
98 | | |
99 | 0 | case HDR_RECORDROUTE_T: |
100 | 0 | free_rr((rr_t**)(void*)(&hf->parsed)); |
101 | 0 | break; |
102 | | |
103 | 0 | case HDR_PATH_T: |
104 | 0 | free_rr((rr_t**)(void*)(&hf->parsed)); |
105 | 0 | break; |
106 | | |
107 | 119 | case HDR_CONTENTTYPE_T: |
108 | 119 | free_contenttype((content_t**)(void*)(&hf->parsed)); |
109 | 119 | break; |
110 | | |
111 | 2.94k | case HDR_CONTENTLENGTH_T: |
112 | 2.94k | break; |
113 | | |
114 | 555 | case HDR_AUTHORIZATION_T: |
115 | 555 | free_credentials((auth_body_t**)(void*)(&(hf->parsed))); |
116 | 555 | break; |
117 | | |
118 | 0 | case HDR_EXPIRES_T: |
119 | 0 | free_expires((exp_body_t**)(void*)(&(hf->parsed))); |
120 | 0 | break; |
121 | | |
122 | 2 | case HDR_PROXYAUTH_T: |
123 | 2 | free_credentials((auth_body_t**)(void*)(&(hf->parsed))); |
124 | 2 | break; |
125 | | |
126 | 0 | case HDR_SUPPORTED_T: |
127 | 0 | free_supported((struct supported_body**)(void*)(&(hf->parsed))); |
128 | 0 | break; |
129 | | |
130 | 0 | case HDR_PROXYREQUIRE_T: |
131 | 0 | break; |
132 | | |
133 | 0 | case HDR_UNSUPPORTED_T: |
134 | 0 | break; |
135 | | |
136 | 0 | case HDR_ALLOW_T: |
137 | 0 | free_allow((struct allow_body**)(void*)(&(hf->parsed))); |
138 | 0 | break; |
139 | | |
140 | 0 | case HDR_EVENT_T: |
141 | 0 | free_event((event_t**)(void*)(&(hf->parsed))); |
142 | 0 | break; |
143 | | |
144 | 0 | case HDR_ACCEPT_T: |
145 | 0 | pkg_free(hf->parsed); |
146 | 0 | hf->parsed = NULL; |
147 | 0 | break; |
148 | | |
149 | 0 | case HDR_ACCEPTLANGUAGE_T: |
150 | 0 | break; |
151 | | |
152 | 0 | case HDR_ORGANIZATION_T: |
153 | 0 | break; |
154 | | |
155 | 0 | case HDR_PRIORITY_T: |
156 | 0 | break; |
157 | | |
158 | 0 | case HDR_SUBJECT_T: |
159 | 0 | break; |
160 | | |
161 | 0 | case HDR_USERAGENT_T: |
162 | 0 | break; |
163 | | |
164 | 0 | case HDR_ACCEPTDISPOSITION_T: |
165 | 0 | break; |
166 | | |
167 | 0 | case HDR_CONTENTDISPOSITION_T: |
168 | 0 | free_disposition( ((struct disposition**)(void*)(&hf->parsed)) ); |
169 | 0 | break; |
170 | | |
171 | 115 | case HDR_DIVERSION_T: |
172 | 115 | free_to(hf->parsed); |
173 | 115 | hf->parsed = NULL; |
174 | 115 | break; |
175 | | |
176 | 2 | case HDR_RPID_T: |
177 | 2 | free_to(hf->parsed); |
178 | 2 | hf->parsed = NULL; |
179 | 2 | break; |
180 | | |
181 | 5 | case HDR_REFER_TO_T: |
182 | 5 | free_to(hf->parsed); |
183 | 5 | hf->parsed = NULL; |
184 | 5 | break; |
185 | | |
186 | 0 | case HDR_SESSION_EXPIRES_T: |
187 | 0 | free_session_expires((struct session_expires*)hf->parsed ); |
188 | 0 | hf->parsed = NULL; |
189 | 0 | break; |
190 | | |
191 | 0 | case HDR_MIN_SE_T: |
192 | 0 | break; |
193 | | |
194 | 0 | case HDR_MIN_EXPIRES_T: |
195 | 0 | break; |
196 | | |
197 | 164 | case HDR_PPI_T: |
198 | 164 | free_to(hf->parsed); |
199 | 164 | hf->parsed = NULL; |
200 | 164 | break; |
201 | | |
202 | 8 | case HDR_PAI_T: |
203 | 8 | free_to(hf->parsed); |
204 | 8 | hf->parsed = NULL; |
205 | 8 | break; |
206 | | |
207 | 0 | case HDR_PRIVACY_T: |
208 | 0 | break; |
209 | | |
210 | 0 | case HDR_RETRY_AFTER_T: |
211 | 0 | break; |
212 | | |
213 | 0 | case HDR_CALL_INFO_T: |
214 | 0 | free_call_info(hf->parsed); |
215 | 0 | hf->parsed = NULL; |
216 | 0 | break; |
217 | | |
218 | 221 | case HDR_WWW_AUTHENTICATE_T: |
219 | 1.35k | case HDR_PROXY_AUTHENTICATE_T: |
220 | 1.35k | free_authenticate((struct authenticate_body *)hf->parsed); |
221 | 1.35k | hf->parsed = NULL; |
222 | 1.35k | break; |
223 | | |
224 | 0 | case HDR_FEATURE_CAPS_T: |
225 | 0 | free_fcaps((struct fcaps_body **)&hf->parsed); |
226 | 0 | break; |
227 | | |
228 | 0 | case HDR_SECURITY_CLIENT_T: |
229 | 0 | case HDR_SECURITY_SERVER_T: |
230 | 0 | case HDR_SECURITY_VERIFY_T: |
231 | 0 | free_sec_agree((sec_agree_body_t **)&hf->parsed); |
232 | 0 | break; |
233 | | |
234 | 0 | case HDR_TO_PATH_T: |
235 | 0 | case HDR_FROM_PATH_T: |
236 | 0 | case HDR_MESSAGE_ID_T: |
237 | 0 | case HDR_BYTE_RANGE_T: |
238 | 0 | case HDR_FAILURE_REPORT_T: |
239 | 0 | case HDR_SUCCESS_REPORT_T: |
240 | 0 | case HDR_STATUS_T: |
241 | 0 | case HDR_USE_PATH_T: |
242 | | /* nothing parsed here */ |
243 | 0 | break; |
244 | | |
245 | 0 | default: |
246 | 0 | LM_CRIT("unknown header type %d\n", hf->type); |
247 | 0 | break; |
248 | 277k | } |
249 | 277k | } |
250 | 1.38M | } |
251 | | |
252 | | |
253 | | /* |
254 | | * Frees a hdr_field list, |
255 | | * WARNING: frees only ->parsed and ->next*/ |
256 | | void free_hdr_field_lst(struct hdr_field* hf) |
257 | 24.6k | { |
258 | 24.6k | struct hdr_field* foo; |
259 | | |
260 | 1.41M | while(hf) { |
261 | 1.38M | foo=hf; |
262 | 1.38M | hf=hf->next; |
263 | 1.38M | clean_hdr_field(foo); |
264 | 1.38M | pkg_free(foo); |
265 | 1.38M | } |
266 | 24.6k | } |
267 | | |
268 | | void dump_hdr_field( struct hdr_field* hf ) |
269 | 0 | { |
270 | 0 | LM_ERR("type=%d, name=%.*s, body=%.*s, parsed=%p, next=%p\n", |
271 | 0 | hf->type, hf->name.len, ZSW(hf->name.s), |
272 | 0 | hf->body.len, ZSW(hf->body.s), |
273 | 0 | hf->parsed, hf->next ); |
274 | 0 | } |