diff --git a/action.c b/action.c index 5263f0279..b21e122f6 100644 --- a/action.c +++ b/action.c @@ -482,80 +482,6 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg) ret=E_BUG; goto error; } - break; - case SEND_T: - case SEND_TCP_T: - 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); - } - if (ret==0){ - if (p_onsend){ - tmp=p_onsend->buf; - len=p_onsend->len; - }else{ - tmp=msg->buf; - len=msg->len; - } - if (a->type==SEND_T){ - /*udp*/ - dst.proto=PROTO_UDP; /* not really needed for udp_send */ - dst.send_sock=get_send_socket(msg, &dst.to, PROTO_UDP); - if (dst.send_sock!=0){ - ret=udp_send(&dst, tmp, len); - }else{ - ret=-1; - } - } -#ifdef USE_TCP - else{ - /*tcp*/ - dst.proto=PROTO_TCP; - dst.id=0; - ret=tcp_send(&dst, 0, tmp, len); - } -#endif - }else{ - ret=E_BUG; - goto error; - } - if (ret>=0) ret=1; - break; case LOG_T: if ((a->val[0].type!=NUMBER_ST)|(a->val[1].type!=STRING_ST)){ diff --git a/cfg.lex b/cfg.lex index e9ce79a1d..5042ca34e 100644 --- a/cfg.lex +++ b/cfg.lex @@ -195,8 +195,6 @@ DROP "drop" EXIT "exit" RETURN "return" BREAK "break" -SEND send -SEND_TCP send_tcp LOG log ERROR error ROUTE route @@ -603,8 +601,6 @@ IMPORTFILE "import_file" {EXIT} { count(); yylval.strval=yytext; return EXIT; } {RETURN} { count(); yylval.strval=yytext; return RETURN; } {BREAK} { count(); yylval.strval=yytext; return BREAK; } -{SEND} { count(); yylval.strval=yytext; return SEND; } -{SEND_TCP} { count(); yylval.strval=yytext; return SEND_TCP; } {LOG} { count(); yylval.strval=yytext; return LOG_TOK; } {ERROR} { count(); yylval.strval=yytext; return ERROR; } {SETFLAG} { count(); yylval.strval=yytext; return SETFLAG; } diff --git a/cfg.y b/cfg.y index 08872830e..425754051 100644 --- a/cfg.y +++ b/cfg.y @@ -305,8 +305,6 @@ extern char *finame; %token FORWARD_TLS %token FORWARD_SCTP %token FORWARD_UDP -%token SEND -%token SEND_TCP %token EXIT %token DROP %token RETURN @@ -3157,24 +3155,6 @@ 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($$); } - | SEND LPAREN host COMMA NUMBER RPAREN { $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); } - | SEND LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); } - | 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($$); } - | SEND_TCP LPAREN host COMMA NUMBER RPAREN { $$=mk_action( SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$);} - | SEND_TCP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); } - | SEND_TCP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(SEND_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); } - | SEND_TCP error { $$=0; yyerror("missing '(' or ')' ?"); } - | SEND_TCP LPAREN error RPAREN { $$=0; yyerror("bad send_tcp argument"); } | LOG_TOK LPAREN STRING RPAREN {$$=mk_action(LOG_T, 2, NUMBER_ST, (void*)(L_DBG+1), STRING_ST, $3); set_cfg_pos($$); } diff --git a/modules/corex/corex_lib.c b/modules/corex/corex_lib.c index 1f69847ea..cfe49fd1e 100644 --- a/modules/corex/corex_lib.c +++ b/modules/corex/corex_lib.c @@ -27,6 +27,8 @@ #include "../../dprint.h" #include "../../dset.h" #include "../../forward.h" +#include "../../parser/parse_uri.h" +#include "../../resolve.h" #include "corex_lib.h" @@ -211,3 +213,88 @@ int corex_register_check_self(void) } return 0; } + +int corex_send(sip_msg_t *msg, gparam_t *pu, enum sip_protos proto) +{ + str dest = {0}; + int ret = 0; + struct sip_uri next_hop, *u; + struct dest_info dst; + char *p; + + if (pu) + { + if (fixup_get_svalue(msg, pu, &dest)) + { + LM_ERR("cannot get the destination parameter\n"); + return -1; + } + } + + init_dest_info(&dst); + + if (dest.len <= 0) + { + /*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; + } + } + else + { + u = &next_hop; + u->port_no = 5060; + u->host = dest; + p = memchr(dest.s, ':', dest.len); + if (p) + { + u->host.len = p - dest.s; + p++; + u->port_no = str2s(p, dest.len - (p - dest.s), NULL); + } + } + + 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; + } + + dst.proto = proto; + if (proto == PROTO_UDP) + { + dst.send_sock=get_send_socket(msg, &dst.to, PROTO_UDP); + if (dst.send_sock!=0){ + ret=udp_send(&dst, msg->buf, msg->len); + }else{ + ret=-1; + } + } +#ifdef USE_TCP + else{ + /*tcp*/ + dst.id=0; + ret=tcp_send(&dst, 0, msg->buf, msg->len); + } +#endif + + if (ret>=0) ret=1; + + +error: + return ret; +} diff --git a/modules/corex/corex_lib.h b/modules/corex/corex_lib.h index 49fa712ef..433e28a0f 100644 --- a/modules/corex/corex_lib.h +++ b/modules/corex/corex_lib.h @@ -25,6 +25,7 @@ #include "../../mod_fix.h" int corex_append_branch(sip_msg_t *msg, gparam_t *pu, gparam_t *pq); +int corex_send(sip_msg_t *msg, gparam_t *pu, enum sip_protos proto); int corex_add_alias_subdomains(char* aliasval); diff --git a/modules/corex/corex_mod.c b/modules/corex/corex_mod.c index 5b4690c77..bddba039c 100644 --- a/modules/corex/corex_mod.c +++ b/modules/corex/corex_mod.c @@ -34,6 +34,8 @@ MODULE_VERSION static int w_append_branch(sip_msg_t *msg, char *su, char *sq); +static int w_send(sip_msg_t *msg, char *su, char *sq); +static int w_send_tcp(sip_msg_t *msg, char *su, char *sq); int corex_alias_subdomains_param(modparam_t type, void *val); @@ -48,6 +50,14 @@ static cmd_export_t cmds[]={ 0, REQUEST_ROUTE | FAILURE_ROUTE }, {"append_branch", (cmd_function)w_append_branch, 2, fixup_spve_spve, 0, REQUEST_ROUTE | FAILURE_ROUTE }, + {"send", (cmd_function)w_send, 0, 0, + 0, REQUEST_ROUTE | FAILURE_ROUTE }, + {"send", (cmd_function)w_send, 1, fixup_spve_spve, + 0, REQUEST_ROUTE | FAILURE_ROUTE }, + {"send_tcp", (cmd_function)w_send_tcp, 0, 0, + 0, REQUEST_ROUTE | FAILURE_ROUTE }, + {"send_tcp", (cmd_function)w_send_tcp, 1, fixup_spve_null, + 0, REQUEST_ROUTE | FAILURE_ROUTE }, {0, 0, 0, 0, 0, 0} @@ -123,6 +133,22 @@ static int w_append_branch(sip_msg_t *msg, char *su, char *sq) return 1; } +/** + * config wrapper for send() and send_tcp() + */ +static int w_send(sip_msg_t *msg, char *su, char *sq) +{ + if(corex_send(msg, (gparam_t*)su, PROTO_UDP) < 0) + return -1; + return 1; +} +static int w_send_tcp(sip_msg_t *msg, char *su, char *sq) +{ + if(corex_send(msg, (gparam_t*)su, PROTO_TCP) < 0) + return -1; + return 1; +} + int corex_alias_subdomains_param(modparam_t type, void *val) { diff --git a/modules/debugger/debugger_act.c b/modules/debugger/debugger_act.c index e9372fa2b..e825054ca 100644 --- a/modules/debugger/debugger_act.c +++ b/modules/debugger/debugger_act.c @@ -46,7 +46,6 @@ static str _dbg_action_special[] = { static dbg_action_t _dbg_action_list[] = { { FORWARD_T, str_init("forward") }, - { SEND_T, str_init("send") }, { LOG_T, str_init("log") }, { ERROR_T, str_init("error") }, { ROUTE_T, str_init("route") }, @@ -82,7 +81,6 @@ static dbg_action_t _dbg_action_list[] = { { FORWARD_UDP_T, str_init("forward_udp") }, { FORWARD_TLS_T, str_init("forward_tls") }, { FORWARD_SCTP_T, str_init("forward_sctp") }, - { SEND_TCP_T, str_init("send_tcp") }, { FORCE_RPORT_T, str_init("force_rport") }, { ADD_LOCAL_RPORT_T, str_init("add_local_rport") }, { SET_ADV_ADDR_T, str_init("set_adv_addr") }, diff --git a/route.c b/route.c index 7990cfd1c..17c1b5690 100644 --- a/route.c +++ b/route.c @@ -663,8 +663,6 @@ int fix_actions(struct action* a) case FORWARD_TCP_T: case FORWARD_SCTP_T: case FORWARD_UDP_T: - case SEND_T: - case SEND_TCP_T: switch(t->val[0].type){ case IP_ST: tmp=strdup(ip_addr2a( diff --git a/route_struct.c b/route_struct.c index d2dee058f..b46b1b7ed 100644 --- a/route_struct.c +++ b/route_struct.c @@ -371,12 +371,6 @@ void print_action(struct action* t) case FORWARD_UDP_T: DBG("forward_udp("); break; - case SEND_T: - DBG("send("); - break; - case SEND_TCP_T: - DBG("send_tcp("); - break; case DROP_T: DBG("drop("); break; diff --git a/route_struct.h b/route_struct.h index b176b9ce5..e56f4c0fd 100644 --- a/route_struct.h +++ b/route_struct.h @@ -79,7 +79,7 @@ enum _expr_l_type{ SNDAF_O, RETCODE_O, SELECT_O, PVAR_O, RVEXP_O, SELECT_UNFIXED_O}; /* action types */ enum action_type{ - FORWARD_T=1, SEND_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T, + FORWARD_T=1, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T, SET_HOST_T, SET_HOSTPORT_T, SET_USER_T, SET_USERPASS_T, SET_PORT_T, SET_URI_T, SET_HOSTPORTTRANS_T, SET_HOSTALL_T, SET_USERPHONE_T, @@ -100,7 +100,6 @@ enum action_type{ FORWARD_UDP_T, FORWARD_TLS_T, FORWARD_SCTP_T, - SEND_TCP_T, FORCE_RPORT_T, ADD_LOCAL_RPORT_T, SET_ADV_ADDR_T,