diff options
author | Waqas Hussain <waqas20@gmail.com> | 2009-05-31 13:31:20 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2009-05-31 13:31:20 +0500 |
commit | 27593d477fe24b3fa7863f7c051393be4f33cb5b (patch) | |
tree | 9302ce73637ec8017eb12ec2401b175c571e72e8 | |
parent | 4841e267c503cf5b153f5fb5d19892a629cedeb7 (diff) | |
download | prosody-27593d477fe24b3fa7863f7c051393be4f33cb5b.tar.gz prosody-27593d477fe24b3fa7863f7c051393be4f33cb5b.zip |
modulemanager: Keep track of event handlers added by module:hook, and remove them on module unload
-rw-r--r-- | core/modulemanager.lua | 9 |
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 |