]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Allow modules to be called as "foo" instead of "m_foo.so"
authorAttila Molnar <attilamolnar@hush.com>
Wed, 20 May 2015 13:02:24 +0000 (15:02 +0200)
committerAttila Molnar <attilamolnar@hush.com>
Wed, 20 May 2015 13:02:24 +0000 (15:02 +0200)
include/modules.h
src/modmanager_dynamic.cpp
src/modmanager_static.cpp
src/modules.cpp

index 3cf7802846f7cc6acd2e817d8b218a1c3e6805f8..7944aa609cdc8d631066297e43c1e3d39f2ad61b 100644 (file)
@@ -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;
 
index fc6161e3175f2320d22e331bd3d52c22a6369295..9a687ad2bf1af38002134ff30aefc3f288ff6603 100644 (file)
 
 #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))
index ac127b7031b2d5f0e8a61ec56f111396a2e4a3c3..98ed26c672c1fe787512e912aa13ba455b400d2a 100644 (file)
@@ -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;
index b8982579cdde355f9d1e0ec403a2dd35b0e70764..334ac39f8f21b477d977f2ba90cc84e0d1690d06 100644 (file)
@@ -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;