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,2148 +0,0 @@
1
-/*
2
- * SIP routing engine
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
-
25
-/** Kamailio core :: expression evaluation, route fixups and routing lists.
26
- * @file route.c
27
- * @ingroup core
28
- * Module: @ref core
29
- */
30
-
31
-#include <stdlib.h>
32
-#include <sys/types.h>
33
-#include <regex.h>
34
-#include <netdb.h>
35
-#include <string.h>
36
-#include <sys/socket.h>
37
-#include <netinet/in.h>
38
-#include <arpa/inet.h>
39
-#include <netdb.h>
40
-
41
-#include "route.h"
42
-#include "forward.h"
43
-#include "dprint.h"
44
-#include "proxy.h"
45
-#include "action.h"
46
-#include "lvalue.h"
47
-#include "rvalue.h"
48
-#include "sr_module.h"
49
-#include "ip_addr.h"
50
-#include "resolve.h"
51
-#include "socket_info.h"
52
-#include "parser/parse_uri.h"
53
-#include "parser/parse_from.h"
54
-#include "parser/parse_to.h"
55
-#include "mem/mem.h"
56
-#include "select.h"
57
-#include "onsend.h"
58
-#include "str_hash.h"
59
-#include "ut.h"
60
-#include "rvalue.h"
61
-#include "switch.h"
62
-#include "cfg/cfg_struct.h"
63
-
64
-#define RT_HASH_SIZE	8 /* route names hash */
65
-
66
-/* main routing script table  */
67
-struct route_list main_rt;
68
-struct route_list onreply_rt;
69
-struct route_list failure_rt;
70
-struct route_list branch_rt;
71
-struct route_list onsend_rt;
72
-struct route_list event_rt;
73
-
74
-int route_type = REQUEST_ROUTE;
75
-
76
-/** script optimization level, useful for debugging.
77
- *  0 - no optimization
78
- *  1 - optimize rval expressions
79
- *  2 - optimize expr elems
80
- */
81
-int scr_opt_lev=9;
82
-
83
-inline static void destroy_rlist(struct route_list* rt)
84
-{
85
-	struct str_hash_entry* e;
86
-	struct str_hash_entry* tmp;
87
-
88
-	if (rt->rlist){
89
-		pkg_free(rt->rlist);
90
-		rt->rlist=0;
91
-		rt->entries=0;
92
-	}
93
-	if (rt->names.table){
94
-		clist_foreach_safe(rt->names.table, e, tmp, next){
95
-			pkg_free(e);
96
-		}
97
-		pkg_free(rt->names.table);
98
-		rt->names.table=0;
99
-		rt->names.size=0;
100
-	}
101
-}
102
-
103
-
104
-
105
-void destroy_routes()
106
-{
107
-	destroy_rlist(&main_rt);
108
-	destroy_rlist(&onreply_rt);
109
-	destroy_rlist(&failure_rt);
110
-	destroy_rlist(&branch_rt);
111
-	destroy_rlist(&event_rt);
112
-}
113
-
114
-
115
-
116
-/* adds route name -> i mapping
117
- * WARNING: it doesn't check for pre-existing routes 
118
- * return -1 on error, route index on success
119
- */
120
-static int route_add(struct route_list* rt, char* name, int i)
121
-{
122
-	struct str_hash_entry* e;
123
-	
124
-	e=pkg_malloc(sizeof(struct str_hash_entry));
125
-	if (e==0){
126
-		LM_CRIT("out of memory\n");
127
-		goto error;
128
-	}
129
-	LM_DBG("mapping routing block (%p)[%s] to %d\n", rt, name, i);
130
-	e->key.s=name;
131
-	e->key.len=strlen(name);
132
-	e->flags=0;
133
-	e->u.n=i;
134
-	str_hash_add(&rt->names, e);
135
-	return 0;
136
-error:
137
-	return -1;
138
-}
139
-
140
-
141
-
142
-/* returns -1 on error, 0 on success */
143
-inline  static int init_rlist(char* r_name, struct route_list* rt,
144
-								int n_entries, int hash_size)
145
-{
146
-		rt->rlist=pkg_malloc(sizeof(struct action*)*n_entries);
147
-		if (rt->rlist==0){ 
148
-			LM_CRIT("failed to allocate \"%s\" route tables: " 
149
-					"out of memory\n", r_name); 
150
-			goto error; 
151
-		}
152
-		memset(rt->rlist, 0 , sizeof(struct action*)*n_entries);
153
-		rt->idx=1; /* idx=0 == default == reserved */
154
-		rt->entries=n_entries;
155
-		if (str_hash_alloc(&rt->names, hash_size)<0){
156
-			LM_CRIT("\"%s\" route table: failed to alloc hash\n",
157
-					r_name);
158
-			goto error;
159
-		}
160
-		str_hash_init(&rt->names);
161
-		route_add(rt, "0", 0);  /* default route */
162
-		
163
-		return 0;
164
-error:
165
-		return -1;
166
-}
167
-
168
-
169
-
170
-/* init route tables */
171
-int init_routes()
172
-{
173
-	if (init_rlist("main", &main_rt, RT_NO, RT_HASH_SIZE)<0)
174
-		goto error;
175
-	if (init_rlist("on_reply", &onreply_rt, ONREPLY_RT_NO, RT_HASH_SIZE)<0)
176
-		goto error;
177
-	if (init_rlist("failure", &failure_rt, FAILURE_RT_NO, RT_HASH_SIZE)<0)
178
-		goto error;
179
-	if (init_rlist("branch", &branch_rt, BRANCH_RT_NO, RT_HASH_SIZE)<0)
180
-		goto error;
181
-	if (init_rlist("on_send", &onsend_rt, ONSEND_RT_NO, RT_HASH_SIZE)<0)
182
-		goto error;
183
-	if (init_rlist("event", &event_rt, EVENT_RT_NO, RT_HASH_SIZE)<0)
184
-		goto error;
185
-	return 0;
186
-error:
187
-	destroy_routes();
188
-	return -1;
189
-}
190
-
191
-
192
-
193
-static inline int route_new_list(struct route_list* rt)
194
-{
195
-	int ret;
196
-	struct action** tmp;
197
-	
198
-	ret=-1;
199
-	if (rt->idx >= rt->entries){
200
-		tmp=pkg_realloc(rt->rlist, 2*rt->entries*sizeof(struct action*));
201
-		if (tmp==0){
202
-			LM_CRIT("out of memory\n");
203
-			goto end;
204
-		}
205
-		/* init the newly allocated memory chunk */
206
-		memset(&tmp[rt->entries], 0, rt->entries*sizeof(struct action*));
207
-		rt->rlist=tmp;
208
-		rt->entries*=2;
209
-	}
210
-	if (rt->idx<rt->entries){
211
-		ret=rt->idx;
212
-		rt->idx++;
213
-	}
214
-end:
215
-	return ret;
216
-}
217
-
218
-
219
-
220
-
221
-/* 
222
- * if the "name" route already exists, return its index, else
223
- * create a new empty route
224
- * return route index in rt->rlist or -1 on error
225
- */
226
-int route_get(struct route_list* rt, char* name)
227
-{
228
-	int len;
229
-	struct str_hash_entry* e;
230
-	int i;
231
-	
232
-	len=strlen(name);
233
-	/* check if exists an non empty*/
234
-	e=str_hash_get(&rt->names, name, len);
235
-	if (e){
236
-		i=e->u.n;
237
-	}else{
238
-		i=route_new_list(rt);
239
-		if (i==-1) goto error;
240
-		if (route_add(rt, name, i)<0){
241
-			goto error;
242
-		}
243
-	}
244
-	return i;
245
-error:
246
-	return -1;
247
-}
248
-
249
-
250
-
251
-/* 
252
- * if the "name" route already exists, return its index, else
253
- * return error
254
- * return route index in rt->rlist or -1 on error
255
- */
256
-int route_lookup(struct route_list* rt, char* name)
257
-{
258
-	int len;
259
-	struct str_hash_entry* e;
260
-	
261
-	len=strlen(name);
262
-	/* check if exists an non empty*/
263
-	e=str_hash_get(&rt->names, name, len);
264
-	if (e){
265
-		return e->u.n;
266
-	}else{
267
-		return -1;
268
-	}
269
-}
270
-
271
-
272
-
273
-int fix_actions(struct action* a); /*fwd declaration*/
274
-
275
-
276
-/** optimize the left side of a struct expr.
277
- *  @return 1 if optimized, 0 if not and -1 on error
278
- */
279
-static int exp_optimize_left(struct expr* exp)
280
-{
281
-	struct rval_expr* rve;
282
-	struct rvalue* rval;
283
-	int old_ltype, old_rtype, old_op;
284
-	int ret;
285
-	
286
-	ret=0;
287
-	if (exp->type!=ELEM_T)
288
-		return 0;
289
-	old_ltype=exp->l_type;
290
-	old_rtype=exp->r_type;
291
-	old_op=exp->op;
292
-	if (exp->l_type==RVEXP_O){
293
-		rve=exp->l.param;
294
-		/* rve should be previously fixed/optimized */
295
-		/* optimize exp (rval(val)) -> exp(val) */
296
-		if (rve->op==RVE_RVAL_OP){
297
-			rval=&rve->left.rval;
298
-			switch(rval->type){
299
-				case RV_INT:
300
-					if (exp->op==NO_OP){
301
-						exp->l_type=NUMBER_O;
302
-						exp->l.param=0;
303
-						exp->r_type=NUMBER_ST;
304
-						exp->r.numval=rval->v.l;
305
-						rval_destroy(rval);
306
-						pkg_free(rve);
307
-						ret=1;
308
-					}
309
-					break;
310
-				case RV_STR:
311
-					/* string evaluated in expression context - not
312
-					   supported */
313
-					break;
314
-				case RV_BEXPR:
315
-					if (exp->op==NO_OP){
316
-						/* replace the current expr. */
317
-						*exp=*(rval->v.bexpr);
318
-						rval_destroy(rval);
319
-						pkg_free(rve);
320
-						ret=1;
321
-					};
322
-					break;
323
-				case RV_ACTION_ST:
324
-					if (exp->op==NO_OP){
325
-						exp->l_type=ACTION_O;
326
-						exp->l.param=0;
327
-						exp->r_type=ACTION_ST;
328
-						exp->r.param=rval->v.action;
329
-						rval_destroy(rval);
330
-						pkg_free(rve);
331
-						ret=1;
332
-					}
333
-					break;
334
-				case RV_SEL:
335
-					exp->l.select=pkg_malloc(sizeof(*exp->l.select));
336
-					if (exp->l.select){
337
-						exp->l_type=SELECT_O;
338
-						*exp->l.select=rval->v.sel;
339
-						rval_destroy(rval);
340
-						pkg_free(rve);
341
-						ret=1;
342
-					}else
343
-						ret=-1;
344
-					break;
345
-				case RV_AVP:
346
-					exp->l.attr=pkg_malloc(sizeof(*exp->l.attr));
347
-					if (exp->l.attr){
348
-						exp->l_type=AVP_O;
349
-						*exp->l.attr=rval->v.avps;
350
-						rval_destroy(rval);
351
-						pkg_free(rve);
352
-						ret=1;
353
-					}else
354
-						ret=-1;
355
-					break;
356
-				case RV_PVAR:
357
-					exp->l.param=pkg_malloc(sizeof(pv_spec_t));
358
-					if (exp->l.param){
359
-						exp->l_type=PVAR_O;
360
-						*((pv_spec_t*)exp->l.param)=rval->v.pvs;
361
-						rval_destroy(rval);
362
-						pkg_free(rve);
363
-						ret=1;
364
-					}else
365
-						ret=-1;
366
-					break;
367
-				case RV_NONE:
368
-					break;
369
-			}
370
-		}
371
-	}
372
-	if (ret>0)
373
-		LM_DBG("op%d(_O%d_, ST%d) => op%d(_O%d_, ST%d)\n",
374
-			old_op, old_ltype, old_rtype, exp->op, exp->l_type, exp->r_type);
375
-	return ret;
376
-}
377
-
378
-
379
-
380
-/** optimize the left side of a struct expr.
381
- *  @return 1 if optimized, 0 if not and -1 on error
382
- */
383
-static int exp_optimize_right(struct expr* exp)
384
-{
385
-	struct rval_expr* rve;
386
-	struct rvalue* rval;
387
-	int old_ltype, old_rtype, old_op;
388
-	int ret;
389
-	
390
-	ret=0;
391
-	if ((exp->type!=ELEM_T) ||(exp->op==NO_OP))
392
-		return 0;
393
-	old_ltype=exp->l_type;
394
-	old_rtype=exp->r_type;
395
-	old_op=exp->op;
396
-	if (exp->r_type==RVE_ST){
397
-		rve=exp->r.param;
398
-		/* rve should be previously fixed/optimized */
399
-		/* optimize exp (rval(val)) -> exp(val) */
400
-		if (rve->op==RVE_RVAL_OP){
401
-			rval=&rve->left.rval;
402
-			switch(rval->type){
403
-				case RV_INT:
404
-					exp->r_type=NUMBER_ST;
405
-					exp->r.numval=rval->v.l;
406
-					rval_destroy(rval);
407
-					pkg_free(rve);
408
-					ret=1;
409
-					break;
410
-				case RV_STR:
411
-					exp->r.str.s=pkg_malloc(rval->v.s.len+1);
412
-					if (exp->r.str.s){
413
-						exp->r.str.len=rval->v.s.len;
414
-						memcpy(exp->r.str.s, rval->v.s.s, rval->v.s.len);
415
-						exp->r.str.s[exp->r.str.len]=0;
416
-						exp->r_type=STRING_ST;
417
-						rval_destroy(rval);
418
-						pkg_free(rve);
419
-						ret=1;
420
-					}else
421
-						ret=-1;
422
-					break;
423
-				case RV_BEXPR:
424
-					/* cannot be optimized further, is an exp_elem
425
-					   which is not constant */
426
-					break;
427
-				case RV_ACTION_ST:
428
-					/* cannot be optimized further, is not constant and
429
-					  eval_elem() does not support ACTION_ST for op!=NO_OP*/
430
-					break;
431
-				case RV_SEL:
432
-					exp->r.select=pkg_malloc(sizeof(*exp->l.select));
433
-					if (exp->r.select){
434
-						exp->r_type=SELECT_ST;
435
-						*exp->r.select=rval->v.sel;
436
-						rval_destroy(rval);
437
-						pkg_free(rve);
438
-						ret=1;
439
-					}else
440
-						ret=-1;
441
-					break;
442
-				case RV_AVP:
443
-					exp->r.attr=pkg_malloc(sizeof(*exp->l.attr));
444
-					if (exp->r.attr){
445
-						exp->r_type=AVP_ST;
446
-						*exp->r.attr=rval->v.avps;
447
-						rval_destroy(rval);
448
-						pkg_free(rve);
449
-						ret=1;
450
-					}else
451
-						ret=-1;
452
-					break;
453
-				case RV_PVAR:
454
-					exp->r.param=pkg_malloc(sizeof(pv_spec_t));
455
-					if (exp->r.param){
456
-						exp->r_type=PVAR_ST;
457
-						*((pv_spec_t*)exp->r.param)=rval->v.pvs;
458
-						rval_destroy(rval);
459
-						pkg_free(rve);
460
-						ret=1;
461
-					}else
462
-						ret=-1;
463
-					break;
464
-				case RV_NONE:
465
-					ret=-1;
466
-					break;
467
-			}
468
-		}
469
-	}
470
-	if (ret>0)
471
-		LM_DBG("op%d(O%d, _ST%d_) => op%d(O%d, _ST%d_)\n",
472
-			old_op, old_ltype, old_rtype, exp->op, exp->l_type, exp->r_type);
473
-	return ret;
474
-}
475
-
476
-
477
-
478
-/* traverses an expr tree and compiles the REs where necessary)
479
- * returns: 0 for ok, <0 if errors */
480
-int fix_expr(struct expr* exp)
481
-{
482
-	regex_t* re;
483
-	int ret;
484
-	int len;
485
-
486
-	ret=E_BUG;
487
-	if (exp==0){
488
-		LM_CRIT("null pointer\n");
489
-		return E_BUG;
490
-	}
491
-	if (exp->type==EXP_T){
492
-		switch(exp->op){
493
-			case LOGAND_OP:
494
-			case LOGOR_OP:
495
-						if ((ret=fix_expr(exp->l.expr))!=0)
496
-							return ret;
497
-						ret=fix_expr(exp->r.expr);
498
-						break;
499
-			case NOT_OP:
500
-						ret=fix_expr(exp->l.expr);
501
-						break;
502
-			default:
503
-						LM_CRIT("unknown op %d\n", exp->op);
504
-		}
505
-	}else if (exp->type==ELEM_T){
506
-			/* first calculate lengths of strings  (only right side, since 
507
-			  left side can never be a string) */
508
-			if (exp->r_type==STRING_ST) {
509
-				if (exp->r.string) len = strlen(exp->r.string);
510
-				else len = 0;
511
-				exp->r.str.s = exp->r.string;
512
-				exp->r.str.len = len;
513
-			}
514
-			/* then fix & optimize rve/rvals (they might be optimized
515
-			   to non-rvals, e.g. string, avp a.s.o and needs to be done
516
-			   before MATCH_OP and other fixups) */
517
-			if (exp->l_type==RVEXP_O){
518
-				if ((ret=fix_rval_expr(exp->l.param))<0){
519
-					LM_ERR("Unable to fix left rval expression\n");
520
-					return ret;
521
-				}
522
-				if (scr_opt_lev>=2)
523
-					exp_optimize_left(exp);
524
-			}
525
-			if (exp->r_type==RVE_ST){
526
-				if ((ret=fix_rval_expr(exp->r.param))<0){
527
-					LM_ERR("Unable to fix right rval expression\n");
528
-					return ret;
529
-				}
530
-				if (scr_opt_lev>=2)
531
-					exp_optimize_right(exp);
532
-			}
533
-			
534
-			
535
-			if (exp->op==MATCH_OP){
536
-				     /* right side either has to be string, in which case
537
-				      * we turn it into regular expression, or it is regular
538
-				      * expression already. In that case we do nothing
539
-				      */
540
-				if (exp->r_type==STRING_ST){
541
-					re=(regex_t*)pkg_malloc(sizeof(regex_t));
542
-					if (re==0){
543
-						LM_CRIT("memory allocation failure\n");
544
-						return E_OUT_OF_MEM;
545
-					}
546
-					if (regcomp(re, (char*) exp->r.param,
547
-								REG_EXTENDED|REG_NOSUB|REG_ICASE) ){
548
-						LM_CRIT("bad re \"%s\"\n", (char*) exp->r.param);
549
-						pkg_free(re);
550
-						return E_BAD_RE;
551
-					}
552
-					/* replace the string with the re */
553
-					pkg_free(exp->r.param);
554
-					exp->r.re=re;
555
-					exp->r_type=RE_ST;
556
-				}else if (exp->r_type!=RE_ST && exp->r_type != AVP_ST
557
-						&& exp->r_type != SELECT_ST &&
558
-						exp->r_type != SELECT_UNFIXED_ST &&
559
-						exp->r_type!= RVE_ST
560
-						&& exp->r_type != PVAR_ST){
561
-					LM_CRIT("invalid type for match\n");
562
-					return E_BUG;
563
-				}
564
-			}
565
-			if (exp->l_type==ACTION_O){
566
-				ret=fix_actions((struct action*)exp->r.param);
567
-				if (ret!=0){
568
-					LM_CRIT("fix_actions error\n");
569
-					return ret;
570
-				}
571
-			}
572
-			if (exp->l_type==SELECT_UNFIXED_O) {
573
-				if ((ret=resolve_select(exp->l.select)) < 0) {
574
-					LM_ERR("Unable to resolve select\n");
575
-					print_select(exp->l.select);
576
-					return ret;
577
-				}
578
-				exp->l_type=SELECT_O;
579
-			}
580
-			if (exp->r_type==SELECT_UNFIXED_ST) {
581
-				if ((ret=resolve_select(exp->r.select)) < 0) {
582
-					LM_ERR("Unable to resolve select\n");
583
-					print_select(exp->r.select);
584
-					return ret;
585
-				}
586
-				exp->r_type=SELECT_ST;
587
-			}
588
-			/* PVAR don't need fixing */
589
-			ret=0;
590
-	}
591
-	return ret;
592
-}
593
-
594
-
595
-
596
-/* adds the proxies in the proxy list & resolves the hostnames */
597
-/* returns 0 if ok, <0 on error */
598
-int fix_actions(struct action* a)
599
-{
600
-	struct action *t;
601
-	struct proxy_l* p;
602
-	char *tmp;
603
-	void *tmp_p;
604
-	int ret;
605
-	int i;
606
-	sr31_cmd_export_t* cmd;
607
-	str s;
608
-	struct hostent* he;
609
-	struct ip_addr ip;
610
-	struct socket_info* si;
611
-	struct lvalue* lval;
612
-	struct rval_expr* rve;
613
-	struct rval_expr* err_rve;
614
-	enum rval_type rve_type, err_type, expected_type;
615
-	struct rvalue* rv;
616
-	int rve_param_no;
617
-
618
-	if (a==0){
619
-		LM_CRIT("null pointer\n");
620
-		return E_BUG;
621
-	}
622
-	for(t=a; t!=0; t=t->next){
623
-		switch(t->type){
624
-			case FORWARD_T:
625
-			case FORWARD_TLS_T:
626
-			case FORWARD_TCP_T:
627
-			case FORWARD_SCTP_T:
628
-			case FORWARD_UDP_T:
629
-					switch(t->val[0].type){
630
-						case IP_ST:
631
-							tmp=strdup(ip_addr2a(
632
-										(struct ip_addr*)t->val[0].u.data));
633
-							if (tmp==0){
634
-								LM_CRIT("memory allocation failure\n");
635
-								ret = E_OUT_OF_MEM;
636
-								goto error;
637
-							}
638
-							t->val[0].type=STRING_ST;
639
-							t->val[0].u.string=tmp;
640
-							/* no break */
641
-						case STRING_ST:
642
-							s.s = t->val[0].u.string;
643
-							s.len = strlen(s.s);
644
-							p=add_proxy(&s, t->val[1].u.number, 0); /* FIXME proto*/
645
-							if (p==0) { ret =E_BAD_ADDRESS; goto error; }
646
-							t->val[0].u.data=p;
647
-							t->val[0].type=PROXY_ST;
648
-							break;
649
-						case URIHOST_ST:
650
-							break;
651
-						default:
652
-							LM_CRIT("invalid type %d (should be string or number)\n",
653
-										t->type);
654
-							ret = E_BUG;
655
-							goto error;
656
-					}
657
-					break;
658
-			case IF_T:
659
-				if (t->val[0].type!=RVE_ST){
660
-					LM_CRIT("invalid subtype %d for if (should be rval expr)\n",
661
-								t->val[0].type);
662
-					ret = E_BUG;
663
-					goto error;
664
-				}else if( (t->val[1].type!=ACTIONS_ST) &&
665
-							(t->val[1].type!=NOSUBTYPE) ){
666
-					LM_CRIT("invalid subtype %d for if() {...} (should be action)\n",
667
-								t->val[1].type);
668
-					ret = E_BUG;
669
-					goto error;
670
-				}else if( (t->val[2].type!=ACTIONS_ST) &&
671
-							(t->val[2].type!=NOSUBTYPE) ){
672
-					LM_CRIT("invalid subtype %d for if() {} else{...}(should be action)\n",
673
-								t->val[2].type);
674
-					ret = E_BUG;
675
-					goto error;
676
-				}
677
-				rve=(struct rval_expr*)t->val[0].u.data;
678
-				if (rve){
679
-					err_rve=0;
680
-					if (!rve_check_type(&rve_type, rve, &err_rve,
681
-											&err_type, &expected_type)){
682
-						if (err_rve)
683
-							LM_ERR("invalid expression "
684
-									"(%d,%d): subexpression (%d,%d) has type"
685
-									" %s,  but %s is expected\n",
686
-									rve->fpos.s_line, rve->fpos.s_col,
687
-									err_rve->fpos.s_line, err_rve->fpos.s_col,
688
-									rval_type_name(err_type),
689
-									rval_type_name(expected_type) );
690
-						else
691
-							LM_ERR("invalid expression  (%d,%d): type mismatch?",
692
-									rve->fpos.s_line, rve->fpos.s_col);
693
-						ret = E_SCRIPT;
694
-						goto error;
695
-					}
696
-					/* it's not an error anymore to have non-int in an if,
697
-					   only a script warning (to allow backward compat. stuff
698
-					   like if (@ruri) 
699
-					if (rve_type!=RV_INT && rve_type!=RV_NONE){
700
-						LM_ERR("fix_actions: invalid expression (%d,%d):"
701
-								" bad type, integer expected\n",
702
-								rve->fpos.s_line, rve->fpos.s_col);
703
-						return E_UNSPEC;
704
-					}
705
-					*/
706
-					if ((ret=fix_rval_expr(t->val[0].u.data))<0)
707
-						goto error;
708
-				}
709
-				if ( (t->val[1].type==ACTIONS_ST)&&(t->val[1].u.data) ){
710
-					if ((ret=fix_actions((struct action*)t->val[1].u.data))<0)
711
-						goto error;
712
-				}
713
-				if ( (t->val[2].type==ACTIONS_ST)&&(t->val[2].u.data) ){
714
-						if ((ret=fix_actions((struct action*)t->val[2].u.data))
715
-								<0)
716
-						goto error;
717
-				}
718
-				break;
719
-			case SWITCH_T:
720
-				if (t->val[0].type!=RVE_ST){
721
-					LM_CRIT("invalid subtype %d for switch() (should be expr)\n",
722
-								t->val[0].type);
723
-					ret = E_BUG;
724
-					goto error;
725
-				}else if (t->val[1].type!=CASE_ST){
726
-					LM_CRIT("invalid subtype %d for switch(...){...}(should be case)\n",
727
-								t->val[1].type);
728
-					ret = E_BUG;
729
-					goto error;
730
-				}
731
-				if (t->val[0].u.data){
732
-					if ((ret=fix_rval_expr(t->val[0].u.data))<0)
733
-						goto error;
734
-				}else{
735
-					LM_CRIT("null switch() expression\n");
736
-					ret = E_BUG;
737
-					goto error;
738
-				}
739
-				if ((ret=fix_switch(t))<0)
740
-					goto error;
741
-				break;
742
-			case WHILE_T:
743
-				if (t->val[0].type!=RVE_ST){
744
-					LM_CRIT("invalid subtype %d for while() (should be expr)\n",
745
-								t->val[0].type);
746
-					ret = E_BUG;
747
-					goto error;
748
-				}else if (t->val[1].type!=ACTIONS_ST){
749
-					LM_CRIT("invalid subtype %d for while(...){...}(should be action)\n",
750
-								t->val[1].type);
751
-					ret = E_BUG;
752
-					goto error;
753
-				}
754
-				rve=(struct rval_expr*)t->val[0].u.data;
755
-				if (rve){
756
-					err_rve=0;
757
-					if (!rve_check_type(&rve_type, rve, &err_rve,
758
-											&err_type, &expected_type)){
759
-						if (err_rve)
760
-							LM_ERR("invalid expression "
761
-									"(%d,%d): subexpression (%d,%d) has type"
762
-									" %s,  but %s is expected\n",
763
-									rve->fpos.s_line, rve->fpos.s_col,
764
-									err_rve->fpos.s_line, err_rve->fpos.s_col,
765
-									rval_type_name(err_type),
766
-									rval_type_name(expected_type) );
767
-						else
768
-							LM_ERR("invalid expression (%d,%d): type mismatch?",
769
-									rve->fpos.s_line, rve->fpos.s_col);
770
-						ret = E_SCRIPT;
771
-						goto error;
772
-					}
773
-					if (rve_type!=RV_INT && rve_type!=RV_NONE){
774
-						LM_ERR("invalid expression (%d,%d): bad type, integer expected\n",
775
-								rve->fpos.s_line, rve->fpos.s_col);
776
-						ret = E_SCRIPT;
777
-						goto error;
778
-					}
779
-					if ((ret=fix_rval_expr(t->val[0].u.data))<0)
780
-						goto error;
781
-				}else{
782
-					LM_CRIT("null while() expression\n");
783
-					ret = E_BUG;
784
-					goto error;
785
-				}
786
-				if ( t->val[1].u.data && 
787
-					((ret= fix_actions((struct action*)t->val[1].u.data))<0)){
788
-					goto error;
789
-				}
790
-				break;
791
-			case DROP_T:
792
-				/* only RVEs need fixing for drop/return/break */
793
-				if (t->val[0].type!=RVE_ST)
794
-					break;
795
-				rve=(struct rval_expr*)t->val[0].u.data;
796
-				if (rve){
797
-					err_rve=0;
798
-					if (!rve_check_type(&rve_type, rve, &err_rve,
799
-											&err_type, &expected_type)){
800
-						if (err_rve)
801
-							LM_ERR("invalid expression "
802
-									"(%d,%d): subexpression (%d,%d) has type"
803
-									" %s,  but %s is expected\n",
804
-									rve->fpos.s_line, rve->fpos.s_col,
805
-									err_rve->fpos.s_line, err_rve->fpos.s_col,
806
-									rval_type_name(err_type),
807
-									rval_type_name(expected_type) );
808
-						else
809
-							LM_ERR("invalid expression (%d,%d): type mismatch?",
810
-									rve->fpos.s_line, rve->fpos.s_col);
811
-						ret = E_SCRIPT;
812
-						goto error;
813
-					}
814
-					if (rve_type!=RV_INT && rve_type!=RV_NONE){
815
-						LM_ERR("invalid expression (%d,%d): bad type, integer expected\n",
816
-								rve->fpos.s_line, rve->fpos.s_col);
817
-						ret = E_SCRIPT;
818
-						goto error;
819
-					}
820
-					if ((ret=fix_rval_expr(t->val[0].u.data))<0)
821
-						goto error;
822
-				}else{
823
-					LM_CRIT("null drop/return expression\n");
824
-					ret = E_BUG;
825
-					goto error;
826
-				}
827
-				break;
828
-			case ASSIGN_T:
829
-			case ADD_T:
830
-				if (t->val[0].type !=LVAL_ST) {
831
-					LM_CRIT("Invalid left side of assignment\n");
832
-					ret = E_BUG;
833
-					goto error;
834
-				}
835
-				if (t->val[1].type !=RVE_ST) {
836
-					LM_CRIT("Invalid right side of assignment (%d)\n",
837
-								t->val[1].type);
838
-					ret = E_BUG;
839
-					goto error;
840
-				}
841
-				lval=t->val[0].u.data;
842
-				if (lval->type==LV_AVP){
843
-					if (lval->lv.avps.type & AVP_CLASS_DOMAIN) {
844
-						LM_ERR("You cannot change domain"
845
-									" attributes from the script, they are"
846
-									" read-only\n");
847
-						ret = E_BUG;
848
-						goto error;
849
-					} else if (lval->lv.avps.type & AVP_CLASS_GLOBAL) {
850
-						LM_ERR("You cannot change global"
851
-								   " attributes from the script, they are"
852
-								   "read-only\n");
853
-						ret = E_BUG;
854
-						goto error;
855
-					}
856
-				}
857
-				if ((ret=fix_rval_expr(t->val[1].u.data))<0)
858
-					goto error;
859
-				break;
860
-
861
-			case MODULE0_T:
862
-			case MODULE1_T:
863
-			case MODULE2_T:
864
-			case MODULE3_T:
865
-			case MODULE4_T:
866
-			case MODULE5_T:
867
-			case MODULE6_T:
868
-			case MODULEX_T:
869
-				cmd = t->val[0].u.data;
870
-				rve_param_no = 0;
871
-				if (cmd) {
872
-					LM_DBG("fixing %s()\n", cmd->name);
873
-					if (t->val[1].u.number==0) {
874
-						ret = call_fixup(cmd->fixup, 0, 0);
875
-						if (ret < 0)
876
-							goto error;
877
-					}
878
-					for (i=0; i < t->val[1].u.number; i++) {
879
-						if (t->val[i+2].type == RVE_ST) {
880
-							rve = t->val[i+2].u.data;
881
-							if (rve_is_constant(rve)) {
882
-								/* if expression is constant => evaluate it
883
-								   as string and replace it with the corresp.
884
-								   string */
885
-								rv = rval_expr_eval(0, 0, rve);
886
-								if (rv == 0 ||
887
-										rval_get_str( 0, 0, &s, rv, 0) < 0 ) {
888
-									ERR("failed to fix constant rve");
889
-									if (rv) rval_destroy(rv);
890
-									ret = E_BUG;
891
-									goto error;
892
-								}
893
-								rval_destroy(rv);
894
-								rve_destroy(rve);
895
-								t->val[i+2].type = STRING_ST;/*asciiz string*/
896
-								t->val[i+2].u.string = s.s;
897
-								/* len is not used for now */
898
-								t->val[i+2].u.str.len = s.len;
899
-								tmp_p = t->val[i+2].u.data;
900
-								ret = call_fixup(cmd->fixup,
901
-												&t->val[i+2].u.data, i+1);
902
-								if (t->val[i+2].u.data != tmp_p)
903
-									t->val[i+2].type = MODFIXUP_ST;
904
-								if (ret < 0)
905
-									goto error;