Prechádzať zdrojové kódy

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)
Juha Heinanen 15 rokov pred
rodič
commit
ef10212404
1 zmenil súbory, kde vykonal 37 pridanie a 0 odobranie
  1. 37 0
      modules/mediaproxy/mediaproxy.c

+ 37 - 0
modules/mediaproxy/mediaproxy.c

@@ -128,6 +128,7 @@ typedef struct {
     str type;      // stream type (`audio', `video', `image', ...)
     str type;      // stream type (`audio', `video', `image', ...)
     str ip;
     str ip;
     str port;
     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 rtcp_port; // pointer to the rtcp port if explicitly specified by stream
     str direction;
     str direction;
     Bool local_ip; // true if the IP is locally defined inside this media stream
     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
 // 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
 // returns: -1 on error, 0 if not found, 1 if found
 static int
 static int
@@ -1118,6 +1147,7 @@ get_session_info(str *sdp, SessionInfo *session)
             session->streams[i].local_ip = 1;
             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].rtcp_port = get_rtcp_port_attribute(&block);
         session->streams[i].direction = get_direction_attribute(&block, &session->direction);
         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 (stream.local_ip && !isnulladdr(stream.ip)) {
             if (!replace_element(msg, &stream.ip, &tokens[0])) {
             if (!replace_element(msg, &stream.ip, &tokens[0])) {
                 LM_ERR("failed to replace IP address in media stream number %d\n", i+1);
                 LM_ERR("failed to replace IP address in media stream number %d\n", i+1);