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,759 +0,0 @@
1
-/* 
2
- * Generic Parameter Parser
3
- *
4
- * Copyright (C) 2001-2003 FhG Fokus
5
- *
6
- * This file is part of Kamailio, a free SIP server.
7
- *
8
- * Kamailio 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
- * Kamailio is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU General Public License for more details.
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 
20
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
- *
22
- */
23
-
24
-/*! \file
25
- * \brief Parser :: Generic Parameter Parser
26
- *
27
- * \ingroup parser
28
- */
29
-
30
-#include <string.h>
31
-#include "../str.h"
32
-#include "../ut.h"
33
-#include "../dprint.h"
34
-#include "../trim.h"
35
-#include "../mem/mem.h"
36
-#include "../mem/shm_mem.h"
37
-#include "parse_param.h"
38
-
39
-
40
-static inline void parse_event_dialog_class(param_hooks_t* h, param_t* p)
41
-{
42
-
43
-	if (!p->name.s) {
44
-		LOG(L_ERR, "ERROR: parse_event_dialog_class: empty value\n");
45
-		return;
46
-	}
47
-	if (!h) {
48
-		LOG(L_CRIT, "BUG: parse_event_dialog_class: NULL param hook pointer\n");
49
-		return;
50
-	}
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;
105
-	}
106
-}
107
-
108
-
109
-/*! \brief
110
- * Try to find out parameter name, recognized parameters
111
- * are q, expires and methods
112
- */
113
-static inline void parse_contact_class(param_hooks_t* _h, param_t* _p)
114
-{
115
-
116
-	if (!_p->name.s) {
117
-		LOG(L_ERR, "ERROR: parse_contact_class: empty value\n");
118
-		return;
119
-	}
120
-	if (!_h) {
121
-		LOG(L_CRIT, "BUG: parse_contact_class: NULL param hook pointer\n");
122
-		return;
123
-	}
124
-	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;
163
-	case '+':
164
-		if ((_p->name.len == 13) &&
165
-			(!strncasecmp(_p->name.s + 1, "sip.instance", 12))) {
166
-			_p->type = P_INSTANCE;
167
-			_h->contact.instance = _p;
168
-		}
169
-		break;
170
-	case 'o':
171
-	case 'O':
172
-		if ((_p->name.len == 2) &&
173
-		    (!strncasecmp(_p->name.s + 1, "b", 1))) {
174
-			_p->type = P_OB;
175
-			_h->contact.ob = _p;
176
-		}
177
-		break;
178
-	}
179
-}
180
-
181
-
182
-/*! \brief
183
- * Try to find out parameter name, recognized parameters
184
- * are transport, lr, r2, maddr
185
- */
186
-static inline void parse_uri_class(param_hooks_t* _h, param_t* _p)
187
-{
188
-
189
-	if (!_p->name.s) {
190
-		LOG(L_ERR, "ERROR: parse_uri_class: empty value\n");
191
-		return;
192
-	}
193
-	if (!_h) {
194
-		LOG(L_CRIT, "BUG: parse_uri_class: NULL param hook pointer\n");
195
-		return;
196
-	}
197
-	switch(_p->name.s[0]) {
198
-	case 't':
199
-	case 'T':
200
-		if ((_p->name.len == 9) &&
201
-		    (!strncasecmp(_p->name.s + 1, "ransport", 8))) {
202
-			_p->type = P_TRANSPORT;
203
-			_h->uri.transport = _p;
204
-		} else if (_p->name.len == 2) {
205
-			if (((_p->name.s[1] == 't') || (_p->name.s[1] == 'T')) &&
206
-			    ((_p->name.s[2] == 'l') || (_p->name.s[2] == 'L'))) {
207
-				_p->type = P_TTL;
208
-				_h->uri.ttl = _p;
209
-			}
210
-		}
211
-		break;
212
-
213
-	case 'l':
214
-	case 'L':
215
-		if ((_p->name.len == 2) && ((_p->name.s[1] == 'r') || (_p->name.s[1] == 'R'))) {
216
-			_p->type = P_LR;
217
-			_h->uri.lr = _p;
218
-		}
219
-		break;
220
-
221
-	case 'r':
222
-	case 'R':
223
-		if ((_p->name.len == 2) && (_p->name.s[1] == '2')) {
224
-			_p->type = P_R2;
225
-			_h->uri.r2 = _p;
226
-		}
227
-		break;
228
-
229
-	case 'm':
230
-	case 'M':
231
-		if ((_p->name.len == 5) &&
232
-		    (!strncasecmp(_p->name.s + 1, "addr", 4))) {
233
-			_p->type = P_MADDR;
234
-			_h->uri.maddr = _p;
235
-		}
236
-		break;
237
-		
238
-	case 'd':
239
-	case 'D':
240
-		if ((_p->name.len == 5) &&
241
-		    (!strncasecmp(_p->name.s + 1, "stip", 4))) {
242
-			_p->type = P_DSTIP;
243
-			_h->uri.dstip = _p;
244
-		} else if ((_p->name.len == 7) &&
245
-			   (!strncasecmp(_p->name.s + 1, "stport", 6))) {
246
-			_p->type = P_DSTPORT;
247
-			_h->uri.dstport = _p;
248
-		}
249
-		break;
250
-	case 'f':
251
-	case 'F':
252
-		if ((_p->name.len == 4) &&
253
-		    (!strncasecmp(_p->name.s + 1, "tag", 3))) {
254
-			_p->type = P_FTAG;
255
-			_h->uri.ftag = _p;
256
-		}
257
-		break;
258
-	case 'o':
259
-	case 'O':
260
-		if ((_p->name.len == 2) &&
261
-		    (!strncasecmp(_p->name.s + 1, "b", 1))) {
262
-			_p->type = P_OB;
263
-			_h->uri.ob = _p;
264
-		}
265
-		break;
266
-	}
267
-
268
-}
269
-
270
-
271
-/*! \brief
272
- * Parse quoted string in a parameter body
273
- * return the string without quotes in _r
274
- * parameter and update _s to point behind the
275
- * closing quote
276
- */
277
-static inline int parse_quoted_param(str* _s, str* _r)
278
-{
279
-	char* end_quote;
280
-	char quote;
281
-
282
-	     /* The string must have at least
283
-	      * surrounding quotes
284
-	      */
285
-	if (_s->len < 2) {
286
-		return -1;
287
-	}
288
-
289
-	     /* Store the kind of quoting (single or double)
290
-	      * which we're handling with
291
-	      */
292
-	quote = (_s->s)[0];
293
-
294
-	     /* Skip opening quote */
295
-	_s->s++;
296
-	_s->len--;
297
-
298
-
299
-	     /* Find closing quote */
300
-	end_quote = q_memchr(_s->s, quote, _s->len);
301
-
302
-	     /* Not found, return error */
303
-	if (!end_quote) {
304
-		return -2;
305
-	}
306
-
307
-	     /* Let _r point to the string without
308
-	      * surrounding quotes
309
-	      */
310
-	_r->s = _s->s;
311
-	_r->len = end_quote - _s->s;
312
-
313
-	     /* Update _s parameter to point
314
-	      * behind the closing quote
315
-	      */
316
-	_s->len -= (end_quote - _s->s + 1);
317
-	_s->s = end_quote + 1;
318
-
319
-	     /* Everything went OK */
320
-	return 0;
321
-}
322
-
323
-
324
-/*! \brief
325
- * Parse unquoted token in a parameter body
326
- * let _r point to the token and update _s
327
- * to point right behind the token
328
- */
329
-static inline int parse_token_param(str* _s, str* _r, char separator)
330
-{
331
-	int i;
332
-
333
-	     /* There is nothing to parse,
334
-	      * return error
335
-	      */
336
-	if (_s->len == 0) {
337
-		return -1;
338
-	}
339
-
340
-	     /* Save the begining of the
341
-	      * token in _r->s
342
-	      */
343
-	_r->s = _s->s;
344
-
345
-	     /* Iterate through the
346
-	      * token body
347
-	      */
348
-	for(i = 0; i < _s->len; i++) {
349
-
350
-		     /* All these characters
351
-		      * mark end of the token
352
-		      */
353
-		switch(_s->s[i]) {
354
-		case ' ':
355
-		case '\t':
356
-		case '\r':
357
-		case '\n':
358
-		case ',':
359
-			     /* So if you find
360
-			      * any of them
361
-			      * stop iterating
362
-			      */
363
-			goto out;
364
-		default:
365
-			if(_s->s[i] == separator)
366
-				goto out;
367
-		}
368
-	}
369
- out:
370
-	if (i == 0) {
371
-		return -1;
372
-        }
373
-
374
-	     /* Save length of the token */
375
-        _r->len = i;
376
-
377
-	     /* Update _s parameter so it points
378
-	      * right behind the end of the token
379
-	      */
380
-	_s->s = _s->s + i;
381
-	_s->len -= i;
382
-
383
-	     /* Everything went OK */
384
-	return 0;
385
-}
386
-
387
-
388
-/*! \brief
389
- * Parse a parameter name
390
- */
391
-static inline void parse_param_name(str* _s, pclass_t _c, param_hooks_t* _h, param_t* _p, char separator)
392
-{
393
-
394
-	if (!_s->s) {
395
-		DBG("DEBUG: parse_param_name: empty parameter\n");
396
-		return;
397
-	}
398
-
399
-	_p->name.s = _s->s;
400
-
401
-	while(_s->len) {
402
-		switch(_s->s[0]) {
403
-		case ' ':
404
-		case '\t':
405
-		case '\r':
406
-		case '\n':
407
-		case ',':
408
-		case '=':
409
-			goto out;
410
-		default:
411
-			if (_s->s[0] == separator)
412
-				goto out;
413
-		}
414
-		_s->s++;
415
-		_s->len--;
416
-	}
417
-
418
- out:
419
-	_p->name.len = _s->s - _p->name.s;
420
-
421
-	switch(_c) {
422
-	case CLASS_CONTACT: parse_contact_class(_h, _p); break;
423
-	case CLASS_URI:     parse_uri_class(_h, _p);     break;
424
-	case CLASS_EVENT_DIALOG: parse_event_dialog_class(_h, _p); break;
425
-	default: break;
426
-	}
427
-}
428
-
429
-
430
-
431
-
432
-
433
-/*! \brief
434
- * Parse body of a parameter. It can be quoted string or
435
- * a single token.
436
- */
437
-static inline int parse_param_body(str* _s, param_t* _c, char separator)
438
-{
439
-	if (_s->s[0] == '\"' || _s->s[0] == '\'') {
440
-		if (parse_quoted_param(_s, &(_c->body)) < 0) {
441
-			LOG(L_ERR, "parse_param_body(): Error while parsing quoted string\n");
442
-			return -2;
443
-		}
444
-	} else {
445
-		if (parse_token_param(_s, &(_c->body), separator) < 0) {
446
-			LOG(L_ERR, "parse_param_body(): Error while parsing token\n");
447
-			return -3;
448
-		}
449
-	}
450
-
451
-	return 0;
452
-}
453
-
454
-
455
-
456
-
457
-/*!  \brief
458
- * Only parse one parameter
459
- * Returns:
460
- * 	t: out parameter
461
- * 	-1: on error
462
- * 	0: success, but expect a next paramter
463
- * 	1: success and exepect no more parameters
464
- */
465
-static inline int parse_param2(str *_s, pclass_t _c, param_hooks_t *_h, param_t *t, char separator)
466
-{
467
-	memset(t, 0, sizeof(param_t));
468
-
469
-	parse_param_name(_s, _c, _h, t, separator);
470
-	trim_leading(_s);
471
-	
472
-	if (_s->len == 0) { /* The last parameter without body */
473
-		t->len = t->name.len;
474
-		goto ok;
475
-	}
476
-	
477
-	if (_s->s[0] == '=') {
478
-		_s->s++;
479
-		_s->len--;
480
-		trim_leading(_s);
481
-
482
-		if (_s->len == 0) {
483
-		    /* Be forgiving and accept parameters with missing value,
484
-		     * we just set the length of parameter body to 0. */
485
-		    t->body.s = _s->s;
486
-		    t->body.len = 0;
487
-		} else if (parse_param_body(_s, t, separator) < 0) {
488
-			LOG(L_ERR, "parse_params(): Error while parsing param body\n");
489
-			goto error;
490
-		}
491
-
492
-		t->len = _s->s - t->name.s;
493
-
494
-		trim_leading(_s);
495
-		if (_s->len == 0) {
496
-			goto ok;
497
-		}
498
-	} else {
499
-		t->len = t->name.len;
500
-	}
501
-
502
-	if (_s->s[0] == ',') goto ok; /* To be able to parse header parameters */
503
-	if (_s->s[0] == '>') goto ok; /* To be able to parse URI parameters */
504
-
505
-	if (_s->s[0] != separator) {
506
-		LOG(L_ERR, "parse_params(): Invalid character, %c expected\n",
507
-			separator);
508
-		goto error;
509
-	}
510
-
511
-	_s->s++;
512
-	_s->len--;
513
-	trim_leading(_s);
514
-	
515
-	if (_s->len == 0) {
516
-		LOG(L_ERR, "parse_params(): Param name missing after %c\n",
517
-				separator);
518
-		goto error;
519
-	}
520
-
521
-	return 0; /* expect more params */
522
-
523
-ok:
524
-	return 1; /* done with parsing for params */
525
-error:
526
-	return -1;
527
-}
528
-
529
-/*!  \brief
530
- * Only parse one parameter
531
- * Returns:
532
- * 	t: out parameter
533
- * 	-1: on error
534
- * 	0: success, but expect a next paramter
535
- * 	1: success and exepect no more parameters
536
- */
537
-int parse_param(str *_s, pclass_t _c, param_hooks_t *_h, param_t *t)
538
-{
539
-	return parse_param2(_s, _c, _h, t, ';');
540
-}
541
-
542
-/*! \brief
543
- * Parse parameters
544
- * \param _s is string containing parameters, it will be updated to point behind the parameters
545
- * \param _c is class of parameters
546
- * \param _h is pointer to structure that will be filled with pointer to well known parameters
547
- * \param _p pointing to linked list where parsed parameters will be stored
548
- * \return 0 on success and negative number on an error
549
- */
550
-int parse_params(str* _s, pclass_t _c, param_hooks_t* _h, param_t** _p)
551
-{
552
-	return parse_params2(_s, _c, _h, _p, ';');
553
-}
554
-
555
-/*! \brief
556
- * Parse parameters with configurable separator
557
- * \param _s is string containing parameters, it will be updated to point behind the parameters
558
- * \param _c is class of parameters
559
- * \param _h is pointer to structure that will be filled with pointer to well known parameters
560
- * \param _p pointing to linked list where parsed parameters will be stored
561
- * \param separator single character separator
562
- * \return 0 on success and negative number on an error
563
- */
564
-int parse_params2(str* _s, pclass_t _c, param_hooks_t* _h, param_t** _p,
565
-			char separator)
566
-{
567
-	param_t* t;
568
-
569
-	if (!_s || !_p) {
570
-		LOG(L_ERR, "parse_params(): Invalid parameter value\n");
571
-		return -1;
572
-	}
573
-
574
-	if (_h)
575
-		memset(_h, 0, sizeof(param_hooks_t));
576
-	*_p = 0;
577
-
578
-	if (!_s->s) { /* no parameters at all -- we're done */
579
-		DBG("DEBUG: parse_params: empty uri params, skipping\n");
580
-		return 0;
581
-	}
582
-			
583
-	while(1) {
584
-		t = (param_t*)pkg_malloc(sizeof(param_t));
585
-		if (t == 0) {
586
-			LOG(L_ERR, "parse_params(): No memory left\n");
587
-			goto error;
588
-		}
589
-
590
-		switch(parse_param2(_s, _c, _h, t, separator)) {
591
-		case 0: break;
592
-		case 1: goto ok;
593
-		default: goto error;
594
-		}
595
-
596
-		t->next = *_p;
597
-		*_p = t;
598
-	}
599
-
600
- error:
601
-	if (t) pkg_free(t);
602
-	free_params(*_p);
603
-	*_p = 0;
604
-	return -2;
605
-
606
- ok:
607
-	t->next = *_p;
608
-	*_p = t;
609
-	return 0;
610
-}
611
-
612
-
613
-/*! \brief
614
- * Free linked list of parameters
615
- */
616
-static inline void do_free_params(param_t* _p, int _shm)
617
-{
618
-	param_t* ptr;
619
-	
620
-	while(_p) {
621
-		ptr = _p;
622
-		_p = _p->next;
623
-		if (_shm) shm_free(ptr);
624
-		else pkg_free(ptr);
625
-	}	
626
-}
627
-
628
-
629
-/*! \brief
630
- * Free linked list of parameters
631
- */
632
-void free_params(param_t* _p)
633
-{
634
-	do_free_params(_p, 0);
635
-}
636
-
637
-
638
-/*! \brief
639
- * Free linked list of parameters
640
- */
641
-void shm_free_params(param_t* _p)
642
-{
643
-	do_free_params(_p, 1);
644
-}
645
-
646
-
647
-/*! \brief
648
- * Print a parameter structure, just for debugging
649
- */
650
-static inline void print_param(FILE* _o, param_t* _p)
651
-{
652
-	char* type;
653
-
654
-	fprintf(_o, "---param(%p)---\n", _p);
655
-	
656
-	switch(_p->type) {
657
-	case P_OTHER:     type = "P_OTHER";     break;
658
-	case P_Q:         type = "P_Q";         break;
659
-	case P_EXPIRES:   type = "P_EXPIRES";   break;
660
-	case P_METHODS:   type = "P_METHODS";   break;
661
-	case P_TRANSPORT: type = "P_TRANSPORT"; break;
662
-	case P_LR:        type = "P_LR";        break;
663
-	case P_R2:        type = "P_R2";        break;
664
-	case P_MADDR:     type = "P_MADDR";     break;
665
-	case P_TTL:       type = "P_TTL";       break;
666
-	case P_RECEIVED:  type = "P_RECEIVED";  break;
667
-	case P_DSTIP:     type = "P_DSTIP";     break;
668
-	case P_DSTPORT:   type = "P_DSTPORT";   break;
669
-	case P_INSTANCE:  type = "P_INSTANCE";  break;
670
-	case P_FTAG:      type = "P_FTAG";      break;
671
-	case P_CALL_ID:   type = "P_CALL_ID";   break;
672
-	case P_FROM_TAG:  type = "P_FROM_TAG";  break;
673
-	case P_TO_TAG:    type = "P_TO_TAG";    break;
674
-	case P_ISD:       type = "P_ISD";       break;
675
-	case P_SLA:       type = "P_SLA";       break;
676
-	default:          type = "UNKNOWN";     break;
677
-	}
678
-	
679
-	fprintf(_o, "type: %s\n", type);
680
-	fprintf(_o, "name: \'%.*s\'\n", _p->name.len, _p->name.s);
681
-	fprintf(_o, "body: \'%.*s\'\n", _p->body.len, _p->body.s);
682
-	fprintf(_o, "len : %d\n", _p->len);
683
-	fprintf(_o, "---/param---\n");
684
-}
685
-
686
-
687
-/*! \brief
688
- * Print linked list of parameters, just for debugging
689
- */
690
-void print_params(FILE* _o, param_t* _p)
691
-{
692
-	param_t* ptr;
693
-	
694
-	ptr = _p;
695
-	while(ptr) {
696
-		print_param(_o, ptr);
697
-		ptr = ptr->next;
698
-	}
699
-}
700
-
701
-
702
-/*! \brief
703
- * Duplicate linked list of parameters
704
- */
705
-static inline int do_duplicate_params(param_t** _n, param_t* _p, int _shm)
706
-{
707
-	param_t* last, *ptr, *t;
708
-
709
-	if (!_n) {
710
-		LOG(L_ERR, "duplicate_params(): Invalid parameter value\n");
711
-		return -1;
712
-	}
713
-	
714
-	last = 0;
715
-	*_n = 0;
716
-	ptr = _p;
717
-	while(ptr) {
718
-		if (_shm) {
719
-			t = (param_t*)shm_malloc(sizeof(param_t));
720
-		} else {
721
-			t = (param_t*)pkg_malloc(sizeof(param_t));
722
-		}
723
-		if (!t) {
724
-			LOG(L_ERR, "duplicate_params(): Invalid parameter value\n");
725
-			goto err;
726
-		}
727
-		memcpy(t, ptr, sizeof(param_t));
728
-		t->next = 0;
729
-
730
-		if (!*_n) *_n = t;
731
-		if (last) last->next = t;
732
-		last = t;
733
-
734
-		ptr = ptr->next;
735
-	}
736
-	return 0;
737
-
738
- err:
739
-	do_free_params(*_n, _shm);
740
-	return -2;
741
-}
742
-
743
-
744
-/*! \brief
745
- * Duplicate linked list of parameters
746
- */
747
-int duplicate_params(param_t** _n, param_t* _p)
748
-{
749
-	return do_duplicate_params(_n, _p, 0);
750
-}
751
-
752
-
753
-/*! \brief
754
- * Duplicate linked list of parameters
755
- */
756
-int shm_duplicate_params(param_t** _n, param_t* _p)
757
-{
758
-	return do_duplicate_params(_n, _p, 1);
759
-}
Browse code

core: parser - remove inline for parse_param()

- it gets recent compiler warnings when is an extern object
- reported by Victor Seva, GH#286

Daniel-Constantin Mierla authored on 02/11/2015 15:19:44
Showing 1 changed files
... ...
@@ -534,7 +534,7 @@ error:
534 534
  * 	0: success, but expect a next paramter
535 535
  * 	1: success and exepect no more parameters
536 536
  */
537
-inline int parse_param(str *_s, pclass_t _c, param_hooks_t *_h, param_t *t)
537
+int parse_param(str *_s, pclass_t _c, param_hooks_t *_h, param_t *t)
538 538
 {
539 539
 	return parse_param2(_s, _c, _h, t, ';');
540 540
 }
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
... ...
@@ -3,14 +3,14 @@
3 3
  *
4 4
  * Copyright (C) 2001-2003 FhG Fokus
5 5
  *
6
- * This file is part of ser, a free SIP server.
6
+ * This file is part of Kamailio, a free SIP server.
7 7
  *
8
- * ser is free software; you can redistribute it and/or modify
8
+ * Kamailio is free software; you can redistribute it and/or modify
9 9
  * it under the terms of the GNU General Public License as published by
10 10
  * the Free Software Foundation; either version 2 of the License, or
11 11
  * (at your option) any later version
12 12
  *
13
- * ser is distributed in the hope that it will be useful,
13
+ * Kamailio is distributed in the hope that it will be useful,
14 14
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 15
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 16
  * GNU General Public License for more details.
... ...
@@ -19,11 +19,6 @@
19 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
- * History:
23
- * -------
24
- * 2003-03-24 Created by janakj
25
- * 2003-04-07 shm duplication added (janakj)
26
- * 2003-04-07 URI class added (janakj)
27 22
  */
28 23
 
29 24
 /*! \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
... ...
@@ -17,7 +17,7 @@
17 17
  *
18 18
  * You should have received a copy of the GNU General Public License 
19 19
  * along with this program; if not, write to the Free Software 
20
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 21
  *
22 22
  * History:
23 23
  * -------
Browse code

core: updated parse_param so that the delimiter for parameters can be user-defined

Peter Dunkley authored on 25/09/2013 15:11:23
Showing 1 changed files
... ...
@@ -331,7 +331,7 @@ static inline int parse_quoted_param(str* _s, str* _r)
331 331
  * let _r point to the token and update _s
332 332
  * to point right behind the token
333 333
  */
334
-static inline int parse_token_param(str* _s, str* _r)
334
+static inline int parse_token_param(str* _s, str* _r, char separator)
335 335
 {
336 336
 	int i;
337 337
 
... ...
@@ -361,12 +361,14 @@ static inline int parse_token_param(str* _s, str* _r)
361 361
 		case '\r':
362 362
 		case '\n':
363 363
 		case ',':
364
-		case ';':
365 364
 			     /* So if you find
366 365
 			      * any of them
367 366
 			      * stop iterating
368 367
 			      */
369 368
 			goto out;
369
+		default:
370
+			if(_s->s[i] == separator)
371
+				goto out;
370 372
 		}
371 373
 	}
372 374
  out:
... ...
@@ -391,7 +393,7 @@ static inline int parse_token_param(str* _s, str* _r)
391 393
 /*! \brief
392 394
  * Parse a parameter name
393 395
  */
394
-static inline void parse_param_name(str* _s, pclass_t _c, param_hooks_t* _h, param_t* _p)
396
+static inline void parse_param_name(str* _s, pclass_t _c, param_hooks_t* _h, param_t* _p, char separator)
395 397
 {
396 398
 
397 399
 	if (!_s->s) {
... ...
@@ -407,10 +409,12 @@ static inline void parse_param_name(str* _s, pclass_t _c, param_hooks_t* _h, par
407 409
 		case '\t':
408 410
 		case '\r':
409 411
 		case '\n':
410
-		case ';':
411 412
 		case ',':
412 413
 		case '=':
413 414
 			goto out;
415
+		default:
416
+			if (_s->s[0] == separator)
417
+				goto out;
414 418
 		}
415 419
 		_s->s++;
416 420
 		_s->len--;
... ...
@@ -435,7 +439,7 @@ static inline void parse_param_name(str* _s, pclass_t _c, param_hooks_t* _h, par
435 439
  * Parse body of a parameter. It can be quoted string or
436 440
  * a single token.
437 441
  */
438
-static inline int parse_param_body(str* _s, param_t* _c)
442
+static inline int parse_param_body(str* _s, param_t* _c, char separator)
439 443
 {
440 444
 	if (_s->s[0] == '\"' || _s->s[0] == '\'') {
441 445
 		if (parse_quoted_param(_s, &(_c->body)) < 0) {
... ...
@@ -443,7 +447,7 @@ static inline int parse_param_body(str* _s, param_t* _c)
443 447
 			return -2;
444 448
 		}
445 449
 	} else {
446
-		if (parse_token_param(_s, &(_c->body)) < 0) {
450
+		if (parse_token_param(_s, &(_c->body), separator) < 0) {
447 451
 			LOG(L_ERR, "parse_param_body(): Error while parsing token\n");
448 452
 			return -3;
449 453
 		}
... ...
@@ -453,6 +457,8 @@ static inline int parse_param_body(str* _s, param_t* _c)
453 457
 }
454 458
 
455 459
 
460
+
461
+
456 462
 /*!  \brief
457 463
  * Only parse one parameter
458 464
  * Returns:
... ...
@@ -461,11 +467,11 @@ static inline int parse_param_body(str* _s, param_t* _c)
461 467
  * 	0: success, but expect a next paramter
462 468
  * 	1: success and exepect no more parameters
463 469
  */
464
-inline int parse_param(str *_s, pclass_t _c, param_hooks_t *_h, param_t *t)
470
+static inline int parse_param2(str *_s, pclass_t _c, param_hooks_t *_h, param_t *t, char separator)
465 471
 {
466 472
 	memset(t, 0, sizeof(param_t));
467 473
 
468
-	parse_param_name(_s, _c, _h, t);
474
+	parse_param_name(_s, _c, _h, t, separator);
469 475
 	trim_leading(_s);
470 476
 	
471 477
 	if (_s->len == 0) { /* The last parameter without body */
... ...
@@ -483,7 +489,7 @@ inline int parse_param(str *_s, pclass_t _c, param_hooks_t *_h, param_t *t)
483 489
 		     * we just set the length of parameter body to 0. */
484 490
 		    t->body.s = _s->s;
485 491
 		    t->body.len = 0;
486
-		} else if (parse_param_body(_s, t) < 0) {
492
+		} else if (parse_param_body(_s, t, separator) < 0) {
487 493
 			LOG(L_ERR, "parse_params(): Error while parsing param body\n");
488 494
 			goto error;
489 495
 		}
... ...
@@ -501,8 +507,9 @@ inline int parse_param(str *_s, pclass_t _c, param_hooks_t *_h, param_t *t)
501