From 1d0cb4c0d0ad517d82b6900abdc4c399d84021e2 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 11 Apr 2013 14:58:02 -0400 Subject: [PATCH] incorporate received= escaping fixes --- modules_k/path/Makefile | 3 +++ modules_k/path/path.c | 22 ++++++++++++++++------ modules_k/registrar/path.c | 19 +++++++++++++++++-- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/modules_k/path/Makefile b/modules_k/path/Makefile index a9aa7f12d..26d784fe9 100644 --- a/modules_k/path/Makefile +++ b/modules_k/path/Makefile @@ -12,4 +12,7 @@ LIBS= DEFS+=-DKAMAILIO_MOD_INTERFACE +SERLIBPATH=../../lib +SER_LIBS+=$(SERLIBPATH)/kcore/kcore + include ../../Makefile.modules diff --git a/modules_k/path/path.c b/modules_k/path/path.c index 2d182cee6..f5bc54a5b 100644 --- a/modules_k/path/path.c +++ b/modules_k/path/path.c @@ -36,6 +36,7 @@ #include "../../mem/mem.h" #include "../../data_lump.h" #include "../../parser/parse_param.h" +#include "../../lib/kcore/strcommon.h" #include "../../dset.h" #include "../../sr_module.h" @@ -46,9 +47,9 @@ #define PATH_PREFIX_LEN (sizeof(PATH_PREFIX)-1) const static char *proto_strings[] = { - [PROTO_TCP] = ";transport=tcp", - [PROTO_TLS] = ";transport=tls", - [PROTO_SCTP] = ";transport=sctp", + [PROTO_TCP] = "%3Btransport%3Dtcp", + [PROTO_TLS] = "%3Btransport%3Dtls", + [PROTO_SCTP] = "%3Btransport%3Dsctp", }; static int prepend_path(struct sip_msg* _m, str *user, int recv, str *parms) @@ -59,7 +60,7 @@ static int prepend_path(struct sip_msg* _m, str *user, int recv, str *parms) int prefix_len, suffix_len; struct hdr_field *hf; - suffix_len = strlen(";lr;received='sip::12345;transport=sctp';>\r\n") + suffix_len = strlen(";lr;received=sip::12345%3Btransport%3Dsctp;>\r\n") + IP_ADDR_MAX_STR_SIZE + (parms ? parms->len : 0) + 1; cp = suffix = pkg_malloc(suffix_len); if (!suffix) { @@ -75,7 +76,7 @@ static int prepend_path(struct sip_msg* _m, str *user, int recv, str *parms) else proto_str = NULL; - cp += sprintf(cp, ";received='sip:%s:%hu%s'", ip_addr2a(&_m->rcv.src_ip), + cp += sprintf(cp, ";received=sip:%s:%hu%s", ip_addr2a(&_m->rcv.src_ip), _m->rcv.src_port, proto_str ? : ""); } @@ -167,6 +168,8 @@ void path_rr_callback(struct sip_msg *_m, str *r_param, void *cb_param) { param_hooks_t hooks; param_t *params; + static char dst_uri_buf[MAX_URI_SIZE]; + static str dst_uri; if (parse_params(r_param, CLASS_CONTACT, &hooks, ¶ms) != 0) { LM_ERR("failed to parse route parameters\n"); @@ -174,7 +177,14 @@ void path_rr_callback(struct sip_msg *_m, str *r_param, void *cb_param) } if (hooks.contact.received) { - if (set_dst_uri(_m, &hooks.contact.received->body) != 0) { + dst_uri.s = dst_uri_buf; + dst_uri.len = MAX_URI_SIZE; + if (unescape_user(&(hooks.contact.received->body), &dst_uri) < 0) { + LM_ERR("unescaping received failed\n"); + free_params(params); + return; + } + if (set_dst_uri(_m, &dst_uri) != 0) { LM_ERR("failed to set dst-uri\n"); free_params(params); return; diff --git a/modules_k/registrar/path.c b/modules_k/registrar/path.c index a4fd48545..cefd59af4 100644 --- a/modules_k/registrar/path.c +++ b/modules_k/registrar/path.c @@ -32,15 +32,19 @@ #include "../../data_lump.h" #include "../../parser/parse_rr.h" #include "../../parser/parse_uri.h" +#include "../../lib/kcore/strcommon.h" #include "path.h" #include "reg_mod.h" + /*! \brief * Combines all Path HF bodies into one string. */ int build_path_vector(struct sip_msg *_m, str *path, str *received) { static char buf[MAX_PATH_SIZE]; + static char uri_buf[MAX_URI_SIZE]; + static str uri_str; char *p; struct hdr_field *hdr; struct sip_uri puri; @@ -92,8 +96,18 @@ int build_path_vector(struct sip_msg *_m, str *path, str *received) LM_ERR("failed to parse parameters of first hop\n"); goto error; } - if (hooks.contact.received) - *received = hooks.contact.received->body; + + if (hooks.contact.received) { + uri_str.s = uri_buf; + uri_str.len = MAX_URI_SIZE; + if (unescape_user(&(hooks.contact.received->body), &uri_str) < 0) { + LM_ERR("unescaping received failed\n"); + goto error; + } + *received = uri_str; + LM_DBG("received is <%.*s>\n", received->len, received->s); + } + /*for (;params; params = params->next) { if (params->type == P_RECEIVED) { *received = hooks.contact.received->body; @@ -107,6 +121,7 @@ int build_path_vector(struct sip_msg *_m, str *path, str *received) path->s = buf; path->len = p-buf; + LM_DBG("path is <%.*s>\n", path->len, path->s); return 0; error: if(route) free_rr(&route);