Module: kamailio Branch: master Commit: 94d1eecc618067bb04ed36deaf0ceee4e3bff06b URL: https://github.com/kamailio/kamailio/commit/94d1eecc618067bb04ed36deaf0ceee4...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2021-11-30T11:15:30+01:00
core: added #!defenvs preprocessor directive
- similar to #!defenv, but the value is enclosed in double quotes to make it covenient to be used as a string token
---
Modified: src/core/cfg.lex Modified: src/core/ppcfg.h
---
Diff: https://github.com/kamailio/kamailio/commit/94d1eecc618067bb04ed36deaf0ceee4... Patch: https://github.com/kamailio/kamailio/commit/94d1eecc618067bb04ed36deaf0ceee4...
---
diff --git a/src/core/cfg.lex b/src/core/cfg.lex index 06c87361a7..551cfab014 100644 --- a/src/core/cfg.lex +++ b/src/core/cfg.lex @@ -129,7 +129,7 @@
/* start conditions */ %x STRING1 STRING2 STR_BETWEEN COMMENT COMMENT_LN ATTR SELECT AVP_PVAR PVAR_P -%x PVARID INCLF IMPTF EVRTNAME CFGPRINTMODE CFGPRINTLOADMOD DEFENV_ID +%x PVARID INCLF IMPTF EVRTNAME CFGPRINTMODE CFGPRINTLOADMOD DEFENV_ID DEFENVS_ID %x LINECOMMENT DEFINE_ID DEFINE_EOL DEFINE_DATA IFDEF_ID IFDEF_EOL IFDEF_SKIP
/* config script types : #!SER or #!KAMAILIO or #!MAX_COMPAT */ @@ -565,6 +565,7 @@ ENDIF endif TRYDEF "trydefine"|"trydef" REDEF "redefine"|"redef" DEFENV defenv +DEFENVS defenvs
/* else is already defined */
@@ -1449,7 +1450,28 @@ IMPORTFILE "import_file" <DEFENV_ID>[^ \t\r\n]+ { /* get the define id of environment variable */ count(); ksr_cfg_print_part(yytext); - if(pp_define_env(yytext, yyleng) < 0) { + if(pp_define_env(yytext, yyleng, KSR_PPDEF_NORMAL) < 0) { + LM_CRIT("error at %s line %d\n", (finame)?finame:"cfg", line); + ksr_exit(-1); + } + state = INITIAL; + ksr_cfg_print_initial_state(); +} + +<INITIAL,CFGPRINTMODE>{PREP_START}{DEFENVS} { count(); + ksr_cfg_print_part(yytext); + state = DEFINE_S; + BEGIN(DEFENVS_ID); +} + +<DEFENVS_ID>[ \t]* { /* eat the whitespace */ + count(); + ksr_cfg_print_part(yytext); + } +<DEFENVS_ID>[^ \t\r\n]+ { /* get the define id of environment variable */ + count(); + ksr_cfg_print_part(yytext); + if(pp_define_env(yytext, yyleng, KSR_PPDEF_QUOTED) < 0) { LM_CRIT("error at %s line %d\n", (finame)?finame:"cfg", line); ksr_exit(-1); } @@ -2060,7 +2082,7 @@ int pp_define_set(int len, char *text, int mode) return 0; }
-int pp_define_env(const char *text, int len) +int pp_define_env(const char *text, int len, int qmode) { char *r; str defname; @@ -2093,7 +2115,7 @@ int pp_define_env(const char *text, int len) LM_ERR("cannot set define name [%s]\n", (char*)text); return -1; } - if(pp_define_set(defvalue.len, defvalue.s, KSR_PPDEF_NORMAL)<0) { + if(pp_define_set(defvalue.len, defvalue.s, qmode)<0) { LM_ERR("cannot set define value [%s]\n", (char*)text); return -1; } diff --git a/src/core/ppcfg.h b/src/core/ppcfg.h index 17b19380bc..a8d27f7083 100644 --- a/src/core/ppcfg.h +++ b/src/core/ppcfg.h @@ -45,7 +45,7 @@ int pp_define(int len, const char *text); int pp_define_set(int len, char *text, int mode); int pp_define_set_type(int type); str *pp_define_get(int len, const char * text); -int pp_define_env(const char * text, int len); +int pp_define_env(const char * text, int len, int qmode);
void pp_ifdef_level_update(int val); int pp_ifdef_level_check(void);