mod_s2s: Move filter initialization to common place
authorKim Alvefur <zash@zash.se>
Thu, 22 May 2014 20:48:06 +0000 (22:48 +0200)
committerKim Alvefur <zash@zash.se>
Thu, 22 May 2014 20:48:06 +0000 (22:48 +0200)
plugins/mod_s2s/mod_s2s.lua
plugins/mod_s2s/s2sout.lib.lua

index d35fc4891712f370fd9aff2cf8bb9e8a9e6dd41f..b256374a51595887bf12498aa6c8e21bf7812029 100644 (file)
@@ -541,7 +541,23 @@ local function initialize_session(session)
 
        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 @@ function listener.onconnect(conn)
                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);
index 42b4281c7deb859de9b3fab40e121ac947250bd1..942a618d6244b86ae09b705b894810ca4fc3483f 100644 (file)
@@ -297,21 +297,6 @@ function s2sout.make_connect(host_session, connect_host, connect_port)
        conn = wrapclient(conn, connect_host.addr, connect_port, s2s_listener, "*a");
        host_session.conn = conn;
 
-       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("^[^>]*>?"));
-               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, tostring(t));
-                       end
-               end
-       end
-
        -- Register this outgoing connection so that xmppserver_listener knows about it
        -- otherwise it will assume it is a new incoming connection
        s2s_listener.register_outgoing(conn, host_session);