diff options
author | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2018-01-23 10:54:52 +0300 |
---|---|---|
committer | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2018-01-23 10:54:52 +0300 |
commit | ba2b650464bd3aae2b6b0f3a3177476360cb6d08 (patch) | |
tree | 5d55501f76edcdcfe145ba0c3367a54ea0314e5c /src/mod_proxy65.erl | |
parent | Do not try to start ezlib application too frequently (diff) |
Introduce new gen_mod callback: mod_options/1
The callback is supposed to provide known options and their default
values, as long as the documentation. Passing default values into
get_mod functions is now deprecated: all defaults should be provided
by the Mod:mod_options/1 callback.
Diffstat (limited to 'src/mod_proxy65.erl')
-rw-r--r-- | src/mod_proxy65.erl | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/src/mod_proxy65.erl b/src/mod_proxy65.erl index d49b95b9..eb6950c6 100644 --- a/src/mod_proxy65.erl +++ b/src/mod_proxy65.erl @@ -39,10 +39,12 @@ %% supervisor callbacks. -export([init/1]). --export([start_link/2, mod_opt_type/1, depends/2]). +-export([start_link/2, mod_opt_type/1, mod_options/1, depends/2]). -define(PROCNAME, ejabberd_mod_proxy65). +-include("translate.hrl"). + -callback init() -> any(). -callback register_stream(binary(), pid()) -> ok | {error, any()}. -callback unregister_stream(binary()) -> ok | {error, any()}. @@ -114,9 +116,14 @@ mod_opt_type(access) -> fun acl:access_rules_validator/1; mod_opt_type(host) -> fun iolist_to_binary/1; mod_opt_type(hosts) -> fun(L) -> lists:map(fun iolist_to_binary/1, L) end; -mod_opt_type(hostname) -> fun iolist_to_binary/1; +mod_opt_type(hostname) -> + fun(undefined) -> undefined; + (H) -> iolist_to_binary(H) + end; mod_opt_type(ip) -> - fun (S) -> + fun(undefined) -> + undefined; + (S) -> {ok, Addr} = inet_parse:address(binary_to_list(iolist_to_binary(S))), Addr @@ -130,11 +137,20 @@ mod_opt_type(max_connections) -> end; mod_opt_type(ram_db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end; +mod_opt_type(iqdisc) -> + fun gen_iq_handler:check_type/1; mod_opt_type(Opt) -> - case mod_proxy65_stream:listen_opt_type(Opt) of - Opts when is_list(Opts) -> - [access, host, hosts, hostname, ip, name, port, - max_connections, ram_db_type] ++ Opts; - Fun -> - Fun - end. + mod_proxy65_stream:listen_opt_type(Opt). + +mod_options(Host) -> + [{ram_db_type, ejabberd_config:default_ram_db(Host, ?MODULE)}, + {iqdisc, gen_iq_handler:iqdisc(Host)}, + {access, all}, + {host, <<"proxy.@HOST@">>}, + {hosts, []}, + {hostname, undefined}, + {ip, undefined}, + {port, 7777}, + {name, ?T("SOCKS5 Bytestreams")}, + {max_connections, infinity}] ++ + mod_proxy65_stream:listen_options(). |