Browse code

Merge commit 'origin/daniel/pv'

* commit 'origin/daniel/pv':
more PV API integration
PV get null helper added
updated pvar.h file according to previous commit
pseudo-variable engine api

Andrei Pelinescu-Onciul authored on 24/11/2008 13:18:03
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,1192 @@
1
+/*
2
+ * $Id$
3
+ *
4
+ * Copyright (C) 2001-2003 FhG Fokus
5
+ *
6
+ * This file is part of SIP-Router, a free SIP server.
7
+ *
8
+ * SIP-Router 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
+ * SIP-Router 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
+ */
22
+
23
+/*!
24
+ * \file
25
+ * \brief PV API specification
26
+ */
27
+
28
+#include <stdio.h>
29
+#include <string.h>
30
+#include <sys/types.h>
31
+#include <unistd.h>
32
+
33
+#include "mem/mem.h"
34
+#include "mem/shm_mem.h"
35
+#include "ut.h"
36
+#include "dprint.h"
37
+#include "hashes.h"
38
+#include "pvar.h"
39
+
40
+#define is_in_str(p, in) (p<in->s+in->len && *p)
41
+
42
+#define PV_TABLE_SIZE	16
43
+#define TR_TABLE_SIZE	2
44
+
45
+
46
+void tr_destroy(trans_t *t);
47
+void tr_free(trans_t *t);
48
+void tr_param_free(tr_param_t *tp);
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
+
61
+/**
62
+ *
63
+ */
64
+void pv_init_table()
65
+{
66
+	memset(_pv_table, 0, sizeof(pv_item_t*)*PV_TABLE_SIZE);
67
+	_pv_table_set = 1;
68
+}
69
+
70
+/**
71
+ *
72
+ */
73
+static int is_pv_valid_char(char c)
74
+{
75
+	if((c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z')
76
+			|| (c=='_') || (c=='.'))
77
+		return 1;
78
+	return 0;
79
+}
80
+
81
+/**
82
+ *
83
+ */
84
+int pv_table_add(pv_export_t *e)
85
+{
86
+	char *p;
87
+	str  *in;
88
+	pv_item_t *pvi = NULL;
89
+	pv_item_t *pvj = NULL;
90
+	pv_item_t *pvn = NULL;
91
+	int found;
92
+	int pvid;
93
+
94
+	if(e==NULL || e->name.s==NULL || e->getf==NULL || e->type==PVT_NONE)
95
+	{
96
+		LM_ERR("invalid parameters\n");
97
+		return -1;
98
+	}
99
+	
100
+	if(_pv_table_set==0)
101
+	{
102
+		LM_DBG("PV table not initialized, doing it now\n");
103
+		pv_init_table();
104
+	}
105
+	in = &(e->name);
106
+	p = in->s;	
107
+	while(is_in_str(p,in) && is_pv_valid_char(*p))
108
+		p++;
109
+	if(is_in_str(p,in))
110
+	{
111
+		LM_ERR("invalid char [%c] in [%.*s]\n", *p, in->len, in->s);
112
+		return -1;
113
+	}
114
+	found = 0;
115
+	pvid = get_hash1_raw(in->s, in->len);
116
+
117
+	pvi = _pv_table[pvid%PV_TABLE_SIZE];
118
+	while(pvi)
119
+	{
120
+		if(pvi->pvid > pvid)
121
+			break;
122
+		if(pvi->pve.name.len > in->len)
123
+			break;
124
+		if(pvi->pve.name.len==in->len)
125
+		{
126
+			found = strncmp(pvi->pve.name.s, in->s, in->len);
127
+			if(found>0)
128
+				break;
129
+			if(found==0)
130
+			{
131
+				LM_ERR("pvar [%.*s] already exists\n", in->len, in->s);
132
+				return -1;
133
+			}
134
+		}
135
+		pvj = pvi;
136
+		pvi = pvi->next;
137
+	}
138
+
139
+	pvn = (pv_item_t*)pkg_malloc(sizeof(pv_item_t));
140
+	if(pvn==0)
141
+	{
142
+		LM_ERR("no more memory\n");
143
+		return -1;
144
+	}
145
+	memset(pvn, 0, sizeof(pv_item_t));
146
+	memcpy(&(pvn->pve), e, sizeof(pv_export_t));
147
+	pvn->pvid = pvid;
148
+
149
+	if(pvj==0)
150
+	{
151
+		pvn->next = _pv_table[pvid%PV_TABLE_SIZE];
152
+		_pv_table[pvid%PV_TABLE_SIZE] = pvn;
153
+		goto done;
154
+	}
155
+	pvn->next = pvj->next;
156
+	pvj->next = pvn;
157
+
158
+done:
159
+	return 0;
160
+}
161
+
162
+/**
163
+ *
164
+ */
165
+int register_pvars_mod(char *mod_name, pv_export_t *items)
166
+{
167
+	int ret;
168
+	int i;
169
+
170
+	if (items==0)
171
+		return 0;
172
+
173
+	for ( i=0 ; items[i].name.s ; i++ ) {
174
+		ret = pv_table_add(&items[i]);
175
+		if (ret!=0) {
176
+			LM_ERR("failed to register pseudo-variable <%.*s> for module %s\n",
177
+					items[i].name.len, items[i].name.s, mod_name);
178
+		}
179
+	}
180
+	return 0;
181
+}
182
+
183
+/**
184
+ *
185
+ */
186
+int pv_table_free(void)
187
+{
188
+	pv_item_p xe;
189
+	pv_item_p xe1;
190
+	int i;
191
+
192
+	for(i=0; i<PV_TABLE_SIZE; i++)
193
+	{
194
+		xe = _pv_table[i];
195
+		while(xe!=0)
196
+		{
197
+			xe1 = xe;
198
+			xe = xe->next;
199
+			pkg_free(xe1);
200
+		}
201
+		memset(_pv_table, 0, sizeof(pv_item_t*)*PV_TABLE_SIZE);
202
+		_pv_table_set = 0;
203
+	}
204
+	
205
+	return 0;
206
+}
207
+
208
+/********** helper functions ********/
209
+/**
210
+ * convert unsigned int to pv_value_t
211
+ */
212
+int pv_get_uintval(struct sip_msg *msg, pv_param_t *param,
213
+		pv_value_t *res, unsigned int uival)
214
+{
215
+	int l = 0;
216
+	char *ch = NULL;
217
+
218
+	if(res==NULL)
219
+		return -1;
220
+
221
+	ch = int2str(uival, &l);
222
+	res->rs.s = ch;
223
+	res->rs.len = l;
224
+
225
+	res->ri = (int)uival;
226
+	res->flags = PV_VAL_STR|PV_VAL_INT|PV_TYPE_INT;
227
+	return 0;
228
+}
229
+
230
+/**
231
+ * convert signed int to pv_value_t
232
+ */
233
+int pv_get_sintval(struct sip_msg *msg, pv_param_t *param,
234
+		pv_value_t *res, int sival)
235
+{
236
+	int l = 0;
237
+	char *ch = NULL;
238
+
239
+	if(res==NULL)
240
+		return -1;
241
+
242
+	ch = int2str(sival, &l);
243
+	res->rs.s = ch;
244
+	res->rs.len = l;
245
+
246
+	res->ri = sival;
247
+	res->flags = PV_VAL_STR|PV_VAL_INT|PV_TYPE_INT;
248
+	return 0;
249
+}
250
+
251
+/**
252
+ * convert str to pv_value_t
253
+ */
254
+int pv_get_strval(struct sip_msg *msg, pv_param_t *param,
255
+		pv_value_t *res, str *sval)
256
+{
257
+	if(res==NULL)
258
+		return -1;
259
+
260
+	res->rs = *sval;
261
+	res->flags = PV_VAL_STR;
262
+	return 0;
263
+}
264
+
265
+/**
266
+ * convert str-int to pv_value_t (type is str)
267
+ */
268
+int pv_get_strintval(struct sip_msg *msg, pv_param_t *param,
269
+		pv_value_t *res, str *sval, int ival)
270
+{
271
+	if(res==NULL)
272
+		return -1;
273
+
274
+	res->rs = *sval;
275
+	res->ri = ival;
276
+	res->flags = PV_VAL_STR|PV_VAL_INT;
277
+	return 0;
278
+}
279
+
280
+/**
281
+ * convert int-str to pv_value_t (type is int)
282
+ */
283
+int pv_get_intstrval(struct sip_msg *msg, pv_param_t *param,
284
+		pv_value_t *res, int ival, str *sval)
285
+{
286
+	if(res==NULL)
287
+		return -1;
288
+
289
+	res->rs = *sval;
290
+	res->ri = ival;
291
+	res->flags = PV_VAL_STR|PV_VAL_INT|PV_TYPE_INT;
292
+	return 0;
293
+}
294
+
295
+/*** ============================= ***/
296
+static str pv_str_marker = { PV_MARKER_STR, 1 };
297
+static int pv_get_marker(struct sip_msg *msg, pv_param_t *param,
298
+		pv_value_t *res)
299
+{
300
+	return pv_get_strintval(msg, param, res, &pv_str_marker,
301
+			(int)pv_str_marker.s[0]);
302
+}
303
+
304
+static str pv_str_empty  = { "", 0 };
305
+static str pv_str_null   = { "<null>", 6 };
306
+int pv_get_null(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
307
+{
308
+	if(res==NULL)
309
+		return -1;
310
+	
311
+	res->rs = pv_str_empty;
312
+	res->ri = 0;
313
+	res->flags = PV_VAL_NULL;
314
+	return 0;
315
+}
316
+
317
+pv_export_t* pv_lookup_spec_name(str *pvname, pv_spec_p e)
318
+{
319
+	pv_item_t *pvi;
320
+	unsigned int pvid;
321
+
322
+	if(pvname==0 || e==0)
323
+	{
324
+		LM_ERR("bad parameters\n");
325
+		return NULL;
326
+	}
327
+
328
+	/* search in PV table */
329
+	pvid = get_hash1_raw(pvname->s, pvname->len);
330
+	pvi = _pv_table[pvid%PV_TABLE_SIZE];
331
+	while(pvi)
332
+	{
333
+		if(pvi->pvid > pvid)
334
+			break;
335
+		if(pvi->pve.name.len > pvname->len)
336
+			break;
337
+
338
+		if(pvi->pvid==pvid && pvi->pve.name.len==pvname->len
339
+			&& memcmp(pvi->pve.name.s, pvname->s, pvname->len)==0)
340
+		{
341
+			/*LM_DBG("found [%.*s] [%d]\n", pvname->len, pvname->s,
342
+					_pv_names_table[i].type);*/
343
+			/* copy data from table to spec */
344
+			e->type = pvi->pve.type;
345
+			e->getf = pvi->pve.getf;
346
+			e->setf = pvi->pve.setf;
347
+			return &(pvi->pve);
348
+		}
349
+		pvi = pvi->next;
350
+	}
351
+
352
+	return NULL;
353
+}
354
+
355
+char* pv_parse_spec(str *in, pv_spec_p e)
356
+{
357
+	char *p;
358
+	str s;
359
+	str pvname;
360
+	int pvstate;
361
+	trans_t *tr = NULL;
362
+	pv_export_t *pte = NULL;
363
+	int n=0;
364
+
365
+	if(in==NULL || in->s==NULL || e==NULL || *in->s!=PV_MARKER)
366
+	{
367
+		LM_ERR("bad parameters\n");
368
+		return NULL;
369
+	}
370
+	
371
+	/* LM_DBG("***** input [%.*s] (%d)\n", in->len, in->s, in->len); */
372
+	tr = 0;
373
+	pvstate = 0;
374
+	memset(e, 0, sizeof(pv_spec_t));
375
+	p = in->s;
376
+	p++;
377
+	if(*p==PV_LNBRACKET)
378
+	{
379
+		p++;
380
+		pvstate = 1;
381
+	}
382
+	pvname.s = p;
383
+	if(*p == PV_MARKER) {
384
+		p++;
385
+		if(pvstate==1)
386
+		{
387
+			if(*p!=PV_RNBRACKET)
388
+				goto error;
389
+			p++;
390
+		}
391
+		e->getf = pv_get_marker;
392
+		e->type = PVT_MARKER;
393
+		pvname.len = 1;
394
+		goto done_all;
395
+	}
396
+	while(is_in_str(p,in) && is_pv_valid_char(*p))
397
+		p++;
398
+	pvname.len = p - pvname.s;
399
+	if(pvstate==1)
400
+	{
401
+		if(*p==PV_RNBRACKET)
402
+		{ /* full pv name ended here*/
403
+			goto done_inm;
404
+		} else if(*p==PV_LNBRACKET) {
405
+			p++;
406
+			pvstate = 2;
407
+		} else if(*p==PV_LIBRACKET) {
408
+			p++;
409
+			pvstate = 3;
410
+		} else if(*p==TR_LBRACKET) {
411
+			p++;
412
+			pvstate = 4;
413
+		} else {
414
+			LM_ERR("invalid char '%c' in [%.*s] (%d)\n", *p, in->len, in->s,
415
+					pvstate);
416
+			goto error;
417
+		}
418
+	} else { 
419
+		if(!is_in_str(p, in)) {
420
+			p--;
421
+			goto done_inm;
422
+		} else if(*p==PV_LNBRACKET) {
423
+			p++;
424
+			pvstate = 5;
425
+		} else {
426
+			/* still in input str, but end of PV */
427
+			/* p is increased at the end, so decrement here */
428
+			p--;
429
+			goto done_inm;
430
+		}
431
+	}
432
+
433
+done_inm:
434
+	if((pte = pv_lookup_spec_name(&pvname, e))==NULL)
435
+	{
436
+		LM_ERR("error searching pvar \"%.*s\"\n", pvname.len, pvname.s);
437
+		goto error;
438
+	}
439
+	if(pte->parse_name!=NULL && pvstate!=2 && pvstate!=5)
440
+	{
441
+		LM_ERR("pvar \"%.*s\" expects an inner name\n",
442
+				pvname.len, pvname.s);
443
+		goto error;
444
+	}
445
+	if(pvstate==2 || pvstate==5)
446
+	{
447
+		if(pte->parse_name==NULL)
448
+		{
449
+			LM_ERR("pvar \"%.*s\" does not get name param\n",
450
+					pvname.len, pvname.s);
451
+			goto error;
452
+		}
453
+		s.s = p;
454
+		n = 0;
455
+		while(is_in_str(p, in))
456
+		{
457
+			if(*p==PV_RNBRACKET)
458
+			{
459
+				if(n==0)
460
+					break;
461
+				n--;
462
+			}
463
+			if(*p == PV_LNBRACKET)
464
+				n++;
465
+			p++;
466
+		}
467
+
468
+		if(!is_in_str(p, in))
469
+			goto error;
470
+
471
+		if(p==s.s)
472
+		{
473
+			LM_ERR("pvar \"%.*s\" does not get empty name param\n",
474
+					pvname.len, pvname.s);
475
+			goto error;
476
+		}
477
+		s.len = p - s.s;
478
+		if(pte->parse_name(e, &s)!=0)
479
+		{
480
+			LM_ERR("pvar \"%.*s\" has an invalid name param [%.*s]\n",
481
+					pvname.len, pvname.s, s.len, s.s);
482
+			goto error;
483
+		}
484
+		if(pvstate==2)
485
+		{
486
+			p++;
487
+			if(*p==PV_RNBRACKET)
488
+			{ /* full pv name ended here*/
489
+				goto done_vnm;
490
+			} else if(*p==PV_LIBRACKET) {
491
+				p++;
492
+				pvstate = 3;
493
+			} else if(*p==TR_LBRACKET) {
494
+				p++;
495
+				pvstate = 4;
496
+			} else {
497
+				LM_ERR("invalid char '%c' in [%.*s] (%d)\n", *p, in->len, in->s,
498
+					pvstate);
499
+				goto error;
500
+			}
501
+		} else {
502
+			if(*p==PV_RNBRACKET)
503
+			{ /* full pv name ended here*/
504
+				p++;
505
+				goto done_all;
506
+			} else {
507
+				LM_ERR("invalid char '%c' in [%.*s] (%d)\n", *p, in->len, in->s,
508
+					pvstate);
509
+				goto error;
510
+			}
511
+		}
512
+	}
513
+done_vnm:
514
+	if(pvstate==3)
515
+	{
516
+		if(pte->parse_index==NULL)
517
+		{
518
+			LM_ERR("pvar \"%.*s\" does not get index param\n",
519
+					pvname.len, pvname.s);
520
+			goto error;
521
+		}
522
+		s.s = p;
523
+		n = 0;
524
+		while(is_in_str(p, in))
525
+		{
526
+			if(*p==PV_RIBRACKET)
527
+			{
528
+				if(n==0)
529
+					break;
530
+				n--;
531
+			}
532
+			if(*p == PV_LIBRACKET)
533
+				n++;
534
+			p++;
535
+		}
536
+		if(!is_in_str(p, in))
537
+			goto error;
538
+
539
+		if(p==s.s)
540
+		{
541
+			LM_ERR("pvar \"%.*s\" does not get empty index param\n",
542
+					pvname.len, pvname.s);
543
+			goto error;
544
+		}
545
+		s.len = p - s.s;
546
+		if(pte->parse_index(e, &s)!=0)
547
+		{
548
+			LM_ERR("pvar \"%.*s\" has an invalid index param [%.*s]\n",
549
+					pvname.len, pvname.s, s.len, s.s);
550
+			goto error;
551
+		}
552
+		p++;
553
+		if(*p==PV_RNBRACKET)
554
+		{ /* full pv name ended here*/
555
+			goto done_idx;
556
+		} else if(*p==TR_LBRACKET) {
557
+			p++;
558
+			pvstate = 4;
559
+		} else {
560
+			LM_ERR("invalid char '%c' in [%.*s] (%d)\n", *p, in->len, in->s,
561
+					pvstate);
562
+			goto error;
563
+		}
564
+	}
565
+done_idx:
566
+	if(pvstate==4)
567
+	{
568
+		s.s = p-1;
569
+		n = 0;
570
+		while(is_in_str(p, in))
571
+		{
572
+			if(*p==TR_RBRACKET)
573
+			{
574
+				if(n==0)
575
+				{
576
+					/* yet another transformation */
577
+					p++;
578
+					while(is_in_str(p, in) && (*p==' ' || *p=='\t')) p++;
579
+
580
+					if(!is_in_str(p, in) || *p != TR_LBRACKET)
581
+					{
582
+						p--;
583
+						break;
584
+					}
585
+				}
586
+				n--;
587
+			}
588
+			if(*p == TR_LBRACKET)
589
+				n++;
590
+			p++;
591
+		}
592
+		if(!is_in_str(p, in))
593
+			goto error;
594
+
595
+		if(p==s.s)
596
+		{
597
+			LM_ERR("pvar \"%.*s\" does not get empty index param\n",
598
+					pvname.len, pvname.s);
599
+			goto error;
600
+		}
601
+		s.len = p - s.s + 1;
602
+
603
+		p = tr_lookup(&s, &tr);
604
+		if(p==NULL)
605
+		{
606
+			LM_ERR("bad tr in pvar name \"%.*s\"\n", pvname.len, pvname.s);
607
+			goto error;
608
+		}
609
+		if(*p!=PV_RNBRACKET)
610
+		{
611
+			LM_ERR("bad pvar name \"%.*s\" (%c)!\n", in->len, in->s, *p);
612
+			goto error;
613
+		}
614
+		e->trans = (void*)tr;
615
+	}
616
+	p++;
617
+
618
+done_all:
619
+	if(pte!=NULL && pte->init_param)
620
+		pte->init_param(e, pte->iparam);
621
+	return p;
622
+
623
+error:
624
+	if(p!=NULL)
625
+		LM_ERR("wrong char [%c/%d] in [%.*s] at [%d (%d)]\n", *p, (int)*p,
626
+			in->len, in->s, (int)(p-in->s), pvstate);
627
+	else
628
+		LM_ERR("invalid parsing in [%.*s] at (%d)\n", in->len, in->s, pvstate);
629
+	return NULL;
630
+
631
+} /* end: pv_parse_spec */
632
+
633
+/**
634
+ *
635
+ */
636
+int pv_parse_format(str *in, pv_elem_p *el)
637
+{
638
+	char *p, *p0;
639
+	int n = 0;
640
+	pv_elem_p e, e0;
641
+	str s;
642
+
643
+	if(in==NULL || in->s==NULL || el==NULL)
644
+		return -1;
645
+
646
+	/*LM_DBG("parsing [%.*s]\n", in->len, in->s);*/
647
+	
648
+	if(in->len == 0)
649
+	{
650
+		*el = pkg_malloc(sizeof(pv_elem_t));
651
+		if(*el == NULL)
652
+			goto error;
653
+		memset(*el, 0, sizeof(pv_elem_t));
654
+		(*el)->text = *in;
655
+		return 0;
656
+	}
657
+
658
+	p = in->s;
659
+	*el = NULL;
660
+	e = e0 = NULL;
661
+
662
+	while(is_in_str(p,in))
663
+	{
664
+		e0 = e;
665
+		e = pkg_malloc(sizeof(pv_elem_t));
666
+		if(!e)
667
+			goto error;
668
+		memset(e, 0, sizeof(pv_elem_t));
669
+		n++;
670
+		if(*el == NULL)
671
+			*el = e;
672
+		if(e0)
673
+			e0->next = e;
674
+	
675
+		e->text.s = p;
676
+		while(is_in_str(p,in) && *p!=PV_MARKER)
677
+			p++;
678
+		e->text.len = p - e->text.s;
679
+		
680
+		if(*p == '\0' || !is_in_str(p,in))
681
+			break;
682
+		s.s = p;
683
+		s.len = in->s+in->len-p;
684
+		p0 = pv_parse_spec(&s, &e->spec);
685
+		
686
+		if(p0==NULL)
687
+			goto error;
688
+		if(*p0 == '\0')
689
+			break;
690
+		p = p0;
691
+	}
692
+	/*LM_DBG("format parsed OK: [%d] items\n", n);*/
693
+
694
+	if(*el == NULL)
695
+		return -1;
696
+
697
+	return 0;
698
+
699
+error:
700
+	pv_elem_free_all(*el);
701
+	*el = NULL;
702
+	return -1;
703
+}
704
+
705
+int pv_get_spec_value(struct sip_msg* msg, pv_spec_p sp, pv_value_t *value)
706
+{
707
+	int ret = 0;
708
+
709
+	if(msg==NULL || sp==NULL || sp->getf==NULL || value==NULL
710
+			|| sp->type==PVT_NONE)
711
+	{
712
+		LM_ERR("bad parameters\n");
713
+		return -1;
714
+	}
715
+	
716
+	memset(value, 0, sizeof(pv_value_t));
717
+
718
+	ret = (*sp->getf)(msg, &(sp->pvp), value);
719
+	if(ret!=0)
720
+		return ret;
721
+	if(sp->trans)
722
+		return tr_exec(msg, (trans_t*)sp->trans, value);
723
+	return ret;
724
+}
725
+
726
+/**
727
+ *
728
+ */
729
+int pv_printf(struct sip_msg* msg, pv_elem_p list, char *buf, int *len)
730
+{
731
+	int n, h;
732
+	pv_value_t tok;
733
+	pv_elem_p it;
734
+	char *cur;
735
+	
736
+	if(msg==NULL || list==NULL || buf==NULL || len==NULL)
737
+		return -1;
738
+
739
+	if(*len <= 0)
740
+		return -1;
741
+
742
+	*buf = '\0';
743
+	cur = buf;
744
+	
745
+	h = 0;
746
+	n = 0;
747
+	for (it=list; it; it=it->next)
748
+	{
749
+		/* put the text */
750
+		if(it->text.s && it->text.len>0)
751
+		{
752
+			if(n+it->text.len < *len)
753
+			{
754
+				memcpy(cur, it->text.s, it->text.len);
755
+				n += it->text.len;
756
+				cur += it->text.len;
757
+			} else {
758
+				LM_ERR("no more space for text [%d]\n", it->text.len);
759
+				goto overflow;
760
+			}
761
+		}
762
+		/* put the value of the specifier */
763
+		if(it->spec.type!=PVT_NONE
764
+				&& pv_get_spec_value(msg, &(it->spec), &tok)==0)
765
+		{
766
+			if(tok.flags&PV_VAL_NULL)
767
+				tok.rs = pv_str_null;
768
+			if(n+tok.rs.len < *len)
769
+			{
770
+				if(tok.rs.len>0)
771
+				{
772
+					memcpy(cur, tok.rs.s, tok.rs.len);
773
+					n += tok.rs.len;
774
+					cur += tok.rs.len;
775
+				}
776
+			} else {
777
+				LM_ERR("no more space for spec value\n");
778
+				goto overflow;
779
+			}
780
+		}
781
+	}
782
+
783
+	goto done;
784
+	
785
+overflow:
786
+	LM_ERR("buffer overflow -- increase the buffer size...\n");
787
+	return -1;
788
+
789
+done:
790
+#ifdef EXTRA_DEBUG
791
+	LM_DBG("final buffer length %d\n", n);
792
+#endif
793
+	*cur = '\0';
794
+	*len = n;
795
+	return 0;
796
+}
797
+
798
+
799
+/**
800
+ *
801
+ */
802
+void pv_spec_free(pv_spec_t *spec)
803
+{
804
+	if(spec==0) return;
805
+	/* TODO: free name if it is PV */
806
+	if(spec->trans)
807
+		tr_free((trans_t*)spec->trans);
808
+	pkg_free(spec);
809
+}
810
+
811
+/**
812
+ *
813
+ */
814
+int pv_elem_free_all(pv_elem_p log)
815
+{
816
+	pv_elem_p t;
817
+	while(log)
818
+	{
819
+		t = log;
820
+		log = log->next;
821
+		pkg_free(t);
822
+	}
823
+	return 0;
824
+}
825
+
826
+/**
827
+ *
828
+ */
829
+void pv_value_destroy(pv_value_t *val)
830
+{
831
+	if(val==0) return;
832
+	if(val->flags&PV_VAL_PKG) pkg_free(val->rs.s);
833
+	if(val->flags&PV_VAL_SHM) shm_free(val->rs.s);
834
+	memset(val, 0, sizeof(pv_value_t));
835
+}
836
+
837
+
838
+/********************************************************
839
+ * Transformations API
840
+ ********************************************************/
841
+
842
+/**
843
+ *
844
+ */
845
+static inline char* tr_get_class(str *in, char *p, str *tclass)
846
+{
847
+	tclass->s = p;
848
+	while(is_in_str(p, in) && *p!=TR_CLASS_MARKER) p++;
849
+	if(*p!=TR_CLASS_MARKER || tclass->s == p)
850
+	{
851
+		LM_ERR("invalid transformation: %.*s (%c)!\n", in->len, in->s, *p);
852
+		return NULL;
853
+	}
854
+	tclass->len = p - tclass->s;
855
+	p++;
856
+
857
+	return p;
858
+}
859
+
860
+/**
861
+ *
862
+ */
863
+static inline trans_t* tr_new()
864
+{
865
+	trans_t *t = NULL;
866
+
867
+	t = (trans_t*)pkg_malloc(sizeof(trans_t));
868
+	if(t == NULL)
869
+	{
870
+		LM_ERR("no more private memory\n");
871
+		return NULL;
872
+	}
873
+	memset(t, 0, sizeof(trans_t));
874
+	return t;
875
+}
876
+
877
+char* tr_lookup(str *in, trans_t **tr)
878
+{
879
+	char *p;
880
+	char *p0;
881
+	str tclass;
882
+	tr_export_t *te = NULL; 
883
+	trans_t *t = NULL;
884
+	trans_t *t0 = NULL;
885
+	str s;
886
+
887
+	if(in==NULL || in->s==NULL || tr==NULL)
888
+		return NULL;
889
+	
890
+	p = in->s;
891
+	do {
892
+		while(is_in_str(p, in) && (*p==' ' || *p=='\t' || *p=='\n')) p++;
893
+		if(*p != TR_LBRACKET)
894
+			break;
895
+		p++;
896
+
897
+		if((t = tr_new())==NULL) return NULL;
898
+
899
+		if(t0==NULL) *tr = t;
900
+		else t0->next = t;
901
+		t0 = t;
902
+
903
+		/* find transformation class */
904
+		p = tr_get_class(in, p, &tclass);
905
+		if(p==NULL) goto error;
906
+
907
+		/* locate transformation */
908
+		te = tr_lookup_class(&tclass);
909
+		if(te==NULL)
910
+		{
911
+			LM_ERR("unknown transformation: [%.*s] in [%.*s]\n",
912
+				tclass.len, tclass.s, in->len, in->s);
913
+			goto error;
914
+		}
915
+
916
+		s.s = p; s.len = in->s + in->len - p;
917
+		p0 = te->tparse(&s, t);
918
+		if(p0==NULL)
919
+			goto error;
920
+		p = p0;
921
+
922
+		if(*p != TR_RBRACKET)
923
+		{
924
+			LM_ERR("invalid transformation: %.*s | %c !!\n", in->len,
925
+					in->s, *p);
926
+			goto error;
927
+		}
928
+
929
+		p++;
930
+		if(!is_in_str(p, in))
931
+			break;
932
+	} while(1);
933
+
934
+	return p;
935
+error:
936
+	LM_ERR("error parsing [%.*s]\n", in->len, in->s);
937
+	t = *tr;
938
+	while(t)
939
+	{
940
+		t0 = t;
941
+		t = t->next;
942
+		tr_destroy(t0);
943
+		pkg_free(t0);
944
+	}
945
+	return NULL;
946
+}
947
+
948
+/*!
949
+ * \brief Destroy transformation including eventual parameter
950
+ * \param t transformation
951
+ */
952
+void tr_destroy(trans_t *t)
953
+{
954
+	tr_param_t *tp;
955
+	tr_param_t *tp0;
956
+	if(t==NULL) return;
957
+
958
+	tp = t->params;
959
+	while(tp)
960
+	{
961
+		tp0 = tp;
962
+		tp = tp->next;
963
+		tr_param_free(tp0);
964
+	}
965
+	memset(t, 0, sizeof(trans_t));
966
+}
967
+
968
+int tr_exec(struct sip_msg *msg, trans_t *t, pv_value_t *v)
969
+{
970
+	int r;
971
+	trans_t *i;
972
+
973
+	if(t==NULL || v==NULL)
974
+	{
975
+		LM_DBG("invalid parameters\n");
976
+		return -1;
977
+	}
978
+	
979
+	for(i = t; i!=NULL; i=i->next)
980
+	{
981
+		r = (*i->trf)(msg, i->params, i->subtype, v);
982
+		if(r!=0)
983
+			return r;
984
+	}
985
+	return 0;
986
+}
987
+
988
+/*!
989
+ * \brief Free allocated memory of transformation list
990
+ * \param t transformation list
991
+ */
992
+void tr_free(trans_t *t)
993
+{
994
+	trans_t *t0;
995
+
996
+	while(t)
997
+	{
998
+		t0 = t;
999
+		t = t->next;
1000
+		tr_destroy(t0);
1001
+		pkg_free(t0);
1002
+	}
1003
+}
1004
+
1005
+
1006
+/*!
1007
+ * \brief Free transformation parameter list
1008
+ * \param tp transformation list
1009
+ */
1010
+void tr_param_free(tr_param_t *tp)
1011
+{
1012
+	tr_param_t *tp0;
1013
+
1014
+	if(tp==NULL) return;
1015
+	while(tp)
1016
+	{
1017
+		tp0 = tp;
1018
+		tp = tp->next;
1019
+		if(tp0->type==TR_PARAM_SPEC)
1020
+			pv_spec_free((pv_spec_t*)tp0->v.data);
1021
+		pkg_free(tp0);
1022
+	}
1023
+}
1024
+
1025
+typedef struct _tr_item
1026
+{
1027
+	tr_export_t tre;
1028
+	unsigned int trid;
1029
+	struct _tr_item *next;
1030
+} tr_item_t, *tr_item_p;
1031
+
1032
+static tr_item_t* _tr_table[PV_TABLE_SIZE];
1033
+static int _tr_table_set = 0;
1034
+
1035
+
1036
+/**
1037
+ *
1038
+ */
1039
+void tr_init_table()
1040
+{
1041
+	memset(_tr_table, 0, sizeof(tr_item_t*)*TR_TABLE_SIZE);
1042
+	_tr_table_set = 1;
1043
+}
1044
+
1045
+/**
1046
+ *
1047
+ */
1048
+int tr_table_add(tr_export_t *e)
1049
+{
1050
+	tr_item_t *tri = NULL;
1051
+	tr_item_t *trj = NULL;
1052
+	tr_item_t *trn = NULL;
1053
+	int found;
1054
+	int trid;
1055
+
1056
+	if(e==NULL || e->tclass.s==NULL)
1057
+	{
1058
+		LM_ERR("invalid parameters\n");
1059
+		return -1;
1060
+	}
1061
+	
1062
+	if(_tr_table_set==0)
1063
+	{
1064
+		LM_DBG("TR table not initialized, doing it now\n");
1065
+		tr_init_table();
1066
+	}
1067
+
1068
+	found = 0;
1069
+	trid = get_hash1_raw(e->tclass.s, e->tclass.len);
1070
+
1071
+	tri = _tr_table[trid%PV_TABLE_SIZE];
1072
+	while(tri)
1073
+	{
1074
+		if(tri->trid > trid)
1075
+			break;
1076
+		if(tri->tre.tclass.len > e->tclass.len)
1077
+			break;
1078
+		if(tri->tre.tclass.len==e->tclass.len)
1079
+		{
1080
+			found = strncmp(tri->tre.tclass.s, e->tclass.s, e->tclass.len);
1081
+			if(found>0)
1082
+				break;
1083
+			if(found==0)
1084
+			{
1085
+				LM_ERR("TR class [%.*s] already exists\n", e->tclass.len,
1086
+						e->tclass.s);
1087
+				return -1;
1088
+			}
1089
+		}
1090
+		trj = tri;
1091
+		tri = tri->next;
1092
+	}
1093
+
1094
+	trn = (tr_item_t*)pkg_malloc(sizeof(tr_item_t));
1095
+	if(trn==0)
1096
+	{
1097
+		LM_ERR("no more memory\n");
1098
+		return -1;
1099
+	}
1100
+	memset(trn, 0, sizeof(tr_item_t));
1101
+	memcpy(&(trn->tre), e, sizeof(tr_export_t));
1102
+	trn->trid = trid;
1103
+
1104
+	if(trj==0)
1105
+	{
1106
+		trn->next = _tr_table[trid%PV_TABLE_SIZE];
1107
+		_tr_table[trid%PV_TABLE_SIZE] = trn;
1108
+		goto done;
1109
+	}
1110
+	trn->next = trj->next;
1111
+	trj->next = trn;
1112
+
1113
+done:
1114
+	return 0;
1115
+}
1116
+
1117
+/**
1118
+ *
1119
+ */
1120
+int register_trans_mod(char *mod_name, tr_export_t *items)
1121
+{
1122
+	int ret;
1123
+	int i;
1124
+
1125
+	if (items==0)
1126
+		return 0;
1127
+
1128
+	for ( i=0 ; items[i].tclass.s ; i++ ) {
1129
+		ret = tr_table_add(&items[i]);
1130
+		if (ret!=0) {
1131
+			LM_ERR("failed to register pseudo-variable <%.*s> for module %s\n",
1132
+					items[i].tclass.len, items[i].tclass.s, mod_name);
1133
+		}
1134
+	}
1135
+	return 0;
1136
+}
1137
+
1138
+/**
1139
+ *
1140
+ */
1141
+int tr_table_free(void)
1142
+{
1143
+	tr_item_p te;
1144
+	tr_item_p te1;
1145
+	int i;
1146
+
1147
+	for(i=0; i<TR_TABLE_SIZE; i++)
1148
+	{
1149
+		te = _tr_table[i];
1150
+		while(te!=0)
1151
+		{
1152
+			te1 = te;
1153
+			te = te->next;
1154
+			pkg_free(te1);
1155
+		}
1156
+		memset(_tr_table, 0, sizeof(tr_item_t*)*TR_TABLE_SIZE);
1157
+		_tr_table_set = 0;
1158
+	}
1159
+	
1160
+	return 0;
1161
+}
1162
+
1163
+tr_export_t* tr_lookup_class(str *tclass)
1164
+{
1165
+	tr_item_t *tri;
1166
+	unsigned int trid;
1167
+
1168
+	if(tclass==0 || tclass->s==0)
1169
+	{
1170
+		LM_ERR("bad parameters\n");
1171
+		return NULL;
1172
+	}
1173
+
1174
+	/* search in TR table */
1175
+	trid = get_hash1_raw(tclass->s, tclass->len);
1176
+	tri = _tr_table[trid%TR_TABLE_SIZE];
1177
+	while(tri)
1178
+	{
1179
+		if(tri->trid > trid)
1180
+			break;
1181
+		if(tri->tre.tclass.len > tclass->len)
1182
+			break;
1183
+
1184
+		if(tri->trid==trid && tri->tre.tclass.len==tclass->len
1185
+				&& memcmp(tri->tre.tclass.s, tclass->s, tclass->len)==0)
1186
+			return &(tri->tre);
1187
+		tri = tri->next;
1188
+	}
1189
+
1190
+	return NULL;
1191
+}
1192
+
... ...
@@ -1,74 +1,85 @@
1 1
 /*
2
- * $Id$
2
+ * $Id: items.h 2111 2007-05-01 11:18:08Z juhe $
3 3
  *
4
- * Copyright (C) 2008 
4
+ * Copyright (C) 2001-2003 FhG Fokus
5 5
  *
6
- * Permission to use, copy, modify, and distribute this software for any
7
- * purpose with or without fee is hereby granted, provided that the above
8
- * copyright notice and this permission notice appear in all copies.
6
+ * This file is part of SIP-Router, a free SIP server.
9 7
  *
10
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
- */
18
-/*
19
- * pvar compatibility wrapper for kamailio
20
- * for now it doesn't do anything (feel free to rm & replace the file)
8
+ * SIP-Router 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
21 12
  *
22
- * History:
23
- * --------
24
- *  2008-11-17  initial version compatible with kamailio pvar.h (andrei)
13
+ * SIP-Router 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
+ */
22
+
23
+/*!
24
+ * \file
25
+ * \brief Definitions for Pseudo-variable support
25 26
  */
26 27
 
27
-#ifndef _pvar_h_
28
-#define _pvar_h_
28
+
29
+#ifndef _PVAR_H_
30
+#define _PVAR_H_
29 31
 
30 32
 #include "str.h"
31 33
 #include "usr_avp.h"
32 34
 #include "parser/msg_parser.h"
33 35
 
34
-
35
-
36
+#define PV_MARKER_STR	"$"
37
+#define PV_MARKER		'$'
38
+
39
+#define PV_LNBRACKET_STR	"("
40
+#define PV_LNBRACKET		'('
41
+#define PV_RNBRACKET_STR	")"
42
+#define PV_RNBRACKET		')'
43
+
44
+#define PV_LIBRACKET_STR	"["
45
+#define PV_LIBRACKET		'['
46
+#define PV_RIBRACKET_STR	"]"
47
+#define PV_RIBRACKET		']'
48
+
49
+#define PV_VAL_NONE			0
50
+#define PV_VAL_NULL			1
51
+#define PV_VAL_EMPTY		2
52
+#define PV_VAL_STR			4
53
+#define PV_VAL_INT			8
54
+#define PV_TYPE_INT			16
55
+#define PV_VAL_PKG			32
56
+#define PV_VAL_SHM			64
57
+
58
+#define PV_NAME_INTSTR	0
59
+#define PV_NAME_PVAR	1
60
+
61
+#define PV_IDX_INT	0
62
+#define PV_IDX_PVAR	1
63
+#define PV_IDX_ALL	2
64
+
65
+/*! if PV name is dynamic, integer, or str */
66
+#define pv_has_dname(pv) ((pv)->pvp.pvn.type==PV_NAME_PVAR)
67
+#define pv_has_iname(pv) ((pv)->pvp.pvn.type==PV_NAME_INTSTR \
68
+							&& !((pv)->pvp.pvn.u.isname.type&AVP_NAME_STR))
69
+#define pv_has_sname(pv) ((pv)->pvp.pvn.type==PV_NAME_INTSTR \
70
+							&& (pv)->pvp.pvn.u.isname.type&AVP_NAME_STR)
71
+#define pv_is_w(pv)	((pv)->setf!=NULL)
36 72
 
37 73
 enum _pv_type { 
38 74
 	PVT_NONE=0,           PVT_EMPTY,             PVT_NULL, 
39
-	PVT_MARKER,           PVT_AVP,               PVT_HDR,
40
-	PVT_PID,              PVT_RETURN_CODE,       PVT_TIMES,
41
-	PVT_TIMEF,            PVT_MSGID,             PVT_METHOD,
42
-	PVT_STATUS,           PVT_REASON,            PVT_RURI,
43
-	PVT_RURI_USERNAME,    PVT_RURI_DOMAIN,       PVT_RURI_PORT,
44
-	PVT_FROM,             PVT_FROM_USERNAME,     PVT_FROM_DOMAIN,
45
-	PVT_FROM_TAG,         PVT_TO,                PVT_TO_USERNAME,
46
-	PVT_TO_DOMAIN,        PVT_TO_TAG,            PVT_CSEQ,
47
-	PVT_CONTACT,          PVT_CALLID,            PVT_USERAGENT,
48
-	PVT_MSG_BUF,          PVT_MSG_LEN,           PVT_FLAGS,
49
-	PVT_HEXFLAGS,         PVT_SRCIP,             PVT_SRCPORT,
50
-	PVT_RCVIP,            PVT_RCVPORT,           PVT_REFER_TO,
51
-	PVT_DSET,             PVT_DSTURI,            PVT_COLOR,
52
-	PVT_BRANCH,           PVT_BRANCHES,          PVT_CONTENT_TYPE,
53
-	PVT_CONTENT_LENGTH,   PVT_MSG_BODY,          PVT_AUTH_USERNAME,
54
-	PVT_AUTH_REALM,       PVT_RURI_PROTOCOL,     PVT_DSTURI_DOMAIN,
55
-	PVT_DSTURI_PORT,      PVT_DSTURI_PROTOCOL,   PVT_FROM_DISPLAYNAME,
56
-	PVT_TO_DISPLAYNAME,   PVT_OURI,              PVT_OURI_USERNAME,
57
-	PVT_OURI_DOMAIN,      PVT_OURI_PORT,         PVT_OURI_PROTOCOL,
58
-	PVT_FORCE_SOCK,       PVT_RPID_URI,          PVT_DIVERSION_URI,
59
-	PVT_ACC_USERNAME,     PVT_PPI,               PVT_PPI_DISPLAYNAME,
60
-	PVT_PPI_DOMAIN,       PVT_PPI_USERNAME,      PVT_PAI_URI,
61
-	PVT_BFLAGS,           PVT_HEXBFLAGS,         PVT_SFLAGS,
62
-	PVT_HEXSFLAGS,        PVT_ERR_CLASS,         PVT_ERR_LEVEL,
63
-	PVT_ERR_INFO,         PVT_ERR_RCODE,         PVT_ERR_RREASON,
64
-	PVT_SCRIPTVAR,        PVT_PROTO,             PVT_AUTH_USERNAME_WHOLE,
65
-	PVT_AUTH_DURI,        PVT_DIV_REASON,        PVT_DIV_PRIVACY,
66
-	PVT_AUTH_DOMAIN,      PVT_EXTRA /* keep it last */
75
+	PVT_MARKER,           PVT_AVP,               PVT_COLOR,
76
+	PVT_OTHER,            PVT_EXTRA /* keep it last */
67 77
 };
68 78
 
69 79
 typedef enum _pv_type pv_type_t;
70 80
 typedef int pv_flags_t;
71 81
 
82
+
72 83
 typedef struct _pv_value
73 84
 {
74 85
 	str rs;    /*!< string value */
... ...
@@ -114,8 +125,6 @@ typedef struct _pv_spec {
114 125
 	void         *trans; /*!< transformations */
115 126
 } pv_spec_t, *pv_spec_p;
116 127
 
117
-
118
-
119 128
 typedef int (*pv_parse_name_f)(pv_spec_p sp, str *in);
120 129
 typedef int (*pv_parse_index_f)(pv_spec_p sp, str *in);
121 130
 typedef int (*pv_init_param_f)(pv_spec_p sp, int param);
... ...
@@ -142,4 +151,104 @@ typedef struct _pv_export {
142 151
 	int iparam;                    /*!< parameter for the init function */
143 152
 } pv_export_t;
144 153
 
145
-#endif /* _pvar_h_ */
154
+typedef struct _pv_elem
155
+{
156
+	str text;
157
+	pv_spec_t spec;
158
+	struct _pv_elem *next;
159
+} pv_elem_t, *pv_elem_p;
160
+
161
+char* pv_parse_spec(str *in, pv_spec_p sp);
162
+int pv_get_spec_value(struct sip_msg* msg, pv_spec_p sp, pv_value_t *value);
163
+int pv_print_spec(struct sip_msg* msg, pv_spec_p sp, char *buf, int *len);
164
+int pv_printf(struct sip_msg* msg, pv_elem_p list, char *buf, int *len);
165
+int pv_elem_free_all(pv_elem_p log);
166
+void pv_value_destroy(pv_value_t *val);
167
+void pv_spec_free(pv_spec_t *spec);
168
+int pv_spec_dbg(pv_spec_p sp);
169
+int pv_get_spec_index(struct sip_msg* msg, pv_param_p ip, int *idx, int *flags);
170
+int pv_get_avp_name(struct sip_msg* msg, pv_param_p ip, int_str *avp_name,
171
+		unsigned short *name_type);
172
+int pv_get_spec_name(struct sip_msg* msg, pv_param_p ip, pv_value_t *name);
173
+int pv_parse_format(str *in, pv_elem_p *el);
174
+int pv_init_iname(pv_spec_p sp, int param);
175
+int pv_printf_s(struct sip_msg* msg, pv_elem_p list, str *s);
176
+
177
+typedef struct _pvname_list {
178
+	pv_spec_t sname;
179
+	struct _pvname_list *next;
180
+} pvname_list_t, *pvname_list_p;
181
+
182
+typedef struct pv_spec_list {
183
+	pv_spec_p spec;
184
+	struct pv_spec_list *next;
185
+} pv_spec_list_t, *pv_spec_list_p;
186
+
187
+pvname_list_t* parse_pvname_list(str *in, unsigned int type);
188
+
189
+int register_pvars_mod(char *mod_name, pv_export_t *items);
190
+int pv_free_extra_list(void);
191
+
192
+/*! \brief PV helper functions */
193
+int pv_parse_index(pv_spec_p sp, str *in);
194
+
195
+int pv_get_null(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
196
+int pv_update_time(struct sip_msg *msg, time_t *t);
197
+
198
+int pv_get_uintval(struct sip_msg *msg, pv_param_t *param,
199
+		pv_value_t *res, unsigned int uival);
200
+int pv_get_sintval(struct sip_msg *msg, pv_param_t *param,
201
+		pv_value_t *res, int sival);
202
+int pv_get_strval(struct sip_msg *msg, pv_param_t *param,
203
+		pv_value_t *res, str *sval);
204
+int pv_get_strintval(struct sip_msg *msg, pv_param_t *param,
205
+		pv_value_t *res, str *sval, int ival);
206
+int pv_get_intstrval(struct sip_msg *msg, pv_param_t *param,
207
+		pv_value_t *res, int ival, str *sval);
208
+
209
+/**
210
+ * Transformations
211
+ */
212
+#define TR_LBRACKET_STR		"{"
213
+#define TR_LBRACKET		'{'
214
+#define TR_RBRACKET_STR		"}"
215
+#define TR_RBRACKET		'}'
216
+#define TR_CLASS_MARKER		'.'
217
+#define TR_PARAM_MARKER		','
218
+
219
+enum _tr_param_type { TR_PARAM_NONE=0, TR_PARAM_STRING, TR_PARAM_NUMBER,
220
+	TR_PARAM_SPEC };
221
+
222
+typedef struct _tr_param {
223
+	int type;
224
+	union {
225
+		int n;
226
+		str s;
227
+		void *data;
228
+	} v;
229
+	struct _tr_param *next;
230
+} tr_param_t, *tr_param_p;
231
+
232
+typedef int (*tr_func_t) (struct sip_msg *, tr_param_t*, int, pv_value_t*);
233
+
234
+typedef struct _trans {
235
+	str name;
236
+	int type;
237
+	int subtype;
238
+	tr_func_t trf;