Browse code

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

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

Daniel-Constantin Mierla authored on 03/01/2021 21:05:06
Showing 4 changed files
... ...
@@ -488,6 +488,7 @@ ONSEND_RT_REPLY		"onsend_route_reply"
488 488
 CFG_DESCRIPTION		"description"|"descr"|"desc"
489 489
 
490 490
 LOADMODULE	loadmodule
491
+LOADMODULEX	loadmodulex
491 492
 LOADPATH	"loadpath"|"mpath"
492 493
 MODPARAM        modparam
493 494
 MODPARAMX        modparamx
... ...
@@ -1002,6 +1003,7 @@ IMPORTFILE      "import_file"
1002 1003
 <INITIAL>{LATENCY_LIMIT_CFG}  { count(); yylval.strval=yytext; return LATENCY_LIMIT_CFG;}
1003 1004
 <INITIAL>{CFG_DESCRIPTION}	{ count(); yylval.strval=yytext; return CFG_DESCRIPTION; }
1004 1005
 <INITIAL>{LOADMODULE}	{ count(); yylval.strval=yytext; return LOADMODULE; }
1006
+<INITIAL>{LOADMODULEX}	{ count(); yylval.strval=yytext; return LOADMODULEX; }
1005 1007
 <INITIAL>{LOADPATH}		{ count(); yylval.strval=yytext; return LOADPATH; }
1006 1008
 <INITIAL>{MODPARAM}     { count(); yylval.strval=yytext; return MODPARAM; }
1007 1009
 <INITIAL>{MODPARAMX}     { count(); yylval.strval=yytext; return MODPARAMX; }
... ...
@@ -401,6 +401,7 @@ extern char *default_routename;
401 401
 %token USER_AGENT_HEADER
402 402
 %token REPLY_TO_VIA
403 403
 %token LOADMODULE
404
+%token LOADMODULEX
404 405
 %token LOADPATH
405 406
 %token MODPARAM
406 407
 %token MODPARAMX
... ...
@@ -1850,6 +1851,13 @@ module_stm:
1850 1851
 			}
1851 1852
 	}
1852 1853
 	| LOADMODULE error	{ yyerror("string expected"); }
1854
+	| LOADMODULEX STRING {
1855
+		LM_DBG("loading module %s\n", $2);
1856
+			if (load_modulex($2)!=0) {
1857
+				yyerror("failed to load module");
1858
+			}
1859
+	}
1860
+	| LOADMODULEX error	{ yyerror("string expected"); }
1853 1861
 	| LOADPATH STRING {
1854 1862
 		if(mods_dir_cmd==0) {
1855 1863
 			LM_DBG("loading modules under %s\n", $2);
... ...
@@ -42,6 +42,7 @@
42 42
 #include "rpc_lookup.h"
43 43
 #include "sr_compat.h"
44 44
 #include "ppcfg.h"
45
+#include "fmsg.h"
45 46
 #include "async_task.h"
46 47
 #include "shm_init.h"
47 48
 
... ...
@@ -611,6 +612,29 @@ skip:
611 612
 	return -1;
612 613
 }
613 614
 
615
+/**
616
+ *
617
+ */
618
+int load_modulex(char* mod_path)
619
+{
620
+	str seval;
621
+	str sfmt;
622
+	sip_msg_t *fmsg;
623
+	char* emod;
624
+
625
+	emod = mod_path;
626
+	if(strchr(mod_path, '$') != NULL) {
627
+		fmsg = faked_msg_get_next();
628
+		sfmt.s = mod_path;
629
+		sfmt.len = strlen(sfmt.s);
630
+		if(pv_eval_str(fmsg, &seval, &sfmt)>=0) {
631
+			emod = seval.s;
632
+		}
633
+	}
634
+
635
+	return load_module(emod);
636
+}
637
+
614 638
 /**
615 639
  * test if command flags are compatible with route block flags (type)
616 640
  * - decide if the command is allowed to run within a specific route block
... ...
@@ -330,6 +330,7 @@ extern int mod_response_cbk_no; /**< size of reponse callbacks array */
330 330
 
331 331
 int register_builtin_modules(void);
332 332
 int load_module(char* path);
333
+int load_modulex(char* path);
333 334
 ksr_cmd_export_t* find_export_record(char* name, int param_no, int flags);
334 335
 cmd_function find_export(char* name, int param_no, int flags);
335 336
 cmd_function find_mod_export(char* mod, char* name, int param_no, int flags);