summaryrefslogtreecommitdiff
path: root/src/modulemanager.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-04-28 22:44:34 -0400
committerAdam <Adam@anope.org>2011-05-16 04:09:32 -0400
commit583954d3a1db658281a9afb7b7dd6773726c8c11 (patch)
tree6a00865d5738c6d0bc42efb35f3f468c5876eb3e /src/modulemanager.cpp
parent8fb1604f649bec6f356770daf5df6bb8ab811bbf (diff)
Use module type to determine what type each module is instead of its location in the configuration file.
Diffstat (limited to 'src/modulemanager.cpp')
-rw-r--r--src/modulemanager.cpp64
1 files changed, 34 insertions, 30 deletions
diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp
index ac6316728..e2f837f0f 100644
--- a/src/modulemanager.cpp
+++ b/src/modulemanager.cpp
@@ -126,24 +126,6 @@ static ModuleReturn moduleCopyFile(const Anope::string &name, Anope::string &out
return MOD_ERR_OK;
}
-static bool IsOneOfModuleTypeLoaded(MODType mt)
-{
- int pmods = 0;
-
- for (std::list<Module *>::const_iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it)
- if ((*it)->type == mt)
- ++pmods;
-
- /*
- * 2, because module constructors now add modules to the hash.. so 1 (original module)
- * and 2 (this module). -- w00t
- */
- if (pmods == 2)
- return true;
-
- return false;
-}
-
/* This code was found online at http://www.linuxjournal.com/article/3687#comment-26593
*
* This function will take a pointer from either dlsym or GetProcAddress and cast it in
@@ -176,12 +158,7 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
/* Don't skip return value checking! -GD */
ModuleReturn ret = moduleCopyFile(modname, pbuf);
if (ret != MOD_ERR_OK)
- {
- /* XXX: This used to assign filename here, but I don't think that was correct..
- * even if it was, it makes life very fucking difficult, so.
- */
return ret;
- }
ano_modclearerr();
@@ -246,7 +223,7 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
else if (v.GetBuild() == Anope::VersionBuild())
Log(LOG_DEBUG) << "Module " << modname << " compiled against current version of Anope " << v.GetBuild();
- if (m->type == PROTOCOL && IsOneOfModuleTypeLoaded(PROTOCOL))
+ if (m->type == PROTOCOL && ModuleManager::FindFirstOf(PROTOCOL) != m)
{
DeleteModule(m);
Log() << "You cannot load two protocol modules";
@@ -260,13 +237,38 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u)
ModuleReturn ModuleManager::UnloadModule(Module *m, User *u)
{
+ if (!m)
+ return MOD_ERR_PARAMS;
+
FOREACH_MOD(I_OnModuleUnload, OnModuleUnload(u, m));
- if (DNSEngine)
- DNSEngine->Cleanup(m);
+ return DeleteModule(m);
+}
- DeleteModule(m);
- return MOD_ERR_OK;
+Module *ModuleManager::FindModule(const Anope::string &name)
+{
+ for (std::list<Module *>::const_iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it)
+ {
+ Module *m = *it;
+
+ if (m->name.equals_ci(name))
+ return m;
+ }
+
+ return NULL;
+}
+
+Module *ModuleManager::FindFirstOf(ModType type)
+{
+ for (std::list<Module *>::const_iterator it = Modules.begin(), it_end = Modules.end(); it != it_end; ++it)
+ {
+ Module *m = *it;
+
+ if (m->type == type)
+ return m;
+ }
+
+ return NULL;
}
void ModuleManager::RequireVersion(int major, int minor, int patch, int build)
@@ -298,10 +300,10 @@ void ModuleManager::RequireVersion(int major, int minor, int patch, int build)
throw ModuleException("This module requires version " + stringify(major) + "." + stringify(minor) + "." + stringify(patch) + "-" + build + " - this is " + Anope::Version());
}
-void ModuleManager::DeleteModule(Module *m)
+ModuleReturn ModuleManager::DeleteModule(Module *m)
{
if (!m || !m->handle)
- return;
+ return MOD_ERR_PARAMS;
ano_module_t handle = m->handle;
Anope::string filename = m->filename;
@@ -322,6 +324,8 @@ void ModuleManager::DeleteModule(Module *m)
if (!filename.empty())
DeleteFile(filename.c_str());
+
+ return MOD_ERR_OK;
}
bool ModuleManager::Attach(Implementation i, Module *mod)