Browse code

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 authored on 26/03/2013 22:45:50
Showing 1 changed files
... ...
@@ -64,6 +64,7 @@
64 64
 #include "globals.h"
65 65
 #include "rpc_lookup.h"
66 66
 #include "sr_compat.h"
67
+#include "ppcfg.h"
67 68
 
68 69
 #include <sys/stat.h>
69 70
 #include <regex.h>
... ...
@@ -271,6 +272,7 @@ static int register_module(unsigned ver, union module_exports_u* e,
271 271
 {
272 272
 	int ret, i;
273 273
 	struct sr_module* mod;
274
+	char defmod[64];
274 275
 
275 276
 	ret=-1;
276 277
 
... ...
@@ -366,6 +368,20 @@ static int register_module(unsigned ver, union module_exports_u* e,
366 366
 		/* i==0 => success */
367 367
 	}
368 368
 
369
+	/* add cfg define for each module: MOD_modulename */
370
+	if(strlen(mod->exports.name)>=60) {
371
+		LM_ERR("too long module name: %s\n", mod->exports.name);
372
+		goto error;
373
+	}
374
+	strcpy(defmod, "MOD_");
375
+	strcat(defmod, mod->exports.name);
376
+	pp_define_set_type(0);
377
+	if(pp_define(strlen(defmod), defmod)<0) {
378
+		LM_ERR("unable to set cfg define for module: %s\n",
379
+				mod->exports.name);
380
+		goto error;
381
+	}
382
+
369 383
 	/* link module in the list */
370 384
 	mod->next=modules;
371 385
 	modules=mod;