Module: sip-router Branch: master Commit: ee308afd99cfb80d8a9787f6dfe7fb0935cdb386 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ee308afd...
Author: Andrei Pelinescu-Onciul andrei@iptel.org Committer: Andrei Pelinescu-Onciul andrei@iptel.org Date: Thu May 14 21:42:46 2009 +0200
core script engine: support for rval expr. in return/drop
---
action.c | 20 ++++++++++++++++---- route.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-)
diff --git a/action.c b/action.c index f99079a..9f89ac6 100644 --- a/action.c +++ b/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: diff --git a/route.c b/route.c index 8d8c7db..77adbfb 100644 --- a/route.c +++ b/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) {