diff --git a/src/modules/siptrace/siptrace.c b/src/modules/siptrace/siptrace.c index 1519d49a7a5..77b7978f85f 100644 --- a/src/modules/siptrace/siptrace.c +++ b/src/modules/siptrace/siptrace.c @@ -90,7 +90,8 @@ static int w_sip_trace0(struct sip_msg *, char *p1, char *p2); static int w_sip_trace1(struct sip_msg *, char *dest, char *p2); static int w_sip_trace2(struct sip_msg *, char *dest, char *correlation_id); static int w_sip_trace3(struct sip_msg *, char *dest, char *correlation_id, char *trace_type); -static int w_sip_trace_msg(sip_msg_t *msg, char *dest, char *correlation_id, char *vmsg); +static int w_sip_trace_msg(sip_msg_t *msg, char *vmsg, char *saddr, char *taddr, + char *duri, char *corrid); static int fixup_siptrace(void **param, int param_no); static int fixup_free_siptrace(void **param, int param_no); static int w_sip_trace_mode(sip_msg_t *msg, char *pmode, char *p2); @@ -217,7 +218,7 @@ static cmd_export_t cmds[] = { ANY_ROUTE}, {"sip_trace", (cmd_function)w_sip_trace3, 3, fixup_siptrace, fixup_free_siptrace, ANY_ROUTE}, - {"sip_trace_msg", (cmd_function)w_sip_trace_msg, 3, fixup_spve_all, fixup_free_spve_all, + {"sip_trace_msg", (cmd_function)w_sip_trace_msg, 5, fixup_spve_all, fixup_free_spve_all, ANY_ROUTE}, {"hlog", (cmd_function)w_hlog1, 1, fixup_spve_null, 0, ANY_ROUTE}, @@ -1169,62 +1170,59 @@ static int w_sip_trace3(sip_msg_t *msg, char *dest, char *correlation_id, char * /** * */ -static int w_sip_trace_msg(sip_msg_t *msg, char *dest, char *correlation_id, char *vmsg) +static int w_sip_trace_msg(sip_msg_t *msg, char *vmsg, char *saddr, char *taddr, + char *duri, char *corrid) { str vmsg_str = {0, 0}; - sip_msg_t *nmsg = NULL; - sip_msg_t tmsg; - char tbuf[BUF_SIZE]; - int ret; - - if (vmsg) { - if(fixup_get_svalue(msg, (gparam_t*)vmsg, &vmsg_str) != 0) { - LM_ERR("unable to parse the msg data parameter\n"); + str saddr_str = {0, 0}; + str taddr_str = {0, 0}; + str duri_str = {0, 0}; + str corrid_str = {0, 0}; + dest_info_t dest; + + if(fixup_get_svalue(msg, (gparam_t*)vmsg, &vmsg_str) != 0) { + LM_ERR("unable to get the msg data parameter\n"); + return -1; + } + if(vmsg_str.s==NULL || vmsg_str.len<=0) { + LM_ERR("invalid msg data parameter\n"); + return -1; + } + if(fixup_get_svalue(msg, (gparam_t*)saddr, &saddr_str) != 0) { + LM_ERR("unable to get the msg source address parameter\n"); + return -1; + } + if(saddr_str.s==NULL || saddr_str.len<=0) { + LM_ERR("invalid msg source address parameter\n"); + return -1; + } + if(fixup_get_svalue(msg, (gparam_t*)taddr, &taddr_str) != 0) { + LM_ERR("unable to get the msg target address parameter\n"); + return -1; + } + if(taddr_str.s==NULL || taddr_str.len<=0) { + LM_ERR("invalid msg target address parameter\n"); + return -1; + } + if(duri!=NULL) { + if(fixup_get_svalue(msg, (gparam_t*)duri, &duri_str) != 0) { + LM_ERR("unable to get mirroring destination uri parameter\n"); return -1; } - memset(&tmsg, 0, sizeof(sip_msg_t)); - memcpy(tbuf, vmsg_str.s, vmsg_str.len); - tbuf[vmsg_str.len] = 0; - tmsg.buf = tbuf; - tmsg.len = vmsg_str.len; - if (parse_msg(tmsg.buf, tmsg.len, &tmsg)!=0) { - LM_ERR("parse msg failed\n"); + if (siptrace_parse_uri(&duri_str, &dest) < 0) { + LM_ERR("failed to parse mirroring destination uri\n"); return -1; } - if (parse_headers(msg, HDR_EOH_F, 0)==-1) { - LM_DBG("parsing headers failed [[%.*s]]\n", - msg->len, msg->buf); - goto error; - } - - if(parse_from_header(msg)<0) { - LM_ERR("cannot parse FROM header\n"); - goto error; - } - - if(parse_to_header(msg)<0 || msg->to==NULL) { - LM_ERR("cannot parse TO header\n"); - goto error; - } - tmsg.id = msg->id; - tmsg.pid = msg->pid; - tmsg.rcv = msg->rcv; - nmsg = &tmsg; - } else { - nmsg = msg; } - - ret = w_sip_trace3(nmsg, dest, correlation_id, NULL); - - if(nmsg != msg) { - free_sip_msg(&tmsg); + if(corrid!=NULL && fixup_get_svalue(msg, (gparam_t*)corrid, &corrid_str) != 0) { + LM_ERR("unable to get correlation id parameter\n"); + return -1; } - return ret; + trace_send_hep_duplicate(&vmsg_str, &saddr_str, &taddr_str, (duri)?&dest:NULL, + (corrid)?&corrid_str:NULL); -error: - free_sip_msg(&tmsg); - return -1; + return 1; } /**