Browse code

- re-added break script in condition (if function returns 0)

(not tested yet)

Andrei Pelinescu-Onciul authored on 23/01/2002 18:10:41
Showing 3 changed files
... ...
@@ -334,20 +334,15 @@ int do_action(struct action* a, struct sip_msg* msg)
334 334
 				if ((a->p1_type==EXPR_ST)&&a->p1.data){
335 335
 					v=eval_expr((struct expr*)a->p1.data, msg);
336 336
 					if (v<0){
337
-						LOG(L_WARN,"WARNING: do_action:"
338
-									"error in expression\n");
337
+						if (v==EXPR_DROP){ /* hack to quit on DROP*/
338
+							ret=0;
339
+							break;
340
+						}else{
341
+							LOG(L_WARN,"WARNING: do_action:"
342
+										"error in expression\n");
343
+						}
339 344
 					}
340
-#if 0
341
-					/*andrei: totally wrong, it will bail out at the first 
342
-					 * false expression and if w/o else!!!!!!*/
343
-
344
-					/* jku ret=1;  default is continue */
345
-					ret=( v!=0); /* stop if things went wrong,
346
-								  continue if FALSE (<0) or
347
-								  TRUE (>0) returned */
348
-					/* jku: if (v==1){ */
349
-#endif
350
-
345
+					
351 346
 					ret=1;  /*default is continue */
352 347
 					if (v>0) {
353 348
 						if ((a->p2_type==ACTIONS_ST)&&a->p2.data){
... ...
@@ -279,7 +279,7 @@ error:
279 279
 
280 280
 
281 281
 
282
-/* returns: 0/1 (false/true) or -1 on error */
282
+/* returns: 0/1 (false/true) or -1 on error, -127 EXPR_DROP */
283 283
 static int eval_elem(struct expr* e, struct sip_msg* msg)
284 284
 {
285 285
 
... ...
@@ -314,7 +314,9 @@ static int eval_elem(struct expr* e, struct sip_msg* msg)
314 314
 				ret=!(!e->r.intval); /* !! to transform it in {0,1} */
315 315
 				break;
316 316
 		case ACTION_O:
317
-				ret=(run_actions( (struct action*)e->r.param, msg)>=0)?1:0;
317
+				ret=run_actions( (struct action*)e->r.param, msg);
318
+				if (ret<=0) ret=(ret==0)?EXPR_DROP:0;
319
+				else ret=1;
318 320
 				break;
319 321
 		default:
320 322
 				LOG(L_CRIT, "BUG: eval_elem: invalid operand %d\n",
... ...
@@ -327,7 +329,7 @@ error:
327 327
 
328 328
 
329 329
 
330
-/* ret= 0/1 (true/false) & -1 on error */
330
+/* ret= 0/1 (true/false) ,  -1 on error or EXPR_DROP (-127)  */
331 331
 int eval_expr(struct expr* e, struct sip_msg* msg)
332 332
 {
333 333
 	static int rec_lev=0;
... ...
@@ -6,6 +6,19 @@
6 6
 #ifndef route_struct_h
7 7
 #define route_struct_h
8 8
 
9
+#define EXPR_DROP -127  /* used only by the expression and if evaluator */
10
+/*
11
+ * Other important values (no macros for them yet):
12
+ * expr true = 1
13
+ * expr false = 0 (used only inside the expression and if evaluator)
14
+ * 
15
+ * action continue  or if used in condition true = 1
16
+ * action drop/quit/stop script processing = 0
17
+ * action error or if used in condition false = -1 (<0 and !=EXPR_DROP)
18
+ * 
19
+ */
20
+
21
+
9 22
 enum { EXP_T=1, ELEM_T };
10 23
 enum { AND_OP=1, OR_OP, NOT_OP };
11 24
 enum { EQUAL_OP=10, MATCH_OP, NO_OP };