mod_c2s: Remove connection object from session object when connection disconnected...
[prosody.git] / plugins / mod_compression.lua
index 67a88eb978ccb7467ec1ae11f17b007ff1f57d66..1ec4c85ad1e5b0dd8860272e59f6761aa4f4242e 100644 (file)
@@ -126,7 +126,7 @@ end
 module:hook("stanza/http://jabber.org/protocol/compress:compressed", function(event)
        local session = event.origin;
        
-       if session.type == "s2sout_unauthed" or session.type == "s2sout" then
+       if session.type == "s2sout" then
                session.log("debug", "Activating compression...")
                -- create deflate and inflate streams
                local deflate_stream = get_deflate_stream(session);
@@ -141,19 +141,22 @@ module:hook("stanza/http://jabber.org/protocol/compress:compressed", function(ev
                -- setup decompression for session.data
                setup_decompression(session, inflate_stream);
                session:reset_stream();
-               local default_stream_attr = {xmlns = "jabber:server", ["xmlns:stream"] = "http://etherx.jabber.org/streams",
-                                                                       ["xmlns:db"] = 'jabber:server:dialback', version = "1.0", to = session.to_host, from = session.from_host};
-               session.sends2s("<?xml version='1.0'?>");
-               session.sends2s(st.stanza("stream:stream", default_stream_attr):top_tag());
+               session:open_stream(session.from_host, session.to_host);
                session.compressed = true;
                return true;
        end
 end);
 
+module:hook("stanza/http://jabber.org/protocol/compress:failure", function(event)
+       local err = event.stanza:get_child();
+       (event.origin.log or module._log)("warn", "Compression setup failed (%s)", err and err.name or "unknown reason");
+       return true;
+end);
+
 module:hook("stanza/http://jabber.org/protocol/compress:compress", function(event)
        local session, stanza = event.origin, event.stanza;
 
-       if session.type == "c2s" or session.type == "s2sin" or session.type == "c2s_unauthed" or session.type == "s2sin_unauthed" then
+       if session.type == "c2s" or session.type == "s2sin" then
                -- fail if we are already compressed
                if session.compressed then
                        local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed");