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

Removing dynamically compiled module from mod_inbox #3350

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
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
177 changes: 177 additions & 0 deletions src/inbox/mod_inbox_backend.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
%% 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(Host, Opts) -> ok when
Host :: mongooseim:host_type(),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
-callback init(Host, Opts) -> ok when
Host :: mongooseim:host_type(),
-callback init(HostType, Opts) -> ok when
HostType :: mongooseim:host_type(),

Opts :: list().

-callback get_inbox(HostType, LUser, LServer, Params) -> mod_index:get_inbox_res() when
Copy link
Member

Choose a reason for hiding this comment

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

There are multiple occurrences of mod_index, please replace with mod_inbox

HostType :: mongooseim:host_type(),
LUser :: jid:luser(),
LServer :: jid:lserver(),
Params :: mod_inbox:get_inbox_params().

-callback clear_inbox(HostType, LUser, LServer) -> mod_index: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_index: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_index: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_index: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_index:entry_properties().

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

-spec init(Host, Opts) -> ok when
Host :: 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_index: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_index: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_index: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_index: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_index: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_index:entry_properties().
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_index:entry_properties(),
Ret :: mod_index:entry_properties() | {error, binary()}.
set_entry_properties(HostType, InboxEntryKey, Params) ->
Args = [HostType, InboxEntryKey, Params],
mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args).

JanuszJakubiec marked this conversation as resolved.
Show resolved Hide resolved
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].
2 changes: 1 addition & 1 deletion 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
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