# HG changeset patch # User Matthew Wild # Date 1227804750 0 # Node ID 6608ad3a72f3ea43b491b996cced91e086a2a6e9 # Parent 193f9dd64f17f44d488f5028c9c9014fb7281a35 is_loaded() and incomplete unload() for modules diff -r 193f9dd64f17 -r 6608ad3a72f3 core/modulemanager.lua --- a/core/modulemanager.lua Thu Nov 27 03:12:12 2008 +0000 +++ b/core/modulemanager.lua Thu Nov 27 16:52:30 2008 +0000 @@ -27,6 +27,9 @@ 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 @@ 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;