mod_storage_sql2: Add archive store with append and find methods
[prosody.git] / plugins / mod_c2s.lua
index efef8763a3d38f51cd45324a5bff1eab50639a5d..91bde5742f844f6019797129f7e15a64412da32c 100644 (file)
@@ -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].modules.c2s then
                -- We don't serve this host...
                session:close{ condition = "host-unknown", text = "This server does not serve "..tostring(session.host)};
                return;
@@ -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
@@ -262,10 +262,27 @@ function listener.ondisconnect(conn, err)
        end
 end
 
+function listener.onreadtimeout(conn)
+       local session = sessions[conn];
+       if session then
+               return (hosts[session.host] or prosody).events.fire_event("c2s-read-timeout", { session = session });
+       end
+end
+
+local function keepalive(event)
+       return event.session.send(' ');
+end
+
 function listener.associate_session(conn, session)
        sessions[conn] = session;
 end
 
+function module.add_host(module)
+       module:hook("c2s-read-timeout", keepalive, -1);
+end
+
+module:hook("c2s-read-timeout", keepalive, -1);
+
 module:hook("server-stopping", function(event)
        local reason = event.reason;
        for _, session in pairs(sessions) do