Comparison

mod_s2sout_override/mod_s2sout_override.lua @ 5634:6fb93b901aa4

Merge upstream
author Trần H. Trung <xmpp:trần.h.trung@trung.fun>
date Sat, 29 Jul 2023 18:11:24 +0700
parent 5632:ae62d92506dc
comparison
equal deleted inserted replaced
5633:758866b43aa4 5634:6fb93b901aa4
4 local basic_resolver = require "net.resolvers.basic"; 4 local basic_resolver = require "net.resolvers.basic";
5 5
6 local override_for = module:get_option(module.name, {}); -- map of host to "tcp://example.com:5269" 6 local override_for = module:get_option(module.name, {}); -- map of host to "tcp://example.com:5269"
7 7
8 module:hook("s2sout-pre-connect", function(event) 8 module:hook("s2sout-pre-connect", function(event)
9 local override = override_for[event.session.to_host]; 9 local override = override_for[event.session.to_host] or override_for[event.session.to_host:gsub("^[^.]+%.", "*.")] or override_for["*"];
10 if type(override) == "string" then 10 if type(override) == "string" then
11 override = url.parse(override); 11 override = url.parse(override);
12 end 12 end
13 if type(override) == "table" and override.scheme == "tcp" and type(override.host) == "string" then 13 if type(override) == "table" and override.scheme == "tcp" and type(override.host) == "string" then
14 event.resolver = basic_resolver.new(override.host, tonumber(override.port) or 5269, override.scheme, {}); 14 event.resolver = basic_resolver.new(override.host, tonumber(override.port) or 5269, override.scheme, {});