From 74e42e684d46f7918e1c64ed1378fd64c83a60c4 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Thu, 23 Jul 2020 08:51:30 +0200 Subject: [PATCH] core: added global parameter hdr_name_extra_chars - allow specifying additional chars to be allowed in header names --- src/core/cfg.lex | 2 ++ src/core/cfg.y | 3 +++ src/core/globals.h | 1 + src/core/parser/parse_hname2.c | 21 ++++++++++++++++++++- src/core/parser/parse_hname2.h | 1 + src/main.c | 2 ++ 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/core/cfg.lex b/src/core/cfg.lex index f84e9c03bb8..d5ac31ddd83 100644 --- a/src/core/cfg.lex +++ b/src/core/cfg.lex @@ -474,6 +474,7 @@ LATENCY_LIMIT_ACTION latency_limit_action LATENCY_LIMIT_CFG latency_limit_cfg URI_HOST_EXTRA_CHARS "uri_host_extra_chars" +HDR_NAME_EXTRA_CHARS "hdr_name_extra_chars" MSG_TIME msg_time ONSEND_RT_REPLY "onsend_route_reply" @@ -989,6 +990,7 @@ IMPORTFILE "import_file" {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; } +{HDR_NAME_EXTRA_CHARS} { yylval.strval=yytext; return HDR_NAME_EXTRA_CHARS; } {EQUAL} { count(); return EQUAL; } {ADDEQ} { count(); return ADDEQ; } diff --git a/src/core/cfg.y b/src/core/cfg.y index 0c3ba68e72f..6eccec29bda 100644 --- a/src/core/cfg.y +++ b/src/core/cfg.y @@ -507,6 +507,7 @@ extern char *default_routename; %token MSG_TIME %token ONSEND_RT_REPLY %token URI_HOST_EXTRA_CHARS +%token HDR_NAME_EXTRA_CHARS %token FLAGS_DECL %token AVPFLAGS_DECL @@ -1447,6 +1448,8 @@ assign_stm: | 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"); } + | HDR_NAME_EXTRA_CHARS EQUAL STRING { _ksr_hname_extra_chars=$3; } + | HDR_NAME_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 afa2e78c3e0..413e8f23745 100644 --- a/src/core/globals.h +++ b/src/core/globals.h @@ -216,6 +216,7 @@ extern str _ksr_xavp_via_params; extern str _ksr_xavp_via_fields; extern char *_sr_uri_host_extra_chars; +extern char *_ksr_hname_extra_chars; extern char *ksr_stats_namesep; diff --git a/src/core/parser/parse_hname2.c b/src/core/parser/parse_hname2.c index 5afae157696..a4fdca3e37e 100644 --- a/src/core/parser/parse_hname2.c +++ b/src/core/parser/parse_hname2.c @@ -156,6 +156,11 @@ static ksr_hdr_map_idx_t _ksr_hdr_map_idx[KSR_HDR_MAP_IDX_SIZE]; */ static char *_ksr_hname_chars_list = "0123456789AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz-._+~"; +/** + * additional valid chars in header names (core param) + */ +char *_ksr_hname_extra_chars = ""; + /** * indexed valid chars in 256-array for 1-byte-index access check */ @@ -163,7 +168,7 @@ static char _ksr_hname_chars_idx[KSR_HDR_MAP_IDX_SIZE]; /** - * init header name parsing structures and indexes + * init header name parsing structures and indexes at very beginning of start up */ int ksr_hname_init_index(void) { @@ -195,6 +200,20 @@ int ksr_hname_init_index(void) return 0; } +/** + * init header name parsing structures and indexes after config parsing + */ +int ksr_hname_init_config(void) +{ + int i; + + for(i=0; _ksr_hname_extra_chars[i] != 0; i++) { + _ksr_hname_chars_idx[_ksr_hname_extra_chars[i]] = 1; + } + + return 0; +} + /** * parse the sip header name in the buffer starting at 'begin' till before 'end' * - fills hdr structure (must not be null) diff --git a/src/core/parser/parse_hname2.h b/src/core/parser/parse_hname2.h index 90cf2c9c4e2..9eef0bb53e4 100644 --- a/src/core/parser/parse_hname2.h +++ b/src/core/parser/parse_hname2.h @@ -39,5 +39,6 @@ char* parse_hname2(char* const begin, const char* const end, struct hdr_field* c char* parse_hname2_short(char* const begin, const char* const end, struct hdr_field* const hdr); int ksr_hname_init_index(void); +int ksr_hname_init_config(void); #endif /* PARSE_HNAME2_H */ diff --git a/src/main.c b/src/main.c index ea7e1b43e1a..b2a2040631d 100644 --- a/src/main.c +++ b/src/main.c @@ -2545,6 +2545,8 @@ int main(int argc, char** argv) /* init lookup for core event routes */ sr_core_ert_init(); + ksr_hname_init_config(); + if (dont_fork_cnt) dont_fork = dont_fork_cnt; /* override by command line */