[sr-dev] git:kamailio_3.0: modules/mediaproxy: properly fix the IP in the RTCP line

Juha Heinanen jh at tutpro.com
Thu Feb 11 21:27:41 CET 2010


Module: sip-router
Branch: kamailio_3.0
Commit: ef10212404b9bc5489683fc7429fee40b3495994
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ef10212404b9bc5489683fc7429fee40b3495994

Author: Juha Heinanen <jh at tutpro.com>
Committer: Juha Heinanen <jh at tutpro.com>
Date:   Thu Feb 11 22:22:12 2010 +0200

modules/mediaproxy: properly fix the IP in the RTCP line

- Properly fix the IP in the RTCP line (if present in the SDP). Patch
  provided by Saul Ibarra Corretge.
(cherry picked from commit 2a95f9bf915cfc3cf11374f9b8f0f547d4eb4955)

---

 modules/mediaproxy/mediaproxy.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/modules/mediaproxy/mediaproxy.c b/modules/mediaproxy/mediaproxy.c
index 3f44595..bf4764e 100644
--- a/modules/mediaproxy/mediaproxy.c
+++ b/modules/mediaproxy/mediaproxy.c
@@ -128,6 +128,7 @@ typedef struct {
     str type;      // stream type (`audio', `video', `image', ...)
     str ip;
     str port;
+    str rtcp_ip;   // pointer to the rtcp IP if explicitly specified by stream
     str rtcp_port; // pointer to the rtcp port if explicitly specified by stream
     str direction;
     Bool local_ip; // true if the IP is locally defined inside this media stream
@@ -872,6 +873,34 @@ get_rtcp_port_attribute(str *block)
 }
 
 
+// will return the rtcp IP of the stream in the given block
+// if defined by the stream, otherwise will return {NULL, 0}.
+static str
+get_rtcp_ip_attribute(str *block)
+{
+    str zone, tokens[4], undefined = {NULL, 0};
+    char *ptr;
+    int count;
+
+    ptr = find_line_starting_with(block, "a=rtcp:", False);
+
+    if (!ptr)
+        return undefined;
+
+    zone.s = ptr + 7;
+    zone.len = findendline(zone.s, block->s + block->len - zone.s) - zone.s;
+
+    count = get_str_tokens(&zone, tokens, 4);
+
+    if (count != 4) {
+        LM_ERR("invalid `a=rtcp' line in SDP body\n");
+        return undefined;
+    }
+
+    return tokens[3];
+}
+
+
 // will return the ip address present in a `c=' line in the given block
 // returns: -1 on error, 0 if not found, 1 if found
 static int
@@ -1118,6 +1147,7 @@ get_session_info(str *sdp, SessionInfo *session)
             session->streams[i].local_ip = 1;
         }
 
+        session->streams[i].rtcp_ip = get_rtcp_ip_attribute(&block);
         session->streams[i].rtcp_port = get_rtcp_port_attribute(&block);
         session->streams[i].direction = get_direction_attribute(&block, &session->direction);
     }
@@ -1536,6 +1566,13 @@ use_media_proxy(struct sip_msg *msg, char *dialog_id)
             }
         }
 
+        if (stream.rtcp_ip.len > 0) {
+            if (!replace_element(msg, &stream.rtcp_ip, &tokens[0])) {
+                LM_ERR("failed to replace RTCP IP in media stream number %d\n", i+1);
+                return -1;
+            }
+        }
+
         if (stream.local_ip && !isnulladdr(stream.ip)) {
             if (!replace_element(msg, &stream.ip, &tokens[0])) {
                 LM_ERR("failed to replace IP address in media stream number %d\n", i+1);




More information about the sr-dev mailing list