# HG changeset patch # User Matthew Wild # Date 1313344573 14400 # Node ID a24ee48ec30decbc274b2106853a6667b929f1e6 # Parent 20313782304690a2612b9627b4b66c67a37bd738 modulemanager: Add module:hook_global(name, handler, priority) to hook global (server-wide) events diff -r 203137823046 -r a24ee48ec30d core/modulemanager.lua --- a/core/modulemanager.lua Sun Aug 14 13:39:40 2011 -0400 +++ b/core/modulemanager.lua Sun Aug 14 13:56:13 2011 -0400 @@ -177,6 +177,12 @@ (hosts[host] or prosody).events.remove_handler(event, handler); end end + -- unhook event handlers hooked by module:hook_global + for event, handlers in pairs(hooks:get("*", name) or NULL) do + for handler in pairs(handlers or NULL) do + prosody.events.remove_handler(event, handler); + end + end hooks:remove(host, name); if mod.module.items then -- remove items for key,t in pairs(mod.module.items) do @@ -291,6 +297,11 @@ (hosts[self.host] or prosody).events.add_handler(event, handler, priority); end +function api:hook_global(event, handler, priority) + hooks:set("*", self.name, event, handler, true); + prosody.events.add_handler(event, handler, priority); +end + function api:hook_stanza(xmlns, name, handler, priority) if not handler and type(name) == "function" then -- If only 2 options then they specified no xmlns