Software /
code /
prosody
Comparison
core/s2smanager.lua @ 3146:aaaea4cdbf10
s2smanager: Add filters for outgoing bytes and stanzas
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 02 Jun 2010 18:23:15 +0100 |
parent | 2951:294c359a05f5 |
child | 3152:c6091977624b |
comparison
equal
deleted
inserted
replaced
3145:675241be2935 | 3146:aaaea4cdbf10 |
---|---|
21 = tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber, | 21 = tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber, |
22 setmetatable; | 22 setmetatable; |
23 | 23 |
24 local idna_to_ascii = require "util.encodings".idna.to_ascii; | 24 local idna_to_ascii = require "util.encodings".idna.to_ascii; |
25 local connlisteners_get = require "net.connlisteners".get; | 25 local connlisteners_get = require "net.connlisteners".get; |
26 local initialize_filters = require "util.filters".initialize; | |
26 local wrapclient = require "net.server".wrapclient; | 27 local wrapclient = require "net.server".wrapclient; |
27 local modulemanager = require "core.modulemanager"; | 28 local modulemanager = require "core.modulemanager"; |
28 local st = require "stanza"; | 29 local st = require "stanza"; |
29 local stanza = st.stanza; | 30 local stanza = st.stanza; |
30 local nameprep = require "util.encodings".stringprep.nameprep; | 31 local nameprep = require "util.encodings".stringprep.nameprep; |
135 getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; end; | 136 getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; end; |
136 end | 137 end |
137 open_sessions = open_sessions + 1; | 138 open_sessions = open_sessions + 1; |
138 local w, log = conn.write, logger_init("s2sin"..tostring(conn):match("[a-f0-9]+$")); | 139 local w, log = conn.write, logger_init("s2sin"..tostring(conn):match("[a-f0-9]+$")); |
139 session.log = log; | 140 session.log = log; |
140 session.sends2s = function (t) log("debug", "sending: %s", t.top_tag and t:top_tag() or t:match("^([^>]*>?)")); w(conn, tostring(t)); end | 141 local filter = initialize_filters(session); |
142 session.sends2s = function (t) | |
143 if t.name then | |
144 t = filter("stanzas/out", t); | |
145 end | |
146 if t then | |
147 t = filter("bytes/out", tostring(t)); | |
148 if t then | |
149 log("debug", "sending: %s", t.top_tag and t:top_tag() or t:match("^([^>]*>?)")); | |
150 return w(conn, t); | |
151 end | |
152 end | |
153 end | |
141 incoming_s2s[session] = true; | 154 incoming_s2s[session] = true; |
142 add_task(connect_timeout, function () | 155 add_task(connect_timeout, function () |
143 if session.conn ~= conn or | 156 if session.conn ~= conn or |
144 session.type == "s2sin" then | 157 session.type == "s2sin" then |
145 return; -- Ok, we're connect[ed|ing] | 158 return; -- Ok, we're connect[ed|ing] |
163 do | 176 do |
164 local conn_name = "s2sout"..tostring(host_session):match("[a-f0-9]*$"); | 177 local conn_name = "s2sout"..tostring(host_session):match("[a-f0-9]*$"); |
165 log = logger_init(conn_name); | 178 log = logger_init(conn_name); |
166 host_session.log = log; | 179 host_session.log = log; |
167 end | 180 end |
181 | |
182 initialize_filters(host_session); | |
168 | 183 |
169 if connect ~= false then | 184 if connect ~= false then |
170 -- Kick the connection attempting machine into life | 185 -- Kick the connection attempting machine into life |
171 attempt_connection(host_session); | 186 attempt_connection(host_session); |
172 end | 187 end |
330 | 345 |
331 -- Register this outgoing connection so that xmppserver_listener knows about it | 346 -- Register this outgoing connection so that xmppserver_listener knows about it |
332 -- otherwise it will assume it is a new incoming connection | 347 -- otherwise it will assume it is a new incoming connection |
333 cl.register_outgoing(conn, host_session); | 348 cl.register_outgoing(conn, host_session); |
334 | 349 |
350 local filter = initialize_filters(host_session); | |
335 local w, log = conn.write, host_session.log; | 351 local w, log = conn.write, host_session.log; |
336 host_session.sends2s = function (t) log("debug", "sending: %s", (t.top_tag and t:top_tag()) or t:match("^[^>]*>?")); w(conn, tostring(t)); end | 352 host_session.sends2s = function (t) |
353 if t.name then | |
354 t = filter("stanzas/out", t); | |
355 end | |
356 if t then | |
357 t = filter("bytes/out", tostring(t)); | |
358 if t then | |
359 log("debug", "sending: %s", (t.top_tag and t:top_tag()) or t:match("^[^>]*>?")); | |
360 return w(conn, tostring(t)); | |
361 end | |
362 end | |
363 end | |
337 | 364 |
338 host_session:open_stream(from_host, to_host); | 365 host_session:open_stream(from_host, to_host); |
339 | 366 |
340 log("debug", "Connection attempt in progress..."); | 367 log("debug", "Connection attempt in progress..."); |
341 add_task(connect_timeout, function () | 368 add_task(connect_timeout, function () |