Module: sip-router Branch: master Commit: 0a3ab1b240c9879748ffe2f7b4f684510901dacc URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0a3ab1b2...
Author: Andrei Pelinescu-Onciul andrei@iptel.org Committer: Andrei Pelinescu-Onciul andrei@iptel.org Date: Thu Mar 25 22:10:27 2010 +0100
core: trying to execute an undefined route will produce an error
Trying to call non-existing routes (via route("...")) will result now in an error on startup (during fixups). The old behaviour was to consider any non-existing routes as empty (and do nothing).
Reported-by: Juha Heinanen jh tutpro com Closes: FlySpray#51.
---
cfg.y | 16 ++++++++-------- route.c | 30 +++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 13 deletions(-)
diff --git a/cfg.y b/cfg.y index a9350ec..2b12b67 100644 --- a/cfg.y +++ b/cfg.y @@ -3043,14 +3043,14 @@ cmd: | ERROR error { $$=0; yyerror("missing '(' or ')' ?"); } | ERROR LPAREN error RPAREN { $$=0; yyerror("bad error argument"); } | ROUTE LPAREN route_name RPAREN { - i_tmp=route_get(&main_rt, $3); - if (i_tmp==-1){ - yyerror("internal error"); - YYABORT; - } - $$=mk_action(ROUTE_T, 1, NUMBER_ST,(void*)(long)i_tmp); - set_cfg_pos($$); - } + if ($3) { + $$ = mk_action(ROUTE_T, 1, STRING_ST, (void*)$3); + set_cfg_pos($$); + } else { + $$ = 0; + YYERROR; + } + } | ROUTE error { $$=0; yyerror("missing '(' or ')' ?"); } | ROUTE LPAREN error RPAREN { $$=0; yyerror("bad route argument"); } | EXEC LPAREN STRING RPAREN { $$=mk_action(EXEC_T, 1, STRING_ST, $3); set_cfg_pos($$); } diff --git a/route.c b/route.c index 0268c12..729860e 100644 --- a/route.c +++ b/route.c @@ -727,7 +727,7 @@ int fix_actions(struct action* a) LOG(L_ERR, "fix_actions: invalid expression " "(%d,%d): type mismatch?", rve->fpos.s_line, rve->fpos.s_col); - ret = E_UNSPEC; + ret = E_SCRIPT; goto error; } /* it's not an error anymore to have non-int in an if, @@ -810,14 +810,14 @@ int fix_actions(struct action* a) LOG(L_ERR, "fix_actions: invalid expression " "(%d,%d): type mismatch?", rve->fpos.s_line, rve->fpos.s_col); - ret = E_UNSPEC; + ret = E_SCRIPT; goto error; } 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); - ret = E_UNSPEC; + ret = E_SCRIPT; goto error; } if ((ret=fix_rval_expr(&t->val[0].u.data))<0) @@ -854,14 +854,14 @@ int fix_actions(struct action* a) LOG(L_ERR, "fix_actions: invalid expression " "(%d,%d): type mismatch?", rve->fpos.s_line, rve->fpos.s_col); - ret = E_UNSPEC; + ret = E_SCRIPT; goto error; } 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); - ret = E_UNSPEC; + ret = E_SCRIPT; goto error; } if ((ret=fix_rval_expr(&t->val[0].u.data))<0) @@ -1021,6 +1021,26 @@ int fix_actions(struct action* a) t->val[0].u.str=s; t->val[0].type=STR_ST; break; + case ROUTE_T: + if (t->val[0].type == STRING_ST) { + i=route_lookup(&main_rt, t->val[0].u.string); + if (i < 0) { + ERR("route "%s" not found at %s:%d\n", + t->val[0].u.string, + (t->cfile)?t->cfile:"line", t->cline); + ret = E_SCRIPT; + goto error; + } + t->val[0].type = NUMBER_ST; + pkg_free(t->val[0].u.string); + t->val[0].u.number = i; + } else if (t->val[0].type != NUMBER_ST) { + BUG("invalid subtype %d for route()\n", + t->val[0].type); + ret = E_BUG; + goto error; + } + break; default: /* no fixup required for the rest */ break;