2016-04-15 14:11:31 +02:00
|
|
|
%%%-------------------------------------------------------------------
|
2016-12-27 10:44:07 +01:00
|
|
|
%%% File : mod_mam_sql.erl
|
|
|
|
%%% Author : Evgeny Khramtsov <ekhramtsov@process-one.net>
|
2016-04-15 14:11:31 +02:00
|
|
|
%%% Created : 15 Apr 2016 by Evgeny Khramtsov <ekhramtsov@process-one.net>
|
2016-12-27 10:44:07 +01:00
|
|
|
%%%
|
|
|
|
%%%
|
2017-01-02 21:41:53 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2017 ProcessOne
|
2016-12-27 10:44:07 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
|
|
|
%%%
|
|
|
|
%%% You should have received a copy of the GNU General Public License along
|
|
|
|
%%% with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
%%%
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
2016-04-15 14:11:31 +02:00
|
|
|
-module(mod_mam_sql).
|
|
|
|
|
2016-05-04 20:01:05 +02:00
|
|
|
-compile([{parse_transform, ejabberd_sql_pt}]).
|
|
|
|
|
2016-04-15 14:11:31 +02:00
|
|
|
-behaviour(mod_mam).
|
|
|
|
|
|
|
|
%% API
|
|
|
|
-export([init/2, remove_user/2, remove_room/3, delete_old_messages/3,
|
2017-05-07 14:58:11 +02:00
|
|
|
extended_fields/0, store/7, write_prefs/4, get_prefs/2, select/6, export/1]).
|
2016-04-15 14:11:31 +02:00
|
|
|
|
|
|
|
-include_lib("stdlib/include/ms_transform.hrl").
|
2016-07-25 12:50:30 +02:00
|
|
|
-include("xmpp.hrl").
|
2016-04-15 14:11:31 +02:00
|
|
|
-include("mod_mam.hrl").
|
|
|
|
-include("logger.hrl").
|
2016-05-04 20:01:05 +02:00
|
|
|
-include("ejabberd_sql_pt.hrl").
|
2016-04-15 14:11:31 +02:00
|
|
|
|
|
|
|
%%%===================================================================
|
|
|
|
%%% API
|
|
|
|
%%%===================================================================
|
|
|
|
init(_Host, _Opts) ->
|
|
|
|
ok.
|
|
|
|
|
|
|
|
remove_user(LUser, LServer) ->
|
2016-04-20 11:27:32 +02:00
|
|
|
ejabberd_sql:sql_query(
|
2016-04-15 14:11:31 +02:00
|
|
|
LServer,
|
2016-05-04 20:01:05 +02:00
|
|
|
?SQL("delete from archive where username=%(LUser)s")),
|
2016-04-20 11:27:32 +02:00
|
|
|
ejabberd_sql:sql_query(
|
2016-04-15 14:11:31 +02:00
|
|
|
LServer,
|
2016-05-04 20:01:05 +02:00
|
|
|
?SQL("delete from archive_prefs where username=%(LUser)s")).
|
2016-04-15 14:11:31 +02:00
|
|
|
|
|
|
|
remove_room(LServer, LName, LHost) ->
|
2017-02-26 08:07:12 +01:00
|
|
|
LUser = jid:encode({LName, LHost, <<>>}),
|
2016-04-15 14:11:31 +02:00
|
|
|
remove_user(LUser, LServer).
|
|
|
|
|
|
|
|
delete_old_messages(ServerHost, TimeStamp, Type) ->
|
|
|
|
TypeClause = if Type == all -> <<"">>;
|
2017-04-11 12:13:58 +02:00
|
|
|
true -> [<<" and kind='">>, misc:atom_to_binary(Type), <<"'">>]
|
2016-04-15 14:11:31 +02:00
|
|
|
end,
|
|
|
|
TS = integer_to_binary(now_to_usec(TimeStamp)),
|
2016-04-20 11:27:32 +02:00
|
|
|
ejabberd_sql:sql_query(
|
2016-04-15 14:11:31 +02:00
|
|
|
ServerHost, [<<"delete from archive where timestamp<">>,
|
|
|
|
TS, TypeClause, <<";">>]),
|
|
|
|
ok.
|
|
|
|
|
|
|
|
extended_fields() ->
|
2016-11-18 11:38:08 +01:00
|
|
|
[{withtext, <<"">>}].
|
2016-04-15 14:11:31 +02:00
|
|
|
|
|
|
|
store(Pkt, LServer, {LUser, LHost}, Type, Peer, Nick, _Dir) ->
|
|
|
|
TSinteger = p1_time_compat:system_time(micro_seconds),
|
2016-09-24 22:34:28 +02:00
|
|
|
ID = integer_to_binary(TSinteger),
|
2016-04-15 14:11:31 +02:00
|
|
|
SUser = case Type of
|
|
|
|
chat -> LUser;
|
2017-02-26 08:07:12 +01:00
|
|
|
groupchat -> jid:encode({LUser, LHost, <<>>})
|
2016-04-15 14:11:31 +02:00
|
|
|
end,
|
2017-02-26 08:07:12 +01:00
|
|
|
BarePeer = jid:encode(
|
2016-04-15 14:11:31 +02:00
|
|
|
jid:tolower(
|
|
|
|
jid:remove_resource(Peer))),
|
2017-02-26 08:07:12 +01:00
|
|
|
LPeer = jid:encode(
|
2016-04-15 14:11:31 +02:00
|
|
|
jid:tolower(Peer)),
|
|
|
|
XML = fxml:element_to_binary(Pkt),
|
|
|
|
Body = fxml:get_subtag_cdata(Pkt, <<"body">>),
|
2017-04-11 12:13:58 +02:00
|
|
|
SType = misc:atom_to_binary(Type),
|
2016-04-20 11:27:32 +02:00
|
|
|
case ejabberd_sql:sql_query(
|
2016-05-04 20:01:05 +02:00
|
|
|
LServer,
|
|
|
|
?SQL("insert into archive (username, timestamp,"
|
|
|
|
" peer, bare_peer, xml, txt, kind, nick) values ("
|
|
|
|
"%(SUser)s, "
|
|
|
|
"%(TSinteger)d, "
|
|
|
|
"%(LPeer)s, "
|
|
|
|
"%(BarePeer)s, "
|
|
|
|
"%(XML)s, "
|
|
|
|
"%(Body)s, "
|
|
|
|
"%(SType)s, "
|
|
|
|
"%(Nick)s)")) of
|
2016-04-15 14:11:31 +02:00
|
|
|
{updated, _} ->
|
|
|
|
{ok, ID};
|
|
|
|
Err ->
|
|
|
|
Err
|
|
|
|
end.
|
|
|
|
|
|
|
|
write_prefs(LUser, _LServer, #archive_prefs{default = Default,
|
|
|
|
never = Never,
|
|
|
|
always = Always},
|
|
|
|
ServerHost) ->
|
|
|
|
SDefault = erlang:atom_to_binary(Default, utf8),
|
2017-04-11 12:13:58 +02:00
|
|
|
SAlways = misc:term_to_expr(Always),
|
|
|
|
SNever = misc:term_to_expr(Never),
|
2016-05-24 17:44:07 +02:00
|
|
|
case ?SQL_UPSERT(
|
|
|
|
ServerHost,
|
|
|
|
"archive_prefs",
|
|
|
|
["!username=%(LUser)s",
|
|
|
|
"def=%(SDefault)s",
|
|
|
|
"always=%(SAlways)s",
|
|
|
|
"never=%(SNever)s"]) of
|
2017-05-18 11:10:36 +02:00
|
|
|
ok ->
|
2016-04-15 14:11:31 +02:00
|
|
|
ok;
|
|
|
|
Err ->
|
|
|
|
Err
|
|
|
|
end.
|
|
|
|
|
|
|
|
get_prefs(LUser, LServer) ->
|
2016-04-20 11:27:32 +02:00
|
|
|
case ejabberd_sql:sql_query(
|
2016-04-15 14:11:31 +02:00
|
|
|
LServer,
|
2016-05-24 17:44:07 +02:00
|
|
|
?SQL("select @(def)s, @(always)s, @(never)s from archive_prefs"
|
|
|
|
" where username=%(LUser)s")) of
|
|
|
|
{selected, [{SDefault, SAlways, SNever}]} ->
|
2016-04-15 14:11:31 +02:00
|
|
|
Default = erlang:binary_to_existing_atom(SDefault, utf8),
|
2016-04-20 11:27:32 +02:00
|
|
|
Always = ejabberd_sql:decode_term(SAlways),
|
|
|
|
Never = ejabberd_sql:decode_term(SNever),
|
2016-04-15 14:11:31 +02:00
|
|
|
{ok, #archive_prefs{us = {LUser, LServer},
|
|
|
|
default = Default,
|
|
|
|
always = Always,
|
|
|
|
never = Never}};
|
|
|
|
_ ->
|
|
|
|
error
|
|
|
|
end.
|
|
|
|
|
|
|
|
select(LServer, JidRequestor, #jid{luser = LUser} = JidArchive,
|
2016-11-18 11:38:08 +01:00
|
|
|
MAMQuery, RSM, MsgType) ->
|
2016-04-15 14:11:31 +02:00
|
|
|
User = case MsgType of
|
|
|
|
chat -> LUser;
|
2017-02-26 08:07:12 +01:00
|
|
|
{groupchat, _Role, _MUCState} -> jid:encode(JidArchive)
|
2016-04-15 14:11:31 +02:00
|
|
|
end,
|
2016-11-18 11:38:08 +01:00
|
|
|
{Query, CountQuery} = make_sql_query(User, LServer, MAMQuery, RSM),
|
2016-04-15 14:11:31 +02:00
|
|
|
% TODO from XEP-0313 v0.2: "To conserve resources, a server MAY place a
|
|
|
|
% reasonable limit on how many stanzas may be pushed to a client in one
|
|
|
|
% request. If a query returns a number of stanzas greater than this limit
|
|
|
|
% and the client did not specify a limit using RSM then the server should
|
|
|
|
% return a policy-violation error to the client." We currently don't do this
|
|
|
|
% for v0.2 requests, but we do limit #rsm_in.max for v0.3 and newer.
|
2016-04-20 11:27:32 +02:00
|
|
|
case {ejabberd_sql:sql_query(LServer, Query),
|
|
|
|
ejabberd_sql:sql_query(LServer, CountQuery)} of
|
2016-04-15 14:11:31 +02:00
|
|
|
{{selected, _, Res}, {selected, _, [[Count]]}} ->
|
2016-11-18 11:38:08 +01:00
|
|
|
{Max, Direction, _} = get_max_direction_id(RSM),
|
2016-04-15 14:11:31 +02:00
|
|
|
{Res1, IsComplete} =
|
|
|
|
if Max >= 0 andalso Max /= undefined andalso length(Res) > Max ->
|
|
|
|
if Direction == before ->
|
|
|
|
{lists:nthtail(1, Res), false};
|
|
|
|
true ->
|
|
|
|
{lists:sublist(Res, Max), false}
|
|
|
|
end;
|
|
|
|
true ->
|
|
|
|
{Res, true}
|
|
|
|
end,
|
|
|
|
{lists:flatmap(
|
|
|
|
fun([TS, XML, PeerBin, Kind, Nick]) ->
|
2017-01-20 21:21:06 +01:00
|
|
|
case make_archive_el(
|
|
|
|
TS, XML, PeerBin, Kind, Nick,
|
|
|
|
MsgType, JidRequestor, JidArchive) of
|
|
|
|
{ok, El} ->
|
|
|
|
[{TS, binary_to_integer(TS), El}];
|
|
|
|
{error, _} ->
|
2016-04-15 14:11:31 +02:00
|
|
|
[]
|
|
|
|
end
|
2016-09-24 22:34:28 +02:00
|
|
|
end, Res1), IsComplete, binary_to_integer(Count)};
|
2016-04-15 14:11:31 +02:00
|
|
|
_ ->
|
|
|
|
{[], false, 0}
|
|
|
|
end.
|
|
|
|
|
2017-05-07 14:58:11 +02:00
|
|
|
export(_Server) ->
|
|
|
|
[{archive_prefs,
|
|
|
|
fun(Host, #archive_prefs{us =
|
|
|
|
{LUser, LServer},
|
|
|
|
default = Default,
|
|
|
|
always = Always,
|
|
|
|
never = Never})
|
|
|
|
when LServer == Host ->
|
|
|
|
SDefault = erlang:atom_to_binary(Default, utf8),
|
|
|
|
SAlways = misc:term_to_expr(Always),
|
|
|
|
SNever = misc:term_to_expr(Never),
|
|
|
|
[?SQL("insert into archive_prefs (username, def, always, never) values"
|
2017-05-08 09:51:12 +02:00
|
|
|
"(%(LUser)s, %(SDefault)s, %(SAlways)s, %(SNever)s);")];
|
2017-05-07 14:58:11 +02:00
|
|
|
(_Host, _R) ->
|
|
|
|
[]
|
|
|
|
end},
|
|
|
|
{archive_msg,
|
2017-06-26 14:38:12 +02:00
|
|
|
fun(Host, #archive_msg{us ={LUser, LServer},
|
2017-05-07 14:58:11 +02:00
|
|
|
id = _ID, timestamp = TS, peer = Peer,
|
|
|
|
type = Type, nick = Nick, packet = Pkt})
|
|
|
|
when LServer == Host ->
|
|
|
|
TStmp = now_to_usec(TS),
|
|
|
|
SUser = case Type of
|
2017-06-26 14:38:12 +02:00
|
|
|
chat -> LUser;
|
|
|
|
groupchat -> jid:encode({LUser, LServer, <<>>})
|
2017-05-07 14:58:11 +02:00
|
|
|
end,
|
2017-05-10 11:17:12 +02:00
|
|
|
BarePeer = jid:encode(jid:tolower(jid:remove_resource(Peer))),
|
|
|
|
LPeer = jid:encode(jid:tolower(Peer)),
|
2017-05-07 14:58:11 +02:00
|
|
|
XML = fxml:element_to_binary(Pkt),
|
|
|
|
Body = fxml:get_subtag_cdata(Pkt, <<"body">>),
|
2017-05-10 12:05:52 +02:00
|
|
|
SType = misc:atom_to_binary(Type),
|
2017-05-07 14:58:11 +02:00
|
|
|
[?SQL("insert into archive (username, timestamp, "
|
|
|
|
"peer, bare_peer, xml, txt, kind, nick) "
|
|
|
|
"values (%(SUser)s, %(TStmp)d, %(LPeer)s, "
|
|
|
|
"%(BarePeer)s, %(XML)s, %(Body)s, %(SType)s, "
|
2017-05-08 09:51:12 +02:00
|
|
|
"%(Nick)s);")];
|
2017-05-07 14:58:11 +02:00
|
|
|
(_Host, _R) ->
|
|
|
|
[]
|
|
|
|
end}].
|
|
|
|
|
2016-04-15 14:11:31 +02:00
|
|
|
%%%===================================================================
|
|
|
|
%%% Internal functions
|
|
|
|
%%%===================================================================
|
|
|
|
now_to_usec({MSec, Sec, USec}) ->
|
|
|
|
(MSec*1000000 + Sec)*1000000 + USec.
|
|
|
|
|
|
|
|
usec_to_now(Int) ->
|
|
|
|
Secs = Int div 1000000,
|
|
|
|
USec = Int rem 1000000,
|
|
|
|
MSec = Secs div 1000000,
|
|
|
|
Sec = Secs rem 1000000,
|
|
|
|
{MSec, Sec, USec}.
|
|
|
|
|
2016-11-18 11:38:08 +01:00
|
|
|
make_sql_query(User, LServer, MAMQuery, RSM) ->
|
|
|
|
Start = proplists:get_value(start, MAMQuery),
|
|
|
|
End = proplists:get_value('end', MAMQuery),
|
|
|
|
With = proplists:get_value(with, MAMQuery),
|
|
|
|
WithText = proplists:get_value(withtext, MAMQuery),
|
2016-07-25 12:50:30 +02:00
|
|
|
{Max, Direction, ID} = get_max_direction_id(RSM),
|
2017-04-29 10:39:40 +02:00
|
|
|
ODBCType = ejabberd_config:get_option({sql_type, LServer}),
|
2016-05-24 17:44:07 +02:00
|
|
|
Escape =
|
|
|
|
case ODBCType of
|
|
|
|
mssql -> fun ejabberd_sql:standard_escape/1;
|
|
|
|
sqlite -> fun ejabberd_sql:standard_escape/1;
|
|
|
|
_ -> fun ejabberd_sql:escape/1
|
|
|
|
end,
|
2016-04-15 14:11:31 +02:00
|
|
|
LimitClause = if is_integer(Max), Max >= 0, ODBCType /= mssql ->
|
2016-09-24 22:34:28 +02:00
|
|
|
[<<" limit ">>, integer_to_binary(Max+1)];
|
2016-04-15 14:11:31 +02:00
|
|
|
true ->
|
|
|
|
[]
|
|
|
|
end,
|
|
|
|
TopClause = if is_integer(Max), Max >= 0, ODBCType == mssql ->
|
2016-09-24 22:34:28 +02:00
|
|
|
[<<" TOP ">>, integer_to_binary(Max+1)];
|
2016-04-15 14:11:31 +02:00
|
|
|
true ->
|
|
|
|
[]
|
|
|
|
end,
|
2016-09-13 15:56:34 +02:00
|
|
|
WithTextClause = if is_binary(WithText), WithText /= <<>> ->
|
2016-07-25 12:50:30 +02:00
|
|
|
[<<" and match (txt) against ('">>,
|
2016-09-13 15:56:34 +02:00
|
|
|
Escape(WithText), <<"')">>];
|
|
|
|
true ->
|
2016-07-25 12:50:30 +02:00
|
|
|
[]
|
|
|
|
end,
|
|
|
|
WithClause = case catch jid:tolower(With) of
|
2016-04-15 14:11:31 +02:00
|
|
|
{_, _, <<>>} ->
|
|
|
|
[<<" and bare_peer='">>,
|
2017-02-26 08:07:12 +01:00
|
|
|
Escape(jid:encode(With)),
|
2016-04-15 14:11:31 +02:00
|
|
|
<<"'">>];
|
|
|
|
{_, _, _} ->
|
|
|
|
[<<" and peer='">>,
|
2017-02-26 08:07:12 +01:00
|
|
|
Escape(jid:encode(With)),
|
2016-04-15 14:11:31 +02:00
|
|
|
<<"'">>];
|
2016-07-25 12:50:30 +02:00
|
|
|
_ ->
|
2016-04-15 14:11:31 +02:00
|
|
|
[]
|
|
|
|
end,
|
2016-09-24 22:34:28 +02:00
|
|
|
PageClause = case catch binary_to_integer(ID) of
|
2016-04-15 14:11:31 +02:00
|
|
|
I when is_integer(I), I >= 0 ->
|
|
|
|
case Direction of
|
|
|
|
before ->
|
|
|
|
[<<" AND timestamp < ">>, ID];
|
2016-07-25 12:50:30 +02:00
|
|
|
'after' ->
|
2016-04-15 14:11:31 +02:00
|
|
|
[<<" AND timestamp > ">>, ID];
|
|
|
|
_ ->
|
|
|
|
[]
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
[]
|
|
|
|
end,
|
|
|
|
StartClause = case Start of
|
|
|
|
{_, _, _} ->
|
|
|
|
[<<" and timestamp >= ">>,
|
2016-09-24 22:34:28 +02:00
|
|
|
integer_to_binary(now_to_usec(Start))];
|
2016-04-15 14:11:31 +02:00
|
|
|
_ ->
|
|
|
|
[]
|
|
|
|
end,
|
|
|
|
EndClause = case End of
|
|
|
|
{_, _, _} ->
|
|
|
|
[<<" and timestamp <= ">>,
|
2016-09-24 22:34:28 +02:00
|
|
|
integer_to_binary(now_to_usec(End))];
|
2016-04-15 14:11:31 +02:00
|
|
|
_ ->
|
|
|
|
[]
|
|
|
|
end,
|
2016-05-24 17:44:07 +02:00
|
|
|
SUser = Escape(User),
|
2016-04-15 14:11:31 +02:00
|
|
|
|
|
|
|
Query = [<<"SELECT ">>, TopClause, <<" timestamp, xml, peer, kind, nick"
|
|
|
|
" FROM archive WHERE username='">>,
|
2016-07-25 12:50:30 +02:00
|
|
|
SUser, <<"'">>, WithClause, WithTextClause, StartClause, EndClause,
|
2016-04-15 14:11:31 +02:00
|
|
|
PageClause],
|
|
|
|
|
|
|
|
QueryPage =
|
|
|
|
case Direction of
|
|
|
|
before ->
|
|
|
|
% ID can be empty because of
|
|
|
|
% XEP-0059: Result Set Management
|
|
|
|
% 2.5 Requesting the Last Page in a Result Set
|
|
|
|
[<<"SELECT timestamp, xml, peer, kind, nick FROM (">>, Query,
|
|
|
|
<<" ORDER BY timestamp DESC ">>,
|
|
|
|
LimitClause, <<") AS t ORDER BY timestamp ASC;">>];
|
|
|
|
_ ->
|
|
|
|
[Query, <<" ORDER BY timestamp ASC ">>,
|
|
|
|
LimitClause, <<";">>]
|
|
|
|
end,
|
|
|
|
{QueryPage,
|
|
|
|
[<<"SELECT COUNT(*) FROM archive WHERE username='">>,
|
2016-07-25 12:50:30 +02:00
|
|
|
SUser, <<"'">>, WithClause, WithTextClause, StartClause, EndClause, <<";">>]}.
|
|
|
|
|
|
|
|
-spec get_max_direction_id(rsm_set() | undefined) ->
|
|
|
|
{integer() | undefined,
|
|
|
|
before | 'after' | undefined,
|
|
|
|
binary()}.
|
|
|
|
get_max_direction_id(RSM) ->
|
|
|
|
case RSM of
|
|
|
|
#rsm_set{max = Max, before = Before} when is_binary(Before) ->
|
|
|
|
{Max, before, Before};
|
|
|
|
#rsm_set{max = Max, 'after' = After} when is_binary(After) ->
|
|
|
|
{Max, 'after', After};
|
|
|
|
#rsm_set{max = Max} ->
|
|
|
|
{Max, undefined, <<>>};
|
|
|
|
_ ->
|
|
|
|
{undefined, undefined, <<>>}
|
|
|
|
end.
|
2017-01-20 21:21:06 +01:00
|
|
|
|
|
|
|
-spec make_archive_el(binary(), binary(), binary(), binary(),
|
|
|
|
binary(), _, jid(), jid()) ->
|
|
|
|
{ok, xmpp_element()} | {error, invalid_jid |
|
|
|
|
invalid_timestamp |
|
|
|
|
invalid_xml}.
|
|
|
|
make_archive_el(TS, XML, Peer, Kind, Nick, MsgType, JidRequestor, JidArchive) ->
|
|
|
|
case fxml_stream:parse_element(XML) of
|
|
|
|
#xmlel{} = El ->
|
|
|
|
try binary_to_integer(TS) of
|
|
|
|
TSInt ->
|
2017-02-26 08:07:12 +01:00
|
|
|
try jid:decode(Peer) of
|
|
|
|
PeerJID ->
|
2017-01-20 21:21:06 +01:00
|
|
|
Now = usec_to_now(TSInt),
|
|
|
|
PeerLJID = jid:tolower(PeerJID),
|
|
|
|
T = case Kind of
|
|
|
|
<<"">> -> chat;
|
|
|
|
null -> chat;
|
2017-04-11 12:13:58 +02:00
|
|
|
_ -> misc:binary_to_atom(Kind)
|
2017-01-20 21:21:06 +01:00
|
|
|
end,
|
|
|
|
mod_mam:msg_to_el(
|
|
|
|
#archive_msg{timestamp = Now,
|
|
|
|
id = TS,
|
|
|
|
packet = El,
|
|
|
|
type = T,
|
|
|
|
nick = Nick,
|
|
|
|
peer = PeerLJID},
|
2017-02-26 08:07:12 +01:00
|
|
|
MsgType, JidRequestor, JidArchive)
|
|
|
|
catch _:{bad_jid, _} ->
|
2017-01-20 21:21:06 +01:00
|
|
|
?ERROR_MSG("Malformed 'peer' field with value "
|
|
|
|
"'~s' detected for user ~s in table "
|
|
|
|
"'archive': invalid JID",
|
2017-02-26 08:07:12 +01:00
|
|
|
[Peer, jid:encode(JidArchive)]),
|
2017-01-20 21:21:06 +01:00
|
|
|
{error, invalid_jid}
|
|
|
|
end
|
|
|
|
catch _:_ ->
|
|
|
|
?ERROR_MSG("Malformed 'timestamp' field with value '~s' "
|
|
|
|
"detected for user ~s in table 'archive': "
|
|
|
|
"not an integer",
|
2017-02-26 08:07:12 +01:00
|
|
|
[TS, jid:encode(JidArchive)]),
|
2017-01-20 21:21:06 +01:00
|
|
|
{error, invalid_timestamp}
|
|
|
|
end;
|
|
|
|
{error, {_, Reason}} ->
|
|
|
|
?ERROR_MSG("Malformed 'xml' field with value '~s' detected "
|
|
|
|
"for user ~s in table 'archive': ~s",
|
2017-02-26 08:07:12 +01:00
|
|
|
[XML, jid:encode(JidArchive), Reason]),
|
2017-01-20 21:21:06 +01:00
|
|
|
{error, invalid_xml}
|
|
|
|
end.
|