sessionmanager, s2smanager: Destroyed sessions are now simply resting (not dead)...
[prosody.git] / net / xmppserver_listener.lua
index 3def46b5e362a010004076a2af5e5cafbf1c86c8..8a3886adf3b9d38d71b6b9c36ebe87294056e1cc 100644 (file)
@@ -20,12 +20,31 @@ local s2s_attempt_connect = require "core.s2smanager".attempt_connection;
 local stream_callbacks = { default_ns = "jabber:server",
                streamopened = s2s_streamopened, streamclosed = s2s_streamclosed, handlestanza =  core_process_stanza };
 
+local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams";
+
 function stream_callbacks.error(session, error, data)
        if error == "no-stream" then
                session:close("invalid-namespace");
-       else
+       elseif error == "parse-error" then
                session.log("debug", "Server-to-server XML parse error: %s", tostring(error));
                session:close("xml-not-well-formed");
+       elseif error == "stream-error" then
+               local condition, text = "undefined-condition";
+               for child in data:children() do
+                       if child.attr.xmlns == xmlns_xmpp_streams then
+                               if child.name ~= "text" then
+                                       condition = child.name;
+                               else
+                                       text = child:get_text();
+                               end
+                               if condition ~= "undefined-condition" and text then
+                                       break;
+                               end
+                       end
+               end
+               text = condition .. (text and (" ("..text..")") or "");
+               session.log("info", "Session closed by remote with error: %s", text);
+               session:close(nil, text);
        end
 end
 
@@ -136,7 +155,7 @@ function xmppserver.onincoming(conn, data)
        end
 end
        
-function xmppserver.status(conn, status)
+function xmppserver.onstatus(conn, status)
        if status == "ssl-handshake-complete" then
                local session = sessions[conn];
                if session and session.direction == "outgoing" then
@@ -157,7 +176,7 @@ function xmppserver.ondisconnect(conn, err)
                                return; -- Session lives for now
                        end
                end
-               (session.log or log)("info", "s2s disconnected: %s->%s (%s)", tostring(session.from_host), tostring(session.to_host), tostring(err));
+               (session.log or log)("info", "s2s disconnected: %s->%s (%s)", tostring(session.from_host), tostring(session.to_host), tostring(err or "closed"));
                s2s_destroy_session(session, err);
                sessions[conn]  = nil;
                session = nil;