8 |
8 |
9 -- Shortcuts to save having to load util.stanza |
9 -- Shortcuts to save having to load util.stanza |
10 verse.message, verse.presence, verse.iq, verse.stanza, verse.reply, verse.error_reply = |
10 verse.message, verse.presence, verse.iq, verse.stanza, verse.reply, verse.error_reply = |
11 st.message, st.presence, st.iq, st.stanza, st.reply, st.error_reply; |
11 st.message, st.presence, st.iq, st.stanza, st.reply, st.error_reply; |
12 |
12 |
13 local init_xmlhandlers = require "core.xmlhandlers"; |
13 local new_xmpp_stream = require "util.xmppstream".new; |
14 |
14 |
15 local xmlns_stream = "http://etherx.jabber.org/streams"; |
15 local xmlns_stream = "http://etherx.jabber.org/streams"; |
16 |
16 |
17 local function compare_srv_priorities(a,b) |
17 local function compare_srv_priorities(a,b) |
18 return a.priority < b.priority or (a.priority == b.priority and a.weight > b.weight); |
18 return a.priority < b.priority or (a.priority == b.priority and a.weight > b.weight); |
44 |
44 |
45 return stream:event("stanza", stanza); |
45 return stream:event("stanza", stanza); |
46 end |
46 end |
47 |
47 |
48 function stream:reset() |
48 function stream:reset() |
49 -- Reset stream |
49 if self.stream then |
50 local parser = lxp.new(init_xmlhandlers(self, stream_callbacks), "\1"); |
50 self.stream:reset(); |
51 self.parser = parser; |
51 else |
52 |
52 self.stream = new_xmpp_stream(self, stream_callbacks); |
|
53 end |
53 self.notopen = true; |
54 self.notopen = true; |
54 |
|
55 return true; |
55 return true; |
56 end |
56 end |
57 |
57 |
58 function stream:connect_client(jid, pass) |
58 function stream:connect_client(jid, pass) |
59 self.jid, self.password = jid, pass; |
59 self.jid, self.password = jid, pass; |
64 self:add_plugin("sasl"); |
64 self:add_plugin("sasl"); |
65 self:add_plugin("bind"); |
65 self:add_plugin("bind"); |
66 self:add_plugin("session"); |
66 self:add_plugin("session"); |
67 |
67 |
68 function self.data(conn, data) |
68 function self.data(conn, data) |
69 local ok, err = self.parser:parse(data); |
69 local ok, err = self.stream:feed(data); |
70 if ok then return; end |
70 if ok then return; end |
71 stream:debug("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " ")); |
71 stream:debug("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " ")); |
72 stream:close("xml-not-well-formed"); |
72 stream:close("xml-not-well-formed"); |
73 end |
73 end |
74 |
74 |