[sr-dev] git:master: core: allow send() without parameters

Daniel-Constantin Mierla miconda at gmail.com
Fri Apr 6 18:55:22 CEST 2012


Module: sip-router
Branch: master
Commit: 8e4db808bf9f94d3ccf0f14ed22e75586afd0f23
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8e4db808bf9f94d3ccf0f14ed22e75586afd0f23

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Fri Apr  6 14:42:44 2012 +0200

core: allow send() without parameters

- will use r-uri/dst-uri to send the msg buffer

---

 action.c |   47 ++++++++++++++++++++++++++++++++++++++---------
 cfg.y    |    2 ++
 2 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/action.c b/action.c
index ec7df6f..5263f02 100644
--- a/action.c
+++ b/action.c
@@ -485,15 +485,45 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
 			break;
 		case SEND_T:
 		case SEND_TCP_T:
-			if ((a->val[0].type!= PROXY_ST)|(a->val[1].type!=NUMBER_ST)){
-				LOG(L_CRIT, "BUG: do_action: bad send() types %d, %d\n",
-						a->val[0].type, a->val[1].type);
-				ret=E_BUG;
-				goto error;
+			if (a->val[0].type==URIHOST_ST){
+				/*get next hop uri uri*/
+				if (msg->dst_uri.len) {
+					ret = parse_uri(msg->dst_uri.s, msg->dst_uri.len,
+									&next_hop);
+					u = &next_hop;
+				} else {
+					ret = parse_sip_msg_uri(msg);
+					u = &msg->parsed_uri;
+				}
+
+				if (ret<0) {
+					LM_ERR("send() - bad_uri dropping packet\n");
+					ret=E_BUG;
+					goto error;
+				}
+				/* init dst */
+				init_dest_info(&dst);
+				ret = sip_hostport2su(&dst.to, &u->host, u->port_no,
+							&dst.proto);
+				if(ret!=0) {
+					LM_ERR("failed to resolve [%.*s]\n", u->host.len,
+						ZSW(u->host.s));
+					ret=E_BUG;
+					goto error;
+				}
+			} else {
+				if ((a->val[0].type!= PROXY_ST)|(a->val[1].type!=NUMBER_ST)){
+					LOG(L_CRIT, "BUG: do_action: bad send() types %d, %d\n",
+							a->val[0].type, a->val[1].type);
+					ret=E_BUG;
+					goto error;
+				}
+				/* init dst */
+				init_dest_info(&dst);
+				ret=proxy2su(&dst.to,  (struct proxy_l*)a->val[0].u.data);
+				if(ret==0)
+					proxy_mark((struct proxy_l*)a->val[0].u.data, ret);
 			}
-			/* init dst */
-			init_dest_info(&dst);
-			ret=proxy2su(&dst.to,  (struct proxy_l*)a->val[0].u.data);
 			if (ret==0){
 				if (p_onsend){
 					tmp=p_onsend->buf;
@@ -524,7 +554,6 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
 				ret=E_BUG;
 				goto error;
 			}
-			proxy_mark((struct proxy_l*)a->val[0].u.data, ret);
 			if (ret>=0) ret=1;
 
 			break;
diff --git a/cfg.y b/cfg.y
index 99f77a6..1c62c10 100644
--- a/cfg.y
+++ b/cfg.y
@@ -3154,6 +3154,7 @@ cmd:
 	| FORWARD_SCTP error { $$=0; yyerror("missing '(' or ')' ?"); }
 	| FORWARD_SCTP LPAREN error RPAREN { $$=0; 
 									yyerror("bad forward_tls argument"); }
+	| SEND LPAREN RPAREN { $$=mk_action(SEND_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
 	| SEND LPAREN host RPAREN	{ $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
 	| SEND LPAREN STRING RPAREN { $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
 	| SEND LPAREN ip RPAREN		{ $$=mk_action(SEND_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }
@@ -3162,6 +3163,7 @@ cmd:
 	| SEND LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(SEND_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
 	| SEND error { $$=0; yyerror("missing '(' or ')' ?"); }
 	| SEND LPAREN error RPAREN { $$=0; yyerror("bad send argument"); }
+	| SEND_TCP LPAREN RPAREN { $$=mk_action(SEND_TCP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
 	| SEND_TCP LPAREN host RPAREN	{ $$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
 	| SEND_TCP LPAREN STRING RPAREN { $$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
 	| SEND_TCP LPAREN ip RPAREN	{ $$=mk_action(SEND_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }




More information about the sr-dev mailing list