diff options
author | Evgeny Khramtsov <ekhramtsov@process-one.net> | 2019-06-14 12:33:26 +0300 |
---|---|---|
committer | Evgeny Khramtsov <ekhramtsov@process-one.net> | 2019-06-14 12:33:26 +0300 |
commit | a02cff0e780bb735531594c4ece81e8628f79782 (patch) | |
tree | 6fe7d8219d14f58183be1741fcea262c216db447 /src/mod_proxy65_stream.erl | |
parent | Return jid_malformed error when sending presence without nick to conference (diff) |
Use new configuration validator
Diffstat (limited to 'src/mod_proxy65_stream.erl')
-rw-r--r-- | src/mod_proxy65_stream.erl | 75 |
1 files changed, 22 insertions, 53 deletions
diff --git a/src/mod_proxy65_stream.erl b/src/mod_proxy65_stream.erl index 02d2643ee..06cefdb9f 100644 --- a/src/mod_proxy65_stream.erl +++ b/src/mod_proxy65_stream.erl @@ -39,8 +39,7 @@ stream_established/2]). -export([start/3, stop/1, start_link/3, activate/2, - relay/3, accept/1, listen_opt_type/1, - listen_options/0]). + relay/3, accept/1, listen_options/0]). -include("mod_proxy65.hrl"). @@ -65,28 +64,20 @@ code_change(_OldVsn, StateName, StateData, _Extra) -> %%------------------------------- -start(gen_tcp, Socket, Opts1) -> - {[{server_host, Host}], Opts} = lists:partition( - fun({server_host, _}) -> true; - (_) -> false - end, Opts1), - p1_fsm:start(?MODULE, [Socket, Host, Opts], []). - -start_link(gen_tcp, Socket, Opts1) -> - {[{server_host, Host}], Opts} = lists:partition( - fun({server_host, _}) -> true; - (_) -> false - end, Opts1), - start_link(Socket, Host, Opts); -start_link(Socket, Host, Opts) -> - p1_fsm:start_link(?MODULE, [Socket, Host, Opts], []). - -init([Socket, Host, Opts]) -> +start(gen_tcp, Socket, Opts) -> + Host = proplists:get_value(server_host, Opts), + p1_fsm:start(?MODULE, [Socket, Host], []). + +start_link(gen_tcp, Socket, Opts) -> + Host = proplists:get_value(server_host, Opts), + p1_fsm:start_link(?MODULE, [Socket, Host], []). + +init([Socket, Host]) -> process_flag(trap_exit, true), - AuthType = gen_mod:get_opt(auth_type, Opts), - Shaper = gen_mod:get_opt(shaper, Opts), - RecvBuf = gen_mod:get_opt(recbuf, Opts), - SendBuf = gen_mod:get_opt(sndbuf, Opts), + AuthType = mod_proxy65_opt:auth_type(Host), + Shaper = mod_proxy65_opt:shaper(Host), + RecvBuf = mod_proxy65_opt:recbuf(Host), + SendBuf = mod_proxy65_opt:sndbuf(Host), TRef = erlang:send_after(?WAIT_TIMEOUT, self(), stop), inet:setopts(Socket, [{recbuf, RecvBuf}, {sndbuf, SendBuf}]), {ok, accepting, @@ -284,35 +275,13 @@ select_auth_method(anonymous, AuthMethods) -> %% Obviously, we must use shaper with maximum rate. find_maxrate(Shaper, JID1, JID2, Host) -> - MaxRate1 = case acl:match_rule(Host, Shaper, JID1) of - deny -> none; - R1 -> ejabberd_shaper:new(R1) - end, - MaxRate2 = case acl:match_rule(Host, Shaper, JID2) of - deny -> none; - R2 -> ejabberd_shaper:new(R2) - end, - if MaxRate1 == none; MaxRate2 == none -> none; - true -> lists:max([MaxRate1, MaxRate2]) - end. - -listen_opt_type(server_host) -> - fun iolist_to_binary/1; -listen_opt_type(auth_type) -> - fun (plain) -> plain; - (anonymous) -> anonymous - end; -listen_opt_type(recbuf) -> - fun (I) when is_integer(I), I > 0 -> I end; -listen_opt_type(shaper) -> fun acl:shaper_rules_validator/1; -listen_opt_type(sndbuf) -> - 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. + R1 = ejabberd_shaper:match(Host, Shaper, JID1), + R2 = ejabberd_shaper:match(Host, Shaper, JID2), + R = case ejabberd_shaper:get_max_rate(R1) >= ejabberd_shaper:get_max_rate(R2) of + true -> R1; + false -> R2 + end, + ejabberd_shaper:new(R). listen_options() -> - [{auth_type, anonymous}, - {recbuf, 65536}, - {sndbuf, 65536}, - {accept_interval, 0}, - {shaper, none}]. + []. |