Software /
code /
prosody
Annotate
plugins/mod_compression.lua @ 1670:23bb280c5eac
Remove unwanted spaces.
author | Tobias Markmann <tm@ayena.de> |
---|---|
date | Wed, 12 Aug 2009 20:09:07 +0200 |
parent | 1669:b8eec163a823 |
child | 1671:d196ac213104 |
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"; |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
9 local print = print |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
10 |
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" |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
13 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
|
14 |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
15 |
1670 | 16 module:add_event_hook("stream-features", |
1669
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
17 function (session, features) |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
18 features:add_child(compression_stream_feature); |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
19 end |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
20 ); |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
21 |
1670 | 22 module:add_handler("c2s_unauthed", "compress", xmlns_compression_protocol, |
1669
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
23 function(session, stanza) |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
24 -- checking if the compression method is supported |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
25 local method = stanza:child_with_name("method")[1]; |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
26 if method == "zlib" then |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
27 session.log("info", method.." compression selected."); |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
28 session.send(st.stanza("compressed", {xmlns=xmlns_compression_protocol})); |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
29 else |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
30 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
|
31 local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("unsupported-method"); |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
32 session.send(error_st); |
b8eec163a823
Commit initial version of mod_compression.
Tobias Markmann <tm@ayena.de>
parents:
diff
changeset
|
33 end |
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 ); |