hi

the patch below adds support for RTCP attribute in nathelper
module, please review and test.


nathelper will look for the SDP attribute called 'rtcp'. if
present, it will find the port of rtpproxy where the 'real'
rtcp data will arrive, and alter the rtcp attribute in the SDP.





Index: modules/nathelper/nathelper.c
===================================================================
RCS file: /cvsroot/ser/sip_router/modules/nathelper/nathelper.c,v
retrieving revision 1.134
diff -u -1 -r1.134 nathelper.c
--- modules/nathelper/nathelper.c       4 Nov 2008 22:24:12 -0000       1.134
+++ modules/nathelper/nathelper.c       6 Dec 2008 23:54:15 -0000
@@ -1133,2 +1133,27 @@
static int
+extract_rtcp(str *body, str *rtcpport)
+{
+       char *cp, *cp1;
+       int len;
+
+       cp1 = NULL;
+       for (cp = body->s; (len = body->s + body->len - cp) > 0;) {
+               cp1 = ser_memmem(cp, "a=rtcp:", len, 7);
+               if (cp1 == NULL || cp1[-1] == '\n' || cp1[-1] == '\r')
+                       break;
+               cp = cp1 + 7;
+       }
+
+       if (cp1 == NULL)
+               return -1;
+
+       rtcpport->s = cp1 + 7; /* skip `a=rtcp:' */
+       rtcpport->len = eat_line(rtcpport->s, body->s + body->len -
+                                rtcpport->s) - rtcpport->s;
+       trim_len(rtcpport->len, rtcpport->s, *rtcpport);
+
+       return 0;
+}
+
+static int
alter_mediaip(struct sip_msg *msg, str *body, str *oldip, int oldpf,
@@ -1322,2 +1347,36 @@

+static int
+alter_rtcp(struct sip_msg *msg, str *body, str *oldport, str *newport)
+{
+       char *buf;
+       int offset;
+       struct lump* anchor;
+
+       /* check that updating rtcpport is really necessary */
+       if (newport->len == oldport->len &&
+           memcmp(newport->s, oldport->s, newport->len) == 0)
+               return 0;
+
+       buf = pkg_malloc(newport->len);
+       if (buf == NULL) {
+               LOG(L_ERR, "ERROR: alter_rtcp: out of memory\n");
+               return -1;
+       }
+       offset = oldport->s - msg->buf;
+       anchor = del_lump(msg, offset, oldport->len, 0);
+       if (anchor == NULL) {
+               LOG(L_ERR, "ERROR: alter_rtcp: del_lump failed\n");
+               pkg_free(buf);
+               return -1;
+       }
+       memcpy(buf, newport->s, newport->len);
+       if (insert_new_lump_after(anchor, buf, newport->len, 0) == 0) {
+               LOG(L_ERR, "ERROR: alter_rtcp: insert_new_lump_after failed\n");
+               pkg_free(buf);
+               return -1;
+       }
+
+       return 0;
+}
+
static char *
@@ -1864,2 +1923,3 @@
        str callid, from_tag, to_tag, tmp, c1_oldip, payload_types;
+       str oldrtcp, newrtcp;
        int create, port, len, asymmetric, flookup, argc, proxied, real, i;
@@ -2128,2 +2188,9 @@
                        }
+                       /* Extract rtcp attribute */
+                       tmpstr1.s = m1p;
+                       tmpstr1.len = m2p - m1p;
+                       oldrtcp.s = NULL;
+                       oldrtcp.len = 0;
+                       extract_rtcp(&tmpstr1, &oldrtcp);
+
                        ++medianum;
@@ -2276,2 +2343,15 @@
                                if (alter_mediaport(msg, &body1, &oldport, 
&newport, 0) == -1)
+                                       return -1;
+                       }
+                       /*
+                        * Alter RTCP attribute if present. Inserting RTP port 
+ 1 (as allocated
+                        * by RTP proxy). No IP-address is needed in the new 
RTCP attribute as the
+                        * 'c' attribute (altered below) will contain the RTP 
proxy IP address.
+                        */
+                       if (oldrtcp.s && oldrtcp.len) {
+                               newrtcp.s = int2str(port+1, &newrtcp.len); /* 
beware static buffer */
+                               /* Alter port. */
+                               body1.s = m1p;
+                               body1.len = bodylimit - body1.s;
+                               if (alter_rtcp(msg, &body1, &oldrtcp, &newrtcp) 
== -1)
                                        return -1;
_______________________________________________
Serdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/serdev

Reply via email to