Skip to content

Commit

Permalink
core: added global parameter hdr_name_extra_chars
Browse files Browse the repository at this point in the history
- allow specifying additional chars to be allowed in header names
  • Loading branch information
miconda committed Jul 23, 2020
1 parent ddcabc1 commit 74e42e6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/core/cfg.lex
Expand Up @@ -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"
Expand Down Expand Up @@ -989,6 +990,7 @@ IMPORTFILE "import_file"
<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>{HDR_NAME_EXTRA_CHARS} { yylval.strval=yytext; return HDR_NAME_EXTRA_CHARS; }

<INITIAL>{EQUAL} { count(); return EQUAL; }
<INITIAL>{ADDEQ} { count(); return ADDEQ; }
Expand Down
3 changes: 3 additions & 0 deletions src/core/cfg.y
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/core/globals.h
Expand Up @@ -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;

Expand Down
21 changes: 20 additions & 1 deletion src/core/parser/parse_hname2.c
Expand Up @@ -156,14 +156,19 @@ 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
*/
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)
{
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/core/parser/parse_hname2.h
Expand Up @@ -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 */
2 changes: 2 additions & 0 deletions src/main.c
Expand Up @@ -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 */

Expand Down

0 comments on commit 74e42e6

Please sign in to comment.