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 local xmlns_component = "jabber:component:accept"; |
16 local xmlns_component = "jabber:component:accept"; |
17 |
17 |
18 local stream_callbacks = { |
18 local stream_callbacks = { |
41 |
41 |
42 return stream:event("stanza", stanza); |
42 return stream:event("stanza", stanza); |
43 end |
43 end |
44 |
44 |
45 function stream:reset() |
45 function stream:reset() |
46 -- Reset stream |
46 if self.stream then |
47 local parser = lxp.new(init_xmlhandlers(self, stream_callbacks), "\1"); |
47 self.stream:reset(); |
48 self.parser = parser; |
48 else |
49 |
49 self.stream = new_xmpp_stream(self, stream_callbacks); |
|
50 end |
50 self.notopen = true; |
51 self.notopen = true; |
51 |
|
52 return true; |
52 return true; |
53 end |
53 end |
54 |
54 |
55 function stream:connect_component(jid, pass) |
55 function stream:connect_component(jid, pass) |
56 self.jid, self.password = jid, pass; |
56 self.jid, self.password = jid, pass; |
57 self.username, self.host, self.resource = jid_split(jid); |
57 self.username, self.host, self.resource = jid_split(jid); |
58 |
58 |
59 function self.data(conn, data) |
59 function self.data(conn, data) |
60 local ok, err = self.parser:parse(data); |
60 local ok, err = self.stream:feed(data); |
61 if ok then return; end |
61 if ok then return; end |
62 stream:debug("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " ")); |
62 stream:debug("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " ")); |
63 stream:close("xml-not-well-formed"); |
63 stream:close("xml-not-well-formed"); |
64 end |
64 end |
65 |
65 |