diff options
Diffstat (limited to 'src/ejabberd_service.erl')
-rw-r--r-- | src/ejabberd_service.erl | 90 |
1 files changed, 41 insertions, 49 deletions
diff --git a/src/ejabberd_service.erl b/src/ejabberd_service.erl index c39a023ab..0f40822b7 100644 --- a/src/ejabberd_service.erl +++ b/src/ejabberd_service.erl @@ -21,20 +21,19 @@ %%%------------------------------------------------------------------- -module(ejabberd_service). -behaviour(xmpp_stream_in). --behaviour(xmpp_socket). +-behaviour(ejabberd_listener). -protocol({xep, 114, '1.6'}). -%% xmpp_socket callbacks --export([start/2, start_link/2, socket_type/0, close/1, close/2]). %% ejabberd_listener callbacks --export([listen_opt_type/1, transform_listen_option/2]). +-export([start/2, start_link/2, accept/1]). +-export([listen_opt_type/1, listen_options/0, transform_listen_option/2]). %% xmpp_stream_in callbacks -export([init/1, handle_info/2, terminate/2, code_change/3]). -export([handle_stream_start/2, handle_auth_success/4, handle_auth_failure/4, handle_authenticated_packet/2, get_password_fun/1, tls_options/1]). %% API --export([send/2]). +-export([send/2, close/1, close/2]). -include("xmpp.hrl"). -include("logger.hrl"). @@ -53,8 +52,8 @@ start_link(SockData, Opts) -> xmpp_stream_in:start_link(?MODULE, [SockData, Opts], ejabberd_config:fsm_limit_opts(Opts)). -socket_type() -> - xml_stream. +accept(Ref) -> + xmpp_stream_in:accept(Ref). -spec send(pid(), xmpp_element()) -> ok; (state(), xmpp_element()) -> state(). @@ -79,7 +78,8 @@ tls_options(#{tls_options := TLSOptions}) -> init([State, Opts]) -> Access = proplists:get_value(access, Opts, all), - Shaper = proplists:get_value(shaper_rule, Opts, none), + Shaper = proplists:get_value(shaper, Opts, + proplists:get_value(shaper_rule, Opts, none)), GlobalPassword = proplists:get_value(password, Opts, random_password()), HostOpts = proplists:get_value(hosts, Opts, [{global, GlobalPassword}]), HostOpts1 = lists:map( @@ -146,10 +146,10 @@ get_password_fun(#{remote_server := RemoteServer, {ok, Password} -> {Password, undefined}; error -> - ?INFO_MSG("(~s) Domain ~s is unconfigured for " - "external component from ~s", - [xmpp_socket:pp(Socket), RemoteServer, - ejabberd_config:may_hide_data(misc:ip_to_list(IP))]), + ?WARNING_MSG("(~s) Domain ~s is unconfigured for " + "external component from ~s", + [xmpp_socket:pp(Socket), RemoteServer, + ejabberd_config:may_hide_data(misc:ip_to_list(IP))]), {false, undefined} end end. @@ -177,11 +177,11 @@ handle_auth_success(_, Mech, _, handle_auth_failure(_, Mech, Reason, #{remote_server := RemoteServer, socket := Socket, ip := IP} = State) -> - ?INFO_MSG("(~s) Failed external component ~s authentication " - "for ~s from ~s: ~s", - [xmpp_socket:pp(Socket), Mech, RemoteServer, - ejabberd_config:may_hide_data(misc:ip_to_list(IP)), - Reason]), + ?WARNING_MSG("(~s) Failed external component ~s authentication " + "for ~s from ~s: ~s", + [xmpp_socket:pp(Socket), Mech, RemoteServer, + ejabberd_config:may_hide_data(misc:ip_to_list(IP)), + Reason]), State. handle_authenticated_packet(Pkt0, #{ip := {IP, _}, lang := Lang} = State) @@ -281,21 +281,12 @@ transform_listen_option({host, Host, Os}, Opts) -> transform_listen_option(Opt, Opts) -> [Opt|Opts]. --spec listen_opt_type(atom()) -> fun((any()) -> any()) | [atom()]. -listen_opt_type(access) -> fun acl:access_rules_validator/1; -listen_opt_type(shaper_rule) -> fun acl:shaper_rules_validator/1; -listen_opt_type(certfile) -> - fun(S) -> - ejabberd_pkix:add_certfile(S), - iolist_to_binary(S) +listen_opt_type(shaper_rule) -> + fun(V) -> + ?WARNING_MSG("Listening option 'shaper_rule' of module ~s " + "is renamed to 'shaper'", [?MODULE]), + acl:shaper_rules_validator(V) end; -listen_opt_type(ciphers) -> fun iolist_to_binary/1; -listen_opt_type(dhfile) -> fun misc:try_read_file/1; -listen_opt_type(cafile) -> fun misc:try_read_file/1; -listen_opt_type(protocol_options) -> - fun(Options) -> str:join(Options, <<"|">>) end; -listen_opt_type(tls_compression) -> fun(B) when is_boolean(B) -> B end; -listen_opt_type(tls) -> fun(B) when is_boolean(B) -> B end; listen_opt_type(check_from) -> fun(B) when is_boolean(B) -> B end; listen_opt_type(password) -> fun iolist_to_binary/1; listen_opt_type(hosts) -> @@ -310,21 +301,22 @@ listen_opt_type(hosts) -> end, HostOpts) end; listen_opt_type(global_routes) -> - fun(B) when is_boolean(B) -> B end; -listen_opt_type(max_stanza_size) -> - fun(I) when is_integer(I) -> I; - (unlimited) -> infinity; - (infinity) -> infinity - end; -listen_opt_type(max_fsm_queue) -> - fun(I) when is_integer(I), I>0 -> I end; -listen_opt_type(inet) -> fun(B) when is_boolean(B) -> B end; -listen_opt_type(inet6) -> fun(B) when is_boolean(B) -> B end; -listen_opt_type(backlog) -> - fun(I) when is_integer(I), I>0 -> I end; -listen_opt_type(accept_interval) -> - fun(I) when is_integer(I), I>=0 -> I end; -listen_opt_type(_) -> - [access, shaper_rule, certfile, ciphers, dhfile, cafile, tls, - protocol_options, tls_compression, password, hosts, check_from, - max_fsm_queue, global_routes, backlog, inet, inet6, accept_interval]. + fun(B) when is_boolean(B) -> B end. + +listen_options() -> + [{access, all}, + {shaper, none}, + {shaper_rule, none}, + {certfile, undefined}, + {ciphers, undefined}, + {dhfile, undefined}, + {cafile, undefined}, + {protocol_options, undefined}, + {tls, false}, + {tls_compression, false}, + {max_stanza_size, infinity}, + {max_fsm_queue, 5000}, + {password, undefined}, + {hosts, []}, + {check_from, true}, + {global_routes, true}]. |