Software /
code /
prosody
Changeset
3032:38459cffaf67
util.xmppstream: Stream objects now just have feed/reset methods
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 09 May 2010 20:45:53 +0100 |
parents | 3031:421890f3f247 |
children | 3033:0194d7eab8a5 |
files | util/xmppstream.lua |
diffstat | 1 files changed, 22 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/util/xmppstream.lua Fri May 07 21:43:37 2010 +0100 +++ b/util/xmppstream.lua Sun May 09 20:45:53 2010 +0100 @@ -32,8 +32,8 @@ 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 @@ 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 @@ 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;