aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/econf.erl13
-rw-r--r--src/ejabberd_config.erl34
-rw-r--r--src/ejabberd_options.erl27
3 files changed, 35 insertions, 39 deletions
diff --git a/src/econf.erl b/src/econf.erl
index 42bc0f6cf..e1231ea69 100644
--- a/src/econf.erl
+++ b/src/econf.erl
@@ -24,6 +24,7 @@
%% API
-export([parse/3, validate/2, fail/1, format_error/2, replace_macros/1]).
+-export([group_dups/1]).
%% Simple types
-export([pos_int/0, pos_int/1, non_neg_int/0, non_neg_int/1]).
-export([int/0, int/2, number/1, octal/0]).
@@ -227,6 +228,18 @@ format_join([H|_] = L) when is_atom(H) ->
format_join(L) ->
str:join(lists:sort(L), <<", ">>).
+%% All duplicated options having list-values are grouped
+%% into a single option with all list-values being concatenated
+-spec group_dups(list(T)) -> list(T).
+group_dups(Y1) ->
+ {Y2, D} = lists:mapfoldl(
+ fun({Option, Values}, Acc) when is_list(Values) ->
+ {[], dict:append_list(Option, Values, Acc)};
+ (Other, Acc) ->
+ {[Other], Acc}
+ end, dict:new(), Y1),
+ lists:append(Y2) ++ dict:to_list(D).
+
%%%===================================================================
%%% Validators from yconf
%%%===================================================================
diff --git a/src/ejabberd_config.erl b/src/ejabberd_config.erl
index c80d55764..4463e4caa 100644
--- a/src/ejabberd_config.erl
+++ b/src/ejabberd_config.erl
@@ -550,19 +550,15 @@ validate(Y1) ->
-spec pre_validate(term()) -> {ok, [{atom(), term()}]} | error_return().
pre_validate(Y1) ->
- case econf:validate(
- econf:options(
- #{hosts => ejabberd_options:opt_type(hosts),
- loglevel => ejabberd_options:opt_type(loglevel),
- version => ejabberd_options:opt_type(version),
- '_' => econf:any()},
- [{required, [hosts]}]),
- Y1) of
- {ok, Y2} ->
- {ok, group_duplicated_options(Y2)};
- Err ->
- Err
- end.
+ econf:validate(
+ econf:and_then(
+ econf:options(
+ #{hosts => ejabberd_options:opt_type(hosts),
+ loglevel => ejabberd_options:opt_type(loglevel),
+ version => ejabberd_options:opt_type(version),
+ '_' => econf:any()},
+ [{required, [hosts]}]),
+ fun econf:group_dups/1), Y1).
-spec load_file(binary()) -> ok | error_return().
load_file(File) ->
@@ -768,15 +764,3 @@ set_node_start(UnixTime) ->
-spec set_loglevel(logger:level()) -> ok.
set_loglevel(Level) ->
ejabberd_logger:set(Level).
-
-%% All duplicated options having list-values are grouped
-%% into a single option with all list-values being concatenated
--spec group_duplicated_options([{atom(), term()}]) -> [{atom(), term()}].
-group_duplicated_options(Y1) ->
- {Y2, D} = lists:mapfoldl(
- fun({Option, Values}, Acc) when is_list(Values) ->
- {[], dict:append_list(Option, Values, Acc)};
- ({Option, Value}, Acc) ->
- {{Option, Value}, Acc}
- end, dict:new(), Y1),
- lists:flatten(Y2) ++ dict:to_list(D).
diff --git a/src/ejabberd_options.erl b/src/ejabberd_options.erl
index 8aef43de3..f0987986a 100644
--- a/src/ejabberd_options.erl
+++ b/src/ejabberd_options.erl
@@ -53,12 +53,7 @@ opt_type(anonymous_protocol) ->
opt_type(api_permissions) ->
ejabberd_access_permissions:validator();
opt_type(append_host_config) ->
- econf:map(
- econf:and_then(
- econf:domain(),
- econf:enum(ejabberd_config:get_option(hosts))),
- validator(),
- [unique]);
+ opt_type(host_config);
opt_type(auth_cache_life_time) ->
econf:timeout(second, infinity);
opt_type(auth_cache_missed) ->
@@ -150,12 +145,14 @@ opt_type(fqdn) ->
opt_type(hide_sensitive_log_data) ->
econf:bool();
opt_type(host_config) ->
- econf:map(
+ econf:and_then(
econf:and_then(
- econf:domain(),
- econf:enum(ejabberd_config:get_option(hosts))),
- validator(),
- [unique]);
+ econf:map(econf:domain(), econf:list(econf:any())),
+ fun econf:group_dups/1),
+ econf:map(
+ econf:enum(ejabberd_config:get_option(hosts)),
+ validator(),
+ [unique]));
opt_type(hosts) ->
econf:non_empty(econf:list(econf:domain(), [unique]));
opt_type(include_config_file) ->
@@ -737,9 +734,11 @@ globals() ->
validator() ->
Disallowed = ejabberd_config:globals(),
{Validators, Required} = ejabberd_config:validators(Disallowed),
- econf:options(
- Validators,
- [{disallowed, Required ++ Disallowed}, unique]).
+ econf:and_then(
+ fun econf:group_dups/1,
+ econf:options(
+ Validators,
+ [{disallowed, Required ++ Disallowed}, unique])).
-spec fqdn(global | binary()) -> [binary()].
fqdn(global) ->