Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,555 +0,0 @@
1
-/*
2
- * Copyright (C) 2001-2003 FhG Fokus
3
- *
4
- * This file is part of Kamailio, a free SIP server.
5
- *
6
- * Kamailio 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
- * Kamailio 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
- */
21
-
22
-/*! \file
23
- * \brief Parser :: Content part
24
- *
25
- * \ingroup parser
26
- */
27
-
28
-
29
-#include <stdio.h>
30
-#include <stdlib.h>
31
-#include <sys/types.h>
32
-#include <unistd.h>
33
-#include "../mem/mem.h"
34
-#include "../dprint.h"
35
-#include "../str.h"
36
-#include "../ut.h"
37
-#include "parse_content.h"
38
-
39
-
40
-#define is_mime_char(_c_) \
41
-	(isalpha((int)_c_) || (_c_)=='-' || (_c_)=='+' || (_c_)=='.' || (_c_)=='_')
42
-#define is_char_equal(_c_,_cs_) \
43
-	( (isalpha((int)_c_)?(((_c_)|0x20)==(_cs_)):((_c_)==(_cs_)))==1 )
44
-
45
-
46
-/*! \brief
47
- * Node of the type's tree; this tree contains all the known types;
48
- */
49
-typedef struct type_node_s {
50
-	char c;                      /*!< char contained by this node */
51
-	unsigned char final;         /*!< says what mime type/subtype was detected
52
-	                              *!< if string ends at this node */
53
-	unsigned char nr_sons;       /*!< the number of sub-nodes */
54
-	int next;                    /*!< the next sibling node */
55
-}type_node_t;
56
-
57
-
58
-static type_node_t type_tree[] = {
59
-	{'t',TYPE_UNKNOWN,1,4}, /* 0 */
60
-		{'e',TYPE_UNKNOWN,1,-1},
61
-			{'x',TYPE_UNKNOWN,1,-1},
62
-				{'t',TYPE_TEXT,0,-1},
63
-	{'m',TYPE_UNKNOWN,2,19}, /* 4 */
64
-		{'e',TYPE_UNKNOWN,1,11}, /* 5 */
65
-			{'s',TYPE_UNKNOWN,1,-1},
66
-				{'s',TYPE_UNKNOWN,1,-1},
67
-					{'a',TYPE_UNKNOWN,1,-1},
68
-						{'g',TYPE_UNKNOWN,1,-1},
69
-							{'e',TYPE_MESSAGE,0,-1},
70
-		{'u',TYPE_UNKNOWN,1,-1}, /* 11 */
71
-			{'l',TYPE_UNKNOWN,1,-1},
72
-				{'t',TYPE_UNKNOWN,1,-1},
73
-					{'i',TYPE_UNKNOWN,1,-1},
74
-						{'p',TYPE_UNKNOWN,1,-1},
75
-							{'a',TYPE_UNKNOWN,1,-1},
76
-								{'r',TYPE_UNKNOWN,1,-1},
77
-									{'t',TYPE_MULTIPART,0,-1},
78
-	{'a',TYPE_UNKNOWN,1,-1}, /* 19 */
79
-		{'p',TYPE_UNKNOWN,1,-1},
80
-			{'p',TYPE_UNKNOWN,1,-1},
81
-				{'l',TYPE_UNKNOWN,1,-1},
82
-					{'i',TYPE_UNKNOWN,1,-1},
83
-						{'c',TYPE_UNKNOWN,1,-1},
84
-							{'a',TYPE_UNKNOWN,1,-1},
85
-								{'t',TYPE_UNKNOWN,1,-1},
86
-									{'i',TYPE_UNKNOWN,1,-1},
87
-										{'o',TYPE_UNKNOWN,1,-1},
88
-											{'n',TYPE_APPLICATION,0,-1},
89
-	};
90
-
91
-static type_node_t subtype_tree[] = {
92
-	{'p',SUBTYPE_UNKNOWN,2,13},
93
-		{'l',SUBTYPE_UNKNOWN,1,5},
94
-			{'a',SUBTYPE_UNKNOWN,1,-1},
95
-				{'i',SUBTYPE_UNKNOWN,1,-1},
96
-					{'n',SUBTYPE_PLAIN,0,-1},
97
-		{'i',SUBTYPE_UNKNOWN,1,-1}, /* 5 */
98
-			{'d',SUBTYPE_UNKNOWN,1,-1},
99
-				{'f',SUBTYPE_UNKNOWN,1,-1},
100
-					{'+',TYPE_UNKNOWN,1,-1},
101
-						{'x',TYPE_UNKNOWN,1,-1},
102
-							{'m',TYPE_UNKNOWN,1,-1},
103
-								{'l',SUBTYPE_PIDFXML,0,-1},
104
-									{'l',SUBTYPE_PIDFXML,0,-1},
105
-	{'s',SUBTYPE_UNKNOWN,1,16}, /* 13 */
106
-		{'d',SUBTYPE_UNKNOWN,1,-1},
107
-			{'p',SUBTYPE_SDP,0,-1},
108
-	{'c',SUBTYPE_UNKNOWN,1,34}, /* 16 */
109
-		{'p',SUBTYPE_UNKNOWN,2,-1},
110
-			{'i',SUBTYPE_UNKNOWN,1,29},
111
-				{'m',SUBTYPE_CPIM,1,-1},
112
-					{'-',SUBTYPE_UNKNOWN,1,-1},
113
-						{'p',SUBTYPE_UNKNOWN,1,-1},
114
-							{'i',SUBTYPE_UNKNOWN,1,-1},
115
-								{'d',SUBTYPE_UNKNOWN,1,-1},
116
-									{'f',SUBTYPE_UNKNOWN,1,-1},
117
-										{'+',SUBTYPE_UNKNOWN,1,-1},
118
-											{'x',SUBTYPE_UNKNOWN,1,-1},
119
-												{'m',SUBTYPE_UNKNOWN,1,-1},
120
-													{'l',SUBTYPE_CPIM_PIDFXML,0,-1},
121
-			{'l',SUBTYPE_UNKNOWN,1,-1}, /* 29 */
122
-				{'+',TYPE_UNKNOWN,1,-1},
123
-					{'x',TYPE_UNKNOWN,1,-1},
124
-						{'m',TYPE_UNKNOWN,1,-1},
125
-							{'l',SUBTYPE_CPLXML,0,-1},
126
-	{'r',SUBTYPE_UNKNOWN,2,48}, /* 34 */
127
-		{'l',SUBTYPE_UNKNOWN,1,42},/* 35 */
128
-			{'m',SUBTYPE_UNKNOWN,1,-1},
129
-				{'i',SUBTYPE_UNKNOWN,1,-1},
130
-					{'+',TYPE_UNKNOWN,1,-1},
131
-						{'x',TYPE_UNKNOWN,1,-1},
132
-							{'m',TYPE_UNKNOWN,1,-1},
133
-								{'l',SUBTYPE_RLMIXML,0,-1},
134
-		{'e',SUBTYPE_UNKNOWN,1,-1}, /* 42 */
135
-			{'l',SUBTYPE_UNKNOWN,1,-1},
136
-				{'a',SUBTYPE_UNKNOWN,1,-1},
137
-					{'t',SUBTYPE_UNKNOWN,1,-1},
138
-						{'e',SUBTYPE_UNKNOWN,1,-1},
139
-							{'d',SUBTYPE_RELATED,0,-1},
140
-	{'l',SUBTYPE_UNKNOWN,1,57}, /* 48 */
141
-		{'p',SUBTYPE_UNKNOWN,1,-1},
142
-			{'i',SUBTYPE_UNKNOWN,1,-1},
143
-				{'d',SUBTYPE_UNKNOWN,1,-1},
144
-					{'f',SUBTYPE_UNKNOWN,1,-1},
145
-						{'+',SUBTYPE_UNKNOWN,1,-1},
146
-							{'x',SUBTYPE_UNKNOWN,1,-1},
147
-								{'m',SUBTYPE_UNKNOWN,1,-1},
148
-									{'l',SUBTYPE_LPIDFXML,0,-1},
149
-	{'w',SUBTYPE_UNKNOWN,1,72}, /* 57 */
150
-		{'a',SUBTYPE_UNKNOWN,1,-1},
151
-			{'t',SUBTYPE_UNKNOWN,1,-1},
152
-				{'c',SUBTYPE_UNKNOWN,1,-1},
153
-					{'h',SUBTYPE_UNKNOWN,1,-1},
154
-						{'e',SUBTYPE_UNKNOWN,1,-1},
155
-							{'r',SUBTYPE_UNKNOWN,1,-1},
156
-								{'i',TYPE_UNKNOWN,1,-1},
157
-									{'n',TYPE_UNKNOWN,1,-1},
158
-										{'f',TYPE_UNKNOWN,1,-1},
159
-											{'o',TYPE_UNKNOWN,1,-1},
160
-												{'+',TYPE_UNKNOWN,1,-1},
161
-													{'x',TYPE_UNKNOWN,1,-1},
162
-														{'m',TYPE_UNKNOWN,1,-1},
163
-															{'l',SUBTYPE_WATCHERINFOXML,0,-1},
164
-	{'x',SUBTYPE_UNKNOWN,2,94}, /* 72 */
165
-		{'p',SUBTYPE_UNKNOWN,1,81}, /* 73 */
166
-			{'i',SUBTYPE_UNKNOWN,1,-1},
167
-				{'d',SUBTYPE_UNKNOWN,1,-1},
168
-					{'f',SUBTYPE_UNKNOWN,1,-1},
169
-						{'+',SUBTYPE_UNKNOWN,1,-1},
170
-							{'x',SUBTYPE_UNKNOWN,1,-1},
171
-								{'m',SUBTYPE_UNKNOWN,1,-1},
172
-									{'l',SUBTYPE_XPIDFXML,0,-1},
173
-		{'m',SUBTYPE_UNKNOWN,1,-1}, /* 81 */
174
-			{'l',SUBTYPE_UNKNOWN,1,-1},
175
-				{'+',SUBTYPE_UNKNOWN,1,-1},
176
-					{'m',SUBTYPE_UNKNOWN,1,-1},
177
-						{'s',SUBTYPE_UNKNOWN,1,-1},
178
-							{'r',SUBTYPE_UNKNOWN,1,-1},
179
-								{'t',SUBTYPE_UNKNOWN,1,-1},
180
-									{'c',SUBTYPE_UNKNOWN,1,-1},
181
-										{'.',SUBTYPE_UNKNOWN,1,-1},
182
-											{'p',SUBTYPE_UNKNOWN,1,-1},
183
-												{'i',SUBTYPE_UNKNOWN,1,-1},
184
-													{'d',SUBTYPE_UNKNOWN,1,-1},
185
-														{'f',SUBTYPE_XML_MSRTC_PIDF,0,-1},
186
-	{'e',SUBTYPE_UNKNOWN,1,107}, /* 94 */
187
-		{'x',SUBTYPE_UNKNOWN,1,-1},
188
-			{'t',SUBTYPE_UNKNOWN,1,-1},
189
-				{'e',SUBTYPE_UNKNOWN,1,-1},
190
-					{'r',SUBTYPE_UNKNOWN,1,-1},
191
-						{'n',SUBTYPE_UNKNOWN,1,-1},
192
-							{'a',SUBTYPE_UNKNOWN,1,-1},
193
-								{'l',SUBTYPE_UNKNOWN,1,-1},
194
-									{'-',SUBTYPE_UNKNOWN,1,-1},
195
-										{'b',SUBTYPE_UNKNOWN,1,-1},
196
-											{'o',SUBTYPE_UNKNOWN,1,-1},
197
-												{'d',SUBTYPE_UNKNOWN,1,-1},
198
-													{'y',SUBTYPE_EXTERNAL_BODY,0,-1},
199
-	{'m',SUBTYPE_UNKNOWN,1,112}, /* 107 */
200
-		{'i',SUBTYPE_UNKNOWN,1,-1},
201
-			{'x',SUBTYPE_UNKNOWN,1,-1},
202
-				{'e',SUBTYPE_UNKNOWN,1,-1},
203
-					{'d',SUBTYPE_MIXED,0,-1},
204
-	{'i',SUBTYPE_UNKNOWN,1,-1}, /* 112 */
205
-		{'s',SUBTYPE_UNKNOWN,1,-1},
206
-			{'u',SUBTYPE_UNKNOWN,1,-1},
207
-				{'p',SUBTYPE_ISUP,0,-1},
208
-};
209
-
210
-
211
-
212
-char* parse_content_length(char* const buffer, const char* const end, int* const length)
213
-{
214
-	int number;
215
-	char *p;
216
-	int  size;
217
-
218
-	p = buffer;
219
-	/* search the begining of the number */
220
-	while ( p<end && (*p==' ' || *p=='\t' ||
221
-	(*p=='\n' && (*(p+1)==' '||*(p+1)=='\t')) ))
222
-		p++;
223
-	if (p==end)
224
-		goto error;
225
-	/* parse the number */
226
-	size = 0;
227
-	number = 0;
228
-	while (p<end && *p>='0' && *p<='9') {
229
-		number = number*10 + (*p)-'0';
230
-		size ++;
231
-		p++;
232
-	}
233
-	if (p==end || size==0)
234
-		goto error;
235
-	/* now we should have only spaces at the end */
236
-	while ( p<end && (*p==' ' || *p=='\t' ||
237
-	(*p=='\n' && (*(p+1)==' '||*(p+1)=='\t')) ))
238
-		p++;
239
-	if (p==end)
240
-		goto error;
241
-	/* the header ends proper? */
242
-	if ( (*(p++)!='\n') && (*(p-1)!='\r' || *(p++)!='\n' ) )
243
-		goto error;
244
-
245
-	*length = number;
246
-	return p;
247
-error:
248
-	LOG(L_ERR,"ERROR:parse_content_length: parse error near char [%d][%c]\n",
249
-		*p,*p);
250
-	return 0;
251
-}
252
-
253
-
254
-
255
-char* decode_mime_type(char* const start, const char* const end, unsigned int* const mime_type)
256
-{
257
-	int node;
258
-	char *mark;
259
-	char *p;
260
-	unsigned int type_candidate;
261
-
262
-	p = start;
263
-
264
-	/* search the begining of the type */
265
-	while ( p<end && (*p==' ' || *p=='\t' ||
266
-	(*p=='\n' && (*(p+1)==' '||*(p+1)=='\t')) ))
267
-		p++;
268
-	if (p==end)
269
-		goto error;
270
-
271
-	/* parse the type */
272
-	if (*p=='*') {
273
-		*mime_type = TYPE_ALL<<16;
274
-		p++;
275
-	} else {
276
-		node = 0;
277
-		mark = p;
278
-		type_candidate = TYPE_UNKNOWN;
279
-		while (p<end && is_mime_char(*p)  ) {
280
-			while ( node!=-1 && !is_char_equal(*p,type_tree[node].c) ){
281
-				node = type_tree[node].next;
282
-			}
283
-			if (node!=-1) {
284
-				type_candidate = type_tree[node].final;
285
-				if (type_tree[node].nr_sons)
286
-					node++;
287
-				else
288
-					node = -1;
289
-			} else {
290
-				/* end of the type tree has reached,
291
-				but the type has still some remaining
292
-				characters (Miklos) */
293
-				type_candidate = TYPE_UNKNOWN;
294
-			}
295
-			p++;
296
-		}
297
-		if (p==end || mark==p)
298
-			goto error;
299
-		*mime_type = type_candidate<<16;
300
-	}
301
-
302
-	/* search the '/' separator */
303
-	while ( p<end && (*p==' ' || *p=='\t' ||
304
-	(*p=='\n' && (*(p+1)==' '||*(p+1)=='\t')) ))
305
-		p++;
306
-	if ( p==end || *(p++)!='/')
307
-		goto error;
308
-
309
-	/* search the begining of the sub-type */
310
-	while ( p<end && (*p==' ' || *p=='\t' ||
311
-	(*p=='\n' && (*(p+1)==' '||*(p+1)=='\t')) ))
312
-		p++;
313
-	if (p==end)
314
-		goto error;
315
-
316
-	/* parse the sub-type */
317
-	if (*p=='*') {
318
-		*mime_type |= SUBTYPE_ALL;
319
-		p++;
320
-	} else {
321
-		node = 0;
322
-		mark = p;
323
-		type_candidate = SUBTYPE_UNKNOWN;
324
-		while (p<end && is_mime_char(*p) ) {
325
-			while(node!=-1 && !is_char_equal(*p,subtype_tree[node].c) )
326
-				node = subtype_tree[node].next;
327
-			if (node!=-1) {
328
-				type_candidate = subtype_tree[node].final;
329
-				if (subtype_tree[node].nr_sons)
330
-					node++;
331
-				else
332
-					node = -1;
333
-			} else {
334
-				/* end of the subtype tree has reached,
335
-				but the subtype has still some remaining
336
-				characters (Miklos) */
337
-				type_candidate = SUBTYPE_UNKNOWN;
338
-			}
339
-			p++;
340
-		}
341
-		if (p==mark)
342
-			goto error;
343
-		*mime_type |= type_candidate;;
344
-	}
345
-
346
-	/* now its possible to have some spaces */
347
-	while ( p<end && (*p==' ' || *p=='\t' ||
348
-	(*p=='\n' && (*(p+1)==' '||*(p+1)=='\t')) ))
349
-		p++;
350
-
351
-	/* if there are params, ignore them!! -> eat everything to
352
-	 * the end or to the first ',' */
353
-	if ( p<end && *p==';' )
354
-		for(p++; p<end && *p!=','; p++);
355
-
356
-	/* is this the correct end? */
357
-	if (p!=end && *p!=',' )
358
-		goto error;
359
-
360
-	/* check the format of the decoded mime */
361
-	if ((*mime_type)>>16==TYPE_ALL && ((*mime_type)&0x00ff)!=SUBTYPE_ALL) {
362
-		LOG(L_ERR,"ERROR:decode_mime_type: invalid mime format found "
363
-			" <*/submime> in [%.*s]!!\n", (int)(end-start),start);
364
-		return 0;
365
-	}
366
-
367
-	return p;
368
-error:
369
-	LOG(L_ERR,"ERROR:decode_mime_type: parse error near in [%.*s] char"
370
-		"[%d][%c] offset=%d\n", (int)(end-start),start,*p,*p,(int)(p-start));
371
-	return 0;
372
-}
373
-
374
-
375
-
376
-/*! \brief
377
- * \return
378
- *  	-   > 0 mime found
379
- *      -   = 0 hdr not found
380
- *      -   =-1 error */
381
-int parse_content_type_hdr(struct sip_msg* const msg)
382
-{
383
-	char *end;
384
-	const char *ret;
385
-	unsigned int  mime;
386
-
387
-	/* is the header already found? */
388
-	if ( msg->content_type==0 ) {
389
-		/* if not, found it */
390
-		if ( parse_headers(msg, HDR_CONTENTTYPE_F, 0)==-1)
391
-			goto error;
392
-		if ( msg->content_type==0 ) {
393
-			DBG("DEBUG:parse_content_type_hdr: missing Content-Type"
394
-				"header\n");
395
-			return 0;
396
-		}
397
-	}
398
-
399
-	/* maybe the header is already parsed! */
400
-	if ( msg->content_type->parsed!=0)
401
-		return get_content_type(msg);
402
-
403
-	/* it seams we have to parse it! :-( */
404
-	end = msg->content_type->body.s + msg->content_type->body.len;
405
-	ret = decode_mime_type(msg->content_type->body.s, end , &mime);
406
-	if (ret==0)
407
-		goto error;
408
-	if (ret!=end) {
409
-		LOG(L_ERR,"ERROR:parse_content_type_hdr: CONTENT_TYPE hdr contains "
410
-			"more then one mime type :-(!\n");
411
-		goto error;
412
-	}
413
-	if ((mime&0x00ff)==SUBTYPE_ALL || (mime>>16)==TYPE_ALL) {
414
-		LOG(L_ERR,"ERROR:parse_content_type_hdr: invalid mime with wildcard "
415
-			"'*' in Content-Type hdr!\n");
416
-		goto error;
417
-	}
418
-
419
-	msg->content_type->parsed = (void*)(unsigned long)mime;
420
-	return mime;
421
-
422
-error:
423
-	return -1;
424
-}
425
-
426
-int parse_accept_body(struct hdr_field* const hdr)
427
-{
428
-	static unsigned int mimes[MAX_MIMES_NR];
429
-	int nr_mimes;
430
-	unsigned int mime;
431
-	char *end;
432
-	char *ret;
433
-
434
-	if (!hdr) return -1;
435
-
436
-	/* maybe the header is already parsed! */
437
-	if (hdr->parsed!=0) return 1;
438
-
439
-	/* it seams we have to parse it! :-( */
440
-	ret = hdr->body.s;
441
-	end = ret + hdr->body.len;
442
-	nr_mimes = 0;
443
-	while (1){
444
-		ret = decode_mime_type(ret, end , &mime);
445
-		if (ret==0)
446
-			goto error;
447
-		/* a new mime was found  -> put it into array */
448
-		if (nr_mimes==MAX_MIMES_NR) {
449
-			LOG(L_ERR,"ERROR:parse_accept_hdr: Accept hdr contains more than"
450
-				" %d mime type -> buffer overflow!!\n",MAX_MIMES_NR);
451
-			goto error;
452
-		}
453
-		mimes[nr_mimes++] = mime;
454
-		/* is another mime following? */
455
-		if (ret==end )
456
-			break;
457
-		/* parse the mime separator ',' */
458
-		if (*ret!=',' || ret+1==end) {
459
-			LOG(L_ERR,"ERROR:parse_accept_hdr: parse error between mimes at "
460
-				"char <%x> (offset=%d) in <%.*s>!\n",
461
-				*ret, (int)(ret-hdr->body.s),
462
-				hdr->body.len, hdr->body.s);
463
-			goto error;
464
-		}
465
-		/* skip the ',' */
466
-		ret++;
467
-	}
468
-
469
-	/* copy and link the mime buffer into the message */
470
-	hdr->parsed = (void*)pkg_malloc((nr_mimes+1)*sizeof(int));
471
-	if (hdr->parsed==0) {
472
-		LOG(L_ERR,"ERROR:parse_accept: no more pkg memory\n");
473
-		goto error;
474
-	}
475
-	memcpy(hdr->parsed,mimes,nr_mimes*sizeof(int));
476
-	/* make the buffer null terminated */
477
-	((int*)hdr->parsed)[nr_mimes] = 0;
478
-
479
-	return 1;
480
-error:
481
-	return -1;
482
-}
483
-
484
-/*! \brief
485
- * returns: > 0 ok
486
- *          = 0 hdr not found
487
- *          = -1 error */
488
-int parse_accept_hdr(struct sip_msg* const msg)
489
-{
490
-	static unsigned int mimes[MAX_MIMES_NR];
491
-	int nr_mimes;
492
-	unsigned int mime;
493
-	char *end;
494
-	char *ret;
495
-
496
-	/* is the header already found? */
497
-	if ( msg->accept==0 ) {
498
-		/* if not, found it */
499
-		if ( parse_headers(msg, HDR_ACCEPT_F, 0)==-1)
500
-			goto error;
501
-		if ( msg->accept==0 ) {
502
-			DBG("DEBUG:parse_accept_hdr: missing Accept header\n");
503
-			return 0;
504
-		}
505
-	}
506
-
507
-	/* maybe the header is already parsed! */
508
-	if ( msg->accept->parsed!=0)
509
-		return 1;
510
-
511
-	/* it seams we have to parse it! :-( */
512
-	ret = msg->accept->body.s;
513
-	end = ret + msg->accept->body.len;
514
-	nr_mimes = 0;
515
-	while (1){
516
-		ret = decode_mime_type(ret, end , &mime);
517
-		if (ret==0)
518
-			goto error;
519
-		/* a new mime was found  -> put it into array */
520
-		if (nr_mimes==MAX_MIMES_NR) {
521
-			LOG(L_ERR,"ERROR:parse_accept_hdr: Accept hdr contains more than"
522
-				" %d mime type -> buffer overflow!!\n",MAX_MIMES_NR);
523
-			goto error;
524
-		}
525
-		mimes[nr_mimes++] = mime;
526
-		/* is another mime following? */
527
-		if (ret==end )
528
-			break;
529
-		/* parse the mime separator ',' */
530
-		if (*ret!=',' || ret+1==end) {
531
-			LOG(L_ERR,"ERROR:parse_accept_hdr: parse error between mimes at "
532
-				"char <%x> (offset=%d) in <%.*s>!\n",
533
-				*ret, (int)(ret-msg->accept->body.s),
534
-				msg->accept->body.len, msg->accept->body.s);
535
-			goto error;
536
-		}
537
-		/* skip the ',' */
538
-		ret++;
539
-	}
540
-
541
-	/* copy and link the mime buffer into the message */
542
-	msg->accept->parsed = (void*)pkg_malloc((nr_mimes+1)*sizeof(int));
543
-	if (msg->accept->parsed==0) {
544
-		LOG(L_ERR,"ERROR:parse_accept_hdr: no more pkg memory\n");
545
-		goto error;
546
-	}
547
-	memcpy(msg->accept->parsed,mimes,nr_mimes*sizeof(int));
548
-	/* make the buffer null terminated */
549
-	((int*)msg->accept->parsed)[nr_mimes] = 0;
550
-
551
-	return 1;
552
-error:
553
-	return -1;
554
-}
555
-
Browse code

core: parse content type allows '_' char

- reported by Fabio Margarido, GH #547

Daniel-Constantin Mierla authored on 18/03/2016 12:32:59
Showing 1 changed files
... ...
@@ -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,7 +38,7 @@
38 38
 
39 39
 
40 40
 #define is_mime_char(_c_) \
41
-	(isalpha((int)_c_) || (_c_)=='-' || (_c_)=='+' || (_c_)=='.')
41
+	(isalpha((int)_c_) || (_c_)=='-' || (_c_)=='+' || (_c_)=='.' || (_c_)=='_')
42 42
 #define is_char_equal(_c_,_cs_) \
43 43
 	( (isalpha((int)_c_)?(((_c_)|0x20)==(_cs_)):((_c_)==(_cs_)))==1 )
44 44
 
... ...
@@ -180,7 +180,7 @@ static type_node_t subtype_tree[] = {
180 180
 									{'c',SUBTYPE_UNKNOWN,1,-1},
181 181
 										{'.',SUBTYPE_UNKNOWN,1,-1},
182 182
 											{'p',SUBTYPE_UNKNOWN,1,-1},
183
-												{'i',SUBTYPE_UNKNOWN,1,-1}, 
183
+												{'i',SUBTYPE_UNKNOWN,1,-1},
184 184
 													{'d',SUBTYPE_UNKNOWN,1,-1},
185 185
 														{'f',SUBTYPE_XML_MSRTC_PIDF,0,-1},
186 186
 	{'e',SUBTYPE_UNKNOWN,1,107}, /* 94 */
... ...
@@ -327,7 +327,7 @@ char* decode_mime_type(char* const start, const char* const end, unsigned int* c
327 327
 			if (node!=-1) {
328 328
 				type_candidate = subtype_tree[node].final;
329 329
 				if (subtype_tree[node].nr_sons)
330
-        				node++;
330
+					node++;
331 331
 				else
332 332
 					node = -1;
333 333
 			} else {
... ...
@@ -432,10 +432,10 @@ int parse_accept_body(struct hdr_field* const hdr)
432 432
 	char *ret;
433 433
 
434 434
 	if (!hdr) return -1;
435
-	
435
+
436 436
 	/* maybe the header is already parsed! */
437 437
 	if (hdr->parsed!=0) return 1;
438
-	
438
+
439 439
 	/* it seams we have to parse it! :-( */
440 440
 	ret = hdr->body.s;
441 441
 	end = ret + hdr->body.len;
Browse code

core parser - remove svn ID, remove history, change "ser" => "Kamailio"

Olle E. Johansson authored on 18/01/2015 19:36:18
Showing 1 changed files
... ...
@@ -1,14 +1,14 @@
1 1
 /*
2 2
  * Copyright (C) 2001-2003 FhG Fokus
3 3
  *
4
- * This file is part of ser, a free SIP server.
4
+ * This file is part of Kamailio, a free SIP server.
5 5
  *
6
- * ser is free software; you can redistribute it and/or modify
6
+ * Kamailio is free software; you can redistribute it and/or modify
7 7
  * it under the terms of the GNU General Public License as published by
8 8
  * the Free Software Foundation; either version 2 of the License, or
9 9
  * (at your option) any later version
10 10
  *
11
- * ser is distributed in the hope that it will be useful,
11
+ * Kamailio is distributed in the hope that it will be useful,
12 12
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
  * GNU General Public License for more details.
... ...
@@ -17,14 +17,6 @@
17 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
- * History:
21
- * 2003-08-04 parse_content_type_hdr separates type from subtype inside
22
- * the mime type (bogdan)
23
- * 2003-08-04 CPL subtype added (bogdan)
24
- * 2003-08-05 parse_accept_hdr function added (bogdan)
25
- * 2008-05-23 reset the type/subtype to unknown, if the end of
26
- *		tree has reached, but the type/subtype has still
27
- *		some remaining characters (Miklos)
28 20
  */
29 21
 
30 22
 /*! \file
Browse code

all: updated FSF address in GPL text

Anthony Messina authored on 04/07/2014 09:36:37 • Daniel-Constantin Mierla committed on 04/07/2014 09:37:36
Showing 1 changed files
... ...
@@ -15,7 +15,7 @@
15 15
  *
16 16
  * You should have received a copy of the GNU General Public License 
17 17
  * along with this program; if not, write to the Free Software 
18
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 19
  *
20 20
  * History:
21 21
  * 2003-08-04 parse_content_type_hdr separates type from subtype inside
Browse code

parser/parse_content: add support for the ISUP subtype

Torrey Searle authored on 08/04/2013 09:17:04
Showing 1 changed files
... ...
@@ -204,11 +204,15 @@ static type_node_t subtype_tree[] = {
204 204
 											{'o',SUBTYPE_UNKNOWN,1,-1},
205 205
 												{'d',SUBTYPE_UNKNOWN,1,-1},
206 206
 													{'y',SUBTYPE_EXTERNAL_BODY,0,-1},
207
-	{'m',SUBTYPE_UNKNOWN,1,-1}, /* 107 */
207
+	{'m',SUBTYPE_UNKNOWN,1,112}, /* 107 */
208 208
 		{'i',SUBTYPE_UNKNOWN,1,-1},
209 209
 			{'x',SUBTYPE_UNKNOWN,1,-1},
210 210
 				{'e',SUBTYPE_UNKNOWN,1,-1},
211 211
 					{'d',SUBTYPE_MIXED,0,-1},
212
+	{'i',SUBTYPE_UNKNOWN,1,-1}, /* 112 */
213
+		{'s',SUBTYPE_UNKNOWN,1,-1},
214
+			{'u',SUBTYPE_UNKNOWN,1,-1},
215
+				{'p',SUBTYPE_ISUP,0,-1},
212 216
 };
213 217
 
214 218
 
Browse code

parser: remove old $Id$ docs header from subversion times, not usable anymore

Henning Westerholt authored on 05/07/2012 21:39:51
Showing 1 changed files
... ...
@@ -1,7 +1,4 @@
1 1
 /*
2
- * $Id$
3
- *
4
- *
5 2
  * Copyright (C) 2001-2003 FhG Fokus
6 3
  *
7 4
  * This file is part of ser, a free SIP server.
Browse code

parser: make get_hdr_field(..) and necessary called functions const-correct

Henning Westerholt authored on 05/07/2012 20:35:22
Showing 1 changed files
... ...
@@ -216,7 +216,7 @@ static type_node_t subtype_tree[] = {
216 216
 
217 217
 
218 218
 
219
-char* parse_content_length( char* buffer, char* end, int* length)
219
+char* parse_content_length(char* const buffer, const char* const end, int* const length)
220 220
 {
221 221
 	int number;
222 222
 	char *p;
... ...
@@ -259,7 +259,7 @@ error:
259 259
 
260 260
 
261 261
 
262
-char* decode_mime_type(char *start, char *end, unsigned int *mime_type)
262
+char* decode_mime_type(char* const start, const char* const end, unsigned int* const mime_type)
263 263
 {
264 264
 	int node;
265 265
 	char *mark;
... ...
@@ -385,10 +385,10 @@ error:
385 385
  *  	-   > 0 mime found
386 386
  *      -   = 0 hdr not found
387 387
  *      -   =-1 error */
388
-int parse_content_type_hdr( struct sip_msg *msg )
388
+int parse_content_type_hdr(struct sip_msg* const msg)
389 389
 {
390 390
 	char *end;
391
-	char *ret;
391
+	const char *ret;
392 392
 	unsigned int  mime;
393 393
 
394 394
 	/* is the header already found? */
... ...
@@ -430,7 +430,7 @@ error:
430 430
 	return -1;
431 431
 }
432 432
 
433
-int parse_accept_body(struct hdr_field *hdr)
433
+int parse_accept_body(struct hdr_field* const hdr)
434 434
 {
435 435
 	static unsigned int mimes[MAX_MIMES_NR];
436 436
 	int nr_mimes;
... ...
@@ -492,7 +492,7 @@ error:
492 492
  * returns: > 0 ok
493 493
  *          = 0 hdr not found
494 494
  *          = -1 error */
495
-int parse_accept_hdr( struct sip_msg *msg )
495
+int parse_accept_hdr(struct sip_msg* const msg)
496 496
 {
497 497
 	static unsigned int mimes[MAX_MIMES_NR];
498 498
 	int nr_mimes;
Browse code

More parser/ doxygen changes

oej authored on 25/10/2009 17:26:46
Showing 1 changed files
... ...
@@ -11,11 +11,6 @@
11 11
  * the Free Software Foundation; either version 2 of the License, or
12 12
  * (at your option) any later version
13 13
  *
14
- * For a license to use the ser software under conditions
15
- * other than those described here, or to purchase support for this
16
- * software, please contact iptel.org by e-mail at the following addresses:
17
- *    info@iptel.org
18
- *
19 14
  * ser is distributed in the hope that it will be useful,
20 15
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 16
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
... ...
@@ -35,6 +30,12 @@
35 30
  *		some remaining characters (Miklos)
36 31
  */
37 32
 
33
+/*! \file
34
+ * \brief Parser :: Content part
35
+ *
36
+ * \ingroup parser
37
+ */
38
+
38 39
 
39 40
 #include <stdio.h>
40 41
 #include <stdlib.h>
... ...
@@ -53,15 +54,15 @@
53 54
 	( (isalpha((int)_c_)?(((_c_)|0x20)==(_cs_)):((_c_)==(_cs_)))==1 )
54 55
 
55 56
 
56
-/*
57
+/*! \brief
57 58
  * Node of the type's tree; this tree contains all the known types;
58 59
  */
59 60
 typedef struct type_node_s {
60
-	char c;                      /* char contained by this node */
61
-	unsigned char final;         /* says what mime type/subtype was detected
62
-	                              * if string ends at this node */
63
-	unsigned char nr_sons;       /* the number of sub-nodes */
64
-	int next;                    /* the next sibling node */
61
+	char c;                      /*!< char contained by this node */
62
+	unsigned char final;         /*!< says what mime type/subtype was detected
63
+	                              *!< if string ends at this node */
64
+	unsigned char nr_sons;       /*!< the number of sub-nodes */
65
+	int next;                    /*!< the next sibling node */
65 66
 }type_node_t;
66 67
 
67 68
 
... ...
@@ -379,9 +380,11 @@ error:
379 380
 
380 381
 
381 382
 
382
-/* returns: > 0 mime found
383
- *          = 0 hdr not found
384
- *          =-1 error */
383
+/*! \brief
384
+ * \return
385
+ *  	-   > 0 mime found
386
+ *      -   = 0 hdr not found
387
+ *      -   =-1 error */
385 388
 int parse_content_type_hdr( struct sip_msg *msg )
386 389
 {
387 390
 	char *end;
... ...
@@ -485,7 +488,8 @@ error:
485 488
 	return -1;
486 489
 }
487 490
 
488
-/* returns: > 0 ok
491
+/*! \brief
492
+ * returns: > 0 ok
489 493
  *          = 0 hdr not found
490 494
  *          = -1 error */
491 495
 int parse_accept_hdr( struct sip_msg *msg )
Browse code

Support for mixed content type.

This patch extendes the content type parser and adds support for
content type mixed.

Signed-off-by: Jan Janak <jan@iptel.org>

Ovidiu Sas authored on 24/03/2009 14:14:53 • Jan Janak committed on 24/03/2009 14:14:53
Showing 1 changed files
... ...
@@ -193,7 +193,7 @@ static type_node_t subtype_tree[] = {
193 193
 												{'i',SUBTYPE_UNKNOWN,1,-1}, 
194 194
 													{'d',SUBTYPE_UNKNOWN,1,-1},
195 195
 														{'f',SUBTYPE_XML_MSRTC_PIDF,0,-1},
196
-	{'e',SUBTYPE_UNKNOWN,1,-1}, /* 94 */
196
+	{'e',SUBTYPE_UNKNOWN,1,107}, /* 94 */
197 197
 		{'x',SUBTYPE_UNKNOWN,1,-1},
198 198
 			{'t',SUBTYPE_UNKNOWN,1,-1},
199 199
 				{'e',SUBTYPE_UNKNOWN,1,-1},
... ...
@@ -206,8 +206,12 @@ static type_node_t subtype_tree[] = {
206 206
 											{'o',SUBTYPE_UNKNOWN,1,-1},
207 207
 												{'d',SUBTYPE_UNKNOWN,1,-1},
208 208
 													{'y',SUBTYPE_EXTERNAL_BODY,0,-1},
209
-
210
-	};
209
+	{'m',SUBTYPE_UNKNOWN,1,-1}, /* 107 */
210
+		{'i',SUBTYPE_UNKNOWN,1,-1},
211
+			{'x',SUBTYPE_UNKNOWN,1,-1},
212
+				{'e',SUBTYPE_UNKNOWN,1,-1},
213
+					{'d',SUBTYPE_MIXED,0,-1},
214
+};
211 215
 
212 216
 
213 217
 
Browse code

decode_mime_type() resets the type/subtype to unknown, if the end of tree has reached, but the type/subtype has still some remaining characters

Miklos Tirpak authored on 23/05/2008 10:04:55
Showing 1 changed files
... ...
@@ -30,6 +30,9 @@
30 30
  * the mime type (bogdan)
31 31
  * 2003-08-04 CPL subtype added (bogdan)
32 32
  * 2003-08-05 parse_accept_hdr function added (bogdan)
33
+ * 2008-05-23 reset the type/subtype to unknown, if the end of
34
+ *		tree has reached, but the type/subtype has still
35
+ *		some remaining characters (Miklos)
33 36
  */
34 37
 
35 38
 
... ...
@@ -256,6 +259,7 @@ char* decode_mime_type(char *start, char *end, unsigned int *mime_type)
256 259
 	int node;
257 260
 	char *mark;
258 261
 	char *p;
262
+	unsigned int type_candidate;
259 263
 
260 264
 	p = start;
261 265
 
... ...
@@ -273,22 +277,28 @@ char* decode_mime_type(char *start, char *end, unsigned int *mime_type)
273 277
 	} else {
274 278
 		node = 0;
275 279
 		mark = p;
280
+		type_candidate = TYPE_UNKNOWN;
276 281
 		while (p<end && is_mime_char(*p)  ) {
277 282
 			while ( node!=-1 && !is_char_equal(*p,type_tree[node].c) ){
278 283
 				node = type_tree[node].next;
279 284
 			}
280
-			if (node!=-1 && type_tree[node].nr_sons)
281
-				node++; 
282
-				/* ? increment only for (p < end - 1), 
283
-				 * otherwise will not work for final nodes with children */
285
+			if (node!=-1) {
286
+				type_candidate = type_tree[node].final;
287
+				if (type_tree[node].nr_sons)
288
+					node++;
289
+				else
290
+					node = -1;
291
+			} else {
292
+				/* end of the type tree has reached,
293
+				but the type has still some remaining
294
+				characters (Miklos) */
295
+				type_candidate = TYPE_UNKNOWN;
296
+			}
284 297
 			p++;
285 298
 		}
286 299
 		if (p==end || mark==p)
287 300
 			goto error;
288
-		if (node!=-1)
289
-			*mime_type = type_tree[node].final<<16;
290
-		else
291
-			*mime_type = TYPE_UNKNOWN<<16;
301
+		*mime_type = type_candidate<<16;
292 302
 	}
293 303
 
294 304
 	/* search the '/' separator */
... ...
@@ -312,19 +322,27 @@ char* decode_mime_type(char *start, char *end, unsigned int *mime_type)
312 322
 	} else {
313 323
 		node = 0;
314 324
 		mark = p;
325
+		type_candidate = SUBTYPE_UNKNOWN;
315 326
 		while (p<end && is_mime_char(*p) ) {
316 327
 			while(node!=-1 && !is_char_equal(*p,subtype_tree[node].c) )
317 328
 				node = subtype_tree[node].next;
318
-			if (node!=-1 && subtype_tree[node].nr_sons && (p < end - 1))
319
-				node++;
329
+			if (node!=-1) {
330
+				type_candidate = subtype_tree[node].final;
331
+				if (subtype_tree[node].nr_sons)
332
+        				node++;
333
+				else
334
+					node = -1;
335
+			} else {
336
+				/* end of the subtype tree has reached,
337
+				but the subtype has still some remaining
338
+				characters (Miklos) */
339
+				type_candidate = SUBTYPE_UNKNOWN;
340
+			}
320 341
 			p++;
321 342
 		}
322 343
 		if (p==mark)
323 344
 			goto error;
324
-		if (node!=-1)