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 90
 	int len;
90 91
 	int user;
91 92
 	struct sip_uri uri, next_hop;
92
-	struct sip_uri* u;
93
+	struct usr_avp *avp;
94
+	struct sip_uri *u;
93 95
 	unsigned short port;
94 96
 	int proto;
95 97
 
... ...
@@ -671,9 +673,45 @@ int do_action(struct action* a, struct sip_msg* msg)
671 673
 			(int)a->p3.number))==-1 ) {
672 674
 				LOG(L_ERR,"ERROR:do_action: load avp failed\n");
673 675
 				ret=E_UNSPEC;
676
+				break;
674 677
 			}
675 678
 			ret = (ret==0)?1/*success*/:E_UNSPEC/*notfound*/;
676 679
 			break;
680
+		case AVP_TO_URI_T:
681
+			if (a->p1_type!=STR_ST ) {
682
+				LOG(L_CRIT,"BUG: do_action: bad avp_to_uri(%d) params "
683
+						"types\n",a->p1_type);
684
+				ret=E_BUG;
685
+				break;
686
+			}
687
+			/* look for the attribute */
688
+			if ( (avp=search_avp( (str*)a->p1.string ))==0) {
689
+				ret=E_UNSPEC;
690
+				break;
691
+			}
692
+			if (avp->val_type!=AVP_TYPE_STR) {
693
+				LOG(L_ERR,"ERROR:do_action: in avp_to_uri attribute <%s> "
694
+					"doesn't has a STR value\n",((str*)a->p1.string)->s);
695
+				ret=E_UNSPEC;
696
+				break;
697
+			}
698
+			/* replace the ruri */
699
+			new_uri = (char*)pkg_malloc( avp->val.str_val.len+1 );
700
+			if (new_uri==0) {
701
+				LOG(L_ERR,"ERROR:tm:t_attr_to_uri: no more pkg memory\n");
702
+				ret = E_OUT_OF_MEM;
703
+				break;
704
+			}
705
+			memcpy( new_uri, avp->val.str_val.s, avp->val.str_val.len);
706
+			new_uri[avp->val.str_val.len] = 0;
707
+			if (msg->new_uri.s)
708
+				pkg_free( msg->new_uri.s );
709
+			msg->new_uri.s = new_uri;
710
+			msg->new_uri.len = avp->val.str_val.len;
711
+			msg->parsed_uri_ok=0;
712
+
713
+			ret = 1;
714
+			break;
677 715
 		default:
678 716
 			LOG(L_CRIT, "BUG: do_action: unknown type %d\n", a->type);
679 717
 	}
... ...
@@ -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 116
 SET_ADV_ADDRESS	"set_advertised_address"
116 117
 SET_ADV_PORT	"set_advertised_port"
117 118
 LOAD_AVP		"load_avp"
119
+AVP_TO_URI		"avp_to_uri"
118 120
 
119 121
 /*ACTION LVALUES*/
120 122
 URIHOST			"uri:host"
... ...
@@ -289,6 +291,7 @@ EAT_ABLE	[\ \t\b\r]
289 291
 <INITIAL>{FORCE_TCP_ALIAS}	{ count(); yylval.strval=yytext;
290 292
 								return FORCE_TCP_ALIAS; }
291 293
 <INITIAL>{LOAD_AVP}	{ count(); yylval.strval=yytext; return LOAD_AVP; }
294
+<INITIAL>{AVP_TO_URI}	{ count(); yylval.strval=yytext; return AVP_TO_URI; }
292 295
 	
293 296
 <INITIAL>{IF}	{ count(); yylval.strval=yytext; return IF; }
294 297
 <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 177
 %token TCP
177 178
 %token TLS
178 179
 %token LOAD_AVP
180
+%token AVP_TO_URI
179 181
 
180 182
 /* config vars. */
181 183
 %token DEBUG
... ...
@@ -1497,6 +1499,19 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1497 1499
 					}
1498 1500
 					}
1499 1501
 		| LOAD_AVP error { $$=0; yyerror("missing '(' or ')' ?"); }
1502
+		| AVP_TO_URI LPAREN STRING RPAREN {
1503
+								$$=0;
1504
+								if ((str_tmp=pkg_malloc(sizeof(str)))==0){
1505
+										LOG(L_CRIT, "ERROR: cfg. parser:"
1506
+													" out of memory.\n");
1507
+								}else{
1508
+										str_tmp->s=$3;
1509
+										str_tmp->len=strlen($3);
1510
+										$$=mk_action(AVP_TO_URI_T, STR_ST,
1511
+											0, str_tmp, 0);
1512
+								}
1513
+										}
1514
+		| AVP_TO_URI error { $$=0; yyerror("missing '(' or ')' ?"); }
1500 1515
 		| SET_ADV_ADDRESS LPAREN listen_id RPAREN {
1501 1516
 								$$=0;
1502 1517
 								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 223
 			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
226 224
 	{"t_check_status",     t_check_status,          1, fixup_str2regexp,
227 225
 			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 226
 	{"t_write_req",       t_write_req,              2, 0,
233 227
 			REQUEST_ROUTE | FAILURE_ROUTE },
234 228
 
... ...
@@ -554,37 +548,6 @@ static int child_init(int rank) {
554 548
 
555 549
 
556 550
 /**************************** 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 551
 static int t_check_status(struct sip_msg* msg, char *regexp, char *foo)
589 552
 {
590 553
 	regmatch_t pmatch;
... ...
@@ -638,34 +601,6 @@ static int t_check_status(struct sip_msg* msg, char *regexp, char *foo)
638 601
 }
639 602
 
640 603
 
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 604
 inline static int w_t_check(struct sip_msg* msg, char* str, char* str2)
670 605
 {
671 606
 	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 331
 			case LOAD_AVP_T:
331 332
 					DBG("load_avp(");
332 333
 					break;
334
+			case AVP_TO_URI_T:
335
+					DBG("avp_to_attr");
336
+					break;
333 337
 			default:
334 338
 					DBG("UNKNOWN(");
335 339
 		}
... ...
@@ -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 74
 		SET_ADV_ADDR_T,
74 75
 		SET_ADV_PORT_T,
75 76
 		FORCE_TCP_ALIAS_T,
76
-		LOAD_AVP_T
77
+		LOAD_AVP_T,
78
+		AVP_TO_URI_T
77 79
 };
78 80
 enum { NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST, RE_ST, PROXY_ST,
79 81
 		EXPR_ST, ACTIONS_ST, CMDF_ST, MODFIXUP_ST, URIHOST_ST, URIPORT_ST,