Prechádzať zdrojové kódy

core: new global parameter uri_host_extra_chars

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

uri_host_extra_chars = "_"
Daniel-Constantin Mierla 6 rokov pred
rodič
commit
038158c99d
4 zmenil súbory, kde vykonal 29 pridanie a 1 odobranie
  1. 3 0
      src/core/cfg.lex
  2. 3 0
      src/core/cfg.y
  3. 2 0
      src/core/globals.h
  4. 21 1
      src/core/parser/parse_uri.c

+ 3 - 0
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; }

+ 3 - 0
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 {

+ 2 - 0
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 */

+ 21 - 1
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:[email protected]: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;
 						}
 				}