[sr-dev] git:master: topoh: update Replaces header

Daniel-Constantin Mierla miconda at gmail.com
Sun Dec 20 18:49:39 CET 2009


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Sun Dec 20 18:44:33 2009 +0100

topoh: update Replaces header

- case when call-id is masked

---

 modules/topoh/th_msg.c    |   67 +++++++++++++++++++++++++++++++++++++++++++++
 modules/topoh/th_msg.h    |    1 +
 modules/topoh/topoh_mod.c |    1 +
 3 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/modules/topoh/th_msg.c b/modules/topoh/th_msg.c
index 621f175..5304b1e 100644
--- a/modules/topoh/th_msg.c
+++ b/modules/topoh/th_msg.c
@@ -31,6 +31,7 @@
 #include "../../mem/mem.h"
 #include "../../data_lump.h"
 #include "../../forward.h"
+#include "../../trim.h"
 #include "../../msg_translator.h"
 #include "../../parser/parse_rr.h"
 #include "../../parser/parse_uri.h"
@@ -735,6 +736,72 @@ int th_unmask_refer_to(sip_msg_t *msg)
 	return 0;
 }
 
+int th_update_hdr_replaces(sip_msg_t *msg)
+{
+	struct hdr_field *hf = NULL;
+	str replaces;
+	str rcallid;
+	struct lump* l;
+	str out;
+
+	LM_DBG("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
+	if(th_param_mask_callid==0)
+		return 0;
+
+	if(!((get_cseq(msg)->method_id)&(METHOD_INVITE)))
+		return 0;
+
+	for (hf=msg->headers; hf; hf=hf->next)
+	{
+		if (hf->name.len==8 && strncasecmp(hf->name.s, "Replaces", 8)==0)
+			break;
+	}
+
+	if(hf==NULL)
+		return 0;
+
+	replaces = hf->body;
+	trim(&replaces);
+	rcallid.s = replaces.s;
+	for(rcallid.len=0; rcallid.len<replaces.len; rcallid.len++)
+	{
+		if(rcallid.s[rcallid.len]==';')
+			break;
+	}
+
+	if(rcallid.len>th_callid_prefix.len
+			&& strncmp(rcallid.s, th_callid_prefix.s, th_callid_prefix.len)==0)
+	{
+		/* value encoded - decode it */
+		out.s = th_mask_decode(rcallid.s, rcallid.len,
+					&th_callid_prefix, 0, &out.len);
+	} else {
+		/* value decoded - encode it */
+		out.s = th_mask_encode(rcallid.s, rcallid.len,
+				&th_callid_prefix, &out.len);
+	}
+	if(out.s==NULL)
+	{
+		LM_ERR("cannot update Replaces callid\n");
+		return -1;
+	}
+
+	l=del_lump(msg, rcallid.s-msg->buf, rcallid.len, 0);
+	if (l==0)
+	{
+		LM_ERR("failed deleting Replaces callid\n");
+		pkg_free(out.s);
+		return -1;
+	}
+	if (insert_new_lump_after(l, out.s, out.len, 0)==0) {
+		LM_ERR("could not insert new lump\n");
+		pkg_free(out.s);
+		return -1;
+	}
+
+	return 0;
+}
+
 char* th_msg_update(sip_msg_t *msg, unsigned int *olen)
 {
 	struct dest_info dst;
diff --git a/modules/topoh/th_msg.h b/modules/topoh/th_msg.h
index f965f9d..d74ec65 100644
--- a/modules/topoh/th_msg.h
+++ b/modules/topoh/th_msg.h
@@ -40,6 +40,7 @@ int th_flip_record_route(sip_msg_t *msg, int mode);
 int th_unmask_ruri(sip_msg_t *msg);
 int th_unmask_route(sip_msg_t *msg);
 int th_unmask_refer_to(sip_msg_t *msg);
+int th_update_hdr_replaces(sip_msg_t *msg);
 char* th_msg_update(sip_msg_t *msg, unsigned int *olen);
 int th_add_via_cookie(sip_msg_t *msg, struct via_body *via);
 int th_add_hdr_cookie(sip_msg_t *msg);
diff --git a/modules/topoh/topoh_mod.c b/modules/topoh/topoh_mod.c
index 8e5dd8b..b3c6cd0 100644
--- a/modules/topoh/topoh_mod.c
+++ b/modules/topoh/topoh_mod.c
@@ -315,6 +315,7 @@ int th_msg_sent(void *data)
 			}
 		} else {
 			/* initial request */
+			th_update_hdr_replaces(&msg);
 			th_mask_callid(&msg);
 		}
 	} else {




More information about the sr-dev mailing list