aboutsummaryrefslogtreecommitdiffstats
path: root/core/modulemanager.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2011-08-14 13:56:13 -0400
committerMatthew Wild <mwild1@gmail.com>2011-08-14 13:56:13 -0400
commit7a4fd8dbcb09c10206c1c5783a2c696514ba48ea (patch)
treed0ed336ca9bd92db3f199ebb431b24f6a380af1d /core/modulemanager.lua
parent95547f989296028151b238418833ed30103b63a8 (diff)
downloadprosody-7a4fd8dbcb09c10206c1c5783a2c696514ba48ea.tar.gz
prosody-7a4fd8dbcb09c10206c1c5783a2c696514ba48ea.zip
modulemanager: Add module:hook_global(name, handler, priority) to hook global (server-wide) events
Diffstat (limited to 'core/modulemanager.lua')
-rw-r--r--core/modulemanager.lua11
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