Software /
code /
prosody
Changeset
10250:1006739de449
mod_s2s_bidi: Enables bi-directional streams via XEP-0288
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 08 Sep 2019 19:45:39 +0200 |
parents | 10249:790c6ae54dd6 |
children | 10251:022d42e122d4 |
files | core/modulemanager.lua plugins/mod_s2s_bidi.lua |
diffstat | 2 files changed, 39 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/core/modulemanager.lua Sat Sep 07 18:54:59 2019 +0200 +++ b/core/modulemanager.lua Sun Sep 08 19:45:39 2019 +0200 @@ -24,7 +24,7 @@ local ipairs, pairs, type, t_insert = ipairs, pairs, type, table.insert; local autoload_modules = {prosody.platform, "presence", "message", "iq", "offline", "c2s", "s2s", "s2s_auth_certs"}; -local component_inheritable_modules = {"tls", "saslauth", "dialback", "iq", "s2s"}; +local component_inheritable_modules = {"tls", "saslauth", "dialback", "iq", "s2s", "s2s_bidi"}; -- We need this to let modules access the real global namespace local _G = _G;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/mod_s2s_bidi.lua Sun Sep 08 19:45:39 2019 +0200 @@ -0,0 +1,38 @@ +-- Prosody IM +-- Copyright (C) 2019 Kim Alvefur +-- +-- This project is MIT/X11 licensed. Please see the +-- COPYING file in the source package for more information. +-- + +local st = require "util.stanza"; + +local xmlns_bidi_feature = "urn:xmpp:features:bidi" +local xmlns_bidi = "urn:xmpp:bidi"; + +module:hook("s2s-stream-features", function(event) + local origin, features = event.origin, event.features; + if origin.type == "s2sin_unauthed" then + features:tag("bidi", { xmlns = xmlns_bidi_feature }):up(); + end +end); + +module:hook_tag("http://etherx.jabber.org/streams", "features", function (session, stanza) + if session.type == "s2sout_unauthed" then + local bidi = stanza:get_child("bidi", xmlns_bidi_feature); + if bidi then + session.incoming = true; + session.log("debug", "Requesting bidirectional stream"); + session.sends2s(st.stanza("bidi", { xmlns = xmlns_bidi })); + end + end +end, 200); + +module:hook_tag("urn:xmpp:bidi", "bidi", function(session) + if session.type == "s2sin_unauthed" then + session.log("debug", "Requested bidirectional stream"); + session.outgoing = true; + return true; + end +end); +