Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mod roster remove dynamic modules #3364

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion big_tests/tests/metrics_roster_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,4 @@ mongoose_metrics(ConfigIn, Metrics) ->
[{mongoose_metrics, MongooseMetrics} | ConfigIn].

roster_rdbms_precondition() ->
mod_roster_rdbms == rpc(mim(), mod_roster_backend, backend, []).
mod_roster_rdbms == rpc(mim(), mongoose_backend, get_backend_name, [domain_helper:host_type(), mod_roster]).
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
mod_mam_cassandra_arch_params,
mod_mam_cassandra_prefs_params, mod_mam_muc_cassandra_arch_params,
mod_pubsub_db_backend, mod_revproxy_dynamic,
mod_roster_backend, mod_routing_machine,
mod_routing_machine,
mod_shared_roster, mongoose_rdbms_type,
%% Deprecated functions
{crypto, rand_uniform, 2},
Expand Down
55 changes: 0 additions & 55 deletions src/mod_roster.erl
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,7 @@

-export([config_metrics/1]).

-define(MOD_ROSTER_BACKEND, mod_roster_backend).
-ignore_xref([
{?MOD_ROSTER_BACKEND, del_roster_t, 4},
{?MOD_ROSTER_BACKEND, get_roster, 3},
{?MOD_ROSTER_BACKEND, get_roster_entry, 6},
{?MOD_ROSTER_BACKEND, get_subscription_lists, 3},
{?MOD_ROSTER_BACKEND, read_roster_version, 3},
{?MOD_ROSTER_BACKEND, remove_user_t, 3},
{?MOD_ROSTER_BACKEND, remove_domain_t, 2},
{?MOD_ROSTER_BACKEND, roster_subscribe_t, 2},
{?MOD_ROSTER_BACKEND, init, 2},
{?MOD_ROSTER_BACKEND, transaction, 2},
{?MOD_ROSTER_BACKEND, update_roster_t, 2},
{?MOD_ROSTER_BACKEND, write_roster_version, 5},
behaviour_info/1, get_jid_info/4, get_personal_data/3, get_subscription_lists/2,
get_user_roster/2, get_user_rosters_length/2, get_versioning_feature/2,
in_subscription/5, item_to_xml/1, out_subscription/4, process_subscription_t/6,
Expand Down Expand Up @@ -116,39 +103,6 @@

-export_type([contact/0, transaction_state/0, entry_format/0, version/0]).

%% Backend API

-callback init(mongooseim:host_type(), list()) -> ok.

-callback transaction(mongooseim:host_type(), fun(() -> any())) ->
{aborted, any()} | {atomic, any()} | {error, any()}.

-callback read_roster_version(mongooseim:host_type(), jid:luser(), jid:lserver()) ->
binary() | error.

-callback write_roster_version(mongooseim:host_type(), jid:luser(), jid:lserver(),
transaction_state(), version()) -> ok.

-callback get_roster(mongooseim:host_type(), jid:luser(), jid:lserver()) -> [roster()].

-callback get_roster_entry(mongooseim:host_type(), jid:luser(), jid:lserver(), contact(),
transaction_state(), entry_format()) ->
roster() | does_not_exist | error.

-callback get_subscription_lists(mongoose_acc:t(), jid:luser(), jid:lserver()) -> [roster()].

-callback roster_subscribe_t(mongooseim:host_type(), roster()) -> ok.

-callback update_roster_t(mongooseim:host_type(), roster()) -> ok.

-callback del_roster_t(mongooseim:host_type(), jid:luser(), jid:lserver(), contact()) -> ok.

-callback remove_user_t(mongooseim:host_type(), jid:luser(), jid:lserver()) -> ok.

-callback remove_domain_t(mongooseim:host_type(), jid:lserver()) -> ok.

-optional_callbacks([remove_domain_t/2]).

%%--------------------------------------------------------------------
%% gdpr callback
%%--------------------------------------------------------------------
Expand Down Expand Up @@ -182,15 +136,6 @@ roster_record_to_gdpr_entry(#roster{ jid = JID, name = Name,
-spec start(mongooseim:host_type(), list()) -> any().
start(HostType, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
TrackedFuns = [read_roster_version,
write_roster_version,
get_roster,
get_roster_entry,
get_subscription_lists,
roster_subscribe_t,
update_roster_t,
del_roster_t],
gen_mod:start_backend_module(?MODULE, Opts, TrackedFuns),
mod_roster_backend:init(HostType, Opts),
ejabberd_hooks:add(hooks(HostType)),
gen_iq_handler:add_iq_handler_for_domain(HostType, ?NS_ROSTER, ejabberd_sm,
Expand Down
132 changes: 132 additions & 0 deletions src/mod_roster_backend.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
%% Just a proxy interface module between the main mod_roster module and
%% the backend modules (i.e. mod_roster_rdbms, mod_roster_mnesia...).
-module(mod_roster_backend).
-export([init/2,
transaction/2,
read_roster_version/3,
write_roster_version/5,
get_roster/3,
get_roster_entry/6,
get_subscription_lists/3,
roster_subscribe_t/2,
update_roster_t/2,
del_roster_t/4,
remove_user_t/3,
remove_domain_t/2]).

-define(MAIN_MODULE, mod_roster).

%% ----------------------------------------------------------------------
%% Callbacks
%% (exactly the same as specs in this module)

-callback init(mongooseim:host_type(), list()) -> ok.

-callback transaction(mongooseim:host_type(), fun(() -> any())) ->
{aborted, any()} | {atomic, any()} | {error, any()}.

-callback read_roster_version(mongooseim:host_type(), jid:luser(), jid:lserver()) ->
binary() | error.

-callback write_roster_version(mongooseim:host_type(), jid:luser(), jid:lserver(),
mod_roster:transaction_state(), mod_roster:version()) -> ok.

-callback get_roster(mongooseim:host_type(), jid:luser(), jid:lserver()) -> [mod_roster:roster()].

-callback get_roster_entry(mongooseim:host_type(), jid:luser(), jid:lserver(), mod_roster:contact(),
mod_roster:transaction_state(), mod_roster:entry_format()) ->
mod_roster:roster() | does_not_exist | error.

-callback get_subscription_lists(mongoose_acc:t(), jid:luser(), jid:lserver()) -> [mod_roster:roster()].

-callback roster_subscribe_t(mongooseim:host_type(), mod_roster:roster()) -> ok.

-callback update_roster_t(mongooseim:host_type(), mod_roster:roster()) -> ok.

-callback del_roster_t(mongooseim:host_type(), jid:luser(), jid:lserver(), mod_roster:contact()) -> ok.

-callback remove_user_t(mongooseim:host_type(), jid:luser(), jid:lserver()) -> ok.

-callback remove_domain_t(mongooseim:host_type(), jid:lserver()) -> ok.

-optional_callbacks([remove_domain_t/2]).

-spec init(mongooseim:host_type(), list()) -> ok.
init(HostType, Opts) ->
TrackedFuns = [read_roster_version,
write_roster_version,
get_roster,
get_roster_entry,
get_subscription_lists,
roster_subscribe_t,
update_roster_t,
del_roster_t],
mongoose_backend:init_per_host_type(HostType, ?MAIN_MODULE, TrackedFuns, Opts),
Args = [HostType, Opts],
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec transaction(mongooseim:host_type(), fun(() -> any())) ->
{aborted, any()} | {atomic, any()} | {error, any()}.
transaction(HostType, F) ->
Args = [HostType, F],
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).


-spec read_roster_version(mongooseim:host_type(), jid:luser(), jid:lserver()) ->
binary() | error.
read_roster_version(HostType, LUser, LServer) ->
Args = [HostType, LUser, LServer],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec write_roster_version(mongooseim:host_type(), jid:luser(), jid:lserver(),
mod_roster:transaction_state(), mod_roster:version()) -> ok.
write_roster_version(HostType, LUser, LServer, TransactionState, Ver) ->
Args = [HostType, LUser, LServer, TransactionState, Ver],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec get_roster(mongooseim:host_type(), jid:luser(), jid:lserver()) -> [mod_roster:roster()].
get_roster(HostType, LUser, LServer) ->
Args = [HostType, LUser, LServer],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec get_roster_entry(mongooseim:host_type(), jid:luser(), jid:lserver(), mod_roster:contact(),
mod_roster:transaction_state(), mod_roster:entry_format()) ->
mod_roster:roster() | does_not_exist | error.
get_roster_entry(HostType, LUser, LServer, LJid, TransactionState, Format) ->
Args = [HostType, LUser, LServer, LJid, TransactionState, Format],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec get_subscription_lists(mongoose_acc:t(), jid:luser(), jid:lserver()) -> [mod_roster:roster()].
get_subscription_lists(Acc, LUser, LServer) ->
Args = [Acc, LUser, LServer],
mongoose_backend:call_tracked(mongoose_acc:host_type(Acc), ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec roster_subscribe_t(mongooseim:host_type(), mod_roster:roster()) -> ok.
roster_subscribe_t(HostType, Roster) ->
Args = [HostType, Roster],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec update_roster_t(mongooseim:host_type(), mod_roster:roster()) -> ok.
update_roster_t(HostType, Roster) ->
Args = [HostType, Roster],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec del_roster_t(mongooseim:host_type(), jid:luser(), jid:lserver(), mod_roster:contact()) -> ok.
del_roster_t(HostType, LUser, LServer, LJid) ->
Args = [HostType, LUser, LServer, LJid],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec remove_user_t(mongooseim:host_type(), jid:luser(), jid:lserver()) -> ok.
remove_user_t(HostType, LUser, LServer) ->
Args = [HostType, LUser, LServer],
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec remove_domain_t(mongooseim:host_type(), jid:lserver()) -> ok.
remove_domain_t(HostType, LServer) ->
Args = [HostType, LServer],
case mongoose_backend:is_exported(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, 2) of
true ->
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args);
false ->
ok
end.
2 changes: 1 addition & 1 deletion src/mod_roster_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
-include("mod_roster.hrl").
-include("jlib.hrl").

-behaviour(mod_roster).
-behaviour(mod_roster_backend).

%% API
-export([init/2,
Expand Down
2 changes: 1 addition & 1 deletion src/mod_roster_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
-include("mongoose.hrl").
-include("mongoose_logger.hrl").

-behaviour(mod_roster).
-behaviour(mod_roster_backend).

%% API
-export([init/2,
Expand Down
2 changes: 1 addition & 1 deletion src/mod_roster_riak.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
-include("jlib.hrl").
-include("mongoose.hrl").

-behaviour(mod_roster).
-behaviour(mod_roster_backend).

%% API
-export([init/2,
Expand Down