[sr-dev] git:master: modules_k/nathelper: fix_nated_sdp("1") fix
Juha Heinanen
jh at tutpro.com
Tue Sep 20 08:55:33 CEST 2011
Module: sip-router
Branch: master
Commit: 4b220639cb255a20bac762fd60e36a4336339a45
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=4b220639cb255a20bac762fd60e36a4336339a45
Author: Juha Heinanen <jh at tutpro.com>
Committer: Juha Heinanen <jh at tutpro.com>
Date: Tue Sep 20 09:46:53 2011 +0300
modules_k/nathelper: fix_nated_sdp("1") fix
- Call fix_nated_sdp("1") now adds a=direction:active line after every
m line in sdp. Earlier it just added one a=direction:active line at
the end of body.
---
modules_k/nathelper/nathelper.c | 44 ++++++++++++++++++++++++++++----------
1 files changed, 32 insertions(+), 12 deletions(-)
diff --git a/modules_k/nathelper/nathelper.c b/modules_k/nathelper/nathelper.c
index a7186d7..f734a8d 100644
--- a/modules_k/nathelper/nathelper.c
+++ b/modules_k/nathelper/nathelper.c
@@ -1352,8 +1352,8 @@ fix_nated_sdp_f(struct sip_msg* msg, char* str1, char* str2)
{
str body;
str ip;
- int level;
- char *buf;
+ int level, rest_len;
+ char *buf, *m_start, *m_end, *rest_s;
struct lump* anchor;
level = (int)(long)str1;
@@ -1366,28 +1366,48 @@ fix_nated_sdp_f(struct sip_msg* msg, char* str1, char* str2)
}
if (level & (ADD_ADIRECTION | ADD_ANORTPPROXY)) {
+
msg->msg_flags |= FL_FORCE_ACTIVE;
- anchor = anchor_lump(msg, body.s + body.len - msg->buf, 0, 0);
- if (anchor == NULL) {
- LM_ERR("anchor_lump failed\n");
- return -1;
- }
+
if (level & ADD_ADIRECTION) {
+ m_start = ser_memmem(body.s, "\r\nm=", body.len, 4);
+ while (m_start != NULL) {
+ m_start = m_start + 2;
+ 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;
+ }
+ anchor = anchor_lump(msg, m_end - msg->buf, 0, 0);
+ if (anchor == NULL) {
+ LM_ERR("anchor_lump failed\n");
+ return -1;
+ }
buf = pkg_malloc((ADIRECTION_LEN + CRLF_LEN) * sizeof(char));
if (buf == NULL) {
- LM_ERR("out of pkg memory\n");
- return -1;
+ LM_ERR("out of pkg memory\n");
+ return -1;
}
memcpy(buf, CRLF, CRLF_LEN);
memcpy(buf + CRLF_LEN, ADIRECTION, ADIRECTION_LEN);
if (insert_new_lump_after(anchor, buf, ADIRECTION_LEN + CRLF_LEN, 0) == NULL) {
- LM_ERR("insert_new_lump_after failed\n");
- pkg_free(buf);
- return -1;
+ LM_ERR("insert_new_lump_after failed\n");
+ 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);
+ }
}
if ((level & ADD_ANORTPPROXY) && nortpproxy_str.len) {
+ anchor = anchor_lump(msg, body.s + body.len - msg->buf, 0, 0);
+ if (anchor == NULL) {
+ LM_ERR("anchor_lump failed\n");
+ return -1;
+ }
buf = pkg_malloc((nortpproxy_str.len + CRLF_LEN) * sizeof(char));
if (buf == NULL) {
LM_ERR("out of pkg memory\n");
More information about the sr-dev
mailing list