25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-28 16:34:13 +01:00

Use correct virtual host for s2s options

This commit is contained in:
Evgeny Khramtsov 2019-06-23 19:37:54 +03:00
parent 4b65fcab62
commit c2cbb4d879
2 changed files with 49 additions and 49 deletions

View File

@ -137,17 +137,17 @@ process_closed(#{server := LServer} = State, Reason) ->
%%%=================================================================== %%%===================================================================
%%% xmpp_stream_in callbacks %%% xmpp_stream_in callbacks
%%%=================================================================== %%%===================================================================
tls_options(#{tls_options := TLSOpts, lserver := LServer}) -> tls_options(#{tls_options := TLSOpts, server_host := ServerHost}) ->
ejabberd_s2s:tls_options(LServer, TLSOpts). ejabberd_s2s:tls_options(ServerHost, TLSOpts).
tls_required(#{lserver := LServer}) -> tls_required(#{server_host := ServerHost}) ->
ejabberd_s2s:tls_required(LServer). ejabberd_s2s:tls_required(ServerHost).
tls_enabled(#{lserver := LServer}) -> tls_enabled(#{server_host := ServerHost}) ->
ejabberd_s2s:tls_enabled(LServer). ejabberd_s2s:tls_enabled(ServerHost).
compress_methods(#{lserver := LServer}) -> compress_methods(#{server_host := ServerHost}) ->
case ejabberd_s2s:zlib_enabled(LServer) of case ejabberd_s2s:zlib_enabled(ServerHost) of
true -> [<<"zlib">>]; true -> [<<"zlib">>];
false -> [] false -> []
end. end.
@ -168,9 +168,9 @@ handle_stream_start(_StreamStart, #{lserver := LServer} = State) ->
State#{server_host => ServerHost, codec_options => Opts} State#{server_host => ServerHost, codec_options => Opts}
end. end.
handle_stream_end(Reason, #{server_host := LServer} = State) -> handle_stream_end(Reason, #{server_host := ServerHost} = State) ->
State1 = State#{stop_reason => Reason}, State1 = State#{stop_reason => Reason},
ejabberd_hooks:run_fold(s2s_in_closed, LServer, State1, [Reason]). ejabberd_hooks:run_fold(s2s_in_closed, ServerHost, State1, [Reason]).
handle_stream_established(State) -> handle_stream_established(State) ->
set_idle_timeout(State#{established => true}). set_idle_timeout(State#{established => true}).
@ -203,12 +203,12 @@ handle_auth_failure(RServer, Mech, Reason,
ejabberd_hooks:run_fold(s2s_in_auth_result, ejabberd_hooks:run_fold(s2s_in_auth_result,
ServerHost, State, [false, RServer]). ServerHost, State, [false, RServer]).
handle_unauthenticated_packet(Pkt, #{server_host := LServer} = State) -> handle_unauthenticated_packet(Pkt, #{server_host := ServerHost} = State) ->
ejabberd_hooks:run_fold(s2s_in_unauthenticated_packet, ejabberd_hooks:run_fold(s2s_in_unauthenticated_packet,
LServer, State, [Pkt]). ServerHost, State, [Pkt]).
handle_authenticated_packet(Pkt, #{server_host := LServer} = State) when not ?is_stanza(Pkt) -> handle_authenticated_packet(Pkt, #{server_host := ServerHost} = State) when not ?is_stanza(Pkt) ->
ejabberd_hooks:run_fold(s2s_in_authenticated_packet, LServer, State, [Pkt]); ejabberd_hooks:run_fold(s2s_in_authenticated_packet, ServerHost, State, [Pkt]);
handle_authenticated_packet(Pkt0, #{ip := {IP, _}} = State) -> handle_authenticated_packet(Pkt0, #{ip := {IP, _}} = State) ->
Pkt = xmpp:put_meta(Pkt0, ip, IP), Pkt = xmpp:put_meta(Pkt0, ip, IP),
From = xmpp:get_from(Pkt), From = xmpp:get_from(Pkt),
@ -229,15 +229,15 @@ handle_authenticated_packet(Pkt0, #{ip := {IP, _}} = State) ->
send(State, Err) send(State, Err)
end. end.
handle_cdata(Data, #{server_host := LServer} = State) -> handle_cdata(Data, #{server_host := ServerHost} = State) ->
ejabberd_hooks:run_fold(s2s_in_handle_cdata, LServer, State, [Data]). ejabberd_hooks:run_fold(s2s_in_handle_cdata, ServerHost, State, [Data]).
handle_recv(El, Pkt, #{server_host := LServer} = State) -> handle_recv(El, Pkt, #{server_host := ServerHost} = State) ->
State1 = set_idle_timeout(State), State1 = set_idle_timeout(State),
ejabberd_hooks:run_fold(s2s_in_handle_recv, LServer, State1, [El, Pkt]). ejabberd_hooks:run_fold(s2s_in_handle_recv, ServerHost, State1, [El, Pkt]).
handle_send(Pkt, Result, #{server_host := LServer} = State) -> handle_send(Pkt, Result, #{server_host := ServerHost} = State) ->
ejabberd_hooks:run_fold(s2s_in_handle_send, LServer, ejabberd_hooks:run_fold(s2s_in_handle_send, ServerHost,
State, [Pkt, Result]). State, [Pkt, Result]).
init([State, Opts]) -> init([State, Opts]) ->
@ -267,19 +267,19 @@ init([State, Opts]) ->
State2 = xmpp_stream_in:set_timeout(State1, Timeout), State2 = xmpp_stream_in:set_timeout(State1, Timeout),
ejabberd_hooks:run_fold(s2s_in_init, {ok, State2}, [Opts]). ejabberd_hooks:run_fold(s2s_in_init, {ok, State2}, [Opts]).
handle_call(Request, From, #{server_host := LServer} = State) -> handle_call(Request, From, #{server_host := ServerHost} = State) ->
ejabberd_hooks:run_fold(s2s_in_handle_call, LServer, State, [Request, From]). ejabberd_hooks:run_fold(s2s_in_handle_call, ServerHost, State, [Request, From]).
handle_cast({update_state, Fun}, State) -> handle_cast({update_state, Fun}, State) ->
case Fun of case Fun of
{M, F, A} -> erlang:apply(M, F, [State|A]); {M, F, A} -> erlang:apply(M, F, [State|A]);
_ when is_function(Fun) -> Fun(State) _ when is_function(Fun) -> Fun(State)
end; end;
handle_cast(Msg, #{server_host := LServer} = State) -> handle_cast(Msg, #{server_host := ServerHost} = State) ->
ejabberd_hooks:run_fold(s2s_in_handle_cast, LServer, State, [Msg]). ejabberd_hooks:run_fold(s2s_in_handle_cast, ServerHost, State, [Msg]).
handle_info(Info, #{server_host := LServer} = State) -> handle_info(Info, #{server_host := ServerHost} = State) ->
ejabberd_hooks:run_fold(s2s_in_handle_info, LServer, State, [Info]). ejabberd_hooks:run_fold(s2s_in_handle_info, ServerHost, State, [Info]).
terminate(Reason, #{auth_domains := AuthDomains, terminate(Reason, #{auth_domains := AuthDomains,
socket := Socket} = State) -> socket := Socket} = State) ->
@ -329,9 +329,9 @@ check_to(#jid{lserver = LServer}, _State) ->
ejabberd_router:is_my_route(LServer). ejabberd_router:is_my_route(LServer).
-spec set_idle_timeout(state()) -> state(). -spec set_idle_timeout(state()) -> state().
set_idle_timeout(#{lserver := LServer, set_idle_timeout(#{server_host := ServerHost,
established := true} = State) -> established := true} = State) ->
Timeout = ejabberd_s2s:get_idle_timeout(LServer), Timeout = ejabberd_s2s:get_idle_timeout(ServerHost),
xmpp_stream_in:set_timeout(State, Timeout); xmpp_stream_in:set_timeout(State, Timeout);
set_idle_timeout(State) -> set_idle_timeout(State) ->
State. State.

View File

@ -177,32 +177,32 @@ process_downgraded(State, _StreamStart) ->
%%%=================================================================== %%%===================================================================
%%% xmpp_stream_out callbacks %%% xmpp_stream_out callbacks
%%%=================================================================== %%%===================================================================
tls_options(#{server := LServer}) -> tls_options(#{server_host := ServerHost}) ->
ejabberd_s2s:tls_options(LServer, []). ejabberd_s2s:tls_options(ServerHost, []).
tls_required(#{server := LServer}) -> tls_required(#{server_host := ServerHost}) ->
ejabberd_s2s:tls_required(LServer). ejabberd_s2s:tls_required(ServerHost).
tls_verify(#{server := LServer} = State) -> tls_verify(#{server_host := ServerHost} = State) ->
ejabberd_hooks:run_fold(s2s_out_tls_verify, LServer, true, [State]). ejabberd_hooks:run_fold(s2s_out_tls_verify, ServerHost, true, [State]).
tls_enabled(#{server := LServer}) -> tls_enabled(#{server_host := ServerHost}) ->
ejabberd_s2s:tls_enabled(LServer). ejabberd_s2s:tls_enabled(ServerHost).
connect_timeout(#{server := LServer}) -> connect_timeout(#{server_host := ServerHost}) ->
ejabberd_option:outgoing_s2s_timeout(LServer). ejabberd_option:outgoing_s2s_timeout(ServerHost).
default_port(#{server := LServer}) -> default_port(#{server_host := ServerHost}) ->
ejabberd_option:outgoing_s2s_port(LServer). ejabberd_option:outgoing_s2s_port(ServerHost).
address_families(#{server := LServer}) -> address_families(#{server_host := ServerHost}) ->
ejabberd_option:outgoing_s2s_families(LServer). ejabberd_option:outgoing_s2s_families(ServerHost).
dns_retries(#{server := LServer}) -> dns_retries(#{server_host := ServerHost}) ->
ejabberd_option:s2s_dns_retries(LServer). ejabberd_option:s2s_dns_retries(ServerHost).
dns_timeout(#{server := LServer}) -> dns_timeout(#{server_host := ServerHost}) ->
ejabberd_option:s2s_dns_timeout(LServer). ejabberd_option:s2s_dns_timeout(ServerHost).
handle_auth_success(Mech, #{socket := Socket, ip := IP, handle_auth_success(Mech, #{socket := Socket, ip := IP,
remote_server := RServer, remote_server := RServer,
@ -258,7 +258,7 @@ handle_timeout(#{on_route := Action, lang := Lang} = State) ->
init([#{server := LServer, remote_server := RServer} = State, Opts]) -> init([#{server := LServer, remote_server := RServer} = State, Opts]) ->
ServerHost = ejabberd_router:host_of_route(LServer), ServerHost = ejabberd_router:host_of_route(LServer),
QueueType = ejabberd_s2s:queue_type(LServer), QueueType = ejabberd_s2s:queue_type(ServerHost),
QueueLimit = case lists:keyfind( QueueLimit = case lists:keyfind(
max_queue, 1, ejabberd_config:fsm_limit_opts([])) of max_queue, 1, ejabberd_config:fsm_limit_opts([])) of
{_, N} -> N; {_, N} -> N;
@ -373,8 +373,8 @@ get_delay() ->
p1_rand:uniform(MaxDelay). p1_rand:uniform(MaxDelay).
-spec set_idle_timeout(state()) -> state(). -spec set_idle_timeout(state()) -> state().
set_idle_timeout(#{on_route := send, server := LServer} = State) -> set_idle_timeout(#{on_route := send, server_host := ServerHost} = State) ->
Timeout = ejabberd_s2s:get_idle_timeout(LServer), Timeout = ejabberd_s2s:get_idle_timeout(ServerHost),
xmpp_stream_out:set_timeout(State, Timeout); xmpp_stream_out:set_timeout(State, Timeout);
set_idle_timeout(State) -> set_idle_timeout(State) ->
State. State.