diff options
author | Matthew Wild <mwild1@gmail.com> | 2010-06-02 17:51:39 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2010-06-02 17:51:39 +0100 |
commit | e9448c71ce7e23b56ff9d24385e4fec18f5144a2 (patch) | |
tree | 2c3d40c60df3dfed3e15717b6c7b076a129cb4aa | |
parent | 828f40f911a2f14ed4a83ce8c70e203887af3361 (diff) | |
download | prosody-e9448c71ce7e23b56ff9d24385e4fec18f5144a2.tar.gz prosody-e9448c71ce7e23b56ff9d24385e4fec18f5144a2.zip |
xmppclient_listener: Add filters for incoming bytes and stanzas
-rw-r--r-- | net/xmppclient_listener.lua | 20 |
1 files changed, 15 insertions, 5 deletions
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) |