From d349f981fbe70fb11e3db4c486f59749ffe74c2b Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Fri, 16 Aug 2013 12:20:06 +0200 Subject: Remove ModuleManager::GetAllModuleNames(), use GetModules() instead --- include/modules.h | 8 -------- src/commands/cmd_modules.cpp | 12 ++++++------ src/configreader.cpp | 21 ++++++++++----------- src/modules.cpp | 9 --------- src/modules/m_httpd_stats.cpp | 9 ++++----- src/modules/m_spanningtree/capab.cpp | 13 +++++++------ 6 files changed, 27 insertions(+), 45 deletions(-) diff --git a/include/modules.h b/include/modules.h index 68044ae89..e81f9465c 100644 --- a/include/modules.h +++ b/include/modules.h @@ -1347,14 +1347,6 @@ class CoreExport ModuleManager return static_cast(FindService(SERVICE_DATA, name)); } - /** Return a list of all modules matching the given filter - * @param filter This int is a bitmask of flags set in Module::Flags, - * such as VF_VENDOR or VF_STATIC. If you wish to receive a list of - * all modules with no filtering, set this to 0. - * @return The list of module names - */ - const std::vector GetAllModuleNames(int filter); - /** Get a map of all loaded modules keyed by their name * @return A ModuleMap containing all loaded modules */ diff --git a/src/commands/cmd_modules.cpp b/src/commands/cmd_modules.cpp index b8a1805b0..c37008563 100644 --- a/src/commands/cmd_modules.cpp +++ b/src/commands/cmd_modules.cpp @@ -51,11 +51,11 @@ class CommandModules : public Command */ CmdResult CommandModules::Handle (const std::vector&, User *user) { - std::vector module_names = ServerInstance->Modules->GetAllModuleNames(0); + const ModuleManager::ModuleMap& mods = ServerInstance->Modules->GetModules(); - for (unsigned int i = 0; i < module_names.size(); i++) + for (ModuleManager::ModuleMap::const_iterator i = mods.begin(); i != mods.end(); ++i) { - Module* m = ServerInstance->Modules->Find(module_names[i]); + Module* m = i->second; Version V = m->GetVersion(); if (user->HasPrivPermission("servers/auspex")) @@ -68,17 +68,17 @@ CmdResult CommandModules::Handle (const std::vector&, User *user) #ifdef PURE_STATIC user->SendText(":%s 702 %s :%p %s %s :%s", ServerInstance->Config->ServerName.c_str(), - user->nick.c_str(), (void*)m, module_names[i].c_str(), flags.c_str(), V.description.c_str()); + user->nick.c_str(), (void*)m, m->ModuleSourceFile.c_str(), flags.c_str(), V.description.c_str()); #else std::string srcrev = m->ModuleDLLManager->GetVersion(); user->SendText(":%s 702 %s :%p %s %s :%s - %s", ServerInstance->Config->ServerName.c_str(), - user->nick.c_str(), (void*)m, module_names[i].c_str(), flags.c_str(), V.description.c_str(), srcrev.c_str()); + user->nick.c_str(), (void*)m, m->ModuleSourceFile.c_str(), flags.c_str(), V.description.c_str(), srcrev.c_str()); #endif } else { user->SendText(":%s 702 %s :%s %s", ServerInstance->Config->ServerName.c_str(), - user->nick.c_str(), module_names[i].c_str(), V.description.c_str()); + user->nick.c_str(), m->ModuleSourceFile.c_str(), V.description.c_str()); } } user->SendText(":%s 703 %s :End of MODULES list", ServerInstance->Config->ServerName.c_str(), user->nick.c_str()); diff --git a/src/configreader.cpp b/src/configreader.cpp index a08047678..656bc338a 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -673,9 +673,8 @@ void ServerConfig::Apply(ServerConfig* old, const std::string &useruid) void ServerConfig::ApplyModules(User* user) { - const std::vector v = ServerInstance->Modules->GetAllModuleNames(0); std::vector added_modules; - std::set removed_modules(v.begin(), v.end()); + ModuleManager::ModuleMap removed_modules = ServerInstance->Modules->GetModules(); ConfigTagList tags = ConfTags("module"); for(ConfigIter i = tags.first; i != tags.second; ++i) @@ -691,27 +690,27 @@ void ServerConfig::ApplyModules(User* user) } } - for (std::set::iterator removing = removed_modules.begin(); removing != removed_modules.end(); removing++) + for (ModuleManager::ModuleMap::iterator i = removed_modules.begin(); i != removed_modules.end(); ++i) { + const std::string& modname = i->first; // Don't remove cmd_*.so, just remove m_*.so - if (removing->c_str()[0] == 'c') + if (modname.c_str()[0] == 'c') continue; - Module* m = ServerInstance->Modules->Find(*removing); - if (m && ServerInstance->Modules->Unload(m)) + if (ServerInstance->Modules->Unload(i->second)) { - ServerInstance->SNO->WriteGlobalSno('a', "*** REHASH UNLOADED MODULE: %s",removing->c_str()); + ServerInstance->SNO->WriteGlobalSno('a', "*** REHASH UNLOADED MODULE: %s", modname.c_str()); if (user) - user->WriteNumeric(RPL_UNLOADEDMODULE, "%s %s :Module %s successfully unloaded.",user->nick.c_str(), removing->c_str(), removing->c_str()); + user->WriteNumeric(RPL_UNLOADEDMODULE, "%s %s :Module %s successfully unloaded.",user->nick.c_str(), modname.c_str(), modname.c_str()); else - ServerInstance->SNO->WriteGlobalSno('a', "Module %s successfully unloaded.", removing->c_str()); + ServerInstance->SNO->WriteGlobalSno('a', "Module %s successfully unloaded.", modname.c_str()); } else { if (user) - user->WriteNumeric(ERR_CANTUNLOADMODULE, "%s %s :Failed to unload module %s: %s",user->nick.c_str(), removing->c_str(), removing->c_str(), ServerInstance->Modules->LastError().c_str()); + user->WriteNumeric(ERR_CANTUNLOADMODULE, "%s %s :Failed to unload module %s: %s",user->nick.c_str(), modname.c_str(), modname.c_str(), ServerInstance->Modules->LastError().c_str()); else - ServerInstance->SNO->WriteGlobalSno('a', "Failed to unload module %s: %s", removing->c_str(), ServerInstance->Modules->LastError().c_str()); + ServerInstance->SNO->WriteGlobalSno('a', "Failed to unload module %s: %s", modname.c_str(), ServerInstance->Modules->LastError().c_str()); } } diff --git a/src/modules.cpp b/src/modules.cpp index d581b76a5..b6a28193a 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -560,15 +560,6 @@ Module* ModuleManager::Find(const std::string &name) return modfind->second; } -const std::vector ModuleManager::GetAllModuleNames(int filter) -{ - std::vector retval; - for (std::map::iterator x = Modules.begin(); x != Modules.end(); ++x) - if (!filter || (x->second->GetVersion().Flags & filter)) - retval.push_back(x->first); - return retval; -} - FileReader::FileReader(const std::string& filename) { Load(filename); diff --git a/src/modules/m_httpd_stats.cpp b/src/modules/m_httpd_stats.cpp index 022d91f1e..5114b26d5 100644 --- a/src/modules/m_httpd_stats.cpp +++ b/src/modules/m_httpd_stats.cpp @@ -141,13 +141,12 @@ class ModuleHttpStats : public Module } data << ""; - std::vector module_names = ServerInstance->Modules->GetAllModuleNames(0); + const ModuleManager::ModuleMap& mods = ServerInstance->Modules->GetModules(); - for (std::vector::iterator i = module_names.begin(); i != module_names.end(); ++i) + for (ModuleManager::ModuleMap::const_iterator i = mods.begin(); i != mods.end(); ++i) { - Module* m = ServerInstance->Modules->Find(i->c_str()); - Version v = m->GetVersion(); - data << "" << *i << "" << Sanitize(v.description) << ""; + Version v = i->second->GetVersion(); + data << "" << i->first << "" << Sanitize(v.description) << ""; } data << ""; diff --git a/src/modules/m_spanningtree/capab.cpp b/src/modules/m_spanningtree/capab.cpp index 1ca5b982c..f4f1e1ace 100644 --- a/src/modules/m_spanningtree/capab.cpp +++ b/src/modules/m_spanningtree/capab.cpp @@ -28,17 +28,18 @@ std::string TreeSocket::MyModules(int filter) { - std::vector modlist = ServerInstance->Modules->GetAllModuleNames(filter); + const ModuleManager::ModuleMap& modlist = ServerInstance->Modules->GetModules(); std::string capabilities; - sort(modlist.begin(),modlist.end()); - for (std::vector::const_iterator i = modlist.begin(); i != modlist.end(); ++i) + for (ModuleManager::ModuleMap::const_iterator i = modlist.begin(); i != modlist.end(); ++i) { + Version v = i->second->GetVersion(); + if (!(v.Flags & filter)) + continue; + if (i != modlist.begin()) capabilities.push_back(' '); - capabilities.append(*i); - Module* m = ServerInstance->Modules->Find(*i); - Version v = m->GetVersion(); + capabilities.append(i->first); if (!v.link_data.empty()) { capabilities.push_back('='); -- cgit v1.2.3