25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

mod_mam: more checks for database failure

This commit is contained in:
Evgeny Khramtsov 2019-01-02 21:11:22 +03:00
parent b318c70401
commit 9af70913b5

View File

@ -64,7 +64,7 @@
-callback store(xmlel(), binary(), {binary(), binary()}, chat | groupchat,
jid(), binary(), recv | send, integer()) -> ok | any().
-callback write_prefs(binary(), binary(), #archive_prefs{}, binary()) -> ok | any().
-callback get_prefs(binary(), binary()) -> {ok, #archive_prefs{}} | error.
-callback get_prefs(binary(), binary()) -> {ok, #archive_prefs{}} | error | {error, db_failure}.
-callback select(binary(), jid(), jid(), mam_query:result(),
#rsm_set{} | undefined, chat | groupchat) ->
{[{binary(), non_neg_integer(), xmlel()}], boolean(), count()} |
@ -599,25 +599,32 @@ process_iq(#iq{from = #jid{luser = LUser, lserver = LServer},
xmpp:make_error(IQ, xmpp:err_internal_server_error(Txt, Lang))
end;
process_iq(#iq{from = #jid{luser = LUser, lserver = LServer},
to = #jid{lserver = LServer},
to = #jid{lserver = LServer}, lang = Lang,
type = get, sub_els = [#mam_prefs{xmlns = NS}]} = IQ) ->
Prefs = get_prefs(LUser, LServer),
case get_prefs(LUser, LServer) of
{ok, Prefs} ->
PrefsEl = prefs_el(Prefs#archive_prefs.default,
Prefs#archive_prefs.always,
Prefs#archive_prefs.never,
NS),
xmpp:make_iq_result(IQ, PrefsEl);
{error, _} ->
Txt = <<"Database failure">>,
xmpp:make_error(IQ, xmpp:err_internal_server_error(Txt, Lang))
end;
process_iq(IQ) ->
xmpp:make_error(IQ, xmpp:err_not_allowed()).
process_iq(LServer, #iq{from = #jid{luser = LUser}, lang = Lang,
sub_els = [SubEl]} = IQ, MsgType) ->
case MsgType of
Ret = case MsgType of
chat ->
maybe_activate_mam(LUser, LServer);
{groupchat, _Role, _MUCState} ->
ok
end,
case Ret of
ok ->
case SubEl of
#mam_query{rsm = #rsm_set{index = I}} when is_integer(I) ->
Txt = <<"Unsupported <index/> element">>,
@ -630,6 +637,10 @@ process_iq(LServer, #iq{from = #jid{luser = LUser}, lang = Lang,
{error, Err} ->
xmpp:make_error(IQ, Err)
end
end;
{error, _} ->
Txt = <<"Database failure">>,
xmpp:make_error(IQ, xmpp:err_internal_server_error(Txt, Lang))
end.
-spec should_archive(message(), binary()) -> boolean().
@ -823,7 +834,8 @@ may_enter_room(From, MUCState) ->
-spec store_msg(message(), binary(), binary(), jid(), send | recv)
-> ok | pass | any().
store_msg(Pkt, LUser, LServer, Peer, Dir) ->
Prefs = get_prefs(LUser, LServer),
case get_prefs(LUser, LServer) of
{ok, Prefs} ->
case {should_archive_peer(LUser, LServer, Prefs, Peer), Pkt} of
{true, #message{meta = #{sm_copy := true}}} ->
ok; % Already stored.
@ -841,6 +853,9 @@ store_msg(Pkt, LUser, LServer, Peer, Dir) ->
end;
{false, _} ->
pass
end;
{error, _} ->
pass
end.
-spec store_muc(mod_muc_room:state(), message(), jid(), jid(), binary())
@ -895,18 +910,20 @@ get_prefs(LUser, LServer) ->
end,
case Res of
{ok, Prefs} ->
Prefs;
{ok, Prefs};
{error, _} ->
{error, db_failure};
error ->
ActivateOpt = gen_mod:get_module_opt(
LServer, ?MODULE,
request_activates_archiving),
case ActivateOpt of
true ->
#archive_prefs{us = {LUser, LServer}, default = never};
{ok, #archive_prefs{us = {LUser, LServer}, default = never}};
false ->
Default = gen_mod:get_module_opt(
LServer, ?MODULE, default),
#archive_prefs{us = {LUser, LServer}, default = Default}
{ok, #archive_prefs{us = {LUser, LServer}, default = Default}}
end
end.
@ -935,6 +952,8 @@ maybe_activate_mam(LUser, LServer) ->
case Res of
{ok, _Prefs} ->
ok;
{error, _} ->
{error, db_failure};
error ->
Default = gen_mod:get_module_opt(
LServer, ?MODULE, default),