stream: old rtp code is now known as stream

This commit is contained in:
Kaian 2018-04-20 23:45:14 +02:00
parent c734e6e407
commit 71eec87ac6
8 changed files with 82 additions and 91 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -32,7 +32,7 @@
#include <stdarg.h>
#include <stdbool.h>
#include <glib.h>
#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 */

View File

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

View File

@ -34,7 +34,7 @@
#include <stddef.h>
#include <time.h>
#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)

View File

@ -20,17 +20,17 @@
**
****************************************************************************/
/**
* @file rtp.h
* @file stream.h
* @author Ivan Alonso [aka Kaian] <kaian@irontec.com>
*
* @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 */