Call Flow: print non standard response code texts

This commit is contained in:
Kaian 2016-01-29 14:22:08 +01:00
parent b908f44bd3
commit 207044b043
4 changed files with 27 additions and 25 deletions

View File

@ -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 *

View File

@ -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

View File

@ -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);

View File

@ -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