aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2010-05-09 20:45:53 +0100
committerMatthew Wild <mwild1@gmail.com>2010-05-09 20:45:53 +0100
commitaa0ed5d64b87574d02f773879145e9dd9a259a53 (patch)
treee2ed8fb279fb526555798216b728fde44349b2d5 /util
parentf83f25d08a14fd01003a5e38e6a2d9867ee5ec28 (diff)
downloadprosody-aa0ed5d64b87574d02f773879145e9dd9a259a53.tar.gz
prosody-aa0ed5d64b87574d02f773879145e9dd9a259a53.zip
util.xmppstream: Stream objects now just have feed/reset methods
Diffstat (limited to 'util')
-rw-r--r--util/xmppstream.lua26
1 files changed, 22 insertions, 4 deletions
diff --git a/util/xmppstream.lua b/util/xmppstream.lua
index f7744fea..ed5395b5 100644
--- a/util/xmppstream.lua
+++ b/util/xmppstream.lua
@@ -32,8 +32,8 @@ local ns_separator = "\1";
local ns_pattern = "^([^"..ns_separator.."]*)"..ns_separator.."?(.*)$";
function new_sax_handlers(session, stream_callbacks)
- local chardata = {};
local xml_handlers = {};
+
local log = session.log or default_log;
local cb_streamopened = stream_callbacks.streamopened;
@@ -47,7 +47,7 @@ function new_sax_handlers(session, stream_callbacks)
local stream_default_ns = stream_callbacks.default_ns;
- local stanza;
+ local chardata, stanza = {};
function xml_handlers:StartElement(tagname, attr)
if stanza and #chardata > 0 then
-- We have some character data in the buffer
@@ -140,11 +140,29 @@ function new_sax_handlers(session, stream_callbacks)
stanza, chardata = nil, {};
end
end
- return xml_handlers;
+
+ local function reset()
+ stanza, chardata = nil, {};
+ end
+
+ return xml_handlers, { reset = reset };
end
function new(session, stream_callbacks)
- return new_parser(new_sax_handlers(session, stream_callbacks), ns_separator);
+ local handlers, meta = new_sax_handlers(session, stream_callbacks);
+ local parser = new_parser(handlers, ns_separator);
+ local parse = parser.parse;
+
+ return {
+ reset = function ()
+ parser = new_parser(handlers, ns_separator);
+ parse = parser.parse;
+ meta.reset();
+ end,
+ feed = function (self, data)
+ return parse(parser, data);
+ end
+ };
end
return _M;