From 7bb75e575b5f6a555a0651057c0cb5b30f93a9d9 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Wed, 20 May 2015 15:02:24 +0200 Subject: [PATCH] Allow modules to be called as "foo" instead of "m_foo.so" --- include/modules.h | 7 +++++++ src/modmanager_dynamic.cpp | 7 ++++--- src/modmanager_static.cpp | 3 ++- src/modules.cpp | 12 +++++++++++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/include/modules.h b/include/modules.h index 3cf780284..7944aa609 100644 --- a/include/modules.h +++ b/include/modules.h @@ -1047,6 +1047,13 @@ class CoreExport ModuleManager : public fakederef */ bool PrioritizeHooks(); + /** Expands the name of a module by prepending "m_" and appending ".so". + * No-op if the name already has the ".so" extension. + * @param modname Module name to expand + * @return Module name starting with "m_" and ending with ".so" + */ + static std::string ExpandModName(const std::string& modname); + public: typedef std::map ModuleMap; diff --git a/src/modmanager_dynamic.cpp b/src/modmanager_dynamic.cpp index fc6161e31..9a687ad2b 100644 --- a/src/modmanager_dynamic.cpp +++ b/src/modmanager_dynamic.cpp @@ -27,15 +27,16 @@ #ifndef PURE_STATIC -bool ModuleManager::Load(const std::string& filename, bool defer) +bool ModuleManager::Load(const std::string& modname, bool defer) { /* Don't allow people to specify paths for modules, it doesn't work as expected */ - if (filename.find('/') != std::string::npos) + if (modname.find('/') != std::string::npos) { - LastModuleError = "You can't load modules with a path: " + filename; + LastModuleError = "You can't load modules with a path: " + modname; return false; } + const std::string filename = ExpandModName(modname); const std::string moduleFile = ServerInstance->Config->Paths.PrependModule(filename); if (!FileSystem::FileExists(moduleFile)) diff --git a/src/modmanager_static.cpp b/src/modmanager_static.cpp index ac127b703..98ed26c67 100644 --- a/src/modmanager_static.cpp +++ b/src/modmanager_static.cpp @@ -80,8 +80,9 @@ class AllModule : public Module MODULE_INIT(AllModule) -bool ModuleManager::Load(const std::string& name, bool defer) +bool ModuleManager::Load(const std::string& inputname, bool defer) { + const std::string name = ExpandModName(inputname); modmap::iterator it = modlist->find(name); if (it == modlist->end()) return false; diff --git a/src/modules.cpp b/src/modules.cpp index b8982579c..334ac39f8 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -636,6 +636,16 @@ ServiceProvider* ModuleManager::FindService(ServiceType type, const std::string& } } +std::string ModuleManager::ExpandModName(const std::string& modname) +{ + // Transform "callerid" -> "m_callerid.so" unless it already has a ".so" extension, + // so coremods in the "core_*.so" form aren't changed + std::string ret = modname; + if ((modname.length() < 3) || (modname.compare(modname.size() - 3, 3, ".so"))) + ret.insert(0, "m_").append(".so"); + return ret; +} + dynamic_reference_base::dynamic_reference_base(Module* Creator, const std::string& Name) : name(Name), hook(NULL), value(NULL), creator(Creator) { @@ -685,7 +695,7 @@ void dynamic_reference_base::resolve() Module* ModuleManager::Find(const std::string &name) { - std::map::iterator modfind = Modules.find(name); + std::map::const_iterator modfind = Modules.find(ExpandModName(name)); if (modfind == Modules.end()) return NULL; -- 2.39.5