aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2009-05-31 13:31:20 +0500
committerWaqas Hussain <waqas20@gmail.com>2009-05-31 13:31:20 +0500
commit27593d477fe24b3fa7863f7c051393be4f33cb5b (patch)
tree9302ce73637ec8017eb12ec2401b175c571e72e8 /core
parent4841e267c503cf5b153f5fb5d19892a629cedeb7 (diff)
downloadprosody-27593d477fe24b3fa7863f7c051393be4f33cb5b.tar.gz
prosody-27593d477fe24b3fa7863f7c051393be4f33cb5b.zip
modulemanager: Keep track of event handlers added by module:hook, and remove them on module unload
Diffstat (limited to 'core')
-rw-r--r--core/modulemanager.lua9
1 files changed, 9 insertions, 0 deletions
diff --git a/core/modulemanager.lua b/core/modulemanager.lua
index d02cb3cd..24fbe3d6 100644
--- a/core/modulemanager.lua
+++ b/core/modulemanager.lua
@@ -49,6 +49,7 @@ local modulehelpers = setmetatable({}, { __index = _G });
local features_table = multitable_new();
local handler_table = multitable_new();
local hooked = multitable_new();
+local hooks = multitable_new();
local event_hooks = multitable_new();
local NULL = {};
@@ -165,6 +166,13 @@ function unload(host, name, ...)
end
end
event_hooks:remove(host, name);
+ -- unhook event handlers hooked by module:hook
+ for event, handlers in pairs(hooks:get(host, name) or NULL) do
+ for handler in pairs(handlers or NULL) do
+ (hosts[host] or prosody).events.remove_handler(event, handler);
+ end
+ end
+ hooks:remove(host, name);
return true;
end
@@ -356,6 +364,7 @@ function api:fire_event(...)
end
function api:hook(event, handler)
+ hooks:set(self.host, self.name, event, handler, true);
(hosts[self.host] or prosody).events.add_handler(event, handler);
end