From 038158c99da96933c26b11a919ed1cbe29af9fab Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Thu, 10 Oct 2019 14:25:43 +0200 Subject: [PATCH] core: new global parameter uri_host_extra_chars - allow specifying additional chars to be allowed in host part - example: uri_host_extra_chars = "_" --- src/core/cfg.lex | 3 +++ src/core/cfg.y | 3 +++ src/core/globals.h | 2 ++ src/core/parser/parse_uri.c | 22 +++++++++++++++++++++- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/core/cfg.lex b/src/core/cfg.lex index a640bd158fd..25671d11271 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" {LOADPATH} { count(); yylval.strval=yytext; return LOADPATH; } {MODPARAM} { count(); yylval.strval=yytext; return MODPARAM; } {CFGENGINE} { count(); yylval.strval=yytext; return CFGENGINE; } +{URI_HOST_EXTRA_CHARS} { yylval.strval=yytext; return URI_HOST_EXTRA_CHARS; } {EQUAL} { count(); return EQUAL; } {ADDEQ} { count(); return ADDEQ; } diff --git a/src/core/cfg.y b/src/core/cfg.y index 0042af83274..56a8c9ab8c9 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 2149eeccd62..81fad0b2848 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 dbf5a7f9f76..ec39ea7cf29 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@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; } }