diff options
author | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2017-04-30 19:01:47 +0300 |
---|---|---|
committer | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2017-04-30 19:01:47 +0300 |
commit | fddd6110e00df12c99a20a2cc9d074f5f4f1f965 (patch) | |
tree | 366575b855f1b2013db7eeb02ecb213f81c98c1f /src/mod_proxy65_stream.erl | |
parent | Merge branch 'new-option-validation' (diff) |
Don't validate an option in gen_mod:get*opt() functions
The changes are very similar to those from previous commit:
* Now there is no need to pass validating function in
gen_mod:get_opt() and gen_mod:get_module_opt() functions,
because the modules' configuration keeps already validated values.
* New functions gen_mod:get_opt/2 and gen_mod:get_module_opt/3 are
introduced.
* Functions gen_mod:get_opt/4 and get_module_opt/5 are deprecated.
If the functions are still called, the "function" argument is
simply ignored.
* Validating callback Mod:listen_opt_type/1 is introduced to validate
listening options at startup.
Diffstat (limited to '')
-rw-r--r-- | src/mod_proxy65_stream.erl | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/src/mod_proxy65_stream.erl b/src/mod_proxy65_stream.erl index 45ce2f44c..899b66727 100644 --- a/src/mod_proxy65_stream.erl +++ b/src/mod_proxy65_stream.erl @@ -38,7 +38,7 @@ stream_established/2]). -export([start/2, stop/1, start_link/3, activate/2, - relay/3, socket_type/0]). + relay/3, socket_type/0, listen_opt_type/1]). -include("mod_proxy65.hrl"). @@ -65,9 +65,10 @@ code_change(_OldVsn, StateName, StateData, _Extra) -> %%------------------------------- start({gen_tcp, Socket}, Opts1) -> - {[Host], Opts} = lists:partition(fun (O) -> is_binary(O) - end, - Opts1), + {[{server_host, Host}], Opts} = lists:partition( + fun({server_host, _}) -> true; + (_) -> false + end, Opts1), Supervisor = gen_mod:get_module_proc(Host, ejabberd_mod_proxy65_sup), supervisor:start_child(Supervisor, @@ -78,19 +79,10 @@ start_link(Socket, Host, Opts) -> init([Socket, Host, Opts]) -> process_flag(trap_exit, true), - AuthType = gen_mod:get_opt(auth_type, Opts, - fun(plain) -> plain; - (anonymous) -> anonymous - end, anonymous), - Shaper = gen_mod:get_opt(shaper, Opts, - fun acl:shaper_rules_validator/1, - none), - RecvBuf = gen_mod:get_opt(recbuf, Opts, - fun(I) when is_integer(I), I>0 -> I end, - 8192), - SendBuf = gen_mod:get_opt(sndbuf, Opts, - fun(I) when is_integer(I), I>0 -> I end, - 8192), + AuthType = gen_mod:get_opt(auth_type, Opts, anonymous), + Shaper = gen_mod:get_opt(shaper, Opts, none), + RecvBuf = gen_mod:get_opt(recbuf, Opts, 8192), + SendBuf = gen_mod:get_opt(sndbuf, Opts, 8192), TRef = erlang:send_after(?WAIT_TIMEOUT, self(), stop), inet:setopts(Socket, [{active, true}, {recbuf, RecvBuf}, {sndbuf, SendBuf}]), @@ -290,3 +282,17 @@ find_maxrate(Shaper, JID1, JID2, Host) -> 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(_) -> + [auth_type, recbuf, sndbuf, shaper]. |