Skip to content

Commit

Permalink
Merge pull request #3091 from esl/i-forgot-myname
Browse files Browse the repository at this point in the history
Remove ?MYNAME macros

Remove all occurences of ?MYNAME except stream errors and the initial value in ejabberd_c2s. These are the only expected uses of this macro.
  • Loading branch information
DenysGonchar authored Apr 23, 2021
2 parents 2513ce3 + 0a2ab15 commit b6c4fed
Show file tree
Hide file tree
Showing 15 changed files with 232 additions and 225 deletions.
12 changes: 6 additions & 6 deletions big_tests/tests/bosh_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -848,23 +848,23 @@ inactivity() ->

inactivity(Value) ->
{inactivity,
fun() -> rpc(mim(), mod_bosh, get_inactivity, []) end,
fun(V) -> rpc(mim(), mod_bosh, set_inactivity, [V]) end,
fun() -> rpc(mim(), mod_bosh, get_inactivity, [domain()]) end,
fun(V) -> rpc(mim(), mod_bosh, set_inactivity, [domain(), V]) end,
Value}.

max_wait() ->
max_wait(?MAX_WAIT).

max_wait(Value) ->
{max_wait,
fun() -> rpc(mim(), mod_bosh, get_max_wait, []) end,
fun(V) -> rpc(mim(), mod_bosh, set_max_wait, [V]) end,
fun() -> rpc(mim(), mod_bosh, get_max_wait, [domain()]) end,
fun(V) -> rpc(mim(), mod_bosh, set_max_wait, [domain(), V]) end,
Value}.

server_acks_opt() ->
{server_acks,
fun() -> rpc(mim(), mod_bosh, get_server_acks, []) end,
fun(V) -> rpc(mim(), mod_bosh, set_server_acks, [V]) end,
fun() -> rpc(mim(), mod_bosh, get_server_acks, [domain()]) end,
fun(V) -> rpc(mim(), mod_bosh, set_server_acks, [domain(), V]) end,
true}.

is_session_alive(Sid) ->
Expand Down
4 changes: 2 additions & 2 deletions big_tests/tests/ejabberdctl_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ remove_old_messages_test(Config) ->
{jid, _, _, _, LUser, LServer, _} = JidRecordBob,
rpc_call(mod_offline_backend, write_messages, [LUser, LServer, [OfflineOld, OfflineNew]]),
%% when
{_, 0} = ejabberdctl("delete_old_messages", ["1"], Config),
{_, 0} = ejabberdctl("delete_old_messages", [LServer, "1"], Config),
{ok, SecondList} = rpc_call(mod_offline_backend, pop_messages, [JidRecordBob]),
%% then
1 = length(SecondList)
Expand Down Expand Up @@ -1243,7 +1243,7 @@ remove_expired_messages_test(Config) ->
Args = [OfflineOld, OfflineNow, OfflineFuture, OfflineFuture2],
rpc_call(mod_offline_backend, write_messages, [LUser, LServer, Args]),
%% when
{_, 0} = ejabberdctl("delete_expired_messages", [], Config),
{_, 0} = ejabberdctl("delete_expired_messages", [LServer], Config),
{ok, SecondList} = rpc_call(mod_offline_backend, pop_messages, [JidRecordKate]),
%% then
2 = length(SecondList)
Expand Down
18 changes: 13 additions & 5 deletions big_tests/tests/mod_global_distrib_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,15 @@ init_per_group_generic(Config0) ->
OldMods = save_modules(NodeName, VirtHosts),

rpc(NodeName, gen_mod_deps, start_modules,
[<<"localhost">>, [{mod_global_distrib, Opts}]]),
[domain(), [{mod_global_distrib, Opts}]]),

[rpc(NodeName, gen_mod, stop_module, [VirtHost, Mod])
|| Mod <- ModulesToStop, VirtHost <- VirtHosts],

ResumeTimeout = rpc(NodeName, mod_stream_management, get_resume_timeout, [1]),
true = rpc(NodeName, mod_stream_management, set_resume_timeout, [1]),
ResumeTimeout = rpc(NodeName, mod_stream_management, get_resume_timeout,
[domain(), 1]),
true = rpc(NodeName, mod_stream_management, set_resume_timeout,
[domain(), 1]),

OldMods ++
[
Expand Down Expand Up @@ -243,7 +245,7 @@ end_per_group_generic(Config) ->
[restore_modules(NodeName, VirtHost, Config) || VirtHost <- VirtHosts],

rpc(NodeName, mod_stream_management, set_resume_timeout,
[?config({resume_timeout, NodeName}, Config)])
[domain(), ?config({resume_timeout, NodeName}, Config)])
end,
get_hosts()).

Expand Down Expand Up @@ -342,7 +344,13 @@ generic_end_per_testcase(CaseName, Config) ->
escalus:end_per_testcase(CaseName, Config).

virtual_hosts() ->
[ct:get_config({hosts, mim, domain}), ct:get_config({hosts, mim, secondary_domain})].
[domain(), secondary_domain()].

domain() ->
ct:get_config({hosts, mim, domain}).

secondary_domain() ->
ct:get_config({hosts, mim, secondary_domain}).

%% Refresher is not started at all or stopped for some test cases
-spec pause_refresher(NodeName :: atom(), CaseName :: atom()) -> ok.
Expand Down
44 changes: 22 additions & 22 deletions big_tests/tests/sm_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ end_per_suite(Config) ->

init_per_group(G, Config) when G =:= unacknowledged_message_hook;
G =:= manual_ack_freq_long_session_timeout ->
true = rpc(mim(), ?MOD_SM, set_ack_freq, [1]),
true = rpc(mim(), ?MOD_SM, set_ack_freq, [domain(), 1]),
escalus_users:update_userspec(Config, alice, manual_ack, true);
init_per_group(parallel_manual_ack_freq_1, Config) ->
true = rpc(mim(), ?MOD_SM, set_ack_freq, [1]),
rpc(mim(), ?MOD_SM, set_resume_timeout, [?SHORT_RESUME_TIMEOUT]),
true = rpc(mim(), ?MOD_SM, set_ack_freq, [domain(), 1]),
rpc(mim(), ?MOD_SM, set_resume_timeout, [domain(), ?SHORT_RESUME_TIMEOUT]),
escalus_users:update_userspec(Config, alice, manual_ack, true);
init_per_group(stale_h, Config) ->
escalus_users:update_userspec(Config, alice, manual_ack, true);
Expand All @@ -161,11 +161,11 @@ end_per_group(stream_mgmt_disabled, Config) ->
dynamic_modules:restore_modules(domain(), Config);
end_per_group(G, Config) when G =:= unacknowledged_message_hook;
G =:= manual_ack_freq_long_session_timeout ->
true = rpc(mim(), ?MOD_SM, set_ack_freq, [never]),
true = rpc(mim(), ?MOD_SM, set_ack_freq, [domain(), never]),
Config;
end_per_group(parallel_manual_ack_freq_1, Config) ->
true = rpc(mim(), ?MOD_SM, set_ack_freq, [never]),
rpc(mim(), ?MOD_SM, set_resume_timeout, [600]),
true = rpc(mim(), ?MOD_SM, set_ack_freq, [domain(), never]),
rpc(mim(), ?MOD_SM, set_resume_timeout, [domain(), 600]),
Config;
end_per_group(_GroupName, Config) ->
Config.
Expand All @@ -179,7 +179,7 @@ set_gc_parameters(RepeatAfter, Geriatric, Config) ->

register_smid(IntSmidId) ->
S = {SMID = make_smid(), IntSmidId},
ok = rpc(mim(), ?MOD_SM, register_stale_smid_h, [SMID, IntSmidId]),
ok = rpc(mim(), ?MOD_SM, register_stale_smid_h, [domain(), SMID, IntSmidId]),
S.

register_some_smid_h(Config) ->
Expand All @@ -188,8 +188,8 @@ register_some_smid_h(Config) ->

init_per_testcase(resume_expired_session_returns_correct_h = CN, Config) ->
Config2 = set_gc_parameters(?BIG_BIG_BIG_TIMEOUT, ?BIG_BIG_BIG_TIMEOUT, Config),
rpc(mim(), ?MOD_SM, set_resume_timeout, [?SHORT_RESUME_TIMEOUT]),
true = rpc(mim(), ?MOD_SM, set_ack_freq, [1]),
rpc(mim(), ?MOD_SM, set_resume_timeout, [domain(), ?SHORT_RESUME_TIMEOUT]),
true = rpc(mim(), ?MOD_SM, set_ack_freq, [domain(), 1]),
escalus:init_per_testcase(CN, Config2);
init_per_testcase(gc_repeat_after_never_means_no_cleaning = CN, Config) ->
Config2 = set_gc_parameters(?BIG_BIG_BIG_TIMEOUT, ?SHORT_RESUME_TIMEOUT, Config),
Expand All @@ -200,7 +200,7 @@ init_per_testcase(gc_repeat_after_timeout_does_clean = CN, Config) ->
Config3 = register_some_smid_h(Config2),
escalus:init_per_testcase(CN, Config3);
init_per_testcase(server_requests_ack_freq_2 = CN, Config) ->
true = rpc(mim(), ?MOD_SM, set_ack_freq, [2]),
true = rpc(mim(), ?MOD_SM, set_ack_freq, [domain(), 2]),
escalus:init_per_testcase(CN, Config);
init_per_testcase(replies_are_processed_by_resumed_session = CN, Config) ->
register_handler(<<"localhost">>),
Expand All @@ -217,7 +217,7 @@ end_per_testcase(CN, Config) when CN =:= resume_expired_session_returns_correct_
dynamic_modules:restore_modules(domain(), Config),
escalus:end_per_testcase(CN, Config);
end_per_testcase(server_requests_ack_freq_2 = CN, Config) ->
true = rpc(mim(), ?MOD_SM, set_ack_freq, [never]),
true = rpc(mim(), ?MOD_SM, set_ack_freq, [domain(), never]),
escalus:end_per_testcase(CN, Config);
end_per_testcase(replies_are_processed_by_resumed_session = CN, Config) ->
unregister_handler(<<"localhost">>),
Expand Down Expand Up @@ -676,15 +676,15 @@ resume_expired_session_returns_correct_h(Config) ->
escalus_connection:stop(NewAlice).

gc_repeat_after_never_means_no_cleaning(Config) ->
true = rpc(mim(), ?MOD_SM, set_stale_h_repeat_after, [?BIG_BIG_BIG_TIMEOUT]),
true = rpc(mim(), ?MOD_SM, set_stale_h_repeat_after, [domain(), ?BIG_BIG_BIG_TIMEOUT]),
[{SMID1, _}, {SMID2, _}, {SMID3, _}] = ?config(smid_test, Config),
{stale_h, 1} = rpc(mim(), ?MOD_SM, get_session_from_smid, [SMID1]),
{stale_h, 2} = rpc(mim(), ?MOD_SM, get_session_from_smid, [SMID2]),
{stale_h, 3} = rpc(mim(), ?MOD_SM, get_session_from_smid, [SMID3]).
{stale_h, 1} = rpc(mim(), ?MOD_SM, get_session_from_smid, [domain(), SMID1]),
{stale_h, 2} = rpc(mim(), ?MOD_SM, get_session_from_smid, [domain(), SMID2]),
{stale_h, 3} = rpc(mim(), ?MOD_SM, get_session_from_smid, [domain(), SMID3]).
gc_repeat_after_timeout_does_clean(Config) ->
[{SMID1, _} | _ ] = ?config(smid_test, Config),
mongoose_helper:wait_until(fun() ->
rpc(mim(), ?MOD_SM, get_stale_h, [SMID1])
rpc(mim(), ?MOD_SM, get_stale_h, [domain(), SMID1])
end,
{error, smid_not_found},
#{name => smid_garbage_collected}).
Expand Down Expand Up @@ -1373,26 +1373,26 @@ discard_offline_messages(Config, User, H) ->
buffer_max(BufferMax) ->
{buffer_max,
fun () ->
rpc(mim(), ?MOD_SM, get_buffer_max, [unset])
rpc(mim(), ?MOD_SM, get_buffer_max, [domain(), unset])
end,
fun (unset) ->
ct:pal("buffer_max was not set - setting to 'undefined'"),
rpc(mim(), ?MOD_SM, set_buffer_max, [undefined]);
rpc(mim(), ?MOD_SM, set_buffer_max, [domain(), undefined]);
(V) ->
rpc(mim(), ?MOD_SM, set_buffer_max, [V])
rpc(mim(), ?MOD_SM, set_buffer_max, [domain(), V])
end,
BufferMax}.

ack_freq(AckFreq) ->
{ack_freq,
fun () ->
rpc(mim(), ?MOD_SM, get_ack_freq, [unset])
rpc(mim(), ?MOD_SM, get_ack_freq, [domain(), unset])
end,
fun (unset) ->
ct:pal("ack_freq was not set - setting to 'undefined'"),
rpc(mim(), ?MOD_SM, set_ack_freq, [undefined]);
rpc(mim(), ?MOD_SM, set_ack_freq, [domain(), undefined]);
(V) ->
rpc(mim(), ?MOD_SM, set_ack_freq, [V])
rpc(mim(), ?MOD_SM, set_ack_freq, [domain(), V])
end,
AckFreq}.

Expand Down
22 changes: 11 additions & 11 deletions src/ejabberd_admin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
registered_users/1,
import_users/1,
%% Purge DB
delete_expired_messages/0, delete_old_messages/1,
delete_expired_messages/1, delete_old_messages/2,
%% Mnesia
set_master/1,
backup_mnesia/1, restore_mnesia/1,
Expand Down Expand Up @@ -88,7 +88,7 @@ commands() ->
module = ?MODULE, function = register,
args = [{host, binary}, {password, binary}],
result = {res, restuple}},
#ejabberd_commands{name = register_identified, tags = [accounts],
#ejabberd_commands{name = register_identified, tags = [accounts],
desc = "Register a user with a specific jid",
module = ?MODULE, function = register,
args = [{user, binary}, {host, binary}, {password, binary}],
Expand All @@ -113,11 +113,11 @@ commands() ->
#ejabberd_commands{name = delete_expired_messages, tags = [purge],
desc = "Delete expired offline messages from database",
module = ?MODULE, function = delete_expired_messages,
args = [], result = {res, restuple}},
args = [{host, binary}], result = {res, restuple}},
#ejabberd_commands{name = delete_old_messages, tags = [purge],
desc = "Delete offline messages older than DAYS",
module = ?MODULE, function = delete_old_messages,
args = [{days, integer}], result = {res, restuple}},
args = [{host, binary}, {days, integer}], result = {res, restuple}},
#ejabberd_commands{name = set_master, tags = [mnesia],
desc = "Set master node of the clustered Mnesia tables",
longdesc = "If you provide as nodename \"self\", this "
Expand Down Expand Up @@ -442,18 +442,18 @@ get_loglevel() ->
%%% Purge DB
%%%

-spec delete_expired_messages() -> {ok, iolist()} | {error, iolist()}.
delete_expired_messages() ->
case mod_offline:remove_expired_messages(?MYNAME) of
-spec delete_expired_messages(jid:lserver()) -> {ok, iolist()} | {error, iolist()}.
delete_expired_messages(LServer) ->
case mod_offline:remove_expired_messages(LServer) of
{ok, C} ->
{ok, io_lib:format("Removed ~p messages", [C])};
{error, Reason} ->
{error, io_lib:format("Can't delete expired messages: ~n~p", [Reason])}
end.

-spec delete_old_messages(Days :: integer()) -> {ok, iolist()} | {error, iolist()}.
delete_old_messages(Days) ->
case mod_offline:remove_old_messages(?MYNAME, Days) of
-spec delete_old_messages(jid:lserver(), Days :: integer()) -> {ok, iolist()} | {error, iolist()}.
delete_old_messages(LServer, Days) ->
case mod_offline:remove_old_messages(LServer, Days) of
{ok, C} ->
{ok, io_lib:format("Removed ~p messages", [C])};
{error, Reason} ->
Expand Down Expand Up @@ -533,7 +533,7 @@ keep_tables() ->
-spec keep_modules_tables() -> [[atom()]]. % list of lists
keep_modules_tables() ->
lists:map(fun(Module) -> module_tables(Module) end,
gen_mod:loaded_modules(?MYNAME)).
gen_mod:loaded_modules()).

%% TODO: This mapping should probably be moved to a callback function in each module.
%% @doc Mapping between modules and their tables
Expand Down
30 changes: 15 additions & 15 deletions src/ejabberd_c2s.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2777,7 +2777,7 @@ bounce_csi_buffer(#state{csi_buffer = Buffer}) ->
%%%----------------------------------------------------------------------
%%% XEP-0198: Stream Management
%%%----------------------------------------------------------------------
maybe_enable_stream_mgmt(NextState, El, StateData) ->
maybe_enable_stream_mgmt(NextState, El, StateData = #state{server = LServer}) ->
case {xml:get_tag_attr_s(<<"xmlns">>, El),
StateData#state.stream_mgmt,
xml:get_tag_attr_s(<<"resume">>, El)}
Expand All @@ -2791,9 +2791,9 @@ maybe_enable_stream_mgmt(NextState, El, StateData) ->
enable_stream_resumption(StateData)
end,
send_element_from_server_jid(NewSD, EnabledEl),
BufferMax = get_buffer_max(),
AckFreq = get_ack_freq(),
ResumeTimeout = get_resume_timeout(),
BufferMax = get_buffer_max(LServer),
AckFreq = get_ack_freq(LServer),
ResumeTimeout = get_resume_timeout(LServer),
fsm_next_state(NextState,
NewSD#state{stream_mgmt = true,
stream_mgmt_buffer_max = BufferMax,
Expand Down Expand Up @@ -2978,17 +2978,17 @@ drop_last(N, List) ->
end, {N, []}, List),
{N - ToDrop, List2}.

-spec get_buffer_max() -> pos_integer() | infinity.
get_buffer_max() ->
mod_stream_management:get_buffer_max(?STREAM_MGMT_CACHE_MAX).
-spec get_buffer_max(jid:lserver()) -> pos_integer() | infinity.
get_buffer_max(LServer) ->
mod_stream_management:get_buffer_max(LServer, ?STREAM_MGMT_CACHE_MAX).

-spec get_ack_freq() -> pos_integer().
get_ack_freq() ->
mod_stream_management:get_ack_freq(?STREAM_MGMT_ACK_FREQ).
-spec get_ack_freq(jid:lserver()) -> pos_integer().
get_ack_freq(LServer) ->
mod_stream_management:get_ack_freq(LServer, ?STREAM_MGMT_ACK_FREQ).

-spec get_resume_timeout() -> pos_integer().
get_resume_timeout() ->
mod_stream_management:get_resume_timeout(?STREAM_MGMT_RESUME_TIMEOUT).
-spec get_resume_timeout(jid:lserver()) -> pos_integer().
get_resume_timeout(LServer) ->
mod_stream_management:get_resume_timeout(LServer, ?STREAM_MGMT_RESUME_TIMEOUT).

maybe_send_ack_request(Acc, #state{stream_mgmt = StreamMgmt})
when StreamMgmt =:= false; StreamMgmt =:= disabled ->
Expand Down Expand Up @@ -3063,11 +3063,11 @@ maybe_enter_resume_session(_SMID, #state{} = SD) ->
end,
{next_state, resume_session, NSD, hibernate()}.

maybe_resume_session(NextState, El, StateData) ->
maybe_resume_session(NextState, El, StateData = #state{server = LServer}) ->
case {xml:get_tag_attr_s(<<"xmlns">>, El),
xml:get_tag_attr_s(<<"previd">>, El)} of
{?NS_STREAM_MGNT_3, SMID} ->
FromSMID = mod_stream_management:get_session_from_smid(SMID),
FromSMID = mod_stream_management:get_session_from_smid(LServer, SMID),
do_resume_session(SMID, El, FromSMID, StateData);
{InvalidNS, _} ->
?LOG_INFO(#{what => c2s_ignores_resume,
Expand Down
8 changes: 8 additions & 0 deletions src/gen_mod.erl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
get_module_opt_by_subhost/4,
set_module_opt_by_subhost/4,

loaded_modules/0,
loaded_modules/1,
loaded_modules_with_opts/1,
opts_for_module/2,
Expand Down Expand Up @@ -404,6 +405,13 @@ get_module_opt_subhost(Host, Module, Default) ->
Spec = get_module_opt(Host, Module, host, Default),
make_subhost(Spec, Host).

-spec loaded_modules() -> [module()].
loaded_modules() ->
ModSet = ets:foldl(fun(#ejabberd_module{module_host = {Mod, _}}, Set) ->
gb_sets:add_element(Mod, Set)
end, gb_sets:new(), ejabberd_modules),
gb_sets:to_list(ModSet).

-spec loaded_modules(jid:server()) -> [module()].
loaded_modules(Host) ->
ets:select(ejabberd_modules,
Expand Down
Loading

0 comments on commit b6c4fed

Please sign in to comment.