Mercurial > prosody-hg
comparison plugins/mod_s2s_bidi.lua @ 11200:bf8f2da84007
Merge 0.11->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 05 Nov 2020 22:31:25 +0100 |
| parents | 602dd1e2f399 |
| children | 38b5b05407be |
comparison
equal
deleted
inserted
replaced
| 11199:6c7c50a4de32 | 11200:bf8f2da84007 |
|---|---|
| 1 -- Prosody IM | |
| 2 -- Copyright (C) 2019 Kim Alvefur | |
| 3 -- | |
| 4 -- This project is MIT/X11 licensed. Please see the | |
| 5 -- COPYING file in the source package for more information. | |
| 6 -- | |
| 7 | |
| 8 local st = require "util.stanza"; | |
| 9 | |
| 10 local xmlns_bidi_feature = "urn:xmpp:features:bidi" | |
| 11 local xmlns_bidi = "urn:xmpp:bidi"; | |
| 12 | |
| 13 local require_encryption = module:get_option_boolean("s2s_require_encryption", false); | |
| 14 | |
| 15 module:hook("s2s-stream-features", function(event) | |
| 16 local origin, features = event.origin, event.features; | |
| 17 if origin.type == "s2sin_unauthed" and (not require_encryption or origin.secure) then | |
| 18 features:tag("bidi", { xmlns = xmlns_bidi_feature }):up(); | |
| 19 end | |
| 20 end); | |
| 21 | |
| 22 module:hook_tag("http://etherx.jabber.org/streams", "features", function (session, stanza) | |
| 23 if session.type == "s2sout_unauthed" and (not require_encryption or session.secure) then | |
| 24 local bidi = stanza:get_child("bidi", xmlns_bidi_feature); | |
| 25 if bidi then | |
| 26 session.incoming = true; | |
| 27 session.log("debug", "Requesting bidirectional stream"); | |
| 28 session.sends2s(st.stanza("bidi", { xmlns = xmlns_bidi })); | |
| 29 end | |
| 30 end | |
| 31 end, 200); | |
| 32 | |
| 33 module:hook_tag("urn:xmpp:bidi", "bidi", function(session) | |
| 34 if session.type == "s2sin_unauthed" and (not require_encryption or session.secure) then | |
| 35 session.log("debug", "Requested bidirectional stream"); | |
| 36 session.outgoing = true; | |
| 37 return true; | |
| 38 end | |
| 39 end); | |
| 40 |
