Software /
code /
prosody
Comparison
plugins/mod_compression.lua @ 2282:6f54dac3ec2d
mod_compression: Prepare activating of compression on s2s.
author | Tobias Markmann <tm@ayena.de> |
---|---|
date | Sun, 29 Nov 2009 22:02:21 +0100 |
parent | 2280:0b0fe49e5251 |
child | 2283:156bb00ba5c0 |
comparison
equal
deleted
inserted
replaced
2281:27441b099984 | 2282:6f54dac3ec2d |
---|---|
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 | |
12 local xmlns_compression_feature = "http://jabber.org/features/compress" | 11 local xmlns_compression_feature = "http://jabber.org/features/compress" |
13 local xmlns_compression_protocol = "http://jabber.org/protocol/compress" | 12 local xmlns_compression_protocol = "http://jabber.org/protocol/compress" |
14 local xmlns_stream = "http://etherx.jabber.org/streams"; | 13 local xmlns_stream = "http://etherx.jabber.org/streams"; |
15 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(); |
16 | 15 |
53 if comp_st then | 52 if comp_st then |
54 -- do we support the mechanism | 53 -- do we support the mechanism |
55 for a in comp_st:children() do | 54 for a in comp_st:children() do |
56 local algorithm = a[1] | 55 local algorithm = a[1] |
57 if algorithm == "zlib" then | 56 if algorithm == "zlib" then |
58 session.sends2s(st.stanza("compress", {xmlns=xmlns_compression_protocol}):text("zlib")) | 57 session.sends2s(st.stanza("compress", {xmlns=xmlns_compression_protocol}):tag("method"):text("zlib")) |
59 session.log("info", "Enabled compression using zlib.") | 58 session.log("info", "Enabled compression using zlib.") |
60 return true; | 59 return true; |
61 end | 60 end |
62 end | 61 end |
63 session.log("debug", "Remote server supports no compression algorithm we support.") | 62 session.log("debug", "Remote server supports no compression algorithm we support.") |
65 end | 64 end |
66 end | 65 end |
67 , 250); | 66 , 250); |
68 | 67 |
69 -- TODO Support compression on S2S level too. | 68 -- TODO Support compression on S2S level too. |
69 module:add_handler({"s2sout_unauthed", "s2sout"}, "compressed", xmlns_compression_protocol, | |
70 function(session ,stanza) | |
71 session.log("debug", "Activating compression...") | |
72 end | |
73 ); | |
74 | |
70 module:add_handler({"c2s_unauthed", "c2s", "s2sin_unauthed", "s2sin"}, "compress", xmlns_compression_protocol, | 75 module:add_handler({"c2s_unauthed", "c2s", "s2sin_unauthed", "s2sin"}, "compress", xmlns_compression_protocol, |
71 function(session, stanza) | 76 function(session, stanza) |
72 -- fail if we are already compressed | 77 -- fail if we are already compressed |
73 if session.compressed then | 78 if session.compressed then |
74 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("unsupported-method"); | 79 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("unsupported-method"); |