Jelajahi Sumber

core: auto-define cfg directive MOD_modname for each loaded module

- example: if acc module is loaded, MOD_acc is defined in cfg
- suggestion by Olle E. Johansson
Daniel-Constantin Mierla 12 tahun lalu
induk
melakukan
14525efb68
1 mengubah file dengan 16 tambahan dan 0 penghapusan
  1. 16 0
      sr_module.c

+ 16 - 0
sr_module.c

@@ -64,6 +64,7 @@
 #include "globals.h"
 #include "globals.h"
 #include "rpc_lookup.h"
 #include "rpc_lookup.h"
 #include "sr_compat.h"
 #include "sr_compat.h"
+#include "ppcfg.h"
 
 
 #include <sys/stat.h>
 #include <sys/stat.h>
 #include <regex.h>
 #include <regex.h>
@@ -271,6 +272,7 @@ static int register_module(unsigned ver, union module_exports_u* e,
 {
 {
 	int ret, i;
 	int ret, i;
 	struct sr_module* mod;
 	struct sr_module* mod;
+	char defmod[64];
 
 
 	ret=-1;
 	ret=-1;
 
 
@@ -366,6 +368,20 @@ static int register_module(unsigned ver, union module_exports_u* e,
 		/* i==0 => success */
 		/* i==0 => success */
 	}
 	}
 
 
+	/* add cfg define for each module: MOD_modulename */
+	if(strlen(mod->exports.name)>=60) {
+		LM_ERR("too long module name: %s\n", mod->exports.name);
+		goto error;
+	}
+	strcpy(defmod, "MOD_");
+	strcat(defmod, mod->exports.name);
+	pp_define_set_type(0);
+	if(pp_define(strlen(defmod), defmod)<0) {
+		LM_ERR("unable to set cfg define for module: %s\n",
+				mod->exports.name);
+		goto error;
+	}
+
 	/* link module in the list */
 	/* link module in the list */
 	mod->next=modules;
 	mod->next=modules;
 	modules=mod;
 	modules=mod;