Comparison

plugins/mod_compression.lua @ 1718:af3d0c329396

Support compression also after SASL.
author Tobias Markmann <tm@ayena.de>
date Tue, 18 Aug 2009 21:46:25 +0200
parent 1716:3f7fd1445d02
child 1719:cf103398e643
comparison
equal deleted inserted replaced
1717:beadd8da061c 1718:af3d0c329396
33 end 33 end
34 end 34 end
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", "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 -- checking if the compression method is supported 40 -- checking if the compression method is supported
41 local method = stanza:child_with_name("method")[1]; 41 local method = stanza:child_with_name("method")[1];
42 if method == "zlib" then 42 if method == "zlib" then
43 session.log("info", method.." compression selected."); 43 session.log("info", method.." compression selected.");
68 68
69 session.send = function(t) 69 session.send = function(t)
70 local status, compressed, eof = pcall(deflate_stream, tostring(t), 'sync'); 70 local status, compressed, eof = pcall(deflate_stream, tostring(t), 'sync');
71 if status == false then 71 if status == false then
72 session:close({ 72 session:close({
73 condition = "undefined-condition"; 73 condition = "undefined-condition";
74 text = compressed; 74 text = compressed;
75 extra = st.stanza("failure", {xmlns="http://jabber.org/protocol/compress"}):tag("processing-failed"); 75 extra = st.stanza("failure", {xmlns="http://jabber.org/protocol/compress"}):tag("processing-failed");
76 }); 76 });
77 module:log("error", compressed); 77 module:log("error", compressed);
78 return; 78 return;
79 end 79 end
80 old_send(compressed); 80 old_send(compressed);
85 local old_data = session.data 85 local old_data = session.data
86 session.data = function(conn, data) 86 session.data = function(conn, data)
87 local status, decompressed, eof = pcall(inflate_stream, data); 87 local status, decompressed, eof = pcall(inflate_stream, data);
88 if status == false then 88 if status == false then
89 session:close({ 89 session:close({
90 condition = "undefined-condition"; 90 condition = "undefined-condition";
91 text = decompressed; 91 text = decompressed;
92 extra = st.stanza("failure", {xmlns="http://jabber.org/protocol/compress"}):tag("processing-failed"); 92 extra = st.stanza("failure", {xmlns="http://jabber.org/protocol/compress"}):tag("processing-failed");
93 }); 93 });
94 module:log("error", decompressed); 94 module:log("error", decompressed);
95 return; 95 return;
96 end 96 end
97 old_data(conn, decompressed); 97 old_data(conn, decompressed);