diff options
-rw-r--r-- | include/modules.h | 7 | ||||
-rw-r--r-- | src/modmanager_dynamic.cpp | 7 | ||||
-rw-r--r-- | src/modmanager_static.cpp | 3 | ||||
-rw-r--r-- | 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<ModuleManager> */ 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<std::string, Module*> 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<std::string, Module*>::iterator modfind = Modules.find(name); + std::map<std::string, Module*>::const_iterator modfind = Modules.find(ExpandModName(name)); if (modfind == Modules.end()) return NULL; |