Mercurial > prosody-hg
comparison plugins/mod_compression.lua @ 6040:b3b1c9da38fb
mod_compression: Only allow compression on authenticated streams
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 18 Feb 2014 20:03:12 +0100 |
| parents | 0df0afc041d7 |
| children | 7a5ddbaf758d 55fda5deb5d5 |
comparison
equal
deleted
inserted
replaced
| 6035:1b5ca55bf895 | 6040:b3b1c9da38fb |
|---|---|
| 124 end | 124 end |
| 125 | 125 |
| 126 module:hook("stanza/http://jabber.org/protocol/compress:compressed", function(event) | 126 module:hook("stanza/http://jabber.org/protocol/compress:compressed", function(event) |
| 127 local session = event.origin; | 127 local session = event.origin; |
| 128 | 128 |
| 129 if session.type == "s2sout_unauthed" or session.type == "s2sout" then | 129 if session.type == "s2sout" then |
| 130 session.log("debug", "Activating compression...") | 130 session.log("debug", "Activating compression...") |
| 131 -- create deflate and inflate streams | 131 -- create deflate and inflate streams |
| 132 local deflate_stream = get_deflate_stream(session); | 132 local deflate_stream = get_deflate_stream(session); |
| 133 if not deflate_stream then return true; end | 133 if not deflate_stream then return true; end |
| 134 | 134 |
| 148 end); | 148 end); |
| 149 | 149 |
| 150 module:hook("stanza/http://jabber.org/protocol/compress:compress", function(event) | 150 module:hook("stanza/http://jabber.org/protocol/compress:compress", function(event) |
| 151 local session, stanza = event.origin, event.stanza; | 151 local session, stanza = event.origin, event.stanza; |
| 152 | 152 |
| 153 if session.type == "c2s" or session.type == "s2sin" or session.type == "c2s_unauthed" or session.type == "s2sin_unauthed" then | 153 if session.type == "c2s" or session.type == "s2sin" then |
| 154 -- fail if we are already compressed | 154 -- fail if we are already compressed |
| 155 if session.compressed then | 155 if session.compressed then |
| 156 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); | 156 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); |
| 157 (session.sends2s or session.send)(error_st); | 157 (session.sends2s or session.send)(error_st); |
| 158 session.log("debug", "Client tried to establish another compression layer."); | 158 session.log("debug", "Client tried to establish another compression layer."); |
