Selaa lähdekoodia

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)
(cherry picked from commit ef10212404b9bc5489683fc7429fee40b3495994)
Juha Heinanen 15 vuotta sitten
vanhempi
commit
c80f76803d
1 muutettua tiedostoa jossa 37 lisäystä ja 0 poistoa
  1. 37 0
      modules/mediaproxy/mediaproxy.c

+ 37 - 0
modules/mediaproxy/mediaproxy.c

@@ -127,6 +127,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
@@ -827,6 +828,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
@@ -1073,6 +1102,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);
     }
@@ -1491,6 +1521,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);