diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/os_modinfo.c | 2 | ||||
-rw-r--r-- | src/module.cpp | 44 | ||||
-rw-r--r-- | src/modulemanager.cpp | 10 | ||||
-rw-r--r-- | src/modules.c | 71 |
4 files changed, 52 insertions, 75 deletions
diff --git a/src/core/os_modinfo.c b/src/core/os_modinfo.c index 0f9452978..c01ac26f7 100644 --- a/src/core/os_modinfo.c +++ b/src/core/os_modinfo.c @@ -67,7 +67,7 @@ int do_modinfo(User * u) } m = findModule(file); if (m) { - tm = *localtime(&m->time); + tm = *localtime(&m->created); strftime_lang(timebuf, sizeof(timebuf), u, STRFTIME_DATE_TIME_FORMAT, &tm); notice_lang(s_OperServ, u, OPER_MODULE_INFO_LIST, m->name.c_str(), diff --git a/src/module.cpp b/src/module.cpp index 3f9aabaed..08d1a1cf0 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -35,6 +35,32 @@ Module::Module(const std::string &mname, const std::string &creator) { this->lang[i].argc = 0; } + + int index = 0; + ModuleHash *current = NULL; + ModuleHash *newHash = NULL; + ModuleHash *lastHash = NULL; + + index = CMD_HASH(this->name); + + for (current = MODULE_HASH[index]; current; current = current->next) { + if (this->name ==current->name) + throw CoreException("Module already exists!"); + lastHash = current; + } + + if ((newHash = (ModuleHash *)malloc(sizeof(ModuleHash))) == NULL) { + fatal("Out of memory"); + } + this->created = time(NULL); + newHash->next = NULL; + newHash->name = sstrdup(this->name.c_str()); + newHash->m = this; + + if (lastHash == NULL) + MODULE_HASH[index] = newHash; + else + lastHash->next = newHash; } Module::~Module() @@ -157,7 +183,25 @@ Module::~Module() } } } + } + + int index = 0; + ModuleHash *lastHash = NULL; + ModuleHash *mhash = NULL; + + index = CMD_HASH(this->name); + for (mhash = MODULE_HASH[index]; mhash; mhash = mhash->next) { + if (this->name == mhash->name) { + if (!lastHash) { + MODULE_HASH[index] = mhash->next; + } else { + lastHash->next = mhash->next; + } + free(mhash->name); + free(mhash); + } + lastHash = mhash; } } diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index 3d22fb50a..3ff8835f6 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -221,13 +221,15 @@ int ModuleManager::LoadModule(const std::string &modname, User * u) if (m->type == PROTOCOL && protocolModuleLoaded()) { + delete m; alog("You cannot load two protocol modules"); - ret = MOD_STOP; + return MOD_STOP; } else if (m->type == ENCRYPTION && encryptionModuleLoaded()) { + delete m; alog("You cannot load two encryption modules"); - ret = MOD_STOP; + return MOD_STOP; } mod_current_module_name = NULL; @@ -237,7 +239,7 @@ int ModuleManager::LoadModule(const std::string &modname, User * u) ircdproto->SendGlobops(s_OperServ, "%s loaded module %s", u->nick, modname.c_str()); notice_lang(s_OperServ, u, OPER_MODULE_LOADED, modname.c_str()); } - addModule(m); + return MOD_ERR_OK; } @@ -263,7 +265,7 @@ int ModuleManager::UnloadModule(Module * m, User * u) notice_lang(s_OperServ, u, OPER_MODULE_UNLOADED, m->name.c_str()); } - delModule(m); + delete m; return MOD_ERR_OK; } diff --git a/src/modules.c b/src/modules.c index 674f8d110..36ffc2ed5 100644 --- a/src/modules.c +++ b/src/modules.c @@ -250,7 +250,7 @@ void modules_unload_all(bool fini, bool unload_proto) mod_current_module_name = mh->m->name.c_str(); mod_current_module_name = NULL; - delModule(mh->m); + delete mh->m; } mh = next; } @@ -277,75 +277,6 @@ void Module::InsertLanguage(int langNumber, int ac, const char **av) } /** - * Add the module to the list of currently loaded modules. - * @param m the currently loaded module - * @return MOD_ERR_OK on success, anything else on fail - */ -int addModule(Module * m) -{ - int index = 0; - ModuleHash *current = NULL; - ModuleHash *newHash = NULL; - ModuleHash *lastHash = NULL; - - index = CMD_HASH(m->name); - - for (current = MODULE_HASH[index]; current; current = current->next) { - if (m->name ==current->name) - return MOD_ERR_EXISTS; - lastHash = current; - } - - if ((newHash = (ModuleHash *)malloc(sizeof(ModuleHash))) == NULL) { - fatal("Out of memory"); - } - m->time = time(NULL); - newHash->next = NULL; - newHash->name = sstrdup(m->name.c_str()); - newHash->m = m; - - if (lastHash == NULL) - MODULE_HASH[index] = newHash; - else - lastHash->next = newHash; - return MOD_ERR_OK; -} - -/** - * Remove the module from the list of loaded modules. - * @param m module to remove - * @return MOD_ERR_OK on success anything else on fail - */ -int delModule(Module * m) -{ - int index = 0; - ModuleHash *current = NULL; - ModuleHash *lastHash = NULL; - - if (!m) { - return MOD_ERR_PARAMS; - } - - index = CMD_HASH(m->name); - - for (current = MODULE_HASH[index]; current; current = current->next) { - if (m->name == current->name) { - if (!lastHash) { - MODULE_HASH[index] = current->next; - } else { - lastHash->next = current->next; - } - delete current->m; - free(current->name); - free(current); - return MOD_ERR_OK; - } - lastHash = current; - } - return MOD_ERR_NOEXIST; -} - -/** * Search the list of loaded modules for the given name. * @param name the name of the module to find * @return a pointer to the module found, or NULL |