Browse code

strip_tail added (on Bill's request)

Jiri Kuthan authored on 22/04/2003 21:15:46
Showing 4 changed files
... ...
@@ -33,6 +33,7 @@
33 33
  *              replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
34 34
  *  2003-04-01  Added support for loose routing in forward (janakj)
35 35
  *  2003-04-12  FORCE_RPORT_T added (andrei)
36
+ *  2003-04-22  strip_tail added (jiri)
36 37
  */
37 38
 
38 39
 
... ...
@@ -376,8 +377,9 @@ int do_action(struct action* a, struct sip_msg* msg)
376 377
 		case SET_URI_T:
377 378
 		case PREFIX_T:
378 379
 		case STRIP_T:
380
+		case STRIP_TAIL_T:
379 381
 				user=0;
380
-				if (a->type==STRIP_T) {
382
+				if (a->type==STRIP_T || a->type==STRIP_TAIL_T) {
381 383
 					if (a->p1_type!=NUMBER_ST) {
382 384
 						LOG(L_CRIT, "BUG: do_action: bad set*() type %d\n",
383 385
 							a->p1_type);
... ...
@@ -464,6 +466,18 @@ int do_action(struct action* a, struct sip_msg* msg)
464 466
 						tmp=uri.user.s + a->p1.number;
465 467
 						len=uri.user.len - a->p1.number;
466 468
 					}
469
+				} else if (a->type==STRIP_TAIL_T) {
470
+					if (a->p1.number>uri.user.len) {
471
+						LOG(L_WARN, "WARNING: too long strip_tail asked; "
472
+									" deleting username: %d of <%.*s>\n",
473
+									a->p1.number, uri.user.len, uri.user.s );
474
+						len=0;
475
+					} else if (a->p1.number==uri.user.len) {
476
+						len=0;
477
+					} else {
478
+						tmp=uri.user.s;
479
+						len=uri.user.len - a->p1.number;
480
+					}
467 481
 				} else {
468 482
 					tmp=uri.user.s;
469 483
 					len=uri.user.len;
... ...
@@ -34,6 +34,7 @@
34 34
  *  2003-04-01  added dst_port, proto (tcp, udp, tls), af(inet, inet6) (andrei)
35 35
  *  2003-04-05  s/reply_route/failure_route, onreply_route introduced (jiri)
36 36
  *  2003-04-12  added force_rport, chdir and wdir (andrei)
37
+ *  2003-04-22  strip_tail added (jiri)
37 38
  */
38 39
 
39 40
 
... ...
@@ -97,6 +98,7 @@ SET_URI			"rewriteuri"|"seturi"
97 98
 REVERT_URI		"revert_uri"
98 99
 PREFIX			"prefix"
99 100
 STRIP			"strip"
101
+STRIP_TAIL		"strip_tail"
100 102
 APPEND_BRANCH	"append_branch"
101 103
 IF				"if"
102 104
 ELSE			"else"
... ...
@@ -232,6 +234,7 @@ EAT_ABLE	[\ \t\b\r]
232 234
 <INITIAL>{REVERT_URI}	{ count(); yylval.strval=yytext; return REVERT_URI; }
233 235
 <INITIAL>{PREFIX}	{ count(); yylval.strval=yytext; return PREFIX; }
234 236
 <INITIAL>{STRIP}	{ count(); yylval.strval=yytext; return STRIP; }
237
+<INITIAL>{STRIP_TAIL}	{ count(); yylval.strval=yytext; return STRIP_TAIL; }
235 238
 <INITIAL>{APPEND_BRANCH}	{ count(); yylval.strval=yytext; 
236 239
 								return APPEND_BRANCH; }
237 240
 <INITIAL>{FORCE_RPORT}	{ count(); yylval.strval=yytext; return FORCE_RPORT; }
... ...
@@ -38,6 +38,7 @@
38 38
  * 2003-04-05  s/reply_route/failure_route, onreply_route introduced (jiri)
39 39
  * 2003-04-12  added force_rport, chroot and wdir (andrei)
40 40
  * 2003-04-15  added tcp_children, disable_tcp (andrei)
41
+ * 2003-04-22  strip_tail added (jiri)
41 42
  */
42 43
 
43 44
 
... ...
@@ -116,6 +117,7 @@ int rt;  /* Type of route block for find_export */
116 117
 %token SET_HOSTPORT
117 118
 %token PREFIX
118 119
 %token STRIP
120
+%token STRIP_TAIL
119 121
 %token APPEND_BRANCH
120 122
 %token SET_USER
121 123
 %token SET_USERPASS
... ...
@@ -1056,6 +1058,12 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1056 1058
 		| PREFIX error { $$=0; yyerror("missing '(' or ')' ?"); }
1057 1059
 		| PREFIX LPAREN error RPAREN { $$=0; yyerror("bad argument, "
1058 1060
 														"string expected"); }
1061
+		| STRIP_TAIL LPAREN NUMBER RPAREN { $$=mk_action(STRIP_TAIL_T, 
1062
+									NUMBER_ST, 0, (void *) $3, 0); }
1063
+		| STRIP_TAIL error { $$=0; yyerror("missing '(' or ')' ?"); }
1064
+		| STRIP_TAIL LPAREN error RPAREN { $$=0; yyerror("bad argument, "
1065
+														"number expected"); }
1066
+
1059 1067
 		| STRIP LPAREN NUMBER RPAREN { $$=mk_action(STRIP_T, NUMBER_ST,
1060 1068
 														0, (void *) $3, 0); }
1061 1069
 		| STRIP error { $$=0; yyerror("missing '(' or ')' ?"); }
... ...
@@ -29,6 +29,7 @@
29 29
  * --------
30 30
  *
31 31
  *  2003-04-12  FORCE_RPORT_T added (andrei)
32
+ *  2003-04-22  strip_tail added (jiri)
32 33
  */
33 34
 
34 35
 
... ...
@@ -58,7 +59,7 @@ enum { FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
58 59
 		SET_HOST_T, SET_HOSTPORT_T, SET_USER_T, SET_USERPASS_T, 
59 60
 		SET_PORT_T, SET_URI_T, IF_T, MODULE_T,
60 61
 		SETFLAG_T, RESETFLAG_T, ISFLAGSET_T ,
61
-		LEN_GT_T, PREFIX_T, STRIP_T,
62
+		LEN_GT_T, PREFIX_T, STRIP_T,STRIP_TAIL_T,
62 63
 		APPEND_BRANCH_T,
63 64
 		REVERT_URI_T,
64 65
 		FORWARD_TCP_T,