Module: kamailio
Branch: 4.4
Commit: 01da6686c00aefb930067bfcb8310cf869278527
URL: 
https://github.com/kamailio/kamailio/commit/01da6686c00aefb930067bfcb8310cf869278527

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2017-08-30T13:07:27+02:00

topoh: option to disable uri prefix checks

- 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 de3386e4a303adecc3eee809c05e0654b7a05065)
(cherry picked from commit a9d6ffa5f39e048642bf14129b9b484250cce3ae)

---

Modified: modules/topoh/th_msg.c
Modified: modules/topoh/topoh_mod.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/01da6686c00aefb930067bfcb8310cf869278527.diff
Patch: 
https://github.com/kamailio/kamailio/commit/01da6686c00aefb930067bfcb8310cf869278527.patch

---

diff --git a/modules/topoh/th_msg.c b/modules/topoh/th_msg.c
index 1d4287f44a..5519b8daac 100644
--- a/modules/topoh/th_msg.c
+++ b/modules/topoh/th_msg.c
@@ -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)
 {
@@ -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;
@@ -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;
                                }
@@ -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;
@@ -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;
diff --git a/modules/topoh/topoh_mod.c b/modules/topoh/topoh_mod.c
index 266cc465a8..9742cef143 100644
--- a/modules/topoh/topoh_mod.c
+++ b/modules/topoh/topoh_mod.c
@@ -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);
@@ -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}
 };
 


_______________________________________________
Kamailio (SER) - Development Mailing List
[email protected]
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to