25 |
25 |
26 local send = session.send; |
26 local send = session.send; |
27 |
27 |
28 local stanza |
28 local stanza |
29 function xml_handlers:StartElement(name, attr) |
29 function xml_handlers:StartElement(name, attr) |
|
30 log("info", "xmlhandlers", "Start element: " .. name); |
30 if stanza and #chardata > 0 then |
31 if stanza and #chardata > 0 then |
31 -- We have some character data in the buffer |
32 -- We have some character data in the buffer |
32 stanza:text(t_concat(chardata)); |
33 stanza:text(t_concat(chardata)); |
33 chardata = {}; |
34 chardata = {}; |
34 end |
35 end |
39 session.host = attr.to or error("Client failed to specify destination hostname"); |
40 session.host = attr.to or error("Client failed to specify destination hostname"); |
40 session.version = attr.version or 0; |
41 session.version = attr.version or 0; |
41 session.streamid = m_random(1000000, 99999999); |
42 session.streamid = m_random(1000000, 99999999); |
42 print(session, session.host, "Client opened stream"); |
43 print(session, session.host, "Client opened stream"); |
43 send("<?xml version='1.0'?>"); |
44 send("<?xml version='1.0'?>"); |
44 send(format("<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='%s' from='%s'>", session.streamid, session.host)); |
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)); |
45 --send("<stream:features>"); |
46 send("<stream:features>"); |
46 --send("<mechanism>PLAIN</mechanism>"); |
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 |
47 --send [[<register xmlns="http://jabber.org/features/iq-register"/> ]] |
54 --send [[<register xmlns="http://jabber.org/features/iq-register"/> ]] |
48 --send("</stream:features>"); |
55 send("</stream:features>"); |
49 log("info", "core", "Stream opened successfully"); |
56 log("info", "core", "Stream opened successfully"); |
50 session.notopen = nil; |
57 session.notopen = nil; |
51 return; |
58 return; |
52 end |
59 end |
53 error("Client failed to open stream successfully"); |
60 error("Client failed to open stream successfully"); |
54 end |
61 end |
55 if name ~= "iq" and name ~= "presence" and name ~= "message" then |
62 if curr_ns == "jabber:client" and name ~= "iq" and name ~= "presence" and name ~= "message" then |
56 error("Client sent invalid top-level stanza"); |
63 error("Client sent invalid top-level stanza"); |
57 end |
64 end |
58 stanza = st.stanza(name, { to = attr.to, type = attr.type, id = attr.id, xmlns = curr_ns }); |
65 attr.xmlns = curr_ns; |
|
66 stanza = st.stanza(name, attr); --{ to = attr.to, type = attr.type, id = attr.id, xmlns = curr_ns }); |
59 curr_tag = stanza; |
67 curr_tag = stanza; |
60 else |
68 else |
61 attr.xmlns = curr_ns; |
69 attr.xmlns = curr_ns; |
62 stanza:tag(name, attr); |
70 stanza:tag(name, attr); |
63 end |
71 end |