mod_dialback, mod_saslauth: Remove broken fallback to dialback on SASL EXTERNAL failure
[prosody.git] / plugins / mod_c2s.lua
index 1fb8dcf571f8b072fb26dec9a0a632fcc822040a..4238b2e7e1f3b729450dcccd845477f9065ff62e 100644 (file)
@@ -38,7 +38,6 @@ local runner_callbacks = {};
 
 --- Stream events handlers
 local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'};
-local default_stream_attr = { ["xmlns:stream"] = "http://etherx.jabber.org/streams", xmlns = stream_callbacks.default_ns, version = "1.0", id = "" };
 
 function stream_callbacks.streamopened(session, attr)
        local send = session.send;
@@ -58,9 +57,7 @@ function stream_callbacks.streamopened(session, attr)
                return;
        end
 
-       send("<?xml version='1.0'?>"..st.stanza("stream:stream", {
-               xmlns = 'jabber:client', ["xmlns:stream"] = 'http://etherx.jabber.org/streams';
-               id = session.streamid, from = session.host, version = '1.0', ["xml:lang"] = 'en' }):top_tag());
+       session:open_stream();
 
        (session.log or log)("debug", "Sent reply <stream:stream> to client");
        session.notopen = nil;
@@ -69,6 +66,7 @@ function stream_callbacks.streamopened(session, attr)
        -- since we now have a new stream header, session is secured
        if session.secure == false then
                session.secure = true;
+               session.encrypted = true;
 
                local sock = session.conn:socket();
                if sock.info then
@@ -93,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));
@@ -128,8 +126,7 @@ local function session_close(session, reason)
        local log = session.log or log;
        if session.conn then
                if session.notopen then
-                       session.send("<?xml version='1.0'?>");
-                       session.send(st.stanza("stream:stream", default_stream_attr):top_tag());
+                       session:open_stream();
                end
                if reason then -- nil == no err, initiated by us, false == initiated by client
                        local stream_error = st.stanza("stream:error");
@@ -209,6 +206,7 @@ function listener.onconnect(conn)
        -- Client is using legacy SSL (otherwise mod_tls sets this flag)
        if conn:ssl() then
                session.secure = true;
+               session.encrypted = true;
 
                -- Check if TLS compression is used
                local sock = conn:socket();
@@ -242,9 +240,9 @@ function listener.onconnect(conn)
        function session.data(data)
                -- Parse the data, which will store stanzas in session.pending_stanzas
                if data then
-                       data = filter("bytes/in", data);
-                       if data then
-                               local ok, err = stream:feed(data);
+               data = filter("bytes/in", data);
+               if data then
+                       local ok, err = stream:feed(data);
                                if not ok then
                                        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("not-well-formed");