Browse code

core: allow send() without parameters

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

Daniel-Constantin Mierla authored on 06/04/2012 12:42:44
Showing 2 changed files
... ...
@@ -485,15 +485,45 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
485 485
 			break;
486 486
 		case SEND_T:
487 487
 		case SEND_TCP_T:
488
-			if ((a->val[0].type!= PROXY_ST)|(a->val[1].type!=NUMBER_ST)){
489
-				LOG(L_CRIT, "BUG: do_action: bad send() types %d, %d\n",
490
-						a->val[0].type, a->val[1].type);
491
-				ret=E_BUG;
492
-				goto error;
488
+			if (a->val[0].type==URIHOST_ST){
489
+				/*get next hop uri uri*/
490
+				if (msg->dst_uri.len) {
491
+					ret = parse_uri(msg->dst_uri.s, msg->dst_uri.len,
492
+									&next_hop);
493
+					u = &next_hop;
494
+				} else {
495
+					ret = parse_sip_msg_uri(msg);
496
+					u = &msg->parsed_uri;
497
+				}
498
+
499
+				if (ret<0) {
500
+					LM_ERR("send() - bad_uri dropping packet\n");
501
+					ret=E_BUG;
502
+					goto error;
503
+				}
504
+				/* init dst */
505
+				init_dest_info(&dst);
506
+				ret = sip_hostport2su(&dst.to, &u->host, u->port_no,
507
+							&dst.proto);
508
+				if(ret!=0) {
509
+					LM_ERR("failed to resolve [%.*s]\n", u->host.len,
510
+						ZSW(u->host.s));
511
+					ret=E_BUG;
512
+					goto error;
513
+				}
514
+			} else {
515
+				if ((a->val[0].type!= PROXY_ST)|(a->val[1].type!=NUMBER_ST)){
516
+					LOG(L_CRIT, "BUG: do_action: bad send() types %d, %d\n",
517
+							a->val[0].type, a->val[1].type);
518
+					ret=E_BUG;
519
+					goto error;
520
+				}
521
+				/* init dst */
522
+				init_dest_info(&dst);
523
+				ret=proxy2su(&dst.to,  (struct proxy_l*)a->val[0].u.data);
524
+				if(ret==0)
525
+					proxy_mark((struct proxy_l*)a->val[0].u.data, ret);
493 526
 			}
494
-			/* init dst */
495
-			init_dest_info(&dst);
496
-			ret=proxy2su(&dst.to,  (struct proxy_l*)a->val[0].u.data);
497 527
 			if (ret==0){
498 528
 				if (p_onsend){
499 529
 					tmp=p_onsend->buf;
... ...
@@ -524,7 +554,6 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
524 524
 				ret=E_BUG;
525 525
 				goto error;
526 526
 			}
527
-			proxy_mark((struct proxy_l*)a->val[0].u.data, ret);
528 527
 			if (ret>=0) ret=1;
529 528
 
530 529
 			break;
... ...
@@ -3154,6 +3154,7 @@ cmd:
3154 3154
 	| FORWARD_SCTP error { $$=0; yyerror("missing '(' or ')' ?"); }
3155 3155
 	| FORWARD_SCTP LPAREN error RPAREN { $$=0; 
3156 3156
 									yyerror("bad forward_tls argument"); }
3157
+	| SEND LPAREN RPAREN { $$=mk_action(SEND_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
3157 3158
 	| SEND LPAREN host RPAREN	{ $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
3158 3159
 	| SEND LPAREN STRING RPAREN { $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
3159 3160
 	| SEND LPAREN ip RPAREN		{ $$=mk_action(SEND_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }
... ...
@@ -3162,6 +3163,7 @@ cmd:
3162 3162
 	| SEND LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(SEND_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
3163 3163
 	| SEND error { $$=0; yyerror("missing '(' or ')' ?"); }
3164 3164
 	| SEND LPAREN error RPAREN { $$=0; yyerror("bad send argument"); }
3165
+	| SEND_TCP LPAREN RPAREN { $$=mk_action(SEND_TCP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
3165 3166
 	| SEND_TCP LPAREN host RPAREN	{ $$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
3166 3167
 	| SEND_TCP LPAREN STRING RPAREN { $$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
3167 3168
 	| SEND_TCP LPAREN ip RPAREN	{ $$=mk_action(SEND_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }