- print the config file by evaluating include_file, import_file, ifdef
and ifndef preprocessor directive
- define and subst (and the variants) tokens are not replaced
... | ... |
@@ -124,7 +124,7 @@ |
124 | 124 |
|
125 | 125 |
/* start conditions */ |
126 | 126 |
%x STRING1 STRING2 STR_BETWEEN COMMENT COMMENT_LN ATTR SELECT AVP_PVAR PVAR_P |
127 |
-%x PVARID INCLF IMPTF EVRTNAME |
|
127 |
+%x PVARID INCLF IMPTF EVRTNAME CFGPRINTMODE |
|
128 | 128 |
%x LINECOMMENT DEFINE_ID DEFINE_EOL DEFINE_DATA IFDEF_ID IFDEF_EOL IFDEF_SKIP |
129 | 129 |
|
130 | 130 |
/* config script types : #!SER or #!KAMAILIO or #!MAX_COMPAT */ |
... | ... |
@@ -670,11 +670,11 @@ IMPORTFILE "import_file" |
670 | 670 |
<INITIAL>{DEFAULT} { count(); yylval.strval=yytext; return DEFAULT; } |
671 | 671 |
<INITIAL>{WHILE} { count(); yylval.strval=yytext; return WHILE; } |
672 | 672 |
|
673 |
-<INITIAL>{INCLUDEFILE} { count(); BEGIN(INCLF); } |
|
674 |
-<INITIAL>{PREP_START}{INCLUDEFILE} { count(); BEGIN(INCLF); } |
|
673 |
+<INITIAL,CFGPRINTMODE>{INCLUDEFILE} { count(); BEGIN(INCLF); } |
|
674 |
+<INITIAL,CFGPRINTMODE>{PREP_START}{INCLUDEFILE} { count(); BEGIN(INCLF); } |
|
675 | 675 |
|
676 |
-<INITIAL>{IMPORTFILE} { count(); BEGIN(IMPTF); } |
|
677 |
-<INITIAL>{PREP_START}{IMPORTFILE} { count(); BEGIN(IMPTF); } |
|
676 |
+<INITIAL,CFGPRINTMODE>{IMPORTFILE} { count(); BEGIN(IMPTF); } |
|
677 |
+<INITIAL,CFGPRINTMODE>{PREP_START}{IMPORTFILE} { count(); BEGIN(IMPTF); } |
|
678 | 678 |
|
679 | 679 |
<INITIAL>{CFG_SELECT} { count(); yylval.strval=yytext; return CFG_SELECT; } |
680 | 680 |
<INITIAL>{CFG_RESET} { count(); yylval.strval=yytext; return CFG_RESET; } |
... | ... |
@@ -1267,6 +1267,10 @@ IMPORTFILE "import_file" |
1267 | 1267 |
<INITIAL>{COM_LINE}!{SER_CFG}{CR} { count(); |
1268 | 1268 |
sr_cfg_compat=SR_COMPAT_SER;} |
1269 | 1269 |
<INITIAL>{COM_LINE}!{KAMAILIO_CFG}{CR} { count(); |
1270 |
+ if(ksr_cfg_print_mode == 1) { |
|
1271 |
+ printf("%s", yytext); |
|
1272 |
+ BEGIN(CFGPRINTMODE); |
|
1273 |
+ } |
|
1270 | 1274 |
sr_cfg_compat=SR_COMPAT_KAMAILIO;} |
1271 | 1275 |
<INITIAL>{COM_LINE}!{MAXCOMPAT_CFG}{CR} { count(); |
1272 | 1276 |
sr_cfg_compat=SR_COMPAT_MAX;} |
... | ... |
@@ -1304,10 +1308,10 @@ IMPORTFILE "import_file" |
1304 | 1308 |
<INITIAL>{PREP_START}{SUBSTDEF} { count(); return SUBSTDEF;} |
1305 | 1309 |
<INITIAL>{PREP_START}{SUBSTDEFS} { count(); return SUBSTDEFS;} |
1306 | 1310 |
|
1307 |
-<INITIAL,IFDEF_SKIP>{PREP_START}{IFDEF}{EAT_ABLE}+ { count(); |
|
1311 |
+<INITIAL,CFGPRINTMODE,IFDEF_SKIP>{PREP_START}{IFDEF}{EAT_ABLE}+ { count(); |
|
1308 | 1312 |
if (pp_ifdef_type(1)) return 1; |
1309 | 1313 |
state = IFDEF_S; BEGIN(IFDEF_ID); } |
1310 |
-<INITIAL,IFDEF_SKIP>{PREP_START}{IFNDEF}{EAT_ABLE}+ { count(); |
|
1314 |
+<INITIAL,CFGPRINTMODE,IFDEF_SKIP>{PREP_START}{IFNDEF}{EAT_ABLE}+ { count(); |
|
1311 | 1315 |
if (pp_ifdef_type(0)) return 1; |
1312 | 1316 |
state = IFDEF_S; BEGIN(IFDEF_ID); } |
1313 | 1317 |
<IFDEF_ID>{ID}{MINUS} { count(); |
... | ... |
@@ -1321,9 +1325,9 @@ IMPORTFILE "import_file" |
1321 | 1325 |
state = IFDEF_EOL_S; BEGIN(IFDEF_EOL); } |
1322 | 1326 |
<IFDEF_EOL>{EAT_ABLE}*{CR} { count(); pp_ifdef(); } |
1323 | 1327 |
|
1324 |
-<INITIAL,IFDEF_SKIP>{PREP_START}{ELSE}{EAT_ABLE}*{CR} { count(); pp_else(); } |
|
1328 |
+<INITIAL,CFGPRINTMODE,IFDEF_SKIP>{PREP_START}{ELSE}{EAT_ABLE}*{CR} { count(); pp_else(); } |
|
1325 | 1329 |
|
1326 |
-<INITIAL,IFDEF_SKIP>{PREP_START}{ENDIF}{EAT_ABLE}*{CR} { count(); |
|
1330 |
+<INITIAL,CFGPRINTMODE,IFDEF_SKIP>{PREP_START}{ENDIF}{EAT_ABLE}*{CR} { count(); |
|
1327 | 1331 |
pp_endif(); } |
1328 | 1332 |
|
1329 | 1333 |
/* we're in an ifdef that evaluated to false -- throw it away */ |
... | ... |
@@ -1364,7 +1368,11 @@ IMPORTFILE "import_file" |
1364 | 1368 |
exit(-1); |
1365 | 1369 |
} |
1366 | 1370 |
memset(&s_buf, 0, sizeof(s_buf)); |
1367 |
- BEGIN(INITIAL); |
|
1371 |
+ if(ksr_cfg_print_mode == 1) { |
|
1372 |
+ BEGIN(CFGPRINTMODE); |
|
1373 |
+ } else { |
|
1374 |
+ BEGIN(INITIAL); |
|
1375 |
+ } |
|
1368 | 1376 |
} |
1369 | 1377 |
|
1370 | 1378 |
<IMPTF>[ \t]* /* eat the whitespace */ |
... | ... |
@@ -1378,9 +1386,15 @@ IMPORTFILE "import_file" |
1378 | 1386 |
exit(-1); |
1379 | 1387 |
} |
1380 | 1388 |
memset(&s_buf, 0, sizeof(s_buf)); |
1381 |
- BEGIN(INITIAL); |
|
1389 |
+ if(ksr_cfg_print_mode == 1) { |
|
1390 |
+ BEGIN(CFGPRINTMODE); |
|
1391 |
+ } else { |
|
1392 |
+ BEGIN(INITIAL); |
|
1393 |
+ } |
|
1382 | 1394 |
} |
1383 | 1395 |
|
1396 |
+<CFGPRINTMODE>.|{CR} { count(); printf("%s", yytext); } |
|
1397 |
+ |
|
1384 | 1398 |
|
1385 | 1399 |
<<EOF>> { |
1386 | 1400 |
switch(state){ |
... | ... |
@@ -1948,7 +1962,11 @@ static void pp_update_state() |
1948 | 1962 |
return; |
1949 | 1963 |
} |
1950 | 1964 |
|
1951 |
- state = INITIAL; BEGIN(INITIAL); |
|
1965 |
+ if(ksr_cfg_print_mode == 1) { |
|
1966 |
+ state = CFGPRINTMODE; BEGIN(CFGPRINTMODE); |
|
1967 |
+ } else { |
|
1968 |
+ state = INITIAL; BEGIN(INITIAL); |
|
1969 |
+ } |
|
1952 | 1970 |
} |
1953 | 1971 |
|
1954 | 1972 |
static void pp_ifdef() |
... | ... |
@@ -215,6 +215,7 @@ extern int ksr_route_locks_size; |
215 | 215 |
extern str _ksr_xavp_via_params; |
216 | 216 |
extern str _ksr_xavp_via_fields; |
217 | 217 |
extern int ksr_sip_parser_mode; |
218 |
+extern int ksr_cfg_print_mode; |
|
218 | 219 |
|
219 | 220 |
extern char *_sr_uri_host_extra_chars; |
220 | 221 |
extern unsigned char *_ksr_hname_extra_chars; |
... | ... |
@@ -533,6 +533,8 @@ char *sr_memmng_shm = NULL; |
533 | 533 |
|
534 | 534 |
static int *_sr_instance_started = NULL; |
535 | 535 |
|
536 |
+int ksr_cfg_print_mode = 0; |
|
537 |
+ |
|
536 | 538 |
/** |
537 | 539 |
* return 1 if all child processes were forked |
538 | 540 |
* - note: they might still be in init phase (i.e., child init) |
... | ... |
@@ -1933,6 +1935,7 @@ int main(int argc, char** argv) |
1933 | 1935 |
{"modparam", required_argument, 0, KARGOPTVAL + 6}, |
1934 | 1936 |
{"log-engine", required_argument, 0, KARGOPTVAL + 7}, |
1935 | 1937 |
{"debug", required_argument, 0, KARGOPTVAL + 8}, |
1938 |
+ {"cfg-print", no_argument, 0, KARGOPTVAL + 9}, |
|
1936 | 1939 |
{0, 0, 0, 0 } |
1937 | 1940 |
}; |
1938 | 1941 |
|
... | ... |
@@ -2003,6 +2006,9 @@ int main(int argc, char** argv) |
2003 | 2006 |
goto error; |
2004 | 2007 |
} |
2005 | 2008 |
break; |
2009 |
+ case KARGOPTVAL+9: |
|
2010 |
+ ksr_cfg_print_mode = 1; |
|
2011 |
+ break; |
|
2006 | 2012 |
|
2007 | 2013 |
default: |
2008 | 2014 |
if (c == 'h' || (optarg && strcmp(optarg, "-h") == 0)) { |
... | ... |
@@ -2165,6 +2171,7 @@ int main(int argc, char** argv) |
2165 | 2171 |
case KARGOPTVAL+6: |
2166 | 2172 |
case KARGOPTVAL+7: |
2167 | 2173 |
case KARGOPTVAL+8: |
2174 |
+ case KARGOPTVAL+9: |
|
2168 | 2175 |
break; |
2169 | 2176 |
|
2170 | 2177 |
/* long options */ |
... | ... |
@@ -2318,13 +2325,20 @@ try_again: |
2318 | 2325 |
|
2319 | 2326 |
yyin=cfg_stream; |
2320 | 2327 |
debug_save = default_core_cfg.debug; |
2321 |
- if ((yyparse()!=0)||(cfg_errors)||(pp_ifdef_level_check()<0)){ |
|
2322 |
- fprintf(stderr, "ERROR: bad config file (%d errors)\n", cfg_errors); |
|
2328 |
+ r = yyparse(); |
|
2329 |
+ if (ksr_cfg_print_mode == 1) { |
|
2330 |
+ /* printed evaluated content of config file based on include and ifdef */ |
|
2331 |
+ return 0; |
|
2332 |
+ } |
|
2333 |
+ if ((r!=0)||(cfg_errors)||(pp_ifdef_level_check()<0)){ |
|
2334 |
+ fprintf(stderr, "ERROR: bad config file (%d errors) (parsing code: %d)\n", |
|
2335 |
+ cfg_errors, r); |
|
2323 | 2336 |
if (debug_flag) default_core_cfg.debug = debug_save; |
2324 | 2337 |
pp_ifdef_level_error(); |
2325 | 2338 |
|
2326 | 2339 |
goto error; |
2327 | 2340 |
} |
2341 |
+ |
|
2328 | 2342 |
if (cfg_warnings){ |
2329 | 2343 |
fprintf(stderr, "%d config warnings\n", cfg_warnings); |
2330 | 2344 |
} |