Diff

plugins/mod_s2s/mod_s2s.lua @ 6256:d05627c89c99

mod_s2s: Move filter initialization to common place
author Kim Alvefur <zash@zash.se>
date Thu, 22 May 2014 22:48:06 +0200
parent 6255:6167f8bc5a6b
child 6257:9dace3a712f0
line wrap: on
line diff
--- a/plugins/mod_s2s/mod_s2s.lua	Thu May 22 22:45:58 2014 +0200
+++ b/plugins/mod_s2s/mod_s2s.lua	Thu May 22 22:48:06 2014 +0200
@@ -541,7 +541,23 @@
 
 	session.stream_attrs = session_stream_attrs;
 
-	local filter = session.filter;
+	local filter = initialize_filters(session);
+	local conn = session.conn;
+	local w = conn.write;
+
+	function session.sends2s(t)
+		log("debug", "sending: %s", t.top_tag and t:top_tag() or t:match("^[^>]*>?"));
+		if t.name then
+			t = filter("stanzas/out", t);
+		end
+		if t then
+			t = filter("bytes/out", tostring(t));
+			if t then
+				return w(conn, t);
+			end
+		end
+	end
+
 	function session.data(data)
 		data = filter("bytes/in", data);
 		if data then
@@ -580,22 +596,6 @@
 		session = s2s_new_incoming(conn);
 		sessions[conn] = session;
 		session.log("debug", "Incoming s2s connection");
-
-		local filter = initialize_filters(session);
-		local w = conn.write;
-		session.sends2s = function (t)
-			log("debug", "sending: %s", t.top_tag and t:top_tag() or t:match("^([^>]*>?)"));
-			if t.name then
-				t = filter("stanzas/out", t);
-			end
-			if t then
-				t = filter("bytes/out", tostring(t));
-				if t then
-					return w(conn, t);
-				end
-			end
-		end
-
 		initialize_session(session);
 	else -- Outgoing session connected
 		session:open_stream(session.from_host, session.to_host);