net.http: destroy_request(): Remove update for new server API, pass request.handler...
[prosody.git] / net / xmppclient_listener.lua
index 34438f3de33b2e573024a158d6fd5bd1b7f8dca6..3a0c65beaa98dfcbdf0a2a902edbe1b83465fb16 100644 (file)
@@ -27,8 +27,10 @@ local sm_streamopened = sessionmanager.streamopened;
 local sm_streamclosed = sessionmanager.streamclosed;
 local st = require "util.stanza";
 
-local stream_callbacks = { stream_tag = "http://etherx.jabber.org/streams\1stream", 
-               default_ns = "jabber:client",
+local config = require "core.configmanager";
+local opt_keepalives = config.get("*", "core", "tcp_keepalives");
+
+local stream_callbacks = { default_ns = "jabber:client",
                streamopened = sm_streamopened, streamclosed = sm_streamclosed, handlestanza = core_process_stanza };
 
 function stream_callbacks.error(session, error, data)
@@ -61,16 +63,15 @@ local function session_reset_stream(session)
                function session.data(conn, data)
                        local ok, err = parser:parse(data);
                        if ok then return; end
-                       log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "));
+                       log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_"));
                        session:close("xml-not-well-formed");
                end
                
                return true;
 end
 
-
 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'};
-local default_stream_attr = { ["xmlns:stream"] = stream_callbacks.stream_tag:match("[^\1]*"), xmlns = stream_callbacks.default_ns, version = "1.0", id = "" };
+local default_stream_attr = { ["xmlns:stream"] = "http://etherx.jabber.org/streams", xmlns = stream_callbacks.default_ns, version = "1.0", id = "" };
 local function session_close(session, reason)
        local log = session.log or log;
        if session.conn then
@@ -101,7 +102,7 @@ local function session_close(session, reason)
                end
                session.send("</stream:stream>");
                session.conn:close();
-               xmppclient.disconnect(session.conn, (reason and (reason.text or reason.condition)) or reason or "session closed");
+               xmppclient.ondisconnect(session.conn, (reason and (reason.text or reason.condition)) or reason or "session closed");
        end
 end
 
@@ -121,6 +122,10 @@ function xmppclient.onincoming(conn, data)
                        session.secure = true;
                end
                
+               if opt_keepalives ~= nil then
+                       conn:setoption("keepalive", opt_keepalives);
+               end
+               
                session.reset_stream = session_reset_stream;
                session.close = session_close;
                
@@ -133,14 +138,13 @@ function xmppclient.onincoming(conn, data)
        end
 end
        
-function xmppclient.disconnect(conn, err)
+function xmppclient.ondisconnect(conn, err)
        local session = sessions[conn];
        if session then
                (session.log or log)("info", "Client disconnected: %s", err);
                sm_destroy_session(session, err);
                sessions[conn]  = nil;
                session = nil;
-               collectgarbage("collect");
        end
 end