int db_nkeys, char *dtext)
{
LM_DBG("storing info - %s\n", dtext);
- if(trace_db_mode = 2 && db_funcs.insert_async != NULL) {
+ if(trace_db_mode == 2 && db_funcs.insert_async != NULL) {
if(db_funcs.insert_async(db_con, db_keys, db_vals, db_nkeys) < 0) {
LM_ERR("error storing trace - async - %s\n", dtext);
return -1;
}
- } else if(trace_db_mode != 1 && db_funcs.insert_delayed != NULL) {
+ } else if(trace_db_mode == 1 && db_funcs.insert_delayed != NULL) {
if(db_funcs.insert_delayed(db_con, db_keys, db_vals, db_nkeys) < 0) {
LM_ERR("error storing trace - delayed - %s\n", dtext);
return -1;
}
if (msg->first_line.type != SIP_REQUEST ||
- (trace_type == SIPTRACE_DIALOG && msg->first_line.u.request.method_value != METHOD_INVITE)) {
+ (trace_type == SIPTRACE_DIALOG
+ && msg->first_line.u.request.method_value != METHOD_INVITE)) {
LM_WARN("When tracing a %s sip_trace() has to be initiated on the %s\n",
trace_type == SIPTRACE_TRANSACTION ? "transaction" : "dialog",
trace_type == SIPTRACE_TRANSACTION ? "request message" : "initial invite");
} else {
/* serialize what's in info */
/* save correlation id in siptrace_info avp
- * we want to have traced user avp value at the moment of sip_trace function call*/
+ * we want to have traced user avp value at the moment
+ * of sip_trace function call */
if (trace_add_info_xavp(info) < 0) {
LM_ERR("failed to serialize siptrace info! Won't trace dialog!\n");
return -1;
}
/**
- * Send sip trace with destination and correlation id and specify what messages to be traced
+ * Send sip trace with destination and correlation id
+ * and specify what messages to be traced
*/
static int ki_sip_trace_dst_cid_flag(sip_msg_t *msg, str *duri, str *cid, str* sflag)
{
(correlation_id)?&correlation_id_str:NULL, NULL, trace_type);
}
+/**
+ * link call-id, method, from-tag and to-tag
+ */
+static int sip_trace_msg_attrs(sip_msg_t *msg, siptrace_data_t *sto)
+{
+ if(sip_trace_prepare(msg) < 0) {
+ return -1;
+ }
+
+ sto->callid = msg->callid->body;
+
+ if(msg->first_line.type == SIP_REQUEST) {
+ sto->method = msg->first_line.u.request.method;
+ } else {
+ sto->method = get_cseq(msg)->method;
+ }
+
+ sto->fromtag = get_from(msg)->tag_value;
+ sto->totag = get_to(msg)->tag_value;
+
+ return 0;
+
+}
+
static int sip_trace(sip_msg_t *msg, dest_info_t *dst,
str *correlation_id_str, char *dir)
{
return -1;
}
- if(sip_trace_prepare(msg) < 0)
+ if(sip_trace_msg_attrs(msg, &sto) < 0) {
return -1;
-
- sto.callid = msg->callid->body;
-
- if(msg->first_line.type == SIP_REQUEST) {
- sto.method = msg->first_line.u.request.method;
- } else {
- if(parse_headers(msg, HDR_CSEQ_F, 0) != 0 || msg->cseq == NULL
- || msg->cseq->parsed == NULL) {
- LM_ERR("cannot parse cseq header\n");
- return -1;
- }
- sto.method = get_cseq(msg)->method;
}
if(msg->first_line.type == SIP_REPLY) {
sto.dir = "out";
}
- sto.fromtag = get_from(msg)->tag_value;
- sto.totag = get_to(msg)->tag_value;
-
#ifdef STATISTICS
if(msg->first_line.type == SIP_REPLY) {
sto.stat = siptrace_rpl;
}
}
- /* for incoming cancel this is the only play(i've found) where I have the CANCEL transaction
- * and can register a callback for the reply */
+ /* for incoming cancel this is the only place where can get the CANCEL
+ * transaction and can register a callback for the reply */
memset(&sto, 0, sizeof(siptrace_data_t));
if(traced_user_avp.n != 0)
return;
}
- if(sip_trace_prepare(msg) < 0)
+ if(sip_trace_msg_attrs(msg, &sto) < 0) {
return;
+ }
if(ps->send_buf.len > 0) {
sto.body = ps->send_buf;
sto.body.len = sizeof("No request buffer") - 1;
}
- sto.callid = msg->callid->body;
-
if(ps->send_buf.len > 10) {
sto.method.s = ps->send_buf.s;
sto.method.len = 0;
sto.dir = "out";
}
- sto.fromtag = get_from(msg)->tag_value;
- sto.totag = get_to(msg)->tag_value;
-
#ifdef STATISTICS
sto.stat = siptrace_req;
#endif
return;
}
- if(sip_trace_prepare(msg) < 0)
+ if(sip_trace_msg_attrs(msg, &sto) < 0) {
return;
+ }
sto.body.s = msg->buf;
sto.body.len = msg->len;
- sto.callid = msg->callid->body;
-
- sto.method = get_cseq(msg)->method;
-
sto.status.s = int2strbuf(ps->code, statusbuf, INT2STR_MAX_LEN, &sto.status.len);
if(sto.status.s == 0) {
LM_ERR("failure to get the status string\n");
sto.dir = "in";
- sto.fromtag = get_from(msg)->tag_value;
- sto.totag = get_to(msg)->tag_value;
#ifdef STATISTICS
sto.stat = siptrace_rpl;
#endif
if (info->uriState == STRACE_RAW_URI) {
- LM_BUG("uriState must be either UNUSED or PARSED here! must be a bug! Message won't be traced!\n");
+ LM_BUG("uriState must be either UNUSED or PARSED here - skip tracing!\n");
return;
}
- sip_trace_store(&sto, info->uriState == STRACE_PARSED_URI ? &info->u.dest_info : NULL, NULL);
+ sip_trace_store(&sto, (info->uriState == STRACE_PARSED_URI)
+ ? &info->u.dest_info : NULL, NULL);
return;
}
faked = 1;
}
- if(sip_trace_prepare(msg) < 0)
+ if(sip_trace_msg_attrs(msg, &sto) < 0) {
return;
+ }
if(faked == 0) {
if(ps->send_buf.len > 0) {
}
}
- sto.callid = msg->callid->body;
- sto.method = get_cseq(msg)->method;
-
if(trace_local_ip.s && trace_local_ip.len > 0) {
sto.fromip = trace_local_ip;
} else {
}
sto.dir = "out";
- sto.fromtag = get_from(msg)->tag_value;
- sto.totag = get_to(msg)->tag_value;
#ifdef STATISTICS
sto.stat = siptrace_rpl;
msg = req;
- if(sip_trace_prepare(msg) < 0)
+ if(sip_trace_msg_attrs(msg, &sto) < 0) {
return;
+ }
sto.body.s = (slcbp->reply) ? slcbp->reply->s : "";
sto.body.len = (slcbp->reply) ? slcbp->reply->len : 0;
- sto.callid = msg->callid->body;
- sto.method = msg->first_line.u.request.method;
-
if(trace_local_ip.len > 0) {
sto.fromip = trace_local_ip;
} else {
}
sto.dir = "out";
- sto.fromtag = get_from(msg)->tag_value;
- sto.totag = get_to(msg)->tag_value;
#ifdef STATISTICS
sto.stat = siptrace_rpl;
goto afterdb;
}
- if(sip_trace_prepare(&tmsg) < 0) {
+ if(sip_trace_msg_attrs(&tmsg, &sto) < 0) {
free_sip_msg(&tmsg);
goto afterdb;
}
- sto.callid = tmsg.callid->body;
- if(tmsg.first_line.type == SIP_REQUEST) {
- sto.method = tmsg.first_line.u.request.method;
- } else {
- sto.method = get_cseq(&tmsg)->method;
- }
-
if(tmsg.first_line.type == SIP_REPLY) {
sto.status = tmsg.first_line.u.reply.status;
} else {
sto.status.s = "";
sto.status.len = 0;
}
- sto.fromtag = get_from(&tmsg)->tag_value;
- sto.totag = get_to(&tmsg)->tag_value;
gettimeofday(&sto.tv, NULL);
sip_trace_store_db(&sto);
goto afterdb;
}
- if(sip_trace_prepare(&tmsg) < 0) {
+ if(sip_trace_msg_attrs(&tmsg, &sto) < 0) {
free_sip_msg(&tmsg);
goto afterdb;
}
- sto.callid = tmsg.callid->body;
- if(tmsg.first_line.type == SIP_REQUEST) {
- sto.method = tmsg.first_line.u.request.method;
- } else {
- sto.method = get_cseq(&tmsg)->method;
- }
-
if(tmsg.first_line.type == SIP_REPLY) {
sto.status = tmsg.first_line.u.reply.status;
} else {
sto.status.s = "";
sto.status.len = 0;
}
- sto.fromtag = get_from(&tmsg)->tag_value;
- sto.totag = get_to(&tmsg)->tag_value;
gettimeofday(&sto.tv, NULL);
sip_trace_store_db(&sto);