Ver Fonte

core script engine: support for rval expr. in return/drop

Andrei Pelinescu-Onciul há 16 anos atrás
pai
commit
ee308afd99
2 ficheiros alterados com 53 adições e 4 exclusões
  1. 16 4
      action.c
  2. 37 0
      route.c

+ 16 - 4
action.c

@@ -135,10 +135,22 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
 	ret=E_BUG;
 	switch ((unsigned char)a->type){
 		case DROP_T:
-				if (a->val[0].type==RETCODE_ST)
-					ret=h->last_retcode;
-				else
-					ret=(int) a->val[0].u.number;
+				switch(a->val[0].type){
+					case NUMBER_ST:
+						ret=(int) a->val[0].u.number;
+						break;
+					case RVE_ST:
+						rve=(struct rval_expr*)a->val[0].u.data;
+						rval_expr_eval_int(h, msg, &ret, rve);
+						break;
+					case RETCODE_ST:
+						ret=h->last_retcode;
+						break;
+					default:
+						BUG("unexpected subtype %d in DROP_T\n",
+								a->val[0].type);
+						ret=0;
+				}
 				h->run_flags|=(unsigned int)a->val[1].u.number;
 			break;
 		case FORWARD_T:

+ 37 - 0
route.c

@@ -807,6 +807,43 @@ int fix_actions(struct action* a)
 					return ret;
 				}
 				break;
+			case DROP_T:
+				/* only RVEs need fixing for drop/return/break */
+				if (t->val[0].type!=RVE_ST)
+					break;
+				rve=(struct rval_expr*)t->val[0].u.data;
+				if (rve){
+					err_rve=0;
+					if (!rve_check_type(&rve_type, rve, &err_rve,
+											&err_type, &expected_type)){
+						if (err_rve)
+							LOG(L_ERR, "fix_actions: invalid expression "
+									"(%d,%d): subexpression (%d,%d) has type"
+									" %s,  but %s is expected\n",
+									rve->fpos.s_line, rve->fpos.s_col,
+									err_rve->fpos.s_line, err_rve->fpos.s_col,
+									rval_type_name(err_type),
+									rval_type_name(expected_type) );
+						else
+							LOG(L_ERR, "fix_actions: invalid expression "
+									"(%d,%d): type mismatch?",
+									rve->fpos.s_line, rve->fpos.s_col);
+						return E_UNSPEC;
+					}
+					if (rve_type!=RV_INT && rve_type!=RV_NONE){
+						LOG(L_ERR, "fix_actions: invalid expression (%d,%d):"
+								" bad type, integer expected\n",
+								rve->fpos.s_line, rve->fpos.s_col);
+						return E_UNSPEC;
+					}
+					if ((ret=fix_rval_expr((void**)&rve))<0)
+						return ret;
+				}else{
+					LOG(L_CRIT, "BUG: fix_actions: null drop/return"
+							" expression\n");
+					return E_BUG;
+				}
+				break;
 			case ASSIGN_T:
 			case ADD_T:
 				if (t->val[0].type !=LVAL_ST) {