Software /
code /
prosody-modules
Comparison
mod_bidi/mod_bidi.lua @ 1387:db2ff8f29472
mod_bidi: Add option for selectively not doing bidi with some hosts
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 22 Apr 2014 19:19:58 +0200 |
parent | 1191:1818a7f08580 |
child | 3720:8e7d400d4db3 |
comparison
equal
deleted
inserted
replaced
1386:4557ac5c205d | 1387:db2ff8f29472 |
---|---|
11 local traceback = debug.traceback; | 11 local traceback = debug.traceback; |
12 local hosts = hosts; | 12 local hosts = hosts; |
13 local xmlns_bidi_feature = "urn:xmpp:features:bidi" | 13 local xmlns_bidi_feature = "urn:xmpp:features:bidi" |
14 local xmlns_bidi = "urn:xmpp:bidi"; | 14 local xmlns_bidi = "urn:xmpp:bidi"; |
15 local secure_only = module:get_option_boolean("secure_bidi_only", true); | 15 local secure_only = module:get_option_boolean("secure_bidi_only", true); |
16 local disable_bidi_for = module:get_option_set("no_bidi_with", { }); | |
16 local bidi_sessions = module:shared"sessions-cache"; | 17 local bidi_sessions = module:shared"sessions-cache"; |
17 | 18 |
18 local function handleerr(err) log("error", "Traceback[s2s]: %s: %s", tostring(err), traceback()); end | 19 local function handleerr(err) log("error", "Traceback[s2s]: %s: %s", tostring(err), traceback()); end |
19 local function handlestanza(session, stanza) | 20 local function handlestanza(session, stanza) |
20 if stanza.attr.xmlns == "jabber:client" then --COMPAT: Prosody pre-0.6.2 may send jabber:client | 21 if stanza.attr.xmlns == "jabber:client" then --COMPAT: Prosody pre-0.6.2 may send jabber:client |
67 -- Incoming s2s | 68 -- Incoming s2s |
68 module:hook("s2s-stream-features", function(event) | 69 module:hook("s2s-stream-features", function(event) |
69 local origin, features = event.origin, event.features; | 70 local origin, features = event.origin, event.features; |
70 if not origin.is_bidi and not origin.bidi_session and not origin.do_bidi | 71 if not origin.is_bidi and not origin.bidi_session and not origin.do_bidi |
71 and not hosts[module.host].s2sout[origin.from_host] | 72 and not hosts[module.host].s2sout[origin.from_host] |
73 and not disable_bidi_for:contains(origin.from_host) | |
72 and (not secure_only or (origin.cert_chain_status == "valid" | 74 and (not secure_only or (origin.cert_chain_status == "valid" |
73 and origin.cert_identity_status == "valid")) then | 75 and origin.cert_identity_status == "valid")) then |
74 module:log("debug", "Announcing support for bidirectional streams"); | 76 module:log("debug", "Announcing support for bidirectional streams"); |
75 features:tag("bidi", { xmlns = xmlns_bidi_feature }):up(); | 77 features:tag("bidi", { xmlns = xmlns_bidi_feature }):up(); |
76 end | 78 end |
77 end); | 79 end); |
78 | 80 |
79 module:hook("stanza/urn:xmpp:bidi:bidi", function(event) | 81 module:hook("stanza/urn:xmpp:bidi:bidi", function(event) |
80 local origin = event.session or event.origin; | 82 local origin = event.session or event.origin; |
81 if not origin.is_bidi and not origin.bidi_session | 83 if not origin.is_bidi and not origin.bidi_session |
84 and not disable_bidi_for:contains(origin.from_host) | |
82 and (not secure_only or origin.cert_chain_status == "valid" | 85 and (not secure_only or origin.cert_chain_status == "valid" |
83 and origin.cert_identity_status == "valid") then | 86 and origin.cert_identity_status == "valid") then |
84 module:log("debug", "%s requested bidirectional stream", origin.from_host); | 87 module:log("debug", "%s requested bidirectional stream", origin.from_host); |
85 origin.do_bidi = true; | 88 origin.do_bidi = true; |
86 return true; | 89 return true; |
89 | 92 |
90 -- Outgoing s2s | 93 -- Outgoing s2s |
91 module:hook("stanza/http://etherx.jabber.org/streams:features", function(event) | 94 module:hook("stanza/http://etherx.jabber.org/streams:features", function(event) |
92 local origin = event.session or event.origin; | 95 local origin = event.session or event.origin; |
93 if not ( origin.bidi_session or origin.is_bidi or origin.do_bidi) | 96 if not ( origin.bidi_session or origin.is_bidi or origin.do_bidi) |
97 and not disable_bidi_for:contains(origin.to_host) | |
94 and event.stanza:get_child("bidi", xmlns_bidi_feature) | 98 and event.stanza:get_child("bidi", xmlns_bidi_feature) |
95 and (not secure_only or origin.cert_chain_status == "valid" | 99 and (not secure_only or origin.cert_chain_status == "valid" |
96 and origin.cert_identity_status == "valid") then | 100 and origin.cert_identity_status == "valid") then |
97 module:log("debug", "%s supports bidirectional streams", origin.to_host); | 101 module:log("debug", "%s supports bidirectional streams", origin.to_host); |
98 origin.sends2s(st.stanza("bidi", { xmlns = xmlns_bidi })); | 102 origin.sends2s(st.stanza("bidi", { xmlns = xmlns_bidi })); |