Comparison

plugins/mod_compression.lua @ 2882:4e72048d4a24

mod_compression: Fixed various possible tracebacks in logging.
author Waqas Hussain <waqas20@gmail.com>
date Tue, 09 Mar 2010 17:43:18 +0500
parent 2874:54c8b3952786
child 2883:adbca5af8536
comparison
equal deleted inserted replaced
2877:1edeb8fe7d14 2882:4e72048d4a24
6 -- 6 --
7 7
8 local st = require "util.stanza"; 8 local st = require "util.stanza";
9 local zlib = require "zlib"; 9 local zlib = require "zlib";
10 local pcall = pcall; 10 local pcall = pcall;
11 local tostring = tostring;
11 12
12 local xmlns_compression_feature = "http://jabber.org/features/compress" 13 local xmlns_compression_feature = "http://jabber.org/features/compress"
13 local xmlns_compression_protocol = "http://jabber.org/protocol/compress" 14 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(); 15 local compression_stream_feature = st.stanza("compression", {xmlns=xmlns_compression_feature}):tag("method"):text("zlib"):up();
15 16
55 local status, deflate_stream = pcall(zlib.deflate, compression_level); 56 local status, deflate_stream = pcall(zlib.deflate, compression_level);
56 if status == false then 57 if status == false then
57 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); 58 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed");
58 session.send(error_st); 59 session.send(error_st);
59 session.log("error", "Failed to create zlib.deflate filter."); 60 session.log("error", "Failed to create zlib.deflate filter.");
60 module:log("error", deflate_stream); 61 module:log("error", "%s", tostring(deflate_stream));
61 return 62 return
62 end 63 end
63 64
64 local status, inflate_stream = pcall(zlib.inflate); 65 local status, inflate_stream = pcall(zlib.inflate);
65 if status == false then 66 if status == false then
66 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); 67 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed");
67 session.send(error_st); 68 session.send(error_st);
68 session.log("error", "Failed to create zlib.deflate filter."); 69 session.log("error", "Failed to create zlib.inflate filter.");
69 module:log("error", inflate_stream); 70 module:log("error", "%s", tostring(inflate_stream));
70 return 71 return
71 end 72 end
72 73
73 -- setup compression for session.w 74 -- setup compression for session.w
74 local old_send = session.send; 75 local old_send = session.send;
79 session:close({ 80 session:close({
80 condition = "undefined-condition"; 81 condition = "undefined-condition";
81 text = compressed; 82 text = compressed;
82 extra = st.stanza("failure", {xmlns="http://jabber.org/protocol/compress"}):tag("processing-failed"); 83 extra = st.stanza("failure", {xmlns="http://jabber.org/protocol/compress"}):tag("processing-failed");
83 }); 84 });
84 module:log("warn", compressed); 85 module:log("warn", "%s", tostring(compressed));
85 return; 86 return;
86 end 87 end
87 old_send(compressed); 88 old_send(compressed);
88 end; 89 end;
89 90
96 session:close({ 97 session:close({
97 condition = "undefined-condition"; 98 condition = "undefined-condition";
98 text = decompressed; 99 text = decompressed;
99 extra = st.stanza("failure", {xmlns="http://jabber.org/protocol/compress"}):tag("processing-failed"); 100 extra = st.stanza("failure", {xmlns="http://jabber.org/protocol/compress"}):tag("processing-failed");
100 }); 101 });
101 module:log("warn", decompressed); 102 module:log("warn", "%s", tostring(decompressed));
102 return; 103 return;
103 end 104 end
104 old_data(conn, decompressed); 105 old_data(conn, decompressed);
105 end; 106 end;
106 end 107 end
112 setup_decompression(session); 113 setup_decompression(session);
113 return true; 114 return true;
114 end; 115 end;
115 session.compressed = true; 116 session.compressed = true;
116 else 117 else
117 session.log("info", method.." compression selected. But we don't support it."); 118 session.log("info", "%s compression selected, but we don't support it.", tostring(method));
118 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("unsupported-method"); 119 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("unsupported-method");
119 session.send(error_st); 120 session.send(error_st);
120 end 121 end
121 end 122 end
122 ); 123 );