Skip to content

Commit

Permalink
Merge pull request #3488 from esl/unfold-module-opts
Browse files Browse the repository at this point in the history
Do not post-process config when starting modules
  • Loading branch information
JanuszJakubiec authored Jan 4, 2022
2 parents 9de9aee + 1603185 commit 1262811
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
22 changes: 11 additions & 11 deletions src/config/mongoose_config_parser.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

%% config post-processing
-export([dedup_state_opts/1,
add_dep_modules/1]).
post_process_modules/1]).

-ignore_xref([behaviour_info/1, get_opts/1,
state_to_global_opt/3, state_to_host_types/1, state_to_hosts/1]).
Expand Down Expand Up @@ -118,20 +118,20 @@ dedup_state_opts_list([{K, _V} = H|List], Removed, Keep, Set) ->
dedup_state_opts_list([], Removed, Keep, _Set) ->
{Keep, Removed}.

-spec add_dep_modules(state()) -> state().
add_dep_modules(State = #state{opts = Opts}) ->
Opts2 = add_dep_modules_opts(Opts),
-spec post_process_modules(state()) -> state().
post_process_modules(State = #state{opts = Opts}) ->
Opts2 = lists:map(fun post_process_modules_opt/1, Opts),
State#state{opts = Opts2}.

add_dep_modules_opts(Opts) ->
lists:map(fun add_dep_modules_opt/1, Opts).

add_dep_modules_opt({{modules, Host}, Modules}) ->
ModulesWithDeps = gen_mod_deps:resolve_deps(Host, Modules),
{{modules, Host}, ModulesWithDeps};
add_dep_modules_opt(Other) ->
post_process_modules_opt({{modules, HostType}, Modules}) ->
ModulesWithDeps = gen_mod_deps:resolve_deps(HostType, Modules),
{{modules, HostType}, unfold_opts(ModulesWithDeps)};
post_process_modules_opt(Other) ->
Other.

unfold_opts(Modules) ->
maps:map(fun(_Mod, Opts) -> proplists:unfold(Opts) end, Modules).

%% local functions

-spec halt_with_msg(string(), [any()]) -> no_return().
Expand Down
2 changes: 1 addition & 1 deletion src/config/mongoose_config_parser_toml.erl
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ build_state(Hosts, HostTypes, Opts) ->
fun(S) -> mongoose_config_parser:set_host_types(HostTypes, S) end,
fun(S) -> mongoose_config_parser:set_opts(Opts, S) end,
fun mongoose_config_parser:dedup_state_opts/1,
fun mongoose_config_parser:add_dep_modules/1]).
fun mongoose_config_parser:post_process_modules/1]).

%% Any nested config_part() may be a config_error() - this function extracts them all recursively
-spec extract_errors([config()]) -> [config_error()].
Expand Down
3 changes: 1 addition & 2 deletions src/gen_mod.erl
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ start_module(HostType, Module, Opts) ->
false -> start_module_for_host_type(HostType, Module, Opts)
end.

start_module_for_host_type(HostType, Module, Opts0) ->
start_module_for_host_type(HostType, Module, Opts) ->
{links, LinksBefore} = erlang:process_info(self(), links),
Opts = proplists:unfold(Opts0),
ets:insert(ejabberd_modules, #ejabberd_module{module_host_type = {Module, HostType},
opts = Opts}),
try
Expand Down
3 changes: 2 additions & 1 deletion src/mongoose_modules.erl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ ensure_stopped(HostType, Module) ->
%% @doc Make sure the module is running with the provided options.
-spec ensure_started(mongooseim:host_type(), module(), module_opts()) ->
already_started | {started, term()} | {restarted, module_opts(), term()}.
ensure_started(HostType, Module, Opts) ->
ensure_started(HostType, Module, RawOpts) ->
Opts = proplists:unfold(RawOpts),
Modules = get_modules(HostType),
case maps:find(Module, Modules) of
error ->
Expand Down
12 changes: 6 additions & 6 deletions test/config_parser_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ options("s2s_only") ->
<<"reg1">> => deny}}].

all_modules() ->
#{mod_mam_rdbms_user => [muc, pm],
#{mod_mam_rdbms_user => [{muc, true}, {pm, true}],
mod_event_pusher_hook_translator => [],
mod_mam_muc =>
[{archive_chat_markers, true},
Expand All @@ -402,7 +402,7 @@ all_modules() ->
{host, {fqdn, <<"muc.example.com">>}},
{is_archivable_message, mod_mam_utils}],
mod_caps => [{cache_life_time, 86}, {cache_size, 1000}],
mod_mam_cache_user => [muc, pm],
mod_mam_cache_user => [{muc, true}, {pm, true}],
mod_offline =>
[{access_max_user_messages, max_user_offline_messages},
{backend, riak},
Expand Down Expand Up @@ -510,14 +510,14 @@ all_modules() ->
{ldap_rfilter, "(objectClass=inetOrgPerson)"},
{ldap_user_cache_validity, 1},
{ldap_userdesc, "cn"}],
mod_mam_mnesia_prefs => [muc],
mod_mam_mnesia_prefs => [{muc, true}],
mod_jingle_sip =>
[{listen_port, 5600},
{local_host, "localhost"},
{proxy_host, "localhost"},
{proxy_port, 5600},
{sdp_origin, "127.0.0.1"}],
mod_mam_rdbms_prefs => [pm],
mod_mam_rdbms_prefs => [{pm, true}],
mod_extdisco =>
[[{host, "stun1"},
{password, "password"},
Expand Down Expand Up @@ -606,7 +606,7 @@ all_modules() ->
{password_strength, 32},
{registration_watchers, [<<"JID1">>, <<"JID2">>]},
{welcome_message, {"Subject", "Body"}}],
mod_mam_rdbms_arch => [no_writer, pm],
mod_mam_rdbms_arch => [{no_writer, true}, {pm, true}],
mod_event_pusher_rabbit =>
[{chat_msg_exchange,
[{name, <<"chat_msg">>},
Expand Down Expand Up @@ -641,7 +641,7 @@ all_modules() ->
{matches, 1},
{search, true}],
mod_mam_muc_rdbms_arch =>
[muc, {db_jid_format, mam_jid_rfc}, {db_message_format, mam_message_xml}],
[{muc, true}, {db_jid_format, mam_jid_rfc}, {db_message_format, mam_message_xml}],
mod_stream_management =>
[{ack_freq, 1},
{buffer_max, 30},
Expand Down

0 comments on commit 1262811

Please sign in to comment.