aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2012-05-19 15:39:16 +0100
committerMatthew Wild <mwild1@gmail.com>2012-05-19 15:39:16 +0100
commit68907c01f2ccd08936abbfac4386556cf94f66b5 (patch)
treedd7978afcf9041580e40c87400524713966b1a0a /core
parent62488ffe3b684f64a863d1515188da42b2058a0f (diff)
downloadprosody-68907c01f2ccd08936abbfac4386556cf94f66b5.tar.gz
prosody-68907c01f2ccd08936abbfac4386556cf94f66b5.zip
modulemanager, moduleapi: Turn module.event_handlers into a multitable and track object->event->handler associations correctly (thanks Zash)
Diffstat (limited to 'core')
-rw-r--r--core/moduleapi.lua7
-rw-r--r--core/modulemanager.lua13
2 files changed, 8 insertions, 12 deletions
diff --git a/core/moduleapi.lua b/core/moduleapi.lua
index 96f1d3ea..24d29dfe 100644
--- a/core/moduleapi.lua
+++ b/core/moduleapi.lua
@@ -70,12 +70,7 @@ function api:fire_event(...)
end
function api:hook_object_event(object, event, handler, priority)
- local handlers = self.event_handlers[event];
- if not handlers then
- handlers = {};
- self.event_handlers[event] = handlers;
- end
- handlers[event] = { handler = handler, priority = priority, object = object };
+ self.event_handlers:set(object, event, handler, true);
return object.add_handler(event, handler, priority);
end
diff --git a/core/modulemanager.lua b/core/modulemanager.lua
index 417dedbe..488319c3 100644
--- a/core/modulemanager.lua
+++ b/core/modulemanager.lua
@@ -10,6 +10,9 @@ local logger = require "util.logger";
local log = logger.init("modulemanager");
local config = require "core.configmanager";
local pluginloader = require "util.pluginloader";
+local set = require "util.set";
+
+local new_multitable = require "util.multitable".new;
local hosts = hosts;
local prosody = prosody;
@@ -26,8 +29,6 @@ pcall = function(f, ...)
return xpcall(function() return f(unpack(params, 1, n)) end, function(e) return tostring(e).."\n"..debug_traceback(); end);
end
-local set = require "util.set";
-
local autoload_modules = {"presence", "message", "iq", "offline", "c2s", "s2s"};
local component_inheritable_modules = {"tls", "dialback", "iq", "s2s"};
@@ -91,8 +92,8 @@ local function do_unload_module(host, name)
end
end
- for event, data in pairs(mod.module.event_handlers) do
- data.object.remove_handler(event, data.handler);
+ for object, event, handler in mod.module.event_handlers:iter(nil, nil, nil) do
+ object.remove_handler(event, handler);
end
if mod.module.items then -- remove items
@@ -132,7 +133,7 @@ local function do_load_module(host, module_name)
if module_has_method(mod, "add_host") then
local _log = logger.init(host..":"..module_name);
local host_module_api = setmetatable({
- host = host, event_handlers = {}, items = {};
+ host = host, event_handlers = new_multitable(), items = {};
_log = _log, log = function (self, ...) return _log(...); end;
},{
__index = modulemap["*"][module_name].module;
@@ -159,7 +160,7 @@ local function do_load_module(host, module_name)
local _log = logger.init(host..":"..module_name);
local api_instance = setmetatable({ name = module_name, host = host, path = err,
- _log = _log, log = function (self, ...) return _log(...); end, event_handlers = {} }
+ _log = _log, log = function (self, ...) return _log(...); end, event_handlers = new_multitable() }
, { __index = api });
local pluginenv = setmetatable({ module = api_instance }, { __index = _G });