25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01:00

Recognize ws5/wss5 urls in mqtt_bridge

This commit is contained in:
Paweł Chmielowski 2023-01-16 11:01:24 +01:00
parent 83418c3195
commit f2cbe7f3c2
2 changed files with 17 additions and 13 deletions

View File

@ -107,7 +107,7 @@ mod_opt_type(replication_user) ->
econf:jid();
mod_opt_type(servers) ->
econf:and_then(
econf:map(econf:url([mqtt, mqtts, mqtt5, mqtt5s, ws, wss]),
econf:map(econf:url([mqtt, mqtts, mqtt5, mqtt5s, ws, wss, ws5, wss5]),
econf:options(
#{
publish => econf:map(econf:binary(), econf:binary(), [{return, map}]),
@ -130,7 +130,8 @@ mod_opt_type(servers) ->
{ok, Scheme, _UserInfo, Host, Port, Path, _Query} =
misc:uri_parse(Url, [{mqtt, 1883}, {mqtts, 8883},
{mqtt5, 1883}, {mqtt5s, 8883},
{ws, 80}, {wss, 443}]),
{ws, 80}, {wss, 443},
{ws5, 80}, {wss5, 443}]),
Publish = maps:get(publish, Opts, #{}),
Subscribe = maps:get(subscribe, Opts, #{}),
Authentication = maps:get(authentication, Opts, []),

View File

@ -88,14 +88,17 @@ start_link(Proc, Transport, Host, Port, Path, Publish, Subscribe, Authentication
%%% gen_server callbacks
%%%===================================================================
init([_Proc, Proto, Host, Port, Path, Publish, Subscribe, Authentication, ReplicationUser]) ->
{Version, Transport} = case Proto of
mqtt -> {4, gen_tcp};
mqtts -> {4, ssl};
mqtt5 -> {5, gen_tcp};
mqtt5s -> {5, ssl};
ws -> {4, gen_tcp};
wss -> {4, ssl}
end,
{Version, Transport, IsWs} =
case Proto of
mqtt -> {4, gen_tcp, false};
mqtts -> {4, ssl, false};
mqtt5 -> {5, gen_tcp, false};
mqtt5s -> {5, ssl, false};
ws -> {4, gen_tcp, true};
wss -> {4, ssl, true};
ws5 -> {5, gen_tcp, true};
wss5 -> {5, ssl, true}
end,
State = #state{version = Version,
id = p1_rand:uniform(65535),
codec = mqtt_codec:new(4096),
@ -104,15 +107,15 @@ init([_Proc, Proto, Host, Port, Path, Publish, Subscribe, Authentication, Replic
usr = jid:tolower(ReplicationUser),
publish = Publish},
case Authentication of
#{certfile := Cert} when Proto == mqtts; Proto == mqtt5s; Proto == wss ->
#{certfile := Cert} when Transport == ssl ->
Sock = ssl:connect(Host, Port, [binary, {active, true}, {certfile, Cert}]),
if Proto == ws orelse Proto == wss ->
if IsWs ->
connect_ws(Host, Port, Path, Sock, State, ssl, none);
true -> connect(Sock, State, ssl, none)
end;
#{username := User, password := Pass} ->
Sock = Transport:connect(Host, Port, [binary, {active, true}]),
if Proto == ws orelse Proto == wss ->
if IsWs ->
connect_ws(Host, Port, Path, Sock, State, Transport, {User, Pass});
true -> connect(Sock, State, Transport, {User, Pass})
end;