diff --git a/big_tests/tests/bosh_SUITE.erl b/big_tests/tests/bosh_SUITE.erl index 0f1a8989b6e..2c71018ff17 100644 --- a/big_tests/tests/bosh_SUITE.erl +++ b/big_tests/tests/bosh_SUITE.erl @@ -848,8 +848,8 @@ 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() -> @@ -857,14 +857,14 @@ 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) -> diff --git a/big_tests/tests/ejabberdctl_SUITE.erl b/big_tests/tests/ejabberdctl_SUITE.erl index fe5476fefbb..b240c989316 100644 --- a/big_tests/tests/ejabberdctl_SUITE.erl +++ b/big_tests/tests/ejabberdctl_SUITE.erl @@ -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) @@ -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) diff --git a/big_tests/tests/mod_global_distrib_SUITE.erl b/big_tests/tests/mod_global_distrib_SUITE.erl index 1300f79a86c..42b2b447ac6 100644 --- a/big_tests/tests/mod_global_distrib_SUITE.erl +++ b/big_tests/tests/mod_global_distrib_SUITE.erl @@ -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 ++ [ @@ -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()). @@ -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. diff --git a/big_tests/tests/sm_SUITE.erl b/big_tests/tests/sm_SUITE.erl index 4798e12466e..0eeb9031c63 100644 --- a/big_tests/tests/sm_SUITE.erl +++ b/big_tests/tests/sm_SUITE.erl @@ -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); @@ -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. @@ -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) -> @@ -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), @@ -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">>), @@ -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">>), @@ -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}). @@ -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}. diff --git a/src/ejabberd_admin.erl b/src/ejabberd_admin.erl index 1809f49f0a2..e99aa318e1d 100644 --- a/src/ejabberd_admin.erl +++ b/src/ejabberd_admin.erl @@ -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, @@ -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}], @@ -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 " @@ -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} -> @@ -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 diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index b7f26e85561..00c1ec1c0b2 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -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)} @@ -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, @@ -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 -> @@ -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, diff --git a/src/gen_mod.erl b/src/gen_mod.erl index fc63100a8a0..fae7a0590e5 100644 --- a/src/gen_mod.erl +++ b/src/gen_mod.erl @@ -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, @@ -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, diff --git a/src/mod_bosh.erl b/src/mod_bosh.erl index c5064c8b07a..63605d37547 100644 --- a/src/mod_bosh.erl +++ b/src/mod_bosh.erl @@ -12,12 +12,12 @@ -xep([{xep, 206}, {version, "1.4"}]). -xep([{xep, 124}, {version, "1.11"}]). %% API --export([get_inactivity/0, - set_inactivity/1, - get_max_wait/0, - set_max_wait/1, - get_server_acks/0, - set_server_acks/1]). +-export([get_inactivity/1, + set_inactivity/2, + get_max_wait/1, + set_max_wait/2, + get_server_acks/1, + set_server_acks/2]). %% gen_mod callbacks -export([start/2, @@ -96,40 +96,40 @@ %% API %%-------------------------------------------------------------------- --spec get_inactivity() -> pos_integer() | infinity. -get_inactivity() -> - gen_mod:get_module_opt(?MYNAME, ?MODULE, inactivity, ?DEFAULT_INACTIVITY). +-spec get_inactivity(jid:lserver()) -> pos_integer() | infinity. +get_inactivity(LServer) -> + gen_mod:get_module_opt(LServer, ?MODULE, inactivity, ?DEFAULT_INACTIVITY). %% @doc Return true if succeeded, false otherwise. --spec set_inactivity(Seconds :: pos_integer() | infinity) -> boolean(). -set_inactivity(infinity) -> - gen_mod:set_module_opt(?MYNAME, ?MODULE, inactivity, infinity); -set_inactivity(Seconds) when is_integer(Seconds), Seconds > 0 -> - gen_mod:set_module_opt(?MYNAME, ?MODULE, inactivity, Seconds). +-spec set_inactivity(jid:lserver(), Seconds :: pos_integer() | infinity) -> boolean(). +set_inactivity(LServer, infinity) -> + gen_mod:set_module_opt(LServer, ?MODULE, inactivity, infinity); +set_inactivity(LServer, Seconds) when is_integer(Seconds), Seconds > 0 -> + gen_mod:set_module_opt(LServer, ?MODULE, inactivity, Seconds). --spec get_max_wait() -> pos_integer() | infinity. -get_max_wait() -> - gen_mod:get_module_opt(?MYNAME, ?MODULE, max_wait, ?DEFAULT_MAX_WAIT). +-spec get_max_wait(jid:lserver()) -> pos_integer() | infinity. +get_max_wait(LServer) -> + gen_mod:get_module_opt(LServer, ?MODULE, max_wait, ?DEFAULT_MAX_WAIT). %% @doc Return true if succeeded, false otherwise. --spec set_max_wait(Seconds :: pos_integer() | infinity) -> boolean(). -set_max_wait(infinity) -> - gen_mod:set_module_opt(?MYNAME, ?MODULE, max_wait, infinity); -set_max_wait(Seconds) when is_integer(Seconds), Seconds > 0 -> - gen_mod:set_module_opt(?MYNAME, ?MODULE, max_wait, Seconds). +-spec set_max_wait(jid:lserver(), Seconds :: pos_integer() | infinity) -> boolean(). +set_max_wait(LServer, infinity) -> + gen_mod:set_module_opt(LServer, ?MODULE, max_wait, infinity); +set_max_wait(LServer, Seconds) when is_integer(Seconds), Seconds > 0 -> + gen_mod:set_module_opt(LServer, ?MODULE, max_wait, Seconds). --spec get_server_acks() -> boolean(). -get_server_acks() -> - gen_mod:get_module_opt(?MYNAME, ?MODULE, server_acks, ?DEFAULT_SERVER_ACKS). +-spec get_server_acks(jid:lserver()) -> boolean(). +get_server_acks(LServer) -> + gen_mod:get_module_opt(LServer, ?MODULE, server_acks, ?DEFAULT_SERVER_ACKS). --spec set_server_acks(EnableServerAcks :: boolean()) -> boolean(). -set_server_acks(EnableServerAcks) -> - gen_mod:set_module_opt(?MYNAME, ?MODULE, server_acks, EnableServerAcks). +-spec set_server_acks(jid:lserver(), EnableServerAcks :: boolean()) -> boolean(). +set_server_acks(LServer, EnableServerAcks) -> + gen_mod:set_module_opt(LServer, ?MODULE, server_acks, EnableServerAcks). %%-------------------------------------------------------------------- %% gen_mod callbacks @@ -361,15 +361,15 @@ maybe_start_session(Req, Body) -> Host = exml_query:attr(Body, <<"to">>), case is_known_host(Host) of true -> - maybe_start_session_on_known_host(Req, Body); + maybe_start_session_on_known_host(Host, Req, Body); false -> Req1 = terminal_condition(<<"host-unknown">>, Req), {false, Req1} end. -maybe_start_session_on_known_host(Req, Body) -> +maybe_start_session_on_known_host(Host, Req, Body) -> try - maybe_start_session_on_known_host_unsafe(Req, Body) + maybe_start_session_on_known_host_unsafe(Host, Req, Body) catch error:Reason -> %% It's here because something catch-y was here before @@ -379,13 +379,13 @@ maybe_start_session_on_known_host(Req, Body) -> {false, Req1} end. -maybe_start_session_on_known_host_unsafe(Req, Body) -> +maybe_start_session_on_known_host_unsafe(Host, Req, Body) -> %% Version isn't checked as it would be meaningless when supporting %% only a subset of the specification. {ok, NewBody} = set_max_hold(Body), Peer = cowboy_req:peer(Req), PeerCert = cowboy_req:cert(Req), - start_session(Peer, PeerCert, NewBody), + start_session(Host, Peer, PeerCert, NewBody), {true, Req}. %% @doc Is the argument locally served host? @@ -393,10 +393,11 @@ is_known_host(Host) -> Hosts = ejabberd_config:get_global_option(hosts), lists:member(Host, Hosts). --spec start_session(mongoose_transport:peer(), binary() | undefined, exml:element()) -> any(). -start_session(Peer, PeerCert, Body) -> +-spec start_session(jid:lserver(), mongoose_transport:peer(), + binary() | undefined, exml:element()) -> any(). +start_session(LServer, Peer, PeerCert, Body) -> Sid = make_sid(), - {ok, Socket} = mod_bosh_socket:start(Sid, Peer, PeerCert), + {ok, Socket} = mod_bosh_socket:start(LServer, Sid, Peer, PeerCert), store_session(Sid, Socket), handle_request(Socket, streamstart, Body), ?LOG_DEBUG(#{what => bosh_start_session, sid => Sid}). diff --git a/src/mod_bosh_socket.erl b/src/mod_bosh_socket.erl index 007971dd62b..6ee74232397 100644 --- a/src/mod_bosh_socket.erl +++ b/src/mod_bosh_socket.erl @@ -4,8 +4,8 @@ -behaviour(mongoose_transport). %% API --export([start/3, - start_link/3, +-export([start/4, + start_link/4, start_supervisor/0, handle_request/2, pause/2]). @@ -74,6 +74,7 @@ inactivity_tref :: reference() | 'undefined', %% Max pause period in seconds. maxpause :: pos_integer() | 'undefined', + max_wait :: pos_integer() | 'infinity', %% Are acknowledgements used? server_acks :: boolean(), last_processed :: rid() | 'undefined', @@ -89,18 +90,18 @@ %% API %%-------------------------------------------------------------------- --spec start(mod_bosh:sid(), mongoose_transport:peer(), binary() | undefined) -> +-spec start(jid:lserver(), mod_bosh:sid(), mongoose_transport:peer(), binary() | undefined) -> {'error', _} | {'ok', 'undefined' | pid()} | {'ok', 'undefined' | pid(), _}. -start(Sid, Peer, PeerCert) -> - supervisor:start_child(?BOSH_SOCKET_SUP, [Sid, Peer, PeerCert]). +start(LServer, Sid, Peer, PeerCert) -> + supervisor:start_child(?BOSH_SOCKET_SUP, [LServer, Sid, Peer, PeerCert]). --spec start_link(mod_bosh:sid(), mongoose_transport:peer(), binary() | undefined) -> +-spec start_link(jid:lserver(), mod_bosh:sid(), mongoose_transport:peer(), binary() | undefined) -> 'ignore' | {'error', _} | {'ok', pid()}. -start_link(Sid, Peer, PeerCert) -> - gen_fsm_compat:start_link(?MODULE, [Sid, Peer, PeerCert], []). - +start_link(LServer, Sid, Peer, PeerCert) -> + gen_fsm_compat:start_link(?MODULE, [LServer, Sid, Peer, PeerCert], []). +-spec start_supervisor() -> {ok, pid()} | {error, any()}. start_supervisor() -> ChildId = ?BOSH_SOCKET_SUP, ChildSpec = @@ -177,22 +178,23 @@ get_cached_responses(Pid) -> %% {stop, StopReason} %% @end %%-------------------------------------------------------------------- -init([Sid, Peer, PeerCert]) -> +init([LServer, Sid, Peer, PeerCert]) -> BoshSocket = #bosh_socket{sid = Sid, pid = self(), peer = Peer, peercert = PeerCert}, C2SOpts = [{xml_socket, true}], {ok, C2SPid} = ejabberd_c2s:start({mod_bosh_socket, BoshSocket}, C2SOpts), State = #state{sid = Sid, c2s_pid = C2SPid, - inactivity = mod_bosh:get_inactivity(), - maxpause = get_maxpause(), - server_acks = mod_bosh:get_server_acks()}, + inactivity = mod_bosh:get_inactivity(LServer), + maxpause = get_maxpause(LServer), + max_wait = mod_bosh:get_max_wait(LServer), + server_acks = mod_bosh:get_server_acks(LServer)}, ?LOG_DEBUG(ls(#{what => bosh_socket_init}, State)), {ok, accumulate, State}. %% TODO: maybe make maxpause runtime configurable like inactivity? -get_maxpause() -> - case gen_mod:get_module_opt(?MYNAME, mod_bosh, maxpause, undefined) of +get_maxpause(LServer) -> + case gen_mod:get_module_opt(LServer, mod_bosh, maxpause, undefined) of undefined -> ?DEFAULT_MAXPAUSE; MP -> MP end. @@ -822,7 +824,7 @@ return_surplus_handlers(SName, #state{pending = Pending} = S) -> {[jlib:xmlstreamel()], state()}. bosh_unwrap(StreamEvent, Body, #state{} = S) when StreamEvent =:= streamstart -> - Wait = min(get_attr(<<"wait">>, Body, S#state.wait), mod_bosh:get_max_wait()), + Wait = min(get_attr(<<"wait">>, Body, S#state.wait), S#state.max_wait), Hold = get_attr(<<"hold">>, Body, S#state.hold), ClientAcks = get_client_acks(StreamEvent, Body, S#state.client_acks, S), From = exml_query:attr(Body, <<"from">>), diff --git a/src/mod_extdisco.erl b/src/mod_extdisco.erl index 87f20b8b9ab..7d49c92fd54 100644 --- a/src/mod_extdisco.erl +++ b/src/mod_extdisco.erl @@ -67,19 +67,19 @@ service_config_spec() -> -spec process_iq(jid:jid(), jid:jid(), mongoose_acc:t(), jlib:iq()) -> {mongoose_acc:t(), jlib:iq()}. -process_iq(_From, _To, Acc, #iq{type = get, sub_el = SubEl} = IQ) -> +process_iq(_From, _To = #jid{lserver = LServer}, Acc, #iq{type = get, sub_el = SubEl} = IQ) -> {ResponseType, Response} = case request_type(SubEl) of all_services -> - RequestedServices = get_external_services(), + RequestedServices = get_external_services(LServer), {result, create_iq_response(RequestedServices)}; {credentials, {Type, Host}} -> - Services = get_external_services(Type), + Services = get_external_services(LServer, Type), RequestedServices = lists:filter(fun(Opts) -> gen_mod:get_opt(host, Opts, undefined) == binary_to_list(Host) end, Services), {result, create_iq_response_credentials(RequestedServices)}; {selected_services, Type} -> - RequestedServices = get_external_services(Type), + RequestedServices = get_external_services(LServer, Type), {result, create_iq_response_services(RequestedServices, Type)}; _ -> {error, [mongoose_xmpp_errors:bad_request()]} @@ -123,14 +123,14 @@ create_iq_response_credentials(Services) -> attrs = [{<<"xmlns">>, ?NS_EXTDISCO}], children = prepare_services_element(Services)}. -get_external_services() -> - case gen_mod:get_module_opts(?MYNAME, ?MODULE) of +get_external_services(LServer) -> + case gen_mod:get_module_opts(LServer, ?MODULE) of [] -> []; ServicesWithOpts -> ServicesWithOpts end. -get_external_services(Type) -> - [Opts || Opts <- get_external_services(), gen_mod:get_opt(type, Opts) == Type]. +get_external_services(LServer, Type) -> + [Opts || Opts <- get_external_services(LServer), gen_mod:get_opt(type, Opts) == Type]. prepare_services_element(Services) -> lists:reverse( diff --git a/src/mod_stream_management.erl b/src/mod_stream_management.erl index 50ffda4b078..ce7bc2b2f35 100644 --- a/src/mod_stream_management.erl +++ b/src/mod_stream_management.erl @@ -15,27 +15,27 @@ session_cleanup/5]). %% `mongooseim.toml' options (don't use outside of tests) --export([get_buffer_max/1, - set_buffer_max/1, - get_ack_freq/1, - set_ack_freq/1, - get_resume_timeout/1, - set_resume_timeout/1, - get_stale_h_repeat_after/1, - set_stale_h_repeat_after/1, - get_stale_h_geriatric/1, - set_stale_h_geriatric/1 +-export([get_buffer_max/2, + set_buffer_max/2, + get_ack_freq/2, + set_ack_freq/2, + get_resume_timeout/2, + set_resume_timeout/2, + get_stale_h_repeat_after/2, + set_stale_h_repeat_after/2, + get_stale_h_geriatric/2, + set_stale_h_geriatric/2 ]). %% API for `ejabberd_c2s' -export([ make_smid/0, - get_session_from_smid/1, + get_session_from_smid/2, get_sid/1, - get_stale_h/1, + get_stale_h/2, register_smid/2, - register_stale_smid_h/2, - remove_stale_smid_h/1 + register_stale_smid_h/3, + remove_stale_smid_h/2 ]). -type smid() :: base64:ascii_binary(). @@ -70,11 +70,7 @@ stop(Host) -> ejabberd_hooks:delete(sm_remove_connection_hook, Host, ?MODULE, remove_smid, 50), ejabberd_hooks:delete(c2s_stream_features, Host, ?MODULE, add_sm_feature, 50), ejabberd_hooks:delete(session_cleanup, Host, ?MODULE, session_cleanup, 50), - StaleOpts = gen_mod:get_module_opt(?MYNAME, ?MODULE, stale_h, []), - case proplists:get_value(enabled, StaleOpts, false) of - false -> ok; - true -> stream_management_stale_h:stop() - end. + ok. -spec config_spec() -> mongoose_config_spec:config_section(). config_spec() -> @@ -137,19 +133,16 @@ sm() -> Info :: undefined | [any()], Reason :: undefined | ejabberd_sm:close_reason(), Acc1 :: mongoose_acc:t(). -remove_smid(Acc, SID, _JID, _Info, _Reason) -> - do_remove_smid(Acc, SID). +remove_smid(Acc, SID, #jid{lserver = LServer}, _Info, _Reason) -> + do_remove_smid(Acc, LServer, SID). -spec session_cleanup(Acc :: map(), LUser :: jid:luser(), LServer :: jid:lserver(), LResource :: jid:lresource(), SID :: ejabberd_sm:sid()) -> any(). -session_cleanup(Acc, _LUser, _LServer, _LResource, SID) -> - do_remove_smid(Acc, SID). +session_cleanup(Acc, _LUser, LServer, _LResource, SID) -> + do_remove_smid(Acc, LServer, SID). --spec do_remove_smid(Acc, SID) -> Acc1 when - Acc :: mongoose_acc:t(), - SID :: ejabberd_sm:sid(), - Acc1 :: mongoose_acc:t(). -do_remove_smid(Acc, SID) -> +-spec do_remove_smid(mongoose_acc:t(), jid:lserver(), ejabberd_sm:sid()) -> mongoose_acc:t(). +do_remove_smid(Acc, LServer, SID) -> H = mongoose_acc:get(stream_mgmt, h, undefined, Acc), MaybeSMID = case mnesia:dirty_index_read(sm_session, SID, #sm_session.sid) of [] -> {error, smid_not_found}; @@ -157,7 +150,7 @@ do_remove_smid(Acc, SID) -> mnesia:dirty_delete(sm_session, SMID), case H of undefined -> ok; - _ -> register_stale_smid_h(SMID, H) + _ -> register_stale_smid_h(LServer, SMID, H) end, {ok, SMID} end, @@ -167,75 +160,75 @@ do_remove_smid(Acc, SID) -> %% `mongooseim.toml' options (don't use outside of tests) %% --spec get_buffer_max(pos_integer() | infinity | no_buffer) +-spec get_buffer_max(jid:lserver(), pos_integer() | infinity | no_buffer) -> pos_integer() | infinity | no_buffer. -get_buffer_max(Default) -> - gen_mod:get_module_opt(?MYNAME, ?MODULE, buffer_max, Default). +get_buffer_max(LServer, Default) -> + gen_mod:get_module_opt(LServer, ?MODULE, buffer_max, Default). %% Return true if succeeded, false otherwise. --spec set_buffer_max(pos_integer() | infinity | no_buffer | undefined) +-spec set_buffer_max(jid:lserver(), pos_integer() | infinity | no_buffer | undefined) -> boolean(). -set_buffer_max(undefined) -> - del_module_opt(?MYNAME, ?MODULE, buffer_max); -set_buffer_max(infinity) -> - set_module_opt(?MYNAME, ?MODULE, buffer_max, infinity); -set_buffer_max(no_buffer) -> - set_module_opt(?MYNAME, ?MODULE, buffer_max, no_buffer); -set_buffer_max(Seconds) when is_integer(Seconds), Seconds > 0 -> - set_module_opt(?MYNAME, ?MODULE, buffer_max, Seconds). - --spec get_ack_freq(pos_integer() | never) -> pos_integer() | never. -get_ack_freq(Default) -> - gen_mod:get_module_opt(?MYNAME, ?MODULE, ack_freq, Default). +set_buffer_max(LServer, undefined) -> + del_module_opt(LServer, ?MODULE, buffer_max); +set_buffer_max(LServer, infinity) -> + set_module_opt(LServer, ?MODULE, buffer_max, infinity); +set_buffer_max(LServer, no_buffer) -> + set_module_opt(LServer, ?MODULE, buffer_max, no_buffer); +set_buffer_max(LServer, Seconds) when is_integer(Seconds), Seconds > 0 -> + set_module_opt(LServer, ?MODULE, buffer_max, Seconds). + +-spec get_ack_freq(jid:lserver(), pos_integer() | never) -> pos_integer() | never. +get_ack_freq(LServer, Default) -> + gen_mod:get_module_opt(LServer, ?MODULE, ack_freq, Default). %% Return true if succeeded, false otherwise. --spec set_ack_freq(pos_integer() | never | undefined) -> boolean(). -set_ack_freq(undefined) -> - del_module_opt(?MYNAME, ?MODULE, ack_freq); -set_ack_freq(never) -> - set_module_opt(?MYNAME, ?MODULE, ack_freq, never); -set_ack_freq(Freq) when is_integer(Freq), Freq > 0 -> - set_module_opt(?MYNAME, ?MODULE, ack_freq, Freq). - --spec get_resume_timeout(pos_integer()) -> pos_integer(). -get_resume_timeout(Default) -> - gen_mod:get_module_opt(?MYNAME, ?MODULE, resume_timeout, Default). - --spec set_resume_timeout(pos_integer()) -> boolean(). -set_resume_timeout(ResumeTimeout) -> - set_module_opt(?MYNAME, ?MODULE, resume_timeout, ResumeTimeout). - - --spec get_stale_h_opt(Opt :: atom(), Def :: pos_integer()) -> pos_integer(). -get_stale_h_opt(Option, Default) -> - MaybeModOpts = gen_mod:get_module_opt(?MYNAME, ?MODULE, stale_h, []), +-spec set_ack_freq(jid:lserver(), pos_integer() | never | undefined) -> boolean(). +set_ack_freq(LServer, undefined) -> + del_module_opt(LServer, ?MODULE, ack_freq); +set_ack_freq(LServer, never) -> + set_module_opt(LServer, ?MODULE, ack_freq, never); +set_ack_freq(LServer, Freq) when is_integer(Freq), Freq > 0 -> + set_module_opt(LServer, ?MODULE, ack_freq, Freq). + +-spec get_resume_timeout(jid:lserver(), pos_integer()) -> pos_integer(). +get_resume_timeout(LServer, Default) -> + gen_mod:get_module_opt(LServer, ?MODULE, resume_timeout, Default). + +-spec set_resume_timeout(jid:lserver(), pos_integer()) -> boolean(). +set_resume_timeout(LServer, ResumeTimeout) -> + set_module_opt(LServer, ?MODULE, resume_timeout, ResumeTimeout). + + +-spec get_stale_h_opt(LServer :: jid:lserver(), Opt :: atom(), Def :: pos_integer()) -> pos_integer(). +get_stale_h_opt(LServer, Option, Default) -> + MaybeModOpts = gen_mod:get_module_opt(LServer, ?MODULE, stale_h, []), proplists:get_value(Option, MaybeModOpts, Default). --spec get_stale_h_repeat_after(pos_integer()) -> pos_integer(). -get_stale_h_repeat_after(Default) -> - get_stale_h_opt(stale_h_repeat_after, Default). +-spec get_stale_h_repeat_after(jid:lserver(), pos_integer()) -> pos_integer(). +get_stale_h_repeat_after(LServer, Default) -> + get_stale_h_opt(LServer, stale_h_repeat_after, Default). --spec get_stale_h_geriatric(pos_integer()) -> pos_integer(). -get_stale_h_geriatric(Default) -> - get_stale_h_opt(stale_h_geriatric, Default). +-spec get_stale_h_geriatric(jid:lserver(), pos_integer()) -> pos_integer(). +get_stale_h_geriatric(LServer, Default) -> + get_stale_h_opt(LServer, stale_h_geriatric, Default). --spec set_stale_h_opt(Option :: atom(), Value :: pos_integer()) -> boolean(). -set_stale_h_opt(Option, Value) -> - MaybeModOpts = gen_mod:get_module_opt(?MYNAME, ?MODULE, stale_h, []), +-spec set_stale_h_opt(LServer :: jid:lserver(), Option :: atom(), Value :: pos_integer()) -> boolean(). +set_stale_h_opt(LServer, Option, Value) -> + MaybeModOpts = gen_mod:get_module_opt(LServer, ?MODULE, stale_h, []), case MaybeModOpts of [] -> false; GCOpts -> NewGCOpts = lists:keystore(Option, 1, GCOpts, {Option, Value}), - set_module_opt(?MYNAME, ?MODULE, stale_h, NewGCOpts) + set_module_opt(LServer, ?MODULE, stale_h, NewGCOpts) end. --spec set_stale_h_repeat_after(pos_integer()) -> boolean(). -set_stale_h_repeat_after(ResumeTimeout) -> - set_stale_h_opt(stale_h_repeat_after, ResumeTimeout). +-spec set_stale_h_repeat_after(jid:lserver(), pos_integer()) -> boolean(). +set_stale_h_repeat_after(LServer, ResumeTimeout) -> + set_stale_h_opt(LServer, stale_h_repeat_after, ResumeTimeout). --spec set_stale_h_geriatric(pos_integer()) -> boolean(). -set_stale_h_geriatric(GeriatricAge) -> - set_stale_h_opt(stale_h_geriatric, GeriatricAge). +-spec set_stale_h_geriatric(jid:lserver(), pos_integer()) -> boolean(). +set_stale_h_geriatric(LServer, GeriatricAge) -> + set_stale_h_opt(LServer, stale_h_geriatric, GeriatricAge). %% %% API for `ejabberd_c2s' @@ -246,15 +239,15 @@ make_smid() -> base64:encode(crypto:strong_rand_bytes(21)). %% Getters --spec get_session_from_smid(SMID :: smid()) -> +-spec get_session_from_smid(jid:lserver(), smid()) -> {sid, ejabberd_sm:sid()} | {stale_h, non_neg_integer()} | {error, smid_not_found}. -get_session_from_smid(SMID) -> +get_session_from_smid(LServer, SMID) -> case get_sid(SMID) of {sid, SID} -> {sid, SID}; - {error, smid_not_found} -> get_stale_h(SMID) + {error, smid_not_found} -> get_stale_h(LServer, SMID) end. --spec get_sid(SMID :: smid()) -> +-spec get_sid(smid()) -> {sid, ejabberd_sm:sid()} | {error, smid_not_found}. get_sid(SMID) -> case mnesia:dirty_read(sm_session, SMID) of @@ -262,10 +255,10 @@ get_sid(SMID) -> [] -> {error, smid_not_found} end. --spec get_stale_h(SMID :: smid()) -> +-spec get_stale_h(LServer :: jid:lserver(), SMID :: smid()) -> {stale_h, non_neg_integer()} | {error, smid_not_found}. -get_stale_h(SMID) -> - MaybeModOpts = gen_mod:get_module_opt(?MYNAME, ?MODULE, stale_h, []), +get_stale_h(LServer, SMID) -> + MaybeModOpts = gen_mod:get_module_opt(LServer, ?MODULE, stale_h, []), case proplists:get_value(enabled, MaybeModOpts, false) of false -> {error, smid_not_found}; true -> stream_management_stale_h:read_stale_h(SMID) @@ -281,15 +274,15 @@ register_smid(SMID, SID) -> {error, Reason} end. -register_stale_smid_h(SMID, H) -> - MaybeModOpts = gen_mod:get_module_opt(?MYNAME, ?MODULE, stale_h, []), +register_stale_smid_h(LServer, SMID, H) -> + MaybeModOpts = gen_mod:get_module_opt(LServer, ?MODULE, stale_h, []), case proplists:get_value(enabled, MaybeModOpts, false) of false -> ok; true -> stream_management_stale_h:write_stale_h(SMID, H) end. -remove_stale_smid_h(SMID) -> - MaybeModOpts = gen_mod:get_module_opt(?MYNAME, ?MODULE, stale_h, []), +remove_stale_smid_h(LServer, SMID) -> + MaybeModOpts = gen_mod:get_module_opt(LServer, ?MODULE, stale_h, []), case proplists:get_value(enabled, MaybeModOpts, false) of false -> ok; true -> stream_management_stale_h:delete_stale_h(SMID) diff --git a/src/mod_vcard_ldap.erl b/src/mod_vcard_ldap.erl index fe713804fc5..95801550e39 100644 --- a/src/mod_vcard_ldap.erl +++ b/src/mod_vcard_ldap.erl @@ -414,7 +414,7 @@ make_user_item_if_exists(Username, Attrs, true -> RFields = lists:map(fun ({_, VCardName}) -> {VCardName, map_vcard_attr(VCardName, Attrs, VCardMap, - {Username, ?MYNAME})} + {Username, LServer})} end, SearchReported), Result = [?FIELD(<<"jid">>, <>)] ++ diff --git a/src/mongoose_cluster_id.erl b/src/mongoose_cluster_id.erl index a6712110c7c..ddddd6c3779 100644 --- a/src/mongoose_cluster_id.erl +++ b/src/mongoose_cluster_id.erl @@ -84,7 +84,7 @@ make_cluster_id() -> %% Which backend is enabled -spec which_backend_available() -> mongoose_backend(). which_backend_available() -> - case mongoose_rdbms:db_engine(<<>>) of + case mongoose_wpool:get_pool_settings(rdbms, global, default) of undefined -> mnesia; _ -> rdbms end. @@ -99,7 +99,7 @@ set_new_cluster_id(ID, rdbms) -> SQLQuery = [<<"INSERT INTO mongoose_cluster_id(k,v) " "VALUES ('cluster_id',">>, mongoose_rdbms:use_escaped(mongoose_rdbms:escape_string(ID)), ");"], - try mongoose_rdbms:sql_query(?MYNAME, SQLQuery) of + try mongoose_rdbms:sql_query(global, SQLQuery) of {updated, 1} -> {ok, ID}; {error, _} = Err -> Err catch @@ -123,7 +123,7 @@ set_new_cluster_id(ID, mnesia) -> -spec get_backend_cluster_id(mongoose_backend()) -> maybe_cluster_id(). get_backend_cluster_id(rdbms) -> SQLQuery = [<<"SELECT v FROM mongoose_cluster_id WHERE k='cluster_id'">>], - try mongoose_rdbms:sql_query(?MYNAME, SQLQuery) of + try mongoose_rdbms:sql_query(global, SQLQuery) of {selected, [{Row}]} -> {ok, Row}; {selected, []} -> {error, no_value_in_backend}; {error, _} = Err -> Err @@ -144,7 +144,7 @@ clean_table() -> -spec clean_table(mongoose_backend()) -> ok | {error, any()}. clean_table(rdbms) -> SQLQuery = [<<"TRUNCATE TABLE mongoose_cluster_id;">>], - try mongoose_rdbms:sql_query(?MYNAME, SQLQuery) of + try mongoose_rdbms:sql_query(global, SQLQuery) of {selected, _} -> ok; {updated, _} -> ok; {error, _} = Err -> Err diff --git a/src/rdbms/mongoose_rdbms.erl b/src/rdbms/mongoose_rdbms.erl index 0d178b81cfe..0123488d072 100644 --- a/src/rdbms/mongoose_rdbms.erl +++ b/src/rdbms/mongoose_rdbms.erl @@ -530,7 +530,7 @@ init(Opts) -> handle_call({sql_cmd, Command, Timestamp}, From, State) -> run_sql_cmd(Command, From, State, Timestamp); handle_call(get_db_info, _, #state{db_ref = DbRef} = State) -> - {reply, {ok, db_engine(?MYNAME), DbRef}, State}; + {reply, {ok, db_engine(global), DbRef}, State}; handle_call(Request, From, State) -> ?UNEXPECTED_CALL(Request, From), {reply, {error, badarg}, State}. diff --git a/src/stream_management/stream_management_stale_h.erl b/src/stream_management/stream_management_stale_h.erl index 1de838d9516..fb7e7714a72 100644 --- a/src/stream_management/stream_management_stale_h.erl +++ b/src/stream_management/stream_management_stale_h.erl @@ -21,9 +21,7 @@ clear_table/1 ]). --export([maybe_start/1, - stop/0 - ]). +-export([maybe_start/1]). %% Internal exports -export([start_link/1]). @@ -88,9 +86,6 @@ start_cleaner(Opts) -> permanent, 5000, worker, [?MODULE]}, ejabberd_sup:start_child(ChildSpec). -stop() -> - ok. - start_link(Opts) -> gen_server:start_link({local, ?MODULE}, ?MODULE, [Opts], []).