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,2063 +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 Kamailio core :: PV API specification
24
- * \ingroup core
25
- * Module: \ref core
26
- */
27
-
28
-
29
-#include <stdio.h>
30
-#include <string.h>
31
-#include <sys/types.h>
32
-#include <unistd.h>
33
-
34
-#include "mem/mem.h"
35
-#include "mem/shm_mem.h"
36
-#include "ut.h"
37
-#include "dprint.h"
38
-#include "hashes.h"
39
-#include "route.h"
40
-#include "pvapi.h"
41
-#include "pvar.h"
42
-
43
-#define PV_TABLE_SIZE	32  /*!< pseudo-variables table size */
44
-#define TR_TABLE_SIZE	16  /*!< transformations table size */
45
-
46
-
47
-void tr_destroy(trans_t *t);
48
-void tr_free(trans_t *t);
49
-
50
-typedef struct _pv_item
51
-{
52
-	pv_export_t pve;
53
-	unsigned int pvid;
54
-	struct _pv_item *next;
55
-} pv_item_t, *pv_item_p;
56
-
57
-static pv_item_t* _pv_table[PV_TABLE_SIZE];
58
-static int _pv_table_set = 0;
59
-
60
-static pv_cache_t* _pv_cache[PV_CACHE_SIZE];
61
-static int _pv_cache_set = 0;
62
-
63
-/**
64
- *
65
- */
66
-void pv_init_table(void)
67
-{
68
-	memset(_pv_table, 0, sizeof(pv_item_t*)*PV_TABLE_SIZE);
69
-	_pv_table_set = 1;
70
-}
71
-
72
-/**
73
- *
74
- */
75
-void pv_init_cache(void)
76
-{
77
-	memset(_pv_cache, 0, sizeof(pv_cache_t*)*PV_CACHE_SIZE);
78
-	_pv_cache_set = 1;
79
-}
80
-
81
-/**
82
- *
83
- */
84
-pv_cache_t **pv_cache_get_table(void)
85
-{
86
-	if(_pv_cache_set==1) return _pv_cache;
87
-	return NULL;
88
-}
89
-
90
-/**
91
- * @brief Check if a char is valid according to the PV syntax
92
- * @param c checked char
93
- * @return 1 if char is valid, 0 if not valid
94
- */
95
-static int is_pv_valid_char(char c)
96
-{
97
-	if((c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z')
98
-			|| (c=='_') || (c=='.') || (c=='?') /* ser $? */)
99
-		return 1;
100
-	return 0;
101
-}
102
-
103
-/**
104
- *
105
- */
106
-int pv_locate_name(str *in)
107
-{
108
-	int i;
109
-	int pcount;
110
-
111
-	if(in==NULL || in->s==NULL || in->len<2)
112
-	{
113
-		LM_ERR("bad parameters\n");
114
-		return -1;
115
-	}
116
-
117
-	if(in->s[0]!=PV_MARKER)
118
-	{
119
-		LM_ERR("missing pv marker [%.*s]\n", in->len, in->s);
120
-		return -1;
121
-	}
122
-	if(in->s[1]==PV_MARKER)
123
-	{
124
-		return 2;
125
-	}
126
-	pcount = 0;
127
-	if(in->s[1]==PV_LNBRACKET)
128
-	{
129
-		/* name with parenthesis: $(...) */
130
-		pcount = 1;
131
-		for(i=2; i<in->len; i++)
132
-		{
133
-			if(in->s[i]==PV_LNBRACKET)
134
-				pcount++;
135
-			else if(in->s[i]==PV_RNBRACKET)
136
-				pcount--;
137
-			if(pcount==0)
138
-				return i+1;
139
-		}
140
-		/* non-closing name parenthesis */
141
-		LM_ERR("non-closing name parenthesis [%.*s]\n",in->len,in->s);
142
-		return -1;
143
-	}
144
-
145
-	/* name without parenthesis: $xyz(...) */
146
-	for(i=1; i<in->len; i++)
147
-	{
148
-		if(!is_pv_valid_char(in->s[i]))
149
-		{
150
-			if(in->s[i]==PV_LNBRACKET)
151
-			{
152
-				/* inner-name parenthesis */
153
-				pcount = 1;
154
-				break;
155
-			} else {
156
-				return i;
157
-			}
158
-		}
159
-	}
160
-	if(pcount==0)
161
-		return i;
162
-
163
-	i++;
164
-	for( ; i<in->len; i++)
165
-	{
166
-		if(in->s[i]==PV_LNBRACKET)
167
-			pcount++;
168
-		else if(in->s[i]==PV_RNBRACKET)
169
-			pcount--;
170
-		if(pcount==0)
171
-			return i+1;
172
-	}
173
-	/* non-closing inner-name parenthesis */
174
-	LM_ERR("non-closing inner-name parenthesis [%.*s]\n",in->len,in->s);
175
-	return -1;
176
-}
177
-
178
-/**
179
- *
180
- */
181
-int pv_table_add(pv_export_t *e)
182
-{
183
-	char *p;
184
-	str  *in;
185
-	pv_item_t *pvi = NULL;
186
-	pv_item_t *pvj = NULL;
187
-	pv_item_t *pvn = NULL;
188
-	int found;
189
-	unsigned int pvid;
190
-
191
-	if(e==NULL || e->name.s==NULL || e->getf==NULL || e->type==PVT_NONE)
192
-	{
193
-		LM_ERR("invalid parameters\n");
194
-		return -1;
195
-	}
196
-
197
-	if(_pv_table_set==0)
198
-	{
199
-		LM_DBG("PV table not initialized, doing it now\n");
200
-		pv_init_table();
201
-	}
202
-	in = &(e->name);
203
-	p = in->s;
204
-	while(is_in_str(p,in) && is_pv_valid_char(*p))
205
-		p++;
206
-	if(is_in_str(p,in))
207
-	{
208
-		LM_ERR("invalid char [%c] in [%.*s]\n", *p, in->len, in->s);
209
-		return -1;
210
-	}
211
-	found = 0;
212
-	//pvid = get_hash1_raw(in->s, in->len);
213
-	pvid = get_hash1_raw(in->s, in->len);
214
-
215
-	pvi = _pv_table[pvid%PV_TABLE_SIZE];
216
-	while(pvi)
217
-	{
218
-		if(pvi->pvid > pvid)
219
-			break;
220
-		if(pvi->pve.name.len==in->len)
221
-		{
222
-			found = strncmp(pvi->pve.name.s, in->s, in->len);
223
-
224
-			if(found==0)
225
-			{
226
-				LM_ERR("pvar [%.*s] already exists\n", in->len, in->s);
227
-				return -1;
228
-			}
229
-		}
230
-		pvj = pvi;
231
-		pvi = pvi->next;
232
-	}
233
-
234
-	pvn = (pv_item_t*)pkg_malloc(sizeof(pv_item_t));
235
-	if(pvn==0)
236
-	{
237
-		LM_ERR("no more memory\n");
238
-		return -1;
239
-	}
240
-	memset(pvn, 0, sizeof(pv_item_t));
241
-	memcpy(&(pvn->pve), e, sizeof(pv_export_t));
242
-	pvn->pvid = pvid;
243
-
244
-	if(pvj==0)
245
-	{
246
-		pvn->next = _pv_table[pvid%PV_TABLE_SIZE];
247
-		_pv_table[pvid%PV_TABLE_SIZE] = pvn;
248
-		goto done;
249
-	}
250
-	pvn->next = pvj->next;
251
-	pvj->next = pvn;
252
-
253
-done:
254
-	return 0;
255
-}
256
-
257
-/**
258
- *
259
- */
260
-pv_spec_t* pv_cache_add(str *name)
261
-{
262
-	pv_cache_t *pvn;
263
-	unsigned int pvid;
264
-	char *p;
265
-
266
-	if(_pv_cache_set==0)
267
-	{
268
-		LM_DBG("PV cache not initialized, doing it now\n");
269
-		pv_init_cache();
270
-	}
271
-	pvid = get_hash1_raw(name->s, name->len);
272
-	pvn = (pv_cache_t*)pkg_malloc(sizeof(pv_cache_t) + name->len + 1);
273
-	if(pvn==0)
274
-	{
275
-		LM_ERR("no more memory\n");
276
-		return NULL;
277
-	}
278
-	memset(pvn, 0, sizeof(pv_cache_t) + name->len + 1);
279
-	pvn->pvname.len = name->len;
280
-	pvn->pvname.s = (char*)pvn + sizeof(pv_cache_t);
281
-	memcpy(pvn->pvname.s, name->s, name->len);
282
-	p = pv_parse_spec(&pvn->pvname, &pvn->spec);
283
-
284
-	if(p==NULL)
285
-	{
286
-		pkg_free(pvn);
287
-		return NULL;
288
-	}
289
-	pvn->pvid = pvid;
290
-	pvn->next = _pv_cache[pvid%PV_CACHE_SIZE];
291
-	_pv_cache[pvid%PV_CACHE_SIZE] = pvn;
292
-
293
-	LM_DBG("pvar [%.*s] added in cache\n", name->len, name->s);
294
-	return &pvn->spec;
295
-}
296
-
297
-/**
298
- *
299
- */
300
-pv_spec_t* pv_cache_lookup(str *name)
301
-{
302
-	pv_cache_t *pvi;
303
-	unsigned int pvid;
304
-	int found;
305
-
306
-	if(_pv_cache_set==0)
307
-		return NULL;
308
-
309
-	pvid = get_hash1_raw(name->s, name->len);
310
-	pvi = _pv_cache[pvid%PV_CACHE_SIZE];
311
-	while(pvi)
312
-	{
313
-		if(pvi->pvid == pvid) {
314
-			if(pvi->pvname.len==name->len)
315
-			{
316
-				found = strncmp(pvi->pvname.s, name->s, name->len);
317
-
318
-				if(found==0)
319
-				{
320
-					LM_DBG("pvar [%.*s] found in cache\n",
321
-							name->len, name->s);
322
-					return &pvi->spec;
323
-				}
324
-			}
325
-		}
326
-		pvi = pvi->next;
327
-	}
328
-	return NULL;
329
-}
330
-
331
-/**
332
- *
333
- */
334
-pv_spec_t* pv_cache_get(str *name)
335
-{
336
-	pv_spec_t *pvs;
337
-	str tname;
338
-
339
-	if(name->s==NULL || name->len==0)
340
-	{
341
-		LM_ERR("invalid parameters\n");
342
-		return NULL;
343
-	}
344
-
345
-	tname.s = name->s;
346
-	tname.len = pv_locate_name(name);
347
-
348
-	if(tname.len < 0)
349
-		return NULL;
350
-
351
-	pvs = pv_cache_lookup(&tname);
352
-
353
-	if(pvs!=NULL)
354
-		return pvs;
355
-
356
-	return pv_cache_add(&tname);
357
-}
358
-
359
-str* pv_cache_get_name(pv_spec_t *spec)
360
-{
361
-	int i;
362
-	pv_cache_t *pvi;
363
-	if(spec==NULL)
364
-	{
365
-		LM_ERR("invalid parameters\n");
366
-		return NULL;
367
-	}
368
-
369
-	if(_pv_cache_set==0)
370
-		return NULL;
371
-
372
-	for(i=0;i<PV_CACHE_SIZE;i++)
373
-	{
374
-		pvi = _pv_cache[i];
375
-		while(pvi)
376
-		{
377
-			if(&pvi->spec == spec)
378
-			{
379
-				LM_DBG("pvar[%p]->name[%.*s] found in cache\n", spec,
380
-					pvi->pvname.len, pvi->pvname.s);
381
-				return &pvi->pvname;
382
-			}
383
-			pvi = pvi->next;
384
-		}
385
-	}
386
-	return NULL;
387
-}
388
-
389
-/**
390
- *
391
- */
392
-pv_spec_t* pv_spec_lookup(str *name, int *len)
393
-{
394
-	pv_spec_t *pvs;
395
-	str tname;
396
-
397
-	if(len!=NULL)
398
-		*len = 0;
399
-	if(name->s==NULL || name->len==0)
400
-	{
401
-		LM_ERR("invalid parameters\n");
402
-		return NULL;
403
-	}
404
-
405
-	tname.s = name->s;
406
-	tname.len = pv_locate_name(name);
407
-
408
-	if(tname.len < 0)
409
-		return NULL;
410
-
411
-	if(len!=NULL)
412
-		*len = tname.len;
413
-
414
-	pvs = pv_cache_lookup(&tname);
415
-
416
-	if(pvs!=NULL)
417
-		return pvs;
418
-
419
-	LM_DBG("PV <%.*s> is not in cache\n", tname.len, tname.s);
420
-	return pv_cache_add(&tname);
421
-}
422
-
423
-/**
424
- *
425
- */
426
-int register_pvars_mod(char *mod_name, pv_export_t *items)
427
-{
428
-	int ret;
429
-	int i;
430
-
431
-	if (items==0)
432
-		return 0;
433
-
434
-	for ( i=0 ; items[i].name.s ; i++ ) {
435
-		ret = pv_table_add(&items[i]);
436
-		if (ret!=0) {
437
-			LM_ERR("failed to register pseudo-variable <%.*s> for module %s\n",
438
-					items[i].name.len, items[i].name.s, mod_name);
439
-		}
440
-	}
441
-	return 0;
442
-}
443
-
444
-/**
445
- *
446
- */
447
-int pv_table_free(void)
448
-{
449
-	pv_item_p xe;
450
-	pv_item_p xe1;
451
-	int i;
452
-
453
-	for(i=0; i<PV_TABLE_SIZE; i++)
454
-	{
455
-		xe = _pv_table[i];
456
-		while(xe!=0)
457
-		{
458
-			xe1 = xe;
459
-			xe = xe->next;
460
-			pkg_free(xe1);
461
-		}
462
-	}
463
-	memset(_pv_table, 0, sizeof(pv_item_t*)*PV_TABLE_SIZE);
464
-	_pv_table_set = 0;
465
-
466
-	return 0;
467
-}
468
-
469
-/********** helper functions ********/
470
-/**
471
- * convert unsigned int to pv_value_t
472
- */
473
-int pv_get_uintval(struct sip_msg *msg, pv_param_t *param,
474
-		pv_value_t *res, unsigned int uival)
475
-{
476
-	int l = 0;
477
-	char *ch = NULL;
478
-
479
-	if(res==NULL)
480
-		return -1;
481
-
482
-	ch = int2str(uival, &l);
483
-	res->rs.s = ch;
484
-	res->rs.len = l;
485
-
486
-	res->ri = (int)uival;
487
-	res->flags = PV_VAL_STR|PV_VAL_INT|PV_TYPE_INT;
488
-	return 0;
489
-}
490
-
491
-/**
492
- * convert signed int to pv_value_t
493
- */
494
-int pv_get_sintval(struct sip_msg *msg, pv_param_t *param,
495
-		pv_value_t *res, int sival)
496
-{
497
-	int l = 0;
498
-	char *ch = NULL;
499
-
500
-	if(res==NULL)
501
-		return -1;
502
-
503
-	ch = sint2str(sival, &l);
504
-	res->rs.s = ch;
505
-	res->rs.len = l;
506
-
507
-	res->ri = sival;
508
-	res->flags = PV_VAL_STR|PV_VAL_INT|PV_TYPE_INT;
509
-	return 0;
510
-}
511
-
512
-/**
513
- * convert str to pv_value_t
514
- */
515
-int pv_get_strval(struct sip_msg *msg, pv_param_t *param,
516
-		pv_value_t *res, str *sval)
517
-{
518
-	if(res==NULL)
519
-		return -1;
520
-
521
-	res->rs = *sval;
522
-	res->flags = PV_VAL_STR;
523
-	return 0;
524
-}
525
-
526
-/**
527
- * convert strz to pv_value_t
528
- */
529
-int pv_get_strzval(struct sip_msg *msg, pv_param_t *param,
530
-		pv_value_t *res, char *sval)
531
-{
532
-	if(res==NULL)
533
-		return -1;
534
-
535
-	res->rs.s = sval;
536
-	res->rs.len = strlen(sval);
537
-	res->flags = PV_VAL_STR;
538
-	return 0;
539
-}
540
-
541
-/**
542
- * convert char* with len to pv_value_t
543
- */
544
-int pv_get_strlval(struct sip_msg *msg, pv_param_t *param,
545
-		pv_value_t *res, char *sval, int slen)
546
-{
547
-	if(res==NULL)
548
-		return -1;
549
-
550
-	res->rs.s = sval;
551
-	res->rs.len = slen;
552
-	res->flags = PV_VAL_STR;
553
-	return 0;
554
-}
555
-
556
-/**
557
- * convert str-int to pv_value_t (type is str)
558
- */
559
-int pv_get_strintval(struct sip_msg *msg, pv_param_t *param,
560
-		pv_value_t *res, str *sval, int ival)
561
-{
562
-	if(res==NULL)
563
-		return -1;
564
-
565
-	res->rs = *sval;
566
-	res->ri = ival;
567
-	res->flags = PV_VAL_STR|PV_VAL_INT;
568
-	return 0;
569
-}
570
-
571
-/**
572
- * convert int-str to pv_value_t (type is int)
573
- */
574
-int pv_get_intstrval(struct sip_msg *msg, pv_param_t *param,
575
-		pv_value_t *res, int ival, str *sval)
576
-{
577
-	if(res==NULL)
578
-		return -1;
579
-
580
-	res->rs = *sval;
581
-	res->ri = ival;
582
-	res->flags = PV_VAL_STR|PV_VAL_INT|PV_TYPE_INT;
583
-	return 0;
584
-}
585
-
586
-/*** ============================= ***/
587
-static str pv_str_marker = { PV_MARKER_STR, 1 };
588
-static int pv_get_marker(struct sip_msg *msg, pv_param_t *param,
589
-		pv_value_t *res)
590
-{
591
-	return pv_get_strintval(msg, param, res, &pv_str_marker,
592
-			(int)pv_str_marker.s[0]);
593
-}
594
-
595
-static char pv_str_empty_buf[2];
596
-static char pv_str_null_buf[8];
597
-
598
-static str pv_str_empty  = { "", 0 };
599
-static str pv_str_null   = { "<null>", 6 };
600
-int pv_get_null(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
601
-{
602
-	if(res==NULL)
603
-		return -1;
604
-
605
-	res->rs = pv_str_empty;
606
-	res->ri = 0;
607
-	res->flags = PV_VAL_NULL;
608
-	return 0;
609
-}
610
-
611
-/**
612
- *
613
- */
614
-int pv_get_strempty(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
615
-{
616
-	if(res==NULL)
617
-		return -1;
618
-
619
-	res->rs = pv_str_empty;
620
-	res->ri = 0;
621
-	res->flags = PV_VAL_STR;
622
-	return 0;
623
-}
624
-
625
-
626
-/**
627
- *
628
- */
629
-pv_export_t* pv_lookup_spec_name(str *pvname, pv_spec_p e)
630
-{
631
-	pv_item_t *pvi;
632
-	unsigned int pvid;
633
-
634
-	if(pvname==0 || e==0)
635
-	{
636
-		LM_ERR("bad parameters\n");
637
-		return NULL;
638
-	}
639
-
640
-	/* search in PV table */
641
-	// pvid = get_hash1_raw(pvname->s, pvname->len);
642
-	pvid = get_hash1_raw(pvname->s, pvname->len);
643
-	pvi = _pv_table[pvid%PV_TABLE_SIZE];
644
-	while(pvi)
645
-	{
646
-		if(pvi->pvid > pvid)
647
-			break;
648
-
649
-		if(pvi->pvid==pvid && pvi->pve.name.len==pvname->len
650
-			&& memcmp(pvi->pve.name.s, pvname->s, pvname->len)==0)
651
-		{
652
-			/*LM_DBG("found [%.*s] [%d]\n", pvname->len, pvname->s,
653
-					_pv_names_table[i].type);*/
654
-			/* copy data from table to spec */
655
-			e->type = pvi->pve.type;
656
-			e->getf = pvi->pve.getf;
657
-			e->setf = pvi->pve.setf;
658
-			return &(pvi->pve);
659
-		}
660
-		pvi = pvi->next;
661
-	}
662
-
663
-	return NULL;
664
-}
665
-
666
-/**
667
- *
668
- */
669
-int pv_parse_index(pv_spec_p sp, str *in)
670
-{
671
-	char *p;
672
-	char *s;
673
-	int sign;
674
-	pv_spec_p nsp = 0;
675
-
676
-	if(in==NULL || in->s==NULL || sp==NULL)
677
-		return -1;
678
-	p = in->s;
679
-	if(*p==PV_MARKER)
680
-	{
681
-		nsp = (pv_spec_p)pkg_malloc(sizeof(pv_spec_t));
682
-		if(nsp==NULL)
683
-		{
684
-			LM_ERR("no more memory\n");
685
-			return -1;
686
-		}
687
-		s = pv_parse_spec(in, nsp);
688
-		if(s==NULL)
689
-		{
690
-			LM_ERR("invalid index [%.*s]\n", in->len, in->s);
691
-			pv_spec_free(nsp);
692
-			return -1;
693
-		}
694
-		sp->pvp.pvi.type = PV_IDX_PVAR;
695
-		sp->pvp.pvi.u.dval = (void*)nsp;
696
-		return 0;
697
-	}
698
-	if(*p=='*' && in->len==1)
699
-	{
700
-		sp->pvp.pvi.type = PV_IDX_ALL;
701
-		return 0;
702
-	}
703
-	if(*p=='+' && in->len==1)
704
-	{
705
-		sp->pvp.pvi.type = PV_IDX_ITR;
706
-		return 0;
707
-	}
708
-	sign = 1;
709
-	if(*p=='-')
710
-	{
711
-		sign = -1;
712
-		p++;
713
-	}
714
-	sp->pvp.pvi.u.ival = 0;
715
-	while(p<in->s+in->len && *p>='0' && *p<='9')
716
-	{
717
-		sp->pvp.pvi.u.ival = sp->pvp.pvi.u.ival * 10 + *p - '0';
718
-		p++;
719
-	}
720
-	if(p!=in->s+in->len)
721
-	{
722
-		LM_ERR("invalid index [%.*s]\n", in->len, in->s);
723
-		return -1;
724
-	}
725
-	sp->pvp.pvi.u.ival *= sign;
726
-	sp->pvp.pvi.type = PV_IDX_INT;
727
-	return 0;
728
-}
729
-
730
-/**
731
- *
732
- */
733
-int pv_init_iname(pv_spec_p sp, int param)
734
-{
735
-	if(sp==NULL)
736
-		return -1;
737
-	sp->pvp.pvn.type = PV_NAME_INTSTR;
738
-	sp->pvp.pvn.u.isname.name.n = param;
739
-	return 0;
740
-}
741
-
742
-/**
743
- *
744
- */
745
-char* pv_parse_spec2(str *in, pv_spec_p e, int silent)
746
-{
747
-	char *p;
748
-	str s;
749
-	str pvname;
750
-	int pvstate;
751
-	trans_t *tr = NULL;
752
-	pv_export_t *pte = NULL;
753
-	int n=0;
754
-
755
-	if(in==NULL || in->s==NULL || e==NULL || *in->s!=PV_MARKER)
756
-	{
757
-		if (!silent) LM_ERR("bad parameters\n");
758
-		return NULL;
759
-	}
760
-
761
-	/* LM_DBG("***** input [%.*s] (%d)\n", in->len, in->s, in->len); */
762
-	tr = 0;
763
-	pvstate = 0;
764
-	memset(e, 0, sizeof(pv_spec_t));
765
-	p = in->s;
766
-	p++;
767
-	if(*p==PV_LNBRACKET)
768
-	{
769
-		p++;
770
-		pvstate = 1;
771
-	}
772
-	pvname.s = p;
773
-	if(*p == PV_MARKER) {
774
-		p++;
775
-		if(pvstate==1)
776
-		{
777
-			if(*p!=PV_RNBRACKET)
778
-				goto error;
779
-			p++;
780
-		}
781
-		e->getf = pv_get_marker;
782
-		e->type = PVT_MARKER;
783
-		pvname.len = 1;
784
-		goto done_all;
785
-	}
786
-	while(is_in_str(p,in) && is_pv_valid_char(*p))
787
-		p++;
788
-	pvname.len = p - pvname.s;
789
-	if(pvstate==1)
790
-	{
791
-		if(*p==PV_RNBRACKET)
792
-		{ /* full pv name ended here*/
793
-			goto done_inm;
794
-		} else if(*p==PV_LNBRACKET) {
795
-			p++;
796
-			pvstate = 2;
797
-		} else if(*p==PV_LIBRACKET) {
798
-			p++;
799
-			pvstate = 3;
800
-		} else if(*p==TR_LBRACKET) {
801
-			p++;
802
-			pvstate = 4;
803
-		} else {
804
-			if (!silent)
805
-				LM_ERR("invalid char '%c' in [%.*s] (%d)\n",
806
-							*p, in->len, in->s, pvstate);
807
-			goto error;
808
-		}
809
-	} else {
810
-		if(!is_in_str(p, in)) {
811
-			p--;
812
-			goto done_inm;
813
-		} else if(*p==PV_LNBRACKET) {
814
-			p++;
815
-			pvstate = 5;
816
-		} else {
817
-			/* still in input str, but end of PV */
818
-			/* p is increased at the end, so decrement here */
819
-			p--;
820
-			goto done_inm;
821
-		}
822
-	}
823
-
824
-done_inm:
825
-	if((pte = pv_lookup_spec_name(&pvname, e))==NULL)
826
-	{
827
-		if (!silent)
828
-			LM_ERR("error searching pvar \"%.*s\"\n", pvname.len, pvname.s);
829
-		goto error;
830
-	}
831
-	if(pte->parse_name!=NULL && pvstate!=2 && pvstate!=5)
832
-	{
833
-		if (!silent)
834
-			LM_ERR("pvar \"%.*s\" expects an inner name\n",
835
-						pvname.len, pvname.s);
836
-		goto error;
837
-	}
838
-	if(pvstate==2 || pvstate==5)
839
-	{
840
-		if(pte->parse_name==NULL)
841
-		{
842
-			if (!silent)
843
-				LM_ERR("pvar \"%.*s\" does not get name param\n",
844
-						pvname.len, pvname.s);
845
-			goto error;
846
-		}
847
-		s.s = p;
848
-		n = 0;
849
-		while(is_in_str(p, in))
850
-		{
851
-			if(*p==PV_RNBRACKET)
852
-			{
853
-				if(n==0)
854
-					break;
855
-				n--;
856
-			}
857
-			if(*p == PV_LNBRACKET)
858
-				n++;
859
-			p++;
860
-		}
861
-
862
-		if(!is_in_str(p, in))
863
-			goto error;
864
-
865
-		if(p==s.s)
866
-		{
867
-			if (!silent)
868
-				LM_ERR("pvar \"%.*s\" does not get empty name param\n",
869
-						pvname.len, pvname.s);
870
-			goto error;
871
-		}
872
-		s.len = p - s.s;
873
-		if(pte->parse_name(e, &s)!=0)
874
-		{
875
-			if (!silent)
876
-				LM_ERR("pvar \"%.*s\" has an invalid name param [%.*s]\n",
877
-						pvname.len, pvname.s, s.len, s.s);
878
-			goto error;
879
-		}
880
-		if(pvstate==2)
881
-		{
882
-			p++;
883
-			if(*p==PV_RNBRACKET)
884
-			{ /* full pv name ended here*/
885
-				goto done_vnm;
886
-			} else if(*p==PV_LIBRACKET) {
887
-				p++;
888
-				pvstate = 3;
889
-			} else if(*p==TR_LBRACKET) {
890
-				p++;
891
-				pvstate = 4;
892
-			} else {
893
-				if (!silent)
894
-					LM_ERR("invalid char '%c' in [%.*s] (%d)\n",
895
-								*p, in->len, in->s, pvstate);
896
-				goto error;
897
-			}
898
-		} else {
899
-			if(*p==PV_RNBRACKET)
900
-			{ /* full pv name ended here*/
901
-				p++;
902
-				goto done_all;
903
-			} else {
904
-				if (!silent)
905
-					LM_ERR("invalid char '%c' in [%.*s] (%d)\n",
906
-								*p, in->len, in->s, pvstate);
907
-				goto error;
908
-			}
909
-		}
910
-	}
911
-done_vnm: