35 ); |
35 ); |
36 |
36 |
37 -- TODO Support compression on S2S level too. |
37 -- TODO Support compression on S2S level too. |
38 module:add_handler({"c2s_unauthed", "c2s_authed"}, "compress", xmlns_compression_protocol, |
38 module:add_handler({"c2s_unauthed", "c2s_authed"}, "compress", xmlns_compression_protocol, |
39 function(session, stanza) |
39 function(session, stanza) |
|
40 -- fail if we are already compressed |
|
41 if session.compressed then |
|
42 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("unsupported-method"); |
|
43 session.send(error_st); |
|
44 session:log("warn", "Tried to establish another compression layer."); |
|
45 end |
|
46 |
40 -- checking if the compression method is supported |
47 -- checking if the compression method is supported |
41 local method = stanza:child_with_name("method")[1]; |
48 local method = stanza:child_with_name("method")[1]; |
42 if method == "zlib" then |
49 if method == "zlib" then |
43 session.log("info", method.." compression selected."); |
50 session.log("info", method.." compression selected."); |
44 session.send(st.stanza("compressed", {xmlns=xmlns_compression_protocol})); |
51 session.send(st.stanza("compressed", {xmlns=xmlns_compression_protocol})); |
89 session:close({ |
96 session:close({ |
90 condition = "undefined-condition"; |
97 condition = "undefined-condition"; |
91 text = decompressed; |
98 text = decompressed; |
92 extra = st.stanza("failure", {xmlns="http://jabber.org/protocol/compress"}):tag("processing-failed"); |
99 extra = st.stanza("failure", {xmlns="http://jabber.org/protocol/compress"}):tag("processing-failed"); |
93 }); |
100 }); |
94 module:log("error", decompressed); |
101 module:log("warn", decompressed); |
95 return; |
102 return; |
96 end |
103 end |
97 old_data(conn, decompressed); |
104 old_data(conn, decompressed); |
98 end; |
105 end; |
99 end |
106 end |