25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Validate and set 'version' option at an earlier stage

This commit is contained in:
Evgeny Khramtsov 2019-06-23 12:23:22 +03:00
parent e31373a86c
commit e477a8c220
2 changed files with 22 additions and 17 deletions

View File

@ -32,6 +32,7 @@
-export([get_shared_key/0, get_node_start/0]).
-export([fsm_limit_opts/1]).
-export([codec_options/0]).
-export([version/0]).
-export([default_db/2, default_db/3, default_ram_db/2, default_ram_db/3]).
-export([beams/1, validators/1, globals/0, may_hide_data/1]).
-export([dump/0, dump/1, convert_to_yaml/1, convert_to_yaml/2]).
@ -225,6 +226,23 @@ codec_options() ->
false -> [ignore_els]
end.
%% Do not use this function in runtime:
%% It's slow and doesn't read 'version' option from the config.
%% Use ejabberd_option:version() instead.
-spec version() -> binary().
version() ->
case application:get_env(ejabberd, custom_vsn) of
{ok, Vsn0} when is_list(Vsn0) ->
list_to_binary(Vsn0);
{ok, Vsn1} when is_binary(Vsn1) ->
Vsn1;
_ ->
case application:get_key(ejabberd, vsn) of
undefined -> <<"">>;
{ok, Vsn} -> list_to_binary(Vsn)
end
end.
-spec default_db(binary() | global, module()) -> atom().
default_db(Host, Module) ->
default_db(default_db, Host, Module, mnesia).
@ -500,9 +518,11 @@ validate(Y1) ->
case ejabberd_config_transformer:map_reduce(Y2) of
{ok, Y3} ->
Hosts = proplists:get_value(hosts, Y3),
Version = proplists:get_value(version, Y3, version()),
create_tmp_config(),
set_option(hosts, Hosts),
set_option(host, hd(Hosts)),
set_option(version, Version),
set_option(yaml_config, Y3),
{Validators, Required} = validators([]),
Validator = econf:options(Validators,
@ -522,6 +542,7 @@ pre_validate(Y1) ->
econf:options(
#{hosts => ejabberd_options:opt_type(hosts),
loglevel => ejabberd_options:opt_type(loglevel),
version => ejabberd_options:opt_type(version),
host_config => econf:map(econf:binary(), econf:any()),
append_host_config => econf:map(econf:binary(), econf:any()),
'_' => econf:any()},

View File

@ -444,6 +444,7 @@ options() ->
{default_db, mnesia},
{default_ram_db, mnesia},
{queue_type, ram},
{version, ejabberd_config:version()},
%% Other options
{acl, []},
{access_rules, []},
@ -638,7 +639,6 @@ options() ->
{sql_username, <<"ejabberd">>},
{trusted_proxies, []},
{validate_stream, false},
{version, fun version/1},
{websocket_origin, []},
{websocket_ping_interval, timer:seconds(60)},
{websocket_timeout, timer:minutes(5)}].
@ -743,22 +743,6 @@ fqdn(global) ->
fqdn(_) ->
ejabberd_config:get_option(fqdn).
-spec version(global | binary()) -> binary().
version(global) ->
case application:get_env(ejabberd, custom_vsn) of
{ok, Vsn0} when is_list(Vsn0) ->
list_to_binary(Vsn0);
{ok, Vsn1} when is_binary(Vsn1) ->
Vsn1;
_ ->
case application:get_key(ejabberd, vsn) of
undefined -> <<"">>;
{ok, Vsn} -> list_to_binary(Vsn)
end
end;
version(_) ->
ejabberd_config:get_option(version).
-spec concat_tls_protocol_options([binary()]) -> binary().
concat_tls_protocol_options(Opts) ->
str:join(Opts, <<"|">>).