Skip to content

Commit

Permalink
Get rid of get_module_opt_subhost
Browse files Browse the repository at this point in the history
It was used in two places:
- For ejabberd_admin, where the function was not usable from the CLI
  and would not work with dynamic domains, so it was removed.
  There is stil an utility function in mod_mucm should someone need it.
- For mod_muc, it was used to trigger the (un)register_subhost hooks,
  which are triggered by mongoose_router anyway when routes are added
  and all other modules including mod_muc_light are making use of this
  fact. mod_muc was the only exception here.
  • Loading branch information
chrzaszcz committed Apr 6, 2022
1 parent 28e306b commit 1fa34d3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 42 deletions.
16 changes: 1 addition & 15 deletions src/ejabberd_admin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
-export([start/0, stop/0,
%% Server
status/0,
send_service_message_all_mucs/2,
%% Accounts
register/3, register/2, unregister/2,
registered_users/1,
Expand All @@ -58,7 +57,7 @@
get_loglevel/0, import_users/1, install_fallback_mnesia/1,
join_cluster/1, leave_cluster/0, load_mnesia/1, mnesia_change_nodename/4,
register/2, register/3, registered_users/1, remove_from_cluster/1,
restore_mnesia/1, send_service_message_all_mucs/2, set_master/1, status/0,
restore_mnesia/1, set_master/1, status/0,
stop/0, unregister/2]).

-include("mongoose.hrl").
Expand Down Expand Up @@ -279,7 +278,6 @@ do_leave_cluster() ->
{error, {E, R}}
end.


-spec status() -> {'mongooseim_not_running', io_lib:chars()} | {'ok', io_lib:chars()}.
status() ->
{InternalStatus, ProvidedStatus} = init:get_status(),
Expand All @@ -294,18 +292,6 @@ status() ->
end,
{Is_running, String1 ++ String2}.


-spec send_service_message_all_mucs(Subject :: string() | binary(),
AnnouncementText :: string() | binary()) -> 'ok'.
send_service_message_all_mucs(Subject, AnnouncementText) ->
Message = io_lib:format("~s~n~s", [Subject, AnnouncementText]),
lists:foreach(
fun(Host) ->
MUCHost = gen_mod:get_module_opt_subhost(Host, mod_muc, mod_muc:default_host()),
mod_muc:broadcast_service_message(MUCHost, Message)
end,
?MYHOSTS).

%%%
%%% Account management
%%%
Expand Down
15 changes: 1 addition & 14 deletions src/gen_mod.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
get_module_opt/4,
get_module_opts/2,
get_loaded_module_opts/2,
get_module_opt_subhost/3,

loaded_modules/0,
loaded_modules/1,
Expand All @@ -62,7 +61,6 @@
-include("mongoose.hrl").

-type module_feature() :: atom().
-type domain_name() :: mongooseim:domain_name().
-type host_type() :: mongooseim:host_type().
-type key_path() :: mongoose_config:key_path().
-type opt_key() :: atom().
Expand Down Expand Up @@ -271,23 +269,12 @@ get_module_opt(HostType, Module, Opt) ->

-spec get_module_opts(mongooseim:host_type(), module()) -> module_opts().
get_module_opts(HostType, Module) ->
mongoose_config:get_opt([{modules, HostType}, Module], []).
mongoose_config:get_opt([{modules, HostType}, Module], #{}).

-spec get_loaded_module_opts(mongooseim:host_type(), module()) -> module_opts().
get_loaded_module_opts(HostType, Module) ->
mongoose_config:get_opt([{modules, HostType}, Module]).

-spec get_module_opt_subhost(domain_name(),
module(),
mongoose_subdomain_utils:subdomain_pattern()) ->
domain_name().
get_module_opt_subhost(Host, Module, Default) ->
%% TODO: try to get rid of this interface
%% note that get_module_opt/4 requires host_type(), while
%% mongoose_subdomain_utils:get_fqdn/2 expects domain_name()
Spec = get_module_opt(Host, Module, host, Default),
mongoose_subdomain_utils:get_fqdn(Spec, Host).

-spec loaded_modules() -> [module()].
loaded_modules() ->
lists:usort(lists:flatmap(fun loaded_modules/1, ?ALL_HOST_TYPES)).
Expand Down
14 changes: 1 addition & 13 deletions src/mod_muc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ init({HostType, Opts}) ->
text => <<"Only one MUC domain would work with this host type">>})
end,
mongoose_domain_api:register_subdomain(HostType, SubdomainPattern, PacketHandler),
register_for_global_distrib(HostType),
%% Loading
case LoadPermRoomsAtStartup of
false ->
Expand Down Expand Up @@ -601,9 +600,7 @@ stop_if_hibernated_for_specified_time(Pid, Now, Timeout, {hibernated, LastHibern

terminate(_Reason, #muc_state{host_type = HostType,
subdomain_pattern = SubdomainPattern}) ->
mongoose_domain_api:unregister_subdomain(HostType, SubdomainPattern),
unregister_for_global_distrib(HostType),
ok.
mongoose_domain_api:unregister_subdomain(HostType, SubdomainPattern).

code_change(_OldVsn, State, _Extra) ->
{ok, State}.
Expand Down Expand Up @@ -1406,12 +1403,3 @@ make_server_host(To, #muc_state{host_type = HostType,
{fqdn, _} ->
HostType
end.

register_for_global_distrib(HostType) ->
%% Would not work for multitenancy
SubHost = gen_mod:get_module_opt_subhost(HostType, ?MODULE, default_host()),
mongoose_hooks:register_subhost(SubHost, false).

unregister_for_global_distrib(HostType) ->
SubHost = gen_mod:get_module_opt_subhost(HostType, ?MODULE, default_host()),
mongoose_hooks:unregister_subhost(SubHost).

0 comments on commit 1fa34d3

Please sign in to comment.