[sr-dev] git:5.0:a9d6ffa5: topoh: option to disable uri prefix checks

Daniel-Constantin Mierla miconda at gmail.com
Sun Jun 25 10:11:35 CEST 2017


Module: kamailio
Branch: 5.0
Commit: a9d6ffa5f39e048642bf14129b9b484250cce3ae
URL: https://github.com/kamailio/kamailio/commit/a9d6ffa5f39e048642bf14129b9b484250cce3ae

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-06-25T10:10:58+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)

---

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

---

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

---

diff --git a/src/modules/topoh/th_msg.c b/src/modules/topoh/th_msg.c
index a1f117e316..24bb32e185 100644
--- a/src/modules/topoh/th_msg.c
+++ b/src/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/src/modules/topoh/topoh_mod.c b/src/modules/topoh/topoh_mod.c
index 5eb7490b85..4ff52f6e0a 100644
--- a/src/modules/topoh/topoh_mod.c
+++ b/src/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}
 };
 




More information about the sr-dev mailing list