Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
685:55d1bc45acf1 | 686:13ed38531f69 |
---|---|
53 | 53 |
54 local modulehelpers = setmetatable({}, { __index = _G }); | 54 local modulehelpers = setmetatable({}, { __index = _G }); |
55 | 55 |
56 local features_table = multitable_new(); | 56 local features_table = multitable_new(); |
57 local handler_table = multitable_new(); | 57 local handler_table = multitable_new(); |
58 local hooked = multitable_new(); | |
59 local event_hooks = multitable_new(); | |
60 | |
58 local NULL = {}; | 61 local NULL = {}; |
59 | 62 |
60 -- Load modules when a host is activated | 63 -- Load modules when a host is activated |
61 function load_modules_for_host(host) | 64 function load_modules_for_host(host) |
62 -- Load modules from global section | 65 -- Load modules from global section |
149 for _, param in pairs(params) do | 152 for _, param in pairs(params) do |
150 local handlers = stanza_handlers:get(param[1], param[2], param[3], param[4]); | 153 local handlers = stanza_handlers:get(param[1], param[2], param[3], param[4]); |
151 handler_info[handlers[1]] = nil; | 154 handler_info[handlers[1]] = nil; |
152 stanza_handlers:remove(param[1], param[2], param[3], param[4]); | 155 stanza_handlers:remove(param[1], param[2], param[3], param[4]); |
153 end | 156 end |
157 event_hooks:remove(host, name); | |
154 return true; | 158 return true; |
155 end | 159 end |
156 | 160 |
157 function handle_stanza(host, origin, stanza) | 161 function handle_stanza(host, origin, stanza) |
158 local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns, origin.type; | 162 local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns, origin.type; |
232 | 236 |
233 function api:add_feature(xmlns) | 237 function api:add_feature(xmlns) |
234 features_table:set(self.host, self.name, xmlns, true); | 238 features_table:set(self.host, self.name, xmlns, true); |
235 end | 239 end |
236 | 240 |
237 function api:add_event_hook (...) return eventmanager.add_event_hook(...); end | 241 local event_hook = function(host, mod_name, event_name, ...) |
242 if type((...)) == "table" and (...).host and (...).host ~= host then return; end | |
243 for handler in pairs(event_hooks:get(host, mod_name, event_name) or NULL) do | |
244 handler(...); | |
245 end | |
246 end; | |
247 function api:add_event_hook(name, handler) | |
248 if not hooked:get(self.host, self.name, name) then | |
249 eventmanager.add_event_hook(name, function(...) event_hook(self.host, self.name, name, ...); end); | |
250 hooked:set(self.host, self.name, name, true); | |
251 end | |
252 event_hooks:set(self.host, self.name, name, handler, true); | |
253 end | |
238 | 254 |
239 -------------------------------------------------------------------- | 255 -------------------------------------------------------------------- |
240 | 256 |
241 return _M; | 257 return _M; |