From 71eec87ac654d937ee94fcd261749fe24b3aa121 Mon Sep 17 00:00:00 2001 From: Kaian Date: Fri, 20 Apr 2018 23:45:14 +0200 Subject: [PATCH] stream: old rtp code is now known as stream --- CMakeLists.txt | 2 +- src/capture/capture_pcap.c | 2 +- src/packet/dissectors/packet_rtp.h | 2 + src/sip_call.c | 55 ++++++++++++++++++++++++ src/sip_call.h | 8 +++- src/storage.c | 12 +++--- src/{packet/rtp.c => stream.c} | 69 ++---------------------------- src/{packet/rtp.h => stream.h} | 23 +++------- 8 files changed, 82 insertions(+), 91 deletions(-) rename src/{packet/rtp.c => stream.c} (76%) rename src/{packet/rtp.h => stream.h} (85%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d45696..f60beac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ set(SOURCES src/main.c src/option.c src/packet/old_packet.c - src/packet/rtp.c + src/stream.c src/setting.c src/sip_attr.c src/storage.c diff --git a/src/capture/capture_pcap.c b/src/capture/capture_pcap.c index 95263df..de71471 100644 --- a/src/capture/capture_pcap.c +++ b/src/capture/capture_pcap.c @@ -42,7 +42,7 @@ #include "capture_pcap.h" #include "packet/dissectors/packet_link.h" #include "storage.h" -#include "packet/rtp.h" +#include "stream.h" #include "setting.h" #include "util.h" diff --git a/src/packet/dissectors/packet_rtp.h b/src/packet/dissectors/packet_rtp.h index 45fe931..6002676 100644 --- a/src/packet/dissectors/packet_rtp.h +++ b/src/packet/dissectors/packet_rtp.h @@ -25,6 +25,8 @@ * * @brief Functions to manage RTP packets * + * @note RTP_VERSION and RTP_PAYLOAD_TYPE macros has been taken from wireshark + * source code: packet-rtp.c */ #ifndef __SNGREP_PACKET_RTP_H diff --git a/src/sip_call.c b/src/sip_call.c index dbaa5e9..71397d8 100644 --- a/src/sip_call.c +++ b/src/sip_call.c @@ -380,3 +380,58 @@ call_add_xcall(sip_call_t *call, sip_call_t *xcall) // Add the xcall to the list g_sequence_append(call->xcalls, xcall); } + +rtp_stream_t * +call_find_stream(struct sip_call *call, Address src, Address dst) +{ + rtp_stream_t *stream; + GSequenceIter *it; + + // Create an iterator for call streams + it = g_sequence_get_end_iter(call->streams); + + // Look for an incomplete stream with this destination + while(!g_sequence_iter_is_begin(it)) { + it = g_sequence_iter_prev(it); + stream = g_sequence_get(it); + if (addressport_equals(dst, stream->dst)) { + if (!src.port) { + return stream; + } else { + if (!stream->pktcnt) { + return stream; + } + } + } + } + + // Try to look for a complete stream with this destination + if (src.port) { + return call_find_stream_exact(call, src, dst); + } + + // Nothing found + return NULL; +} + +rtp_stream_t * +call_find_stream_exact(struct sip_call *call, Address src, Address dst) +{ + rtp_stream_t *stream; + GSequenceIter *it; + + // Create an iterator for call streams + it = g_sequence_get_end_iter(call->streams); + + while(!g_sequence_iter_is_begin(it)) { + it = g_sequence_iter_prev(it); + stream = g_sequence_get(it); + if (addressport_equals(src, stream->src) && + addressport_equals(dst, stream->dst)) { + return stream; + } + } + + // Nothing found + return NULL; +} diff --git a/src/sip_call.h b/src/sip_call.h index b3c71de..c79d99b 100644 --- a/src/sip_call.h +++ b/src/sip_call.h @@ -32,7 +32,7 @@ #include #include #include -#include "packet/rtp.h" +#include "stream.h" #include "sip_msg.h" #include "sip_attr.h" @@ -262,4 +262,10 @@ call_attr_compare(const sip_call_t *one, const sip_call_t *two, enum sip_attr_id void call_add_xcall(sip_call_t *call, sip_call_t *xcall); +rtp_stream_t * +call_find_stream(struct sip_call *call, Address src, Address dst); + +rtp_stream_t * +call_find_stream_exact(struct sip_call *call, Address src, Address dst); + #endif /* __SNGREP_SIP_CALL_H */ diff --git a/src/storage.c b/src/storage.c index e8025c9..3469bbd 100644 --- a/src/storage.c +++ b/src/storage.c @@ -254,7 +254,7 @@ storage_check_rtp_packet(packet_t *packet) guint8 format = rtp->encoding->id; // Find the matching stream - stream = rtp_find_stream_format(src, dst, format); + stream = stream_find_by_format(src, dst, format); // Check if a valid stream has been found if (!stream) @@ -294,7 +294,7 @@ storage_check_rtp_packet(packet_t *packet) */ // Check if an stream in the opposite direction exists - if (!(reverse = rtp_find_call_stream(stream->msg->call, stream->dst, stream->src))) { + if (!(reverse = call_find_stream(stream->msg->call, stream->dst, stream->src))) { reverse = stream_create(packet->newpacket, stream->media); stream_complete(reverse, stream->dst); stream_set_format(reverse, format); @@ -302,7 +302,7 @@ storage_check_rtp_packet(packet_t *packet) } else { // If the reverse stream has other source configured if (reverse->src.port && !addressport_equals(stream->src, reverse->src)) { - if (!(reverse = rtp_find_call_exact_stream(stream->msg->call, stream->dst, stream->src))) { + if (!(reverse = call_find_stream_exact(stream->msg->call, stream->dst, stream->src))) { // Create a new reverse stream reverse = stream_create(packet->newpacket, stream->media); stream_complete(reverse, stream->dst); @@ -409,7 +409,7 @@ storage_register_streams(sip_msg_t *msg) g_sequence_append(msg->medias, media); // Create RTP stream for this media - if (rtp_find_call_stream(msg->call, emptyaddr, media->address) == NULL) { + if (call_find_stream(msg->call, emptyaddr, media->address) == NULL) { rtp_stream_t *stream = stream_create(packet, media); stream->type = PACKET_RTP; stream->msg = msg; @@ -417,7 +417,7 @@ storage_register_streams(sip_msg_t *msg) } // Create RTCP stream for this media - if (rtp_find_call_stream(msg->call, emptyaddr, media->address) == NULL) { + if (call_find_stream(msg->call, emptyaddr, media->address) == NULL) { rtp_stream_t *stream = stream_create(packet, media); stream->dst.port = (media->rtcpport) ? media->rtcpport : (guint16) (media->rtpport + 1); stream->type = PACKET_RTCP; @@ -426,7 +426,7 @@ storage_register_streams(sip_msg_t *msg) } // Create RTP stream with source of message as destination address - if (rtp_find_call_stream(msg->call, msg->packet->src, media->address) == NULL) { + if (call_find_stream(msg->call, msg->packet->src, media->address) == NULL) { rtp_stream_t *stream = stream_create(packet, media); stream->type = PACKET_RTP; stream->msg = msg; diff --git a/src/packet/rtp.c b/src/stream.c similarity index 76% rename from src/packet/rtp.c rename to src/stream.c index f1bbad8..e9c9d0b 100644 --- a/src/packet/rtp.c +++ b/src/stream.c @@ -34,7 +34,7 @@ #include #include #include "glib-utils.h" -#include "rtp.h" +#include "stream.h" #include "storage.h" rtp_stream_t * @@ -83,13 +83,6 @@ stream_get_count(rtp_stream_t *stream) return stream->pktcnt; } -struct sip_call * -stream_get_call(rtp_stream_t *stream) { - if (stream && stream->media && stream->msg) - return stream->msg->call; - return NULL; -} - const char * stream_get_format(rtp_stream_t *stream) { @@ -118,7 +111,7 @@ stream_get_format(rtp_stream_t *stream) } rtp_stream_t * -rtp_find_stream_format(Address src, Address dst, uint32_t format) +stream_find_by_format(Address src, Address dst, uint32_t format) { // Structure for RTP packet streams rtp_stream_t *stream; @@ -170,7 +163,7 @@ rtp_find_stream_format(Address src, Address dst, uint32_t format) } rtp_stream_t * -rtp_find_stream(Address src, Address dst) +stream_find(Address src, Address dst) { // Structure for RTP packet streams rtp_stream_t *stream; @@ -186,7 +179,7 @@ rtp_find_stream(Address src, Address dst) calls = g_sequence_iter_prev(calls); call = g_sequence_get(calls); // Check if this call has an RTP stream for current packet data - if ((stream = rtp_find_call_stream(call, src, dst))) { + if ((stream = call_find_stream(call, src, dst))) { return stream; } } @@ -195,60 +188,6 @@ rtp_find_stream(Address src, Address dst) } -rtp_stream_t * -rtp_find_call_stream(struct sip_call *call, Address src, Address dst) -{ - rtp_stream_t *stream; - GSequenceIter *it; - - // Create an iterator for call streams - it = g_sequence_get_end_iter(call->streams); - - // Look for an incomplete stream with this destination - while(!g_sequence_iter_is_begin(it)) { - it = g_sequence_iter_prev(it); - stream = g_sequence_get(it); - if (addressport_equals(dst, stream->dst)) { - if (!src.port) { - return stream; - } else { - if (!stream->pktcnt) { - return stream; - } - } - } - } - - // Try to look for a complete stream with this destination - if (src.port) { - return rtp_find_call_exact_stream(call, src, dst); - } - - // Nothing found - return NULL; -} - -rtp_stream_t * -rtp_find_call_exact_stream(struct sip_call *call, Address src, Address dst) -{ - rtp_stream_t *stream; - GSequenceIter *it; - - // Create an iterator for call streams - it = g_sequence_get_end_iter(call->streams); - - while(!g_sequence_iter_is_begin(it)) { - it = g_sequence_iter_prev(it); - stream = g_sequence_get(it); - if (addressport_equals(src, stream->src) && - addressport_equals(dst, stream->dst)) { - return stream; - } - } - - // Nothing found - return NULL; -} int stream_is_older(rtp_stream_t *one, rtp_stream_t *two) diff --git a/src/packet/rtp.h b/src/stream.h similarity index 85% rename from src/packet/rtp.h rename to src/stream.h index 3232444..7811aca 100644 --- a/src/packet/rtp.h +++ b/src/stream.h @@ -20,17 +20,17 @@ ** ****************************************************************************/ /** - * @file rtp.h + * @file stream.h * @author Ivan Alonso [aka Kaian] * - * @brief Functions to manage rtp captured packets + * @brief Functions to manage rtp streams * * @note RTP_VERSION and RTP_PAYLOAD_TYPE macros has been taken from wireshark * source code: packet-rtp.c */ -#ifndef __SNGREP_RTP_H -#define __SNGREP_RTP_H +#ifndef __SNGREP_STREAM_H +#define __SNGREP_STREAM_H #include "config.h" #include "sip_msg.h" @@ -78,23 +78,12 @@ stream_add_packet(rtp_stream_t *stream, packet_t *packet); uint32_t stream_get_count(rtp_stream_t *stream); -struct sip_call * -stream_get_call(rtp_stream_t *stream); - const char * stream_get_format(rtp_stream_t *stream); rtp_stream_t * -rtp_find_stream_format(Address src, Address dst, uint32_t format); +stream_find_by_format(Address src, Address dst, uint32_t format); -rtp_stream_t * -rtp_find_stream(Address src, Address dst); - -rtp_stream_t * -rtp_find_call_stream(struct sip_call *call, Address src, Address dst); - -rtp_stream_t * -rtp_find_call_exact_stream(struct sip_call *call, Address src, Address dst); /** * @brief Check if a message is older than other @@ -122,4 +111,4 @@ stream_is_complete(rtp_stream_t *stream); int stream_is_active(rtp_stream_t *stream); -#endif /* __SNGREP_RTP_H */ +#endif /* __SNGREP_STREAM_H */