Comparison

plugins/mod_compression.lua @ 2279:49bc4c7bdef8

Fixing some typos.
author Tobias Markmann <tm@ayena.de>
date Fri, 20 Nov 2009 17:12:12 +0100
parent 1728:cb4c94b47d53
child 2280:0b0fe49e5251
child 2882:4e72048d4a24
comparison
equal deleted inserted replaced
2090:7810648ea26d 2279:49bc4c7bdef8
12 local xmlns_compression_feature = "http://jabber.org/features/compress" 12 local xmlns_compression_feature = "http://jabber.org/features/compress"
13 local xmlns_compression_protocol = "http://jabber.org/protocol/compress" 13 local xmlns_compression_protocol = "http://jabber.org/protocol/compress"
14 local compression_stream_feature = st.stanza("compression", {xmlns=xmlns_compression_feature}):tag("method"):text("zlib"):up(); 14 local compression_stream_feature = st.stanza("compression", {xmlns=xmlns_compression_feature}):tag("method"):text("zlib"):up();
15 15
16 local compression_level = module:get_option("compression_level"); 16 local compression_level = module:get_option("compression_level");
17
18 -- if not defined assume admin wants best compression 17 -- if not defined assume admin wants best compression
19 if compression_level == nil then compression_level = 9 end; 18 if compression_level == nil then compression_level = 9 end;
19
20 20
21 compression_level = tonumber(compression_level); 21 compression_level = tonumber(compression_level);
22 if not compression_level or compression_level < 1 or compression_level > 9 then 22 if not compression_level or compression_level < 1 or compression_level > 9 then
23 module:log("warn", "Invalid compression level in config: %s", tostring(compression_level)); 23 module:log("warn", "Invalid compression level in config: %s", tostring(compression_level));
24 module:log("warn", "Module loading aborted. Compression won't be available."); 24 module:log("warn", "Module loading aborted. Compression won't be available.");
39 function(session, stanza) 39 function(session, stanza)
40 -- fail if we are already compressed 40 -- fail if we are already compressed
41 if session.compressed then 41 if session.compressed then
42 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("unsupported-method"); 42 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("unsupported-method");
43 session.send(error_st); 43 session.send(error_st);
44 session:log("warn", "Tried to establish another compression layer."); 44 session.log("warn", "Tried to establish another compression layer.");
45 end 45 end
46 46
47 -- checking if the compression method is supported 47 -- checking if the compression method is supported
48 local method = stanza:child_with_name("method")[1]; 48 local method = stanza:child_with_name("method")[1];
49 if method == "zlib" then 49 if method == "zlib" then
54 -- create deflate and inflate streams 54 -- create deflate and inflate streams
55 local status, deflate_stream = pcall(zlib.deflate, compression_level); 55 local status, deflate_stream = pcall(zlib.deflate, compression_level);
56 if status == false then 56 if status == false then
57 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); 57 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed");
58 session.send(error_st); 58 session.send(error_st);
59 session:log("error", "Failed to create zlib.deflate filter."); 59 session.log("error", "Failed to create zlib.deflate filter.");
60 module:log("error", deflate_stream); 60 module:log("error", deflate_stream);
61 return 61 return
62 end 62 end
63 63
64 local status, inflate_stream = pcall(zlib.inflate); 64 local status, inflate_stream = pcall(zlib.inflate);
65 if status == false then 65 if status == false then
66 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); 66 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed");
67 session.send(error_st); 67 session.send(error_st);
68 session:log("error", "Failed to create zlib.deflate filter."); 68 session.log("error", "Failed to create zlib.deflate filter.");
69 module:log("error", inflate_stream); 69 module:log("error", inflate_stream);
70 return 70 return
71 end 71 end
72 72
73 -- setup compression for session.w 73 -- setup compression for session.w