浏览代码

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

- example
  #!define MYMOD async.so
  loadmodulex "$def(MYMOD)"
Daniel-Constantin Mierla 4 年之前
父节点
当前提交
6fc0ccc5c2
共有 4 个文件被更改,包括 35 次插入0 次删除
  1. 2 0
      src/core/cfg.lex
  2. 8 0
      src/core/cfg.y
  3. 24 0
      src/core/sr_module.c
  4. 1 0
      src/core/sr_module.h

+ 2 - 0
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; }

+ 8 - 0
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);

+ 24 - 0
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 @@ skip:
 	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

+ 1 - 0
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);