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

Migrate mod_privacy to mongoose_backend #3347

Merged
merged 2 commits into from
Oct 20, 2021
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 rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
mod_mam_cassandra_prefs_params, mod_mam_muc_cassandra_arch_params,
mod_muc_db_backend, mod_muc_light_codec_backend,
mod_muc_light_db_backend, mod_offline_backend,
mod_offline_chatmarkers_backend, mod_privacy_backend,
mod_offline_chatmarkers_backend,
mod_pubsub_cache_backend,
mod_pubsub_db_backend, mod_revproxy_dynamic,
mod_roster_backend, mod_routing_machine,
Expand Down
2 changes: 1 addition & 1 deletion src/event_pusher/mod_event_pusher_push_backend.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
-spec init(Host :: jid:server(), Opts :: list()) -> ok.
init(Host, Opts) ->
TrackedFuns = [enable, disable, get_publish_services],
mongoose_backend:init_per_host_type(Host, ?MAIN_MODULE, TrackedFuns),
mongoose_backend:init_per_host_type(Host, ?MAIN_MODULE, TrackedFuns, Opts),
Args = [Host, Opts],
mongoose_backend:call(Host, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

Expand Down
91 changes: 0 additions & 91 deletions src/privacy/mod_privacy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,10 @@
-export([config_metrics/1]).

-ignore_xref([
{mod_privacy_backend, init, 2},
{mod_privacy_backend, get_default_list, 3},
{mod_privacy_backend, get_list_names, 3},
{mod_privacy_backend, get_privacy_list, 4},
{mod_privacy_backend, set_default_list, 4},
{mod_privacy_backend, forget_default_list, 3},
{mod_privacy_backend, remove_privacy_list, 4},
{mod_privacy_backend, replace_privacy_list, 5},
{mod_privacy_backend, remove_user, 3},
{mod_privacy_backend, remove_domain, 2},
behaviour_info/1, check_packet/5, get_user_list/3, process_iq_get/5,
process_iq_set/4, remove_user/3, updated_list/3,
remove_user/3, remove_domain/3, disco_local_features/1]).

-include("mongoose.hrl").
-include("jlib.hrl").
-include("mod_privacy.hrl").
-include("mongoose_config_spec.hrl").
Expand All @@ -76,91 +65,11 @@
-type list_item() :: #listitem{}.
-type privacy_item_type() :: none | jid | group | subscription.

%% ------------------------------------------------------------------
%% Backend callbacks
%% ------------------------------------------------------------------

-callback init(HostType, Opts) -> ok when
HostType :: mongooseim:host_type(),
Opts :: gen_mod:module_opts().

-callback remove_user(HostType, LUser, LServer) -> any() when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver().

-callback remove_domain(HostType, LServer) -> any() when
HostType :: mongooseim:host_type(),
LServer :: jid:lserver().

-callback get_list_names(HostType, LUser, LServer) ->
{ok, {Default, Names}} | {error, Reason} when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver(),
Default :: list_name(),
Names :: list(list_name()),
Reason :: not_found | term().

-callback get_privacy_list(HostType, LUser, LServer, Name) ->
{ok, Items} | {error, Reason} when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver(),
Name :: list_name(),
Items :: list(list_item()),
Reason :: not_found | term().

-callback set_default_list(HostType, LUser, LServer, Name) ->
ok | {error, Reason} when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver(),
Name :: list_name(),
Reason :: not_found | term().

-callback forget_default_list(HostType, LUser, LServer) ->
ok | {error, Reason} when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver(),
Reason :: not_found | term().

-callback remove_privacy_list(HostType, LUser, LServer, Name) ->
ok | {error, Reason} when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver(),
Name :: list_name(),
Reason :: conflict | term().

-callback replace_privacy_list(HostType, LUser, LServer, Name, Items) ->
ok | {error, Reason} when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver(),
Name :: list_name(),
Items :: list(list_item()),
Reason :: conflict | term().

-callback get_default_list(HostType, LUser, LServer) ->
{ok, {Default, Items}} | {error, Reason} when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver(),
Default :: list_name(),
Items :: list(list_item()),
Reason :: not_found | term().

%% ------------------------------------------------------------------
%% gen_mod callbacks
%% ------------------------------------------------------------------

start(HostType, Opts) ->
gen_mod:start_backend_module(?MODULE, Opts, [get_privacy_list, get_list_names,
set_default_list, forget_default_list,
remove_privacy_list, replace_privacy_list,
get_default_list]),
mod_privacy_backend:init(HostType, Opts),
ejabberd_hooks:add(hooks(HostType)).

Expand Down
171 changes: 171 additions & 0 deletions src/privacy/mod_privacy_backend.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
-module(mod_privacy_backend).

-define(MAIN_MODULE, mod_privacy).

-export([init/2,
get_default_list/3,
get_list_names/3,
get_privacy_list/4,
set_default_list/4,
forget_default_list/3,
remove_privacy_list/4,
replace_privacy_list/5,
remove_user/3,
remove_domain/2]).

%% ------------------------------------------------------------------
%% Backend callbacks
%% ------------------------------------------------------------------

-callback init(HostType, Opts) -> ok when
HostType :: mongooseim:host_type(),
Opts :: gen_mod:module_opts().

-callback remove_user(HostType, LUser, LServer) -> any() when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver().

-callback remove_domain(HostType, LServer) -> any() when
HostType :: mongooseim:host_type(),
LServer :: jid:lserver().

-callback get_list_names(HostType, LUser, LServer) ->
{ok, {Default, Names}} | {error, Reason} when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver(),
Default :: mod_privacy:list_name(),
Names :: [mod_privacy:list_name()],
Reason :: not_found | term().

-callback get_privacy_list(HostType, LUser, LServer, Name) ->
{ok, Items} | {error, Reason} when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver(),
Name :: mod_privacy:list_name(),
Items :: [mod_privacy:list_item()],
Reason :: not_found | term().

-callback set_default_list(HostType, LUser, LServer, Name) ->
ok | {error, Reason} when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver(),
Name :: mod_privacy:list_name(),
Reason :: not_found | term().

-callback forget_default_list(HostType, LUser, LServer) ->
ok | {error, Reason} when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver(),
Reason :: not_found | term().

-callback remove_privacy_list(HostType, LUser, LServer, Name) ->
ok | {error, Reason} when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver(),
Name :: mod_privacy:list_name(),
Reason :: conflict | term().

-callback replace_privacy_list(HostType, LUser, LServer, Name, Items) ->
ok | {error, Reason} when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver(),
Name :: mod_privacy:list_name(),
Items :: [mod_privacy:list_item()],
Reason :: conflict | term().

-callback get_default_list(HostType, LUser, LServer) ->
{ok, {Default, Items}} | {error, Reason} when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver(),
Default :: mod_privacy:list_name(),
Items :: [mod_privacy:list_item()],
Reason :: not_found | term().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line here, but can be fixed in other PR.

%% ------------------------------------------------------------------
%% Backend implementation
%% ------------------------------------------------------------------

-spec init(mongooseim:host_type(), gen_mod:module_opts()) -> ok.
init(HostType, Opts) ->
TrackedFuns = [get_privacy_list, get_list_names, set_default_list, forget_default_list,
remove_privacy_list, replace_privacy_list, get_default_list],
mongoose_backend:init_per_host_type(HostType, ?MAIN_MODULE, TrackedFuns, Opts),
Args = [HostType, Opts],
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

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

-spec remove_domain(mongooseim:host_type(), jid:lserver()) -> any().
remove_domain(HostType, LServer) ->
Args = [HostType, LServer],
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec get_list_names(mongooseim:host_type(), jid:luser(), jid:lserver()) ->
{ok, {Default, Names}} | {error, Reason} when
Default :: mod_privacy:list_name(),
Names :: [mod_privacy:list_name()],
Reason :: not_found | term().
get_list_names(HostType, LUser, LServer) ->
Args = [HostType, LUser, LServer],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec get_privacy_list(mongooseim:host_type(), jid:luser(), jid:lserver(), Name) ->
{ok, Items} | {error, Reason} when
Name :: mod_privacy:list_name(),
Items :: [mod_privacy:list_item()],
Reason :: not_found | term().
get_privacy_list(HostType, LUser, LServer, Name) ->
Args = [HostType, LUser, LServer, Name],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec set_default_list(mongooseim:host_type(), jid:luser(), jid:lserver(), Name) ->
ok | {error, Reason} when
Name :: mod_privacy:list_name(),
Reason :: not_found | term().
set_default_list(HostType, LUser, LServer, Name) ->
Args = [HostType, LUser, LServer, Name],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec forget_default_list(mongooseim:host_type(), jid:luser(), jid:lserver()) ->
ok | {error, Reason} when
Reason :: not_found | term().
forget_default_list(HostType, LUser, LServer) ->
Args = [HostType, LUser, LServer],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec remove_privacy_list(mongooseim:host_type(), jid:luser(), jid:lserver(), Name) ->
ok | {error, Reason} when
Name :: mod_privacy:list_name(),
Reason :: conflict | term().
remove_privacy_list(HostType, LUser, LServer, Name) ->
Args = [HostType, LUser, LServer, Name],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec replace_privacy_list(mongooseim:host_type(), jid:luser(), jid:lserver(), Name, Items) ->
ok | {error, Reason} when
Name :: mod_privacy:list_name(),
Items :: [mod_privacy:list_item()],
Reason :: conflict | term().
replace_privacy_list(HostType, LUser, LServer, Name, List) ->
Args = [HostType, LUser, LServer, Name, List],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec get_default_list(mongooseim:host_type(), jid:luser(), jid:lserver()) ->
{ok, {Default, Items}} | {error, Reason} when
Default :: mod_privacy:list_name(),
Items :: [mod_privacy:list_item()],
Reason :: not_found | term().
get_default_list(HostType, LUser, LServer) ->
Args = [HostType, LUser, LServer],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).
2 changes: 1 addition & 1 deletion src/privacy/mod_privacy_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
-module(mod_privacy_mnesia).
-author('alexey@process-one.net').
-author('arcusfelis@gmail.com').
-behaviour(mod_privacy).
-behaviour(mod_privacy_backend).

-export([init/2,
get_default_list/3,
Expand Down
2 changes: 1 addition & 1 deletion src/privacy/mod_privacy_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
-module(mod_privacy_rdbms).
-author('alexey@process-one.net').
-author('arcusfelis@gmail.com').
-behaviour(mod_privacy).
-behaviour(mod_privacy_backend).

-export([init/2,
get_default_list/3,
Expand Down
2 changes: 1 addition & 1 deletion src/privacy/mod_privacy_riak.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

-module(mod_privacy_riak).
-author('guillaume@bour.cc').
-behaviour(mod_privacy).
-behaviour(mod_privacy_backend).

-export([init/2,
get_default_list/3,
Expand Down