Rework message and call attribute storage

Most of the attributes (displayed data in columns in CallList) can
be obtained from payload or packet header. Avoiding data duplication
reduces a lot memory consumption and parsing speedup.

All attributes are now calculated when required, so the parsing
proccess is also faster.
This commit is contained in:
Kaian 2015-09-22 11:55:40 +02:00
parent 02ad96f987
commit 34428e87c3
14 changed files with 746 additions and 391 deletions

347
compile Executable file
View File

@ -0,0 +1,347 @@
#! /bin/sh
# Wrapper for compilers which do not understand '-c -o'.
scriptversion=2012-10-14.11; # UTC
# Copyright (C) 1999-2014 Free Software Foundation, Inc.
# Written by Tom Tromey <tromey@cygnus.com>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a
# configuration script generated by Autoconf, you may include it under
# the same distribution terms that you use for the rest of that program.
# This file is maintained in Automake, please report
# bugs to <bug-automake@gnu.org> or send patches to
# <automake-patches@gnu.org>.
nl='
'
# We need space, tab and new line, in precisely that order. Quoting is
# there to prevent tools from complaining about whitespace usage.
IFS=" "" $nl"
file_conv=
# func_file_conv build_file lazy
# Convert a $build file to $host form and store it in $file
# Currently only supports Windows hosts. If the determined conversion
# type is listed in (the comma separated) LAZY, no conversion will
# take place.
func_file_conv ()
{
file=$1
case $file in
/ | /[!/]*) # absolute file, and not a UNC file
if test -z "$file_conv"; then
# lazily determine how to convert abs files
case `uname -s` in
MINGW*)
file_conv=mingw
;;
CYGWIN*)
file_conv=cygwin
;;
*)
file_conv=wine
;;
esac
fi
case $file_conv/,$2, in
*,$file_conv,*)
;;
mingw/*)
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
;;
cygwin/*)
file=`cygpath -m "$file" || echo "$file"`
;;
wine/*)
file=`winepath -w "$file" || echo "$file"`
;;
esac
;;
esac
}
# func_cl_dashL linkdir
# Make cl look for libraries in LINKDIR
func_cl_dashL ()
{
func_file_conv "$1"
if test -z "$lib_path"; then
lib_path=$file
else
lib_path="$lib_path;$file"
fi
linker_opts="$linker_opts -LIBPATH:$file"
}
# func_cl_dashl library
# Do a library search-path lookup for cl
func_cl_dashl ()
{
lib=$1
found=no
save_IFS=$IFS
IFS=';'
for dir in $lib_path $LIB
do
IFS=$save_IFS
if $shared && test -f "$dir/$lib.dll.lib"; then
found=yes
lib=$dir/$lib.dll.lib
break
fi
if test -f "$dir/$lib.lib"; then
found=yes
lib=$dir/$lib.lib
break
fi
if test -f "$dir/lib$lib.a"; then
found=yes
lib=$dir/lib$lib.a
break
fi
done
IFS=$save_IFS
if test "$found" != yes; then
lib=$lib.lib
fi
}
# func_cl_wrapper cl arg...
# Adjust compile command to suit cl
func_cl_wrapper ()
{
# Assume a capable shell
lib_path=
shared=:
linker_opts=
for arg
do
if test -n "$eat"; then
eat=
else
case $1 in
-o)
# configure might choose to run compile as 'compile cc -o foo foo.c'.
eat=1
case $2 in
*.o | *.[oO][bB][jJ])
func_file_conv "$2"
set x "$@" -Fo"$file"
shift
;;
*)
func_file_conv "$2"
set x "$@" -Fe"$file"
shift
;;
esac
;;
-I)
eat=1
func_file_conv "$2" mingw
set x "$@" -I"$file"
shift
;;
-I*)
func_file_conv "${1#-I}" mingw
set x "$@" -I"$file"
shift
;;
-l)
eat=1
func_cl_dashl "$2"
set x "$@" "$lib"
shift
;;
-l*)
func_cl_dashl "${1#-l}"
set x "$@" "$lib"
shift
;;
-L)
eat=1
func_cl_dashL "$2"
;;
-L*)
func_cl_dashL "${1#-L}"
;;
-static)
shared=false
;;
-Wl,*)
arg=${1#-Wl,}
save_ifs="$IFS"; IFS=','
for flag in $arg; do
IFS="$save_ifs"
linker_opts="$linker_opts $flag"
done
IFS="$save_ifs"
;;
-Xlinker)
eat=1
linker_opts="$linker_opts $2"
;;
-*)
set x "$@" "$1"
shift
;;
*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
func_file_conv "$1"
set x "$@" -Tp"$file"
shift
;;
*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
func_file_conv "$1" mingw
set x "$@" "$file"
shift
;;
*)
set x "$@" "$1"
shift
;;
esac
fi
shift
done
if test -n "$linker_opts"; then
linker_opts="-link$linker_opts"
fi
exec "$@" $linker_opts
exit 1
}
eat=
case $1 in
'')
echo "$0: No command. Try '$0 --help' for more information." 1>&2
exit 1;
;;
-h | --h*)
cat <<\EOF
Usage: compile [--help] [--version] PROGRAM [ARGS]
Wrapper for compilers which do not understand '-c -o'.
Remove '-o dest.o' from ARGS, run PROGRAM with the remaining
arguments, and rename the output as expected.
If you are trying to build a whole package this is not the
right script to run: please start by reading the file 'INSTALL'.
Report bugs to <bug-automake@gnu.org>.
EOF
exit $?
;;
-v | --v*)
echo "compile $scriptversion"
exit $?
;;
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
func_cl_wrapper "$@" # Doesn't return...
;;
esac
ofile=
cfile=
for arg
do
if test -n "$eat"; then
eat=
else
case $1 in
-o)
# configure might choose to run compile as 'compile cc -o foo foo.c'.
# So we strip '-o arg' only if arg is an object.
eat=1
case $2 in
*.o | *.obj)
ofile=$2
;;
*)
set x "$@" -o "$2"
shift
;;
esac
;;
*.c)
cfile=$1
set x "$@" "$1"
shift
;;
*)
set x "$@" "$1"
shift
;;
esac
fi
shift
done
if test -z "$ofile" || test -z "$cfile"; then
# If no '-o' option was seen then we might have been invoked from a
# pattern rule where we don't need one. That is ok -- this is a
# normal compilation that the losing compiler can handle. If no
# '.c' file was seen then we are probably linking. That is also
# ok.
exec "$@"
fi
# Name of file we expect compiler to create.
cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
# Create the lock directory.
# Note: use '[/\\:.-]' here to ensure that we don't use the same name
# that we are using for the .o file. Also, base the name on the expected
# object file name, since that is what matters with a parallel build.
lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
while true; do
if mkdir "$lockdir" >/dev/null 2>&1; then
break
fi
sleep 1
done
# FIXME: race condition here if user kills between mkdir and trap.
trap "rmdir '$lockdir'; exit 1" 1 2 15
# Run the compile.
"$@"
ret=$?
if test -f "$cofile"; then
test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
elif test -f "${cofile}bj"; then
test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
fi
rmdir "$lockdir"
exit $ret
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-time-zone: "UTC"
# time-stamp-end: "; # UTC"
# End:

View File

@ -95,8 +95,7 @@ int
filter_check_call(void *item)
{
int i;
const char *data;
char linetext[256];
char data[256];
sip_call_t *call = (sip_call_t*) item;
// Filter for this call has already be processed
@ -112,27 +111,29 @@ filter_check_call(void *item)
if (!filters[i].expr)
continue;
// Initialize
memset(data, 0, sizeof(data));
// Get filtered field
switch(i) {
case FILTER_SIPFROM:
data = call_get_attribute(call, SIP_ATTR_SIPFROM);
call_get_attribute(call, SIP_ATTR_SIPFROM, data);
break;
case FILTER_SIPTO:
data = call_get_attribute(call, SIP_ATTR_SIPTO);
call_get_attribute(call, SIP_ATTR_SIPTO, data);
break;
case FILTER_SOURCE:
data = call_get_attribute(call, SIP_ATTR_SRC);
call_get_attribute(call, SIP_ATTR_SRC, data);
break;
case FILTER_DESTINATION:
data = call_get_attribute(call, SIP_ATTR_DST);
call_get_attribute(call, SIP_ATTR_DST, data);
break;
case FILTER_METHOD:
data = call_get_attribute(call, SIP_ATTR_METHOD);
call_get_attribute(call, SIP_ATTR_METHOD, data);
break;
case FILTER_CALL_LIST:
// FIXME Maybe call should know hot to calculate this line
memset(linetext, 0, sizeof(linetext));
data = call_list_line_text(ui_get_panel(ui_find_by_type(PANEL_CALL_LIST)), call, linetext);
call_list_line_text(ui_get_panel(ui_find_by_type(PANEL_CALL_LIST)), call, data);
break;
default:
// Unknown filter id

246
src/sip.c
View File

@ -49,6 +49,96 @@
sip_call_list_t calls =
{ 0 };
/* @brief list of methods and responses */
sip_code_t sip_codes[] = {
{ SIP_METHOD_REGISTER, "REGISTER" },
{ SIP_METHOD_INVITE, "INVITE" },
{ SIP_METHOD_SUBSCRIBE, "SUBSCRIBE" },
{ SIP_METHOD_NOTIFY, "NOTIFY" },
{ SIP_METHOD_OPTIONS, "OPTIONS" },
{ SIP_METHOD_PUBLISH, "PUBLISH" },
{ SIP_METHOD_MESSAGE, "MESSAGE" },
{ SIP_METHOD_CANCEL, "CANCEL" },
{ SIP_METHOD_BYE, "BYE" },
{ SIP_METHOD_ACK, "ACK" },
{ SIP_METHOD_PRACK, "PRACK" },
{ SIP_METHOD_INFO, "INFO" },
{ SIP_METHOD_REFER, "REFER" },
{ SIP_METHOD_UPDATE, "UPDATE" },
{ 100, "100 Trying" },
{ 180, "180 Ringing" },
{ 181, "181 Call is Being Forwarded" },
{ 182, "182 Queued" },
{ 183, "183 Session Progress" },
{ 199, "199 Early Dialog Terminated" },
{ 200, "200 OK" },
{ 202, "202 Accepted" },
{ 204, "204 No Notification" },
{ 300, "300 Multiple Choices" },
{ 301, "301 Moved Permanently" },
{ 302, "302 Moved Temporarily" },
{ 305, "305 Use Proxy" },
{ 380, "380 Alternative Service" },
{ 400, "400 Bad Request" },
{ 401, "401 Unauthorized" },
{ 402, "402 Payment Required" },
{ 403, "403 Forbidden" },
{ 404, "404 Not Found" },
{ 405, "405 Method Not Allowed" },
{ 406, "406 Not Acceptable" },
{ 407, "407 Proxy Authentication Required" },
{ 408, "408 Request Timeout" },
{ 409, "409 Conflict" },
{ 410, "410 Gone" },
{ 411, "411 Length Required" },
{ 412, "412 Conditional Request Failed" },
{ 413, "413 Request Entity Too Large" },
{ 414, "414 Request-URI Too Long" },
{ 415, "415 Unsupported Media Type" },
{ 416, "416 Unsupported URI Scheme" },
{ 417, "417 Unknown Resource-Priority" },
{ 420, "420 Bad Extension" },
{ 421, "421 Extension Required" },
{ 422, "422 Session Interval Too Small" },
{ 423, "423 Interval Too Brief" },
{ 424, "424 Bad Location Information" },
{ 428, "428 Use Identity Header" },
{ 429, "429 Provide Referrer Identity" },
{ 430, "430 Flow Failed" },
{ 433, "433 Anonymity Disallowed" },
{ 436, "436 Bad Identity-Info" },
{ 437, "437 Unsupported Certificate" },
{ 438, "438 Invalid Identity Header" },
{ 439, "439 First Hop Lacks Outbound Support" },
{ 470, "470 Consent Needed" },
{ 480, "480 Temporarily Unavailable" },
{ 481, "481 Call/Transaction Does Not Exist" },
{ 482, "482 Loop Detected." },
{ 483, "483 Too Many Hops" },
{ 484, "484 Address Incomplete" },
{ 485, "485 Ambiguous" },
{ 486, "486 Busy Here" },
{ 487, "487 Request Terminated" },
{ 488, "488 Not Acceptable Here" },
{ 489, "489 Bad Event" },
{ 491, "491 Request Pending" },
{ 493, "493 Undecipherable" },
{ 494, "494 Security Agreement Required" },
{ 500, "500 Server Internal Error" },
{ 501, "501 Not Implemented" },
{ 502, "502 Bad Gateway" },
{ 503, "503 Service Unavailable" },
{ 504, "504 Server Time-out" },
{ 505, "505 Version Not Supported" },
{ 513, "513 Message Too Large" },
{ 580, "580 Precondition Failure" },
{ 600, "600 Busy Everywhere" },
{ 603, "603 Decline" },
{ 604, "604 Does Not Exist Anywhere" },
{ 606, "606 Not Acceptable" },
{ -1 , NULL },
};
void
sip_init(int limit, int only_calls, int no_incomplete)
{
@ -117,9 +207,9 @@ sip_get_callid(const char* payload, char *callid)
// Try to get Call-ID from payload
if (regexec(&calls.reg_callid, payload, 3, pmatch, 0) == 0) {
// Allocate memory for Call-Id (caller MUST free it)
memset(callid, 0, pmatch[2].rm_eo - pmatch[2].rm_so + 1);
memset(callid, 0, (int)pmatch[2].rm_eo - pmatch[2].rm_so + 1);
// Copy the matching part of payload
strncpy(callid, payload + pmatch[2].rm_so, pmatch[2].rm_eo - pmatch[2].rm_so);
strncpy(callid, payload + pmatch[2].rm_so, (int) pmatch[2].rm_eo - pmatch[2].rm_so);
}
return callid;
@ -131,7 +221,6 @@ sip_load_message(capture_packet_t *packet, const char *src, u_short sport, const
ENTRY entry;
sip_msg_t *msg;
sip_call_t *call;
int call_idx;
char callid[1024];
char msg_src[ADDRESSLEN];
char msg_dst[ADDRESSLEN];
@ -188,18 +277,15 @@ sip_load_message(capture_packet_t *packet, const char *src, u_short sport, const
goto skip_message;
// Store this call in hash table
entry.key = (char *) call_get_attribute(call, SIP_ATTR_CALLID);
entry.key = (char *) call->callid;
entry.data = (void *) call;
hsearch(entry, ENTER);
// Append this call to the call list
pthread_mutex_lock(&calls.lock);
vector_append(calls.list, call);
call_idx = vector_count(calls.list);
call->index = vector_count(calls.list);
pthread_mutex_unlock(&calls.lock);
// Store current call Index
call_set_attribute(call, SIP_ATTR_CALLINDEX, "%d", call_idx);
}
// Store sorce address. Prefix too long IPv6 addresses with two dots
@ -216,25 +302,25 @@ sip_load_message(capture_packet_t *packet, const char *src, u_short sport, const
strcpy(msg_dst, dst);
}
// Set Source and Destination attributes
msg_set_attribute(msg, SIP_ATTR_SRC, "%s:%u", msg_src, sport);
msg_set_attribute(msg, SIP_ATTR_DST, "%s:%u", msg_dst, dport);
// Add this SIP packet to the message
// At this point we know we're handling an interesting SIP Packet
msg->packet = packet;
// Add the message to the call
call_add_message(call, msg);
// Always parse first call message
if (call_msg_count(call) == 1 || call_is_invite(call)) {
if (call_msg_count(call) == 1) {
// Parse SIP payload
sip_parse_msg_payload(msg, payload);
}
if (call_is_invite(call)) {
// Parse media data
sip_parse_msg_media(msg, payload);
// Update Call State
call_update_state(call, msg);
}
pthread_mutex_unlock(&calls.lock);
// Return the loaded message
return msg;
@ -294,14 +380,13 @@ sip_find_by_callid(const char *callid)
sip_call_t *
sip_find_by_xcallid(const char *xcallid)
{
const char *cur_xcallid;
sip_call_t *cur;
int i;
//FIXME Iterator pls?
for (i=0; i < vector_count(calls.list); i++) {
cur = vector_item(calls.list, i);
cur_xcallid = call_get_attribute(cur, SIP_ATTR_XCALLID);
if (cur_xcallid && !strcmp(cur_xcallid, xcallid)) {
if (cur->xcallid && !strcmp(cur->xcallid, xcallid)) {
return cur;
}
}
@ -314,10 +399,10 @@ call_get_xcall(sip_call_t *call)
{
sip_call_t *xcall;
pthread_mutex_lock(&calls.lock);
if (call_get_attribute(call, SIP_ATTR_XCALLID)) {
xcall = sip_find_by_callid(call_get_attribute(call, SIP_ATTR_XCALLID));
if (call->xcallid) {
xcall = sip_find_by_callid(call->xcallid);
} else {
xcall = sip_find_by_xcallid(call_get_attribute(call, SIP_ATTR_CALLID));
xcall = sip_find_by_xcallid(call->callid);
}
pthread_mutex_unlock(&calls.lock);
return xcall;
@ -337,13 +422,10 @@ sip_get_msg_reqresp(sip_msg_t *msg, const u_char *payload)
// Method & CSeq
if (regexec(&calls.reg_method, (const char *)payload, 2, pmatch, 0) == 0) {
sprintf(reqresp, "%.*s", (int)(pmatch[1].rm_eo - pmatch[1].rm_so), payload + pmatch[1].rm_so);
msg_set_attribute(msg, SIP_ATTR_METHOD, reqresp);
}
// Response code
if (regexec(&calls.reg_response, (const char *)payload, 3, pmatch, 0) == 0) {
msg_set_attribute(msg, SIP_ATTR_METHOD, "%.*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);
}
@ -367,7 +449,7 @@ int
sip_parse_msg_payload(sip_msg_t *msg, const u_char *payload)
{
regmatch_t pmatch[4];
char date[12], time[20], cseq[11];
char cseq[11];
// CSeq
if (regexec(&calls.reg_cseq, (char*)payload, 2, pmatch, 0) == 0) {
@ -375,41 +457,25 @@ sip_parse_msg_payload(sip_msg_t *msg, const u_char *payload)
msg->cseq = atoi(cseq);
}
// X-Call-Id
// X-Call-Id.
// TODO Move this from msg parse
if (!msg->call->xcallid) {
if (regexec(&calls.reg_xcallid, (const char *)payload, 3, pmatch, 0) == 0) {
msg_set_attribute(msg, SIP_ATTR_XCALLID, "%.*s", pmatch[2].rm_eo - pmatch[2].rm_so,
payload + pmatch[2].rm_so);
msg->call->xcallid = sng_malloc((int)pmatch[2].rm_eo - pmatch[2].rm_so + 1);
strncpy(msg->call->xcallid, (const char *)payload + pmatch[2].rm_so, (int)pmatch[2].rm_eo - pmatch[2].rm_so);
}
}
// From
if (regexec(&calls.reg_from, (const char *)payload, 4, pmatch, 0) == 0) {
msg_set_attribute(msg, SIP_ATTR_SIPFROM, "%.*s", pmatch[2].rm_eo - pmatch[2].rm_so,
payload + pmatch[2].rm_so);
msg_set_attribute(msg, SIP_ATTR_SIPFROMUSER, "%.*s", pmatch[3].rm_eo - pmatch[3].rm_so,
payload + pmatch[3].rm_so);
msg->sip_from = sng_malloc((int)pmatch[2].rm_eo - pmatch[2].rm_so + 1);
strncpy(msg->sip_from, (const char *)payload + pmatch[2].rm_so, (int)pmatch[2].rm_eo - pmatch[2].rm_so);
}
// To
if (regexec(&calls.reg_to, (const char *)payload, 4, pmatch, 0) == 0) {
msg_set_attribute(msg, SIP_ATTR_SIPTO, "%.*s", pmatch[2].rm_eo - pmatch[2].rm_so,
payload + pmatch[2].rm_so);
msg_set_attribute(msg, SIP_ATTR_SIPTOUSER, "%.*s", pmatch[3].rm_eo - pmatch[3].rm_so,
payload + pmatch[3].rm_so);
}
// Set message Date and Time attribute
msg_set_attribute(msg, SIP_ATTR_DATE, timeval_to_date(msg_get_time(msg), date));
msg_set_attribute(msg, SIP_ATTR_TIME, timeval_to_time(msg_get_time(msg), time));
// Store Transport attribute
if (msg->packet->type == CAPTURE_PACKET_SIP_UDP) {
msg_set_attribute(msg, SIP_ATTR_TRANSPORT, "UDP");
} else if (msg->packet->type == CAPTURE_PACKET_SIP_TCP) {
msg_set_attribute(msg, SIP_ATTR_TRANSPORT, "TCP");
} else if (msg->packet->type == CAPTURE_PACKET_SIP_TLS) {
msg_set_attribute(msg, SIP_ATTR_TRANSPORT, "TLS");
} else if (msg->packet->type == CAPTURE_PACKET_SIP_WS) {
msg_set_attribute(msg, SIP_ATTR_TRANSPORT, "WS");
msg->sip_to = sng_malloc((int)pmatch[2].rm_eo - pmatch[2].rm_so + 1);
strncpy(msg->sip_to, (const char *)payload + pmatch[2].rm_so, (int)pmatch[2].rm_eo - pmatch[2].rm_so);
}
return 0;
@ -474,13 +540,6 @@ sip_parse_msg_media(sip_msg_t *msg, const u_char *payload)
}
sng_free(tofree);
// If message has media
if ((media = vector_first(msg->medias))) {
msg_set_attribute(msg, SIP_ATTR_SDP_ADDRESS, media_get_address(media));
msg_set_attribute(msg, SIP_ATTR_SDP_PORT, "%d", media_get_port(media));
}
}
@ -553,11 +612,12 @@ sip_check_msg_ignore(sip_msg_t *msg)
{
int i;
sip_attr_hdr_t *header;
char value[512];
// Check if an ignore option exists
for (i = 0; i < SIP_ATTR_COUNT; i++) {
header = sip_attr_get_header(i);
if (is_ignored_value(header->name, msg_get_attribute(msg, header->id))) {
if (is_ignored_value(header->name, call_get_attribute(msg->call, header->id, value))) {
return 1;
}
}
@ -567,39 +627,31 @@ sip_check_msg_ignore(sip_msg_t *msg)
const char *
sip_method_str(enum sip_methods method)
{
switch (method) {
case SIP_METHOD_REGISTER:
return "REGISTER";
case SIP_METHOD_INVITE:
return "INVITE";
case SIP_METHOD_SUBSCRIBE:
return "SUBSCRIBE";
case SIP_METHOD_NOTIFY:
return "NOTIFY";
case SIP_METHOD_OPTIONS:
return "OPTIONS";
case SIP_METHOD_PUBLISH:
return "PUBLISH";
case SIP_METHOD_MESSAGE:
return "MESSAGE";
case SIP_METHOD_CANCEL:
return "CANCEL";
case SIP_METHOD_BYE:
return "BYE";
case SIP_METHOD_ACK:
return "ACK";
case SIP_METHOD_PRACK:
return "PRACK";
case SIP_METHOD_INFO:
return "INFO";
case SIP_METHOD_REFER:
return "REFER";
case SIP_METHOD_UPDATE:
return "UPDATE";
case SIP_METHOD_SENTINEL:
return "";
int i;
for (i = 0; sip_codes[i].id > 0; i++) {
if (method == sip_codes[i].id)
return sip_codes[i].text;
}
return NULL;
return "";
}
const char *
sip_transport_str(int transport)
{
switch(transport)
{
case CAPTURE_PACKET_SIP_UDP:
return "UDP";
case CAPTURE_PACKET_SIP_TCP:
return "TCP";
case CAPTURE_PACKET_SIP_TLS:
return "TLS";
case CAPTURE_PACKET_SIP_WS:
return "WS";
case CAPTURE_PACKET_SIP_WSS:
return "WSS";
}
return "";
}
int
@ -615,16 +667,16 @@ sip_method_from_str(const char *method)
char *
sip_get_msg_header(sip_msg_t *msg, char *out)
{
// Source and Destination address
char from_addr[80], to_addr[80];
char from_addr[80], to_addr[80], time[80], date[80];
// We dont use Message attributes here because it contains truncated data
// This should not overload too much as all results should be already cached
sprintf(from_addr, "%s", sip_address_port_format(SRC(msg)));
sprintf(to_addr, "%s", sip_address_port_format(DST(msg)));
// Source and Destination address
msg_get_attribute(msg, SIP_ATTR_DATE, date);
msg_get_attribute(msg, SIP_ATTR_TIME, time);
msg_get_attribute(msg, SIP_ATTR_SRC, from_addr);
msg_get_attribute(msg, SIP_ATTR_DST, to_addr);
// Get msg header
sprintf(out, "%s %s %s -> %s", DATE(msg), TIME(msg), from_addr, to_addr);
sprintf(out, "%s %s %s -> %s", date, time, from_addr, to_addr);
return out;
}

View File

@ -44,6 +44,37 @@
//! Shorter declaration of sip_call_list structure
typedef struct sip_call_list sip_call_list_t;
//! Shorter declaration of sip codes structure
typedef struct sip_code sip_code_t;
//! SIP Methods
enum sip_methods {
SIP_METHOD_REGISTER = 1,
SIP_METHOD_INVITE,
SIP_METHOD_SUBSCRIBE,
SIP_METHOD_NOTIFY,
SIP_METHOD_OPTIONS,
SIP_METHOD_PUBLISH,
SIP_METHOD_MESSAGE,
SIP_METHOD_CANCEL,
SIP_METHOD_BYE,
SIP_METHOD_ACK,
SIP_METHOD_PRACK,
SIP_METHOD_INFO,
SIP_METHOD_REFER,
SIP_METHOD_UPDATE,
SIP_METHOD_SENTINEL,
};
/**
* @brief Different Request/Response codes in SIP Protocol
*/
struct sip_code
{
int id;
const char *text;
};
/**
* @brief call structures head list
@ -276,6 +307,12 @@ sip_check_msg_ignore(struct sip_msg *msg);
const char *
sip_method_str(enum sip_methods method);
/*
* @brief Get String value of Transport
*/
const char *
sip_transport_str(int transport);
/**
* @brief Converts Request Name or Response code to number
*

View File

@ -116,58 +116,4 @@ sip_attr_from_name(const char *name)
return -1;
}
sip_attr_t *
sip_attr_create(enum sip_attr_id id, const char *value)
{
sip_attr_t *attr;
// Create a new attribute struct and store it
if (!(attr = sng_malloc(sizeof(sip_attr_t))))
return NULL;
attr->id = id;
attr->value = strdup(value);
return attr;
}
void
sip_attr_destroy(sip_attr_t *attr)
{
sng_free(attr->value);
sng_free(attr);
}
void
sip_attr_destroyer(void *attr)
{
sip_attr_destroy((sip_attr_t*) attr);
}
void
sip_attr_set(vector_t *attrs, enum sip_attr_id id, const char *value)
{
sip_attr_t *attr;
// Remove previous value if any
if ((attr = sip_attr_get(attrs, id)))
vector_remove(attrs, attr);
// Create a new attribute struct and store it
vector_append(attrs, sip_attr_create(id, value));
}
sip_attr_t *
sip_attr_get(vector_t *attrs, enum sip_attr_id id)
{
sip_attr_t *attr;
vector_iter_t it = vector_iterator(attrs);
while ((attr = vector_iterator_next(&it))) {
if (attr->id == id)
return attr;
}
return NULL;
}
const char *
sip_attr_get_value(vector_t *attrs, enum sip_attr_id id)
{
sip_attr_t *attr = sip_attr_get(attrs, id);
return (attr) ? attr->value : NULL;
}

View File

@ -32,13 +32,6 @@
#include "config.h"
#include "vector.h"
/* Some very used macros */
#define CALLID(msg) call_get_attribute(msg->call, SIP_ATTR_CALLID)
#define SRC(msg) msg_get_attribute(msg, SIP_ATTR_SRC)
#define DST(msg) msg_get_attribute(msg, SIP_ATTR_DST)
#define TIME(msg) msg_get_attribute(msg, SIP_ATTR_TIME)
#define DATE(msg) msg_get_attribute(msg, SIP_ATTR_DATE)
//! Shorter declaration of sip_attr_hdr structure
typedef struct sip_attr_hdr sip_attr_hdr_t;
//! Shorter declaration of sip_attr structure
@ -192,51 +185,4 @@ sip_attr_get_width(enum sip_attr_id id);
enum sip_attr_id
sip_attr_from_name(const char *name);
/**
* @brief Allocate memory for an attribute structure
*/
sip_attr_t *
sip_attr_create(enum sip_attr_id id, const char *value);
/**
* @brief Free memory for an attribute structe
*/
void
sip_attr_destroy(sip_attr_t *attr);
/**
* @brief Wrapper around sip_attr_destroy for attribute vectors
*/
void
sip_attr_destroyer(void *attr);
/**
* @brief Sets the given attribute value to an attribute
*
* Primitive for setting an attribute value of a given attribute list.
* This can be used for calls and message attributes.
*
* @param list Pointer to the attribute list
* @param id Attribute id
* @param value Attribute value
*/
void
sip_attr_set(vector_t *attrs, enum sip_attr_id id, const char *value);
/**
* @brief Gets the given attribute value to an attribute
*
* Primitive for getting an attribute value of a given attribute list.
* This can be used for calls and message attributes.
*
*/
sip_attr_t *
sip_attr_get(vector_t *attrs, enum sip_attr_id id);
/**
* @brief Get attribute value
*/
const char *
sip_attr_get_value(vector_t *attrs, enum sip_attr_id id);
#endif /* __SNGREP_SIP_ATTR_H */

View File

@ -30,6 +30,7 @@
*/
#include "sip_call.h"
#include "sip.h"
sip_call_t *
call_create(char *callid)
@ -44,10 +45,6 @@ call_create(char *callid)
call->msgs = vector_create(2, 2);
vector_set_destroyer(call->msgs, msg_destroyer);
// Create a vector to store call attributes
call->attrs = vector_create(1, 1);
vector_set_destroyer(call->attrs, sip_attr_destroyer);
// Create an empty vector to store rtp packets
call->rtp_packets = vector_create(0, 40);
vector_set_destroyer(call->rtp_packets, capture_packet_destroyer);
@ -60,7 +57,8 @@ call_create(char *callid)
call->filtered = -1;
// Set message callid
call_set_attribute(call, SIP_ATTR_CALLID, callid);
call->callid = strdup(callid);
return call;
}
@ -71,11 +69,11 @@ call_destroy(sip_call_t *call)
vector_destroy(call->msgs);
// Remove all call streams
vector_destroy(call->streams);
// Remove all call attributes
vector_destroy(call->attrs);
// Remove all call rtp packets
vector_destroy(call->rtp_packets);
// Deallocate call memory
sng_free(call->callid);
sng_free(call->xcallid);
sng_free(call);
}
@ -92,8 +90,6 @@ call_add_message(sip_call_t *call, sip_msg_t *msg)
msg->call = call;
// Put this msg at the end of the msg list
msg->index = vector_append(call->msgs, msg);
// Store message count
call_set_attribute(call, SIP_ATTR_MSGCNT, "%d", vector_count(call->msgs));
}
void
@ -119,7 +115,7 @@ call_is_active(void *item)
{
// TODO
sip_call_t *call = (sip_call_t *)item;
return call->active;
return (call->state == SIP_CALLSTATE_CALLSETUP || call->state == SIP_CALLSTATE_INCALL);
}
int
@ -142,7 +138,8 @@ call_msg_is_retrans(sip_msg_t *msg)
it = vector_iterator(msg->call->msgs);
vector_iterator_set_current(&it, vector_index(msg->call->msgs, msg));
while ((prev = vector_iterator_prev(&it))) {
if (!strcmp(SRC(prev), SRC(msg)) && !strcmp(DST(prev), DST(msg)))
if (!strcmp(prev->packet->ip_src, msg->packet->ip_src) &&
!strcmp(prev->packet->ip_dst, msg->packet->ip_dst))
break;
}
@ -153,8 +150,6 @@ call_msg_is_retrans(sip_msg_t *msg)
void
call_update_state(sip_call_t *call, sip_msg_t *msg)
{
const char *callstate;
char dur[20];
int reqresp;
sip_msg_t *first;
@ -168,84 +163,95 @@ call_update_state(sip_call_t *call, sip_msg_t *msg)
reqresp = msg->reqresp;
// If this message is actually a call, get its current state
if ((callstate = call_get_attribute(call, SIP_ATTR_CALLSTATE))) {
if (!strcmp(callstate, SIP_CALLSTATE_CALLSETUP)) {
if (call->state) {
if (call->state == SIP_CALLSTATE_CALLSETUP) {
if (reqresp == 200) {
// Alice and Bob are talking
call_set_attribute(call, SIP_ATTR_CALLSTATE, SIP_CALLSTATE_INCALL);
// Store the timestap where call has started
call->active = 1;
call->state = SIP_CALLSTATE_INCALL;
call->cstart_msg = msg;
} else if (reqresp == SIP_METHOD_CANCEL) {
// Alice is not in the mood
call_set_attribute(call, SIP_ATTR_CALLSTATE, SIP_CALLSTATE_CANCELLED);
// Store total call duration
call_set_attribute(call, SIP_ATTR_TOTALDUR, timeval_to_duration(msg_get_time(first), msg_get_time(msg), dur));
call->active = 0;
call->state = SIP_CALLSTATE_CANCELLED;
} else if (reqresp > 400) {
// Bob is not in the mood
call_set_attribute(call, SIP_ATTR_CALLSTATE, SIP_CALLSTATE_REJECTED);
// Store total call duration
call_set_attribute(call, SIP_ATTR_TOTALDUR, timeval_to_duration(msg_get_time(first), msg_get_time(msg), dur));
call->active = 0;
call->state = SIP_CALLSTATE_REJECTED;
}
} else if (!strcmp(callstate, SIP_CALLSTATE_INCALL)) {
} else if (call->state == SIP_CALLSTATE_INCALL) {
if (reqresp == SIP_METHOD_BYE) {
// Thanks for all the fish!
call_set_attribute(call, SIP_ATTR_CALLSTATE, SIP_CALLSTATE_COMPLETED);
// Store Conversation duration
call_set_attribute(call, SIP_ATTR_CONVDUR,
timeval_to_duration(msg_get_time(call->cstart_msg), msg_get_time(msg), dur));
call->active = 0;
call->state = SIP_CALLSTATE_COMPLETED;
call->cend_msg = msg;
}
} else if (reqresp == SIP_METHOD_INVITE && strcmp(callstate, SIP_CALLSTATE_INCALL)) {
} else if (reqresp == SIP_METHOD_INVITE && call->state != SIP_CALLSTATE_INCALL) {
// Call is being setup (after proper authentication)
call_set_attribute(call, SIP_ATTR_CALLSTATE, SIP_CALLSTATE_CALLSETUP);
call->active = 1;
} else {
// Store total call duration
call_set_attribute(call, SIP_ATTR_TOTALDUR, timeval_to_duration(msg_get_time(first), msg_get_time(msg), dur));
call->state = SIP_CALLSTATE_CALLSETUP;
}
} else {
// This is actually a call
if (reqresp == SIP_METHOD_INVITE) {
call_set_attribute(call, SIP_ATTR_CALLSTATE, SIP_CALLSTATE_CALLSETUP);
call->active = 1;
call->state = SIP_CALLSTATE_CALLSETUP;
}
}
}
void
call_set_attribute(sip_call_t *call, enum sip_attr_id id, const char *fmt, ...)
{
char value[512];
// Get the actual value for the attribute
va_list ap;
va_start(ap, fmt);
vsprintf(value, fmt, ap);
va_end(ap);
sip_attr_set(call->attrs, id, value);
}
const char *
call_get_attribute(sip_call_t *call, enum sip_attr_id id)
call_get_attribute(sip_call_t *call, enum sip_attr_id id, char *value)
{
sip_msg_t *first, *last;
if (!call)
return NULL;
switch (id) {
case SIP_ATTR_CALLINDEX:
sprintf(value, "%d", call->index);
break;
case SIP_ATTR_CALLID:
sprintf(value, "%s", call->callid);
break;
case SIP_ATTR_XCALLID:
sprintf(value, "%s", call->callid);
break;
case SIP_ATTR_MSGCNT:
sprintf(value, "%d", vector_count(call->msgs));
break;
case SIP_ATTR_CALLSTATE:
sprintf(value, "%s", call_state_to_str(call->state));
break;
case SIP_ATTR_TRANSPORT:
first = vector_first(call->msgs);
sprintf(value, "%s", sip_transport_str(first->packet->type));
break;
case SIP_ATTR_CONVDUR:
timeval_to_duration(msg_get_time(call->cstart_msg), msg_get_time(call->cend_msg), value);
break;
case SIP_ATTR_TOTALDUR:
return sip_attr_get_value(call->attrs, id);
first = vector_first(call->msgs);
last = vector_last(call->msgs);
timeval_to_duration(msg_get_time(first), msg_get_time(last), value);
break;
default:
return msg_get_attribute(vector_first(call->msgs), id);
return msg_get_attribute(vector_first(call->msgs), id, value);
break;
}
return NULL;
return strlen(value) ? value : NULL;
}
const char *
call_state_to_str(int state)
{
switch (state) {
case SIP_CALLSTATE_CALLSETUP:
return "CALL SETUP";
case SIP_CALLSTATE_INCALL:
return "IN CALL";
case SIP_CALLSTATE_CANCELLED:
return "CANCELLED";
case SIP_CALLSTATE_REJECTED:
return "REJECTED";
case SIP_CALLSTATE_COMPLETED:
return "COMPLETED";
}
return "";
}

View File

@ -36,16 +36,19 @@
#include "sip_msg.h"
#include "sip_attr.h"
//! SIP Call State
#define SIP_CALLSTATE_CALLSETUP "CALL SETUP"
#define SIP_CALLSTATE_INCALL "IN CALL"
#define SIP_CALLSTATE_CANCELLED "CANCELLED"
#define SIP_CALLSTATE_REJECTED "REJECTED"
#define SIP_CALLSTATE_COMPLETED "COMPLETED"
//! Shorter declaration of sip_call structure
typedef struct sip_call sip_call_t;
//! SIP Call State
enum call_state
{
SIP_CALLSTATE_CALLSETUP = 1,
SIP_CALLSTATE_INCALL,
SIP_CALLSTATE_CANCELLED,
SIP_CALLSTATE_REJECTED,
SIP_CALLSTATE_COMPLETED
};
/**
* @brief Contains all information of a call and its messages
*
@ -54,16 +57,21 @@ typedef struct sip_call sip_call_t;
* data from its messages to speed up searches.
*/
struct sip_call {
// Call index in the call list
int index;
// Call identifier
char *callid;
//! Related Call identifier
char *xcallid;
//! Flag this call as filtered so won't be displayed
signed char filtered;
//! For call dialogs, mark if call has not yet finished
u_char active;
//! Call State. For dialogs starting with an INVITE method
int state;
//! List of messages of this call (sip_msg_t*)
vector_t *msgs;
//! Message when conversation started
sip_msg_t *cstart_msg;
//! Call attribute list
vector_t *attrs;
//! Message when conversation started and ended
sip_msg_t *cstart_msg, *cend_msg;
//! RTP streams for this call (rtp_stream_t *)
vector_t *streams;
//! RTP packets for this call (capture_packet_t *)
@ -192,18 +200,6 @@ call_msg_is_retrans(sip_msg_t *msg);
void
call_update_state(sip_call_t *call, sip_msg_t *msg);
/**
* @brief Sets the attribute value for a given call
*
* This function acts as wrapper of sip call attributes
*
* @param call SIP call structure
* @param id Attribute id
* @param value Attribute value
*/
void
call_set_attribute(struct sip_call *call, enum sip_attr_id id, const char *fmt, ...);
/**
* @brief Return a call attribute value
*
@ -216,6 +212,13 @@ call_set_attribute(struct sip_call *call, enum sip_attr_id id, const char *fmt,
* @return Attribute value or NULL if not found
*/
const char *
call_get_attribute(struct sip_call *call, enum sip_attr_id id);
call_get_attribute(struct sip_call *call, enum sip_attr_id id, char *value);
/**
* @brief Return the string represtation of a call state
*
*/
const char *
call_state_to_str(int state);
#endif /* __SNGREP_SIP_CALL_H */

View File

@ -29,6 +29,8 @@
*
*/
#include "sip_msg.h"
#include "media.h"
#include "sip.h"
sip_msg_t *
msg_create(const char *payload)
@ -36,25 +38,19 @@ msg_create(const char *payload)
sip_msg_t *msg;
if (!(msg = sng_malloc(sizeof(sip_msg_t))))
return NULL;
// Create a vector to store attributes
msg->attrs = vector_create(4, 4);
vector_set_destroyer(msg->attrs, sip_attr_destroyer);
return msg;
}
void
msg_destroy(sip_msg_t *msg)
{
// Free message attribute list
vector_destroy(msg->attrs);
// Free message SDP media
vector_destroy(msg->medias);
// Free message packets
capture_packet_destroy(msg->packet);
// Free payload if parsed
sng_free(msg->payload);
// Free all memory
sng_free(msg->sip_from);
sng_free(msg->sip_to);
sng_free(msg);
}
@ -114,22 +110,57 @@ msg_get_time(sip_msg_t *msg) {
return t;
}
void
msg_set_attribute(sip_msg_t *msg, enum sip_attr_id id, const char *fmt, ...)
{
char value[512];
// Get the actual value for the attribute
va_list ap;
va_start(ap, fmt);
vsprintf(value, fmt, ap);
va_end(ap);
sip_attr_set(msg->attrs, id, value);
}
const char *
msg_get_attribute(sip_msg_t *msg, enum sip_attr_id id)
msg_get_attribute(sip_msg_t *msg, int id, char *value)
{
return sip_attr_get_value(msg->attrs, id);
sdp_media_t *media;
char *ar;
switch (id) {
case SIP_ATTR_SRC:
sprintf(value, "%s:%u", msg->packet->ip_src, msg->packet->sport);
break;
case SIP_ATTR_DST:
sprintf(value, "%s:%u", msg->packet->ip_dst, msg->packet->dport);
break;
case SIP_ATTR_METHOD:
sprintf(value, "%s", sip_method_str(msg->reqresp));
break;
case SIP_ATTR_SIPFROM:
sprintf(value, "%s", msg->sip_from);
break;
case SIP_ATTR_SIPTO:
sprintf(value, "%s", msg->sip_to);
break;
case SIP_ATTR_SIPFROMUSER:
sprintf(value, "%s", msg->sip_from);
if ((ar = strchr(value, '@')))
*ar = '\0';
break;
case SIP_ATTR_SIPTOUSER:
sprintf(value, "%s", msg->sip_to);
if ((ar = strchr(value, '@')))
*ar = '\0';
break;
case SIP_ATTR_DATE:
timeval_to_date(msg_get_time(msg), value);
break;
case SIP_ATTR_TIME:
timeval_to_time(msg_get_time(msg), value);
break;
case SIP_ATTR_SDP_ADDRESS:
if ((media = vector_first(msg->medias)))
sprintf(value, "%s", media_get_address(media));
break;
case SIP_ATTR_SDP_PORT:
if ((media = vector_first(msg->medias)))
sprintf(value, "%d", media_get_port(media));
break;
default:
fprintf(stderr, "Unhandled attribute %s (%d)\n", sip_attr_get_name(id), id); abort();
break;
}
return strlen(value) ? value : NULL;
}

View File

@ -39,25 +39,6 @@
//! Shorter declaration of sip_msg structure
typedef struct sip_msg sip_msg_t;
//! SIP Methods
enum sip_methods {
SIP_METHOD_REGISTER = 1,
SIP_METHOD_INVITE,
SIP_METHOD_SUBSCRIBE,
SIP_METHOD_NOTIFY,
SIP_METHOD_OPTIONS,
SIP_METHOD_PUBLISH,
SIP_METHOD_MESSAGE,
SIP_METHOD_CANCEL,
SIP_METHOD_BYE,
SIP_METHOD_ACK,
SIP_METHOD_PRACK,
SIP_METHOD_INFO,
SIP_METHOD_REFER,
SIP_METHOD_UPDATE,
SIP_METHOD_SENTINEL,
};
/**
* @brief Information of a single message withing a dialog.
*
@ -68,14 +49,12 @@ enum sip_methods {
*/
struct sip_call;
struct sip_msg {
//! Temporal payload data before being parsed
u_char *payload;
//! Request Method or Response Code @see sip_methods
int reqresp;
//! Message Cseq
u_int cseq;
//! Message attribute list
vector_t *attrs;
//! SIP From and TO
char *sip_from, *sip_to;
//! SDP payload information (sdp_media_t *)
vector_t *medias;
//! Captured packets for this message (capture_packet_t *)
@ -187,18 +166,6 @@ msg_get_payload(sip_msg_t *msg);
struct timeval
msg_get_time(sip_msg_t *msg);
/**
* @brief Sets the attribute value for a given message
*
* This function acts as wrapper of sip message attributes
*
* @param msg SIP message structure
* @param id Attribute id
* @param value Attribute value
*/
void
msg_set_attribute(struct sip_msg *msg, enum sip_attr_id id, const char *fmt, ...);
/**
* @brief Return a message attribute value
*
@ -207,10 +174,11 @@ msg_set_attribute(struct sip_msg *msg, enum sip_attr_id id, const char *fmt, ...
*
* @param msg SIP message structure
* @param id Attribute id
* @param out Buffer to store attribute value
* @return Attribute value or NULL if not found
*/
const char *
msg_get_attribute(struct sip_msg *msg, enum sip_attr_id id);
msg_get_attribute(struct sip_msg *msg, int id, char *value);
#endif /* __SNGREP_SIP_MSG_H */

View File

@ -151,6 +151,7 @@ call_flow_draw(PANEL *panel)
call_flow_arrow_t *arrow = NULL;
int height, width, cline = 0;
char title[256];
char callid[256];
// Get panel information
info = call_flow_info(panel);
@ -163,7 +164,7 @@ call_flow_draw(PANEL *panel)
// Set title
if (call_group_count(info->group) == 1) {
sprintf(title, "Call flow for %s",
call_get_attribute(vector_first(info->group->calls), SIP_ATTR_CALLID));
call_get_attribute(vector_first(info->group->calls), SIP_ATTR_CALLID, callid));
} else {
sprintf(title, "Call flow for %d dialogs", call_group_count(info->group));
}
@ -246,6 +247,7 @@ call_flow_draw_columns(PANEL *panel)
vector_iter_t columns;
int flow_height, flow_width;
const char *coltext;
char ip_src[80], ip_dst[80];
// Get panel information
info = call_flow_info(panel);
@ -257,8 +259,12 @@ call_flow_draw_columns(PANEL *panel)
// Load columns
for (msg = call_group_get_next_msg(info->group, info->last_msg); msg;
msg = call_group_get_next_msg(info->group, msg)) {
call_flow_column_add(panel, call_get_attribute(msg_get_call(msg), SIP_ATTR_CALLID), SRC(msg));
call_flow_column_add(panel, call_get_attribute(msg_get_call(msg), SIP_ATTR_CALLID), DST(msg));
memset(ip_src, 0, sizeof(ip_src));
memset(ip_dst, 0, sizeof(ip_dst));
msg_get_attribute(msg, SIP_ATTR_SRC, ip_src);
msg_get_attribute(msg, SIP_ATTR_DST, ip_dst);
call_flow_column_add(panel, msg->call->callid, ip_src);
call_flow_column_add(panel, msg->call->callid, ip_dst);
info->last_msg = msg;
}
@ -300,11 +306,13 @@ call_flow_draw_message(PANEL *panel, call_flow_arrow_t *arrow, int cline)
call_flow_info_t *info;
WINDOW *win;
sdp_media_t *media;
const char *msg_time;
const char *msg_callid;
const char *msg_method;
const char *msg_src;
const char *msg_dst;
char msg_time[80];
char msg_src[80];
char msg_dst[80];
char sdp_address[80];
char sdp_port[80];
char method[80];
char delta[15] = { };
int height, width;
@ -331,15 +339,11 @@ call_flow_draw_message(PANEL *panel, call_flow_arrow_t *arrow, int cline)
return NULL;
// Get message attributes
msg_time = msg_get_attribute(msg, SIP_ATTR_TIME);
msg_callid = call_get_attribute(msg_get_call(msg), SIP_ATTR_CALLID);
msg_method = msg_get_attribute(msg, SIP_ATTR_METHOD);
msg_src = msg_get_attribute(msg, SIP_ATTR_SRC);
msg_dst = msg_get_attribute(msg, SIP_ATTR_DST);
// Check method has value. We prefer empty arrows rather than crashes
if (!msg_method)
msg_method = "";
msg_callid = msg->call->callid;
msg_method = sip_method_str(msg->reqresp);
msg_get_attribute(msg, SIP_ATTR_TIME, msg_time);
msg_get_attribute(msg, SIP_ATTR_SRC, msg_src);
msg_get_attribute(msg, SIP_ATTR_DST, msg_dst);
// Print timestamp
if (info->selected == arrow)
@ -372,13 +376,13 @@ call_flow_draw_message(PANEL *panel, call_flow_arrow_t *arrow, int cline)
if (msg_has_sdp(msg) && setting_has_value(SETTING_CF_SDP_INFO, "first")) {
sprintf(method, "%.3s (%s:%s)",
msg_method,
msg_get_attribute(msg, SIP_ATTR_SDP_ADDRESS),
msg_get_attribute(msg, SIP_ATTR_SDP_PORT));
msg_get_attribute(msg, SIP_ATTR_SDP_ADDRESS, sdp_address),
msg_get_attribute(msg, SIP_ATTR_SDP_PORT, sdp_port));
}
if (msg_has_sdp(msg) && setting_has_value(SETTING_CF_SDP_INFO, "full")) {
sprintf(method, "%.3s (%s)",
msg_method,
msg_get_attribute(msg, SIP_ATTR_SDP_ADDRESS));
msg_get_attribute(msg, SIP_ATTR_SDP_ADDRESS, sdp_address));
}
// Draw message type or status and line
@ -484,6 +488,8 @@ call_flow_draw_stream(PANEL *panel, call_flow_arrow_t *arrow, int cline)
WINDOW *win;
char codec[50], time[20];
int height, width;
const char *callid;
char msg_dst[80], msg_src[80];
call_flow_column_t *column1, *column2;
rtp_stream_t *stream = arrow->stream;
@ -510,22 +516,27 @@ call_flow_draw_stream(PANEL *panel, call_flow_arrow_t *arrow, int cline)
// Get Message method (include extra info)
sprintf(codec, "RTP (%s) %d", stream_get_format(stream), stream_get_count(stream));
// Get message data
msg_get_attribute(stream->media->msg, SIP_ATTR_SRC, msg_src);
msg_get_attribute(stream->media->msg, SIP_ATTR_DST, msg_dst);
callid = stream->media->msg->call->callid;
// Get origin column for this stream.
// If we share the same Address from its setup SIP packet, use that column instead.
if (!strncmp(stream->ip_src, SRC(stream->media->msg), strlen(stream->ip_src))) {
column1 = call_flow_column_get(panel, CALLID(stream->media->msg), SRC(stream->media->msg));
} else if (!strncmp(stream->ip_src, DST(stream->media->msg), strlen(stream->ip_src))) {
column1 = call_flow_column_get(panel, CALLID(stream->media->msg), DST(stream->media->msg));
if (!strncmp(stream->ip_src, msg_src, strlen(stream->ip_src))) {
column1 = call_flow_column_get(panel, callid, msg_src);
} else if (!strncmp(stream->ip_src, msg_dst, strlen(stream->ip_src))) {
column1 = call_flow_column_get(panel, callid, msg_dst);
} else {
column1 = call_flow_column_get(panel, 0, stream->ip_src);
}
// Get destination column for this stream.
// If we share the same Address from its setup SIP packet, use that column instead.
if (!strncmp(stream->ip_dst, DST(stream->media->msg), strlen(stream->ip_dst))) {
column2 = call_flow_column_get(panel, CALLID(stream->media->msg), DST(stream->media->msg));
} else if (!strncmp(stream->ip_dst, SRC(stream->media->msg), strlen(stream->ip_dst))) {
column2 = call_flow_column_get(panel, CALLID(stream->media->msg), SRC(stream->media->msg));
if (!strncmp(stream->ip_dst, msg_dst, strlen(stream->ip_dst))) {
column2 = call_flow_column_get(panel, callid, msg_dst);
} else if (!strncmp(stream->ip_dst, msg_src, strlen(stream->ip_dst))) {
column2 = call_flow_column_get(panel, callid, msg_src);
} else {
column2 = call_flow_column_get(panel, 0, stream->ip_dst);
}
@ -1078,7 +1089,7 @@ call_flow_column_add(PANEL *panel, const char *callid, const char *addr)
column = sng_malloc(sizeof(call_flow_column_t));
column->callid = callid;
column->addr = addr;
strcpy(column->addr, addr);
column->colpos = vector_count(info->columns);
vector_append(info->columns, column);
}

View File

@ -100,7 +100,7 @@ struct call_flow_arrow {
* @brief Structure to hold one column information
*/
struct call_flow_column {
const char *addr;
char addr[80];
const char *callid;
const char *callid2;
int colpos;

View File

@ -378,7 +378,7 @@ const char *
call_list_line_text(PANEL *panel, sip_call_t *call, char *text)
{
int i, collen;
const char *call_attr;
char call_attr[256];
char coltext[256];
int colid;
int width;
@ -410,8 +410,10 @@ call_list_line_text(PANEL *panel, sip_call_t *call, char *text)
// Initialize column text
memset(coltext, 0, sizeof(coltext));
memset(call_attr, 0, sizeof(call_attr));
// Get call attribute for current column
if ((call_attr = call_get_attribute(call, colid))) {
if (call_get_attribute(call, colid, call_attr)) {
sprintf(coltext, "%.*s", collen, call_attr);
}
// Add the column text to the existing columns

View File

@ -540,7 +540,12 @@ save_to_file(PANEL *panel)
void
save_msg_txt(FILE *f, sip_msg_t *msg)
{
fprintf(f, "%s %s %s -> %s\n%s\n\n", msg_get_attribute(msg, SIP_ATTR_DATE),
msg_get_attribute(msg, SIP_ATTR_TIME), msg_get_attribute(msg, SIP_ATTR_SRC),
msg_get_attribute(msg, SIP_ATTR_DST), msg_get_payload(msg));
char date[20], time[20], src[80], dst[80];
fprintf(f, "%s %s %s -> %s\n%s\n\n",
msg_get_attribute(msg, SIP_ATTR_DATE, date),
msg_get_attribute(msg, SIP_ATTR_TIME, time),
msg_get_attribute(msg, SIP_ATTR_SRC, src),
msg_get_attribute(msg, SIP_ATTR_DST, dst),
msg_get_payload(msg));
}