mod_c2s: Remove connection object from session object when connection disconnected...
[prosody.git] / plugins / mod_compression.lua
index 44bc05fe880ea7dad94508bd965577bad031b125..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,16 +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();
-               session:open_stream();
+               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");