Backout 63f5870f9afe, no longer needed since Windows is currently unsupported
[prosody.git] / plugins / mod_c2s.lua
index efef8763a3d38f51cd45324a5bff1eab50639a5d..3d6487c91eadd11b942e2063a32437b58990ce9c 100644 (file)
@@ -25,7 +25,7 @@ local log = module._log;
 
 local c2s_timeout = module:get_option_number("c2s_timeout");
 local stream_close_timeout = module:get_option_number("c2s_close_timeout", 5);
-local opt_keepalives = module:get_option_boolean("tcp_keepalives", false);
+local opt_keepalives = module:get_option_boolean("c2s_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true));
 
 local sessions = module:shared("sessions");
 local core_process_stanza = prosody.core_process_stanza;
@@ -50,7 +50,7 @@ function stream_callbacks.streamopened(session, attr)
        session.streamid = uuid_generate();
        (session.log or session)("debug", "Client sent opening <stream:stream> to %s", session.host);
 
-       if not hosts[session.host] then
+       if not hosts[session.host] or not hosts[session.host].users then
                -- We don't serve this host...
                session:close{ condition = "host-unknown", text = "This server does not serve "..tostring(session.host)};
                return;
@@ -91,7 +91,7 @@ end
 
 function stream_callbacks.error(session, error, data)
        if error == "no-stream" then
-               session.log("debug", "Invalid opening stream header");
+               session.log("debug", "Invalid opening stream header (%s)", (data:gsub("^([^\1]+)\1", "{%1}")));
                session:close("invalid-namespace");
        elseif error == "parse-error" then
                (session.log or log)("debug", "Client XML parse error: %s", tostring(data));
@@ -157,7 +157,7 @@ local function session_close(session, reason)
                session.send("</stream:stream>");
                function session.send() return false; end
                
-               local reason = (reason and (reason.text or reason.condition)) or reason;
+               local reason = (reason and (reason.name or reason.text or reason.condition)) or reason;
                session.log("info", "c2s stream for %s closed: %s", session.full_jid or ("<"..session.ip..">"), reason or "session closed");
 
                -- Authenticated incoming stream may still be sending us stanzas, so wait for </stream:stream> from remote
@@ -266,6 +266,10 @@ function listener.associate_session(conn, session)
        sessions[conn] = session;
 end
 
+function listener.ondetach(conn)
+       sessions[conn] = nil;
+end
+
 module:hook("server-stopping", function(event)
        local reason = event.reason;
        for _, session in pairs(sessions) do