mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Recognize ws5/wss5 urls in mqtt_bridge
This commit is contained in:
parent
83418c3195
commit
f2cbe7f3c2
@ -107,7 +107,7 @@ mod_opt_type(replication_user) ->
|
|||||||
econf:jid();
|
econf:jid();
|
||||||
mod_opt_type(servers) ->
|
mod_opt_type(servers) ->
|
||||||
econf:and_then(
|
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(
|
econf:options(
|
||||||
#{
|
#{
|
||||||
publish => econf:map(econf:binary(), econf:binary(), [{return, map}]),
|
publish => econf:map(econf:binary(), econf:binary(), [{return, map}]),
|
||||||
@ -130,7 +130,8 @@ mod_opt_type(servers) ->
|
|||||||
{ok, Scheme, _UserInfo, Host, Port, Path, _Query} =
|
{ok, Scheme, _UserInfo, Host, Port, Path, _Query} =
|
||||||
misc:uri_parse(Url, [{mqtt, 1883}, {mqtts, 8883},
|
misc:uri_parse(Url, [{mqtt, 1883}, {mqtts, 8883},
|
||||||
{mqtt5, 1883}, {mqtt5s, 8883},
|
{mqtt5, 1883}, {mqtt5s, 8883},
|
||||||
{ws, 80}, {wss, 443}]),
|
{ws, 80}, {wss, 443},
|
||||||
|
{ws5, 80}, {wss5, 443}]),
|
||||||
Publish = maps:get(publish, Opts, #{}),
|
Publish = maps:get(publish, Opts, #{}),
|
||||||
Subscribe = maps:get(subscribe, Opts, #{}),
|
Subscribe = maps:get(subscribe, Opts, #{}),
|
||||||
Authentication = maps:get(authentication, Opts, []),
|
Authentication = maps:get(authentication, Opts, []),
|
||||||
|
@ -88,13 +88,16 @@ start_link(Proc, Transport, Host, Port, Path, Publish, Subscribe, Authentication
|
|||||||
%%% gen_server callbacks
|
%%% gen_server callbacks
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
init([_Proc, Proto, Host, Port, Path, Publish, Subscribe, Authentication, ReplicationUser]) ->
|
init([_Proc, Proto, Host, Port, Path, Publish, Subscribe, Authentication, ReplicationUser]) ->
|
||||||
{Version, Transport} = case Proto of
|
{Version, Transport, IsWs} =
|
||||||
mqtt -> {4, gen_tcp};
|
case Proto of
|
||||||
mqtts -> {4, ssl};
|
mqtt -> {4, gen_tcp, false};
|
||||||
mqtt5 -> {5, gen_tcp};
|
mqtts -> {4, ssl, false};
|
||||||
mqtt5s -> {5, ssl};
|
mqtt5 -> {5, gen_tcp, false};
|
||||||
ws -> {4, gen_tcp};
|
mqtt5s -> {5, ssl, false};
|
||||||
wss -> {4, ssl}
|
ws -> {4, gen_tcp, true};
|
||||||
|
wss -> {4, ssl, true};
|
||||||
|
ws5 -> {5, gen_tcp, true};
|
||||||
|
wss5 -> {5, ssl, true}
|
||||||
end,
|
end,
|
||||||
State = #state{version = Version,
|
State = #state{version = Version,
|
||||||
id = p1_rand:uniform(65535),
|
id = p1_rand:uniform(65535),
|
||||||
@ -104,15 +107,15 @@ init([_Proc, Proto, Host, Port, Path, Publish, Subscribe, Authentication, Replic
|
|||||||
usr = jid:tolower(ReplicationUser),
|
usr = jid:tolower(ReplicationUser),
|
||||||
publish = Publish},
|
publish = Publish},
|
||||||
case Authentication of
|
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}]),
|
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);
|
connect_ws(Host, Port, Path, Sock, State, ssl, none);
|
||||||
true -> connect(Sock, State, ssl, none)
|
true -> connect(Sock, State, ssl, none)
|
||||||
end;
|
end;
|
||||||
#{username := User, password := Pass} ->
|
#{username := User, password := Pass} ->
|
||||||
Sock = Transport:connect(Host, Port, [binary, {active, true}]),
|
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});
|
connect_ws(Host, Port, Path, Sock, State, Transport, {User, Pass});
|
||||||
true -> connect(Sock, State, Transport, {User, Pass})
|
true -> connect(Sock, State, Transport, {User, Pass})
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user