- this is at parsing level, not handled by cfg interpreter, so the
modules are not effectively loaded
... | ... |
@@ -119,12 +119,13 @@ |
119 | 119 |
static void pp_else(); |
120 | 120 |
static void pp_endif(); |
121 | 121 |
static void ksr_cfg_print_part(char *text); |
122 |
+ static void ksr_cfg_print_define_module(char *modpath, int modpathlen); |
|
122 | 123 |
|
123 | 124 |
%} |
124 | 125 |
|
125 | 126 |
/* start conditions */ |
126 | 127 |
%x STRING1 STRING2 STR_BETWEEN COMMENT COMMENT_LN ATTR SELECT AVP_PVAR PVAR_P |
127 |
-%x PVARID INCLF IMPTF EVRTNAME CFGPRINTMODE |
|
128 |
+%x PVARID INCLF IMPTF EVRTNAME CFGPRINTMODE CFGPRINTLOADMOD |
|
128 | 129 |
%x LINECOMMENT DEFINE_ID DEFINE_EOL DEFINE_DATA IFDEF_ID IFDEF_EOL IFDEF_SKIP |
129 | 130 |
|
130 | 131 |
/* config script types : #!SER or #!KAMAILIO or #!MAX_COMPAT */ |
... | ... |
@@ -1257,15 +1258,20 @@ IMPORTFILE "import_file" |
1257 | 1258 |
return STRING; |
1258 | 1259 |
} |
1259 | 1260 |
|
1260 |
-<INITIAL,COMMENT>{COM_START} { count(); comment_nest++; state=COMMENT_S; |
|
1261 |
- BEGIN(COMMENT); } |
|
1262 |
-<COMMENT>{COM_END} { count(); comment_nest--; |
|
1263 |
- if (comment_nest==0){ |
|
1264 |
- state=INITIAL_S; |
|
1265 |
- BEGIN(INITIAL); |
|
1266 |
- } |
|
1261 |
+<INITIAL,CFGPRINTMODE,COMMENT>{COM_START} { count(); |
|
1262 |
+ ksr_cfg_print_part(yytext); |
|
1263 |
+ comment_nest++; state=COMMENT_S; |
|
1264 |
+ BEGIN(COMMENT); |
|
1265 |
+ } |
|
1266 |
+<COMMENT>{COM_END} { count(); |
|
1267 |
+ ksr_cfg_print_part(yytext); |
|
1268 |
+ comment_nest--; |
|
1269 |
+ if (comment_nest==0){ |
|
1270 |
+ state=INITIAL_S; |
|
1271 |
+ ksr_cfg_print_initial_state(); |
|
1272 |
+ } |
|
1267 | 1273 |
} |
1268 |
-<COMMENT>.|{EAT_ABLE}|{CR} { count(); }; |
|
1274 |
+<COMMENT>.|{EAT_ABLE}|{CR} { count(); ksr_cfg_print_part(yytext); }; |
|
1269 | 1275 |
|
1270 | 1276 |
<INITIAL>{COM_LINE}!{SER_CFG}{CR} { count(); |
1271 | 1277 |
sr_cfg_compat=SR_COMPAT_SER;} |
... | ... |
@@ -1349,9 +1355,16 @@ IMPORTFILE "import_file" |
1349 | 1355 |
<IFDEF_SKIP>.|{CR} { count(); } |
1350 | 1356 |
|
1351 | 1357 |
/* this is split so the shebangs match more, giving them priority */ |
1352 |
-<INITIAL>{COM_LINE} { count(); state = LINECOMMENT_S; |
|
1353 |
- BEGIN(LINECOMMENT); } |
|
1354 |
-<LINECOMMENT>.*{CR} { count(); state = INITIAL_S; BEGIN(INITIAL); } |
|
1358 |
+<INITIAL,CFGPRINTMODE>{COM_LINE} { count(); |
|
1359 |
+ ksr_cfg_print_part(yytext); |
|
1360 |
+ state = LINECOMMENT_S; |
|
1361 |
+ BEGIN(LINECOMMENT); |
|
1362 |
+ } |
|
1363 |
+<LINECOMMENT>.*{CR} { count(); |
|
1364 |
+ ksr_cfg_print_part(yytext); |
|
1365 |
+ state = INITIAL_S; |
|
1366 |
+ ksr_cfg_print_initial_state(); |
|
1367 |
+ } |
|
1355 | 1368 |
|
1356 | 1369 |
<INITIAL>{ID} { if ((sdef = pp_define_get(yyleng, yytext))!=NULL) { |
1357 | 1370 |
for (r=sdef->len-1; r>=0; r--) |
... | ... |
@@ -1400,9 +1413,21 @@ IMPORTFILE "import_file" |
1400 | 1413 |
ksr_cfg_print_initial_state(); |
1401 | 1414 |
} |
1402 | 1415 |
|
1416 |
+<CFGPRINTMODE>{LOADMODULE} { count(); printf("%s", yytext); |
|
1417 |
+ BEGIN(CFGPRINTLOADMOD); |
|
1418 |
+ } |
|
1403 | 1419 |
<CFGPRINTMODE>.|{CR} { count(); printf("%s", yytext); } |
1404 | 1420 |
|
1405 | 1421 |
|
1422 |
+<CFGPRINTLOADMOD>[ \t]* { /* eat the whitespace */ |
|
1423 |
+ count(); printf("%s", yytext); |
|
1424 |
+ } |
|
1425 |
+<CFGPRINTLOADMOD>[^ \t\r\n]+ { /* get the module name */ |
|
1426 |
+ count(); printf("%s", yytext); |
|
1427 |
+ ksr_cfg_print_define_module(yytext, yyleng); |
|
1428 |
+ ksr_cfg_print_initial_state(); |
|
1429 |
+} |
|
1430 |
+ |
|
1406 | 1431 |
<<EOF>> { |
1407 | 1432 |
switch(state){ |
1408 | 1433 |
case STR_BETWEEN_S: |
... | ... |
@@ -1460,6 +1485,54 @@ static void ksr_cfg_print_part(char *text) |
1460 | 1485 |
} |
1461 | 1486 |
} |
1462 | 1487 |
|
1488 |
+static void ksr_cfg_print_define_module(char *modpath, int modpathlen) |
|
1489 |
+{ |
|
1490 |
+ char defmod[64]; |
|
1491 |
+ str modname; |
|
1492 |
+ char *p; |
|
1493 |
+ |
|
1494 |
+ modname.s = modpath; |
|
1495 |
+ modname.len = modpathlen; |
|
1496 |
+ |
|
1497 |
+ if(modname.len <= 2) { |
|
1498 |
+ return; |
|
1499 |
+ } |
|
1500 |
+ if(modname.s[0] == '\'' && modname.s[modname.len - 1] == '\'') { |
|
1501 |
+ modname.s++; |
|
1502 |
+ modname.len -= 2; |
|
1503 |
+ } else if(modname.s[0] == '"' && modname.s[modname.len - 1] == '"') { |
|
1504 |
+ modname.s++; |
|
1505 |
+ modname.len -= 2; |
|
1506 |
+ } |
|
1507 |
+ |
|
1508 |
+ if(modname.len>3 && strncmp(modname.s + modname.len-3, ".so", 3)==0) { |
|
1509 |
+ modname.len -= 3; |
|
1510 |
+ } |
|
1511 |
+ if (strchr(modpath, '/')) { |
|
1512 |
+ /* only the name */ |
|
1513 |
+ p = modname.s + modname.len - 1; |
|
1514 |
+ modname.len = 0; |
|
1515 |
+ while(p>=modname.s && *p!='/') { |
|
1516 |
+ p--; |
|
1517 |
+ modname.len++; |
|
1518 |
+ } |
|
1519 |
+ modname.s = p + 1; |
|
1520 |
+ } |
|
1521 |
+ |
|
1522 |
+ /* add cfg define for each module: MOD_modulename */ |
|
1523 |
+ if(modname.len >= 60) { |
|
1524 |
+ printf("\n# ***** ERROR: too long module name: %s\n", modpath); |
|
1525 |
+ return; |
|
1526 |
+ } |
|
1527 |
+ memcpy(defmod, "MOD_", 4); |
|
1528 |
+ memcpy(defmod+4, modname.s, modname.len); |
|
1529 |
+ pp_define_set_type(0); |
|
1530 |
+ if(pp_define(modname.len + 4, defmod)<0) { |
|
1531 |
+ printf("\n# ***** ERROR: unable to set cfg define for module: %s\n", |
|
1532 |
+ modpath); |
|
1533 |
+ } |
|
1534 |
+} |
|
1535 |
+ |
|
1463 | 1536 |
void ksr_cfg_print_initial_state(void) |
1464 | 1537 |
{ |
1465 | 1538 |
if(ksr_cfg_print_mode == 1) { |