sends2s -> s2s_session.send(), s2s_session.send() -> s2s_session.sends2s()
authorMatthew Wild <mwild1@gmail.com>
Thu, 30 Oct 2008 21:11:22 +0000 (21:11 +0000)
committerMatthew Wild <mwild1@gmail.com>
Thu, 30 Oct 2008 21:11:22 +0000 (21:11 +0000)
Should fix outward routing problems.

core/s2smanager.lua
core/stanza_router.lua

index 76381e2db597ff78be7e8aa9c2177ca9f77f99a1..c980a0b02db7d7fb604a3f9f1a819b4463791d16 100644 (file)
@@ -30,7 +30,7 @@ end
 function send_to_host(from_host, to_host, data)
        if hosts[to_host] then
                -- Write to connection
-               hosts[to_host].send(data);
+               hosts[to_host].sends2s(data);
                log("debug", "stanza sent over s2s");
        else
                log("debug", "opening a new outgoing connection for this stanza");
@@ -54,7 +54,7 @@ function new_incoming(conn)
        end
        open_sessions = open_sessions + 1;
        local w = conn.write;
-       session.send = function (t) w(tostring(t)); end
+       session.sends2s = function (t) w(tostring(t)); end
        return session;
 end
 
@@ -81,7 +81,7 @@ function new_outgoing(from_host, to_host)
                end
                
                local w = conn.write;
-               host_session.send = function (t) w(tostring(t)); end
+               host_session.sends2s = function (t) w(tostring(t)); end
                
                conn.write(format([[<stream:stream xmlns='jabber:server' xmlns:db='jabber:server:dialback' xmlns:stream='http://etherx.jabber.org/streams' from='%s' to='%s' version='1.0'>]], from_host, to_host));
                 
@@ -90,7 +90,7 @@ end
 
 function streamopened(session, attr)
        session.log("debug", "s2s stream opened");
-       local send = session.send;
+       local send = session.sends2s;
        
        session.version = tonumber(attr.version) or 0;
        if session.version >= 1.0 and not (attr.to and attr.from) then
@@ -118,7 +118,7 @@ function streamopened(session, attr)
                        if not attr.id then error("stream response did not give us a streamid!!!"); end
                        session.streamid = attr.id;
                        session.dialback_key = generate_dialback(session.streamid, session.to_host, session.from_host);
-                       session.send(format("<db:result from='%s' to='%s'>%s</db:result>", session.from_host, session.to_host, session.dialback_key));
+                       session.sends2s(format("<db:result from='%s' to='%s'>%s</db:result>", session.from_host, session.to_host, session.dialback_key));
                        session.log("info", "sent dialback key on outgoing s2s stream");
                else
                        mark_connected(session);
@@ -163,10 +163,17 @@ function make_authenticated(session)
 end
 
 function mark_connected(session)
-       local sendq, send = session.sendq, session.send;
+       local sendq, send = session.sendq, session.sends2s;
+       
+       local from, to = session.from_host, session.to_host;
+       
        session.log("debug", session.direction.." s2s connection "..session.from_host.."->"..session.to_host.." is now complete");
+       
+       local send_to_host = send_to_host;
+       function session.send(data) send_to_host(from, to, data); end
+       
        if sendq then
-               session.log("debug", "sending queued stanzas across new outgoing connection");
+               session.log("debug", "sending queued stanzas across new outgoing connection to "..session.to_host);
                for i, data in ipairs(sendq) do
                        send(data);
                        sendq[i] = nil;
index dfb91ee3714e75f82ae5c24ff8acc22df2c33627..430d5ed921b8e89a16b6c842faf3bbb6b276fe9c 100644 (file)
@@ -8,20 +8,7 @@ require "core.servermanager"
 local log = require "util.logger".init("stanzarouter")
 
 local st = require "util.stanza";
-local _send = require "core.sessionmanager".send_to_session;
-local send_s2s = require "core.s2smanager".send_to_host;
-function send(session, stanza)
-       if session.type == "c2s" then
-               _send(session, stanza);
-       else
-               local xmlns = stanza.attr.xmlns;
-               --stanza.attr.xmlns = "jabber:server";
-               stanza.attr.xmlns = nil;
-               log("debug", "sending s2s stanza: %s", tostring(stanza));
-               send_s2s(session.host, host, stanza); -- TODO handle remote routing errors
-               stanza.attr.xmlns = xmlns; -- reset
-       end
-end
+
 local user_exists = require "core.usermanager".user_exists;
 
 local rostermanager = require "core.rostermanager";
@@ -142,7 +129,7 @@ function core_handle_stanza(origin, stanza)
                                        type = "invalid"
                                        log("warn", "Asked to verify a dialback key that was incorrect. An imposter is claiming to be %s?", attr.to);
                                end
-                               origin.send(format("<db:verify from='%s' to='%s' id='%s' type='%s'>%s</db:verify>", attr.to, attr.from, attr.id, type, stanza[1]));
+                               origin.sends2s(format("<db:verify from='%s' to='%s' id='%s' type='%s'>%s</db:verify>", attr.to, attr.from, attr.id, type, stanza[1]));
                        elseif stanza.name == "result" and origin.type == "s2sin_unauthed" then
                                -- he wants to be identified through dialback
                                -- We need to check the key with the Authoritative server
@@ -175,7 +162,7 @@ function core_handle_stanza(origin, stanza)
                                        log("warn", "dialback for "..(origin.dialback_verifying.from_host or "(unknown)").." failed");
                                        valid = "invalid";
                                end
-                               origin.dialback_verifying.send(format("<db:result from='%s' to='%s' id='%s' type='%s'>%s</db:result>", attr.from, attr.to, attr.id, valid, origin.dialback_verifying.dialback_key));
+                               origin.dialback_verifying.sends2s(format("<db:result from='%s' to='%s' id='%s' type='%s'>%s</db:result>", attr.from, attr.to, attr.id, valid, origin.dialback_verifying.dialback_key));
                        end
                end
        else
@@ -194,7 +181,7 @@ function send_presence_of_available_resources(user, host, jid, recipient_session
                                if pres then
                                        pres.attr.to = jid;
                                        pres.attr.from = session.full_jid;
-                                       send(recipient_session, pres);
+                                       recipient_session.send(pres);
                                        pres.attr.to = nil;
                                        pres.attr.from = nil;
                                        count = count + 1;
@@ -318,7 +305,7 @@ function core_route_stanza(origin, stanza)
                                                for k in pairs(user.sessions) do -- presence broadcast to all user resources. FIXME should this be just for available resources? Do we need to check subscription?
                                                        if user.sessions[k].full_jid then
                                                                stanza.attr.to = user.sessions[k].full_jid; -- reset at the end of function
-                                                               send(user.sessions[k], stanza);
+                                                               user.sessions[k].send(stanza);
                                                        end
                                                end
                                        end
@@ -330,14 +317,14 @@ function core_route_stanza(origin, stanza)
                                                end
                                        end
                                        -- TODO find resource with greatest priority
-                                       send(res, stanza);
+                                       res.send(stanza);
                                else
                                        -- TODO send IQ error
                                end
                        else
                                -- User + resource is online...
                                stanza.attr.to = res.full_jid; -- reset at the end of function
-                               send(res, stanza); -- Yay \o/
+                               res.send(stanza); -- Yay \o/
                        end
                else
                        -- user not online
@@ -357,11 +344,11 @@ function core_route_stanza(origin, stanza)
                                -- TODO we would get here for nodeless JIDs too. Do something fun maybe? Echo service? Let plugins use xmpp:server/resource addresses?
                                if stanza.name == "presence" then
                                        if stanza.attr.type == "probe" then
-                                               send(origin, st.presence({from = to_bare, to = from_bare, type = "unsubscribed"}));
+                                               origin.send(st.presence({from = to_bare, to = from_bare, type = "unsubscribed"}));
                                        end
                                        -- else ignore
                                else
-                                       send(origin, st.error_reply(stanza, "cancel", "service-unavailable"));
+                                       origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
                                end
                        end
                end