Software /
code /
prosody
Changeset
3144:9e16012c2155
xmppclient_listener: Add filters for incoming bytes and stanzas
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 02 Jun 2010 17:51:39 +0100 |
parents | 3143:887a6374f51c |
children | 3145:675241be2935 |
files | net/xmppclient_listener.lua |
diffstat | 1 files changed, 15 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/net/xmppclient_listener.lua Wed Jun 02 17:51:14 2010 +0100 +++ b/net/xmppclient_listener.lua Wed Jun 02 17:51:39 2010 +0100 @@ -138,14 +138,24 @@ 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)