From 8b89857bfaca58d04c19b31a73f1d7d8575940db Mon Sep 17 00:00:00 2001 From: pk910 Date: Sun, 12 Feb 2012 23:34:12 +0100 Subject: [PATCH] added modules to neonserv.example.conf and added protected as a module setting --- neonserv.example.conf | 27 +++++++++++++++++++++++++++ src/modules.c | 31 +++++++++++++++++++++---------- src/modules.h | 5 +++-- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/neonserv.example.conf b/neonserv.example.conf index 334d730..5be3085 100644 --- a/neonserv.example.conf +++ b/neonserv.example.conf @@ -52,3 +52,30 @@ */ "loglevel" = 3; }; +"modules" { + "libglobalcmd" { + "enabled" = 1; + "protected" = 1; //may not be unloaded + }; + "libDummyServ" { + "enabled" = 1; + "protected" = 0; + }; + "libfuncmds" { + "enabled" = 1; + "protected" = 0; + }; + "libNeonHelp" { + "enabled" = 1; + "protected" = 0; + }; + "libNeonServ" { + "enabled" = 1; + "protected" = 0; + }; + "libNeonSpam" { + "enabled" = 1; + "protected" = 0; + }; +}; + diff --git a/src/modules.c b/src/modules.c index b848f6d..d29e7a8 100644 --- a/src/modules.c +++ b/src/modules.c @@ -256,17 +256,25 @@ static void unregister_module_hooks(int module_id); void loadModules() { char **modulelist = get_all_fieldnames("modules"); int i = 0; + char tmp[MAXLEN]; + struct ModuleInfo *modinfo; while(modulelist[i]) { - loadModule(modulelist[i]); + sprintf(tmp, "modules.%s.enabled", modulelist[i]); + if(get_int_field(tmp)) { + modinfo = loadModule(modulelist[i]); + sprintf(tmp, "modules.%s.protected", modulelist[i]); + if(!get_int_field(tmp)) + modinfo->state |= MODINFO_STATE_PROTECTED; + } i++; } start_modules(); } -int loadModule(char *name) { +struct ModuleInfo *loadModule(char *name) { struct ModuleInfo *modinfo; for(modinfo = modules; modinfo; modinfo = modinfo->next) { - if(!stricmp(modinfo->name, name)) return 0; + if(!stricmp(modinfo->name, name)) return NULL; } char fname[256]; #ifndef WIN32 @@ -277,7 +285,7 @@ int loadModule(char *name) { module = dlopen(fname, RTLD_LAZY); if(!module) { putlog(LOGLEVEL_ERROR, "Error loading module '%s': %s not found.\n", name, fname); - return 0; + return NULL; } } void* initfunc = dlsym(module, "init_module"); @@ -290,7 +298,7 @@ int loadModule(char *name) { HMODULE module = LoadLibrary(fname); if(!module) { putlog(LOGLEVEL_ERROR, "Error loading module '%s': %s not found.\n", name, fname); - return 0; + return NULL; } FARPROC initfunc = GetProcAddress(module, "init_module"); FARPROC startfunc = GetProcAddress(module, "start_module"); @@ -300,24 +308,24 @@ int loadModule(char *name) { #endif if(!startfunc || !loopfunc || !stopfunc || !modversion) { putlog(LOGLEVEL_ERROR, "Error loading module '%s': required symbols not found.\n", name); - return 0; + return NULL; } int version = ((int (*)(void)) modversion)(); if(version != MODULE_VERSION) { putlog(LOGLEVEL_ERROR, "Error loading module '%s': version mismatch ('%d' main code, '%d' module)\n", name, MODULE_VERSION, version); - return 0; + return NULL; } //start module int errid; int module_id = module_id_counter++; if((errid = ((int (*)(void **, int)) initfunc)(global_functions, module_id))) { putlog(LOGLEVEL_ERROR, "Error loading module '%s': module reported error (errid: %d)\n", name, errid); - return 0; + return NULL; } modinfo = malloc(sizeof(*modinfo)); if(!modinfo) { unregister_module_hooks(module_id); - return 0; + return NULL; } modinfo->name = strdup(name); modinfo->module_id = module_id; @@ -327,7 +335,7 @@ int loadModule(char *name) { modinfo->stopfunc = stopfunc; modinfo->next = modules; modules = modinfo; - return 1; + return modinfo; } #ifndef WIN32 @@ -357,6 +365,9 @@ int ext_unload_module(char *name) { struct ModuleInfo *old_modinfo, *old_prev = NULL; for(old_modinfo = modules; old_modinfo; old_modinfo = old_modinfo->next) { if(!stricmp(old_modinfo->name, name)) { + if(old_modinfo->state & MODINFO_STATE_PROTECTED) { + return 0; + } if(old_prev) old_prev->next = old_modinfo->next; else diff --git a/src/modules.h b/src/modules.h index e729c2e..9df733f 100644 --- a/src/modules.h +++ b/src/modules.h @@ -17,7 +17,8 @@ #ifndef _modules_h #define _modules_h -#define MODINFO_STATE_STARTED 0x01 +#define MODINFO_STATE_STARTED 0x01 +#define MODINFO_STATE_PROTECTED 0x02 struct ModuleInfo { char *name; @@ -36,7 +37,7 @@ struct ModuleInfo { #ifndef DND_FUNCTIONS void loadModules(); -int loadModule(char *name); +struct ModuleInfo *loadModule(char *name); void start_modules(); void loop_modules(); void stop_modules(); -- 2.20.1