Module: sip-router
Branch: master
Commit: 978ec2fb51751529953eadec653772edd5dc1ccd
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=978ec2fb51751529953eadec653772edd5dc1ccd

Author: Richard Fuchs <[email protected]>
Committer: Richard Fuchs <[email protected]>
Date:   Wed Aug 29 15:47:10 2012 -0400

modules_k/nathelper: fix a= lines inserted out of order

RFC 4566 dictates a particular order of fields in the SDP body, in particular
media-specific a= lines must be last fields within an m= block. Inserting
them right after the m= lines violates this order if other fields (such as
c=) are present, causing parse errors in some clients. So instead, insert
them at the end of each m= block.

---

 modules_k/nathelper/nathelper.c |   15 +++++----------
 1 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/modules_k/nathelper/nathelper.c b/modules_k/nathelper/nathelper.c
index c27d073..7b13010 100644
--- a/modules_k/nathelper/nathelper.c
+++ b/modules_k/nathelper/nathelper.c
@@ -1393,7 +1393,7 @@ fix_nated_sdp_f(struct sip_msg* msg, char* str1, char* 
str2)
        str body;
        str ip;
        int level, rest_len;
-       char *buf, *m_start, *m_end, *rest_s;
+       char *buf, *m_start, *m_end;
        struct lump* anchor;
 
        level = (int)(long)str1;
@@ -1412,13 +1412,11 @@ fix_nated_sdp_f(struct sip_msg* msg, char* str1, char* 
str2)
                if (level & ADD_ADIRECTION) {
                    m_start = ser_memmem(body.s, "\r\nm=", body.len, 4);
                    while (m_start != NULL) {
-                       m_start = m_start + 2;
+                       m_start += 4;
                        rest_len = body.len - (m_start - body.s);
-                       m_end = ser_memmem(m_start, "\r\n", rest_len, 2);
-                       if (m_end == NULL) {
-                           LM_ERR("m line is not crlf terminated\n");
-                           return -1;
-                       }
+                       m_start = m_end = ser_memmem(m_start, "\r\nm=", 
rest_len, 4);
+                       if (!m_end)
+                               m_end = body.s + body.len; /* just before the 
final \r\n */
                        anchor = anchor_lump(msg, m_end - msg->buf, 0, 0);
                        if (anchor == NULL) {
                            LM_ERR("anchor_lump failed\n");
@@ -1436,9 +1434,6 @@ fix_nated_sdp_f(struct sip_msg* msg, char* str1, char* 
str2)
                            pkg_free(buf);
                            return -1;
                        }
-                       rest_s = m_end + 2;
-                       rest_len = body.len - (rest_s - body.s);
-                       m_start = ser_memmem(rest_s, "\r\nm=", rest_len, 4);
                    }
                }
 


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to