Software /
code /
prosody
Changeset
1259:6bd11bca9725
modulemanager: Keep track of event handlers added by module:hook, and remove them on module unload
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 31 May 2009 13:31:20 +0500 |
parents | 1254:c199be608546 |
children | 1260:04c1fae0eb03 |
files | core/modulemanager.lua |
diffstat | 1 files changed, 9 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/core/modulemanager.lua Sun May 31 02:20:30 2009 +0500 +++ b/core/modulemanager.lua Sun May 31 13:31:20 2009 +0500 @@ -49,6 +49,7 @@ 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 @@ 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 @@ 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