aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/componentmanager.lua6
-rw-r--r--core/modulemanager.lua9
-rw-r--r--core/stanza_router.lua3
3 files changed, 15 insertions, 3 deletions
diff --git a/core/componentmanager.lua b/core/componentmanager.lua
index ff60de28..8f624f15 100644
--- a/core/componentmanager.lua
+++ b/core/componentmanager.lua
@@ -89,6 +89,12 @@ function register_component(host, component, session)
if not hosts[host] or (hosts[host].type == 'component' and not hosts[host].connected) then
components[host] = component;
hosts[host] = session or create_component(host, component);
+
+ -- Add events object if not already one
+ if not hosts[host].events then
+ hosts[host].events = events_new();
+ end
+
-- add to disco_items
if not(host:find("@", 1, true) or host:find("/", 1, true)) and host:find(".", 1, true) then
disco_items:set(host:sub(host:find(".", 1, true)+1), host, true);
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/core/stanza_router.lua b/core/stanza_router.lua
index 4ade0055..7e7e3a43 100644
--- a/core/stanza_router.lua
+++ b/core/stanza_router.lua
@@ -165,9 +165,6 @@ function core_post_stanza(origin, stanza)
else
if h.events.fire_event(stanza.name..to_type, event_data) then return; end -- do processing
end
- else -- non-local recipient
- core_route_stanza(origin, stanza);
- return;
end
if host and fire_event(host.."/"..stanza.name, event_data) then