Comparison

plugins/mod_s2s/mod_s2s.lua @ 10403:3b82e9df5a7a

mod_s2s: Allow passing bounce reason as an util.error object (see #770) This argument is currently unused in s2smanager.
author Kim Alvefur <zash@zash.se>
date Fri, 08 Nov 2019 23:03:47 +0100
parent 10381:66fa45d24481
child 10421:09b54ad0fdc4
comparison
equal deleted inserted replaced
10402:0971694b30a8 10403:3b82e9df5a7a
27 local uuid_gen = require "util.uuid".generate; 27 local uuid_gen = require "util.uuid".generate;
28 local fire_global_event = prosody.events.fire_event; 28 local fire_global_event = prosody.events.fire_event;
29 local runner = require "util.async".runner; 29 local runner = require "util.async".runner;
30 local connect = require "net.connect".connect; 30 local connect = require "net.connect".connect;
31 local service = require "net.resolvers.service"; 31 local service = require "net.resolvers.service";
32 local errors = require "util.error";
32 33
33 local connect_timeout = module:get_option_number("s2s_timeout", 90); 34 local connect_timeout = module:get_option_number("s2s_timeout", 90);
34 local stream_close_timeout = module:get_option_number("s2s_close_timeout", 5); 35 local stream_close_timeout = module:get_option_number("s2s_close_timeout", 5);
35 local opt_keepalives = module:get_option_boolean("s2s_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true)); 36 local opt_keepalives = module:get_option_boolean("s2s_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true));
36 local secure_auth = module:get_option_boolean("s2s_secure_auth", false); -- One day... 37 local secure_auth = module:get_option_boolean("s2s_secure_auth", false); -- One day...
81 }; 82 };
82 -- FIXME Allow for more specific error conditions 83 -- FIXME Allow for more specific error conditions
83 -- TODO use util.error ? 84 -- TODO use util.error ?
84 local error_type = "cancel"; 85 local error_type = "cancel";
85 local condition = "remote-server-not-found"; 86 local condition = "remote-server-not-found";
87 local reason_text;
86 if session.had_stream then -- set when a stream is opened by the remote 88 if session.had_stream then -- set when a stream is opened by the remote
87 error_type, condition = "wait", "remote-server-timeout"; 89 error_type, condition = "wait", "remote-server-timeout";
90 end
91 if errors.is_err(reason) then
92 error_type, condition, reason_text = reason.type, reason.condition, reason.text;
93 elseif type(reason) == "string" then
94 reason_text = reason;
88 end 95 end
89 for i, data in ipairs(sendq) do 96 for i, data in ipairs(sendq) do
90 local reply = data[2]; 97 local reply = data[2];
91 if reply and not(reply.attr.xmlns) and bouncy_stanzas[reply.name] then 98 if reply and not(reply.attr.xmlns) and bouncy_stanzas[reply.name] then
92 reply.attr.type = "error"; 99 reply.attr.type = "error";
93 reply:tag("error", {type = error_type, by = session.from_host}) 100 reply:tag("error", {type = error_type, by = session.from_host})
94 :tag(condition, {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}):up(); 101 :tag(condition, {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}):up();
95 if reason then 102 if reason_text then
96 reply:tag("text", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}) 103 reply:tag("text", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"})
97 :text("Server-to-server connection failed: "..reason):up(); 104 :text("Server-to-server connection failed: "..reason_text):up();
98 end 105 end
99 core_process_stanza(dummy, reply); 106 core_process_stanza(dummy, reply);
100 end 107 end
101 sendq[i] = nil; 108 sendq[i] = nil;
102 end 109 end