From e9448c71ce7e23b56ff9d24385e4fec18f5144a2 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 2 Jun 2010 17:51:39 +0100 Subject: xmppclient_listener: Add filters for incoming bytes and stanzas --- net/xmppclient_listener.lua | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'net') diff --git a/net/xmppclient_listener.lua b/net/xmppclient_listener.lua index 49b0e7f9..623a98c8 100644 --- a/net/xmppclient_listener.lua +++ b/net/xmppclient_listener.lua @@ -138,14 +138,24 @@ function xmppclient.onconnect(conn) session.stream:reset(); end + local filter = session.filter; function session.data(data) - local ok, err = stream:feed(data); - if ok then return; end - log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_")); - session:close("xml-not-well-formed"); + data = filter("bytes/in", data); + if data then + local ok, err = stream:feed(data); + if ok then return; end + log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_")); + session:close("xml-not-well-formed"); + end end - session.dispatch_stanza = stream_callbacks.handlestanza; + local handlestanza = stream_callbacks.handlestanza; + function session.dispatch_stanza(session, stanza) + stanza = filter("stanzas/in", stanza); + if stanza then + return handlestanza(session, stanza); + end + end end function xmppclient.onincoming(conn, data) -- cgit v1.2.3