Annotate

plugins/mod_s2s_bidi.lua @ 10261:010c67532ed0

util.encodings: Switch ICU binding to IDNA2008 (fixes #533, #1301)
author Kim Alvefur <zash@zash.se>
date Wed, 11 Sep 2019 00:14:59 +0200
parent 10250:1006739de449
child 10458:602dd1e2f399
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10250
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 -- Prosody IM
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 -- Copyright (C) 2019 Kim Alvefur
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 --
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 -- This project is MIT/X11 licensed. Please see the
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 -- COPYING file in the source package for more information.
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 --
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local st = require "util.stanza";
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 local xmlns_bidi_feature = "urn:xmpp:features:bidi"
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 local xmlns_bidi = "urn:xmpp:bidi";
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 module:hook("s2s-stream-features", function(event)
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 local origin, features = event.origin, event.features;
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 if origin.type == "s2sin_unauthed" then
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 features:tag("bidi", { xmlns = xmlns_bidi_feature }):up();
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 end
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 end);
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 module:hook_tag("http://etherx.jabber.org/streams", "features", function (session, stanza)
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 if session.type == "s2sout_unauthed" then
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 local bidi = stanza:get_child("bidi", xmlns_bidi_feature);
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 if bidi then
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 session.incoming = true;
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 session.log("debug", "Requesting bidirectional stream");
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 session.sends2s(st.stanza("bidi", { xmlns = xmlns_bidi }));
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 end
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 end
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 end, 200);
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 module:hook_tag("urn:xmpp:bidi", "bidi", function(session)
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 if session.type == "s2sin_unauthed" then
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 session.log("debug", "Requested bidirectional stream");
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 session.outgoing = true;
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 return true;
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 end
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 end);
1006739de449 mod_s2s_bidi: Enables bi-directional streams via XEP-0288
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38