s2smanager: Have both destroy_session and bounce_sendq accept a reason string to...
authorMatthew Wild <mwild1@gmail.com>
Thu, 17 Dec 2009 18:59:29 +0000 (18:59 +0000)
committerMatthew Wild <mwild1@gmail.com>
Thu, 17 Dec 2009 18:59:29 +0000 (18:59 +0000)
core/s2smanager.lua

index 4891b4994d514dea5b3895256b64e7029bf7e185..34efc2543bd6af826516de16dbd5ac9bbb4a6fc2 100644 (file)
@@ -54,7 +54,7 @@ function compare_srv_priorities(a,b)
        return a.priority < b.priority or (a.priority == b.priority and a.weight > b.weight);
 end
 
        return a.priority < b.priority or (a.priority == b.priority and a.weight > b.weight);
 end
 
-local function bounce_sendq(session)
+local function bounce_sendq(session, reason)
        local sendq = session.sendq;
        if sendq then
                session.log("info", "sending error replies for "..#sendq.." queued stanzas because of failed outgoing connection to "..tostring(session.to_host));
        local sendq = session.sendq;
        if sendq then
                session.log("info", "sending error replies for "..#sendq.." queued stanzas because of failed outgoing connection to "..tostring(session.to_host));
@@ -72,6 +72,9 @@ local function bounce_sendq(session)
                                reply.attr.type = "error";
                                reply:tag("error", {type = "cancel"})
                                        :tag("remote-server-not-found", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}):up();
                                reply.attr.type = "error";
                                reply:tag("error", {type = "cancel"})
                                        :tag("remote-server-not-found", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}):up();
+                               if reason then
+                                       reply:tag("text", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}):text("Connection failed: "..reason):up();
+                               end
                                core_process_stanza(dummy, reply);
                        end
                        sendq[i] = nil;
                                core_process_stanza(dummy, reply);
                        end
                        sendq[i] = nil;
@@ -491,12 +494,12 @@ function mark_connected(session)
        end
 end
 
        end
 end
 
-function destroy_session(session)
+function destroy_session(session, reason)
        (session.log or log)("info", "Destroying "..tostring(session.direction).." session "..tostring(session.from_host).."->"..tostring(session.to_host));
        
        if session.direction == "outgoing" then
                hosts[session.from_host].s2sout[session.to_host] = nil;
        (session.log or log)("info", "Destroying "..tostring(session.direction).." session "..tostring(session.from_host).."->"..tostring(session.to_host));
        
        if session.direction == "outgoing" then
                hosts[session.from_host].s2sout[session.to_host] = nil;
-               bounce_sendq(session);
+               bounce_sendq(session, reason);
        elseif session.direction == "incoming" then
                incoming_s2s[session] = nil;
        end
        elseif session.direction == "incoming" then
                incoming_s2s[session] = nil;
        end