From 207044b0435b91069e1f99a6f64322ad545c6a0d Mon Sep 17 00:00:00 2001 From: Kaian Date: Fri, 29 Jan 2016 14:22:08 +0100 Subject: [PATCH] Call Flow: print non standard response code texts --- src/sip.c | 42 +++++++++++++++++++++++------------------- src/sip.h | 2 +- src/sip_msg.c | 6 +----- src/sip_msg.h | 2 ++ 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/sip.c b/src/sip.c index 225ce3e..2d6b5d0 100644 --- a/src/sip.c +++ b/src/sip.c @@ -410,12 +410,17 @@ int sip_get_msg_reqresp(sip_msg_t *msg, const u_char *payload) { regmatch_t pmatch[3]; - char reqresp[20]; + char resp_str[40]; + char reqresp[40]; + const char *resp_def; + + // Initialize variables + memset(pmatch, 0, sizeof(pmatch)); + memset(resp_str, 0, sizeof(resp_str)); + memset(reqresp, 0, sizeof(reqresp)); // If not already parsed if (!msg->reqresp) { - // Initialize variables - memset(reqresp, 0, sizeof(reqresp)); // Method & CSeq if (regexec(&calls.reg_method, (const char *)payload, 2, pmatch, 0) == 0) { @@ -424,35 +429,34 @@ sip_get_msg_reqresp(sip_msg_t *msg, const u_char *payload) // Response code if (regexec(&calls.reg_response, (const char *)payload, 3, pmatch, 0) == 0) { + sprintf(resp_str, "%.*s", (int)(pmatch[1].rm_eo - pmatch[1].rm_so), payload + pmatch[1].rm_so); sprintf(reqresp, "%.*s", (int)(pmatch[2].rm_eo - pmatch[2].rm_so), payload + pmatch[2].rm_so); } // Get Request/Response Code msg->reqresp = sip_method_from_str(reqresp); + + // For response codes, check if the text matches the default + if (!msg_is_request(msg)) { + resp_def = sip_method_str(msg->reqresp); + if (!resp_def || strcmp(resp_def, resp_str)) { + msg->resp_str = strdup(resp_str); + } + } } return msg->reqresp; } const char * -sip_get_response_str(sip_msg_t *msg, char *out) +sip_get_msg_reqresp_str(sip_msg_t *msg) { - regmatch_t pmatch[3]; - const char *payload; - - // If not already parsed - if (msg_is_request(msg)) - return NULL; - - // Get message payload - payload = msg_get_payload(msg); - - // Response code (full text) - if (regexec(&calls.reg_response, payload, 3, pmatch, 0) == 0) { - sprintf(out, "%.*s", (int)(pmatch[1].rm_eo - pmatch[1].rm_so), payload + pmatch[1].rm_so); + // Check if code has non-standard text + if (msg->resp_str) { + return msg->resp_str; + } else { + return sip_method_str(msg->reqresp); } - - return out; } sip_msg_t * diff --git a/src/sip.h b/src/sip.h index ce8648d..5dcad8b 100644 --- a/src/sip.h +++ b/src/sip.h @@ -256,7 +256,7 @@ sip_get_msg_reqresp(sip_msg_t *msg, const u_char *payload); * */ const char * -sip_get_response_str(sip_msg_t *msg, char *out); +sip_get_msg_reqresp_str(sip_msg_t *msg); /** * @brief Parse SIP Message payload if not parsed diff --git a/src/sip_msg.c b/src/sip_msg.c index 4886308..3584d86 100644 --- a/src/sip_msg.c +++ b/src/sip_msg.c @@ -123,11 +123,7 @@ msg_get_attribute(sip_msg_t *msg, int id, char *value) sprintf(value, "%s:%u", msg->packet->dst.ip, msg->packet->dst.port); break; case SIP_ATTR_METHOD: - if (sip_method_str(msg->reqresp)) { - sprintf(value, "%s", sip_method_str(msg->reqresp)); - } else { - sip_get_response_str(msg, value); - } + sprintf(value, "%s", sip_get_msg_reqresp_str(msg)); break; case SIP_ATTR_SIPFROM: sprintf(value, "%s", msg->sip_from); diff --git a/src/sip_msg.h b/src/sip_msg.h index e4babfa..aafbfae 100644 --- a/src/sip_msg.h +++ b/src/sip_msg.h @@ -52,6 +52,8 @@ struct sip_call; struct sip_msg { //! Request Method or Response Code @see sip_methods int reqresp; + //! Response text if it doesn't matches an standard + char *resp_str; //! Message Cseq uint32_t cseq; //! SIP From Header