Module: sip-router
Branch: kamailio_3.0
Commit: 0583dc249d72b36fe93763542e861d881fb0830f
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0583dc2…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Sun Dec 20 17:50:51 2009 +0100
topoh: code to update Refer-to URI
(cherry picked from commit e9400dba371252edef970407be7b85dbe45e1ea3)
---
modules/topoh/th_msg.c | 60 +++++++++++++++++++++++++++++++++++++++++++++
modules/topoh/th_msg.h | 1 +
modules/topoh/topoh_mod.c | 1 +
3 files changed, 62 insertions(+), 0 deletions(-)
diff --git a/modules/topoh/th_msg.c b/modules/topoh/th_msg.c
index 5a4837c..db0de77 100644
--- a/modules/topoh/th_msg.c
+++ b/modules/topoh/th_msg.c
@@ -32,6 +32,7 @@
#include "../../parser/parse_to.h"
#include "../../parser/parse_via.h"
#include "../../parser/contact/parse_contact.h"
+#include "../../parser/parse_refer_to.h"
#include "th_mask.h"
#include "th_msg.h"
@@ -668,6 +669,65 @@ int th_unmask_ruri(sip_msg_t *msg)
return 0;
}
+int th_unmask_refer_to(sip_msg_t *msg)
+{
+ str eval;
+ str *uri;
+ int ulen;
+ struct lump* l;
+ str out;
+
+ if(!((get_cseq(msg)->method_id)&(METHOD_REFER)))
+ return 0;
+
+ if(parse_refer_to_header(msg)==-1)
+ {
+ LM_DBG("no Refer-To header\n");
+ return 0;
+ }
+ if(msg->refer_to==NULL || get_refer_to(msg)==NULL)
+ {
+ LM_DBG("Refer-To header not found\n");
+ return 0;
+ }
+
+ uri = &(get_refer_to(msg)->uri);
+ if(th_get_uri_param_value(uri, &th_uparam_name, &eval)<0
+ || eval.len<=0)
+ return -1;
+
+ out.s = th_mask_decode(eval.s, eval.len,
+ &th_uparam_prefix, 0, &out.len);
+ if(out.s==NULL)
+ {
+ LM_ERR("cannot decode r-uri\n");
+ return -1;
+ }
+
+ LM_DBG("+decoded: %d: [%.*s]\n", out.len, out.len, out.s);
+ for(ulen=0; ulen<uri->len; ulen++)
+ {
+ if(uri->s[ulen]=='?')
+ break;
+ }
+
+ l=del_lump(msg, uri->s-msg->buf, ulen, 0);
+ if (l==0)
+ {
+ LM_ERR("failed deleting r-uri\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 6e1fd99..b68f63b 100644
--- a/modules/topoh/th_msg.h
+++ b/modules/topoh/th_msg.h
@@ -32,6 +32,7 @@ int th_unmask_callid(sip_msg_t *msg);
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);
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 4b341dd..5fb092b 100644
--- a/modules/topoh/topoh_mod.c
+++ b/modules/topoh/topoh_mod.c
@@ -207,6 +207,7 @@ int th_msg_received(void *data)
/* dialog request */
th_unmask_ruri(&msg);
th_unmask_route(&msg);
+ th_unmask_refer_to(&msg);
if(direction==1)
{
th_unmask_callid(&msg);