aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2008-11-27 16:52:30 +0000
committerMatthew Wild <mwild1@gmail.com>2008-11-27 16:52:30 +0000
commitce18fc957d0c3d54fa9e5b42cf2fa7ef54129c5c (patch)
tree9a5020f4e7b2c62613bc2ced09aba1eb4537829f
parenta153b3c26704686bf9a3f2255d9aeb3c5f6aa2b1 (diff)
downloadprosody-ce18fc957d0c3d54fa9e5b42cf2fa7ef54129c5c.tar.gz
prosody-ce18fc957d0c3d54fa9e5b42cf2fa7ef54129c5c.zip
is_loaded() and incomplete unload() for modules
-rw-r--r--core/modulemanager.lua20
1 files changed, 20 insertions, 0 deletions
diff --git a/core/modulemanager.lua b/core/modulemanager.lua
index 704bd26f..ce34f3e6 100644
--- a/core/modulemanager.lua
+++ b/core/modulemanager.lua
@@ -27,6 +27,9 @@ local modulehelpers = setmetatable({}, { __index = _G });
function load(host, module_name, config)
+ if not (host and module_name) then
+ return nil, "insufficient-parameters";
+ end
local mod, err = loadfile("plugins/mod_"..module_name..".lua");
if not mod then
log("error", "Unable to load module '%s': %s", module_name or "nil", err or "nil");
@@ -59,6 +62,23 @@ function load(host, module_name, config)
return true;
end
+function is_loaded(host, name)
+ return modulemap[host] and modulemap[host][name] and true;
+end
+
+function unload(host, name, ...)
+ local mod = modulemap[host] and modulemap[host][name];
+ if not mod then return nil, "module-not-loaded"; end
+
+ if type(mod.unload) == "function" then
+ local ok, err = pcall(mod.unload, ...)
+ if (not ok) and err then
+ log("warn", "Non-fatal error unloading module '%s' from '%s': %s", name, host, err);
+ end
+ end
+
+end
+
function handle_stanza(host, origin, stanza)
local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns, origin.type;