Software /
code /
verse
Changeset
70:36d113fb0f3c
verse.client: Add stream:reset(), keep self.data static between resets
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 28 May 2010 23:26:31 +0100 |
parents | 69:a2a888aec7f3 |
children | 71:5b74d155036d |
files | client.lua |
diffstat | 1 files changed, 12 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/client.lua Fri May 28 20:59:38 2010 +0100 +++ b/client.lua Fri May 28 23:26:31 2010 +0100 @@ -39,19 +39,12 @@ return stream:event("stanza", stanza); end -local function reset_stream(stream) +function stream:reset() -- Reset stream - local parser = lxp.new(init_xmlhandlers(stream, stream_callbacks), "\1"); - stream.parser = parser; - - stream.notopen = true; + local parser = lxp.new(init_xmlhandlers(self, stream_callbacks), "\1"); + self.parser = parser; - function stream.data(conn, data) - local ok, err = parser:parse(data); - if ok then return; end - stream:debug("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " ")); - stream:close("xml-not-well-formed"); - end + self.notopen = true; return true; end @@ -66,6 +59,13 @@ self:add_plugin("bind"); self:add_plugin("session"); + function self.data(conn, data) + local ok, err = self.parser:parse(data); + if ok then return; end + stream:debug("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " ")); + stream:close("xml-not-well-formed"); + end + self:hook("incoming-raw", function (data) return self.data(self.conn, data); end); self.curr_id = 0; @@ -99,12 +99,11 @@ -- Initialise connection self:connect(self.connect_host or self.host, self.connect_port or 5222); - --reset_stream(self); self:reopen(); end function stream:reopen() - reset_stream(self); + self:reset(); self:send(st.stanza("stream:stream", { to = self.host, ["xmlns:stream"]='http://etherx.jabber.org/streams', xmlns = "jabber:client", version = "1.0" }):top_tag()); end