2
0
Эх сурвалжийг харах

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

Bogdan-Andrei Iancu 21 жил өмнө
parent
commit
1bee75ad6a
6 өөрчлөгдсөн 64 нэмэгдсэн , 67 устгасан
  1. 39 1
      action.c
  2. 3 0
      cfg.lex
  3. 15 0
      cfg.y
  4. 0 65
      modules/tm/tm.c
  5. 4 0
      route_struct.c
  6. 3 1
      route_struct.h

+ 39 - 1
action.c

@@ -36,6 +36,7 @@
  *  2003-04-22  strip_tail added (jiri)
  *  2003-10-02  added SET_ADV_ADDR_T & SET_ADV_PORT_T (andrei)
  *  2003-10-29  added FORCE_TCP_ALIAS_T (andrei)
+ *  2004-02-24  added LOAD_AVP_T and AVP_TO_URI_T (bogdan)
  */
 
 
@@ -89,7 +90,8 @@ int do_action(struct action* a, struct sip_msg* msg)
 	int len;
 	int user;
 	struct sip_uri uri, next_hop;
-	struct sip_uri* u;
+	struct usr_avp *avp;
+	struct sip_uri *u;
 	unsigned short port;
 	int proto;
 
@@ -671,9 +673,45 @@ int do_action(struct action* a, struct sip_msg* msg)
 			(int)a->p3.number))==-1 ) {
 				LOG(L_ERR,"ERROR:do_action: load avp failed\n");
 				ret=E_UNSPEC;
+				break;
 			}
 			ret = (ret==0)?1/*success*/:E_UNSPEC/*notfound*/;
 			break;
+		case AVP_TO_URI_T:
+			if (a->p1_type!=STR_ST ) {
+				LOG(L_CRIT,"BUG: do_action: bad avp_to_uri(%d) params "
+						"types\n",a->p1_type);
+				ret=E_BUG;
+				break;
+			}
+			/* look for the attribute */
+			if ( (avp=search_avp( (str*)a->p1.string ))==0) {
+				ret=E_UNSPEC;
+				break;
+			}
+			if (avp->val_type!=AVP_TYPE_STR) {
+				LOG(L_ERR,"ERROR:do_action: in avp_to_uri attribute <%s> "
+					"doesn't has a STR value\n",((str*)a->p1.string)->s);
+				ret=E_UNSPEC;
+				break;
+			}
+			/* replace the ruri */
+			new_uri = (char*)pkg_malloc( avp->val.str_val.len+1 );
+			if (new_uri==0) {
+				LOG(L_ERR,"ERROR:tm:t_attr_to_uri: no more pkg memory\n");
+				ret = E_OUT_OF_MEM;
+				break;
+			}
+			memcpy( new_uri, avp->val.str_val.s, avp->val.str_val.len);
+			new_uri[avp->val.str_val.len] = 0;
+			if (msg->new_uri.s)
+				pkg_free( msg->new_uri.s );
+			msg->new_uri.s = new_uri;
+			msg->new_uri.len = avp->val.str_val.len;
+			msg->parsed_uri_ok=0;
+
+			ret = 1;
+			break;
 		default:
 			LOG(L_CRIT, "BUG: do_action: unknown type %d\n", a->type);
 	}

+ 3 - 0
cfg.lex

@@ -44,6 +44,7 @@
  *  2003-10-13  added fifo_dir (andrei)
  *  2003-10-28  added tcp_accept_aliases (andrei)
  *  2003-11-29  added {tcp_send, tcp_connect, tls_*}_timeout (andrei)
+ *  2004-02-24  added LOAD_AVP_T and AVP_TO_URI_T (bogdan)
  */
 
 
@@ -115,6 +116,7 @@ ELSE			"else"
 SET_ADV_ADDRESS	"set_advertised_address"
 SET_ADV_PORT	"set_advertised_port"
 LOAD_AVP		"load_avp"
+AVP_TO_URI		"avp_to_uri"
 
 /*ACTION LVALUES*/
 URIHOST			"uri:host"
@@ -289,6 +291,7 @@ EAT_ABLE	[\ \t\b\r]
 <INITIAL>{FORCE_TCP_ALIAS}	{ count(); yylval.strval=yytext;
 								return FORCE_TCP_ALIAS; }
 <INITIAL>{LOAD_AVP}	{ count(); yylval.strval=yytext; return LOAD_AVP; }
+<INITIAL>{AVP_TO_URI}	{ count(); yylval.strval=yytext; return AVP_TO_URI; }
 	
 <INITIAL>{IF}	{ count(); yylval.strval=yytext; return IF; }
 <INITIAL>{ELSE}	{ count(); yylval.strval=yytext; return ELSE; }

+ 15 - 0
cfg.y

@@ -50,6 +50,7 @@
  * 2003-10-24  converted to the new socket_info lists (andrei)
  * 2003-10-28  added tcp_accept_aliases (andrei)
  * 2003-11-20  added {tcp_connect, tcp_send, tls_*}_timeout (andrei)
+ * 2004-02-24  added LOAD_AVP_T and AVP_TO_URI_T (bogdan)
  */
 
 
@@ -176,6 +177,7 @@ static struct id_list* mk_listen_id(char*, int, int);
 %token TCP
 %token TLS
 %token LOAD_AVP
+%token AVP_TO_URI
 
 /* config vars. */
 %token DEBUG
@@ -1497,6 +1499,19 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
 					}
 					}
 		| LOAD_AVP error { $$=0; yyerror("missing '(' or ')' ?"); }
+		| AVP_TO_URI LPAREN STRING RPAREN {
+								$$=0;
+								if ((str_tmp=pkg_malloc(sizeof(str)))==0){
+										LOG(L_CRIT, "ERROR: cfg. parser:"
+													" out of memory.\n");
+								}else{
+										str_tmp->s=$3;
+										str_tmp->len=strlen($3);
+										$$=mk_action(AVP_TO_URI_T, STR_ST,
+											0, str_tmp, 0);
+								}
+										}
+		| AVP_TO_URI error { $$=0; yyerror("missing '(' or ')' ?"); }
 		| SET_ADV_ADDRESS LPAREN listen_id RPAREN {
 								$$=0;
 								if ((str_tmp=pkg_malloc(sizeof(str)))==0){

+ 0 - 65
modules/tm/tm.c

@@ -166,8 +166,6 @@ inline static int w_t_forward_nonack_tls(struct sip_msg* msg, char* str,char*);
 inline static int w_t_on_negative(struct sip_msg* msg, char *go_to, char *foo);
 inline static int w_t_on_reply(struct sip_msg* msg, char *go_to, char *foo );
 inline static int t_check_status(struct sip_msg* msg, char *regexp, char *foo);
-inline static int t_flush_flags(struct sip_msg* msg, char *dir, char *foo);
-static int t_attr_to_uri(struct sip_msg* msg, char *s, char *foo);
 
 
 static cmd_export_t cmds[]={
@@ -225,10 +223,6 @@ static cmd_export_t cmds[]={
 			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
 	{"t_check_status",     t_check_status,          1, fixup_str2regexp,
 			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
-	{"t_flush_flags",     t_flush_flags,            1, fixup_str2int,
-			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
-	{"t_attr_to_uri",     t_attr_to_uri,            1, fixup_string2str,
-			REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE },
 	{"t_write_req",       t_write_req,              2, 0,
 			REQUEST_ROUTE | FAILURE_ROUTE },
 
@@ -554,37 +548,6 @@ static int child_init(int rank) {
 
 
 /**************************** wrapper functions ***************************/
-static int t_attr_to_uri(struct sip_msg* msg, char *s, char *foo)
-{
-	struct usr_avp   *avp;
-	char             *uri;
-
-	/* look for the attribute */
-	avp = search_avp( (str*)s );
-	if (avp==0)
-		return -1;
-	if (avp->val_type!=AVP_TYPE_STR) {
-		LOG(L_ERR,"ERROR:tm:t_attr_to_uri: attribute <%.*s> doesn't has a "
-			" STR value\n", ((str*)s)->len, ((str*)s)->s);
-		return -1;
-	}
-	/* replace the ruri */
-	uri = (char*)pkg_malloc( avp->val.str_val.len+1 );
-	if (uri==0) {
-		LOG(L_ERR,"ERROR:tm:t_attr_to_uri: no more pkg memory\n");
-		return -1;
-	}
-	memcpy( uri, avp->val.str_val.s, avp->val.str_val.len);
-	uri[avp->val.str_val.len] = 0;
-	if (msg->new_uri.s)
-		pkg_free( msg->new_uri.s );
-	msg->new_uri.s = uri;
-	msg->new_uri.len = avp->val.str_val.len;
-	msg->parsed_uri_ok=0;
-	return 1;
-}
-
-
 static int t_check_status(struct sip_msg* msg, char *regexp, char *foo)
 {
 	regmatch_t pmatch;
@@ -638,34 +601,6 @@ static int t_check_status(struct sip_msg* msg, char *regexp, char *foo)
 }
 
 
-static int t_flush_flags(struct sip_msg* msg, char *dir, char *foo)
-{
-	struct cell *t;
-
-	/* first get the transaction */
-	if (t_check( msg , 0 )==-1) return -1;
-	if ( (t=get_t())==0) {
-		LOG(L_ERR, "ERROR: t_flush_flags: cannot flush flags for a message "
-			"which has no T-state established\n");
-		return -1;
-	}
-
-	/* do the flush */
-	switch ((int)dir) {
-		case  1:
-			t->uas.request->flags = msg->flags;
-			break;
-		case  2:
-			msg->flags = t->uas.request->flags;
-			break;
-		default:
-			LOG(L_ERR,"ERROR:t_flush_flags: unknown direction %d\n",(int)dir);
-			return -1;
-	}
-	return 1;
-}
-
-
 inline static int w_t_check(struct sip_msg* msg, char* str, char* str2)
 {
 	return t_check( msg , 0  ) ? 1 : -1;

+ 4 - 0
route_struct.c

@@ -32,6 +32,7 @@
  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  *  2003-04-12  FORCE_RPORT_T added (andrei)
  *  2003-10-02  added SET_ADV_ADDRESS & SET_ADV_PORT (andrei)
+ *  2004-02-24  added LOAD_AVP_T and AVP_TO_URI_T (bogdan)
  */
 
 
@@ -330,6 +331,9 @@ void print_action(struct action* a)
 			case LOAD_AVP_T:
 					DBG("load_avp(");
 					break;
+			case AVP_TO_URI_T:
+					DBG("avp_to_attr");
+					break;
 			default:
 					DBG("UNKNOWN(");
 		}

+ 3 - 1
route_struct.h

@@ -32,6 +32,7 @@
  *  2003-04-22  strip_tail added (jiri)
  *  2003-10-10  >,<,>=,<=, != and MSGLEN_O added (andrei)
  *  2003-10-28  FORCE_TCP_ALIAS added (andrei)
+ *  2004-02-24  added LOAD_AVP_T and AVP_TO_URI_T (bogdan)
  */
 
 
@@ -73,7 +74,8 @@ enum { FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
 		SET_ADV_ADDR_T,
 		SET_ADV_PORT_T,
 		FORCE_TCP_ALIAS_T,
-		LOAD_AVP_T
+		LOAD_AVP_T,
+		AVP_TO_URI_T
 };
 enum { NOSUBTYPE=0, STRING_ST, NET_ST, NUMBER_ST, IP_ST, RE_ST, PROXY_ST,
 		EXPR_ST, ACTIONS_ST, CMDF_ST, MODFIXUP_ST, URIHOST_ST, URIPORT_ST,