aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/modulemanager.lua9
-rw-r--r--plugins/mod_iq.lua12
2 files changed, 19 insertions, 2 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
diff --git a/plugins/mod_iq.lua b/plugins/mod_iq.lua
index e0c9813d..fc79e92c 100644
--- a/plugins/mod_iq.lua
+++ b/plugins/mod_iq.lua
@@ -22,12 +22,20 @@ module:hook("iq/bare", function(data)
-- TODO if not user exists, return an error
-- TODO fire post processing events
- -- TODO fire event with the xmlns:tag of the child, or with the id of errors and results
+ if #stanza.tags == 1 then
+ return module:fire_event("iq/bare/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name);
+ else
+ return true; -- TODO do something with results and errors
+ end
end);
module:hook("iq/host", function(data)
-- IQ to a local host recieved
local origin, stanza = data.origin, data.stanza;
- -- TODO fire event with the xmlns:tag of the child, or with the id of errors and results
+ if #stanza.tags == 1 then
+ return module:fire_event("iq/host/"..stanza.tags[1].attr.xmlns..":"..stanza.tags[1].name);
+ else
+ return true; -- TODO do something with results and errors
+ end
end);