Software /
code /
prosody
Comparison
core/modulemanager.lua @ 196:ebe23269b377
Fix for add_iq_handler to allow multiple origin types too
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 02 Nov 2008 01:26:37 +0000 |
parent | 191:e64c8a44060f |
child | 197:19c57a24afa1 |
comparison
equal
deleted
inserted
replaced
195:08753eafbf46 | 196:ebe23269b377 |
---|---|
16 local handler_info = {}; | 16 local handler_info = {}; |
17 local handlers = {}; | 17 local handlers = {}; |
18 | 18 |
19 local modulehelpers = setmetatable({}, { __index = _G }); | 19 local modulehelpers = setmetatable({}, { __index = _G }); |
20 | 20 |
21 function modulehelpers.add_iq_handler(origin_type, xmlns, handler) | 21 local function _add_iq_handler(module, origin_type, xmlns, handler) |
22 if not (origin_type and handler and xmlns) then return false; end | |
23 handlers[origin_type] = handlers[origin_type] or {}; | 22 handlers[origin_type] = handlers[origin_type] or {}; |
24 handlers[origin_type].iq = handlers[origin_type].iq or {}; | 23 handlers[origin_type].iq = handlers[origin_type].iq or {}; |
25 if not handlers[origin_type].iq[xmlns] then | 24 if not handlers[origin_type].iq[xmlns] then |
26 handlers[origin_type].iq[xmlns]= handler; | 25 handlers[origin_type].iq[xmlns]= handler; |
27 handler_info[handler] = getfenv(2).module; | 26 handler_info[handler] = module; |
28 log("debug", "mod_%s now handles tag 'iq' with query namespace '%s'", getfenv(2).module.name, xmlns); | 27 log("debug", "mod_%s now handles tag 'iq' with query namespace '%s'", module.name, xmlns); |
29 else | 28 else |
30 log("warning", "mod_%s wants to handle tag 'iq' with query namespace '%s' but mod_%s already handles that", getfenv(2).module.name, xmlns, handler_info[handlers[origin_type].iq[xmlns]].module.name); | 29 log("warning", "mod_%s wants to handle tag 'iq' with query namespace '%s' but mod_%s already handles that", module.name, xmlns, handler_info[handlers[origin_type].iq[xmlns]].module.name); |
31 end | 30 end |
31 end | |
32 | |
33 function modulehelpers.add_iq_handler(origin_type, xmlns, handler) | |
34 if not (origin_type and handler and xmlns) then return false; end | |
35 if type(origin_type) == "table" then | |
36 for _, origin_type in ipairs(origin_type) do | |
37 _add_iq_handler(getfenv(2), origin_type, xmlns, handler); | |
38 end | |
39 return; | |
40 end | |
41 _add_iq_handler(getfenv(2), origin_type, xmlns, handler); | |
32 end | 42 end |
33 | 43 |
34 local function _add_handler(module, origin_type, tag, xmlns, handler) | 44 local function _add_handler(module, origin_type, tag, xmlns, handler) |
35 handlers[origin_type] = handlers[origin_type] or {}; | 45 handlers[origin_type] = handlers[origin_type] or {}; |
36 if not handlers[origin_type][tag] then | 46 if not handlers[origin_type][tag] then |