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,417 +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 :: lvalues (assignment)
20
- * \ingroup core
21
- * Module: \ref core
22
- */
23
-
24
-#include "lvalue.h"
25
-#include "dprint.h"
26
-#include "route.h"
27
-
28
-/* callback to log assign actions */
29
-static log_assign_action_f _log_assign_action = NULL;
30
-
31
-/**
32
- * @brief set callback function log assign actions
33
- */
34
-void set_log_assign_action_cb(log_assign_action_f f)
35
-{
36
-	_log_assign_action = f;
37
-}
38
-
39
-/**
40
- * @brief eval rve and assign the result to an avp
41
- * 
42
- * eval rve and assign the result to an avp, lv->lv.avp=eval(rve)
43
- * based on do_action() ASSIGN_T.
44
- * @param h  - script context
45
- * @param msg - sip msg
46
- * @param lv - lvalue
47
- * @param rv - rvalue expression
48
- * @return >= 0 on success (expr. bool value), -1 on error
49
- */
50
-inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
51
-									struct lvalue* lv, struct rvalue* rv)
52
-{
53
-	avp_spec_t* avp;
54
-	avp_t* r_avp;
55
-	avp_t* avp_mark;
56
-	pv_value_t pval;
57
-	int_str value;
58
-	unsigned short flags;
59
-	struct search_state st;
60
-	int ret, v, destroy_pval;
61
-	int avp_add;
62
-
63
-#if 0
64
-	#define AVP_ASSIGN_NOVAL() \
65
-		/* unknown value => reset the avp in function of its type */ \
66
-		flags=avp->type; \
67
-		if (flags & AVP_VAL_STR){ \
68
-			value.s.s=""; \
69
-			value.s.len=0; \
70
-		}else{ \
71
-			value.n=0; \
72
-		}
73
-#endif
74
-	#define AVP_ASSIGN_NOVAL() \
75
-		/* no value => delete avp */ \
76
-		avp_add=0
77
-	
78
-	destroy_pval=0;
79
-	flags = 0;
80
-	avp=&lv->lv.avps;
81
-	ret=0;
82
-	avp_add=1;
83
-	
84
-	switch(rv->type){
85
-		case RV_NONE:
86
-			BUG("non-initialized rval / rval expr \n");
87
-			/* unknown value => reset the avp in function of its type */
88
-			flags=avp->type;
89
-			AVP_ASSIGN_NOVAL();
90
-			ret=-1;
91
-			break;
92
-		case RV_INT:
93
-			value.n=rv->v.l;
94
-			flags=avp->type & ~AVP_VAL_STR;
95
-			ret=!(!value.n);
96
-			break;
97
-		case RV_STR:
98
-			value.s=rv->v.s;
99
-			flags=avp->type | AVP_VAL_STR;
100
-			ret=(value.s.len>0);
101
-			break;
102
-		case RV_ACTION_ST:
103
-			flags=avp->type & ~AVP_VAL_STR;
104
-			if (rv->v.action) {
105
-				value.n=run_actions_safe(h, rv->v.action, msg);
106
-				h->run_flags &= ~(RETURN_R_F|BREAK_R_F); /* catch return &
107
-														    break in expr*/
108
-			} else
109
-				value.n=-1;
110
-			ret=value.n;
111
-			break;
112
-		case RV_BEXPR: /* logic/boolean expr. */
113
-			value.n=eval_expr(h, rv->v.bexpr, msg);
114
-			if (unlikely(value.n<0)){
115
-				if (value.n==EXPR_DROP) /* hack to quit on drop */
116
-					goto drop;
117
-				WARN("error in expression\n");
118
-				value.n=0; /* expr. is treated as false */
119
-			}
120
-			flags=avp->type & ~AVP_VAL_STR;
121
-			ret=value.n;
122
-			break;
123
-		case RV_SEL:
124
-			flags=avp->type|AVP_VAL_STR;
125
-			v=run_select(&value.s, &rv->v.sel, msg);
126
-			if (unlikely(v!=0)){
127
-				value.s.s="";
128
-				value.s.len=0;
129
-				if (v<0){
130
-					ret=-1;
131
-					break;
132
-				} /* v>0 */
133
-			}
134
-			ret=(value.s.len>0);
135
-			break;
136
-		case RV_AVP:
137
-			avp_mark=0;
138
-			if (unlikely((rv->v.avps.type & AVP_INDEX_ALL) == AVP_INDEX_ALL)){
139
-				/* special case: add the value to the avp */
140
-				r_avp = search_first_avp(rv->v.avps.type, rv->v.avps.name,
141
-											&value, &st);
142
-				while(r_avp){
143
-					/* We take only the val type  from the source avp
144
-					 * and reset the class, track flags and name type  */
145
-					flags=(avp->type & ~(AVP_INDEX_ALL|AVP_VAL_STR)) | 
146
-							(r_avp->flags & ~(AVP_CLASS_ALL|AVP_TRACK_ALL|
147
-												AVP_NAME_STR|AVP_NAME_RE));
148
-					if (add_avp_before(avp_mark, flags, avp->name, value)<0){
149
-						ERR("failed to assign avp\n");
150
-						ret=-1;
151
-						goto error;
152
-					}
153
-					/* move the mark, so the next found AVP will come before
154
-					   the one currently added so they will have the same 
155
-					   order as in the source list */
156
-					if (avp_mark) avp_mark=avp_mark->next;
157
-					else
158
-						avp_mark=search_first_avp(flags, avp->name, 0, 0);
159
-					r_avp=search_next_avp(&st, &value);
160
-				}
161
-				ret=1;
162
-				goto end;
163
-			}else{
164
-				/* normal case, value is replaced */
165
-				r_avp = search_avp_by_index(rv->v.avps.type, rv->v.avps.name,
166
-											&value, rv->v.avps.index);
167
-				if (likely(r_avp)){
168
-					/* take only the val type from the source avp
169
-					 * and reset the class, track flags and name type  */
170
-					flags=(avp->type & ~AVP_VAL_STR) | (r_avp->flags & 
171
-								~(AVP_CLASS_ALL|AVP_TRACK_ALL|AVP_NAME_STR|
172
-									AVP_NAME_RE));
173
-					ret=1;
174
-				}else{
175
-					/* on error, keep the type of the assigned avp, but
176
-					   reset it to an empty value */
177
-					AVP_ASSIGN_NOVAL();
178
-					ret=0;
179
-					break;
180
-				}
181
-			}
182
-			break;
183
-		case RV_PVAR:
184
-			memset(&pval, 0, sizeof(pval));
185
-			if (likely(pv_get_spec_value(msg, &rv->v.pvs, &pval)==0)){
186
-				destroy_pval=1;
187
-				if (pval.flags & PV_TYPE_INT){
188
-					value.n=pval.ri;
189
-					ret=value.n;
190
-					flags=avp->type & ~AVP_VAL_STR;
191
-				}else if (pval.flags & PV_VAL_STR){
192
-					value.s=pval.rs;
193
-					ret=(value.s.len>0);
194
-					flags=avp->type | AVP_VAL_STR;
195
-				}else if (pval.flags==PV_VAL_NONE ||
196
-							(pval.flags & (PV_VAL_NULL|PV_VAL_EMPTY))){
197
-					AVP_ASSIGN_NOVAL();
198
-					ret=0;
199
-				}
200
-			}else{
201
-				/* non existing pvar */
202
-				/* on error, keep the type of the assigned avp, but
203
-				   reset it to an empty value */
204
-				AVP_ASSIGN_NOVAL();
205
-				ret=0;
206
-			}
207
-			break;
208
-	}
209
-	/* If the left attr was specified without indexing brackets delete
210
-	 * existing AVPs before adding the new value */
211
-	delete_avp(avp->type, avp->name);
212
-	if (avp_add && (add_avp(flags & ~AVP_INDEX_ALL, avp->name, value) < 0)) {
213
-		ERR("failed to assign value to avp\n");
214
-		goto error;
215
-	}
216
-end:
217
-	if (destroy_pval) pv_value_destroy(&pval);
218
-	return ret;
219
-error:
220
-	if (destroy_pval) pv_value_destroy(&pval);
221
-	return -1;
222
-drop:
223
-	if (destroy_pval) pv_value_destroy(&pval);
224
-	return EXPR_DROP;
225
-}
226
-
227
-
228
-
229
-/**
230
- * @brief eval rve and assign the result to a pvar
231
- *
232
- * eval rve and assign the result to a pvar, lv->lv.pvar=eval(rve)
233
- * based on do_action() ASSIGN_T.
234
- * @param h  - script context
235
- * @param msg - sip msg
236
- * @param lv - lvalue
237
- * @param rv - rvalue expression
238
- * @return >= 0 on success (expr. bool value), -1 on error
239
- */
240
-inline static int lval_pvar_assign(struct run_act_ctx* h, struct sip_msg* msg,
241
-									struct lvalue* lv, struct rvalue* rv)
242
-{
243
-	pv_spec_t* pvar;
244
-	pv_value_t pval;
245
-	avp_t* r_avp;
246
-	int_str avp_val;
247
-	int ret;
248
-	int v;
249
-	int destroy_pval;
250
-	
251
-	#define PVAR_ASSIGN_NOVAL() \
252
-		/* no value found => "undefine" */ \
253
-		pv_get_null(msg, 0, &pval)
254
-	
255
-	destroy_pval=0;
256
-	pvar=lv->lv.pvs;
257
-	if (unlikely(!pv_is_w(pvar))){
258
-		ERR("read only pvar\n");
259
-		goto error;
260
-	}
261
-	memset(&pval, 0, sizeof(pval));
262
-	ret=0;
263
-	switch(rv->type){
264
-		case RV_NONE:
265
-			BUG("non-initialized rval / rval expr \n");
266
-			PVAR_ASSIGN_NOVAL();
267
-			ret=-1;
268
-			break;
269
-		case RV_INT:
270
-			pval.flags=PV_TYPE_INT|PV_VAL_INT;
271
-			pval.ri=rv->v.l;
272
-			ret=!(!pval.ri);
273
-			break;
274
-		case RV_STR:
275
-			pval.flags=PV_VAL_STR;
276
-			pval.rs=rv->v.s;
277
-			ret=(pval.rs.len>0);
278
-			break;
279
-		case RV_ACTION_ST:
280
-			pval.flags=PV_TYPE_INT|PV_VAL_INT;
281
-			if (rv->v.action) {
282
-				pval.ri=run_actions_safe(h, rv->v.action, msg);
283
-				h->run_flags &= ~(RETURN_R_F|BREAK_R_F); /* catch return &
284
-														    break in expr*/
285
-			} else
286
-				pval.ri=0;
287
-			ret=!(!pval.ri);
288
-			break;
289
-		case RV_BEXPR: /* logic/boolean expr. */
290
-			pval.flags=PV_TYPE_INT|PV_VAL_INT;
291
-			pval.ri=eval_expr(h, rv->v.bexpr, msg);
292
-			if (unlikely(pval.ri<0)){
293
-				if (pval.ri==EXPR_DROP) /* hack to quit on drop */
294
-					goto drop;
295
-				WARN("error in expression\n");
296
-				pval.ri=0; /* expr. is treated as false */
297
-			}
298
-			ret=!(!pval.ri);
299
-			break;
300
-		case RV_SEL:
301
-			pval.flags=PV_VAL_STR;
302
-			v=run_select(&pval.rs, &rv->v.sel, msg);
303
-			if (unlikely(v!=0)){
304
-				pval.flags|=PV_VAL_EMPTY;
305
-				pval.rs.s="";
306
-				pval.rs.len=0;
307
-				if (v<0){
308
-					ret=-1;
309
-					break;
310
-				}
311
-			}
312
-			ret=(pval.rs.len>0);
313
-			break;
314
-		case RV_AVP:
315
-				r_avp = search_avp_by_index(rv->v.avps.type, rv->v.avps.name,
316
-											&avp_val, rv->v.avps.index);
317
-				if (likely(r_avp)){
318
-					if (r_avp->flags & AVP_VAL_STR){
319
-						pval.flags=PV_VAL_STR;
320
-						pval.rs=avp_val.s;
321
-						ret=(pval.rs.len>0);
322
-					}else{
323
-						pval.flags=PV_TYPE_INT|PV_VAL_INT;
324
-						pval.ri=avp_val.n;
325
-						ret=!(!pval.ri);
326
-					}
327
-				}else{
328
-					PVAR_ASSIGN_NOVAL();
329
-					ret=0; /* avp not defined (valid case) */
330
-					break;
331
-				}
332
-			break;
333
-		case RV_PVAR:
334
-			if (likely(pv_get_spec_value(msg, &rv->v.pvs, &pval)==0)){
335
-				destroy_pval=1;
336
-				if (pval.flags & PV_TYPE_INT){
337
-					ret=!(!pval.ri);
338
-				}else if (pval.flags & PV_VAL_STR){
339
-					ret=(pval.rs.len>0);
340
-				}else{
341
-					/* no value / not defined (e.g. avp) -> keep the flags */
342
-					ret=0;
343
-				}
344
-			}else{
345
-				ERR("non existing right pvar\n");
346
-				PVAR_ASSIGN_NOVAL();
347
-				ret=-1;
348
-			}
349
-			break;
350
-	}
351
-	if (unlikely(pvar->setf(msg, &pvar->pvp, EQ_T, &pval)<0)){
352
-		ERR("setting pvar failed\n");
353
-		goto error;
354
-	}
355
-	if (destroy_pval) pv_value_destroy(&pval);
356
-	return ret;
357
-error:
358
-	if (destroy_pval) pv_value_destroy(&pval);
359
-	return -1;
360
-drop:
361
-	if (destroy_pval) pv_value_destroy(&pval);
362
-	return EXPR_DROP;
363
-}
364
-
365
-
366
-
367
-/** eval rve and assign the result to lv
368
- * lv=eval(rve)
369
- *
370
- * @param h  - script context
371
- * @param msg - sip msg
372
- * @param lv - lvalue
373
- * @param rve - rvalue expression
374
- * @return >= 0 on success (expr. bool value), -1 on error
375
- */
376
-int lval_assign(struct run_act_ctx* h, struct sip_msg* msg, 
377
-				struct lvalue* lv, struct rval_expr* rve)
378
-{
379
-	struct rvalue* rv;
380
-	int ret;
381
-	
382
-	ret=0;
383
-	rv=rval_expr_eval(h, msg, rve);
384
-	if (unlikely(rv==0)){
385
-		ERR("rval expression evaluation failed (%d,%d-%d,%d)\n",
386
-				rve->fpos.s_line, rve->fpos.s_col,
387
-				rve->fpos.e_line, rve->fpos.e_col);
388
-		goto error;
389
-	}
390
-	switch(lv->type){
391
-		case LV_NONE:
392
-			BUG("uninitialized/invalid lvalue (%d) (cfg line: %d)\n",
393
-					lv->type, rve->fpos.s_line);
394
-			goto error;
395
-		case LV_AVP:
396
-			ret=lval_avp_assign(h, msg, lv, rv);
397
-			break;
398
-		case LV_PVAR:
399
-			ret=lval_pvar_assign(h, msg, lv, rv);
400
-			break;
401
-	}
402
-	if (unlikely(ret<0)){
403
-		ERR("assignment failed at pos: (%d,%d-%d,%d)\n",
404
-			rve->fpos.s_line, rve->fpos.s_col,
405
-			rve->fpos.e_line, rve->fpos.e_col);
406
-	}
407
-	else
408
-	{
409
-		if(unlikely(_log_assign_action!=NULL))
410
-			_log_assign_action(msg, lv);
411
-	}
412
-	rval_destroy(rv);
413
-	return ret;
414
-error:
415
-	if (rv) rval_destroy(rv);
416
-	return -1;
417
-}
Browse code

core: fix spelling errors catched by lintian #688

Victor Seva authored on 29/06/2016 14:29:17
Showing 1 changed files
... ...
@@ -83,7 +83,7 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
83 83
 	
84 84
 	switch(rv->type){
85 85
 		case RV_NONE:
86
-			BUG("non-intialized rval / rval expr \n");
86
+			BUG("non-initialized rval / rval expr \n");
87 87
 			/* unknown value => reset the avp in function of its type */
88 88
 			flags=avp->type;
89 89
 			AVP_ASSIGN_NOVAL();
... ...
@@ -262,7 +262,7 @@ inline static int lval_pvar_assign(struct run_act_ctx* h, struct sip_msg* msg,
262 262
 	ret=0;
263 263
 	switch(rv->type){
264 264
 		case RV_NONE:
265
-			BUG("non-intialized rval / rval expr \n");
265
+			BUG("non-initialized rval / rval expr \n");
266 266
 			PVAR_ASSIGN_NOVAL();
267 267
 			ret=-1;
268 268
 			break;
Browse code

Core Removed history, svn $id$ and doxygen udpates on the .c files

Olle E. Johansson authored on 03/01/2015 09:53:17
Showing 1 changed files
... ...
@@ -16,22 +16,11 @@
16 16
 
17 17
 /**
18 18
  * @file 
19
- * @brief SIP-router core :: lvalues (assignment)
19
+ * @brief Kamailio core :: lvalues (assignment)
20 20
  * \ingroup core
21 21
  * Module: \ref core
22 22
  */
23 23
 
24
-/* 
25
- * History:
26
- * --------
27
- *  2008-11-30  initial version (andrei)
28
- *  2009-04-24  delete avps after finding their new value and not before
29
- *               (fixed $avp=$avp)
30
- *              when assigning something undefined (e.g. non-existing avp),
31
- *              delete the lvalue (similar to perl)  (andrei)
32
- */
33
-
34
-
35 24
 #include "lvalue.h"
36 25
 #include "dprint.h"
37 26
 #include "route.h"
Browse code

core: Add callback to be able to log assign actions.

Victor Seva authored on 29/05/2013 10:25:09
Showing 1 changed files
... ...
@@ -36,7 +36,16 @@
36 36
 #include "dprint.h"
37 37
 #include "route.h"
38 38
 
39
+/* callback to log assign actions */
40
+static log_assign_action_f _log_assign_action = NULL;
39 41
 
42
+/**
43
+ * @brief set callback function log assign actions
44
+ */
45
+void set_log_assign_action_cb(log_assign_action_f f)
46
+{
47
+	_log_assign_action = f;
48
+}
40 49
 
41 50
 /**
42 51
  * @brief eval rve and assign the result to an avp
... ...
@@ -406,6 +415,11 @@ int lval_assign(struct run_act_ctx* h, struct sip_msg* msg,
406 415
 			rve->fpos.s_line, rve->fpos.s_col,
407 416
 			rve->fpos.e_line, rve->fpos.e_col);
408 417
 	}
418
+	else
419
+	{
420
+		if(unlikely(_log_assign_action!=NULL))
421
+			_log_assign_action(msg, lv);
422
+	}
409 423
 	rval_destroy(rv);
410 424
 	return ret;
411 425
 error:
Browse code

core: use pointer to pv_spec_t on lvalue union. Use pv_cache_get() on interpreter.

Victor Seva authored on 29/05/2013 10:24:00
Showing 1 changed files
... ...
@@ -255,7 +255,7 @@ inline static int lval_pvar_assign(struct run_act_ctx* h, struct sip_msg* msg,
255 255
 		pv_get_null(msg, 0, &pval)
256 256
 	
257 257
 	destroy_pval=0;
258
-	pvar=&lv->lv.pvs;
258
+	pvar=lv->lv.pvs;
259 259
 	if (unlikely(!pv_is_w(pvar))){
260 260
 		ERR("read only pvar\n");
261 261
 		goto error;
Browse code

core: fix all reported doxygen errors in PV and value evaluation code

Henning Westerholt authored on 28/07/2011 21:58:00
Showing 1 changed files
... ...
@@ -1,6 +1,4 @@
1 1
 /* 
2
- * $Id$
3
- * 
4 2
  * Copyright (C) 2008 iptelorg GmbH
5 3
  *
6 4
  * Permission to use, copy, modify, and distribute this software for any
... ...
@@ -15,10 +13,14 @@
15 13
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 14
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 15
  */
16
+
18 17
 /**
19 18
  * @file 
20
- * @brief lvalues (assignment)
19
+ * @brief SIP-router core :: lvalues (assignment)
20
+ * \ingroup core
21
+ * Module: \ref core
21 22
  */
23
+
22 24
 /* 
23 25
  * History:
24 26
  * --------
... ...
@@ -29,12 +31,6 @@
29 31
  *              delete the lvalue (similar to perl)  (andrei)
30 32
  */
31 33
 
32
-/*!
33
- * \file
34
- * \brief SIP-router core :: 
35
- * \ingroup core
36
- * Module: \ref core
37
- */
38 34
 
39 35
 #include "lvalue.h"
40 36
 #include "dprint.h"
... ...
@@ -42,15 +38,15 @@
42 38
 
43 39
 
44 40
 
45
-/** eval rve and assign the result to an avp
46
- * lv->lv.avp=eval(rve)
47
- *
48
- * based on do_action() ASSIGN_T
49
- *
41
+/**
42
+ * @brief eval rve and assign the result to an avp
43
+ * 
44
+ * eval rve and assign the result to an avp, lv->lv.avp=eval(rve)
45
+ * based on do_action() ASSIGN_T.
50 46
  * @param h  - script context
51 47
  * @param msg - sip msg
52 48
  * @param lv - lvalue
53
- * @param rve - rvalue expression
49
+ * @param rv - rvalue expression
54 50
  * @return >= 0 on success (expr. bool value), -1 on error
55 51
  */
56 52
 inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
... ...
@@ -232,15 +228,15 @@ drop:
232 228
 
233 229
 
234 230
 
235
-/** eval rve and assign the result to a pvar
236
- * lv->lv.pvar=eval(rve)
237
- *
238
- * based on do_action() ASSIGN_T
231
+/**
232
+ * @brief eval rve and assign the result to a pvar
239 233
  *
234
+ * eval rve and assign the result to a pvar, lv->lv.pvar=eval(rve)
235
+ * based on do_action() ASSIGN_T.
240 236
  * @param h  - script context
241 237
  * @param msg - sip msg
242 238
  * @param lv - lvalue
243
- * @param rve - rvalue expression
239
+ * @param rv - rvalue expression
244 240
  * @return >= 0 on success (expr. bool value), -1 on error
245 241
  */
246 242
 inline static int lval_pvar_assign(struct run_act_ctx* h, struct sip_msg* msg,
Browse code

core: proper return code for pvar assignment

- in some case the value of the right expression was returned instead of
proper >=0 for success cases
- reported by Juha Heinannen

Daniel-Constantin Mierla authored on 21/02/2011 22:15:29
Showing 1 changed files
... ...
@@ -290,7 +290,7 @@ inline static int lval_pvar_assign(struct run_act_ctx* h, struct sip_msg* msg,
290 290
 														    break in expr*/
291 291
 			} else
292 292
 				pval.ri=0;
293
-			ret=pval.ri;
293
+			ret=!(!pval.ri);
294 294
 			break;
295 295
 		case RV_BEXPR: /* logic/boolean expr. */
296 296
 			pval.flags=PV_TYPE_INT|PV_VAL_INT;
... ...
@@ -301,7 +301,7 @@ inline static int lval_pvar_assign(struct run_act_ctx* h, struct sip_msg* msg,
301 301
 				WARN("error in expression\n");
302 302
 				pval.ri=0; /* expr. is treated as false */
303 303
 			}
304
-			ret=pval.ri;
304
+			ret=!(!pval.ri);
305 305
 			break;
306 306
 		case RV_SEL:
307 307
 			pval.flags=PV_VAL_STR;
... ...
@@ -315,7 +315,7 @@ inline static int lval_pvar_assign(struct run_act_ctx* h, struct sip_msg* msg,
315 315
 					break;
316 316
 				}
317 317
 			}
318
-			ret=(pval.rs.len)>0;
318
+			ret=(pval.rs.len>0);
319 319
 			break;
320 320
 		case RV_AVP:
321 321
 				r_avp = search_avp_by_index(rv->v.avps.type, rv->v.avps.name,
Browse code

core: small spelling fix in log message

Henning Westerholt authored on 28/01/2011 14:29:45
Showing 1 changed files
... ...
@@ -406,7 +406,7 @@ int lval_assign(struct run_act_ctx* h, struct sip_msg* msg,
406 406
 			break;
407 407
 	}
408 408
 	if (unlikely(ret<0)){
409
-		ERR("assignmet failed at pos: (%d,%d-%d,%d)\n",
409
+		ERR("assignment failed at pos: (%d,%d-%d,%d)\n",
410 410
 			rve->fpos.s_line, rve->fpos.s_col,
411 411
 			rve->fpos.e_line, rve->fpos.e_col);
412 412
 	}
Browse code

core: print cfg line for failed eval expressions

Daniel-Constantin Mierla authored on 27/01/2011 23:02:47
Showing 1 changed files
... ...
@@ -395,7 +395,8 @@ int lval_assign(struct run_act_ctx* h, struct sip_msg* msg,
395 395
 	}
396 396
 	switch(lv->type){
397 397
 		case LV_NONE:
398
-			BUG("uninitialized/invalid lvalue (%d)\n", lv->type);
398
+			BUG("uninitialized/invalid lvalue (%d) (cfg line: %d)\n",
399
+					lv->type, rve->fpos.s_line);
399 400
 			goto error;
400 401
 		case LV_AVP:
401 402
 			ret=lval_avp_assign(h, msg, lv, rv);
... ...
@@ -404,6 +405,11 @@ int lval_assign(struct run_act_ctx* h, struct sip_msg* msg,
404 405
 			ret=lval_pvar_assign(h, msg, lv, rv);
405 406
 			break;
406 407
 	}
408
+	if (unlikely(ret<0)){
409
+		ERR("assignmet failed at pos: (%d,%d-%d,%d)\n",
410
+			rve->fpos.s_line, rve->fpos.s_col,
411
+			rve->fpos.e_line, rve->fpos.e_col);
412
+	}
407 413
 	rval_destroy(rv);
408 414
 	return ret;
409 415
 error:
Browse code

core: return & break are absorbed in expressions

return & break inside an expression do not cause the current route
block or while/switch statement to end.
E.g.: $v = { return 1; } will not end the current route, will
only set $v to 1.

Andrei Pelinescu-Onciul authored on 29/09/2010 15:35:25
Showing 1 changed files
... ...
@@ -107,9 +107,11 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
107 107
 			break;
108 108
 		case RV_ACTION_ST:
109 109
 			flags=avp->type & ~AVP_VAL_STR;
110
-			if (rv->v.action)
110
+			if (rv->v.action) {
111 111
 				value.n=run_actions_safe(h, rv->v.action, msg);
112
-			else
112
+				h->run_flags &= ~(RETURN_R_F|BREAK_R_F); /* catch return &
113
+														    break in expr*/
114
+			} else
113 115
 				value.n=-1;
114 116
 			ret=value.n;
115 117
 			break;
... ...
@@ -282,9 +284,11 @@ inline static int lval_pvar_assign(struct run_act_ctx* h, struct sip_msg* msg,
282 284
 			break;
283 285
 		case RV_ACTION_ST:
284 286
 			pval.flags=PV_TYPE_INT|PV_VAL_INT;
285
-			if (rv->v.action)
287
+			if (rv->v.action) {
286 288
 				pval.ri=run_actions_safe(h, rv->v.action, msg);
287
-			else
289
+				h->run_flags &= ~(RETURN_R_F|BREAK_R_F); /* catch return &
290
+														    break in expr*/
291
+			} else
288 292
 				pval.ri=0;
289 293
 			ret=pval.ri;
290 294
 			break;
Browse code

core: fix end-script commands in expr. leaks

When having commands that end the script immediately in
assignments (e.g. $foo = { drop; }) or in expressions
(e.g. if ($v + { drop; } > 0)), the script was terminated
immediately via longjmp. However this might leave some un-freed
variables.
This fix introduces a safe version of run_actions()
(run_actions_safe()) that will not use longjmp() to immediately
end the whole script on drop, returning instead to its caller.

Andrei Pelinescu-Onciul authored on 29/09/2010 14:30:40
Showing 1 changed files
... ...
@@ -108,7 +108,7 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
108 108
 		case RV_ACTION_ST:
109 109
 			flags=avp->type & ~AVP_VAL_STR;
110 110
 			if (rv->v.action)
111
-				value.n=run_actions(h, rv->v.action, msg);
111
+				value.n=run_actions_safe(h, rv->v.action, msg);
112 112
 			else
113 113
 				value.n=-1;
114 114
 			ret=value.n;
... ...
@@ -283,7 +283,7 @@ inline static int lval_pvar_assign(struct run_act_ctx* h, struct sip_msg* msg,
283 283
 		case RV_ACTION_ST:
284 284
 			pval.flags=PV_TYPE_INT|PV_VAL_INT;
285 285
 			if (rv->v.action)
286
-				pval.ri=run_actions(h, rv->v.action, msg);
286
+				pval.ri=run_actions_safe(h, rv->v.action, msg);
287 287
 			else
288 288
 				pval.ri=0;
289 289
 			ret=pval.ri;
Browse code

Merge remote branch 'origin/sr_3.0'

latest sr_3.0 fixes, after kamailio 3.0 release.

* origin/sr_3.0: (58 commits)
Backport of the changes (see previous commits).
kex: documented missing functions
kex: aliased avp_printf to pv_printf
auth_diameter(k): remove redundant declaration of find_credentials, now in core
- fix bug in encode_contact()
- fix bug when RURI was changed before and newuri will be used
- remove unused code
modules_k/nathelper: removed garbage from documentation (credits to Klaus)
modules_k/nathelper: improved handle_ruri_alias() documentation
modules/lcr and modules_k/nathelper: fixed compiler warnings
modules_k/nathelper: handle_uri_alias() alias handling fix
modules_k/usrloc: changed 'Kamailio' to 'SIP Router' in user agent string.
tm: safer handling for local transactions and drop_replies!=0
sctp: stats: don't increment ASSOC_SHUTDOWN on COMM_LOST
sctp: SCTP_STATS_ASSOC_SHUTDOWN
tm doc: local_ack_mode documentation
tm: new param: local_ack_mode
makefile: fix make bin & basedir
core: fix parsing for avps with the same name as a pv class
tls: name the certificates based on $MAIN_NAME
...

Conflicts:
modules/tm/README
modules_k/nathelper/rtpproxy_stream.c
pkg/debian/rules

Andrei Pelinescu-Onciul authored on 13/01/2010 16:20:23
Showing 0 changed files
Browse code

script engine: verbose conversion-to-int errors

- more verbose errors (all of them contain now the config file
position for the error).
- integer conversion errors will now by default log a warning
message. Like before they won't cause the expression evaluation
to fail, they'll just evaluate the failed conversion to 0.
The behaviour can be changed using the defines at the top of
rvalue.c. To restore the old behaviour (no int conversion error
message and error ignored), comment out the following defines:
RV_STR2INT_VERBOSE_ERR, RV_STRINT_ERR, EVAL_GET_INT_ERR_WARN,
RVAL_GET_INT_ERR_IGN. For more info see the comments in the
file.

Andrei Pelinescu-Onciul authored on 16/11/2009 18:41:02
Showing 1 changed files
... ...
@@ -377,7 +377,9 @@ int lval_assign(struct run_act_ctx* h, struct sip_msg* msg,
377 377
 	ret=0;
378 378
 	rv=rval_expr_eval(h, msg, rve);
379 379
 	if (unlikely(rv==0)){
380
-		ERR("rval expression evaluation failed\n");
380
+		ERR("rval expression evaluation failed (%d,%d-%d,%d)\n",
381
+				rve->fpos.s_line, rve->fpos.s_col,
382
+				rve->fpos.e_line, rve->fpos.e_col);
381 383
 		goto error;
382 384
 	}
383 385
 	switch(lv->type){
Browse code

Adding doxygen template to all core .c files

Please fill in after the :: to explain the function of this file.

oej authored on 10/10/2009 13:54:13
Showing 1 changed files
... ...
@@ -29,6 +29,13 @@
29 29
  *              delete the lvalue (similar to perl)  (andrei)
30 30
  */
31 31
 
32
+/*!
33
+ * \file
34
+ * \brief SIP-router core :: 
35
+ * \ingroup core
36
+ * Module: \ref core
37
+ */
38
+
32 39
 #include "lvalue.h"
33 40
 #include "dprint.h"
34 41
 #include "route.h"
Browse code

core: avp & pvars assignment fixes & changes

- fix: delete avps after finding their new value and not before
(fixes $v=$v or $v=$avp(v) deleting $v's value)

- when assigning something undefined (like a non-existing avp),
delete the lvalue.
E.g.: $v=$foo and $ foo undefined => delete/undefine $v
An expr is undefined only if it consists only on an undefined
avp or pvar. If it contains more elements it's always defined
(even if all the elements are undefined).
E.g: $foo and $bar are undefined => defined $foo == 0, defined
$bar == 0, but defined ($foo+$bar) == 1.
An avp is undefined if it doesn't exist or there is some error
accessing it.
A pvar is undefined if it's PV_VAL_NULL or there is an error
getting it's value.

Andrei Pelinescu-Onciul authored on 24/04/2009 19:40:26
Showing 1 changed files
... ...
@@ -23,6 +23,10 @@
23 23
  * History:
24 24
  * --------
25 25
  *  2008-11-30  initial version (andrei)
26
+ *  2009-04-24  delete avps after finding their new value and not before
27
+ *               (fixed $avp=$avp)
28
+ *              when assigning something undefined (e.g. non-existing avp),
29
+ *              delete the lvalue (similar to perl)  (andrei)
26 30
  */
27 31
 
28 32
 #include "lvalue.h"
... ...
@@ -53,19 +57,37 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
53 57
 	unsigned short flags;
54 58
 	struct search_state st;
55 59
 	int ret, v, destroy_pval;
60
+	int avp_add;
61
+
62
+#if 0
63
+	#define AVP_ASSIGN_NOVAL() \
64
+		/* unknown value => reset the avp in function of its type */ \
65
+		flags=avp->type; \
66
+		if (flags & AVP_VAL_STR){ \
67
+			value.s.s=""; \
68
+			value.s.len=0; \
69
+		}else{ \
70
+			value.n=0; \
71
+		}
72
+#endif
73
+	#define AVP_ASSIGN_NOVAL() \
74
+		/* no value => delete avp */ \
75
+		avp_add=0
56 76
 	
57 77
 	destroy_pval=0;
58 78
 	flags = 0;
59 79
 	avp=&lv->lv.avps;
60 80
 	ret=0;
61
-	/* If the left attr was specified without indexing brackets delete
62
-	 * existing AVPs before adding new ones */
63
-	if ((avp->type & AVP_INDEX_ALL) != AVP_INDEX_ALL)
64
-		delete_avp(avp->type, avp->name);
81
+	avp_add=1;
82
+	
65 83
 	switch(rv->type){
66 84
 		case RV_NONE:
67 85
 			BUG("non-intialized rval / rval expr \n");
68
-			goto error;
86
+			/* unknown value => reset the avp in function of its type */
87
+			flags=avp->type;
88
+			AVP_ASSIGN_NOVAL();
89
+			ret=-1;
90
+			break;
69 91
 		case RV_INT:
70 92
 			value.n=rv->v.l;
71 93
 			flags=avp->type & ~AVP_VAL_STR;
... ...
@@ -96,22 +118,22 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
96 118
 			ret=value.n;
97 119
 			break;
98 120
 		case RV_SEL:
121
+			flags=avp->type|AVP_VAL_STR;
99 122
 			v=run_select(&value.s, &rv->v.sel, msg);
100 123
 			if (unlikely(v!=0)){
124
+				value.s.s="";
125
+				value.s.len=0;
101 126
 				if (v<0){
102 127
 					ret=-1;
103
-					goto error;
104
-				}else { /* v>0 */
105
-					value.s.s="";
106
-					value.s.len=0;
107
-				}
128
+					break;
129
+				} /* v>0 */
108 130
 			}
109
-			flags=avp->type|AVP_VAL_STR;
110 131
 			ret=(value.s.len>0);
111 132
 			break;
112 133
 		case RV_AVP:
113 134
 			avp_mark=0;
114 135
 			if (unlikely((rv->v.avps.type & AVP_INDEX_ALL) == AVP_INDEX_ALL)){
136
+				/* special case: add the value to the avp */
115 137
 				r_avp = search_first_avp(rv->v.avps.type, rv->v.avps.name,
116 138
 											&value, &st);
117 139
 				while(r_avp){
... ...
@@ -136,6 +158,7 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
136 158
 				ret=1;
137 159
 				goto end;
138 160
 			}else{
161
+				/* normal case, value is replaced */
139 162
 				r_avp = search_avp_by_index(rv->v.avps.type, rv->v.avps.name,
140 163
 											&value, rv->v.avps.index);
141 164
 				if (likely(r_avp)){
... ...
@@ -146,8 +169,11 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
146 169
 									AVP_NAME_RE));
147 170
 					ret=1;
148 171
 				}else{
149
-					ret=-1;
150
-					goto error;
172
+					/* on error, keep the type of the assigned avp, but
173
+					   reset it to an empty value */
174
+					AVP_ASSIGN_NOVAL();
175
+					ret=0;
176
+					break;
151 177
 				}
152 178
 			}
153 179
 			break;
... ...
@@ -165,21 +191,22 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
165 191
 					flags=avp->type | AVP_VAL_STR;
166 192
 				}else if (pval.flags==PV_VAL_NONE ||
167 193
 							(pval.flags & (PV_VAL_NULL|PV_VAL_EMPTY))){
168
-					value.s.s="";
169
-					value.s.len=0;
194
+					AVP_ASSIGN_NOVAL();
170 195
 					ret=0;
171
-					flags=avp->type | AVP_VAL_STR;
172 196
 				}
173 197
 			}else{
174 198
 				/* non existing pvar */
175
-				value.s.s="";
176
-				value.s.len=0;
199
+				/* on error, keep the type of the assigned avp, but
200
+				   reset it to an empty value */
201
+				AVP_ASSIGN_NOVAL();
177 202
 				ret=0;
178
-				flags=avp->type | AVP_VAL_STR;
179 203
 			}
180 204
 			break;
181 205
 	}
182
-	if (add_avp(flags & ~AVP_INDEX_ALL, avp->name, value) < 0) {
206
+	/* If the left attr was specified without indexing brackets delete
207
+	 * existing AVPs before adding the new value */
208
+	delete_avp(avp->type, avp->name);
209
+	if (avp_add && (add_avp(flags & ~AVP_INDEX_ALL, avp->name, value) < 0)) {
183 210
 		ERR("failed to assign value to avp\n");
184 211
 		goto error;
185 212
 	}
... ...
@@ -218,6 +245,10 @@ inline static int lval_pvar_assign(struct run_act_ctx* h, struct sip_msg* msg,
218 245
 	int v;
219 246
 	int destroy_pval;
220 247
 	
248
+	#define PVAR_ASSIGN_NOVAL() \
249
+		/* no value found => "undefine" */ \
250
+		pv_get_null(msg, 0, &pval)
251
+	
221 252
 	destroy_pval=0;
222 253
 	pvar=&lv->lv.pvs;
223 254
 	if (unlikely(!pv_is_w(pvar))){
... ...
@@ -229,7 +260,9 @@ inline static int lval_pvar_assign(struct run_act_ctx* h, struct sip_msg* msg,
229 260
 	switch(rv->type){
230 261
 		case RV_NONE:
231 262
 			BUG("non-intialized rval / rval expr \n");
232
-			goto error;
263
+			PVAR_ASSIGN_NOVAL();
264
+			ret=-1;
265
+			break;
233 266
 		case RV_INT:
234 267
 			pval.flags=PV_TYPE_INT|PV_VAL_INT;
235 268
 			pval.ri=rv->v.l;
... ...
@@ -263,12 +296,12 @@ inline static int lval_pvar_assign(struct run_act_ctx* h, struct sip_msg* msg,
263 296
 			pval.flags=PV_VAL_STR;
264 297
 			v=run_select(&pval.rs, &rv->v.sel, msg);
265 298
 			if (unlikely(v!=0)){
299
+				pval.flags|=PV_VAL_EMPTY;
300
+				pval.rs.s="";
301
+				pval.rs.len=0;
266 302
 				if (v<0){
267 303
 					ret=-1;
268
-					goto error;
269
-				}else { /* v>0 */
270
-					pval.rs.s="";
271
-					pval.rs.len=0;
304
+					break;
272 305
 				}
273 306
 			}
274 307
 			ret=(pval.rs.len)>0;
... ...
@@ -287,8 +320,9 @@ inline static int lval_pvar_assign(struct run_act_ctx* h, struct sip_msg* msg,
287 320
 						ret=!(!pval.ri);
288 321
 					}
289 322
 				}else{
290
-					ret=-1;
291
-					goto error;
323
+					PVAR_ASSIGN_NOVAL();
324
+					ret=0; /* avp not defined (valid case) */
325
+					break;
292 326
 				}
293 327
 			break;
294 328
 		case RV_PVAR:
... ...
@@ -299,14 +333,13 @@ inline static int lval_pvar_assign(struct run_act_ctx* h, struct sip_msg* msg,
299 333
 				}else if (pval.flags & PV_VAL_STR){
300 334
 					ret=(pval.rs.len>0);
301 335
 				}else{
302
-					ERR("no value in pvar assignment rval\n");
303
-					ret=-1;
304