From cb5b77242767f60d54624708cfca01bb9f1671a6 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 2 Jun 2010 18:23:15 +0100 Subject: s2smanager: Add filters for outgoing bytes and stanzas --- core/s2smanager.lua | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index ca87670a..7d39240f 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -23,6 +23,7 @@ local tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber, 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 @@ function new_incoming(conn) 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 @@ function new_outgoing(from_host, to_host, connect) 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 @@ function make_connect(host_session, connect_host, connect_port) -- 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); -- cgit v1.2.3