Browse code

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.

Alex Hermann authored on 05/08/2011 12:49:16
Showing 4 changed files
... ...
@@ -559,6 +559,21 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
559 559
 				ruri_mark_consumed();
560 560
 			break;
561 561
 
562
+		/* remove last branch */
563
+		case REMOVE_BRANCH_T:
564
+			if (a->val[0].type!=NUMBER_ST) {
565
+				ret=drop_sip_branch(0) ? -1 : 1;
566
+			} else {
567
+				ret=drop_sip_branch(a->val[0].u.number) ? -1 : 1;
568
+			}
569
+			break;
570
+
571
+		/* remove all branches */
572
+		case CLEAR_BRANCHES_T:
573
+			clear_branches();
574
+			ret=1;
575
+			break;
576
+
562 577
 		/* jku begin: is_length_greater_than */
563 578
 		case LEN_GT_T:
564 579
 			if (a->val[0].type!=NUMBER_ST) {
... ...
@@ -237,6 +237,8 @@ STRIP			"strip"
237 237
 STRIP_TAIL		"strip_tail"
238 238
 SET_USERPHONE		"userphone"
239 239
 APPEND_BRANCH	"append_branch"
240
+REMOVE_BRANCH	"remove_branch"
241
+CLEAR_BRANCHES	"clear_branches"
240 242
 IF				"if"
241 243
 ELSE			"else"
242 244
 SET_ADV_ADDRESS	"set_advertised_address"
... ...
@@ -623,6 +625,10 @@ IMPORTFILE      "import_file"
623 623
 <INITIAL>{STRIP_TAIL}	{ count(); yylval.strval=yytext; return STRIP_TAIL; }
624 624
 <INITIAL>{APPEND_BRANCH}	{ count(); yylval.strval=yytext;
625 625
 								return APPEND_BRANCH; }
626
+<INITIAL>{REMOVE_BRANCH}	{ count(); yylval.strval=yytext;
627
+								return REMOVE_BRANCH; }
628
+<INITIAL>{CLEAR_BRANCHES}	{ count(); yylval.strval=yytext;
629
+								return CLEAR_BRANCHES; }
626 630
 <INITIAL>{SET_USERPHONE}	{ count(); yylval.strval=yytext;
627 631
 								return SET_USERPHONE; }
628 632
 <INITIAL>{FORCE_RPORT}	{ count(); yylval.strval=yytext; return FORCE_RPORT; }
... ...
@@ -324,6 +324,8 @@ extern char *finame;
324 324
 %token STRIP_TAIL
325 325
 %token SET_USERPHONE
326 326
 %token APPEND_BRANCH
327
+%token REMOVE_BRANCH
328
+%token CLEAR_BRANCHES
327 329
 %token SET_USER
328 330
 %token SET_USERPASS
329 331
 %token SET_PORT
... ...
@@ -3198,6 +3200,17 @@ cmd:
3198 3198
 							NUMBER_ST, (void *)Q_UNSPECIFIED);
3199 3199
 		set_cfg_pos($$);
3200 3200
 	}
3201
+	| REMOVE_BRANCH LPAREN NUMBER RPAREN {
3202
+			$$=mk_action(REMOVE_BRANCH_T, 1, NUMBER_ST, (void*)$3);
3203
+			set_cfg_pos($$);
3204
+	}
3205
+	| REMOVE_BRANCH LPAREN RPAREN {
3206
+			$$=mk_action(REMOVE_BRANCH_T, 0);
3207
+			set_cfg_pos($$);
3208
+	}
3209
+	| REMOVE_BRANCH error { $$=0; yyerror("missing '(' or ')' ?"); }
3210
+	| REMOVE_BRANCH LPAREN error RPAREN { $$=0; yyerror("bad argument, number expected"); }
3211
+	| CLEAR_BRANCHES LPAREN RPAREN { $$=mk_action(CLEAR_BRANCHES_T, 0); set_cfg_pos($$); }
3201 3212
 	| SET_HOSTPORT LPAREN STRING RPAREN { $$=mk_action(SET_HOSTPORT_T, 1, STRING_ST, $3); set_cfg_pos($$); }
3202 3213
 	| SET_HOSTPORT error { $$=0; yyerror("missing '(' or ')' ?"); }
3203 3214
 	| SET_HOSTPORT LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
... ...
@@ -94,7 +94,7 @@ enum action_type{
94 94
 		SETFLAG_T, RESETFLAG_T, ISFLAGSET_T ,
95 95
 		AVPFLAG_OPER_T,
96 96
 		LEN_GT_T, PREFIX_T, STRIP_T,STRIP_TAIL_T,
97
-		APPEND_BRANCH_T,
97
+		APPEND_BRANCH_T, REMOVE_BRANCH_T, CLEAR_BRANCHES_T,
98 98
 		REVERT_URI_T,
99 99
 		FORWARD_TCP_T,
100 100
 		FORWARD_UDP_T,