Software / code / prosody
Comparison
plugins/mod_compression.lua @ 2886:3baee526d714
mod_compression: Return <setup-failed/> instead of <unsupported-method/> where applicable.
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Tue, 09 Mar 2010 20:14:47 +0500 |
| parent | 2885:ae72c0dd6f1f |
| child | 2887:765e7070d0a8 |
| child | 2890:6273d4672cb4 |
comparison
equal
deleted
inserted
replaced
| 2885:ae72c0dd6f1f | 2886:3baee526d714 |
|---|---|
| 38 -- TODO Support compression on S2S level too. | 38 -- TODO Support compression on S2S level too. |
| 39 module:add_handler({"c2s_unauthed", "c2s"}, "compress", xmlns_compression_protocol, | 39 module:add_handler({"c2s_unauthed", "c2s"}, "compress", xmlns_compression_protocol, |
| 40 function(session, stanza) | 40 function(session, stanza) |
| 41 -- fail if we are already compressed | 41 -- fail if we are already compressed |
| 42 if session.compressed then | 42 if session.compressed then |
| 43 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("unsupported-method"); | 43 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); |
| 44 session.send(error_st); | 44 session.send(error_st); |
| 45 session.log("warn", "Tried to establish another compression layer."); | 45 session.log("warn", "Tried to establish another compression layer."); |
| 46 return; | 46 return; |
| 47 end | 47 end |
| 48 | 48 |
| 49 -- checking if the compression method is supported | 49 -- checking if the compression method is supported |
| 50 local method = stanza:child_with_name("method"); | 50 local method = stanza:child_with_name("method"); |
| 51 method = method and method[1]; | 51 method = method and (method[1] or ""); |
| 52 if method == "zlib" then | 52 if method == "zlib" then |
| 53 -- create deflate and inflate streams | 53 -- create deflate and inflate streams |
| 54 local status, deflate_stream = pcall(zlib.deflate, compression_level); | 54 local status, deflate_stream = pcall(zlib.deflate, compression_level); |
| 55 if status == false then | 55 if status == false then |
| 56 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); | 56 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); |
| 114 session_reset_stream(session); | 114 session_reset_stream(session); |
| 115 setup_decompression(session); | 115 setup_decompression(session); |
| 116 return true; | 116 return true; |
| 117 end; | 117 end; |
| 118 session.compressed = true; | 118 session.compressed = true; |
| 119 else | 119 elseif method then |
| 120 session.log("info", "%s compression selected, but we don't support it.", tostring(method)); | 120 session.log("info", "%s compression selected, but we don't support it.", tostring(method)); |
| 121 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("unsupported-method"); | 121 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("unsupported-method"); |
| 122 session.send(error_st); | 122 session.send(error_st); |
| 123 else | |
| 124 session.send(st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed")); | |
| 123 end | 125 end |
| 124 end | 126 end |
| 125 ); | 127 ); |