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.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 'src/mod_proxy65.erl')
-rw-r--r-- | src/mod_proxy65.erl | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/mod_proxy65.erl b/src/mod_proxy65.erl index 53f70834..aee32496 100644 --- a/src/mod_proxy65.erl +++ b/src/mod_proxy65.erl @@ -50,14 +50,21 @@ ok | {error, limit | conflict | notfound | term()}. start(Host, Opts) -> - case mod_proxy65_service:add_listener(Host, Opts) of + {ListenOpts, ModOpts} = lists:partition( + fun({auth_type, _}) -> true; + ({recbuf, _}) -> true; + ({sndbuf, _}) -> true; + ({shaper, _}) -> true; + (_) -> false + end, Opts), + case mod_proxy65_service:add_listener(Host, ListenOpts) of {error, _} = Err -> Err; _ -> Mod = gen_mod:ram_db_mod(global, ?MODULE), Mod:init(), Proc = gen_mod:get_module_proc(Host, ?PROCNAME), - ChildSpec = {Proc, {?MODULE, start_link, [Host, Opts]}, + ChildSpec = {Proc, {?MODULE, start_link, [Host, ModOpts]}, transient, infinity, supervisor, [?MODULE]}, supervisor:start_child(ejabberd_gen_mod_sup, ChildSpec) end. @@ -103,15 +110,6 @@ init([Host, Opts]) -> depends(_Host, _Opts) -> []. -mod_opt_type(auth_type) -> - fun (plain) -> plain; - (anonymous) -> anonymous - end; -mod_opt_type(recbuf) -> - fun (I) when is_integer(I), I > 0 -> I end; -mod_opt_type(shaper) -> fun acl:shaper_rules_validator/1; -mod_opt_type(sndbuf) -> - fun (I) when is_integer(I), I > 0 -> I end; mod_opt_type(access) -> fun acl:access_rules_validator/1; mod_opt_type(host) -> fun iolist_to_binary/1; mod_opt_type(hostname) -> fun iolist_to_binary/1; @@ -130,7 +128,11 @@ mod_opt_type(max_connections) -> end; mod_opt_type(ram_db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end; -mod_opt_type(_) -> - [auth_type, recbuf, shaper, sndbuf, - access, host, hostname, ip, name, port, - max_connections, ram_db_type]. +mod_opt_type(Opt) -> + case mod_proxy65_stream:listen_opt_type(Opt) of + Opts when is_list(Opts) -> + [access, host, hostname, ip, name, port, + max_connections, ram_db_type] ++ Opts; + Fun -> + Fun + end. |