aboutsummaryrefslogtreecommitdiffstats
path: root/core/s2smanager.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2010-06-02 18:23:15 +0100
committerMatthew Wild <mwild1@gmail.com>2010-06-02 18:23:15 +0100
commitcb5b77242767f60d54624708cfca01bb9f1671a6 (patch)
tree3323a16b1b2c6015a2c42d591332bda1e2bc40f4 /core/s2smanager.lua
parent215235bd7c20cd24c832f013f3f6515d7692c711 (diff)
downloadprosody-cb5b77242767f60d54624708cfca01bb9f1671a6.tar.gz
prosody-cb5b77242767f60d54624708cfca01bb9f1671a6.zip
s2smanager: Add filters for outgoing bytes and stanzas
Diffstat (limited to 'core/s2smanager.lua')
-rw-r--r--core/s2smanager.lua31
1 files 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);