Comparison

core/xmlhandlers.lua @ 40:2c0147bbd81a

Move stream opening handling from xmlhandlers to sessionmanager
author Matthew Wild <mwild1@gmail.com>
date Fri, 03 Oct 2008 22:18:08 +0100
parent 38:3fdfd6e0cb4e
child 53:14ea0fe6ca86
comparison
equal deleted inserted replaced
39:89877d61ac51 40:2c0147bbd81a
1 1
2 local sessionmanager_streamopened = require "core.sessionmanager".streamopened;
2 require "util.stanza" 3 require "util.stanza"
3 4
4 local st = stanza; 5 local st = stanza;
5 local tostring = tostring; 6 local tostring = tostring;
6 local format = string.format; 7 local format = string.format;
25 26
26 local send = session.send; 27 local send = session.send;
27 28
28 local stanza 29 local stanza
29 function xml_handlers:StartElement(name, attr) 30 function xml_handlers:StartElement(name, attr)
30 log("info", "xmlhandlers", "Start element: " .. name);
31 if stanza and #chardata > 0 then 31 if stanza and #chardata > 0 then
32 -- We have some character data in the buffer 32 -- We have some character data in the buffer
33 stanza:text(t_concat(chardata)); 33 stanza:text(t_concat(chardata));
34 chardata = {}; 34 chardata = {};
35 end 35 end
36 curr_ns,name = name:match("^(.+):(%w+)$"); 36 curr_ns,name = name:match("^(.+):(%w+)$");
37 if not stanza then 37 if not stanza then
38 if session.notopen then 38 if session.notopen then
39 if name == "stream" then 39 if name == "stream" then
40 session.host = attr.to or error("Client failed to specify destination hostname"); 40 sessionmanager_streamopened(session, attr);
41 session.version = attr.version or 0;
42 session.streamid = m_random(1000000, 99999999);
43 print(session, session.host, "Client opened stream");
44 send("<?xml version='1.0'?>");
45 send(format("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='%s' from='%s' version='1.0'>", session.streamid, session.host));
46 send("<stream:features>");
47 if not session.username then
48 send("<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>");
49 send("<mechanism>PLAIN</mechanism>");
50 send("</mechanisms>");
51 else
52 send("<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><required/></bind>");
53 end
54 --send [[<register xmlns="http://jabber.org/features/iq-register"/> ]]
55 send("</stream:features>");
56 log("info", "core", "Stream opened successfully");
57 session.notopen = nil;
58 return; 41 return;
59 end 42 end
60 error("Client failed to open stream successfully"); 43 error("Client failed to open stream successfully");
61 end 44 end
62 if curr_ns == "jabber:client" and name ~= "iq" and name ~= "presence" and name ~= "message" then 45 if curr_ns == "jabber:client" and name ~= "iq" and name ~= "presence" and name ~= "message" then