Browse code

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

Andrei Pelinescu-Onciul authored on 14/05/2009 19:42:46
Showing 2 changed files
... ...
@@ -135,10 +135,22 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
135 135
 	ret=E_BUG;
136 136
 	switch ((unsigned char)a->type){
137 137
 		case DROP_T:
138
-				if (a->val[0].type==RETCODE_ST)
139
-					ret=h->last_retcode;
140
-				else
141
-					ret=(int) a->val[0].u.number;
138
+				switch(a->val[0].type){
139
+					case NUMBER_ST:
140
+						ret=(int) a->val[0].u.number;
141
+						break;
142
+					case RVE_ST:
143
+						rve=(struct rval_expr*)a->val[0].u.data;
144
+						rval_expr_eval_int(h, msg, &ret, rve);
145
+						break;
146
+					case RETCODE_ST:
147
+						ret=h->last_retcode;
148
+						break;
149
+					default:
150
+						BUG("unexpected subtype %d in DROP_T\n",
151
+								a->val[0].type);
152
+						ret=0;
153
+				}
142 154
 				h->run_flags|=(unsigned int)a->val[1].u.number;
143 155
 			break;
144 156
 		case FORWARD_T:
... ...
@@ -807,6 +807,43 @@ int fix_actions(struct action* a)
807 807
 					return ret;
808 808
 				}
809 809
 				break;
810
+			case DROP_T:
811
+				/* only RVEs need fixing for drop/return/break */
812
+				if (t->val[0].type!=RVE_ST)
813
+					break;
814
+				rve=(struct rval_expr*)t->val[0].u.data;
815
+				if (rve){
816
+					err_rve=0;
817
+					if (!rve_check_type(&rve_type, rve, &err_rve,
818
+											&err_type, &expected_type)){
819
+						if (err_rve)
820
+							LOG(L_ERR, "fix_actions: invalid expression "
821
+									"(%d,%d): subexpression (%d,%d) has type"
822
+									" %s,  but %s is expected\n",
823
+									rve->fpos.s_line, rve->fpos.s_col,
824
+									err_rve->fpos.s_line, err_rve->fpos.s_col,
825
+									rval_type_name(err_type),
826
+									rval_type_name(expected_type) );
827
+						else
828
+							LOG(L_ERR, "fix_actions: invalid expression "
829
+									"(%d,%d): type mismatch?",
830
+									rve->fpos.s_line, rve->fpos.s_col);
831
+						return E_UNSPEC;
832
+					}
833
+					if (rve_type!=RV_INT && rve_type!=RV_NONE){
834
+						LOG(L_ERR, "fix_actions: invalid expression (%d,%d):"
835
+								" bad type, integer expected\n",
836
+								rve->fpos.s_line, rve->fpos.s_col);
837
+						return E_UNSPEC;
838
+					}
839
+					if ((ret=fix_rval_expr((void**)&rve))<0)
840
+						return ret;
841
+				}else{
842
+					LOG(L_CRIT, "BUG: fix_actions: null drop/return"
843
+							" expression\n");
844
+					return E_BUG;
845
+				}
846
+				break;
810 847
 			case ASSIGN_T:
811 848
 			case ADD_T:
812 849
 				if (t->val[0].type !=LVAL_ST) {