--- /dev/null
+%%%----------------------------------------------------------------------
+%%% ejabberd, Copyright (C) 2017 ProcessOne
+%%%
+%%% 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.
+%%%
+%%%----------------------------------------------------------------------
+-record(push_session,
+ {us = {<<"">>, <<"">>} :: {binary(), binary()},
+ timestamp = p1_time_compat:timestamp() :: erlang:timestamp(),
+ service = {<<"">>, <<"">>, <<"">>} :: ljid(),
+ node = <<"">> :: binary(),
+ xdata = #xdata{} :: xdata()}).
-include_lib("stdlib/include/ms_transform.hrl").
-include("logger.hrl").
-include("xmpp.hrl").
-
--record(push_session,
- {us = {<<"">>, <<"">>} :: {binary(), binary()},
- timestamp = p1_time_compat:timestamp() :: erlang:timestamp(),
- service = {<<"">>, <<"">>, <<"">>} :: ljid(),
- node = <<"">> :: binary(),
- xdata = #xdata{} :: xdata()}).
+-include("mod_push.hrl").
%%%-------------------------------------------------------------------
%%% API
%% API
-export([init/2, store_session/6, lookup_session/4, lookup_session/3,
lookup_sessions/3, lookup_sessions/2, lookup_sessions/1,
- delete_session/3, delete_old_sessions/2]).
+ delete_session/3, delete_old_sessions/2, export/1]).
-include("xmpp.hrl").
-include("logger.hrl").
-include("ejabberd_sql_pt.hrl").
+-include("mod_push.hrl").
%%%===================================================================
%%% API
ok.
store_session(LUser, LServer, NowTS, PushJID, Node, XData) ->
- XML = case XData of
- undefined -> <<>>;
- _ -> fxml:element_to_binary(xmpp:encode(XData))
- end,
+ XML = encode_xdata(XData),
TS = misc:now_to_usec(NowTS),
PushLJID = jid:tolower(PushJID),
Service = jid:encode(PushLJID),
{error, db_failure}
end.
+export(_Server) ->
+ [{push_session,
+ fun(Host, #push_session{us = {LUser, LServer},
+ timestamp = NowTS,
+ service = PushLJID,
+ node = Node,
+ xdata = XData})
+ when LServer == Host ->
+ TS = misc:now_to_usec(NowTS),
+ Service = jid:encode(PushLJID),
+ XML = encode_xdata(XData),
+ [?SQL("delete from push_session where "
+ "username=%(LUser)s and timestamp=%(TS)d and "
+ "service=%(Service)s and node=%(Node)s and "
+ "xml=%(XML)s;"),
+ ?SQL("insert into push_session(username, timestamp, "
+ "service, node, xml) values ("
+ "%(LUser)s, %(TS)d, %(Service)s, %(Node)s, %(XML)s);")];
+ (_Host, _R) ->
+ []
+ end}].
+
%%%===================================================================
%%% Internal functions
%%%===================================================================
[XML, LUser, LServer, Err]),
undefined
end.
+
+encode_xdata(undefined) ->
+ <<>>;
+encode_xdata(XData) ->
+ fxml:element_to_binary(xmpp:encode(XData)).