Mercurial > prosody-hg
comparison plugins/mod_compression.lua @ 6057:a3d7b8f4d9c7
mod_compression: Use get_child() and get_child_text()
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 03 Apr 2014 23:40:20 +0200 |
| parents | 29cbbe882441 |
| children | 1607b03356ed |
comparison
equal
deleted
inserted
replaced
| 6056:29cbbe882441 | 6057:a3d7b8f4d9c7 |
|---|---|
| 43 -- Hook to activate compression if remote server supports it. | 43 -- Hook to activate compression if remote server supports it. |
| 44 module:hook_stanza(xmlns_stream, "features", | 44 module:hook_stanza(xmlns_stream, "features", |
| 45 function (session, stanza) | 45 function (session, stanza) |
| 46 if not session.compressed and session.type == "s2sout" then | 46 if not session.compressed and session.type == "s2sout" then |
| 47 -- does remote server support compression? | 47 -- does remote server support compression? |
| 48 local comp_st = stanza:child_with_name("compression"); | 48 local comp_st = stanza:get_child("compression", xmlns_compression_feature); |
| 49 if comp_st then | 49 if comp_st then |
| 50 -- do we support the mechanism | 50 -- do we support the mechanism |
| 51 for a in comp_st:children() do | 51 for a in comp_st:children() do |
| 52 local algorithm = a[1] | 52 local algorithm = a[1] |
| 53 if algorithm == "zlib" then | 53 if algorithm == "zlib" then |
| 158 session.log("debug", "Client tried to establish another compression layer."); | 158 session.log("debug", "Client tried to establish another compression layer."); |
| 159 return true; | 159 return true; |
| 160 end | 160 end |
| 161 | 161 |
| 162 -- checking if the compression method is supported | 162 -- checking if the compression method is supported |
| 163 local method = stanza:child_with_name("method"); | 163 local method = stanza:get_child_text("method"); |
| 164 method = method and (method[1] or ""); | |
| 165 if method == "zlib" then | 164 if method == "zlib" then |
| 166 session.log("debug", "zlib compression enabled."); | 165 session.log("debug", "zlib compression enabled."); |
| 167 | 166 |
| 168 -- create deflate and inflate streams | 167 -- create deflate and inflate streams |
| 169 local deflate_stream = get_deflate_stream(session); | 168 local deflate_stream = get_deflate_stream(session); |
