Comparison

core/modulemanager.lua @ 38:3fdfd6e0cb4e

SASL! (but before you get too excited, no resource binding yet. And yes, there are still plenty of rough edges to the code...) ((eg. must move <stream:features> out of xmlhandlers.lua o_O ))
author Matthew Wild <mwild1@gmail.com>
date Thu, 02 Oct 2008 01:08:58 +0100
parent 30:bcf539295f2d
child 39:89877d61ac51
comparison
equal deleted inserted replaced
37:06eadafafefa 38:3fdfd6e0cb4e
21 handlers[origin_type] = handlers[origin_type] or {}; 21 handlers[origin_type] = handlers[origin_type] or {};
22 handlers[origin_type].iq = handlers[origin_type].iq or {}; 22 handlers[origin_type].iq = handlers[origin_type].iq or {};
23 if not handlers[origin_type].iq[xmlns] then 23 if not handlers[origin_type].iq[xmlns] then
24 handlers[origin_type].iq[xmlns]= handler; 24 handlers[origin_type].iq[xmlns]= handler;
25 handler_info[handler] = getfenv(2).module; 25 handler_info[handler] = getfenv(2).module;
26 log("debug", "mod_%s now handles iq,%s", getfenv(2).module.name, xmlns); 26 log("debug", "mod_%s now handles tag 'iq' with query namespace '%s'", getfenv(2).module.name, xmlns);
27 else 27 else
28 log("warning", "mod_%s wants to handle iq,%s but mod_%s already handles that", getfenv(2).module.name, xmlns, handler_info[handlers[origin_type].iq[xmlns]].module.name); 28 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 end 29 end
30 end 30 end
31 31
32 function modulehelpers.add_presence_handler(origin_type, handler) 32 function modulehelpers.add_handler(origin_type, tag, handler)
33 end 33 handlers[origin_type] = handlers[origin_type] or {};
34 34 if not handlers[origin_type][tag] then
35 function modulehelpers.add_message_handler(origin_type, handler) 35 handlers[origin_type][tag]= handler;
36 handler_info[handler] = getfenv(2).module;
37 log("debug", "mod_%s now handles tag '%s'", getfenv(2).module.name, tag);
38 elseif handler_info[handlers[origin_type][tag]] then
39 log("warning", "mod_%s wants to handle tag '%s' but mod_%s already handles that", getfenv(2).module.name, tag, handler_info[handlers[origin_type][tag]].module.name);
40 end
36 end 41 end
37 42
38 function loadall() 43 function loadall()
44 load("saslauth");
39 load("legacyauth"); 45 load("legacyauth");
40 load("roster"); 46 load("roster");
41 end 47 end
42 48
43 function load(name) 49 function load(name)
56 return; 62 return;
57 end 63 end
58 end 64 end
59 65
60 function handle_stanza(origin, stanza) 66 function handle_stanza(origin, stanza)
61 local name, origin_type = stanza.name, origin.type; 67 local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns, origin.type;
62 68
63 if name == "iq" then 69 if name == "iq" and xmlns == "jabber:client" and handlers[origin_type] then
64 log("debug", "Stanza is an <iq/>"); 70 log("debug", "Stanza is an <iq/>");
65 local child = stanza.tags[1]; 71 local child = stanza.tags[1];
66 if child then 72 if child then
67 local xmlns = child.attr.xmlns; 73 local xmlns = child.attr.xmlns;
68 log("debug", "Stanza has xmlns: %s", xmlns); 74 log("debug", "Stanza has xmlns: %s", xmlns);
71 log("debug", "Passing stanza to mod_%s", handler_info[handler].name); 77 log("debug", "Passing stanza to mod_%s", handler_info[handler].name);
72 return handler(origin, stanza) or true; 78 return handler(origin, stanza) or true;
73 end 79 end
74 80
75 end 81 end
82 --FIXME: All iq's must be replied to, here we should return service-unavailable I think
83 elseif handlers[origin_type] then
84 local handler = handlers[origin_type][name];
85 if handler then
86 log("debug", "Passing stanza to mod_%s", handler_info[handler].name);
87 return handler(origin, stanza) or true;
88 end
76 end 89 end
77 log("debug", "Stanza unhandled by any modules"); 90 log("debug", "Stanza unhandled by any modules");
78 return false; -- we didn't handle it 91 return false; -- we didn't handle it
79 end 92 end