24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-02 21:17:12 +02:00

Split some functions in smaller ones

This commit is contained in:
Evgeniy Khramtsov 2017-05-08 16:29:01 +03:00
parent bf2a2f291f
commit 6b6d07745d

View File

@ -26,6 +26,8 @@
-module(ejabberd_config). -module(ejabberd_config).
-author('alexey@process-one.net'). -author('alexey@process-one.net').
-compile(export_all).
-export([start/0, load_file/1, reload_file/0, read_file/1, -export([start/0, load_file/1, reload_file/0, read_file/1,
get_option/1, get_option/2, add_option/2, has_option/1, get_option/1, get_option/2, add_option/2, has_option/1,
get_vh_by_auth_method/1, is_file_readable/1, get_vh_by_auth_method/1, is_file_readable/1,
@ -179,7 +181,10 @@ read_file(File, Opts) ->
load_file(File) -> load_file(File) ->
State0 = read_file(File), State0 = read_file(File),
State1 = hosts_to_start(State0), State1 = hosts_to_start(State0),
validate_opts(State1). AllMods = get_modules(),
init_module_db_table(AllMods),
ModOpts = get_modules_with_options(AllMods),
validate_opts(State1, ModOpts).
-spec reload_file() -> ok. -spec reload_file() -> ok.
@ -971,11 +976,12 @@ default_db(Opt, Host, Module) ->
end end
end. end.
get_modules_with_options() -> get_modules() ->
{ok, Mods} = application:get_key(ejabberd, modules), {ok, Mods} = application:get_key(ejabberd, modules),
ExtMods = [Name || {Name, _Details} <- ext_mod:installed()], ExtMods = [Name || {Name, _Details} <- ext_mod:installed()],
AllMods = [?MODULE|ExtMods++Mods], ExtMods ++ Mods.
init_module_db_table(AllMods),
get_modules_with_options(Modules) ->
lists:foldl( lists:foldl(
fun(Mod, D) -> fun(Mod, D) ->
case is_behaviour(?MODULE, Mod) orelse Mod == ?MODULE of case is_behaviour(?MODULE, Mod) orelse Mod == ?MODULE of
@ -992,10 +998,9 @@ get_modules_with_options() ->
false -> false ->
D D
end end
end, dict:new(), AllMods). end, dict:new(), Modules).
validate_opts(#state{opts = Opts} = State) -> validate_opts(#state{opts = Opts} = State, ModOpts) ->
ModOpts = get_modules_with_options(),
NewOpts = lists:filtermap( NewOpts = lists:filtermap(
fun(#local_config{key = {Opt, _Host}, value = Val} = In) -> fun(#local_config{key = {Opt, _Host}, value = Val} = In) ->
case dict:find(Opt, ModOpts) of case dict:find(Opt, ModOpts) of