aboutsummaryrefslogtreecommitdiffstats
path: root/core/modulemanager.lua
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2009-01-13 22:37:07 +0500
committerWaqas Hussain <waqas20@gmail.com>2009-01-13 22:37:07 +0500
commita138bcd591d3fa2240b41720b426743a6c05ac9d (patch)
treea6265c22cf51b2f53367fb8d6c8df4d2f07104b0 /core/modulemanager.lua
parent4dc4d175d135e293f48ed6a15f61b19c4dafe8d7 (diff)
downloadprosody-a138bcd591d3fa2240b41720b426743a6c05ac9d.tar.gz
prosody-a138bcd591d3fa2240b41720b426743a6c05ac9d.zip
modulemanager: Added reload support, with callbacks for saving and restoring state
Diffstat (limited to 'core/modulemanager.lua')
-rw-r--r--core/modulemanager.lua31
1 files changed, 29 insertions, 2 deletions
diff --git a/core/modulemanager.lua b/core/modulemanager.lua
index 52fbc65d..c1caaacc 100644
--- a/core/modulemanager.lua
+++ b/core/modulemanager.lua
@@ -140,8 +140,8 @@ function unload(host, name, ...)
local mod = modulemap[host] and modulemap[host][name];
if not mod then return nil, "module-not-loaded"; end
- if type(rawget(mod, "unload")) == "function" then
- local ok, err = pcall(rawget(mod, "unload"), ...)
+ if type(mod.module.unload) == "function" then
+ local ok, err = pcall(mod.module.unload, ...)
if (not ok) and err then
log("warn", "Non-fatal error unloading module '%s' from '%s': %s", name, host, err);
end
@@ -160,6 +160,33 @@ function unload(host, name, ...)
return true;
end
+function reload(host, name, ...)
+ local mod = modulemap[host] and modulemap[host][name];
+ if not mod then return nil, "module-not-loaded"; end
+
+ local saved;
+ if type(mod.module.save) == "function" then
+ local ok, err = pcall(mod.module.save)
+ if (not ok) and err then
+ log("warn", "Non-fatal error unloading module '%s' from '%s': %s", name, host, err);
+ else
+ saved = err;
+ end
+ end
+
+ unload(host, name, ...);
+ if load(host, name, ...) then
+ mod = modulemap[host] and modulemap[host][name];
+ if type(mod.module.restore) == "function" then
+ local ok, err = pcall(mod.module.restore, saved or {})
+ if (not ok) and err then
+ log("warn", "Non-fatal error unloading module '%s' from '%s': %s", name, host, err);
+ end
+ end
+ return true;
+ end
+end
+
function handle_stanza(host, origin, stanza)
local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns, origin.type;
if name == "iq" and xmlns == "jabber:client" then