Browse code

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

Daniel-Constantin Mierla authored on 30/11/2021 10:10:43
Showing 2 changed files
... ...
@@ -129,7 +129,7 @@
129 129
 
130 130
 /* start conditions */
131 131
 %x STRING1 STRING2 STR_BETWEEN COMMENT COMMENT_LN ATTR SELECT AVP_PVAR PVAR_P
132
-%x PVARID INCLF IMPTF EVRTNAME CFGPRINTMODE CFGPRINTLOADMOD DEFENV_ID
132
+%x PVARID INCLF IMPTF EVRTNAME CFGPRINTMODE CFGPRINTLOADMOD DEFENV_ID DEFENVS_ID
133 133
 %x LINECOMMENT DEFINE_ID DEFINE_EOL DEFINE_DATA IFDEF_ID IFDEF_EOL IFDEF_SKIP
134 134
 
135 135
 /* config script types : #!SER  or #!KAMAILIO or #!MAX_COMPAT */
... ...
@@ -565,6 +565,7 @@ ENDIF        endif
565 565
 TRYDEF       "trydefine"|"trydef"
566 566
 REDEF        "redefine"|"redef"
567 567
 DEFENV       defenv
568
+DEFENVS      defenvs
568 569
 
569 570
 /* else is already defined */
570 571
 
... ...
@@ -1449,7 +1450,28 @@ IMPORTFILE      "import_file"
1449 1450
 <DEFENV_ID>[^ \t\r\n]+   { /* get the define id of environment variable */
1450 1451
 				count();
1451 1452
 				ksr_cfg_print_part(yytext);
1452
-				if(pp_define_env(yytext, yyleng) < 0) {
1453
+				if(pp_define_env(yytext, yyleng, KSR_PPDEF_NORMAL) < 0) {
1454
+					LM_CRIT("error at %s line %d\n", (finame)?finame:"cfg", line);
1455
+					ksr_exit(-1);
1456
+				}
1457
+				state = INITIAL;
1458
+				ksr_cfg_print_initial_state();
1459
+}
1460
+
1461
+<INITIAL,CFGPRINTMODE>{PREP_START}{DEFENVS}  { count();
1462
+			ksr_cfg_print_part(yytext);
1463
+			state = DEFINE_S;
1464
+			BEGIN(DEFENVS_ID);
1465
+}
1466
+
1467
+<DEFENVS_ID>[ \t]*      { /* eat the whitespace */
1468
+				count();
1469
+				ksr_cfg_print_part(yytext);
1470
+			}
1471
+<DEFENVS_ID>[^ \t\r\n]+   { /* get the define id of environment variable */
1472
+				count();
1473
+				ksr_cfg_print_part(yytext);
1474
+				if(pp_define_env(yytext, yyleng, KSR_PPDEF_QUOTED) < 0) {
1453 1475
 					LM_CRIT("error at %s line %d\n", (finame)?finame:"cfg", line);
1454 1476
 					ksr_exit(-1);
1455 1477
 				}
... ...
@@ -2060,7 +2082,7 @@ int pp_define_set(int len, char *text, int mode)
2060 2082
 	return 0;
2061 2083
 }
2062 2084
 
2063
-int pp_define_env(const char *text, int len)
2085
+int pp_define_env(const char *text, int len, int qmode)
2064 2086
 {
2065 2087
 	char *r;
2066 2088
 	str defname;
... ...
@@ -2093,7 +2115,7 @@ int pp_define_env(const char *text, int len)
2093 2115
 		LM_ERR("cannot set define name [%s]\n", (char*)text);
2094 2116
 		return -1;
2095 2117
 	}
2096
-	if(pp_define_set(defvalue.len, defvalue.s, KSR_PPDEF_NORMAL)<0) {
2118
+	if(pp_define_set(defvalue.len, defvalue.s, qmode)<0) {
2097 2119
 		LM_ERR("cannot set define value [%s]\n", (char*)text);
2098 2120
 		return -1;
2099 2121
 	}
... ...
@@ -45,7 +45,7 @@ int  pp_define(int len, const char *text);
45 45
 int  pp_define_set(int len, char *text, int mode);
46 46
 int  pp_define_set_type(int type);
47 47
 str *pp_define_get(int len, const char * text);
48
-int  pp_define_env(const char * text, int len);
48
+int  pp_define_env(const char * text, int len, int qmode);
49 49
 
50 50
 void pp_ifdef_level_update(int val);
51 51
 int pp_ifdef_level_check(void);