... | ... |
@@ -34,68 +34,84 @@ |
34 | 34 |
#include "../mem/mem.h" |
35 | 35 |
|
36 | 36 |
|
37 |
-enum { |
|
38 |
- START_TO, DISPLAY_QUOTED, E_DISPLAY_QUOTED, DISPLAY_TOKEN, |
|
39 |
- DISPLAY_TOKEN_SP, S_URI_ENCLOSED, URI_ENCLOSED, E_URI_ENCLOSED, |
|
40 |
- URI_OR_TOKEN, MAYBE_URI_END, END, F_CR, F_LF, F_CRLF |
|
37 |
+enum |
|
38 |
+{ |
|
39 |
+ START_TO, |
|
40 |
+ DISPLAY_QUOTED, |
|
41 |
+ E_DISPLAY_QUOTED, |
|
42 |
+ DISPLAY_TOKEN, |
|
43 |
+ DISPLAY_TOKEN_SP, |
|
44 |
+ S_URI_ENCLOSED, |
|
45 |
+ URI_ENCLOSED, |
|
46 |
+ E_URI_ENCLOSED, |
|
47 |
+ URI_OR_TOKEN, |
|
48 |
+ MAYBE_URI_END, |
|
49 |
+ END, |
|
50 |
+ F_CR, |
|
51 |
+ F_LF, |
|
52 |
+ F_CRLF |
|
41 | 53 |
}; |
42 | 54 |
|
43 | 55 |
|
44 |
-enum { |
|
45 |
- S_PARA_NAME=20, PARA_NAME, S_EQUAL, S_PARA_VALUE, TAG1, TAG2, |
|
46 |
- TAG3, PARA_VALUE_TOKEN , PARA_VALUE_QUOTED, E_PARA_VALUE |
|
56 |
+enum |
|
57 |
+{ |
|
58 |
+ S_PARA_NAME = 20, |
|
59 |
+ PARA_NAME, |
|
60 |
+ S_EQUAL, |
|
61 |
+ S_PARA_VALUE, |
|
62 |
+ TAG1, |
|
63 |
+ TAG2, |
|
64 |
+ TAG3, |
|
65 |
+ PARA_VALUE_TOKEN, |
|
66 |
+ PARA_VALUE_QUOTED, |
|
67 |
+ E_PARA_VALUE |
|
47 | 68 |
}; |
48 | 69 |
|
49 | 70 |
|
50 |
- |
|
51 |
-#define add_param( _param , _body , _newparam ) \ |
|
52 |
- do{\ |
|
53 |
- DBG("DEBUG: add_param: %.*s=%.*s\n",param->name.len,ZSW(param->name.s),\ |
|
54 |
- param->value.len,ZSW(param->value.s));\ |
|
55 |
- if (!(_body)->param_lst) (_body)->param_lst=(_param);\ |
|
56 |
- else (_body)->last_param->next=(_param);\ |
|
57 |
- (_body)->last_param =(_param);\ |
|
58 |
- if ((_param)->type==TAG_PARAM)\ |
|
59 |
- memcpy(&((_body)->tag_value),&((_param)->value),sizeof(str));\ |
|
60 |
- _newparam = 0;\ |
|
61 |
- }while(0); |
|
62 |
- |
|
63 |
- |
|
64 |
- |
|
65 |
- |
|
66 |
- |
|
67 |
-static char* parse_to_param(char* const buffer, const char* const end, |
|
68 |
- struct to_body* const to_b, const int allow_comma_sep, |
|
69 |
- int* const returned_status) |
|
71 |
+#define add_param(_param, _body, _newparam) \ |
|
72 |
+ do { \ |
|
73 |
+ LM_DBG("add param: %.*s=%.*s\n", param->name.len, ZSW(param->name.s), \ |
|
74 |
+ param->value.len, ZSW(param->value.s)); \ |
|
75 |
+ if(!(_body)->param_lst) \ |
|
76 |
+ (_body)->param_lst = (_param); \ |
|
77 |
+ else \ |
|
78 |
+ (_body)->last_param->next = (_param); \ |
|
79 |
+ (_body)->last_param = (_param); \ |
|
80 |
+ if((_param)->type == TAG_PARAM) \ |
|
81 |
+ memcpy(&((_body)->tag_value), &((_param)->value), sizeof(str)); \ |
|
82 |
+ _newparam = 0; \ |
|
83 |
+ } while(0); |
|
84 |
+ |
|
85 |
+ |
|
86 |
+static char *parse_to_param(char *const buffer, const char *const end, |
|
87 |
+ struct to_body *const to_b, const int allow_comma_sep, |
|
88 |
+ int *const returned_status) |
|
70 | 89 |
{ |
71 | 90 |
struct to_param *param; |
72 | 91 |
struct to_param *newparam; |
73 | 92 |
int status; |
74 | 93 |
int saved_status; |
75 |
- char *tmp; |
|
76 |
- |
|
77 |
- param=0; |
|
78 |
- newparam=0; |
|
79 |
- status=E_PARA_VALUE; |
|
80 |
- saved_status=E_PARA_VALUE; |
|
81 |
- for( tmp=buffer; tmp<end; tmp++) |
|
82 |
- { |
|
83 |
- switch(*tmp) |
|
84 |
- { |
|
94 |
+ char *tmp; |
|
95 |
+ |
|
96 |
+ param = 0; |
|
97 |
+ newparam = 0; |
|
98 |
+ status = E_PARA_VALUE; |
|
99 |
+ saved_status = E_PARA_VALUE; |
|
100 |
+ for(tmp = buffer; tmp < end; tmp++) { |
|
101 |
+ switch(*tmp) { |
|
85 | 102 |
case ' ': |
86 | 103 |
case '\t': |
87 |
- switch (status) |
|
88 |
- { |
|
104 |
+ switch(status) { |
|
89 | 105 |
case TAG3: |
90 |
- param->type=TAG_PARAM; |
|
106 |
+ param->type = TAG_PARAM; |
|
91 | 107 |
case PARA_NAME: |
92 | 108 |
case TAG1: |
93 | 109 |
case TAG2: |
94 |
- param->name.len = tmp-param->name.s; |
|
110 |
+ param->name.len = tmp - param->name.s; |
|
95 | 111 |
status = S_EQUAL; |
96 | 112 |
break; |
97 | 113 |
case PARA_VALUE_TOKEN: |
98 |
- param->value.len = tmp-param->value.s; |
|
114 |
+ param->value.len = tmp - param->value.s; |
|
99 | 115 |
status = E_PARA_VALUE; |
100 | 116 |
add_param(param, to_b, newparam); |
101 | 117 |
break; |
... | ... |
@@ -103,69 +119,67 @@ static char* parse_to_param(char* const buffer, const char* const end, |
103 | 119 |
case F_LF: |
104 | 120 |
case F_CR: |
105 | 121 |
/*previous=crlf and now =' '*/ |
106 |
- status=saved_status; |
|
122 |
+ status = saved_status; |
|
107 | 123 |
break; |
108 | 124 |
} |
109 | 125 |
break; |
110 | 126 |
case '\n': |
111 |
- switch (status) |
|
112 |
- { |
|
127 |
+ switch(status) { |
|
113 | 128 |
case S_PARA_NAME: |
114 | 129 |
case S_EQUAL: |
115 | 130 |
case S_PARA_VALUE: |
116 | 131 |
case E_PARA_VALUE: |
117 |
- saved_status=status; |
|
118 |
- status=F_LF; |
|
132 |
+ saved_status = status; |
|
133 |
+ status = F_LF; |
|
119 | 134 |
break; |
120 | 135 |
case TAG3: |
121 |
- param->type=TAG_PARAM; |
|
136 |
+ param->type = TAG_PARAM; |
|
122 | 137 |
case PARA_NAME: |
123 | 138 |
case TAG1: |
124 | 139 |
case TAG2: |
125 |
- param->name.len = tmp-param->name.s; |
|
140 |
+ param->name.len = tmp - param->name.s; |
|
126 | 141 |
saved_status = S_EQUAL; |
127 | 142 |
status = F_LF; |
128 | 143 |
break; |
129 | 144 |
case PARA_VALUE_TOKEN: |
130 |
- param->value.len = tmp-param->value.s; |
|
145 |
+ param->value.len = tmp - param->value.s; |
|
131 | 146 |
saved_status = E_PARA_VALUE; |
132 | 147 |
status = F_LF; |
133 | 148 |
add_param(param, to_b, newparam); |
134 | 149 |
break; |
135 | 150 |
case F_CR: |
136 |
- status=F_CRLF; |
|
151 |
+ status = F_CRLF; |
|
137 | 152 |
break; |
138 | 153 |
case F_CRLF: |
139 | 154 |
case F_LF: |
140 |
- status=saved_status; |
|
155 |
+ status = saved_status; |
|
141 | 156 |
goto endofheader; |
142 | 157 |
default: |
143 | 158 |
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
144 |
- *tmp,status, (int)(tmp-buffer), ZSW(buffer)); |
|
159 |
+ *tmp, status, (int)(tmp - buffer), ZSW(buffer)); |
|
145 | 160 |
goto error; |
146 | 161 |
} |
147 | 162 |
break; |
148 | 163 |
case '\r': |
149 |
- switch (status) |
|
150 |
- { |
|
164 |
+ switch(status) { |
|
151 | 165 |
case S_PARA_NAME: |
152 | 166 |
case S_EQUAL: |
153 | 167 |
case S_PARA_VALUE: |
154 | 168 |
case E_PARA_VALUE: |
155 |
- saved_status=status; |
|
156 |
- status=F_CR; |
|
169 |
+ saved_status = status; |
|
170 |
+ status = F_CR; |
|
157 | 171 |
break; |
158 | 172 |
case TAG3: |
159 |
- param->type=TAG_PARAM; |
|
173 |
+ param->type = TAG_PARAM; |
|
160 | 174 |
case PARA_NAME: |
161 | 175 |
case TAG1: |
162 | 176 |
case TAG2: |
163 |
- param->name.len = tmp-param->name.s; |
|
177 |
+ param->name.len = tmp - param->name.s; |
|
164 | 178 |
saved_status = S_EQUAL; |
165 | 179 |
status = F_CR; |
166 | 180 |
break; |
167 | 181 |
case PARA_VALUE_TOKEN: |
168 |
- param->value.len = tmp-param->value.s; |
|
182 |
+ param->value.len = tmp - param->value.s; |
|
169 | 183 |
saved_status = E_PARA_VALUE; |
170 | 184 |
status = F_CR; |
171 | 185 |
add_param(param, to_b, newparam); |
... | ... |
@@ -173,48 +187,45 @@ static char* parse_to_param(char* const buffer, const char* const end, |
173 | 187 |
case F_CRLF: |
174 | 188 |
case F_CR: |
175 | 189 |
case F_LF: |
176 |
- status=saved_status; |
|
190 |
+ status = saved_status; |
|
177 | 191 |
goto endofheader; |
178 | 192 |
default: |
179 | 193 |
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
180 |
- *tmp,status, (int)(tmp-buffer), ZSW(buffer)); |
|
194 |
+ *tmp, status, (int)(tmp - buffer), ZSW(buffer)); |
|
181 | 195 |
goto error; |
182 | 196 |
} |
183 | 197 |
break; |
184 | 198 |
case 0: |
185 |
- switch (status) |
|
186 |
- { |
|
199 |
+ switch(status) { |
|
187 | 200 |
case TAG3: |
188 | 201 |
param->type = TAG_PARAM; |
189 | 202 |
case PARA_NAME: |
190 | 203 |
case TAG1: |
191 | 204 |
case TAG2: |
192 |
- param->name.len = tmp-param->name.s; |
|
205 |
+ param->name.len = tmp - param->name.s; |
|
193 | 206 |
status = S_EQUAL; |
194 | 207 |
case S_EQUAL: |
195 | 208 |
case S_PARA_VALUE: |
196 |
- saved_status=status; |
|
209 |
+ saved_status = status; |
|
197 | 210 |
goto endofheader; |
198 | 211 |
case PARA_VALUE_TOKEN: |
199 | 212 |
status = E_PARA_VALUE; |
200 |
- param->value.len = tmp-param->value.s; |
|
201 |
- add_param(param , to_b, newparam); |
|
213 |
+ param->value.len = tmp - param->value.s; |
|
214 |
+ add_param(param, to_b, newparam); |
|
202 | 215 |
case E_PARA_VALUE: |
203 | 216 |
saved_status = status; |
204 | 217 |
goto endofheader; |
205 | 218 |
break; |
206 | 219 |
default: |
207 | 220 |
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
208 |
- *tmp,status, (int)(tmp-buffer), ZSW(buffer)); |
|
221 |
+ *tmp, status, (int)(tmp - buffer), ZSW(buffer)); |
|
209 | 222 |
goto error; |
210 | 223 |
} |
211 | 224 |
break; |
212 | 225 |
case '\\': |
213 |
- switch (status) |
|
214 |
- { |
|
226 |
+ switch(status) { |
|
215 | 227 |
case PARA_VALUE_QUOTED: |
216 |
- switch (*(tmp+1)) |
|
217 |
- { |
|
228 |
+ switch(*(tmp + 1)) { |
|
218 | 229 |
case '\r': |
219 | 230 |
case '\n': |
220 | 231 |
break; |
... | ... |
@@ -223,19 +234,18 @@ static char* parse_to_param(char* const buffer, const char* const end, |
223 | 234 |
} |
224 | 235 |
default: |
225 | 236 |
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
226 |
- *tmp,status, (int)(tmp-buffer), ZSW(buffer)); |
|
237 |
+ *tmp, status, (int)(tmp - buffer), ZSW(buffer)); |
|
227 | 238 |
goto error; |
228 | 239 |
} |
229 | 240 |
break; |
230 | 241 |
case '"': |
231 |
- switch (status) |
|
232 |
- { |
|
242 |
+ switch(status) { |
|
233 | 243 |
case S_PARA_VALUE: |
234 |
- param->value.s = tmp+1; |
|
244 |
+ param->value.s = tmp + 1; |
|
235 | 245 |
status = PARA_VALUE_QUOTED; |
236 | 246 |
break; |
237 | 247 |
case PARA_VALUE_QUOTED: |
238 |
- param->value.len=tmp-param->value.s; |
|
248 |
+ param->value.len = tmp - param->value.s; |
|
239 | 249 |
add_param(param, to_b, newparam); |
240 | 250 |
status = E_PARA_VALUE; |
241 | 251 |
break; |
... | ... |
@@ -246,13 +256,12 @@ static char* parse_to_param(char* const buffer, const char* const end, |
246 | 256 |
goto endofheader; |
247 | 257 |
default: |
248 | 258 |
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
249 |
- *tmp,status,(int)(tmp-buffer), ZSW(buffer)); |
|
259 |
+ *tmp, status, (int)(tmp - buffer), ZSW(buffer)); |
|
250 | 260 |
goto error; |
251 | 261 |
} |
252 | 262 |
break; |
253 |
- case ';' : |
|
254 |
- switch (status) |
|
255 |
- { |
|
263 |
+ case ';': |
|
264 |
+ switch(status) { |
|
256 | 265 |
case PARA_VALUE_QUOTED: |
257 | 266 |
break; |
258 | 267 |
case TAG3: |
... | ... |
@@ -260,7 +269,7 @@ static char* parse_to_param(char* const buffer, const char* const end, |
260 | 269 |
case PARA_NAME: |
261 | 270 |
case TAG1: |
262 | 271 |
case TAG2: |
263 |
- param->name.len = tmp-param->name.s; |
|
272 |
+ param->name.len = tmp - param->name.s; |
|
264 | 273 |
case S_EQUAL: |
265 | 274 |
param->value.s = 0; |
266 | 275 |
param->value.len = 0; |
... | ... |
@@ -268,18 +277,18 @@ static char* parse_to_param(char* const buffer, const char* const end, |
268 | 277 |
case S_PARA_VALUE: |
269 | 278 |
param->value.s = tmp; |
270 | 279 |
case PARA_VALUE_TOKEN: |
271 |
- param->value.len=tmp-param->value.s; |
|
272 |
-semicolon_add_param: |
|
280 |
+ param->value.len = tmp - param->value.s; |
|
281 |
+ semicolon_add_param: |
|
273 | 282 |
add_param(param, to_b, newparam); |
274 | 283 |
case E_PARA_VALUE: |
275 |
- param = (struct to_param*) |
|
276 |
- pkg_malloc(sizeof(struct to_param)); |
|
277 |
- if (!param){ |
|
284 |
+ param = (struct to_param *)pkg_malloc( |
|
285 |
+ sizeof(struct to_param)); |
|
286 |
+ if(!param) { |
|
278 | 287 |
LM_ERR("out of memory\n"); |
279 | 288 |
goto error; |
280 | 289 |
} |
281 |
- memset(param,0,sizeof(struct to_param)); |
|
282 |
- param->type=GENERAL_PARAM; |
|
290 |
+ memset(param, 0, sizeof(struct to_param)); |
|
291 |
+ param->type = GENERAL_PARAM; |
|
283 | 292 |
status = S_PARA_NAME; |
284 | 293 |
/* link to free mem if not added in to_body list */ |
285 | 294 |
newparam = param; |
... | ... |
@@ -291,14 +300,13 @@ semicolon_add_param: |
291 | 300 |
goto endofheader; |
292 | 301 |
default: |
293 | 302 |
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
294 |
- *tmp,status, (int)(tmp-buffer), ZSW(buffer)); |
|
303 |
+ *tmp, status, (int)(tmp - buffer), ZSW(buffer)); |
|
295 | 304 |
goto error; |
296 | 305 |
} |
297 | 306 |
break; |
298 | 307 |
case 'T': |
299 |
- case 't' : |
|
300 |
- switch (status) |
|
301 |
- { |
|
308 |
+ case 't': |
|
309 |
+ switch(status) { |
|
302 | 310 |
case PARA_VALUE_QUOTED: |
303 | 311 |
case PARA_VALUE_TOKEN: |
304 | 312 |
case PARA_NAME: |
... | ... |
@@ -323,14 +331,13 @@ semicolon_add_param: |
323 | 331 |
goto endofheader; |
324 | 332 |
default: |
325 | 333 |
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
326 |
- *tmp,status, (int)(tmp-buffer), ZSW(buffer)); |
|
334 |
+ *tmp, status, (int)(tmp - buffer), ZSW(buffer)); |
|
327 | 335 |
goto error; |
328 | 336 |
} |
329 | 337 |
break; |
330 | 338 |
case 'A': |
331 |
- case 'a' : |
|
332 |
- switch (status) |
|
333 |
- { |
|
339 |
+ case 'a': |
|
340 |
+ switch(status) { |
|
334 | 341 |
case PARA_VALUE_QUOTED: |
335 | 342 |
case PARA_VALUE_TOKEN: |
336 | 343 |
case PARA_NAME: |
... | ... |
@@ -357,14 +364,13 @@ semicolon_add_param: |
357 | 364 |
goto endofheader; |
358 | 365 |
default: |
359 | 366 |
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
360 |
- *tmp,status, (int)(tmp-buffer), ZSW(buffer)); |
|
367 |
+ *tmp, status, (int)(tmp - buffer), ZSW(buffer)); |
|
361 | 368 |
goto error; |
362 | 369 |
} |
363 | 370 |
break; |
364 | 371 |
case 'G': |
365 |
- case 'g' : |
|
366 |
- switch (status) |
|
367 |
- { |
|
372 |
+ case 'g': |
|
373 |
+ switch(status) { |
|
368 | 374 |
case PARA_VALUE_QUOTED: |
369 | 375 |
case PARA_VALUE_TOKEN: |
370 | 376 |
case PARA_NAME: |
... | ... |
@@ -391,21 +397,20 @@ semicolon_add_param: |
391 | 397 |
goto endofheader; |
392 | 398 |
default: |
393 | 399 |
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
394 |
- *tmp,status, (int)(tmp-buffer), ZSW(buffer)); |
|
400 |
+ *tmp, status, (int)(tmp - buffer), ZSW(buffer)); |
|
395 | 401 |
goto error; |
396 | 402 |
} |
397 | 403 |
break; |
398 | 404 |
case '=': |
399 |
- switch (status) |
|
400 |
- { |
|
405 |
+ switch(status) { |
|
401 | 406 |
case PARA_VALUE_QUOTED: |
402 | 407 |
break; |
403 | 408 |
case TAG3: |
404 |
- param->type=TAG_PARAM; |
|
409 |
+ param->type = TAG_PARAM; |
|
405 | 410 |
case PARA_NAME: |
406 | 411 |
case TAG1: |
407 | 412 |
case TAG2: |
408 |
- param->name.len = tmp-param->name.s; |
|
413 |
+ param->name.len = tmp - param->name.s; |
|
409 | 414 |
status = S_PARA_VALUE; |
410 | 415 |
break; |
411 | 416 |
case S_EQUAL: |
... | ... |
@@ -418,37 +423,35 @@ semicolon_add_param: |
418 | 423 |
goto endofheader; |
419 | 424 |
default: |
420 | 425 |
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
421 |
- *tmp,status, (int)(tmp-buffer), ZSW(buffer)); |
|
426 |
+ *tmp, status, (int)(tmp - buffer), ZSW(buffer)); |
|
422 | 427 |
goto error; |
423 | 428 |
} |
424 | 429 |
break; |
425 | 430 |
case ',': |
426 |
- if(status==PARA_VALUE_QUOTED) { |
|
431 |
+ if(status == PARA_VALUE_QUOTED) { |
|
427 | 432 |
/* comma is allowed inside quoted values */ |
428 | 433 |
break; |
429 | 434 |
} |
430 |
- if (allow_comma_sep) |
|
431 |
- { |
|
432 |
- switch (status) |
|
433 |
- { |
|
435 |
+ if(allow_comma_sep) { |
|
436 |
+ switch(status) { |
|
434 | 437 |
case S_PARA_NAME: |
435 | 438 |
case S_EQUAL: |
436 | 439 |
case S_PARA_VALUE: |
437 | 440 |
case E_PARA_VALUE: |
438 |
- saved_status=status; |
|
439 |
- status=E_PARA_VALUE; |
|
441 |
+ saved_status = status; |
|
442 |
+ status = E_PARA_VALUE; |
|
440 | 443 |
goto endofheader; |
441 | 444 |
case TAG3: |
442 |
- param->type=TAG_PARAM; |
|
445 |
+ param->type = TAG_PARAM; |
|
443 | 446 |
case PARA_NAME: |
444 | 447 |
case TAG1: |
445 | 448 |
case TAG2: |
446 |
- param->name.len = tmp-param->name.s; |
|
449 |
+ param->name.len = tmp - param->name.s; |
|
447 | 450 |
saved_status = S_EQUAL; |
448 | 451 |
status = E_PARA_VALUE; |
449 | 452 |
goto endofheader; |
450 | 453 |
case PARA_VALUE_TOKEN: |
451 |
- param->value.len = tmp-param->value.s; |
|
454 |
+ param->value.len = tmp - param->value.s; |
|
452 | 455 |
saved_status = E_PARA_VALUE; |
453 | 456 |
status = E_PARA_VALUE; |
454 | 457 |
add_param(param, to_b, newparam); |
... | ... |
@@ -456,27 +459,28 @@ semicolon_add_param: |
456 | 459 |
case F_CRLF: |
457 | 460 |
case F_CR: |
458 | 461 |
case F_LF: |
459 |
- status=saved_status; |
|
462 |
+ status = saved_status; |
|
460 | 463 |
goto endofheader; |
461 | 464 |
default: |
462 |
- LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
|
463 |
- *tmp,status, (int)(tmp-buffer), ZSW(buffer)); |
|
465 |
+ LM_ERR("unexpected char [%c] in status %d: [%.*s] " |
|
466 |
+ ".\n", |
|
467 |
+ *tmp, status, (int)(tmp - buffer), |
|
468 |
+ ZSW(buffer)); |
|
464 | 469 |
goto error; |
465 | 470 |
} |
466 | 471 |
break; |
467 | 472 |
} else { |
468 |
- if((status==S_PARA_VALUE || status==PARA_VALUE_TOKEN) |
|
469 |
- && param->type==TAG_PARAM) { |
|
473 |
+ if((status == S_PARA_VALUE || status == PARA_VALUE_TOKEN) |
|
474 |
+ && param->type == TAG_PARAM) { |
|
470 | 475 |
/* if comma is not separator, allow it as part of value |
471 | 476 |
* - some user agents use it */ |
472 | 477 |
break; |
473 | 478 |
} |
474 | 479 |
LM_ERR("invalid character ',' in status %d: [%.*s]\n", |
475 |
- status, (int)(tmp-buffer), ZSW(buffer)); |
|
480 |
+ status, (int)(tmp - buffer), ZSW(buffer)); |
|
476 | 481 |
} |
477 | 482 |
default: |
478 |
- switch (status) |
|
479 |
- { |
|
483 |
+ switch(status) { |
|
480 | 484 |
case TAG1: |
481 | 485 |
case TAG2: |
482 | 486 |
case TAG3: |
... | ... |
@@ -500,94 +504,92 @@ semicolon_add_param: |
500 | 504 |
/*previous=crlf and now !=' '*/ |
501 | 505 |
goto endofheader; |
502 | 506 |
default: |
503 |
- LM_ERR("spitting out [%c] in status %d\n",*tmp,status); |
|
507 |
+ LM_ERR("spitting out [%c] in status %d\n", *tmp, |
|
508 |
+ status); |
|
504 | 509 |
goto error; |
505 | 510 |
} |
506 |
- }/*switch*/ |
|
507 |
- }/*for*/ |
|
508 |
- if (!(status==F_CR || status==F_LF || status==F_CRLF)) |
|
509 |
- saved_status=status; |
|
511 |
+ } /*switch*/ |
|
512 |
+ } /*for*/ |
|
513 |
+ if(!(status == F_CR || status == F_LF || status == F_CRLF)) |
|
514 |
+ saved_status = status; |
|
510 | 515 |
|
511 | 516 |
|
512 | 517 |
endofheader: |
513 |
- switch(saved_status){ |
|
518 |
+ switch(saved_status) { |
|
514 | 519 |
case TAG3: |
515 |
- param->type = TAG_PARAM; /* tag at the end */ |
|
516 |
- /* no break */ |
|
520 |
+ param->type = TAG_PARAM; /* tag at the end */ |
|
521 |
+ /* no break */ |
|
517 | 522 |
case PARA_NAME: |
518 | 523 |
case TAG1: |
519 | 524 |
case TAG2: |
520 |
- param->name.len = tmp-param->name.s; |
|
521 |
- /* no break */ |
|
525 |
+ param->name.len = tmp - param->name.s; |
|
526 |
+ /* no break */ |
|
522 | 527 |
case S_EQUAL: |
523 | 528 |
/* parameter without '=', e.g. foo */ |
524 |
- param->value.s=0; |
|
525 |
- param->value.len=0; |
|
529 |
+ param->value.s = 0; |
|
530 |
+ param->value.len = 0; |
|
526 | 531 |
add_param(param, to_b, newparam); |
527 |
- saved_status=E_PARA_VALUE; |
|
532 |
+ saved_status = E_PARA_VALUE; |
|
528 | 533 |
break; |
529 | 534 |
case S_PARA_VALUE: |
530 | 535 |
/* parameter with null value, e.g. foo= */ |
531 |
- if ( status==F_CRLF ) |
|
532 |
- param->value.s=tmp-2; |
|
533 |
- else if ( status==F_CR || status==F_LF ) |
|
534 |
- param->value.s=tmp-1; |
|
536 |
+ if(status == F_CRLF) |
|
537 |
+ param->value.s = tmp - 2; |
|
538 |
+ else if(status == F_CR || status == F_LF) |
|
539 |
+ param->value.s = tmp - 1; |
|
535 | 540 |
else |
536 |
- param->value.s=tmp; |
|
537 |
- param->value.len=0; |
|
541 |
+ param->value.s = tmp; |
|
542 |
+ param->value.len = 0; |
|
538 | 543 |
add_param(param, to_b, newparam); |
539 |
- saved_status=E_PARA_VALUE; |
|
544 |
+ saved_status = E_PARA_VALUE; |
|
540 | 545 |
break; |
541 | 546 |
case PARA_VALUE_TOKEN: |
542 |
- param->value.len=tmp-param->value.s; |
|
547 |
+ param->value.len = tmp - param->value.s; |
|
543 | 548 |
add_param(param, to_b, newparam); |
544 |
- saved_status=E_PARA_VALUE; |
|
549 |
+ saved_status = E_PARA_VALUE; |
|
545 | 550 |
break; |
546 | 551 |
case E_PARA_VALUE: |
547 | 552 |
break; |
548 | 553 |
default: |
549 | 554 |
LM_ERR("unexpected end of header, status %d: [%.*s] .\n", |
550 |
- saved_status, (int)(tmp-buffer), ZSW(buffer)); |
|
555 |
+ saved_status, (int)(tmp - buffer), ZSW(buffer)); |
|
551 | 556 |
goto error; |
552 | 557 |
} |
553 |
- *returned_status=saved_status; |
|
558 |
+ *returned_status = saved_status; |
|
554 | 559 |
return tmp; |
555 | 560 |
|
556 | 561 |
error: |
557 |
- if (newparam) pkg_free(newparam); |
|
558 |
- to_b->error=PARSE_ERROR; |
|
562 |
+ if(newparam) |
|
563 |
+ pkg_free(newparam); |
|
564 |
+ to_b->error = PARSE_ERROR; |
|
559 | 565 |
*returned_status = status; |
560 | 566 |
return tmp; |
561 | 567 |
} |
562 | 568 |
|
563 | 569 |
|
564 |
- |
|
565 |
-char* parse_addr_spec(char* const buffer, const char* const end, |
|
566 |
- struct to_body* const to_b, const int allow_comma_sep) |
|
570 |
+char *parse_addr_spec(char *const buffer, const char *const end, |
|
571 |
+ struct to_body *const to_b, const int allow_comma_sep) |
|
567 | 572 |
{ |
568 | 573 |
int status; |
569 | 574 |
int saved_status; |
570 |
- char *tmp,*foo; |
|
575 |
+ char *tmp, *foo; |
|
571 | 576 |
|
572 |
- saved_status=START_TO; /* fixes gcc 4.x warning */ |
|
573 |
- status=START_TO; |
|
577 |
+ saved_status = START_TO; /* fixes gcc 4.x warning */ |
|
578 |
+ status = START_TO; |
|
574 | 579 |
memset(to_b, 0, sizeof(struct to_body)); |
575 |
- to_b->error=PARSE_OK; |
|
576 |
- foo=0; |
|
580 |
+ to_b->error = PARSE_OK; |
|
581 |
+ foo = 0; |
|
577 | 582 |
|
578 |
- for( tmp=buffer; tmp<end; tmp++) |
|
579 |
- { |
|
580 |
- switch(*tmp) |
|
581 |
- { |
|
583 |
+ for(tmp = buffer; tmp < end; tmp++) { |
|
584 |
+ switch(*tmp) { |
|
582 | 585 |
case ' ': |
583 | 586 |
case '\t': |
584 |
- switch (status) |
|
585 |
- { |
|
587 |
+ switch(status) { |
|
586 | 588 |
case F_CRLF: |
587 | 589 |
case F_LF: |
588 | 590 |
case F_CR: |
589 | 591 |
/*previous=crlf and now =' '*/ |
590 |
- status=saved_status; |
|
592 |
+ status = saved_status; |
|
591 | 593 |
break; |
592 | 594 |
case URI_ENCLOSED: |
593 | 595 |
to_b->uri.len = tmp - to_b->uri.s; |
... | ... |
@@ -604,8 +606,7 @@ char* parse_addr_spec(char* const buffer, const char* const end, |
604 | 606 |
} |
605 | 607 |
break; |
606 | 608 |
case '\n': |
607 |
- switch (status) |
|
608 |
- { |
|
609 |
+ switch(status) { |
|
609 | 610 |
case URI_OR_TOKEN: |
610 | 611 |
foo = tmp; |
611 | 612 |
status = MAYBE_URI_END; |
... | ... |
@@ -613,30 +614,29 @@ char* parse_addr_spec(char* const buffer, const char* const end, |
613 | 614 |
case DISPLAY_TOKEN_SP: |
614 | 615 |
case E_DISPLAY_QUOTED: |
615 | 616 |
case END: |
616 |
- saved_status=status; |
|
617 |
- status=F_LF; |
|
617 |
+ saved_status = status; |
|
618 |
+ status = F_LF; |
|
618 | 619 |
break; |
619 | 620 |
case DISPLAY_TOKEN: |
620 |
- foo=tmp; |
|
621 |
- saved_status=DISPLAY_TOKEN_SP; |
|
622 |
- status=F_LF; |
|
621 |
+ foo = tmp; |
|
622 |
+ saved_status = DISPLAY_TOKEN_SP; |
|
623 |
+ status = F_LF; |
|
623 | 624 |
break; |
624 | 625 |
case F_CR: |
625 |
- status=F_CRLF; |
|
626 |
+ status = F_CRLF; |
|
626 | 627 |
break; |
627 | 628 |
case F_CRLF: |
628 | 629 |
case F_LF: |
629 |
- status=saved_status; |
|
630 |
+ status = saved_status; |
|
630 | 631 |
goto endofheader; |
631 | 632 |
default: |
632 | 633 |
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
633 |
- *tmp,status, (int)(tmp-buffer), ZSW(buffer)); |
|
634 |
+ *tmp, status, (int)(tmp - buffer), ZSW(buffer)); |
|
634 | 635 |
goto error; |
635 | 636 |
} |
636 | 637 |
break; |
637 | 638 |
case '\r': |
638 |
- switch (status) |
|
639 |
- { |
|
639 |
+ switch(status) { |
|
640 | 640 |
case URI_OR_TOKEN: |
641 | 641 |
foo = tmp; |
642 | 642 |
status = MAYBE_URI_END; |
... | ... |
@@ -644,28 +644,27 @@ char* parse_addr_spec(char* const buffer, const char* const end, |
644 | 644 |
case DISPLAY_TOKEN_SP: |
645 | 645 |
case E_DISPLAY_QUOTED: |
646 | 646 |
case END: |
647 |
- saved_status=status; |
|
648 |
- status=F_CR; |
|
647 |
+ saved_status = status; |
|
648 |
+ status = F_CR; |
|
649 | 649 |
break; |
650 | 650 |
case DISPLAY_TOKEN: |
651 |
- foo=tmp; |
|
652 |
- saved_status=DISPLAY_TOKEN_SP; |
|
653 |
- status=F_CR; |
|
651 |
+ foo = tmp; |
|
652 |
+ saved_status = DISPLAY_TOKEN_SP; |
|
653 |
+ status = F_CR; |
|
654 | 654 |
break; |
655 | 655 |
case F_CRLF: |
656 | 656 |
case F_CR: |
657 | 657 |
case F_LF: |
658 |
- status=saved_status; |
|
658 |
+ status = saved_status; |
|
659 | 659 |
goto endofheader; |
660 | 660 |
default: |
661 | 661 |
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
662 |
- *tmp,status, (int)(tmp-buffer), ZSW(buffer)); |
|
662 |
+ *tmp, status, (int)(tmp - buffer), ZSW(buffer)); |
|
663 | 663 |
goto error; |
664 | 664 |
} |
665 | 665 |
break; |
666 | 666 |
case 0: |
667 |
- switch (status) |
|
668 |
- { |
|
667 |
+ switch(status) { |
|
669 | 668 |
case URI_OR_TOKEN: |
670 | 669 |
case MAYBE_URI_END: |
671 | 670 |
to_b->uri.len = tmp - to_b->uri.s; |
... | ... |
@@ -674,27 +673,25 @@ char* parse_addr_spec(char* const buffer, const char* const end, |
674 | 673 |
goto endofheader; |
675 | 674 |
default: |
676 | 675 |
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
677 |
- *tmp,status, (int)(tmp-buffer), ZSW(buffer)); |
|
676 |
+ *tmp, status, (int)(tmp - buffer), ZSW(buffer)); |
|
678 | 677 |
goto error; |
679 | 678 |
} |
680 | 679 |
break; |
681 | 680 |
case '\\': |
682 |
- switch (status) |
|
683 |
- { |
|
681 |
+ switch(status) { |
|
684 | 682 |
case DISPLAY_QUOTED: |
685 | 683 |
tmp++; /* jump over next char */ |
686 | 684 |
break; |
687 | 685 |
default: |
688 | 686 |
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
689 |
- *tmp,status, (int)(tmp-buffer), ZSW(buffer)); |
|
687 |
+ *tmp, status, (int)(tmp - buffer), ZSW(buffer)); |
|
690 | 688 |
goto error; |
691 | 689 |
} |
692 | 690 |
break; |
693 | 691 |
case '<': |
694 |
- switch (status) |
|
695 |
- { |
|
692 |
+ switch(status) { |
|
696 | 693 |
case START_TO: |
697 |
- to_b->body.s=tmp; |
|
694 |
+ to_b->body.s = tmp; |
|
698 | 695 |
status = S_URI_ENCLOSED; |
699 | 696 |
break; |
700 | 697 |
case DISPLAY_QUOTED: |
... | ... |
@@ -704,12 +701,12 @@ char* parse_addr_spec(char* const buffer, const char* const end, |
704 | 701 |
break; |
705 | 702 |
case URI_OR_TOKEN: |
706 | 703 |
case DISPLAY_TOKEN: |
707 |
- to_b->display.len=tmp-to_b->display.s; |
|
704 |
+ to_b->display.len = tmp - to_b->display.s; |
|
708 | 705 |
status = S_URI_ENCLOSED; |
709 | 706 |
break; |
710 | 707 |
case DISPLAY_TOKEN_SP: |
711 | 708 |
case MAYBE_URI_END: |
712 |
- to_b->display.len=foo-to_b->display.s; |
|
709 |
+ to_b->display.len = foo - to_b->display.s; |
|
713 | 710 |
status = S_URI_ENCLOSED; |
714 | 711 |
break; |
715 | 712 |
case F_CRLF: |
... | ... |
@@ -719,13 +716,12 @@ char* parse_addr_spec(char* const buffer, const char* const end, |
719 | 716 |
goto endofheader; |
720 | 717 |
default: |
721 | 718 |
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
722 |
- *tmp,status, (int)(tmp-buffer), ZSW(buffer)); |
|
719 |
+ *tmp, status, (int)(tmp - buffer), ZSW(buffer)); |
|
723 | 720 |
goto error; |
724 | 721 |
} |
725 | 722 |
break; |
726 | 723 |
case '>': |
727 |
- switch (status) |
|
728 |
- { |
|
724 |
+ switch(status) { |
|
729 | 725 |
case DISPLAY_QUOTED: |
730 | 726 |
break; |
731 | 727 |
case URI_ENCLOSED: |
... | ... |
@@ -741,13 +737,12 @@ char* parse_addr_spec(char* const buffer, const char* const end, |
741 | 737 |
goto endofheader; |
742 | 738 |
default: |
743 | 739 |
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
744 |
- *tmp,status, (int)(tmp-buffer), ZSW(buffer)); |
|
740 |
+ *tmp, status, (int)(tmp - buffer), ZSW(buffer)); |
|
745 | 741 |
goto error; |
746 | 742 |
} |
747 | 743 |
break; |
748 | 744 |
case '"': |
749 |
- switch (status) |
|
750 |
- { |
|
745 |
+ switch(status) { |
|
751 | 746 |
case START_TO: |
752 | 747 |
to_b->body.s = tmp; |
753 | 748 |
to_b->display.s = tmp; |
... | ... |
@@ -755,7 +750,7 @@ char* parse_addr_spec(char* const buffer, const char* const end, |
755 | 750 |
break; |
756 | 751 |
case DISPLAY_QUOTED: |
757 | 752 |
status = E_DISPLAY_QUOTED; |
758 |
- to_b->display.len = tmp-to_b->display.s+1; |
|
753 |
+ to_b->display.len = tmp - to_b->display.s + 1; |
|
759 | 754 |
break; |
760 | 755 |
case F_CRLF: |
761 | 756 |
case F_LF: |
... | ... |
@@ -764,13 +759,12 @@ char* parse_addr_spec(char* const buffer, const char* const end, |
764 | 759 |
goto endofheader; |
765 | 760 |
default: |
766 | 761 |
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
767 |
- *tmp,status, (int)(tmp-buffer), buffer); |
|
762 |
+ *tmp, status, (int)(tmp - buffer), buffer); |
|
768 | 763 |
goto error; |
769 | 764 |
} |
770 | 765 |
break; |
771 |
- case ';' : |
|
772 |
- switch (status) |
|
773 |
- { |
|
766 |
+ case ';': |
|
767 |
+ switch(status) { |
|
774 | 768 |
case DISPLAY_QUOTED: |
775 | 769 |
case URI_ENCLOSED: |
776 | 770 |
break; |
... | ... |
@@ -779,8 +773,9 @@ char* parse_addr_spec(char* const buffer, const char* const end, |
779 | 773 |
case MAYBE_URI_END: |
780 | 774 |
to_b->uri.len = foo - to_b->uri.s; |
781 | 775 |
case END: |
782 |
- to_b->body.len = tmp-to_b->body.s; |
|
783 |
- tmp = parse_to_param(tmp,end,to_b,allow_comma_sep,&saved_status); |
|
776 |
+ to_b->body.len = tmp - to_b->body.s; |
|
777 |
+ tmp = parse_to_param( |
|
778 |
+ tmp, end, to_b, allow_comma_sep, &saved_status); |
|
784 | 779 |
goto endofheader; |
785 | 780 |
case F_CRLF: |
786 | 781 |
case F_LF: |
... | ... |
@@ -789,15 +784,13 @@ char* parse_addr_spec(char* const buffer, const char* const end, |
789 | 784 |
goto endofheader; |
790 | 785 |
default: |
791 | 786 |
LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
792 |
- *tmp,status, (int)(tmp-buffer), buffer); |
|
787 |
+ *tmp, status, (int)(tmp - buffer), buffer); |
|
793 | 788 |
goto error; |
794 | 789 |
} |
795 | 790 |
break; |
796 |
- case ',' : |
|
797 |
- if (allow_comma_sep) |
|
798 |
- { |
|
799 |
- switch (status) |
|
800 |
- { |
|
791 |
+ case ',': |
|
792 |
+ if(allow_comma_sep) { |
|
793 |
+ switch(status) { |
|
801 | 794 |
case DISPLAY_QUOTED: |
802 | 795 |
case URI_ENCLOSED: |
803 | 796 |
break; |
... | ... |
@@ -806,7 +799,7 @@ char* parse_addr_spec(char* const buffer, const char* const end, |
806 | 799 |
case MAYBE_URI_END: |
807 | 800 |
to_b->uri.len = foo - to_b->uri.s; |
808 | 801 |
case END: |
809 |
- to_b->body.len = tmp-to_b->body.s; |
|
802 |
+ to_b->body.len = tmp - to_b->body.s; |
|
810 | 803 |
saved_status = END; |
811 | 804 |
goto endofheader; |
812 | 805 |
case F_CRLF: |
... | ... |
@@ -815,24 +808,24 @@ char* parse_addr_spec(char* const buffer, const char* const end, |
815 | 808 |
/*previous=crlf and now !=' '*/ |
816 | 809 |
goto endofheader; |
817 | 810 |
default: |
818 |
- LM_ERR("unexpected char [%c] in status %d: [%.*s] .\n", |
|
819 |
- *tmp,status, (int)(tmp-buffer), buffer); |
|
811 |
+ LM_ERR("unexpected char [%c] in status %d: [%.*s] " |
|
812 |
+ ".\n", |
|
813 |
+ *tmp, status, (int)(tmp - buffer), buffer); |
|
820 | 814 |
goto error; |
821 | 815 |
} |
822 | 816 |
break; |
823 | 817 |
} |
824 |
- /* If commas not allowed treat as a default character */ |
|
818 |
+ /* If commas not allowed treat as a default character */ |
|
825 | 819 |
default: |
826 |
- switch (status) |
|
827 |
- { |
|
820 |
+ switch(status) { |
|
828 | 821 |
case START_TO: |
829 | 822 |
to_b->uri.s = to_b->body.s = tmp; |
830 | 823 |
status = URI_OR_TOKEN; |
831 |
- to_b->display.s=tmp; |
|
824 |
+ to_b->display.s = tmp; |
|
832 | 825 |
break; |
833 | 826 |
case S_URI_ENCLOSED: |
834 |
- to_b->uri.s=tmp; |
|
835 |
- status=URI_ENCLOSED; |
|
827 |
+ to_b->uri.s = tmp; |
|
828 |
+ status = URI_ENCLOSED; |
|
836 | 829 |
break; |
837 | 830 |
case MAYBE_URI_END: |
838 | 831 |
case DISPLAY_TOKEN_SP: |
... | ... |
@@ -848,16 +841,15 @@ char* parse_addr_spec(char* const buffer, const char* const end, |
848 | 841 |
/*previous=crlf and now !=' '*/ |
849 | 842 |
goto endofheader; |
850 | 843 |
default: |
851 |
- LM_DBG("spitting out [%c] in status %d\n", |
|
852 |
- *tmp,status ); |
|
844 |
+ LM_DBG("spitting out [%c] in status %d\n", *tmp, |
|
845 |
+ status); |
|
853 | 846 |
goto error; |
854 | 847 |
} |
855 |
- }/*char switch*/ |
|
856 |
- }/*for*/ |
|
848 |
+ } /*char switch*/ |
|
849 |
+ } /*for*/ |
|
857 | 850 |
|
858 | 851 |
/* Reached end of buffer */ |
859 |
- switch (status) |
|
860 |
- { |
|
852 |
+ switch(status) { |
|
861 | 853 |
case URI_OR_TOKEN: |
862 | 854 |
case MAYBE_URI_END: |
863 | 855 |
case END: |
... | ... |
@@ -866,11 +858,12 @@ char* parse_addr_spec(char* const buffer, const char* const end, |
866 | 858 |
} |
867 | 859 |
|
868 | 860 |
endofheader: |
869 |
- if (to_b->display.len==0) to_b->display.s=0; |
|
870 |
- status=saved_status; |
|
861 |
+ if(to_b->display.len == 0) |
|
862 |
+ to_b->display.s = 0; |
|
863 |
+ status = saved_status; |
|
871 | 864 |
LM_DBG("end of header reached, state=%d\n", status); |
872 | 865 |
/* check if error*/ |
873 |
- switch(status){ |
|
866 |
+ switch(status) { |
|
874 | 867 |
case URI_OR_TOKEN: |
875 | 868 |
case MAYBE_URI_END: |
876 | 869 |
to_b->uri.len = foo - to_b->uri.s; |
... | ... |
@@ -880,35 +873,34 @@ endofheader: |
880 | 873 |
break; |
881 | 874 |
default: |
882 | 875 |
LM_ERR("invalid To - unexpected " |
883 |
- "end of header in state %d\n", status); |
|
876 |
+ "end of header in state %d\n", |
|
877 |
+ status); |
|
884 | 878 |
goto error; |
885 | 879 |
} |
886 | 880 |
return tmp; |
887 | 881 |
|
888 | 882 |
error: |
889 | 883 |
free_to_params(to_b); |
890 |
- to_b->error=PARSE_ERROR; |
|
884 |
+ to_b->error = PARSE_ERROR; |
|
891 | 885 |
return tmp; |
892 |
- |
|
893 | 886 |
} |
894 | 887 |
|
895 | 888 |
|
896 |
-void free_to_params(struct to_body* const tb) |
|
889 |
+void free_to_params(struct to_body *const tb) |
|
897 | 890 |
{ |
898 |
- struct to_param *tp=tb->param_lst; |
|
891 |
+ struct to_param *tp = tb->param_lst; |
|
899 | 892 |
struct to_param *foo; |
900 |
- while (tp){ |
|
893 |
+ while(tp) { |
|
901 | 894 |
foo = tp->next; |
902 | 895 |
pkg_free(tp); |
903 |
- tp=foo; |
|
896 |
+ tp = foo; |
|
904 | 897 |
} |
905 | 898 |
tb->param_lst = NULL; |
906 | 899 |
} |
907 | 900 |
|
908 | 901 |
|
909 |
-void free_to(struct to_body* const tb) |
|
902 |
+void free_to(struct to_body *const tb) |
|
910 | 903 |
{ |
911 | 904 |
free_to_params(tb); |
912 | 905 |
pkg_free(tb); |
913 | 906 |
} |
914 |
- |
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-/* |
|
1 |
+/* |
|
2 | 2 |
* Copyright (C) 2001-2003 FhG Fokus |
3 | 3 |
* |
4 | 4 |
* This file is part of Kamailio, a free SIP server. |
... | ... |
@@ -13,10 +13,10 @@ |
13 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | 14 |
* GNU General Public License for more details. |
15 | 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 |
|
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 | 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 |
- * |
|
19 |
+ * |
|
20 | 20 |
*/ |
21 | 21 |
|
22 | 22 |
/*! \file |
... | ... |
@@ -26,77 +26,75 @@ |
26 | 26 |
*/ |
27 | 27 |
|
28 | 28 |
|
29 |
- |
|
30 | 29 |
#include "../comp_defs.h" |
31 | 30 |
#include "parse_cseq.h" |
32 |
-#include "parser_f.h" /* eat_space_end and so on */ |
|
31 |
+#include "parser_f.h" /* eat_space_end and so on */ |
|
33 | 32 |
#include "../dprint.h" |
34 | 33 |
#include "parse_def.h" |
35 | 34 |
#include "parse_methods.h" |
36 | 35 |
#include "../mem/mem.h" |
37 | 36 |
|
38 |
-/*BUGGY*/ |
|
39 |
-char* parse_cseq(char* const buf, const char* const end, struct cseq_body* const cb) |
|
37 |
+/* parse cseq header */ |
|
38 |
+char *parse_cseq(char *const buf, const char *const end, |
|
39 |
+ struct cseq_body *const cb) |
|
40 | 40 |
{ |
41 | 41 |
char *t, *m, *m_end; |
42 |
- |
|
43 |
- cb->error=PARSE_ERROR; |
|
44 |
- t=buf; |
|
45 |
- |
|
46 |
- cb->number.s=t; |
|
47 |
- t=eat_token_end(t, end); |
|
48 |
- if (t>=end) goto error; |
|
49 |
- cb->number.len=t-cb->number.s; |
|
50 | 42 |
|
51 |
- m=eat_space_end(t, end); |
|
52 |
- m_end=eat_token_end(m, end); |
|
43 |
+ cb->error = PARSE_ERROR; |
|
44 |
+ t = buf; |
|
45 |
+ |
|
46 |
+ cb->number.s = t; |
|
47 |
+ t = eat_token_end(t, end); |
|
48 |
+ if(t >= end) |
|
49 |
+ goto error; |
|
50 |
+ cb->number.len = t - cb->number.s; |
|
51 |
+ |
|
52 |
+ m = eat_space_end(t, end); |
|
53 |
+ m_end = eat_token_end(m, end); |
|
53 | 54 |
|
54 |
- if (m_end>=end) { |
|
55 |
- LOG(L_ERR, "ERROR: parse_cseq: " |
|
56 |
- "method terminated unexpectedly\n"); |
|
57 |
- goto error; |
|
55 |
+ if(m_end >= end) { |
|
56 |
+ LM_ERR("method terminated unexpectedly\n"); |
|
57 |
+ goto error; |
|
58 | 58 |
} |
59 |
- if (m_end==m){ |
|
59 |
+ if(m_end == m) { |
|
60 | 60 |
/* null method*/ |
61 |
- LOG(L_ERR, "ERROR:parse_cseq: no method found\n"); |
|
61 |
+ LM_ERR("no method found\n"); |
|
62 | 62 |
goto error; |
63 | 63 |
} |
64 |
- cb->method.s=m; |
|
65 |
- t=m_end; |
|
66 |
- cb->method.len=t-cb->method.s; |
|
64 |
+ cb->method.s = m; |
|
65 |
+ t = m_end; |
|
66 |
+ cb->method.len = t - cb->method.s; |
|
67 | 67 |
|
68 | 68 |
/* Cache method id */ |
69 |
- if (parse_method_name(&cb->method, &cb->method_id)!=0){ |
|
70 |
- LOG(L_ERR, "Cannot parse method string\n"); |
|
69 |
+ if(parse_method_name(&cb->method, &cb->method_id) != 0) { |
|
70 |
+ LM_ERR("Cannot parse method string\n"); |
|
71 | 71 |
goto error; |
72 | 72 |
} |
73 | 73 |
|
74 |
- /* there may be trailing LWS |
|
75 |
- * (it was not my idea to put it in SIP; -jiri ) |
|
76 |
- */ |
|
77 |
- t=eat_lws_end(t, end); |
|
74 |
+ /* there may be trailing LWS */ |
|
75 |
+ t = eat_lws_end(t, end); |
|
78 | 76 |
/*check if the header ends here*/ |
79 |
- if (t>=end) { |
|
80 |
- LOG(L_ERR, "ERROR: parse_cseq: strange EoHF\n"); |
|
77 |
+ if(t >= end) { |
|
78 |
+ LM_ERR("strange EoHF\n"); |
|
81 | 79 |
goto error; |
82 | 80 |
} |
83 |
- if (*t=='\r' && t+1<end && *(t+1)=='\n') { |
|
84 |
- cb->error=PARSE_OK; |
|
85 |
- return t+2; |
|
81 |
+ if(*t == '\r' && t + 1 < end && *(t + 1) == '\n') { |
|
82 |
+ cb->error = PARSE_OK; |
|
83 |
+ return t + 2; |
|
86 | 84 |
} |
87 |
- if (*t=='\n') { |
|
88 |
- cb->error=PARSE_OK; |
|
89 |
- return t+1; |
|
85 |
+ if(*t == '\n') { |
|
86 |
+ cb->error = PARSE_OK; |
|
87 |
+ return t + 1; |
|
90 | 88 |
} |
91 |
- LOG(L_ERR, "ERROR: CSeq EoL expected\n"); |
|
89 |
+ LM_ERR("CSeq EoL expected\n"); |
|
92 | 90 |
|
93 | 91 |
error: |
94 |
- LOG(L_ERR, "ERROR: parse_cseq: bad cseq\n"); |
|
92 |
+ LM_ERR("bad cseq\n"); |
|
95 | 93 |
return t; |
96 | 94 |
} |
97 | 95 |
|
98 | 96 |
|
99 |
-void free_cseq(struct cseq_body* const cb) |
|
97 |
+void free_cseq(struct cseq_body *const cb) |
|
100 | 98 |
{ |
101 | 99 |
pkg_free(cb); |
102 | 100 |
} |
... | ... |
@@ -13,8 +13,8 @@ |
13 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | 14 |
* GNU General Public License for more details. |
15 | 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 |
|
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 | 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | 19 |
*/ |
20 | 20 |
|
... | ... |
@@ -38,40 +38,41 @@ |
38 | 38 |
* This method is used to parse the from header. |
39 | 39 |
* |
40 | 40 |
* \note It was decided not to parse |
41 |
- * anything in core that is not *needed* so this method gets called by |
|
41 |
+ * anything in core that is not *needed* so this method gets called by |
|
42 | 42 |
* rad_acc module and any other modules that needs the FROM header. |
43 | 43 |
* |
44 | 44 |
* params: msg : sip msg |
45 | 45 |
* returns 0 on success, |
46 | 46 |
* -1 on failure. |
47 | 47 |
*/ |
48 |
-int parse_from_header( struct sip_msg *msg) |
|
48 |
+int parse_from_header(struct sip_msg *msg) |
|
49 | 49 |
{ |
50 |
- struct to_body* from_b; |
|
50 |
+ struct to_body *from_b; |
|
51 | 51 |
|
52 |
- if ( !msg->from && ( parse_headers(msg,HDR_FROM_F,0)==-1 || !msg->from)) { |
|
53 |
- LOG(L_ERR,"ERROR:parse_from_header: bad msg or missing FROM header\n"); |
|
52 |
+ if(!msg->from && (parse_headers(msg, HDR_FROM_F, 0) == -1 || !msg->from)) { |
|
53 |
+ LM_ERR("bad msg or missing FROM header\n"); |
|
54 | 54 |
goto error; |
55 | 55 |
} |
56 | 56 |
|
57 | 57 |
/* maybe the header is already parsed! */ |
58 |
- if (msg->from->parsed) |
|
58 |
+ if(msg->from->parsed) |
|
59 | 59 |
return 0; |
60 | 60 |
|
61 | 61 |
/* bad luck! :-( - we have to parse it */ |
62 | 62 |
/* first, get some memory */ |
63 | 63 |
from_b = pkg_malloc(sizeof(struct to_body)); |
64 |
- if (from_b == 0) { |
|
65 |
- LOG(L_ERR, "ERROR:parse_from_header: out of pkg_memory\n"); |
|
64 |
+ if(from_b == 0) { |
|
65 |
+ LM_ERR("out of pkg_memory\n"); |
|
66 | 66 |
goto error; |
67 | 67 |
} |
68 | 68 |
|
69 | 69 |
/* now parse it!! */ |
70 | 70 |
memset(from_b, 0, sizeof(struct to_body)); |
71 |
- parse_to(msg->from->body.s,msg->from->body.s+msg->from->body.len+1,from_b); |
|
72 |
- if (from_b->error == PARSE_ERROR) { |
|
73 |
- LOG(L_ERR, "ERROR:parse_from_header: bad from header [%.*s]\n", |
|
74 |
- msg->from->body.len, msg->from->body.s); |
|
71 |
+ parse_to(msg->from->body.s, msg->from->body.s + msg->from->body.len + 1, |
|
72 |
+ from_b); |
|
73 |
+ if(from_b->error == PARSE_ERROR) { |
|
74 |
+ LM_ERR("bad From header [%.*s]\n", msg->from->body.len, |
|
75 |
+ msg->from->body.s); |
|
75 | 76 |
free_to(from_b); |
76 | 77 |
goto error; |
77 | 78 |
} |
... | ... |
@@ -85,26 +86,24 @@ error: |
85 | 86 |
sip_uri_t *parse_from_uri(sip_msg_t *msg) |
86 | 87 |
{ |
87 | 88 |
to_body_t *tb = NULL; |
88 |
- |
|
89 |
- if(msg==NULL) |
|
89 |
+ |
|
90 |
+ if(msg == NULL) |
|
90 | 91 |
return NULL; |
91 | 92 |
|
92 |
- if(parse_from_header(msg)<0) |
|
93 |
- { |
|
93 |
+ if(parse_from_header(msg) < 0) { |
|
94 | 94 |
LM_ERR("cannot parse FROM header\n"); |
95 | 95 |
return NULL; |
96 | 96 |
} |
97 |
- |
|
98 |
- if(msg->from==NULL || get_from(msg)==NULL) |
|
97 |
+ |
|
98 |
+ if(msg->from == NULL || get_from(msg) == NULL) |
|
99 | 99 |
return NULL; |
100 | 100 |
|
101 | 101 |
tb = get_from(msg); |
102 |
- |
|
103 |
- if(tb->parsed_uri.user.s!=NULL || tb->parsed_uri.host.s!=NULL) |
|
102 |
+ |
|
103 |
+ if(tb->parsed_uri.user.s != NULL || tb->parsed_uri.host.s != NULL) |
|
104 | 104 |
return &tb->parsed_uri; |
105 |
- |
|
106 |
- if (parse_uri(tb->uri.s, tb->uri.len , &tb->parsed_uri)<0) |
|
107 |
- { |
|
105 |
+ |
|
106 |
+ if(parse_uri(tb->uri.s, tb->uri.len, &tb->parsed_uri) < 0) { |
|
108 | 107 |
LM_ERR("failed to parse From uri\n"); |
109 | 108 |
memset(&tb->parsed_uri, 0, sizeof(struct sip_uri)); |
110 | 109 |
return NULL; |
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-/* |
|
1 |
+/* |
|
2 | 2 |
* Generic Parameter Parser |
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2001-2003 FhG Fokus |
... | ... |
@@ -15,8 +15,8 @@ |
15 | 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | 16 |
* GNU General Public License for more details. |
17 | 17 |
* |
18 |
- * You should have received a copy of the GNU General Public License |
|
19 |
- * along with this program; if not, write to the Free Software |
|
18 |
+ * You should have received a copy of the GNU General Public License |
|
19 |
+ * along with this program; if not, write to the Free Software |
|
20 | 20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21 | 21 |
* |
22 | 22 |
*/ |
... | ... |
@@ -37,71 +37,70 @@ |
37 | 37 |
#include "parse_param.h" |
38 | 38 |
|
39 | 39 |
|
40 |
-static inline void parse_event_dialog_class(param_hooks_t* h, param_t* p) |
|
40 |
+static inline void parse_event_dialog_class(param_hooks_t *h, param_t *p) |
|
41 | 41 |
{ |
42 | 42 |
|
43 |
- if (!p->name.s) { |
|
44 |
- LOG(L_ERR, "ERROR: parse_event_dialog_class: empty value\n"); |
|
43 |
+ if(!p->name.s) { |
|
44 |
+ LM_ERR("empty value\n"); |
|
45 | 45 |
return; |
46 | 46 |
} |
47 |
- if (!h) { |
|
48 |
- LOG(L_CRIT, "BUG: parse_event_dialog_class: NULL param hook pointer\n"); |
|
47 |
+ if(!h) { |
|
48 |
+ LM_CRIT("BUG: NULL param hook pointer\n"); |
|
49 | 49 |
return; |
50 | 50 |
} |
51 | 51 |
switch(p->name.s[0]) { |
52 |
- case 'c': |
|
53 |
- case 'C': |
|
54 |
- if ((p->name.len == 7) && |
|
55 |
- (!strncasecmp(p->name.s + 1, "all-id", 6))) { |
|
56 |
- p->type = P_CALL_ID; |
|
57 |
- h->event_dialog.call_id = p; |
|
58 |
- } |
|
59 |
- break; |
|
60 |
- |
|
61 |
- case 'f': |
|
62 |
- case 'F': |
|
63 |
- if ((p->name.len == 8) && |
|
64 |
- (!strncasecmp(p->name.s + 1, "rom-tag", 7))) { |
|
65 |
- p->type = P_FROM_TAG; |
|
66 |
- h->event_dialog.from_tag = p; |
|
67 |
- } |
|
68 |
- break; |
|
69 |
- |
|
70 |
- case 't': |
|
71 |
- case 'T': |
|
72 |
- if ((p->name.len == 6) && |
|
73 |
- (!strncasecmp(p->name.s + 1, "o-tag", 5))) { |
|
74 |
- p->type = P_TO_TAG; |
|
75 |
- h->event_dialog.to_tag = p; |
|
76 |
- } |
|
77 |
- break; |
|
78 |
- |
|
79 |
- case 'i': |
|
80 |
- case 'I': |
|
81 |
- if ((p->name.len == 27) && |
|
82 |
- (!strncasecmp(p->name.s + 1, "nclude-session-description", 26))) { |
|
83 |
- p->type = P_ISD; |
|
84 |
- h->event_dialog.include_session_description = p; |
|
85 |
- } |
|
86 |
- break; |
|
87 |
- |
|
88 |
- case 's': |
|
89 |
- case 'S': |
|
90 |
- if ((p->name.len == 3) && |
|
91 |
- (!strncasecmp(p->name.s + 1, "la", 2))) { |
|
92 |
- p->type = P_SLA; |
|
93 |
- h->event_dialog.sla = p; |
|
94 |
- } |
|
95 |
- break; |
|
96 |
- |
|
97 |
- case 'm': |
|
98 |
- case 'M': |
|
99 |
- if ((p->name.len == 2) && |
|
100 |
- (!strncasecmp(p->name.s + 1, "a", 1))) { |
|
101 |
- p->type = P_MA; |
|
102 |
- h->event_dialog.ma = p; |
|
103 |
- } |
|
104 |
- break; |
|
52 |
+ case 'c': |
|
53 |
+ case 'C': |
|
54 |
+ if((p->name.len == 7) |
|
55 |
+ && (!strncasecmp(p->name.s + 1, "all-id", 6))) { |
|
56 |
+ p->type = P_CALL_ID; |
|
57 |
+ h->event_dialog.call_id = p; |
|
58 |
+ } |
|
59 |
+ break; |
|
60 |
+ |
|
61 |
+ case 'f': |
|
62 |
+ case 'F': |
|
63 |
+ if((p->name.len == 8) |
|
64 |
+ && (!strncasecmp(p->name.s + 1, "rom-tag", 7))) { |
|
65 |
+ p->type = P_FROM_TAG; |
|
66 |
+ h->event_dialog.from_tag = p; |
|
67 |
+ } |
|
68 |
+ break; |
|
69 |
+ |
|
70 |
+ case 't': |
|
71 |
+ case 'T': |
|
72 |
+ if((p->name.len == 6) |
|
73 |
+ && (!strncasecmp(p->name.s + 1, "o-tag", 5))) { |
|
74 |
+ p->type = P_TO_TAG; |
|
75 |
+ h->event_dialog.to_tag = p; |
|
76 |
+ } |
|
77 |
+ break; |
|
78 |
+ |
|
79 |
+ case 'i': |
|
80 |
+ case 'I': |
|
81 |
+ if((p->name.len == 27) |
|
82 |
+ && (!strncasecmp(p->name.s + 1, |
|
83 |
+ "nclude-session-description", 26))) { |
|
84 |
+ p->type = P_ISD; |
|
85 |
+ h->event_dialog.include_session_description = p; |
|
86 |
+ } |
|
87 |
+ break; |
|
88 |
+ |
|
89 |
+ case 's': |
|
90 |
+ case 'S': |
|
91 |
+ if((p->name.len == 3) && (!strncasecmp(p->name.s + 1, "la", 2))) { |
|
92 |
+ p->type = P_SLA; |
|
93 |
+ h->event_dialog.sla = p; |
|
94 |
+ } |
|
95 |
+ break; |
|
96 |
+ |
|
97 |
+ case 'm': |
|
98 |
+ case 'M': |
|
99 |
+ if((p->name.len == 2) && (!strncasecmp(p->name.s + 1, "a", 1))) { |
|
100 |
+ p->type = P_MA; |
|
101 |
+ h->event_dialog.ma = p; |
|
102 |
+ } |
|
103 |
+ break; |
|
105 | 104 |
} |
106 | 105 |
} |
107 | 106 |
|
... | ... |
@@ -110,71 +109,70 @@ static inline void parse_event_dialog_class(param_hooks_t* h, param_t* p) |
110 | 109 |
* Try to find out parameter name, recognized parameters |
111 | 110 |
* are q, expires and methods |
112 | 111 |
*/ |
113 |
-static inline void parse_contact_class(param_hooks_t* _h, param_t* _p) |
|
112 |
+static inline void parse_contact_class(param_hooks_t *_h, param_t *_p) |
|
114 | 113 |
{ |
115 | 114 |
|
116 |
- if (!_p->name.s) { |
|
117 |
- LOG(L_ERR, "ERROR: parse_contact_class: empty value\n"); |
|
115 |
+ if(!_p->name.s) { |
|
116 |
+ LM_ERR("empty value\n"); |
|
118 | 117 |
return; |
119 | 118 |
} |
120 |
- if (!_h) { |
|
121 |
- LOG(L_CRIT, "BUG: parse_contact_class: NULL param hook pointer\n"); |
|
119 |
+ if(!_h) { |
|
120 |
+ LM_CRIT("BUG: NULL param hook pointer\n"); |
|
122 | 121 |
return; |
123 | 122 |
} |
124 | 123 |
switch(_p->name.s[0]) { |
125 |
- case 'q': |
|
126 |
- case 'Q': |
|
127 |
- if (_p->name.len == 1) { |
|
128 |
- _p->type = P_Q; |
|
129 |
- _h->contact.q = _p; |
|
130 |
- } |
|
131 |
- break; |
|
132 |
- |
|
133 |
- case 'e': |
|
134 |
- case 'E': |
|
135 |
- if ((_p->name.len == 7) && |
|
136 |
- (!strncasecmp(_p->name.s + 1, "xpires", 6))) { |
|
137 |
- _p->type = P_EXPIRES; |
|
138 |
- _h->contact.expires = _p; |
|
139 |
- } |
|
140 |
- break; |
|
141 |
- |
|
142 |
- case 'm': |
|
143 |
- case 'M': |
|
144 |
- if ((_p->name.len == 7) && |
|
145 |
- (!strncasecmp(_p->name.s + 1, "ethods", 6))) { |
|
146 |
- _p->type = P_METHODS; |
|
147 |
- _h->contact.methods = _p; |
|
148 |
- } |
|
149 |
- break; |
|
150 |
- |
|
151 |
- case 'r': |
|
152 |
- case 'R': |
|
153 |
- if ((_p->name.len == 8) && |
|
154 |
- (!strncasecmp(_p->name.s + 1, "eceived", 7))) { |
|
155 |
- _p->type = P_RECEIVED; |
|
156 |
- _h->contact.received = _p; |
|
157 |
- } else if((_p->name.len == 6) && |
|
158 |
- (!strncasecmp(_p->name.s + 1, "eg-id", 5))) { |
|
159 |
- _p->type = P_REG_ID; |
|
160 |
- _h->contact.reg_id = _p; |
|
161 |
- } |
|
162 |
- break; |
|