Comparison

core/modulemanager.lua @ 42:2e3715e30912

Small fixes
author Matthew Wild <mwild1@gmail.com>
date Sat, 04 Oct 2008 02:09:46 +0100
parent 39:89877d61ac51
child 47:33ed4c6ac249
comparison
equal deleted inserted replaced
41:68297fef35ff 42:2e3715e30912
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 function modulehelpers.add_iq_handler(origin_type, xmlns, handler)
22 if not (origin_type and handler and xmlns) then return false; end
22 handlers[origin_type] = handlers[origin_type] or {}; 23 handlers[origin_type] = handlers[origin_type] or {};
23 handlers[origin_type].iq = handlers[origin_type].iq or {}; 24 handlers[origin_type].iq = handlers[origin_type].iq or {};
24 if not handlers[origin_type].iq[xmlns] then 25 if not handlers[origin_type].iq[xmlns] then
25 handlers[origin_type].iq[xmlns]= handler; 26 handlers[origin_type].iq[xmlns]= handler;
26 handler_info[handler] = getfenv(2).module; 27 handler_info[handler] = getfenv(2).module;
28 else 29 else
29 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); 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);
30 end 31 end
31 end 32 end
32 33
33 function modulehelpers.add_handler(origin_type, tag, handler) 34 function modulehelpers.add_handler(origin_type, tag, xmlns, handler)
35 if not (origin_type and tag and xmlns and handler) then return false; end
34 handlers[origin_type] = handlers[origin_type] or {}; 36 handlers[origin_type] = handlers[origin_type] or {};
35 if not handlers[origin_type][tag] then 37 if not handlers[origin_type][tag] then
36 handlers[origin_type][tag]= handler; 38 handlers[origin_type][tag]= handler;
37 handler_info[handler] = getfenv(2).module; 39 handler_info[handler] = getfenv(2).module;
38 log("debug", "mod_%s now handles tag '%s'", getfenv(2).module.name, tag); 40 log("debug", "mod_%s now handles tag '%s'", getfenv(2).module.name, tag);
78 log("debug", "Passing stanza to mod_%s", handler_info[handler].name); 80 log("debug", "Passing stanza to mod_%s", handler_info[handler].name);
79 return handler(origin, stanza) or true; 81 return handler(origin, stanza) or true;
80 end 82 end
81 83
82 end 84 end
83 --FIXME: All iq's must be replied to, here we should return service-unavailable I think
84 elseif handlers[origin_type] then 85 elseif handlers[origin_type] then
85 local handler = handlers[origin_type][name]; 86 local handler = handlers[origin_type][name];
86 if handler then 87 if handler then
87 log("debug", "Passing stanza to mod_%s", handler_info[handler].name); 88 log("debug", "Passing stanza to mod_%s", handler_info[handler].name);
88 return handler(origin, stanza) or true; 89 return handler(origin, stanza) or true;