Module: sip-router
Branch: master
Commit: 9fa304f16f3152cae3b35b18b00ecd560c03c404
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=9fa304f…
Author: Alex Hermann <alex(a)speakup.nl>
Committer: Alex Hermann <alex(a)speakup.nl>
Date: Fri Aug 5 14:49:16 2011 +0200
core: add functions remove_branch(int) and clear_branches()
remove_branch(int) - removes the specified branch from the destination set.
If the parameter is absent, the last branch is removed.
clear_branches() - empties the destination set.
---
action.c | 15 +++++++++++++++
cfg.lex | 6 ++++++
cfg.y | 13 +++++++++++++
route_struct.h | 2 +-
4 files changed, 35 insertions(+), 1 deletions(-)
diff --git a/action.c b/action.c
index 8ca143a..6d22bf2 100644
--- a/action.c
+++ b/action.c
@@ -559,6 +559,21 @@ int do_action(struct run_act_ctx* h, struct action* a, struct
sip_msg* msg)
ruri_mark_consumed();
break;
+ /* remove last branch */
+ case REMOVE_BRANCH_T:
+ if (a->val[0].type!=NUMBER_ST) {
+ ret=drop_sip_branch(0) ? -1 : 1;
+ } else {
+ ret=drop_sip_branch(a->val[0].u.number) ? -1 : 1;
+ }
+ break;
+
+ /* remove all branches */
+ case CLEAR_BRANCHES_T:
+ clear_branches();
+ ret=1;
+ break;
+
/* jku begin: is_length_greater_than */
case LEN_GT_T:
if (a->val[0].type!=NUMBER_ST) {
diff --git a/cfg.lex b/cfg.lex
index bfcf832..ff35a8a 100644
--- a/cfg.lex
+++ b/cfg.lex
@@ -237,6 +237,8 @@ STRIP "strip"
STRIP_TAIL "strip_tail"
SET_USERPHONE "userphone"
APPEND_BRANCH "append_branch"
+REMOVE_BRANCH "remove_branch"
+CLEAR_BRANCHES "clear_branches"
IF "if"
ELSE "else"
SET_ADV_ADDRESS "set_advertised_address"
@@ -623,6 +625,10 @@ IMPORTFILE "import_file"
<INITIAL>{STRIP_TAIL} { count(); yylval.strval=yytext; return STRIP_TAIL; }
<INITIAL>{APPEND_BRANCH} { count(); yylval.strval=yytext;
return APPEND_BRANCH; }
+<INITIAL>{REMOVE_BRANCH} { count(); yylval.strval=yytext;
+ return REMOVE_BRANCH; }
+<INITIAL>{CLEAR_BRANCHES} { count(); yylval.strval=yytext;
+ return CLEAR_BRANCHES; }
<INITIAL>{SET_USERPHONE} { count(); yylval.strval=yytext;
return SET_USERPHONE; }
<INITIAL>{FORCE_RPORT} { count(); yylval.strval=yytext; return FORCE_RPORT; }
diff --git a/cfg.y b/cfg.y
index e5679e5..daf38e0 100644
--- a/cfg.y
+++ b/cfg.y
@@ -324,6 +324,8 @@ extern char *finame;
%token STRIP_TAIL
%token SET_USERPHONE
%token APPEND_BRANCH
+%token REMOVE_BRANCH
+%token CLEAR_BRANCHES
%token SET_USER
%token SET_USERPASS
%token SET_PORT
@@ -3198,6 +3200,17 @@ cmd:
NUMBER_ST, (void *)Q_UNSPECIFIED);
set_cfg_pos($$);
}
+ | REMOVE_BRANCH LPAREN NUMBER RPAREN {
+ $$=mk_action(REMOVE_BRANCH_T, 1, NUMBER_ST, (void*)$3);
+ set_cfg_pos($$);
+ }
+ | REMOVE_BRANCH LPAREN RPAREN {
+ $$=mk_action(REMOVE_BRANCH_T, 0);
+ set_cfg_pos($$);
+ }
+ | REMOVE_BRANCH error { $$=0; yyerror("missing '(' or ')' ?");
}
+ | REMOVE_BRANCH LPAREN error RPAREN { $$=0; yyerror("bad argument, number
expected"); }
+ | CLEAR_BRANCHES LPAREN RPAREN { $$=mk_action(CLEAR_BRANCHES_T, 0); set_cfg_pos($$); }
| SET_HOSTPORT LPAREN STRING RPAREN { $$=mk_action(SET_HOSTPORT_T, 1, STRING_ST, $3);
set_cfg_pos($$); }
| SET_HOSTPORT error { $$=0; yyerror("missing '(' or ')' ?");
}
| SET_HOSTPORT LPAREN error RPAREN { $$=0; yyerror("bad argument, string
expected"); }
diff --git a/route_struct.h b/route_struct.h
index 08a576c..4bb5045 100644
--- a/route_struct.h
+++ b/route_struct.h
@@ -94,7 +94,7 @@ enum action_type{
SETFLAG_T, RESETFLAG_T, ISFLAGSET_T ,
AVPFLAG_OPER_T,
LEN_GT_T, PREFIX_T, STRIP_T,STRIP_TAIL_T,
- APPEND_BRANCH_T,
+ APPEND_BRANCH_T, REMOVE_BRANCH_T, CLEAR_BRANCHES_T,
REVERT_URI_T,
FORWARD_TCP_T,
FORWARD_UDP_T,