[sr-dev] git:master:6fc0ccc5: core: added loadmodulex - can evaluate the vars in the parameter

Daniel-Constantin Mierla miconda at gmail.com
Mon Jan 4 10:42:49 CET 2021


Module: kamailio
Branch: master
Commit: 6fc0ccc5c2ac2f86f353562f68924c5af16f5994
URL: https://github.com/kamailio/kamailio/commit/6fc0ccc5c2ac2f86f353562f68924c5af16f5994

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-01-04T10:05:06+01:00

core: added loadmodulex - can evaluate the vars in the parameter

- example
  #!define MYMOD async.so
  loadmodulex "$def(MYMOD)"

---

Modified: src/core/cfg.lex
Modified: src/core/cfg.y
Modified: src/core/sr_module.c
Modified: src/core/sr_module.h

---

Diff:  https://github.com/kamailio/kamailio/commit/6fc0ccc5c2ac2f86f353562f68924c5af16f5994.diff
Patch: https://github.com/kamailio/kamailio/commit/6fc0ccc5c2ac2f86f353562f68924c5af16f5994.patch

---

diff --git a/src/core/cfg.lex b/src/core/cfg.lex
index 01e5218285..67fd519127 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"
 <INITIAL>{LATENCY_LIMIT_CFG}  { count(); yylval.strval=yytext; return LATENCY_LIMIT_CFG;}
 <INITIAL>{CFG_DESCRIPTION}	{ count(); yylval.strval=yytext; return CFG_DESCRIPTION; }
 <INITIAL>{LOADMODULE}	{ count(); yylval.strval=yytext; return LOADMODULE; }
+<INITIAL>{LOADMODULEX}	{ count(); yylval.strval=yytext; return LOADMODULEX; }
 <INITIAL>{LOADPATH}		{ count(); yylval.strval=yytext; return LOADPATH; }
 <INITIAL>{MODPARAM}     { count(); yylval.strval=yytext; return MODPARAM; }
 <INITIAL>{MODPARAMX}     { count(); yylval.strval=yytext; return MODPARAMX; }
diff --git a/src/core/cfg.y b/src/core/cfg.y
index 2a5804c3dd..cc1b0e13e3 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 ba6406ba46..58624ea06e 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 485c732bf7..1d3150b326 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);




More information about the sr-dev mailing list