From 6d2a2e1bf9c8f7254031b9787cde4c47a9f6fbc2 Mon Sep 17 00:00:00 2001 From: stskeeps Date: Sat, 10 Mar 2001 21:04:25 +0000 Subject: [PATCH] +- Added loadmodule "filename.so"; and made the modules + unable to get loaded twice with same name. --- Changes | 2 ++ src/modules.c | 25 ++++++++++++++++++------- src/s_conf.c | 21 ++++++++++++++++++++- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/Changes b/Changes index 627b4df12..8c7b997c1 100644 --- a/Changes +++ b/Changes @@ -312,3 +312,5 @@ - Added Modules, using dlopen() and LoadLibrary for *nix/win32. - Added /module load , /module status (list modules), /module unload +- Added loadmodule "filename.so"; and made the modules + unable to get loaded twice with same name. diff --git a/src/modules.c b/src/modules.c index 67a35e603..c9ca58fa2 100644 --- a/src/modules.c +++ b/src/modules.c @@ -34,6 +34,7 @@ #include #include #ifdef _WIN32 + #include #endif #include @@ -70,7 +71,7 @@ int load_module(char *module) mod_init = irc_dlsym(Mod, "_mod_init"); if (!mod_init) { - sendto_realops + config_progress ("Failed to load module %s: Could not locate mod_init", module); irc_dlclose(Mod); @@ -81,7 +82,7 @@ int load_module(char *module) (*mod_init) (); if (!module_buffer) { - sendto_realops + config_progress ("Failed to load module %s: mod_init did not set module_buffer", module); irc_dlclose(Mod); @@ -89,7 +90,7 @@ int load_module(char *module) } if (module_buffer->mversion != MOD_VERSION) { - sendto_realops + config_progress ("Failed to load module %s: mversion is %i, not %i as we require", module, module_buffer->mversion, MOD_VERSION); irc_dlclose(Mod); @@ -98,7 +99,7 @@ int load_module(char *module) if (!module_buffer->name || !module_buffer->version || !module_buffer->description) { - sendto_realops + config_progress ("Failed to load module %s: name/version/description missing", module); irc_dlclose(Mod); @@ -110,7 +111,7 @@ int load_module(char *module) mod_unload = irc_dlsym(Mod, "_mod_unload"); if (!mod_unload) { - sendto_realops + config_progress ("Failed to load module %s: Could not locate mod_unload", module); irc_dlclose(Mod); @@ -119,6 +120,16 @@ int load_module(char *module) } module_buffer->dll = Mod; module_buffer->unload = mod_unload; + for (i = 0; i < MAXMODULES; i++) + if (Modules[i] && !strcmp(Modules[i]->name, module_buffer->name)) + { + /* We will unload it without notice, its a duplicate */ + sendto_umode(UMODE_JUNK, "Ignoring load of module %s, duplicate names", module_buffer->name); + (*module_buffer->unload)(); + irc_dlclose(Mod); + return 1; + } + for (i = 0; i <= MAXMODULES; i++) { if (!Modules[i]) @@ -130,7 +141,7 @@ int load_module(char *module) } if (i == MAXMODULES) { - sendto_realops + config_progress ("Failed to load module %s: Too many modules loaded"); irc_dlclose(Mod); return -1; @@ -143,7 +154,7 @@ int load_module(char *module) if (err) { - sendto_realops("Failed to load module %s: %s", + config_progress("Failed to load module %s: %s", module, err); } return -1; diff --git a/src/s_conf.c b/src/s_conf.c index bbaf2bedb..f3e2fc82f 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -95,6 +95,7 @@ int _conf_deny_link (ConfigFile *conf, ConfigEntry *ce); int _conf_deny_channel (ConfigFile *conf, ConfigEntry *ce); int _conf_deny_version (ConfigFile *conf, ConfigEntry *ce); int _conf_allow_channel (ConfigFile *conf, ConfigEntry *ce); +int _conf_loadmodule (ConfigFile *conf, ConfigEntry *ce); extern int conf_debuglevel; @@ -118,6 +119,7 @@ static ConfigCommand _ConfigCommands[] = { { "badword", _conf_badword }, #endif { "deny", _conf_deny }, + { "loadmodule", _conf_loadmodule }, { NULL, NULL } }; @@ -337,7 +339,7 @@ static void config_status(char *format, ...) sendto_realops("warning: %s", buffer); } -static void config_progress(char *format, ...) +void config_progress(char *format, ...) { va_list ap; char buffer[1024]; @@ -1001,6 +1003,23 @@ int _conf_me(ConfigFile *conf, ConfigEntry *ce) } } +int _conf_loadmodule(ConfigFile *conf, ConfigEntry *ce) +{ + if (!ce->ce_vardata) + { + config_error("%s:%i: loadmodule without filename", + ce->ce_fileptr->cf_filename, ce->ce_varlinenum); + return -1; + } + if (load_module(ce->ce_vardata) != 1) + { + config_error("%s:%i: loadmodule %s: failed to load", + ce->ce_fileptr->cf_filename, ce->ce_varlinenum, + ce->ce_vardata); + return -1; + } + return 1; +} /* * The oper {} block parser */