Skip to content

Commit

Permalink
Merge pull request #3350 from esl/mod_inbox_remove_dynamic_modules
Browse files Browse the repository at this point in the history
Removing dynamically compiled module from mod_inbox
  • Loading branch information
chrzaszcz authored Oct 25, 2021
2 parents 8a7b507 + 2d74e87 commit 0fcced8
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 80 deletions.
77 changes: 5 additions & 72 deletions src/inbox/mod_inbox.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@
disco_local_features/1
]).

-define(MOD_INBOX_BACKEND, mod_inbox_backend).
-ignore_xref([
{?MOD_INBOX_BACKEND, get_inbox_unread, 2},
{?MOD_INBOX_BACKEND, get_inbox, 4},
{?MOD_INBOX_BACKEND, remove_domain, 2},
{?MOD_INBOX_BACKEND, init, 2},
behaviour_info/1, disco_local_features/1, filter_local_packet/1, get_personal_data/3,
inbox_unread_count/2, remove_domain/3, remove_user/3, user_send_packet/4
]).
Expand All @@ -61,67 +56,11 @@
archive => boolean()
}.

-export_type([entry_key/0, get_inbox_params/0]).

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

-callback get_inbox(HostType, LUser, LServer, Params) -> get_inbox_res() when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver(),
Params :: get_inbox_params().

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

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

-callback set_inbox(HostType, InboxEntryKey, Content, Count, MsgId, Timestamp) ->
inbox_write_res() when
HostType :: mongooseim:host_type(),
InboxEntryKey :: entry_key(),
Content :: binary(),
Count :: integer(),
MsgId :: binary(),
Timestamp :: integer().

-callback remove_inbox_row(HostType, InboxEntryKey) -> inbox_write_res() when
HostType :: mongooseim:host_type(),
InboxEntryKey :: entry_key().

-callback set_inbox_incr_unread(HostType, InboxEntryKey, Content, MsgId, Timestamp) ->
{ok, integer()} | ok when
HostType :: mongooseim:host_type(),
InboxEntryKey :: entry_key(),
Content :: binary(),
MsgId :: binary(),
Timestamp :: integer().

-callback reset_unread(HostType, InboxEntryKey, MsgId) -> inbox_write_res() when
HostType :: mongooseim:host_type(),
InboxEntryKey :: entry_key(),
MsgId :: binary().

-callback get_inbox_unread(HostType, InboxEntryKey) -> {ok, integer()} when
HostType :: mongooseim:host_type(),
InboxEntryKey :: entry_key().

-callback get_entry_properties(HostType, InboxEntryKey) -> Ret when
HostType :: mongooseim:host_type(),
InboxEntryKey :: entry_key(),
Ret :: entry_properties().

-callback set_entry_properties(HostType, InboxEntryKey, Params) -> Ret when
HostType :: mongooseim:host_type(),
InboxEntryKey :: entry_key(),
Params :: entry_properties(),
Ret :: entry_properties() | {error, binary()}.
-export_type([entry_key/0,
get_inbox_params/0,
get_inbox_res/0,
inbox_write_res/0,
entry_properties/0]).

%%--------------------------------------------------------------------
%% gdpr callbacks
Expand Down Expand Up @@ -159,7 +98,6 @@ start(HostType, Opts) ->
FullOpts = add_default_backend(Opts),
IQDisc = gen_mod:get_opt(iqdisc, FullOpts, no_queue),
MucTypes = gen_mod:get_opt(groupchat, FullOpts, [muclight]),
gen_mod:start_backend_module(?MODULE, FullOpts, callback_funs()),
mod_inbox_backend:init(HostType, FullOpts),
lists:member(muc, MucTypes) andalso mod_inbox_muc:start(HostType),
ejabberd_hooks:add(hooks(HostType)),
Expand Down Expand Up @@ -632,11 +570,6 @@ muc_dep(List) ->
false -> []
end.

callback_funs() ->
[get_inbox, set_inbox, set_inbox_incr_unread,
reset_unread, remove_inbox_row, clear_inbox, get_inbox_unread,
get_entry_properties, set_entry_properties, remove_domain].

-spec muclight_enabled(HostType :: mongooseim:host_type()) -> boolean().
muclight_enabled(HostType) ->
Groupchats = get_groupchat_types(HostType),
Expand Down
176 changes: 176 additions & 0 deletions src/inbox/mod_inbox_backend.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
%% Just a proxy interface module between the main mod_inbox module and
%% the backend modules (i.e. mod_inbox_rdbms).
-module(mod_inbox_backend).

-export([init/2,
get_inbox/4,
clear_inbox/3,
remove_domain/2,
set_inbox/6,
remove_inbox_row/2,
set_inbox_incr_unread/5,
get_inbox_unread/2,
get_entry_properties/2,
set_entry_properties/3,
reset_unread/3]).

-define(MAIN_MODULE, mod_inbox).

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

-callback get_inbox(HostType, LUser, LServer, Params) -> mod_inbox:get_inbox_res() when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver(),
Params :: mod_inbox:get_inbox_params().

-callback clear_inbox(HostType, LUser, LServer) -> mod_inbox:inbox_write_res() when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver().

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

-callback set_inbox(HostType, InboxEntryKey, Content, Count, MsgId, Timestamp) ->
mod_inbox:inbox_write_res() when
HostType :: mongooseim:host_type(),
InboxEntryKey :: mod_inbox:entry_key(),
Content :: binary(),
Count :: integer(),
MsgId :: binary(),
Timestamp :: integer().

-callback remove_inbox_row(HostType, InboxEntryKey) -> mod_inbox:inbox_write_res() when
HostType :: mongooseim:host_type(),
InboxEntryKey :: mod_inbox:entry_key().

-callback set_inbox_incr_unread(HostType, InboxEntryKey, Content, MsgId, Timestamp) ->
{ok, integer()} | ok when
HostType :: mongooseim:host_type(),
InboxEntryKey :: mod_inbox:entry_key(),
Content :: binary(),
MsgId :: binary(),
Timestamp :: integer().

-callback reset_unread(HostType, InboxEntryKey, MsgId) -> mod_inbox:inbox_write_res() when
HostType :: mongooseim:host_type(),
InboxEntryKey :: mod_inbox:entry_key(),
MsgId :: binary().

-callback get_inbox_unread(HostType, InboxEntryKey) -> {ok, integer()} when
HostType :: mongooseim:host_type(),
InboxEntryKey :: mod_inbox:entry_key().

-callback get_entry_properties(HostType, InboxEntryKey) -> Ret when
HostType :: mongooseim:host_type(),
InboxEntryKey :: mod_inbox:entry_key(),
Ret :: mod_inbox:entry_properties() | nil().

-callback set_entry_properties(HostType, InboxEntryKey, Params) -> Ret when
HostType :: mongooseim:host_type(),
InboxEntryKey :: mod_inbox:entry_key(),
Params :: mod_inbox:entry_properties(),
Ret :: mod_inbox:entry_properties() | {error, binary()}.

-spec init(HostType, Opts) -> ok when
HostType :: mongooseim:host_type(),
Opts :: list().
init(HostType, Opts) ->
mongoose_backend:init_per_host_type(HostType, ?MAIN_MODULE, callback_funs(), Opts),
Args = [HostType, Opts],
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec get_inbox(HostType, LUser, LServer, Params) -> mod_inbox:get_inbox_res() when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver(),
Params :: mod_inbox:get_inbox_params().
get_inbox(HostType, LUser, LServer, Params) ->
Args = [HostType, LUser, LServer, Params],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec clear_inbox(HostType, LUser, LServer) -> mod_inbox:inbox_write_res() when
HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver().
clear_inbox(HostType, LUser, LServer) ->
Args = [HostType, LUser, LServer],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

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

-spec set_inbox(HostType, InboxEntryKey, Content, Count, MsgId, Timestamp) ->
mod_inbox:inbox_write_res() when
HostType :: mongooseim:host_type(),
InboxEntryKey :: mod_inbox:entry_key(),
Content :: binary(),
Count :: integer(),
MsgId :: binary(),
Timestamp :: integer().
set_inbox(HostType, InboxEntryKey, Content, Count, MsgId, Timestamp) ->
Args = [HostType, InboxEntryKey, Content, Count, MsgId, Timestamp],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec remove_inbox_row(HostType, InboxEntryKey) -> mod_inbox:inbox_write_res() when
HostType :: mongooseim:host_type(),
InboxEntryKey :: mod_inbox:entry_key().
remove_inbox_row(HostType, InboxEntryKey) ->
Args = [HostType, InboxEntryKey],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec set_inbox_incr_unread(HostType, InboxEntryKey, Content, MsgId, Timestamp) ->
{ok, integer()} | ok when
HostType :: mongooseim:host_type(),
InboxEntryKey :: mod_inbox:entry_key(),
Content :: binary(),
MsgId :: binary(),
Timestamp :: integer().
set_inbox_incr_unread(HostType, InboxEntryKey, Content, MsgId, Timestamp) ->
Args = [HostType, InboxEntryKey, Content, MsgId, Timestamp],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec reset_unread(HostType, InboxEntryKey, MsgId) -> mod_inbox:inbox_write_res() when
HostType :: mongooseim:host_type(),
InboxEntryKey :: mod_inbox:entry_key(),
MsgId :: binary() | undefined.
reset_unread(HostType, InboxEntryKey, MsgId) ->
Args = [HostType, InboxEntryKey, MsgId],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec get_inbox_unread(HostType, InboxEntryKey) -> {ok, integer()} when
HostType :: mongooseim:host_type(),
InboxEntryKey :: mod_inbox:entry_key().
get_inbox_unread(HostType, InboxEntryKey) ->
Args = [HostType, InboxEntryKey],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec get_entry_properties(HostType, InboxEntryKey) -> Ret when
HostType :: mongooseim:host_type(),
InboxEntryKey :: mod_inbox:entry_key(),
Ret :: mod_inbox:entry_properties() | nil().
get_entry_properties(HostType, InboxEntryKey) ->
Args = [HostType, InboxEntryKey],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

-spec set_entry_properties(HostType, InboxEntryKey, Params) -> Ret when
HostType :: mongooseim:host_type(),
InboxEntryKey :: mod_inbox:entry_key(),
Params :: mod_inbox:entry_properties(),
Ret :: mod_inbox:entry_properties() | {error, binary()}.
set_entry_properties(HostType, InboxEntryKey, Params) ->
Args = [HostType, InboxEntryKey, Params],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

callback_funs() ->
[get_inbox, set_inbox, set_inbox_incr_unread,
reset_unread, remove_inbox_row, clear_inbox, get_inbox_unread,
get_entry_properties, set_entry_properties, remove_domain].
4 changes: 2 additions & 2 deletions src/inbox/mod_inbox_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
-include("mod_inbox.hrl").
-include("mongoose_logger.hrl").

-behaviour(mod_inbox).
-behaviour(mod_inbox_backend).

%% API
-export([get_inbox/4,
Expand Down Expand Up @@ -175,7 +175,7 @@ clear_inbox(HostType, LUser, LServer) ->

-spec get_entry_properties(HosType :: mongooseim:host_type(),
InboxEntryKey :: mod_inbox:entry_key()) ->
entry_properties().
entry_properties() | nil().
get_entry_properties(HostType, {LUser, LServer, RemBareJID}) ->
case execute_select_properties(HostType, LUser, LServer, RemBareJID) of
{selected, []} ->
Expand Down
6 changes: 0 additions & 6 deletions src/inbox/mod_inbox_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@
build_inbox_entry_key/2
]).

-define(MOD_INBOX_BACKEND, mod_inbox_backend).
-ignore_xref([
{?MOD_INBOX_BACKEND, clear_inbox, 3},
{?MOD_INBOX_BACKEND, reset_unread, 3},
{?MOD_INBOX_BACKEND, reset_unread, 3},
{?MOD_INBOX_BACKEND, set_inbox_incr_unread, 5},
{?MOD_INBOX_BACKEND, set_inbox, 6},
fill_from_attr/2, get_reset_markers/1, if_chat_marker_get_id/2
]).

Expand Down

0 comments on commit 0fcced8

Please sign in to comment.