# HG changeset patch # User Matthew Wild # Date 1275499395 -3600 # Node ID aaaea4cdbf1095b40e3e63f1ecee1f0babf1c385 # Parent 675241be29351ac25ab31e0121e3f508a4568c83 s2smanager: Add filters for outgoing bytes and stanzas diff -r 675241be2935 -r aaaea4cdbf10 core/s2smanager.lua --- a/core/s2smanager.lua Wed Jun 02 18:22:23 2010 +0100 +++ b/core/s2smanager.lua Wed Jun 02 18:23:15 2010 +0100 @@ -23,6 +23,7 @@ local idna_to_ascii = require "util.encodings".idna.to_ascii; local connlisteners_get = require "net.connlisteners".get; +local initialize_filters = require "util.filters".initialize; local wrapclient = require "net.server".wrapclient; local modulemanager = require "core.modulemanager"; local st = require "stanza"; @@ -137,7 +138,19 @@ open_sessions = open_sessions + 1; local w, log = conn.write, logger_init("s2sin"..tostring(conn):match("[a-f0-9]+$")); session.log = log; - session.sends2s = function (t) log("debug", "sending: %s", t.top_tag and t:top_tag() or t:match("^([^>]*>?)")); w(conn, tostring(t)); end + local filter = initialize_filters(session); + session.sends2s = function (t) + if t.name then + t = filter("stanzas/out", t); + end + if t then + t = filter("bytes/out", tostring(t)); + if t then + log("debug", "sending: %s", t.top_tag and t:top_tag() or t:match("^([^>]*>?)")); + return w(conn, t); + end + end + end incoming_s2s[session] = true; add_task(connect_timeout, function () if session.conn ~= conn or @@ -166,6 +179,8 @@ host_session.log = log; end + initialize_filters(host_session); + if connect ~= false then -- Kick the connection attempting machine into life attempt_connection(host_session); @@ -332,8 +347,20 @@ -- otherwise it will assume it is a new incoming connection cl.register_outgoing(conn, host_session); + local filter = initialize_filters(host_session); local w, log = conn.write, host_session.log; - host_session.sends2s = function (t) log("debug", "sending: %s", (t.top_tag and t:top_tag()) or t:match("^[^>]*>?")); w(conn, tostring(t)); end + host_session.sends2s = function (t) + if t.name then + t = filter("stanzas/out", t); + end + if t then + t = filter("bytes/out", tostring(t)); + if t then + log("debug", "sending: %s", (t.top_tag and t:top_tag()) or t:match("^[^>]*>?")); + return w(conn, tostring(t)); + end + end + end host_session:open_stream(from_host, to_host);