Skip to content

Commit

Permalink
Style & other minor subhosts fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fenek committed Dec 13, 2016
1 parent d530e02 commit 8c8ce77
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 39 deletions.
2 changes: 1 addition & 1 deletion apps/ejabberd/src/gen_mod.erl
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ get_opt_subhost(Host, Opts, Default) ->
-spec get_module_opt_subhost(ejabberd:server(), module(), list() | binary()) -> ejabberd:server().
get_module_opt_subhost(Host, Module, Default) ->
Subject = get_module_opt(Host, Module, host, Default),
re:replace(Subject, "@HOST@", Host, [global, {return,binary}]).
re:replace(Subject, "@HOST@", Host, [global, {return, binary}]).

-spec loaded_modules(ejabberd:server()) -> [module()].
loaded_modules(Host) ->
Expand Down
8 changes: 5 additions & 3 deletions apps/ejabberd/src/mod_muc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ init([Host, Opts]) ->
mod_muc:route({From, To, Packet}, State)
end,
ejabberd_router:register_route(MyHost, {apply_fun, F}),
mongoose_subhosts:register(Host, MyHost),

load_permanent_rooms(MyHost, Host,
{Access, AccessCreate, AccessAdmin, AccessPersistent},
Expand Down Expand Up @@ -448,6 +449,7 @@ stop_if_hibernated_for_specified_time(Pid, Now, Timeout, {hibernated, LastHibern
%% The return value is ignored.
%%--------------------------------------------------------------------
terminate(_Reason, State) ->
mongoose_subhosts:unregister(State#state.host),
ejabberd_router:unregister_route(State#state.host),
ok.

Expand Down Expand Up @@ -777,10 +779,10 @@ room_jid_to_pid(#jid{luser=RoomName, lserver=MucService}) ->
{error, not_found}
end.

-spec default_host() -> list().
default_host() -> "conference.@HOST@".
-spec default_host() -> binary().
default_host() -> <<"conference.@HOST@">>.

-spec iq_disco_info(ejabberd:lang()) -> [jlib:xmlel(),...].
-spec iq_disco_info(ejabberd:lang()) -> [jlib:xmlel(), ...].
iq_disco_info(Lang) ->
[#xmlel{name = <<"identity">>,
attrs = [{<<"category">>, <<"conference">>},
Expand Down
4 changes: 2 additions & 2 deletions apps/ejabberd/src/mod_muc_light.erl
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ standard_config_schema() -> ["roomname", "subject"].
-spec standard_default_config() -> [{K :: string(), V :: string()}].
standard_default_config() -> [{"roomname", "Untitled"}, {"subject", ""}].

-spec default_host() -> string().
-spec default_host() -> binary().
default_host() ->
"muclight.@HOST@".
<<"muclight.@HOST@">>.

-spec default_config(MUCServer :: ejabberd:lserver()) -> config().
default_config(MUCServer) ->
Expand Down
16 changes: 6 additions & 10 deletions apps/ejabberd/src/mod_muc_light_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,12 @@ room_limit_reached(UserUS, RoomS) ->
filter_out_prevented(FromUS, {RoomU, MUCServer} = RoomUS, AffUsers) ->
RoomsPerUser = gen_mod:get_module_opt_by_subhost(
MUCServer, mod_muc_light, rooms_per_user, ?DEFAULT_ROOMS_PER_USER),
BlockingQuery = case gen_mod:get_module_opt_by_subhost(
MUCServer, mod_muc_light, blocking, ?DEFAULT_BLOCKING) of
true ->
[{user, FromUS}
| if
RoomU == <<>> -> [];
true -> [{room, RoomUS}]
end];
false ->
undefined
BlockingEnabled = gen_mod:get_module_opt_by_subhost(MUCServer, mod_muc_light,
blocking, ?DEFAULT_BLOCKING),
BlockingQuery = case {BlockingEnabled, RoomU} of
{true, <<>>} -> [{user, FromUS}];
{true, _} -> [{user, FromUS}, {room, RoomUS}];
{false, _} -> undefined
end,
case BlockingQuery == undefined andalso RoomsPerUser == infinity of
true -> AffUsers;
Expand Down
4 changes: 2 additions & 2 deletions apps/ejabberd/src/mod_pubsub.erl
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ stop(Host) ->
ok = supervisor:terminate_child(ejabberd_sup, Proc),
ok = supervisor:delete_child(ejabberd_sup, Proc).

-spec default_host() -> string().
-spec default_host() -> binary().
default_host() ->
"pubsub.@HOST@".
<<"pubsub.@HOST@">>.

%%====================================================================
%% gen_server callbacks
Expand Down
8 changes: 4 additions & 4 deletions apps/ejabberd/src/mod_vcard.erl
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ get_results_limit(LServer) ->
?JUD_MATCHES
end.

-spec default_host() -> string().
-spec default_host() -> binary().
default_host() ->
"vjud.@HOST@".
<<"vjud.@HOST@">>.

%%--------------------------------------------------------------------
%% gen_mod callbacks
Expand Down Expand Up @@ -177,9 +177,9 @@ init([VHost, Opts]) ->
|| {Hook, M, F, Prio} <- hook_handlers() ],
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
gen_iq_handler:add_iq_handler(ejabberd_sm, VHost, ?NS_VCARD,
?MODULE,process_sm_iq, IQDisc),
?MODULE, process_sm_iq, IQDisc),
gen_iq_handler:add_iq_handler(ejabberd_local, VHost, ?NS_VCARD,
?MODULE,process_local_iq, IQDisc),
?MODULE, process_local_iq, IQDisc),
DirectoryHost = gen_mod:get_opt_subhost(VHost, Opts, default_host()),
Search = gen_mod:get_opt(search, Opts, true),
case Search of
Expand Down
4 changes: 2 additions & 2 deletions apps/ejabberd/src/mod_vcard_ldap.erl
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ map_vcard_attr(VCardName, Attributes, Pattern, UD) ->

process_pattern(Str, {User, Domain}, AttrValues) ->
eldap_filter:do_sub(Str,
[{<<"%u">>, User}, {<<"%d">>, Domain}] ++
[{<<"%s">>, V, 1} || V <- AttrValues]).
[{<<"%u">>, User}, {<<"%d">>, Domain}] ++
[{<<"%s">>, V, 1} || V <- AttrValues]).

parse_options(Host, Opts) ->
MyHost = gen_mod:get_opt_subhost(Host, Opts, mod_vcard:default_host()),
Expand Down
2 changes: 1 addition & 1 deletion apps/ejabberd/src/mongoose_subhosts.erl
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ get_host(SubHost) ->
[#subhost_mapping{ host = Host }] -> {ok, Host};
[] -> undefined
end.

11 changes: 10 additions & 1 deletion apps/ejabberd/test/muc_light_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ groups() ->
{codec, [sequence], [codec_calls]}
].

init_per_suite(Config) ->
Config.

end_per_suite(Config) ->
exit(whereis(ejabberd_sup), kill),
Config.

init_per_group(rsm_disco, Config) ->
application:start(stringprep),
Config;
Expand All @@ -51,6 +58,8 @@ init_per_testcase(codec_calls, Config) ->
ejabberd_hooks:start_link(),
ejabberd_router:start_link(),
mim_ct_sup:start_link(ejabberd_sup),
mongoose_subhosts:init(),
gen_mod:start(),
mod_muc_light:start(?DOMAIN, []),
ets:new(testcalls, [named_table]),
ets:insert(testcalls, {hooks, 0}),
Expand All @@ -62,7 +71,7 @@ init_per_testcase(_, Config) ->
end_per_testcase(codec_calls, Config) ->
mod_muc_light:stop(?DOMAIN),
mnesia:stop(),
exit(whereis(ejabberd_sup), kill),
mongoose_subhosts:stop(),
Config;
end_per_testcase(_, Config) ->
Config.
Expand Down
6 changes: 3 additions & 3 deletions test/ejabberd_tests/tests/pep_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ send_caps_after_login_test(Config) ->
required_modules() ->
[{mod_caps, []},
{mod_pubsub, [
{plugins,[<<"dag">>,<<"pep">>]},
{nodetree,<<"dag">>},
{pep_mapping,[]},
{plugins, [<<"dag">>, <<"pep">>]},
{nodetree, <<"dag">>},
{pep_mapping, []},
{host, "pubsub.@HOST@"}
]}].

Expand Down
4 changes: 2 additions & 2 deletions test/ejabberd_tests/tests/pubsub_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ disable_delivery_test(Config) ->

required_modules() ->
[{mod_pubsub, [
{plugins,[<<"dag">>]},
{nodetree,<<"dag">>},
{plugins, [<<"dag">>]},
{nodetree, <<"dag">>},
{host, "pubsub.@HOST@"}
]}].
12 changes: 4 additions & 8 deletions test/ejabberd_tests/tests/rest_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,13 @@ maybe_enable_mam(odbc, Host, Config) ->
init_module(Host, mod_mam_odbc_prefs, [muc, pm]),
init_module(Host, mod_mam_odbc_user, [muc, pm]),
init_module(Host, mod_mam, []),
init_module(Host, mod_muc, [{host, "muc.@HOST@"}]),
init_module(Host, mod_mam_muc, [{host, "muc.@HOST@"}]),
init_module(Host, mod_mam_muc, [{host, "muclight.@HOST@"}]),
[{mam_backend, odbc} | Config];
maybe_enable_mam(riak, Host, Config) ->
init_module(Host, mod_mam_riak_timed_arch_yz, [pm, muc]),
init_module(Host, mod_mam_mnesia_prefs, [pm, muc]),
init_module(Host, mod_mam, []),
init_module(Host, mod_muc, [{host, "muc.@HOST@"}]),
init_module(Host, mod_mam_muc, [{host, "muc.@HOST@"}]),
init_module(Host, mod_mam_muc, [{host, "muclight.@HOST@"}]),
[{mam_backend, riak}, {yz_wait, 2500} | Config];
maybe_enable_mam(_, _, C) ->
[{mam_backend, disabled} | C].
Expand All @@ -187,14 +185,12 @@ maybe_disable_mam(odbc, Host) ->
stop_module(Host, mod_mam_odbc_prefs),
stop_module(Host, mod_mam_odbc_user),
stop_module(Host, mod_mam),
stop_module(Host, mod_mam_muc),
stop_module(Host, mod_muc);
stop_module(Host, mod_mam_muc);
maybe_disable_mam(riak, Host) ->
stop_module(Host, mod_mam_riak_timed_arch_yz),
stop_module(Host, mod_mam_mnesia_prefs),
stop_module(Host, mod_mam),
stop_module(Host, mod_mam_muc),
stop_module(Host, mod_muc);
stop_module(Host, mod_mam_muc);
maybe_disable_mam(_, _) ->
ok.

Expand Down

0 comments on commit 8c8ce77

Please sign in to comment.