mirror of
https://github.com/processone/ejabberd
synced 2025-10-03 09:49:18 +02:00
Validate and set 'version' option at an earlier stage
This commit is contained in:
parent
e31373a86c
commit
e477a8c220
2 changed files with 22 additions and 17 deletions
|
@ -32,6 +32,7 @@
|
||||||
-export([get_shared_key/0, get_node_start/0]).
|
-export([get_shared_key/0, get_node_start/0]).
|
||||||
-export([fsm_limit_opts/1]).
|
-export([fsm_limit_opts/1]).
|
||||||
-export([codec_options/0]).
|
-export([codec_options/0]).
|
||||||
|
-export([version/0]).
|
||||||
-export([default_db/2, default_db/3, default_ram_db/2, default_ram_db/3]).
|
-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([beams/1, validators/1, globals/0, may_hide_data/1]).
|
||||||
-export([dump/0, dump/1, convert_to_yaml/1, convert_to_yaml/2]).
|
-export([dump/0, dump/1, convert_to_yaml/1, convert_to_yaml/2]).
|
||||||
|
@ -225,6 +226,23 @@ codec_options() ->
|
||||||
false -> [ignore_els]
|
false -> [ignore_els]
|
||||||
end.
|
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().
|
-spec default_db(binary() | global, module()) -> atom().
|
||||||
default_db(Host, Module) ->
|
default_db(Host, Module) ->
|
||||||
default_db(default_db, Host, Module, mnesia).
|
default_db(default_db, Host, Module, mnesia).
|
||||||
|
@ -500,9 +518,11 @@ validate(Y1) ->
|
||||||
case ejabberd_config_transformer:map_reduce(Y2) of
|
case ejabberd_config_transformer:map_reduce(Y2) of
|
||||||
{ok, Y3} ->
|
{ok, Y3} ->
|
||||||
Hosts = proplists:get_value(hosts, Y3),
|
Hosts = proplists:get_value(hosts, Y3),
|
||||||
|
Version = proplists:get_value(version, Y3, version()),
|
||||||
create_tmp_config(),
|
create_tmp_config(),
|
||||||
set_option(hosts, Hosts),
|
set_option(hosts, Hosts),
|
||||||
set_option(host, hd(Hosts)),
|
set_option(host, hd(Hosts)),
|
||||||
|
set_option(version, Version),
|
||||||
set_option(yaml_config, Y3),
|
set_option(yaml_config, Y3),
|
||||||
{Validators, Required} = validators([]),
|
{Validators, Required} = validators([]),
|
||||||
Validator = econf:options(Validators,
|
Validator = econf:options(Validators,
|
||||||
|
@ -522,6 +542,7 @@ pre_validate(Y1) ->
|
||||||
econf:options(
|
econf:options(
|
||||||
#{hosts => ejabberd_options:opt_type(hosts),
|
#{hosts => ejabberd_options:opt_type(hosts),
|
||||||
loglevel => ejabberd_options:opt_type(loglevel),
|
loglevel => ejabberd_options:opt_type(loglevel),
|
||||||
|
version => ejabberd_options:opt_type(version),
|
||||||
host_config => econf:map(econf:binary(), econf:any()),
|
host_config => econf:map(econf:binary(), econf:any()),
|
||||||
append_host_config => econf:map(econf:binary(), econf:any()),
|
append_host_config => econf:map(econf:binary(), econf:any()),
|
||||||
'_' => econf:any()},
|
'_' => econf:any()},
|
||||||
|
|
|
@ -444,6 +444,7 @@ options() ->
|
||||||
{default_db, mnesia},
|
{default_db, mnesia},
|
||||||
{default_ram_db, mnesia},
|
{default_ram_db, mnesia},
|
||||||
{queue_type, ram},
|
{queue_type, ram},
|
||||||
|
{version, ejabberd_config:version()},
|
||||||
%% Other options
|
%% Other options
|
||||||
{acl, []},
|
{acl, []},
|
||||||
{access_rules, []},
|
{access_rules, []},
|
||||||
|
@ -638,7 +639,6 @@ options() ->
|
||||||
{sql_username, <<"ejabberd">>},
|
{sql_username, <<"ejabberd">>},
|
||||||
{trusted_proxies, []},
|
{trusted_proxies, []},
|
||||||
{validate_stream, false},
|
{validate_stream, false},
|
||||||
{version, fun version/1},
|
|
||||||
{websocket_origin, []},
|
{websocket_origin, []},
|
||||||
{websocket_ping_interval, timer:seconds(60)},
|
{websocket_ping_interval, timer:seconds(60)},
|
||||||
{websocket_timeout, timer:minutes(5)}].
|
{websocket_timeout, timer:minutes(5)}].
|
||||||
|
@ -743,22 +743,6 @@ fqdn(global) ->
|
||||||
fqdn(_) ->
|
fqdn(_) ->
|
||||||
ejabberd_config:get_option(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().
|
-spec concat_tls_protocol_options([binary()]) -> binary().
|
||||||
concat_tls_protocol_options(Opts) ->
|
concat_tls_protocol_options(Opts) ->
|
||||||
str:join(Opts, <<"|">>).
|
str:join(Opts, <<"|">>).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue