Software /
code /
prosody
Diff
core/modulemanager.lua @ 686:13ed38531f69
modulemanager: Per-host event hooks for plugins - solves issue 41
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Fri, 09 Jan 2009 23:01:21 +0500 |
parent | 675:cc82394fea22 |
child | 695:3384f2784795 |
child | 708:b72d408f5f15 |
line wrap: on
line diff
--- a/core/modulemanager.lua Fri Jan 09 20:49:39 2009 +0500 +++ b/core/modulemanager.lua Fri Jan 09 23:01:21 2009 +0500 @@ -55,6 +55,9 @@ local features_table = multitable_new(); local handler_table = multitable_new(); +local hooked = multitable_new(); +local event_hooks = multitable_new(); + local NULL = {}; -- Load modules when a host is activated @@ -151,6 +154,7 @@ handler_info[handlers[1]] = nil; stanza_handlers:remove(param[1], param[2], param[3], param[4]); end + event_hooks:remove(host, name); return true; end @@ -234,7 +238,19 @@ features_table:set(self.host, self.name, xmlns, true); end -function api:add_event_hook (...) return eventmanager.add_event_hook(...); end +local event_hook = function(host, mod_name, event_name, ...) + if type((...)) == "table" and (...).host and (...).host ~= host then return; end + for handler in pairs(event_hooks:get(host, mod_name, event_name) or NULL) do + handler(...); + end +end; +function api:add_event_hook(name, handler) + if not hooked:get(self.host, self.name, name) then + eventmanager.add_event_hook(name, function(...) event_hook(self.host, self.name, name, ...); end); + hooked:set(self.host, self.name, name, true); + end + event_hooks:set(self.host, self.name, name, handler, true); +end --------------------------------------------------------------------