diff options
author | Matthew Wild <mwild1@gmail.com> | 2011-08-14 13:56:13 -0400 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2011-08-14 13:56:13 -0400 |
commit | 5f57f8ff0b06e3dac8809603bdeed450ba1e8b2e (patch) | |
tree | d0ed336ca9bd92db3f199ebb431b24f6a380af1d /core | |
parent | 92cf5d2089de992cfc7fcf3733862ca51abeb619 (diff) | |
download | prosody-5f57f8ff0b06e3dac8809603bdeed450ba1e8b2e.tar.gz prosody-5f57f8ff0b06e3dac8809603bdeed450ba1e8b2e.zip |
modulemanager: Add module:hook_global(name, handler, priority) to hook global (server-wide) events
Diffstat (limited to 'core')
-rw-r--r-- | core/modulemanager.lua | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 3cf893a1..d0a0f982 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -177,6 +177,12 @@ function unload(host, name, ...) (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 @@ function api:hook(event, handler, priority) (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 |