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,3850 +0,0 @@
1
-/* 
2
- * Copyright (C) 2008 iptelorg GmbH
3
- *
4
- * Permission to use, copy, modify, and distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
-/**
18
- * @file 
19
- * @brief Kamailio core :: rvalue expressions
20
- * @ingroup core
21
- * Module: \ref core
22
- */
23
-
24
-/** special defines:
25
- *
26
- *  UNDEF_EQ_* - how to behave when undef is on the right side of a generic
27
- *               compare operator
28
- *  UNDEF_EQ_ALWAYS_FALSE:  undef  == something  is always false
29
- *  UNDEF_EQ_UNDEF_TRUE  :  undef == something false except for undef==undef
30
- *                          which is true
31
- *  no UNDEF_EQ* define  :  undef == expr => convert undef to typeof(expr)
32
- *                          and perform normal ==. undef == undef will be
33
- *                          converted to string and it will be true
34
- *                          ("" == "")
35
- * NOTE: expr == undef, with defined(expr) is always evaluated this way:
36
-         expr == (type_of(expr))undef
37
- *  RV_STR2INT_VERBOSE_ERR - if a string conversion to int fails, log (L_WARN)
38
- *                           the string that caused it (only the string, not
39
- *                           the expression position).
40
- *  RV_STR2INT_ERR         - if a string conversion to int fails, don't ignore
41
- *                           the error (return error).
42
- *  RVAL_GET_INT_ERR_WARN  - if a conversion to int fails, log a warning with
43
- *                           the expression position.
44
- *                           Depends on RV_STR2INT_ERR.
45
- *  RVAL_GET_INT_ERR_IGN   - if a conversion to int fails, ignore the error
46
- *                           (the result will be 0). Can be combined with
47
- *                           RVAL_GET_INT_ERR_WARN.
48
- *                           Depends on RV_STR2INT_ERR.
49
- */
50
-
51
-
52
-#include "rvalue.h"
53
-
54
-#include <stdlib.h> /* abort() */
55
-
56
-/* if defined warn when str2int conversions fail */
57
-#define RV_STR2INT_VERBOSE_ERR
58
-
59
-/* if defined rval_get_int will fail if str2int conversion fail
60
-   (else convert to 0) */
61
-#define RV_STR2INT_ERR
62
-
63
-/* if a rval_get_int fails (conversion to int), warn
64
-   Depends on RV_STR2INT_ERR.
65
- */
66
-#define RVAL_GET_INT_ERR_WARN
67
-
68
-/* if a rval_get_int fails, ignore it (expression evaluation will not fail,
69
-   the int conversion will result in 0).
70
-   Can be combined with RVAL_GET_INT_ERR_WARN.
71
-   Depends on RV_STR2INT_ERR.
72
- */
73
-#define RVAL_GET_INT_ERR_IGN
74
-
75
-/* minimum size alloc'ed for STR RVs (to accomodate
76
- * strops without reallocs) */
77
-#define RV_STR_EXTRA 80
78
-
79
-#define rv_ref(rv) ((rv)->refcnt++)
80
-
81
-/** unref rv and returns true if 0 */
82
-#define rv_unref(rv) ((--(rv)->refcnt)==0)
83
-
84
-
85
-inline static void rval_force_clean(struct rvalue* rv)
86
-{
87
-	if (rv->flags & RV_CNT_ALLOCED_F){
88
-		switch(rv->type){
89
-			case RV_STR:
90
-				pkg_free(rv->v.s.s);
91
-				rv->v.s.s=0;
92
-				rv->v.s.len=0;
93
-				break;
94
-			default:
95
-				BUG("RV_CNT_ALLOCED_F not supported for type %d\n", rv->type);
96
-		}
97
-		rv->flags&=~RV_CNT_ALLOCED_F;
98
-	}
99
-	if (rv->flags & RV_RE_ALLOCED_F){
100
-		if (rv->v.re.regex){
101
-			if (unlikely(rv->type!=RV_STR || !(rv->flags & RV_RE_F))){
102
-				BUG("RV_RE_ALLOCED_F not supported for type %d or "
103
-						"bad flags %x\n", rv->type, rv->flags);
104
-			}
105
-			regfree(rv->v.re.regex);
106
-			pkg_free(rv->v.re.regex);
107
-			rv->v.re.regex=0;
108
-		}
109
-		rv->flags&=~(RV_RE_ALLOCED_F|RV_RE_F);
110
-	}
111
-}
112
-
113
-
114
-
115
-/** frees a rval returned by rval_new(), rval_convert() or rval_expr_eval().
116
- *   Note: it will be freed only when refcnt reaches 0
117
- */
118
-void rval_destroy(struct rvalue* rv)
119
-{
120
-	if (rv && rv_unref(rv)){
121
-		rval_force_clean(rv);
122
-		/* still an un-regfreed RE ? */
123
-		if ((rv->flags & RV_RE_F) && rv->v.re.regex){
124
-			if (unlikely(rv->type!=RV_STR))
125
-				BUG("RV_RE_F not supported for type %d\n", rv->type);
126
-			regfree(rv->v.re.regex);
127
-		}
128
-		if (rv->flags & RV_RV_ALLOCED_F){
129
-			pkg_free(rv);
130
-		}
131
-	}
132
-}
133
-
134
-
135
-
136
-void rval_clean(struct rvalue* rv)
137
-{
138
-	if (rv_unref(rv))
139
-		rval_force_clean(rv);
140
-}
141
-
142
-
143
-
144
-void rve_destroy(struct rval_expr* rve)
145
-{
146
-	if (rve){
147
-		if (rve->op==RVE_RVAL_OP){
148
-			if (rve->left.rval.refcnt){
149
-				if (rve->left.rval.refcnt==1)
150
-					rval_destroy(&rve->left.rval);
151
-				else
152
-					BUG("rval expr rval with invalid refcnt: %d (%d,%d-%d,%d)"
153
-							"\n", rve->left.rval.refcnt,
154
-							rve->fpos.s_line, rve->fpos.s_col,
155
-							rve->fpos.e_line, rve->fpos.e_col);
156
-			}
157
-			if (rve->right.rval.refcnt){
158
-				if (rve->right.rval.refcnt==1)
159
-					rval_destroy(&rve->right.rval);
160
-				else
161
-					BUG("rval expr rval with invalid refcnt: %d (%d,%d-%d,%d)"
162
-							"\n", rve->right.rval.refcnt,
163
-							rve->fpos.s_line, rve->fpos.s_col,
164
-							rve->fpos.e_line, rve->fpos.e_col);
165
-			}
166
-		}else{
167
-			if (rve->left.rve)
168
-				rve_destroy(rve->left.rve);
169
-			if (rve->right.rve)
170
-				rve_destroy(rve->right.rve);
171
-		}
172
-		pkg_free(rve);
173
-	}
174
-}
175
-
176
-
177
-
178
-void rval_cache_clean(struct rval_cache* rvc)
179
-{
180
-	if ((rvc->cache_type==RV_CACHE_PVAR) && (rvc->val_type!=RV_NONE)){
181
-		pv_value_destroy(&rvc->c.pval);
182
-	}
183
-	rvc->cache_type=RV_CACHE_EMPTY;
184
-	rvc->val_type=RV_NONE;
185
-}
186
-
187
-
188
-#define rv_chg_in_place(rv)  ((rv)->refcnt==1)
189
-
190
-
191
-
192
-/** init a rvalue structure.
193
- * Note: not needed if the structure is allocate with one of the 
194
- * rval_new* functions
195
- */
196
-void rval_init(struct rvalue* rv, enum rval_type t, union rval_val* v, 
197
-				int flags)
198
-{
199
-	rv->flags=flags;
200
-	rv->refcnt=1;
201
-	rv->type=t;
202
-	if (v){
203
-		rv->v=*v;
204
-	}else{
205
-		memset (&rv->v, 0, sizeof(rv->v));
206
-	}
207
-}
208
-
209
-
210
-
211
-/** create a new pk_malloc'ed empty rvalue.
212
-  *
213
-  * @param extra_size - extra space to allocate
214
-  *                    (e.g.: so that future string operation can reuse
215
-  *                     the space)
216
-  * @return new rv or 0 on error
217
-  */
218
-struct rvalue* rval_new_empty(int extra_size)
219
-{
220
-	struct rvalue* rv;
221
-	int size; /* extra size at the end */
222
-	
223
-	size=ROUND_LONG(sizeof(*rv)-sizeof(rv->buf)+extra_size); /* round up */
224
-	rv=pkg_malloc(size);
225
-	if (likely(rv)){
226
-		rv->bsize=size-sizeof(*rv)-sizeof(rv->buf); /* remaining size->buffer*/
227
-		rv->flags=RV_RV_ALLOCED_F;
228
-		rv->refcnt=1;
229
-		rv->type=RV_NONE;
230
-	}
231
-	return rv;
232
-}
233
-
234
-
235
-
236
-/** create a new pk_malloc'ed rv from a str.
237
-  *
238
-  * @param s - pointer to str, must be non-null
239
-  * @param extra_size - extra space to allocate
240
-  *                    (so that future string operation can reuse
241
-  *                     the space)
242
-  * @return new rv or 0 on error
243
-  */
244
-struct rvalue* rval_new_str(str* s, int extra_size)
245
-{
246
-	struct rvalue* rv;
247
-	
248
-	rv=rval_new_empty(extra_size+s->len+1/* 0 term */);
249
-	if (likely(rv)){
250
-		rv->type=RV_STR;
251
-		rv->v.s.s=&rv->buf[0];
252
-		rv->v.s.len=s->len;
253
-		memcpy(rv->v.s.s, s->s, s->len);
254
-		rv->v.s.s[s->len]=0;
255
-	}
256
-	return rv;
257
-}
258
-
259
-
260
-
261
-/** create a new pk_malloc'ed RE rv from a str re.
262
-  * It acts as rval_new_str, but also compiles a RE from the str
263
-  * and sets v->re.regex.
264
-  * @param s - pointer to str, must be non-null, zero-term'ed and a valid RE.
265
-  * @return new rv or 0 on error
266
-  */
267
-struct rvalue* rval_new_re(str* s)
268
-{
269
-	struct rvalue* rv;
270
-	long offs;
271
-	
272
-	offs=(long)&((struct rvalue*)0)->buf[0]; /* offset of the buf. member */
273
-	/* make sure we reserve enough space so that we can satisfy any regex_t
274
-	   alignment requirement (pointer) */
275
-	rv=rval_new_empty(ROUND_POINTER(offs)-offs+sizeof(*rv->v.re.regex)+
276
-						s->len+1/* 0 */);
277
-	if (likely(rv)){
278
-		rv->type=RV_STR;
279
-		/* make sure regex points to a properly aligned address
280
-		   (use max./pointer alignment to be sure ) */
281
-		rv->v.re.regex=(regex_t*)((char*)&rv->buf[0]+ROUND_POINTER(offs)-offs);
282
-		rv->v.s.s=(char*)rv->v.re.regex+sizeof(*rv->v.re.regex);
283
-		rv->v.s.len=s->len;
284
-		memcpy(rv->v.s.s, s->s, s->len);
285
-		rv->v.s.s[s->len]=0;
286
-		/* compile the regex */
287
-		/* same flags as for expr. =~ (fix_expr()) */
288
-		if (unlikely(regcomp(rv->v.re.regex, s->s,
289
-								REG_EXTENDED|REG_NOSUB|REG_ICASE))){
290
-			/* error */
291
-			pkg_free(rv);
292
-			rv=0;
293
-		}else /* success */
294
-			rv->flags|=RV_RE_F;
295
-	}
296
-	return rv;
297
-}
298
-
299
-
300
-
301
-/** get string name for a type.
302
-  *
303
-  * @return - null terminated name of the type
304
-  */
305
-char* rval_type_name(enum rval_type type)
306
-{
307
-	switch(type){
308
-		case RV_NONE:
309
-			return "none";
310
-		case RV_INT:
311
-			return "int";
312
-		case RV_STR:
313
-			return "str";
314
-		case RV_BEXPR:
315
-			return "bexpr_t";
316
-		case RV_ACTION_ST:
317
-			return "action_t";
318
-		case RV_PVAR:
319
-			return "pvar";
320
-		case RV_AVP:
321
-			return "avp";
322
-			break;
323
-		case RV_SEL:
324
-			return "select";
325
-	}
326
-	return "error_unknown_type";
327
-}
328
-
329
-
330
-
331
-/**
332
- * @brief create a new pk_malloc'ed rvalue from a rval_val union
333
- * @param t rvalue type
334
- * @param v rvalue value
335
- * @param extra_size extra space to allocate
336
- * (so that future string operation can reuse the space)
337
- * @return new rv or 0 on error
338
- */
339
-struct rvalue* rval_new(enum rval_type t, union rval_val* v, int extra_size)
340
-{
341
-	struct rvalue* rv;
342
-	
343
-	if (t==RV_STR && v && v->s.s)
344
-		return rval_new_str(&v->s, extra_size);
345
-	rv=rval_new_empty(extra_size);
346
-	if (likely(rv)){
347
-		rv->type=t;
348
-		if (likely(v && t!=RV_STR)){
349
-			rv->v=*v;
350
-		}else if (t==RV_STR){
351
-			rv->v.s.s=&rv->buf[0];
352
-			rv->v.s.len=0;
353
-			if (likely(extra_size)) rv->v.s.s[0]=0;
354
-		}else
355
-			memset (&rv->v, 0, sizeof(rv->v));
356
-	}
357
-	return rv;
358
-}
359
-
360
-
361
-
362
-/**
363
- * @brief get rvalue basic type (RV_INT or RV_STR)
364
- *
365
- * Given a rvalue it tries to determinte its basic type.
366
- * Fills val_cache if non-null and empty (can be used in other rval*
367
- * function calls, to avoid re-resolving avps or pvars). It must be
368
- * rval_cache_clean()'en when no longer needed.
369
- *
370
- * @param h run action context
371
- * @param msg SIP message
372
- * @param rv target rvalue
373
- * @param val_cache write-only value cache, might be filled if non-null,
374
- * it _must_ be rval_cache_clean()'en when done.
375
- * @return basic type or RV_NONE on error
376
- */
377
-inline static enum rval_type rval_get_btype(struct run_act_ctx* h,
378
-											struct sip_msg* msg,
379
-											struct rvalue* rv,
380
-											struct rval_cache* val_cache)
381
-{
382
-	avp_t* r_avp;
383
-	int_str tmp_avp_val;
384
-	int_str* avpv;
385
-	pv_value_t tmp_pval;
386
-	pv_value_t* pv;
387
-	enum rval_type tmp;
388
-	enum rval_type* ptype;
389
-	
390
-	switch(rv->type){
391
-		case RV_INT:
392
-		case RV_STR:
393
-			return rv->type;
394
-		case RV_BEXPR:
395
-		case RV_ACTION_ST:
396
-			return RV_INT;
397
-		case RV_PVAR:
398
-			if (likely(val_cache && val_cache->cache_type==RV_CACHE_EMPTY)){
399
-				pv=&val_cache->c.pval;
400
-				val_cache->cache_type=RV_CACHE_PVAR;
401
-			}else{
402
-				val_cache=0;
403
-				pv=&tmp_pval;
404
-			}
405
-			memset(pv, 0, sizeof(tmp_pval));
406
-			if (likely(pv_get_spec_value(msg, &rv->v.pvs, pv)==0)){
407
-				if (pv->flags & PV_TYPE_INT){
408
-					if (likely(val_cache!=0))
409
-						val_cache->val_type=RV_INT;
410
-					else
411
-						pv_value_destroy(pv);
412
-					return RV_INT;
413
-				}else if (pv->flags & PV_VAL_STR){
414
-					if (likely(val_cache!=0))
415
-						val_cache->val_type=RV_STR;
416
-					else
417
-						pv_value_destroy(pv);
418
-					return RV_STR;
419
-				}else{
420
-					pv_value_destroy(pv);
421
-					if (likely(val_cache!=0))
422
-						val_cache->val_type=RV_NONE; /* undefined */
423
-					goto error;
424
-				}
425
-			}else{
426
-				if (likely(val_cache!=0))
427
-					val_cache->val_type=RV_NONE; /* undefined */
428
-				goto error;
429
-			}
430
-			break;
431
-		case RV_AVP:
432
-			if (likely(val_cache && val_cache->cache_type==RV_CACHE_EMPTY)){
433
-				ptype=&val_cache->val_type;
434
-				avpv=&val_cache->c.avp_val;
435
-				val_cache->cache_type=RV_CACHE_AVP;
436
-			}else{
437
-				ptype=&tmp;
438
-				avpv=&tmp_avp_val;
439
-			}
440
-			r_avp = search_avp_by_index(rv->v.avps.type, rv->v.avps.name,
441
-											avpv, rv->v.avps.index);
442
-			if (likely(r_avp)){
443
-				if (r_avp->flags & AVP_VAL_STR){
444
-					*ptype=RV_STR;
445
-					return RV_STR;
446
-				}else{
447
-					*ptype=RV_INT;
448
-					return RV_INT;
449
-				}
450
-			}else{
451
-				*ptype=RV_NONE;
452
-				goto error;
453
-			}
454
-			break;
455
-		case RV_SEL:
456
-			return RV_STR;
457
-		default:
458
-			BUG("rv type %d not handled\n", rv->type);
459
-	}
460
-error:
461
-	return RV_NONE;
462
-}
463
-
464
-
465
-
466
-/** guess the type of an expression.
467
-  * @return RV_INT, RV_STR or RV_NONE (when type could not be found,
468
-  * e.g. avp or pvar)
469
-  */
470
-enum rval_type rve_guess_type( struct rval_expr* rve)
471
-{
472
-	switch(rve->op){
473
-		case RVE_RVAL_OP:
474
-			switch(rve->left.rval.type){
475
-				case RV_STR:
476
-				case RV_SEL:
477
-					return RV_STR;
478
-				case RV_INT:
479
-				case RV_BEXPR:
480
-				case RV_ACTION_ST:
481
-					return RV_INT;
482
-				case RV_PVAR:
483
-				case RV_AVP:
484
-				case RV_NONE:
485
-					return RV_NONE;
486
-			}
487
-			break;
488
-		case RVE_UMINUS_OP:
489
-		case RVE_BOOL_OP:
490
-		case RVE_LNOT_OP:
491
-		case RVE_BNOT_OP:
492
-		case RVE_MINUS_OP:
493
-		case RVE_MUL_OP:
494
-		case RVE_DIV_OP:
495
-		case RVE_MOD_OP:
496
-		case RVE_BOR_OP:
497
-		case RVE_BAND_OP:
498
-		case RVE_BXOR_OP:
499
-		case RVE_BLSHIFT_OP:
500
-		case RVE_BRSHIFT_OP:
501
-		case RVE_LAND_OP:
502
-		case RVE_LOR_OP:
503
-		case RVE_GT_OP:
504
-		case RVE_GTE_OP:
505
-		case RVE_LT_OP:
506
-		case RVE_LTE_OP:
507
-		case RVE_EQ_OP:
508
-		case RVE_DIFF_OP:
509
-		case RVE_IEQ_OP:
510
-		case RVE_IDIFF_OP:
511
-		case RVE_STREQ_OP:
512
-		case RVE_STRDIFF_OP:
513
-		case RVE_MATCH_OP:
514
-		case RVE_IPLUS_OP:
515
-		case RVE_STRLEN_OP:
516
-		case RVE_STREMPTY_OP:
517
-		case RVE_DEFINED_OP:
518
-		case RVE_NOTDEFINED_OP:
519
-		case RVE_INT_OP:
520
-			return RV_INT;
521
-		case RVE_PLUS_OP:
522
-			/* '+' evaluates to the type of the left operand */
523
-			return rve_guess_type(rve->left.rve);
524
-		case RVE_CONCAT_OP:
525
-		case RVE_STR_OP:
526
-			return RV_STR;
527
-		case RVE_NONE_OP:
528
-			break;
529
-	}
530
-	return RV_NONE;
531
-}
532
-
533
-
534
-
535
-/** returns true if expression is constant.
536
-  * @return 0 or 1 on
537
-  *  non constant type
538
-  */
539
-int rve_is_constant(struct rval_expr* rve)
540
-{
541
-	switch(rve->op){
542
-		case RVE_RVAL_OP:
543
-			switch(rve->left.rval.type){
544
-				case RV_STR:
545
-					return 1;
546
-				case RV_INT:
547
-					return 1;
548
-				case RV_SEL:
549
-				case RV_BEXPR:
550
-				case RV_ACTION_ST:
551
-				case RV_PVAR:
552
-				case RV_AVP:
553
-				case RV_NONE:
554
-					return 0;
555
-			}
556
-			break;
557
-		case RVE_UMINUS_OP:
558
-		case RVE_BOOL_OP:
559
-		case RVE_LNOT_OP:
560
-		case RVE_BNOT_OP:
561
-		case RVE_STRLEN_OP:
562
-		case RVE_STREMPTY_OP:
563
-		case RVE_DEFINED_OP:
564
-		case RVE_NOTDEFINED_OP:
565
-		case RVE_INT_OP:
566
-		case RVE_STR_OP:
567
-			return rve_is_constant(rve->left.rve);
568
-		case RVE_MINUS_OP:
569
-		case RVE_MUL_OP:
570
-		case RVE_DIV_OP:
571
-		case RVE_MOD_OP:
572
-		case RVE_BOR_OP:
573
-		case RVE_BAND_OP:
574
-		case RVE_BXOR_OP:
575
-		case RVE_BLSHIFT_OP:
576
-		case RVE_BRSHIFT_OP:
577
-		case RVE_LAND_OP:
578
-		case RVE_LOR_OP:
579
-		case RVE_GT_OP:
580
-		case RVE_GTE_OP:
581
-		case RVE_LT_OP:
582
-		case RVE_LTE_OP:
583
-		case RVE_EQ_OP:
584
-		case RVE_DIFF_OP:
585
-		case RVE_IEQ_OP:
586
-		case RVE_IDIFF_OP:
587
-		case RVE_STREQ_OP:
588
-		case RVE_STRDIFF_OP:
589
-		case RVE_MATCH_OP:
590
-		case RVE_PLUS_OP:
591
-		case RVE_IPLUS_OP:
592
-		case RVE_CONCAT_OP:
593
-			return rve_is_constant(rve->left.rve) &&
594
-					rve_is_constant(rve->right.rve);
595
-		case RVE_NONE_OP:
596
-			break;
597
-	}
598
-	return 0;
599
-}
600
-
601
-
602
-
603
-/** returns true if the expression has side-effects.
604
-  * @return  1 for possible side-effects, 0 for no side-effects
605
-  * TODO: add better checks
606
-  */
607
-int rve_has_side_effects(struct rval_expr* rve)
608
-{
609
-	return !rve_is_constant(rve);
610
-}
611
-
612
-
613
-
614
-/** returns true if operator is unary (takes only 1 arg).
615
-  * @return 0 or 1 on
616
-  */
617
-static int rve_op_unary(enum rval_expr_op op)
618
-{
619
-	switch(op){
620
-		case RVE_RVAL_OP: /* not realy an operator */
621
-			return -1;
622
-		case RVE_UMINUS_OP:
623
-		case RVE_BOOL_OP:
624
-		case RVE_LNOT_OP:
625
-		case RVE_BNOT_OP:
626
-		case RVE_STRLEN_OP:
627
-		case RVE_STREMPTY_OP:
628
-		case RVE_DEFINED_OP:
629
-		case RVE_NOTDEFINED_OP:
630
-		case RVE_INT_OP:
631
-		case RVE_STR_OP:
632
-			return 1;
633
-		case RVE_MINUS_OP:
634
-		case RVE_MUL_OP:
635
-		case RVE_DIV_OP:
636
-		case RVE_MOD_OP:
637
-		case RVE_BOR_OP:
638
-		case RVE_BAND_OP:
639
-		case RVE_BXOR_OP:
640
-		case RVE_BLSHIFT_OP:
641
-		case RVE_BRSHIFT_OP:
642
-		case RVE_LAND_OP:
643
-		case RVE_LOR_OP:
644
-		case RVE_GT_OP:
645
-		case RVE_GTE_OP:
646
-		case RVE_LT_OP:
647
-		case RVE_LTE_OP:
648
-		case RVE_EQ_OP:
649
-		case RVE_DIFF_OP:
650
-		case RVE_IEQ_OP:
651
-		case RVE_IDIFF_OP:
652
-		case RVE_STREQ_OP:
653
-		case RVE_STRDIFF_OP:
654
-		case RVE_MATCH_OP:
655
-		case RVE_PLUS_OP:
656
-		case RVE_IPLUS_OP:
657
-		case RVE_CONCAT_OP:
658
-			return 0;
659
-		case RVE_NONE_OP:
660
-			return -1;
661
-			break;
662
-	}
663
-	return 0;
664
-}
665
-
666
-
667
-
668
-/**
669
- * @brief Returns 1 if expression is valid (type-wise)
670
- * @param type filled with the type of the expression (RV_INT, RV_STR or
671
- *                RV_NONE if it's dynamic)
672
- * @param rve  checked expression
673
- * @param bad_rve set on failure to the subexpression for which the 
674
- * type check failed
675
- * @param bad_t set on failure to the type of the bad subexpression
676
- * @param exp_t set on failure to the expected type for the bad
677
- * subexpression
678
- * @return 0 or 1 and sets *type to the resulting type
679
- * (RV_INT, RV_STR or RV_NONE if it can be found only at runtime)
680
- */
681
-int rve_check_type(enum rval_type* type, struct rval_expr* rve,
682
-					struct rval_expr** bad_rve, 
683
-					enum rval_type* bad_t,
684
-					enum rval_type* exp_t)
685
-{
686
-	enum rval_type type1, type2;
687
-	
688
-	switch(rve->op){
689
-		case RVE_RVAL_OP:
690
-			*type=rve_guess_type(rve);
691
-			return 1;
692
-		case RVE_UMINUS_OP:
693
-		case RVE_BOOL_OP:
694
-		case RVE_LNOT_OP:
695
-		case RVE_BNOT_OP:
696
-			*type=RV_INT;
697
-			if (rve_check_type(&type1, rve->left.rve, bad_rve, bad_t, exp_t)){
698
-				if (type1==RV_STR){
699
-					if (bad_rve) *bad_rve=rve->left.rve;
700
-					if (bad_t) *bad_t=type1;
701
-					if (exp_t) *exp_t=RV_INT;
702
-					return 0;
703
-				}
704
-				return 1;
705
-			}
706
-			return 0;
707
-			break;
708
-		case RVE_MINUS_OP:
709
-		case RVE_MUL_OP:
710
-		case RVE_DIV_OP:
711
-		case RVE_MOD_OP:
712
-		case RVE_BOR_OP:
713
-		case RVE_BAND_OP:
714
-		case RVE_BXOR_OP:
715
-		case RVE_BLSHIFT_OP:
716
-		case RVE_BRSHIFT_OP:
717
-		case RVE_LAND_OP:
718
-		case RVE_LOR_OP:
719
-		case RVE_GT_OP:
720
-		case RVE_GTE_OP:
721
-		case RVE_LT_OP:
722
-		case RVE_LTE_OP:
723
-		case RVE_IEQ_OP:
724
-		case RVE_IDIFF_OP:
725
-		case RVE_IPLUS_OP:
726
-			*type=RV_INT;
727
-			if (rve_check_type(&type1, rve->left.rve, bad_rve, bad_t, exp_t)){
728
-				if (type1==RV_STR){
729
-					if (bad_rve) *bad_rve=rve->left.rve;
730
-					if (bad_t) *bad_t=type1;
731
-					if (exp_t) *exp_t=RV_INT;
732
-					return 0;
733
-				}
734
-				if (rve_check_type(&type2, rve->right.rve, bad_rve,
735
-									bad_t, exp_t)){
736
-					if (type2==RV_STR){
737
-						if (bad_rve) *bad_rve=rve->right.rve;
738
-						if (bad_t) *bad_t=type2;
739
-						if (exp_t) *exp_t=RV_INT;
740
-						return 0;
741
-					}
742
-					return 1;
743
-				}
744
-			}
745
-			return 0;
746
-		case RVE_EQ_OP:
747
-		case RVE_DIFF_OP:
748
-			*type=RV_INT;
749
-			if (rve_check_type(&type1, rve->left.rve, bad_rve, bad_t, exp_t)){
750
-				if (rve_check_type(&type2, rve->right.rve, bad_rve, bad_t,
751
-										exp_t)){
752
-					if ((type2!=type1) && (type1!=RV_NONE) &&
753
-							(type2!=RV_NONE) && 
754
-							!(type1==RV_STR && type2==RV_INT)){
755
-						if (bad_rve) *bad_rve=rve->right.rve;
756
-						if (bad_t) *bad_t=type2;
757
-						if (exp_t) *exp_t=type1;
758
-						return 0;
759
-					}
760
-					return 1;
761
-				}
762
-			}
763
-			return 0;
764
-		case RVE_PLUS_OP:
765
-			*type=RV_NONE;
766
-			if (rve_check_type(&type1, rve->left.rve, bad_rve, bad_t, exp_t)){
767
-				if (rve_check_type(&type2, rve->right.rve, bad_rve, bad_t,
768
-									exp_t)){
769
-					if ((type2!=type1) && (type1!=RV_NONE) &&
770
-							(type2!=RV_NONE) && 
771
-							!(type1==RV_STR && type2==RV_INT)){
772
-						if (bad_rve) *bad_rve=rve->right.rve;
773
-						if (bad_t) *bad_t=type2;
774
-						if (exp_t) *exp_t=type1;
775
-						return 0;
776
-					}
777
-					*type=type1;
778
-					return 1;
779
-				}
780
-			}
781
-			break;
782
-		case RVE_CONCAT_OP:
783
-			*type=RV_STR;
784
-			if (rve_check_type(&type1, rve->left.rve, bad_rve, bad_t, exp_t)){
785
-				if (rve_check_type(&type2, rve->right.rve, bad_rve, bad_t,
786
-									exp_t)){
787
-					if ((type2!=type1) && (type1!=RV_NONE) &&
788
-							(type2!=RV_NONE) && 
789
-							!(type1==RV_STR && type2==RV_INT)){
790
-						if (bad_rve) *bad_rve=rve->right.rve;
791
-						if (bad_t) *bad_t=type2;
792
-						if (exp_t) *exp_t=type1;
793
-						return 0;
794
-					}
795
-					if (type1==RV_INT){
796
-						if (bad_rve) *bad_rve=rve->left.rve;
797
-						if (bad_t) *bad_t=type1;
798
-						if (exp_t) *exp_t=RV_STR;
799
-						return 0;
800
-					}
801
-					return 1;
802
-				}
803
-			}
804
-			break;
805
-		case RVE_STREQ_OP:
806
-		case RVE_STRDIFF_OP:
807
-		case RVE_MATCH_OP:
808
-			*type=RV_INT;
809
-			if (rve_check_type(&type1, rve->left.rve, bad_rve, bad_t, exp_t)){
810
-				if (rve_check_type(&type2, rve->right.rve, bad_rve, bad_t,
811
-									exp_t)){
812
-					if ((type2!=type1) && (type1!=RV_NONE) &&
813
-							(type2!=RV_NONE) &&
814
-							!(type1==RV_STR && type2==RV_INT)){
815
-						if (bad_rve) *bad_rve=rve->right.rve;
816
-						if (bad_t) *bad_t=type2;
817
-						if (exp_t) *exp_t=type1;
818
-						return 0;
819
-					}
820
-					if (type1==RV_INT){
821
-						if (bad_rve) *bad_rve=rve->left.rve;
822
-						if (bad_t) *bad_t=type1;
823
-						if (exp_t) *exp_t=RV_STR;
824
-						return 0;
825
-					}
826
-					return 1;
827
-				}
828
-			}
829
-			break;
830
-		case RVE_STRLEN_OP:
831
-		case RVE_STREMPTY_OP:
832
-		case RVE_DEFINED_OP:
833
-		case RVE_NOTDEFINED_OP:
834
-			*type=RV_INT;
835
-			if (rve_check_type(&type1, rve->left.rve, bad_rve, bad_t, exp_t)){
836
-				if (type1==RV_INT){
837
-					if (bad_rve) *bad_rve=rve->left.rve;
838
-					if (bad_t) *bad_t=type1;
839
-					if (exp_t) *exp_t=RV_STR;
840
-					return 0;
841
-				}
842
-				return 1;
843
-			}
844
-			break;
845
-		case RVE_INT_OP:
846
-			*type=RV_INT;
847
-			return 1;
848
-			break;
849
-		case RVE_STR_OP:
850
-			*type=RV_STR;
851
-			return 1;
852
-			break;
853
-		case RVE_NONE_OP:
854
-		default:
855
-			BUG("unexpected rve op %d (%d,%d-%d,%d)\n", rve->op,
856
-					rve->fpos.s_line, rve->fpos.s_col,
857
-					rve->fpos.e_line, rve->fpos.e_col);
858
-			if (bad_rve) *bad_rve=rve;
859
-			if (bad_t) *bad_t=RV_NONE;
860
-			if (exp_t) *exp_t=RV_STR;
861
-			break;
862
-	}
863
-	return 0;
864
-}
865
-
866
-
867
-
868
-/** get the integer value of an rvalue.
869
-  * *i=(int)rv
870
-  * if rv == undefined select, avp or pvar, return 0.
871
-  * if an error occurs while evaluating a select, avp or pvar, behave as
872
-  * for the undefined case (and return success).
873
-  * @param h - script context handle
874
-  * @param msg - sip msg
875
-  * @param i   - pointer to int, where the conversion result will be stored
876
-  * @param rv   - rvalue to be converted
877
-  * @param cache - cached rv value (read-only), can be 0
878
-  *
879
-  * @return 0 on success, \<0 on error and EXPR_DROP on drop
880
- */
881
-int rval_get_int(struct run_act_ctx* h, struct sip_msg* msg,
882
-								int* i, struct rvalue* rv,
883
-								struct rval_cache* cache)
884
-{
885
-	avp_t* r_avp;
886
-	int_str avp_val;
887
-	pv_value_t pval;
888
-	str tmp;
889
-	str* s;
890
-	int r, ret;
891
-	int destroy_pval;
892
-	
893
-	destroy_pval=0;
894
-	s=0;
895
-	ret=0;
896
-	switch(rv->type){
897
-		case RV_INT:
898
-			*i=rv->v.l;
899
-			break;
900
-		case RV_STR:
901
-			s=&rv->v.s;
902
-			goto rv_str;
903
-		case RV_BEXPR:
904
-			*i=eval_expr(h, rv->v.bexpr, msg);
905
-			if (*i==EXPR_DROP){
906
-				*i=0; /* false */