diff --git a/src/ejabberd_config.erl b/src/ejabberd_config.erl index a31651430..ca4b427d4 100644 --- a/src/ejabberd_config.erl +++ b/src/ejabberd_config.erl @@ -34,7 +34,7 @@ prepare_opt_val/4, transform_options/1, collect_options/1, convert_to_yaml/1, convert_to_yaml/2, v_db/2, env_binary_to_list/2, opt_type/1, may_hide_data/1, - is_elixir_enabled/0, v_dbs/1, v_dbs_mods/1, + is_elixir_enabled/0, v_dbs/1, v_dbs_mods/1, v_host/1, v_hosts/1, default_db/1, default_db/2, default_ram_db/1, default_ram_db/2, default_queue_type/1, queue_dir/0, fsm_limit_opts/1, use_cache/1, cache_size/1, cache_missed/1, cache_life_time/1, @@ -971,6 +971,33 @@ v_dbs_mods(Mod) -> (atom_to_binary(M, utf8))/binary>>, utf8) end, v_dbs(Mod)). +-spec v_host(binary()) -> binary(). +v_host(Host) -> + hd(v_hosts([Host])). + +-spec v_hosts([binary()]) -> [binary()]. +v_hosts(Hosts) -> + ServerHosts = get_myhosts(), + lists:foldr( + fun(Host, Acc) -> + case lists:member(Host, ServerHosts) of + true -> + ?ERROR_MSG("Failed to reuse route ~s because it's " + "already registered on a virtual host", + [Host]), + erlang:error(badarg); + false -> + case lists:member(Host, Acc) of + true -> + ?ERROR_MSG("Host ~s is defined multiple times", + [Host]), + erlang:error(badarg); + false -> + [Host|Acc] + end + end + end, [], Hosts). + -spec default_db(module()) -> atom(). default_db(Module) -> default_db(global, Module). diff --git a/src/mod_echo.erl b/src/mod_echo.erl index a218c5f40..26cf60611 100644 --- a/src/mod_echo.erl +++ b/src/mod_echo.erl @@ -60,9 +60,8 @@ reload(Host, NewOpts, OldOpts) -> depends(_Host, _Opts) -> []. -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(host) -> fun ejabberd_config:v_host/1; +mod_opt_type(hosts) -> fun ejabberd_config:v_hosts/1. mod_options(_Host) -> [{host, <<"echo.@HOST@">>}, {hosts, []}]. diff --git a/src/mod_http_upload.erl b/src/mod_http_upload.erl index 846071a2a..afba0f09a 100644 --- a/src/mod_http_upload.erl +++ b/src/mod_http_upload.erl @@ -151,9 +151,9 @@ stop(ServerHost) -> -spec mod_opt_type(atom()) -> fun((term()) -> term()) | [atom()]. mod_opt_type(host) -> - fun iolist_to_binary/1; + fun ejabberd_config:v_host/1; mod_opt_type(hosts) -> - fun (L) -> lists:map(fun iolist_to_binary/1, L) end; + fun ejabberd_config:v_hosts/1; mod_opt_type(name) -> fun iolist_to_binary/1; mod_opt_type(access) -> diff --git a/src/mod_mix.erl b/src/mod_mix.erl index 51464e63f..78e5d0251 100644 --- a/src/mod_mix.erl +++ b/src/mod_mix.erl @@ -315,9 +315,8 @@ is_not_subscribed({error, StanzaError}) -> depends(_Host, _Opts) -> [{mod_pubsub, hard}]. -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(host) -> fun ejabberd_config:v_host/1; +mod_opt_type(hosts) -> fun ejabberd_config:v_hosts/1. mod_options(_Host) -> [{host, <<"mix.@HOST@">>}, diff --git a/src/mod_muc.erl b/src/mod_muc.erl index d7bb194c1..8a7fd1664 100644 --- a/src/mod_muc.erl +++ b/src/mod_muc.erl @@ -889,10 +889,9 @@ mod_opt_type(db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end; mod_opt_type(ram_db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end; mod_opt_type(history_size) -> fun (I) when is_integer(I), I >= 0 -> I end; -mod_opt_type(host) -> fun iolist_to_binary/1; +mod_opt_type(host) -> fun ejabberd_config:v_host/1; mod_opt_type(name) -> fun iolist_to_binary/1; -mod_opt_type(hosts) -> - fun (L) -> lists:map(fun iolist_to_binary/1, L) end; +mod_opt_type(hosts) -> fun ejabberd_config:v_hosts/1; mod_opt_type(max_room_desc) -> fun (infinity) -> infinity; (I) when is_integer(I), I > 0 -> I diff --git a/src/mod_multicast.erl b/src/mod_multicast.erl index ea6e5b442..632c3d271 100644 --- a/src/mod_multicast.erl +++ b/src/mod_multicast.erl @@ -1083,9 +1083,8 @@ depends(_Host, _Opts) -> 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(host) -> fun ejabberd_config:v_host/1; +mod_opt_type(hosts) -> fun ejabberd_config:v_hosts/1; mod_opt_type(name) -> fun iolist_to_binary/1; mod_opt_type({limits, Type}) when (Type == local) or (Type == remote) -> fun(L) -> diff --git a/src/mod_proxy65.erl b/src/mod_proxy65.erl index 5a348a819..cc3546cf2 100644 --- a/src/mod_proxy65.erl +++ b/src/mod_proxy65.erl @@ -113,9 +113,8 @@ depends(_Host, _Opts) -> []. 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(host) -> fun ejabberd_config:v_host/1; +mod_opt_type(hosts) -> fun ejabberd_config:v_hosts/1; mod_opt_type(hostname) -> fun(undefined) -> undefined; (H) -> iolist_to_binary(H) diff --git a/src/mod_pubsub.erl b/src/mod_pubsub.erl index 8ca4c6564..d96933e11 100644 --- a/src/mod_pubsub.erl +++ b/src/mod_pubsub.erl @@ -3847,9 +3847,8 @@ purge_offline(Host, LJID, Node) -> mod_opt_type(access_createnode) -> fun acl:access_rules_validator/1; mod_opt_type(db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end; mod_opt_type(name) -> fun iolist_to_binary/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(host) -> fun ejabberd_config:v_host/1; +mod_opt_type(hosts) -> fun ejabberd_config:v_hosts/1; mod_opt_type(ignore_pep_from_offline) -> fun (A) when is_boolean(A) -> A end; mod_opt_type(last_item_cache) -> diff --git a/src/mod_vcard.erl b/src/mod_vcard.erl index fe8af76f4..39da3472e 100644 --- a/src/mod_vcard.erl +++ b/src/mod_vcard.erl @@ -531,9 +531,8 @@ mod_opt_type(allow_return_all) -> fun (B) when is_boolean(B) -> B end; mod_opt_type(db_type) -> fun(T) -> ejabberd_config:v_db(?MODULE, T) end; mod_opt_type(name) -> fun iolist_to_binary/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(host) -> fun ejabberd_config:v_host/1; +mod_opt_type(hosts) -> fun ejabberd_config:v_hosts/1; mod_opt_type(matches) -> fun (infinity) -> infinity; (I) when is_integer(I), I > 0 -> I