Software /
code /
prosody
Annotate
plugins/mod_compression.lua @ 2283:156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
author | Tobias Markmann <tm@ayena.de> |
---|---|
date | Sun, 29 Nov 2009 22:18:06 +0100 |
parent | 2282:6f54dac3ec2d |
child | 2284:491b89d6816b |
rev | line source |
---|---|
1669
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
1 -- Prosody IM |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
2 -- Copyright (C) 2009 Tobias Markmann |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
3 -- |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
4 -- This project is MIT/X11 licensed. Please see the |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
5 -- COPYING file in the source package for more information. |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
6 -- |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
7 |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
8 local st = require "util.stanza"; |
1671
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
9 local zlib = require "zlib"; |
1678
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
10 local pcall = pcall; |
1669
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
11 local xmlns_compression_feature = "http://jabber.org/features/compress" |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
12 local xmlns_compression_protocol = "http://jabber.org/protocol/compress" |
2280
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
13 local xmlns_stream = "http://etherx.jabber.org/streams"; |
1669
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
14 local compression_stream_feature = st.stanza("compression", {xmlns=xmlns_compression_feature}):tag("method"):text("zlib"):up(); |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
15 |
1676 | 16 local compression_level = module:get_option("compression_level"); |
17 -- if not defined assume admin wants best compression | |
18 if compression_level == nil then compression_level = 9 end; | |
19 | |
2279 | 20 |
1676 | 21 compression_level = tonumber(compression_level); |
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)); | |
24 module:log("warn", "Module loading aborted. Compression won't be available."); | |
25 return; | |
26 end | |
1669
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
27 |
1670 | 28 module:add_event_hook("stream-features", |
1669
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
29 function (session, features) |
1673
5f81cd6d4a92
Remove space at the end of a line.
Tobias Markmann <tm@ayena.de>
parents:
1672
diff
changeset
|
30 if not session.compressed then |
1674
250bddde4162
Add a TODO for s2s compression support.
Tobias Markmann <tm@ayena.de>
parents:
1673
diff
changeset
|
31 -- FIXME only advertise compression support when TLS layer has no compression enabled |
1672
614623f393c6
Add FIXME to remember TLS compression detection.
Tobias Markmann <tm@ayena.de>
parents:
1671
diff
changeset
|
32 features:add_child(compression_stream_feature); |
614623f393c6
Add FIXME to remember TLS compression detection.
Tobias Markmann <tm@ayena.de>
parents:
1671
diff
changeset
|
33 end |
1669
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
34 end |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
35 ); |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
36 |
2280
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
37 module:hook("s2s-stream-features", |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
38 function (data) |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
39 local session, features = data.session, data.features; |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
40 -- FIXME only advertise compression support when TLS layer has no compression enabled |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
41 features:add_child(compression_stream_feature); |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
42 end |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
43 ); |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
44 |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
45 -- S2Sout handling aka the client perspective in the S2S connection |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
46 module:hook_stanza(xmlns_stream, "features", |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
47 function (session, stanza) |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
48 if not session.compressed then |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
49 module:log("debug", "FEATURES: "..stanza:pretty_print()) |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
50 -- does remote server support compression? |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
51 local comp_st = stanza:child_with_name("compression"); |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
52 if comp_st then |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
53 -- do we support the mechanism |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
54 for a in comp_st:children() do |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
55 local algorithm = a[1] |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
56 if algorithm == "zlib" then |
2282
6f54dac3ec2d
mod_compression: Prepare activating of compression on s2s.
Tobias Markmann <tm@ayena.de>
parents:
2280
diff
changeset
|
57 session.sends2s(st.stanza("compress", {xmlns=xmlns_compression_protocol}):tag("method"):text("zlib")) |
2280
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
58 session.log("info", "Enabled compression using zlib.") |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
59 return true; |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
60 end |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
61 end |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
62 session.log("debug", "Remote server supports no compression algorithm we support.") |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
63 end |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
64 end |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
65 end |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
66 , 250); |
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
67 |
1674
250bddde4162
Add a TODO for s2s compression support.
Tobias Markmann <tm@ayena.de>
parents:
1673
diff
changeset
|
68 -- TODO Support compression on S2S level too. |
2282
6f54dac3ec2d
mod_compression: Prepare activating of compression on s2s.
Tobias Markmann <tm@ayena.de>
parents:
2280
diff
changeset
|
69 module:add_handler({"s2sout_unauthed", "s2sout"}, "compressed", xmlns_compression_protocol, |
6f54dac3ec2d
mod_compression: Prepare activating of compression on s2s.
Tobias Markmann <tm@ayena.de>
parents:
2280
diff
changeset
|
70 function(session ,stanza) |
6f54dac3ec2d
mod_compression: Prepare activating of compression on s2s.
Tobias Markmann <tm@ayena.de>
parents:
2280
diff
changeset
|
71 session.log("debug", "Activating compression...") |
6f54dac3ec2d
mod_compression: Prepare activating of compression on s2s.
Tobias Markmann <tm@ayena.de>
parents:
2280
diff
changeset
|
72 end |
6f54dac3ec2d
mod_compression: Prepare activating of compression on s2s.
Tobias Markmann <tm@ayena.de>
parents:
2280
diff
changeset
|
73 ); |
6f54dac3ec2d
mod_compression: Prepare activating of compression on s2s.
Tobias Markmann <tm@ayena.de>
parents:
2280
diff
changeset
|
74 |
2280
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
75 module:add_handler({"c2s_unauthed", "c2s", "s2sin_unauthed", "s2sin"}, "compress", xmlns_compression_protocol, |
1669
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
76 function(session, stanza) |
1719
cf103398e643
Don't allow double compression.
Tobias Markmann <tm@ayena.de>
parents:
1718
diff
changeset
|
77 -- fail if we are already compressed |
cf103398e643
Don't allow double compression.
Tobias Markmann <tm@ayena.de>
parents:
1718
diff
changeset
|
78 if session.compressed then |
cf103398e643
Don't allow double compression.
Tobias Markmann <tm@ayena.de>
parents:
1718
diff
changeset
|
79 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("unsupported-method"); |
cf103398e643
Don't allow double compression.
Tobias Markmann <tm@ayena.de>
parents:
1718
diff
changeset
|
80 session.send(error_st); |
2279 | 81 session.log("warn", "Tried to establish another compression layer."); |
1719
cf103398e643
Don't allow double compression.
Tobias Markmann <tm@ayena.de>
parents:
1718
diff
changeset
|
82 end |
cf103398e643
Don't allow double compression.
Tobias Markmann <tm@ayena.de>
parents:
1718
diff
changeset
|
83 |
1669
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
84 -- checking if the compression method is supported |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
85 local method = stanza:child_with_name("method")[1]; |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
86 if method == "zlib" then |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
87 session.log("info", method.." compression selected."); |
2280
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
88 (session.sends2s or session.send)(st.stanza("compressed", {xmlns=xmlns_compression_protocol})); |
1671
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
89 session:reset_stream(); |
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
90 |
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
91 -- create deflate and inflate streams |
1678
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
92 local status, deflate_stream = pcall(zlib.deflate, compression_level); |
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
93 if status == false then |
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
94 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); |
2280
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
95 (session.sends2s or session.send)(error_st); |
2279 | 96 session.log("error", "Failed to create zlib.deflate filter."); |
1716
3f7fd1445d02
mod_compression: Fixed some undefined global accesses
Waqas Hussain <waqas20@gmail.com>
parents:
1679
diff
changeset
|
97 module:log("error", deflate_stream); |
1678
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
98 return |
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
99 end |
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
100 |
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
101 local status, inflate_stream = pcall(zlib.inflate); |
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
102 if status == false then |
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
103 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); |
2280
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
104 (session.sends2s or session.send)(error_st); |
2279 | 105 session.log("error", "Failed to create zlib.deflate filter."); |
1678
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
106 module:log("error", inflate_stream); |
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
107 return |
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
108 end |
1671
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
109 |
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
110 -- setup compression for session.w |
2283
156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
Tobias Markmann <tm@ayena.de>
parents:
2282
diff
changeset
|
111 local function setup_compression(session) |
156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
Tobias Markmann <tm@ayena.de>
parents:
2282
diff
changeset
|
112 local old_send = session.send; |
1671
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
113 |
2283
156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
Tobias Markmann <tm@ayena.de>
parents:
2282
diff
changeset
|
114 session.send = function(t) |
156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
Tobias Markmann <tm@ayena.de>
parents:
2282
diff
changeset
|
115 local status, compressed, eof = pcall(deflate_stream, tostring(t), 'sync'); |
156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
Tobias Markmann <tm@ayena.de>
parents:
2282
diff
changeset
|
116 if status == false then |
156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
Tobias Markmann <tm@ayena.de>
parents:
2282
diff
changeset
|
117 session:close({ |
156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
Tobias Markmann <tm@ayena.de>
parents:
2282
diff
changeset
|
118 condition = "undefined-condition"; |
156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
Tobias Markmann <tm@ayena.de>
parents:
2282
diff
changeset
|
119 text = compressed; |
156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
Tobias Markmann <tm@ayena.de>
parents:
2282
diff
changeset
|
120 extra = st.stanza("failure", {xmlns="http://jabber.org/protocol/compress"}):tag("processing-failed"); |
156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
Tobias Markmann <tm@ayena.de>
parents:
2282
diff
changeset
|
121 }); |
156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
Tobias Markmann <tm@ayena.de>
parents:
2282
diff
changeset
|
122 module:log("warn", compressed); |
156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
Tobias Markmann <tm@ayena.de>
parents:
2282
diff
changeset
|
123 return; |
156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
Tobias Markmann <tm@ayena.de>
parents:
2282
diff
changeset
|
124 end |
156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
Tobias Markmann <tm@ayena.de>
parents:
2282
diff
changeset
|
125 old_send(compressed); |
156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
Tobias Markmann <tm@ayena.de>
parents:
2282
diff
changeset
|
126 end; |
156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
Tobias Markmann <tm@ayena.de>
parents:
2282
diff
changeset
|
127 end |
156bb00ba5c0
mod_compression: Moving compression setup in a dedicated function.
Tobias Markmann <tm@ayena.de>
parents:
2282
diff
changeset
|
128 setup_compression(session); |
1671
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
129 |
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
130 -- setup decompression for session.data |
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
131 local function setup_decompression(session) |
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
132 local old_data = session.data |
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
133 session.data = function(conn, data) |
1678
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
134 local status, decompressed, eof = pcall(inflate_stream, data); |
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
135 if status == false then |
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
136 session:close({ |
1718
af3d0c329396
Support compression also after SASL.
Tobias Markmann <tm@ayena.de>
parents:
1716
diff
changeset
|
137 condition = "undefined-condition"; |
af3d0c329396
Support compression also after SASL.
Tobias Markmann <tm@ayena.de>
parents:
1716
diff
changeset
|
138 text = decompressed; |
af3d0c329396
Support compression also after SASL.
Tobias Markmann <tm@ayena.de>
parents:
1716
diff
changeset
|
139 extra = st.stanza("failure", {xmlns="http://jabber.org/protocol/compress"}):tag("processing-failed"); |
1678
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
140 }); |
1719
cf103398e643
Don't allow double compression.
Tobias Markmann <tm@ayena.de>
parents:
1718
diff
changeset
|
141 module:log("warn", decompressed); |
1678
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
142 return; |
79eb903d0e67
Using pcall to make save the rest from zlib fails. Emit errors on those fails.
Tobias Markmann <tm@ayena.de>
parents:
1677
diff
changeset
|
143 end |
1671
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
144 old_data(conn, decompressed); |
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
145 end; |
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
146 end |
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
147 setup_decompression(session); |
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
148 |
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
149 local session_reset_stream = session.reset_stream; |
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
150 session.reset_stream = function(session) |
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
151 session_reset_stream(session); |
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
152 setup_decompression(session); |
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
153 return true; |
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
154 end; |
d196ac213104
Actually inject de- and compression into the reading/writing functions.
Tobias Markmann <tm@ayena.de>
parents:
1670
diff
changeset
|
155 session.compressed = true; |
1669
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
156 else |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
157 session.log("info", method.." compression selected. But we don't support it."); |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
158 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("unsupported-method"); |
2280
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
159 (session.sends2s or session.send)(error_st); |
1669
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
160 end |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
161 end |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
162 ); |
2280
0b0fe49e5251
Enable one way stream compression on s2s links.
Tobias Markmann <tm@ayena.de>
parents:
2279
diff
changeset
|
163 |