Browse code

t_attr_to_uri() moved from tm into core as avp_to_uri() (Jiri's wish)

Bogdan-Andrei Iancu authored on 24/02/2004 16:59:33
Showing 6 changed files
... ...
@@ -36,6 +36,7 @@
36 36
  *  2003-04-22  strip_tail added (jiri)
37 37
  *  2003-10-02  added SET_ADV_ADDR_T & SET_ADV_PORT_T (andrei)
38 38
  *  2003-10-29  added FORCE_TCP_ALIAS_T (andrei)
39
+ *  2004-02-24  added LOAD_AVP_T and AVP_TO_URI_T (bogdan)
39 40
  */
40 41
 
41 42
 
... ...
@@ -89,7 +90,8 @@ int do_action(struct action* a, struct sip_msg* msg)
89 89
 	int len;
90 90
 	int user;
91 91
 	struct sip_uri uri, next_hop;
92
-	struct sip_uri* u;
92
+	struct usr_avp *avp;
93
+	struct sip_uri *u;
93 94
 	unsigned short port;
94 95
 	int proto;
95 96
 
... ...
@@ -671,9 +673,45 @@ int do_action(struct action* a, struct sip_msg* msg)
671 671
 			(int)a->p3.number))==-1 ) {
672 672
 				LOG(L_ERR,"ERROR:do_action: load avp failed\n");
673 673
 				ret=E_UNSPEC;
674
+				break;
674 675
 			}
675 676
 			ret = (ret==0)?1/*success*/:E_UNSPEC/*notfound*/;
676 677
 			break;
678
+		case AVP_TO_URI_T:
679
+			if (a->p1_type!=STR_ST ) {
680
+				LOG(L_CRIT,"BUG: do_action: bad avp_to_uri(%d) params "
681
+						"types\n",a->p1_type);
682
+				ret=E_BUG;
683
+				break;
684
+			}
685
+			/* look for the attribute */
686
+			if ( (avp=search_avp( (str*)a->p1.string ))==0) {
687
+				ret=E_UNSPEC;
688
+				break;
689
+			}
690
+			if (avp->val_type!=AVP_TYPE_STR) {
691
+				LOG(L_ERR,"ERROR:do_action: in avp_to_uri attribute <%s> "
692
+					"doesn't has a STR value\n",((str*)a->p1.string)->s);
693
+				ret=E_UNSPEC;
694
+				break;
695
+			}
696
+			/* replace the ruri */
697
+			new_uri = (char*)pkg_malloc( avp->val.str_val.len+1 );
698
+			if (new_uri==0) {
699
+				LOG(L_ERR,"ERROR:tm:t_attr_to_uri: no more pkg memory\n");
700
+				ret = E_OUT_OF_MEM;
701
+				break;
702
+			}
703
+			memcpy( new_uri, avp->val.str_val.s, avp->val.str_val.len);
704
+			new_uri[avp->val.str_val.len] = 0;
705
+			if (msg->new_uri.s)
706
+				pkg_free( msg->new_uri.s );
707
+			msg->new_uri.s = new_uri;
708
+			msg->new_uri.len = avp->val.str_val.len;
709
+			msg->parsed_uri_ok=0;
710
+
711
+			ret = 1;
712
+			break;
677 713
 		default:
678 714
 			LOG(L_CRIT, "BUG: do_action: unknown type %d\n", a->type);
679 715
 	}
... ...
@@ -44,6 +44,7 @@
44 44
  *  2003-10-13  added fifo_dir (andrei)
45 45
  *  2003-10-28  added tcp_accept_aliases (andrei)
46 46
  *  2003-11-29  added {tcp_send, tcp_connect, tls_*}_timeout (andrei)
47
+ *  2004-02-24  added LOAD_AVP_T and AVP_TO_URI_T (bogdan)
47 48
  */
48 49
 
49 50
 
... ...
@@ -115,6 +116,7 @@ ELSE			"else"
115 115
 SET_ADV_ADDRESS	"set_advertised_address"
116 116
 SET_ADV_PORT	"set_advertised_port"
117 117
 LOAD_AVP		"load_avp"
118
+AVP_TO_URI		"avp_to_uri"
118 119
 
119 120
 /*ACTION LVALUES*/
120 121
 URIHOST			"uri:host"
... ...
@@ -289,6 +291,7 @@ EAT_ABLE	[\ \t\b\r]
289 289
 <INITIAL>{FORCE_TCP_ALIAS}	{ count(); yylval.strval=yytext;
290 290
 								return FORCE_TCP_ALIAS; }
291 291
 <INITIAL>{LOAD_AVP}	{ count(); yylval.strval=yytext; return LOAD_AVP; }
292
+<INITIAL>{AVP_TO_URI}	{ count(); yylval.strval=yytext; return AVP_TO_URI; }
292 293
 	
293 294
 <INITIAL>{IF}	{ count(); yylval.strval=yytext; return IF; }
294 295
 <INITIAL>{ELSE}	{ count(); yylval.strval=yytext; return ELSE; }
... ...
@@ -50,6 +50,7 @@
50 50
  * 2003-10-24  converted to the new socket_info lists (andrei)
51 51
  * 2003-10-28  added tcp_accept_aliases (andrei)
52 52
  * 2003-11-20  added {tcp_connect, tcp_send, tls_*}_timeout (andrei)
53
+ * 2004-02-24  added LOAD_AVP_T and AVP_TO_URI_T (bogdan)
53 54
  */
54 55
 
55 56
 
... ...
@@ -176,6 +177,7 @@ static struct id_list* mk_listen_id(char*, int, int);
176 176
 %token TCP
177 177
 %token TLS
178 178
 %token LOAD_AVP
179
+%token AVP_TO_URI
179 180
 
180 181
 /* config vars. */
181 182
 %token DEBUG
... ...
@@ -1497,6 +1499,19 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1497 1497
 					}
1498 1498
 					}
1499 1499
 		| LOAD_AVP error { $$=0; yyerror("missing '(' or ')' ?"); }
1500
+		| AVP_TO_URI LPAREN STRING RPAREN {
1501
+								$$=0;
1502
+								if ((str_tmp=pkg_malloc(sizeof(str)))==0){
1503
+										LOG(L_CRIT, "ERROR: cfg. parser:"
1504
+													" out of memory.\n");
1505
+								}else{
1506
+										str_tmp->s=$3;
1507
+										str_tmp->len=strlen($3);
1508
+										$$=mk_action(AVP_TO_URI_T, STR_ST,
1509
+											0, str_tmp, 0);
1510
+								}
1511
+										}
1512
+		| AVP_TO_URI error { $$=0; yyerror("missing '(' or ')' ?"); }
1500 1513
 		| SET_ADV_ADDRESS LPAREN listen_id RPAREN {
1501 1514
 								$$=0;
1502 1515
 								if ((str_tmp=pkg_malloc(sizeof(str)))==0){
... ...
@@ -166,8 +166,6 @@ inline static int w_t_forward_nonack_tls(struct sip_msg* msg, char* str,char*);
166 166
 inline static int w_t_on_negative(struct sip_msg* msg, char *go_to, char *foo);
167 167
 inline static int w_t_on_reply(struct sip_msg* msg, char *go_to, char *foo );
168 168
 inline static int t_check_status(struct sip_msg* msg, char *regexp, char *foo);
169
-inline static int t_flush_flags(struct sip_msg* msg, char *dir, char *foo);
170
-static int t_attr_to_uri(struct sip_msg* msg, char *s, char *foo);
171 169
 
172 170
 
173 171
 static cmd_export_t cmds[]={
... ...
@@ -225,10 +223,6 @@ static cmd_export_t cmds[]={
225 225
 			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
226 226
 	{"t_check_status",     t_check_status,          1, fixup_str2regexp,
227 227
 			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
228
-	{"t_flush_flags",     t_flush_flags,            1, fixup_str2int,
229
-			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
230
-	{"t_attr_to_uri",     t_attr_to_uri,            1, fixup_string2str,
231
-			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
232 228
 	{"t_write_req",       t_write_req,              2, 0,
233 229
 			REQUEST_ROUTE | FAILURE_ROUTE },
234 230
 
... ...
@@ -554,37 +548,6 @@ static int child_init(int rank) {
554 554
 
555 555
 
556 556
 /**************************** wrapper functions ***************************/
557
-static int t_attr_to_uri(struct sip_msg* msg, char *s, char *foo)
558
-{
559
-	struct usr_avp   *avp;
560
-	char             *uri;
561
-
562
-	/* look for the attribute */
563
-	avp = search_avp( (str*)s );
564
-	if (avp==0)
565
-		return -1;
566
-	if (avp->val_type!=AVP_TYPE_STR) {
567
-		LOG(L_ERR,"ERROR:tm:t_attr_to_uri: attribute <%.*s> doesn't has a "
568
-			" STR value\n", ((str*)s)->len, ((str*)s)->s);
569
-		return -1;
570
-	}
571
-	/* replace the ruri */
572
-	uri = (char*)pkg_malloc( avp->val.str_val.len+1 );
573
-	if (uri==0) {
574
-		LOG(L_ERR,"ERROR:tm:t_attr_to_uri: no more pkg memory\n");
575
-		return -1;
576
-	}
577
-	memcpy( uri, avp->val.str_val.s, avp->val.str_val.len);
578
-	uri[avp->val.str_val.len] = 0;
579
-	if (msg->new_uri.s)
580
-		pkg_free( msg->new_uri.s );
581
-	msg->new_uri.s = uri;
582
-	msg->new_uri.len = avp->val.str_val.len;
583
-	msg->parsed_uri_ok=0;
584
-	return 1;
585
-}
586
-
587
-
588 557
 static int t_check_status(struct sip_msg* msg, char *regexp, char *foo)
589 558
 {
590 559
 	regmatch_t pmatch;
... ...
@@ -638,34 +601,6 @@ static int t_check_status(struct sip_msg* msg, char *regexp, char *foo)
638 638
 }
639 639
 
640 640
 
641
-static int t_flush_flags(struct sip_msg* msg, char *dir, char *foo)
642
-{
643
-	struct cell *t;
644
-
645
-	/* first get the transaction */
646
-	if (t_check( msg , 0 )==-1) return -1;
647
-	if ( (t=get_t())==0) {
648
-		LOG(L_ERR, "ERROR: t_flush_flags: cannot flush flags for a message "
649
-			"which has no T-state established\n");
650
-		return -1;
651
-	}
652
-
653
-	/* do the flush */
654
-	switch ((int)dir) {
655
-		case  1:
656
-			t->uas.request->flags = msg->flags;
657
-			break;
658
-		case  2:
659
-			msg->flags = t->uas.request->flags;
660
-			break;
661
-		default:
662
-			LOG(L_ERR,"ERROR:t_flush_flags: unknown direction %d\n",(int)dir);
663
-			return -1;
664
-	}
665
-	return 1;
666
-}
667
-
668
-
669 641
 inline static int w_t_check(struct sip_msg* msg, char* str, char* str2)
670 642
 {
671 643
 	return t_check( msg , 0  ) ? 1 : -1;
... ...
@@ -32,6 +32,7 @@
32 32
  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
33 33
  *  2003-04-12  FORCE_RPORT_T added (andrei)
34 34
  *  2003-10-02  added SET_ADV_ADDRESS & SET_ADV_PORT (andrei)
35
+ *  2004-02-24  added LOAD_AVP_T and AVP_TO_URI_T (bogdan)
35 36
  */
36 37
 
37 38
 
... ...
@@ -330,6 +331,9 @@ void print_action(struct action* a)
330 330
 			case LOAD_AVP_T:
331 331
 					DBG("load_avp(");
332 332
 					break;
333
+			case AVP_TO_URI_T:
334
+					DBG("avp_to_attr");
335
+					break;
333 336
 			default:
334 337
 					DBG("UNKNOWN(");
335 338
 		}
... ...
@@ -32,6 +32,7 @@
32 32
  *  2003-04-22  strip_tail added (jiri)
33 33
  *  2003-10-10  >,<,>=,<=, != and MSGLEN_O added (andrei)
34 34
  *  2003-10-28  FORCE_TCP_ALIAS added (andrei)
35
+ *  2004-02-24  added LOAD_AVP_T and AVP_TO_URI_T (bogdan)
35 36
  */
36 37
 
37 38
 
... ...
@@ -73,7 +74,8 @@ enum { FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
73 73
 		SET_ADV_ADDR_T,
74 74
 		SET_ADV_PORT_T,
75 75
 		FORCE_TCP_ALIAS_T,
76
-		LOAD_AVP_T
76
+		LOAD_AVP_T,
77
+		AVP_TO_URI_T
77 78
 };
78 79
 enum { NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST, RE_ST, PROXY_ST,
79 80
 		EXPR_ST, ACTIONS_ST, CMDF_ST, MODFIXUP_ST, URIHOST_ST, URIPORT_ST,