Module: sip-router
Branch: master
Commit: e9400dba371252edef970407be7b85dbe45e1ea3
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e9400db…
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
---
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 bd9cdaa..621f175 100644
--- a/modules/topoh/th_msg.c
+++ b/modules/topoh/th_msg.c
@@ -39,6 +39,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"
@@ -675,6 +676,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 092918b..f965f9d 100644
--- a/modules/topoh/th_msg.h
+++ b/modules/topoh/th_msg.h
@@ -39,6 +39,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 90d4c2e..8e5dd8b 100644
--- a/modules/topoh/topoh_mod.c
+++ b/modules/topoh/topoh_mod.c
@@ -222,6 +222,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);