From 6fc0ccc5c2ac2f86f353562f68924c5af16f5994 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Sun, 3 Jan 2021 22:05:06 +0100 Subject: [PATCH] core: added loadmodulex - can evaluate the vars in the parameter - example #!define MYMOD async.so loadmodulex "$def(MYMOD)" --- src/core/cfg.lex | 2 ++ src/core/cfg.y | 8 ++++++++ src/core/sr_module.c | 24 ++++++++++++++++++++++++ src/core/sr_module.h | 1 + 4 files changed, 35 insertions(+) diff --git a/src/core/cfg.lex b/src/core/cfg.lex index 01e52182855..67fd519127a 100644 --- a/src/core/cfg.lex +++ b/src/core/cfg.lex @@ -488,6 +488,7 @@ ONSEND_RT_REPLY "onsend_route_reply" CFG_DESCRIPTION "description"|"descr"|"desc" LOADMODULE loadmodule +LOADMODULEX loadmodulex LOADPATH "loadpath"|"mpath" MODPARAM modparam MODPARAMX modparamx @@ -1002,6 +1003,7 @@ IMPORTFILE "import_file" {LATENCY_LIMIT_CFG} { count(); yylval.strval=yytext; return LATENCY_LIMIT_CFG;} {CFG_DESCRIPTION} { count(); yylval.strval=yytext; return CFG_DESCRIPTION; } {LOADMODULE} { count(); yylval.strval=yytext; return LOADMODULE; } +{LOADMODULEX} { count(); yylval.strval=yytext; return LOADMODULEX; } {LOADPATH} { count(); yylval.strval=yytext; return LOADPATH; } {MODPARAM} { count(); yylval.strval=yytext; return MODPARAM; } {MODPARAMX} { count(); yylval.strval=yytext; return MODPARAMX; } diff --git a/src/core/cfg.y b/src/core/cfg.y index 2a5804c3dd8..cc1b0e13e3b 100644 --- a/src/core/cfg.y +++ b/src/core/cfg.y @@ -401,6 +401,7 @@ extern char *default_routename; %token USER_AGENT_HEADER %token REPLY_TO_VIA %token LOADMODULE +%token LOADMODULEX %token LOADPATH %token MODPARAM %token MODPARAMX @@ -1850,6 +1851,13 @@ module_stm: } } | LOADMODULE error { yyerror("string expected"); } + | LOADMODULEX STRING { + LM_DBG("loading module %s\n", $2); + if (load_modulex($2)!=0) { + yyerror("failed to load module"); + } + } + | LOADMODULEX error { yyerror("string expected"); } | LOADPATH STRING { if(mods_dir_cmd==0) { LM_DBG("loading modules under %s\n", $2); diff --git a/src/core/sr_module.c b/src/core/sr_module.c index ba6406ba468..58624ea06ef 100644 --- a/src/core/sr_module.c +++ b/src/core/sr_module.c @@ -42,6 +42,7 @@ #include "rpc_lookup.h" #include "sr_compat.h" #include "ppcfg.h" +#include "fmsg.h" #include "async_task.h" #include "shm_init.h" @@ -611,6 +612,29 @@ int load_module(char* mod_path) return -1; } +/** + * + */ +int load_modulex(char* mod_path) +{ + str seval; + str sfmt; + sip_msg_t *fmsg; + char* emod; + + emod = mod_path; + if(strchr(mod_path, '$') != NULL) { + fmsg = faked_msg_get_next(); + sfmt.s = mod_path; + sfmt.len = strlen(sfmt.s); + if(pv_eval_str(fmsg, &seval, &sfmt)>=0) { + emod = seval.s; + } + } + + return load_module(emod); +} + /** * test if command flags are compatible with route block flags (type) * - decide if the command is allowed to run within a specific route block diff --git a/src/core/sr_module.h b/src/core/sr_module.h index 485c732bf7f..1d3150b3265 100644 --- a/src/core/sr_module.h +++ b/src/core/sr_module.h @@ -330,6 +330,7 @@ extern int mod_response_cbk_no; /**< size of reponse callbacks array */ int register_builtin_modules(void); int load_module(char* path); +int load_modulex(char* path); ksr_cmd_export_t* find_export_record(char* name, int param_no, int flags); cmd_function find_export(char* name, int param_no, int flags); cmd_function find_mod_export(char* mod, char* name, int param_no, int flags);