[sr-dev] git:master:038158c9: core: new global parameter uri_host_extra_chars

Daniel-Constantin Mierla miconda at gmail.com
Thu Oct 10 14:32:03 CEST 2019


Module: kamailio
Branch: master
Commit: 038158c99da96933c26b11a919ed1cbe29af9fab
URL: https://github.com/kamailio/kamailio/commit/038158c99da96933c26b11a919ed1cbe29af9fab

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2019-10-10T14:25:43+02:00

core: new global parameter uri_host_extra_chars

- allow specifying additional chars to be allowed in host part
- example:

uri_host_extra_chars = "_"

---

Modified: src/core/cfg.lex
Modified: src/core/cfg.y
Modified: src/core/globals.h
Modified: src/core/parser/parse_uri.c

---

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

---

diff --git a/src/core/cfg.lex b/src/core/cfg.lex
index a640bd158f..25671d1127 100644
--- a/src/core/cfg.lex
+++ b/src/core/cfg.lex
@@ -470,6 +470,8 @@ LATENCY_LIMIT_DB		latency_limit_db
 LATENCY_LIMIT_ACTION	latency_limit_action
 LATENCY_LIMIT_CFG		latency_limit_cfg
 
+URI_HOST_EXTRA_CHARS	"uri_host_extra_chars"
+
 MSG_TIME	msg_time
 ONSEND_RT_REPLY		"onsend_route_reply"
 CFG_DESCRIPTION		"description"|"descr"|"desc"
@@ -980,6 +982,7 @@ IMPORTFILE      "import_file"
 <INITIAL>{LOADPATH}		{ count(); yylval.strval=yytext; return LOADPATH; }
 <INITIAL>{MODPARAM}     { count(); yylval.strval=yytext; return MODPARAM; }
 <INITIAL>{CFGENGINE}	{ count(); yylval.strval=yytext; return CFGENGINE; }
+<INITIAL>{URI_HOST_EXTRA_CHARS}	{ yylval.strval=yytext; return URI_HOST_EXTRA_CHARS; }
 
 <INITIAL>{EQUAL}	{ count(); return EQUAL; }
 <INITIAL>{ADDEQ}          { count(); return ADDEQ; }
diff --git a/src/core/cfg.y b/src/core/cfg.y
index 0042af8327..56a8c9ab8c 100644
--- a/src/core/cfg.y
+++ b/src/core/cfg.y
@@ -503,6 +503,7 @@ extern char *default_routename;
 %token LATENCY_LIMIT_CFG
 %token MSG_TIME
 %token ONSEND_RT_REPLY
+%token URI_HOST_EXTRA_CHARS
 
 %token FLAGS_DECL
 %token AVPFLAGS_DECL
@@ -1437,6 +1438,8 @@ assign_stm:
 			user_agent_hdr.len=strlen(user_agent_hdr.s);
 	}
 	| USER_AGENT_HEADER EQUAL error { yyerror("string value expected"); }
+	| URI_HOST_EXTRA_CHARS EQUAL STRING { _sr_uri_host_extra_chars=$3; }
+	| URI_HOST_EXTRA_CHARS EQUAL error { yyerror("string value expected"); }
 	| REPLY_TO_VIA EQUAL NUMBER { reply_to_via=$3; }
 	| REPLY_TO_VIA EQUAL error { yyerror("boolean value expected"); }
 	| LISTEN EQUAL id_lst {
diff --git a/src/core/globals.h b/src/core/globals.h
index 2149eeccd6..81fad0b284 100644
--- a/src/core/globals.h
+++ b/src/core/globals.h
@@ -215,6 +215,8 @@ extern int ksr_route_locks_size;
 extern str _ksr_xavp_via_params;
 extern str _ksr_xavp_via_fields;
 
+extern char *_sr_uri_host_extra_chars;
+
 #ifdef USE_DNS_CACHE
 extern int dns_cache_init; /* if 0, the DNS cache is not initialized at startup */
 extern unsigned int dns_timer_interval; /* gc timer interval in s */
diff --git a/src/core/parser/parse_uri.c b/src/core/parser/parse_uri.c
index dbf5a7f9f7..ec39ea7cf2 100644
--- a/src/core/parser/parse_uri.c
+++ b/src/core/parser/parse_uri.c
@@ -37,6 +37,25 @@
 static char _sr_uri_empty_buf[2] = {0};
 static str _sr_uri_empty = { _sr_uri_empty_buf, 0 };
 
+/* extra chars that should be allowed in URI host */
+char *_sr_uri_host_extra_chars = "";
+
+int uri_host_char_allowed(char c)
+{
+	int i = 0;
+
+	if(_sr_uri_host_extra_chars==NULL || _sr_uri_host_extra_chars[0]=='\0') {
+		return 0;
+	}
+	while(_sr_uri_host_extra_chars[i]!='\0') {
+		if(_sr_uri_host_extra_chars[i]==c) {
+			return 1;
+		}
+		i++;
+	}
+	return 0;
+}
+
 /* buf= pointer to begining of uri (sip:x at foo.bar:5060;a=b?h=i)
  * len= len of uri
  * returns: fills uri & returns <0 on error or 0 if ok
@@ -542,7 +561,8 @@ int parse_uri(char* buf, int len, struct sip_uri* uri)
 				switch(*p) {
 					check_host_end;
 					default:
-						if(!isalnum(*p) && (*p != '.') && (*p != '-')) {
+						if(!isalnum(*p) && (*p != '.') && (*p != '-')
+								&& !uri_host_char_allowed(*p)) {
 							goto error_bad_host;
 						}
 				}




More information about the sr-dev mailing list