summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2015-05-20 15:02:24 +0200
committerAttila Molnar <attilamolnar@hush.com>2015-05-20 15:02:24 +0200
commit7bb75e575b5f6a555a0651057c0cb5b30f93a9d9 (patch)
treec99cd7056aa20ce999c678501d6733f3ad3662c2 /src
parent48817837737c4b5908bb51dc319fad8f2e58ea8f (diff)
Allow modules to be called as "foo" instead of "m_foo.so"
Diffstat (limited to 'src')
-rw-r--r--src/modmanager_dynamic.cpp7
-rw-r--r--src/modmanager_static.cpp3
-rw-r--r--src/modules.cpp12
3 files changed, 17 insertions, 5 deletions
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;