Browse code

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.

Juha Heinanen authored on 11/02/2010 20:22:12
Showing 1 changed files
... ...
@@ -128,6 +128,7 @@ typedef struct {
128 128
     str type;      // stream type (`audio', `video', `image', ...)
129 129
     str ip;
130 130
     str port;
131
+    str rtcp_ip;   // pointer to the rtcp IP if explicitly specified by stream
131 132
     str rtcp_port; // pointer to the rtcp port if explicitly specified by stream
132 133
     str direction;
133 134
     Bool local_ip; // true if the IP is locally defined inside this media stream
... ...
@@ -872,6 +873,34 @@ get_rtcp_port_attribute(str *block)
872 873
 }
873 874
 
874 875
 
876
+// will return the rtcp IP of the stream in the given block
877
+// if defined by the stream, otherwise will return {NULL, 0}.
878
+static str
879
+get_rtcp_ip_attribute(str *block)
880
+{
881
+    str zone, tokens[4], undefined = {NULL, 0};
882
+    char *ptr;
883
+    int count;
884
+
885
+    ptr = find_line_starting_with(block, "a=rtcp:", False);
886
+
887
+    if (!ptr)
888
+        return undefined;
889
+
890
+    zone.s = ptr + 7;
891
+    zone.len = findendline(zone.s, block->s + block->len - zone.s) - zone.s;
892
+
893
+    count = get_str_tokens(&zone, tokens, 4);
894
+
895
+    if (count != 4) {
896
+        LM_ERR("invalid `a=rtcp' line in SDP body\n");
897
+        return undefined;
898
+    }
899
+
900
+    return tokens[3];
901
+}
902
+
903
+
875 904
 // will return the ip address present in a `c=' line in the given block
876 905
 // returns: -1 on error, 0 if not found, 1 if found
877 906
 static int
... ...
@@ -1118,6 +1147,7 @@ get_session_info(str *sdp, SessionInfo *session)
1118 1147
             session->streams[i].local_ip = 1;
1119 1148
         }
1120 1149
 
1150
+        session->streams[i].rtcp_ip = get_rtcp_ip_attribute(&block);
1121 1151
         session->streams[i].rtcp_port = get_rtcp_port_attribute(&block);
1122 1152
         session->streams[i].direction = get_direction_attribute(&block, &session->direction);
1123 1153
     }
... ...
@@ -1536,6 +1566,13 @@ use_media_proxy(struct sip_msg *msg, char *dialog_id)
1536 1566
             }
1537 1567
         }
1538 1568
 
1569
+        if (stream.rtcp_ip.len > 0) {
1570
+            if (!replace_element(msg, &stream.rtcp_ip, &tokens[0])) {
1571
+                LM_ERR("failed to replace RTCP IP in media stream number %d\n", i+1);
1572
+                return -1;
1573
+            }
1574
+        }
1575
+
1539 1576
         if (stream.local_ip && !isnulladdr(stream.ip)) {
1540 1577
             if (!replace_element(msg, &stream.ip, &tokens[0])) {
1541 1578
                 LM_ERR("failed to replace IP address in media stream number %d\n", i+1);