Comparison

plugins/mod_compression.lua @ 1719:cf103398e643

Don't allow double compression.
author Tobias Markmann <tm@ayena.de>
date Tue, 18 Aug 2009 22:00:37 +0200
parent 1718:af3d0c329396
child 1728:cb4c94b47d53
comparison
equal deleted inserted replaced
1718:af3d0c329396 1719:cf103398e643
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}));
72 session:close({ 79 session:close({
73 condition = "undefined-condition"; 80 condition = "undefined-condition";
74 text = compressed; 81 text = compressed;
75 extra = st.stanza("failure", {xmlns="http://jabber.org/protocol/compress"}):tag("processing-failed"); 82 extra = st.stanza("failure", {xmlns="http://jabber.org/protocol/compress"}):tag("processing-failed");
76 }); 83 });
77 module:log("error", compressed); 84 module:log("warn", compressed);
78 return; 85 return;
79 end 86 end
80 old_send(compressed); 87 old_send(compressed);
81 end; 88 end;
82 89
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