Skip to content

Commit

Permalink
topoh: option to disable uri prefix checks
Browse files Browse the repository at this point in the history
- some devices do not copy the exact URI as received in headers
  (Contact, Record-Route) - they can add default port or mix parameters
- reported by GH #1165

(cherry picked from commit de3386e)
(cherry picked from commit a9d6ffa)
  • Loading branch information
miconda committed Aug 30, 2017
1 parent 78684f2 commit 01da668
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
23 changes: 14 additions & 9 deletions modules/topoh/th_msg.c
Expand Up @@ -57,6 +57,7 @@ extern str th_vparam_prefix;

extern int th_param_mask_callid;
extern int th_mask_addr_myself;
extern int th_uri_prefix_checks;

int th_skip_rw(char *s, int len)
{
Expand Down Expand Up @@ -391,8 +392,8 @@ int th_unmask_via(sip_msg_t *msg, str *cookie)
if(i!=1)
{
/* Skip if via is not encoded */
if (via->host.len!=th_ip.len
|| strncasecmp(via->host.s, th_ip.s, th_ip.len)!=0)
if (th_uri_prefix_checks && (via->host.len!=th_ip.len
|| strncasecmp(via->host.s, th_ip.s, th_ip.len)!=0))
{
LM_DBG("via %d is not encoded",i);
continue;
Expand Down Expand Up @@ -687,10 +688,13 @@ int th_unmask_route(sip_msg_t *msg)
if(i!=1)
{
/* Skip if route is not encoded */
if ((rr->nameaddr.uri.len<th_uri_prefix.len) ||
(strncasecmp(rr->nameaddr.uri.s,th_uri_prefix.s,th_uri_prefix.len)!=0))
if (th_uri_prefix_checks
&& ((rr->nameaddr.uri.len<th_uri_prefix.len) ||
(strncasecmp(rr->nameaddr.uri.s,th_uri_prefix.s,
th_uri_prefix.len)!=0)))
{
LM_DBG("rr %d is not encoded: [%.*s]",i,rr->nameaddr.uri.len,rr->nameaddr.uri.s);
LM_DBG("rr %d is not encoded: [%.*s]", i,
rr->nameaddr.uri.len, rr->nameaddr.uri.s);
rr = rr->next;
continue;
}
Expand Down Expand Up @@ -736,8 +740,9 @@ int th_unmask_ruri(sip_msg_t *msg)
str out;

/* Do nothing if ruri is not encoded */
if ((REQ_LINE(msg).uri.len<th_uri_prefix.len) ||
(strncasecmp(REQ_LINE(msg).uri.s,th_uri_prefix.s,th_uri_prefix.len)!=0))
if (th_uri_prefix_checks && ((REQ_LINE(msg).uri.len<th_uri_prefix.len) ||
(strncasecmp(REQ_LINE(msg).uri.s, th_uri_prefix.s,
th_uri_prefix.len)!=0)))
{
LM_DBG("ruri [%.*s] is not encoded",REQ_LINE(msg).uri.len,REQ_LINE(msg).uri.s);
return 0;
Expand Down Expand Up @@ -798,8 +803,8 @@ int th_unmask_refer_to(sip_msg_t *msg)
uri = &(get_refer_to(msg)->uri);

/* Do nothing if refer_to is not encoded */
if ((uri->len<th_uri_prefix.len)
|| (strncasecmp(uri->s, th_uri_prefix.s, th_uri_prefix.len)!=0))
if (th_uri_prefix_checks && ((uri->len<th_uri_prefix.len)
|| (strncasecmp(uri->s, th_uri_prefix.s, th_uri_prefix.len)!=0)))
{
LM_DBG("refer-to [%.*s] is not encoded",uri->len,uri->s);
return 0;
Expand Down
4 changes: 3 additions & 1 deletion modules/topoh/topoh_mod.c
Expand Up @@ -74,11 +74,12 @@ str th_uri_prefix = {0, 0};
int th_param_mask_callid = 0;

int th_sanity_checks = 0;
sanity_api_t scb;
int th_uri_prefix_checks = 0;
int th_mask_addr_myself = 0;

int th_msg_received(void *data);
int th_msg_sent(void *data);
sanity_api_t scb;

/** module functions */
static int mod_init(void);
Expand All @@ -93,6 +94,7 @@ static param_export_t params[]={
{"vparam_prefix", PARAM_STR, &th_vparam_prefix},
{"callid_prefix", PARAM_STR, &th_callid_prefix},
{"sanity_checks", PARAM_INT, &th_sanity_checks},
{"uri_prefix_checks", PARAM_INT, &th_uri_prefix_checks},
{0,0,0}
};

Expand Down

0 comments on commit 01da668

Please sign in to comment.