Ver Fonte

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

(not tested yet)
Andrei Pelinescu-Onciul há 24 anos atrás
pai
commit
a1041efe1d
3 ficheiros alterados com 26 adições e 16 exclusões
  1. 8 13
      action.c
  2. 5 3
      route.c
  3. 13 0
      route_struct.h

+ 8 - 13
action.c

@@ -334,20 +334,15 @@ int do_action(struct action* a, struct sip_msg* msg)
 				if ((a->p1_type==EXPR_ST)&&a->p1.data){
 					v=eval_expr((struct expr*)a->p1.data, msg);
 					if (v<0){
-						LOG(L_WARN,"WARNING: do_action:"
-									"error in expression\n");
+						if (v==EXPR_DROP){ /* hack to quit on DROP*/
+							ret=0;
+							break;
+						}else{
+							LOG(L_WARN,"WARNING: do_action:"
+										"error in expression\n");
+						}
 					}
-#if 0
-					/*andrei: totally wrong, it will bail out at the first 
-					 * false expression and if w/o else!!!!!!*/
-
-					/* jku ret=1;  default is continue */
-					ret=( v!=0); /* stop if things went wrong,
-								  continue if FALSE (<0) or
-								  TRUE (>0) returned */
-					/* jku: if (v==1){ */
-#endif
-
+					
 					ret=1;  /*default is continue */
 					if (v>0) {
 						if ((a->p2_type==ACTIONS_ST)&&a->p2.data){

+ 5 - 3
route.c

@@ -279,7 +279,7 @@ error:
 
 
 
-/* returns: 0/1 (false/true) or -1 on error */
+/* returns: 0/1 (false/true) or -1 on error, -127 EXPR_DROP */
 static int eval_elem(struct expr* e, struct sip_msg* msg)
 {
 
@@ -314,7 +314,9 @@ static int eval_elem(struct expr* e, struct sip_msg* msg)
 				ret=!(!e->r.intval); /* !! to transform it in {0,1} */
 				break;
 		case ACTION_O:
-				ret=(run_actions( (struct action*)e->r.param, msg)>=0)?1:0;
+				ret=run_actions( (struct action*)e->r.param, msg);
+				if (ret<=0) ret=(ret==0)?EXPR_DROP:0;
+				else ret=1;
 				break;
 		default:
 				LOG(L_CRIT, "BUG: eval_elem: invalid operand %d\n",
@@ -327,7 +329,7 @@ error:
 
 
 
-/* ret= 0/1 (true/false) & -1 on error */
+/* ret= 0/1 (true/false) ,  -1 on error or EXPR_DROP (-127)  */
 int eval_expr(struct expr* e, struct sip_msg* msg)
 {
 	static int rec_lev=0;

+ 13 - 0
route_struct.h

@@ -6,6 +6,19 @@
 #ifndef route_struct_h
 #define route_struct_h
 
+#define EXPR_DROP -127  /* used only by the expression and if evaluator */
+/*
+ * Other important values (no macros for them yet):
+ * expr true = 1
+ * expr false = 0 (used only inside the expression and if evaluator)
+ * 
+ * action continue  or if used in condition true = 1
+ * action drop/quit/stop script processing = 0
+ * action error or if used in condition false = -1 (<0 and !=EXPR_DROP)
+ * 
+ */
+
+
 enum { EXP_T=1, ELEM_T };
 enum { AND_OP=1, OR_OP, NOT_OP };
 enum { EQUAL_OP=10, MATCH_OP, NO_OP };