2004-12-14 00:00:12 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : mod_offline_odbc.erl
|
2007-08-28 16:36:39 +02:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%% Purpose : Store and manage offline messages in relational database.
|
|
|
|
%%% Created : 5 Jan 2003 by Alexey Shchepin <alexey@process-one.net>
|
2007-12-24 13:58:05 +01:00
|
|
|
%%%
|
|
|
|
%%%
|
2009-01-12 15:44:42 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2009 ProcessOne
|
2007-12-24 13:58:05 +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.
|
2009-01-12 15:44:42 +01:00
|
|
|
%%%
|
2007-12-24 13:58:05 +01:00
|
|
|
%%% 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., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
%%% 02111-1307 USA
|
|
|
|
%%%
|
2004-12-14 00:00:12 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
2007-08-23 02:51:54 +02:00
|
|
|
|
2004-12-14 00:00:12 +01:00
|
|
|
-module(mod_offline_odbc).
|
2007-08-28 16:36:39 +02:00
|
|
|
-author('alexey@process-one.net').
|
2004-12-14 00:00:12 +01:00
|
|
|
|
|
|
|
-behaviour(gen_mod).
|
|
|
|
|
2007-08-28 16:36:39 +02:00
|
|
|
-export([count_offline_messages/2]).
|
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
-export([start/2,
|
2007-08-28 16:36:39 +02:00
|
|
|
init/2,
|
2005-06-20 05:18:13 +02:00
|
|
|
stop/1,
|
2004-12-14 00:00:12 +01:00
|
|
|
store_packet/3,
|
2005-07-13 05:24:13 +02:00
|
|
|
pop_offline_messages/3,
|
2007-08-23 02:51:54 +02:00
|
|
|
remove_user/2,
|
|
|
|
webadmin_page/3,
|
2008-10-12 16:16:05 +02:00
|
|
|
webadmin_user/4,
|
|
|
|
webadmin_user_parse_query/5]).
|
2004-12-14 00:00:12 +01:00
|
|
|
|
|
|
|
-include("ejabberd.hrl").
|
|
|
|
-include("jlib.hrl").
|
2008-07-16 18:58:42 +02:00
|
|
|
-include("web/ejabberd_http.hrl").
|
|
|
|
-include("web/ejabberd_web_admin.hrl").
|
2004-12-14 00:00:12 +01:00
|
|
|
|
|
|
|
-record(offline_msg, {user, timestamp, expire, from, to, packet}).
|
|
|
|
|
|
|
|
-define(PROCNAME, ejabberd_offline).
|
|
|
|
-define(OFFLINE_TABLE_LOCK_THRESHOLD, 1000).
|
|
|
|
|
2007-08-28 16:36:39 +02:00
|
|
|
start(Host, Opts) ->
|
2005-06-20 05:18:13 +02:00
|
|
|
ejabberd_hooks:add(offline_message_hook, Host,
|
2004-12-14 00:00:12 +01:00
|
|
|
?MODULE, store_packet, 50),
|
2005-06-20 05:18:13 +02:00
|
|
|
ejabberd_hooks:add(resend_offline_messages_hook, Host,
|
2004-12-14 00:00:12 +01:00
|
|
|
?MODULE, pop_offline_messages, 50),
|
2005-06-20 05:18:13 +02:00
|
|
|
ejabberd_hooks:add(remove_user, Host,
|
2004-12-19 21:47:35 +01:00
|
|
|
?MODULE, remove_user, 50),
|
2007-05-12 18:28:34 +02:00
|
|
|
ejabberd_hooks:add(anonymous_purge_hook, Host,
|
|
|
|
?MODULE, remove_user, 50),
|
2007-08-23 02:51:54 +02:00
|
|
|
ejabberd_hooks:add(webadmin_page_host, Host,
|
|
|
|
?MODULE, webadmin_page, 50),
|
|
|
|
ejabberd_hooks:add(webadmin_user, Host,
|
|
|
|
?MODULE, webadmin_user, 50),
|
2008-10-12 16:16:05 +02:00
|
|
|
ejabberd_hooks:add(webadmin_user_parse_query, Host,
|
|
|
|
?MODULE, webadmin_user_parse_query, 50),
|
2007-08-28 16:36:39 +02:00
|
|
|
MaxOfflineMsgs = gen_mod:get_opt(user_max_messages, Opts, infinity),
|
2005-07-13 05:24:13 +02:00
|
|
|
register(gen_mod:get_module_proc(Host, ?PROCNAME),
|
2007-08-28 16:36:39 +02:00
|
|
|
spawn(?MODULE, init, [Host, MaxOfflineMsgs])).
|
2004-12-14 00:00:12 +01:00
|
|
|
|
2007-08-28 16:36:39 +02:00
|
|
|
%% MaxOfflineMsgs is either infinity of integer > 0
|
|
|
|
init(Host, infinity) ->
|
|
|
|
loop(Host, infinity);
|
|
|
|
init(Host, MaxOfflineMsgs)
|
|
|
|
when integer(MaxOfflineMsgs), MaxOfflineMsgs > 0 ->
|
|
|
|
loop(Host, MaxOfflineMsgs).
|
2004-12-14 00:00:12 +01:00
|
|
|
|
2007-08-28 16:36:39 +02:00
|
|
|
loop(Host, MaxOfflineMsgs) ->
|
2004-12-14 00:00:12 +01:00
|
|
|
receive
|
2007-09-05 00:12:33 +02:00
|
|
|
#offline_msg{user = User} = Msg ->
|
|
|
|
Msgs = receive_all(User, [Msg]),
|
2007-08-28 16:36:39 +02:00
|
|
|
Len = length(Msgs),
|
|
|
|
|
|
|
|
%% Only count existing messages if needed:
|
|
|
|
Count = if MaxOfflineMsgs =/= infinity ->
|
2007-09-05 00:12:33 +02:00
|
|
|
Len + count_offline_messages(User, Host);
|
2007-08-28 16:36:39 +02:00
|
|
|
true -> 0
|
|
|
|
end,
|
|
|
|
if
|
|
|
|
Count > MaxOfflineMsgs ->
|
|
|
|
discard_warn_sender(Msgs);
|
|
|
|
true ->
|
|
|
|
Query = lists:map(
|
|
|
|
fun(M) ->
|
|
|
|
Username =
|
|
|
|
ejabberd_odbc:escape(
|
|
|
|
(M#offline_msg.to)#jid.luser),
|
|
|
|
From = M#offline_msg.from,
|
|
|
|
To = M#offline_msg.to,
|
|
|
|
{xmlelement, Name, Attrs, Els} =
|
|
|
|
M#offline_msg.packet,
|
|
|
|
Attrs2 = jlib:replace_from_to_attrs(
|
|
|
|
jlib:jid_to_string(From),
|
|
|
|
jlib:jid_to_string(To),
|
|
|
|
Attrs),
|
|
|
|
Packet = {xmlelement, Name, Attrs2,
|
|
|
|
Els ++
|
|
|
|
[jlib:timestamp_to_xml(
|
|
|
|
calendar:now_to_universal_time(
|
|
|
|
M#offline_msg.timestamp))]},
|
|
|
|
XML =
|
|
|
|
ejabberd_odbc:escape(
|
|
|
|
lists:flatten(
|
|
|
|
xml:element_to_string(Packet))),
|
|
|
|
odbc_queries:add_spool_sql(Username, XML)
|
|
|
|
end, Msgs),
|
|
|
|
case catch odbc_queries:add_spool(Host, Query) of
|
|
|
|
{'EXIT', Reason} ->
|
|
|
|
?ERROR_MSG("~p~n", [Reason]);
|
2008-08-25 15:36:34 +02:00
|
|
|
{error, Reason} ->
|
|
|
|
?ERROR_MSG("~p~n", [Reason]);
|
2007-08-28 16:36:39 +02:00
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end
|
2004-12-14 00:00:12 +01:00
|
|
|
end,
|
2007-08-28 16:36:39 +02:00
|
|
|
loop(Host, MaxOfflineMsgs);
|
2004-12-14 00:00:12 +01:00
|
|
|
_ ->
|
2007-08-28 16:36:39 +02:00
|
|
|
loop(Host, MaxOfflineMsgs)
|
2004-12-14 00:00:12 +01:00
|
|
|
end.
|
|
|
|
|
2007-08-28 16:36:39 +02:00
|
|
|
receive_all(Username, Msgs) ->
|
2004-12-14 00:00:12 +01:00
|
|
|
receive
|
2007-08-28 16:36:39 +02:00
|
|
|
#offline_msg{user=Username} = Msg ->
|
|
|
|
receive_all(Username, [Msg | Msgs])
|
2004-12-14 00:00:12 +01:00
|
|
|
after 0 ->
|
2005-08-29 21:00:10 +02:00
|
|
|
lists:reverse(Msgs)
|
2004-12-14 00:00:12 +01:00
|
|
|
end.
|
|
|
|
|
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
stop(Host) ->
|
|
|
|
ejabberd_hooks:delete(offline_message_hook, Host,
|
2004-12-14 00:00:12 +01:00
|
|
|
?MODULE, store_packet, 50),
|
2005-06-20 05:18:13 +02:00
|
|
|
ejabberd_hooks:delete(resend_offline_messages_hook, Host,
|
2004-12-14 00:00:12 +01:00
|
|
|
?MODULE, pop_offline_messages, 50),
|
2005-06-20 05:18:13 +02:00
|
|
|
ejabberd_hooks:delete(remove_user, Host,
|
2004-12-19 21:47:35 +01:00
|
|
|
?MODULE, remove_user, 50),
|
2007-05-12 18:28:34 +02:00
|
|
|
ejabberd_hooks:delete(anonymous_purge_hook, Host,
|
|
|
|
?MODULE, remove_user, 50),
|
2007-08-23 02:51:54 +02:00
|
|
|
ejabberd_hooks:delete(webadmin_page_host, Host,
|
|
|
|
?MODULE, webadmin_page, 50),
|
|
|
|
ejabberd_hooks:delete(webadmin_user, Host,
|
|
|
|
?MODULE, webadmin_user, 50),
|
2008-10-12 16:16:05 +02:00
|
|
|
ejabberd_hooks:delete(webadmin_user_parse_query, Host,
|
|
|
|
?MODULE, webadmin_user_parse_query, 50),
|
2005-07-13 05:24:13 +02:00
|
|
|
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
|
|
|
|
exit(whereis(Proc), stop),
|
2004-12-14 00:00:12 +01:00
|
|
|
ok.
|
|
|
|
|
|
|
|
store_packet(From, To, Packet) ->
|
|
|
|
Type = xml:get_tag_attr_s("type", Packet),
|
|
|
|
if
|
2005-12-07 14:01:33 +01:00
|
|
|
(Type /= "error") and (Type /= "groupchat") and
|
|
|
|
(Type /= "headline") ->
|
2004-12-14 00:00:12 +01:00
|
|
|
case check_event(From, To, Packet) of
|
|
|
|
true ->
|
|
|
|
#jid{luser = LUser} = To,
|
|
|
|
TimeStamp = now(),
|
|
|
|
{xmlelement, _Name, _Attrs, Els} = Packet,
|
|
|
|
Expire = find_x_expire(TimeStamp, Els),
|
2005-07-13 05:24:13 +02:00
|
|
|
gen_mod:get_module_proc(To#jid.lserver, ?PROCNAME) !
|
|
|
|
#offline_msg{user = LUser,
|
|
|
|
timestamp = TimeStamp,
|
|
|
|
expire = Expire,
|
|
|
|
from = From,
|
|
|
|
to = To,
|
|
|
|
packet = Packet},
|
2004-12-14 00:00:12 +01:00
|
|
|
stop;
|
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end;
|
|
|
|
true ->
|
|
|
|
ok
|
|
|
|
end.
|
|
|
|
|
|
|
|
check_event(From, To, Packet) ->
|
|
|
|
{xmlelement, Name, Attrs, Els} = Packet,
|
|
|
|
case find_x_event(Els) of
|
|
|
|
false ->
|
|
|
|
true;
|
|
|
|
El ->
|
|
|
|
case xml:get_subtag(El, "id") of
|
|
|
|
false ->
|
|
|
|
case xml:get_subtag(El, "offline") of
|
|
|
|
false ->
|
|
|
|
true;
|
|
|
|
_ ->
|
|
|
|
ID = case xml:get_tag_attr_s("id", Packet) of
|
|
|
|
"" ->
|
|
|
|
{xmlelement, "id", [], []};
|
|
|
|
S ->
|
|
|
|
{xmlelement, "id", [],
|
|
|
|
[{xmlcdata, S}]}
|
|
|
|
end,
|
|
|
|
ejabberd_router:route(
|
|
|
|
To, From, {xmlelement, Name, Attrs,
|
|
|
|
[{xmlelement, "x",
|
|
|
|
[{"xmlns", ?NS_EVENT}],
|
|
|
|
[ID,
|
|
|
|
{xmlelement, "offline", [], []}]}]
|
|
|
|
}),
|
|
|
|
true
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
find_x_event([]) ->
|
|
|
|
false;
|
|
|
|
find_x_event([{xmlcdata, _} | Els]) ->
|
|
|
|
find_x_event(Els);
|
|
|
|
find_x_event([El | Els]) ->
|
|
|
|
case xml:get_tag_attr_s("xmlns", El) of
|
|
|
|
?NS_EVENT ->
|
|
|
|
El;
|
|
|
|
_ ->
|
|
|
|
find_x_event(Els)
|
|
|
|
end.
|
|
|
|
|
|
|
|
find_x_expire(_, []) ->
|
|
|
|
never;
|
|
|
|
find_x_expire(TimeStamp, [{xmlcdata, _} | Els]) ->
|
|
|
|
find_x_expire(TimeStamp, Els);
|
|
|
|
find_x_expire(TimeStamp, [El | Els]) ->
|
|
|
|
case xml:get_tag_attr_s("xmlns", El) of
|
|
|
|
?NS_EXPIRE ->
|
2007-08-23 02:51:54 +02:00
|
|
|
Val = xml:get_tag_attr_s("seconds", El),
|
|
|
|
case catch list_to_integer(Val) of
|
|
|
|
{'EXIT', _} ->
|
|
|
|
never;
|
|
|
|
Int when Int > 0 ->
|
|
|
|
{MegaSecs, Secs, MicroSecs} = TimeStamp,
|
|
|
|
S = MegaSecs * 1000000 + Secs + Int,
|
|
|
|
MegaSecs1 = S div 1000000,
|
|
|
|
Secs1 = S rem 1000000,
|
|
|
|
{MegaSecs1, Secs1, MicroSecs};
|
2004-12-14 00:00:12 +01:00
|
|
|
_ ->
|
|
|
|
never
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
find_x_expire(TimeStamp, Els)
|
|
|
|
end.
|
|
|
|
|
|
|
|
|
2005-07-13 05:24:13 +02:00
|
|
|
pop_offline_messages(Ls, User, Server) ->
|
2004-12-14 00:00:12 +01:00
|
|
|
LUser = jlib:nodeprep(User),
|
2005-07-13 05:24:13 +02:00
|
|
|
LServer = jlib:nameprep(Server),
|
2004-12-14 00:00:12 +01:00
|
|
|
EUser = ejabberd_odbc:escape(LUser),
|
2006-09-03 17:15:46 +02:00
|
|
|
case odbc_queries:get_and_del_spool_msg_t(LServer, EUser) of
|
2005-12-21 17:10:56 +01:00
|
|
|
{atomic, {selected, ["username","xml"], Rs}} ->
|
2004-12-14 00:00:12 +01:00
|
|
|
Ls ++ lists:flatmap(
|
|
|
|
fun({_, XML}) ->
|
|
|
|
case xml_stream:parse_element(XML) of
|
|
|
|
{error, _Reason} ->
|
|
|
|
[];
|
|
|
|
El ->
|
|
|
|
To = jlib:string_to_jid(
|
|
|
|
xml:get_tag_attr_s("to", El)),
|
|
|
|
From = jlib:string_to_jid(
|
|
|
|
xml:get_tag_attr_s("from", El)),
|
|
|
|
if
|
|
|
|
(To /= error) and
|
|
|
|
(From /= error) ->
|
|
|
|
[{route, From, To, El}];
|
|
|
|
true ->
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end, Rs);
|
|
|
|
_ ->
|
|
|
|
Ls
|
|
|
|
end.
|
|
|
|
|
|
|
|
|
2005-07-13 05:24:13 +02:00
|
|
|
remove_user(User, Server) ->
|
2004-12-14 00:00:12 +01:00
|
|
|
LUser = jlib:nodeprep(User),
|
2005-07-13 05:24:13 +02:00
|
|
|
LServer = jlib:nameprep(Server),
|
2004-12-14 00:00:12 +01:00
|
|
|
Username = ejabberd_odbc:escape(LUser),
|
2006-09-03 17:15:46 +02:00
|
|
|
odbc_queries:del_spool_msg(LServer, Username).
|
2004-12-14 00:00:12 +01:00
|
|
|
|
2007-08-23 02:51:54 +02:00
|
|
|
|
2007-08-28 16:36:39 +02:00
|
|
|
%% Helper functions:
|
|
|
|
|
|
|
|
%% TODO: Warning - This function is a duplicate from mod_offline.erl
|
|
|
|
%% It is duplicate to stay consistent (many functions are duplicated
|
|
|
|
%% in this module). It will be refactored later on.
|
|
|
|
%% Warn senders that their messages have been discarded:
|
|
|
|
discard_warn_sender(Msgs) ->
|
|
|
|
lists:foreach(
|
|
|
|
fun(#offline_msg{from=From, to=To, packet=Packet}) ->
|
|
|
|
ErrText = "Your contact offline message queue is full. The message has been discarded.",
|
|
|
|
Lang = xml:get_tag_attr_s("xml:lang", Packet),
|
|
|
|
Err = jlib:make_error_reply(
|
|
|
|
Packet, ?ERRT_RESOURCE_CONSTRAINT(Lang, ErrText)),
|
|
|
|
ejabberd_router:route(
|
|
|
|
To,
|
|
|
|
From, Err)
|
|
|
|
end, Msgs).
|
|
|
|
|
|
|
|
|
2007-08-23 02:51:54 +02:00
|
|
|
webadmin_page(_, Host,
|
|
|
|
#request{us = _US,
|
|
|
|
path = ["user", U, "queue"],
|
|
|
|
q = Query,
|
|
|
|
lang = Lang} = _Request) ->
|
|
|
|
Res = user_queue(U, Host, Query, Lang),
|
|
|
|
{stop, Res};
|
|
|
|
|
|
|
|
webadmin_page(Acc, _, _) -> Acc.
|
|
|
|
|
|
|
|
user_queue(User, Server, Query, Lang) ->
|
|
|
|
LUser = jlib:nodeprep(User),
|
|
|
|
LServer = jlib:nameprep(Server),
|
|
|
|
Username = ejabberd_odbc:escape(LUser),
|
|
|
|
US = {LUser, LServer},
|
|
|
|
Res = user_queue_parse_query(Username, LServer, Query),
|
|
|
|
Msgs = case catch ejabberd_odbc:sql_query(
|
|
|
|
LServer,
|
|
|
|
["select username, xml from spool"
|
|
|
|
" where username='", Username, "'"
|
|
|
|
" order by seq;"]) of
|
|
|
|
{selected, ["username", "xml"], Rs} ->
|
|
|
|
lists:flatmap(
|
|
|
|
fun({_, XML}) ->
|
|
|
|
case xml_stream:parse_element(XML) of
|
|
|
|
{error, _Reason} ->
|
|
|
|
[];
|
|
|
|
El ->
|
|
|
|
[El]
|
|
|
|
end
|
|
|
|
end, Rs);
|
|
|
|
_ ->
|
|
|
|
[]
|
|
|
|
end,
|
|
|
|
FMsgs =
|
|
|
|
lists:map(
|
2007-12-07 01:09:48 +01:00
|
|
|
fun({xmlelement, _Name, _Attrs, _Els} = Msg) ->
|
2007-08-23 02:51:54 +02:00
|
|
|
ID = jlib:encode_base64(binary_to_list(term_to_binary(Msg))),
|
|
|
|
Packet = Msg,
|
|
|
|
FPacket = ejabberd_web_admin:pretty_print_xml(Packet),
|
|
|
|
?XE("tr",
|
|
|
|
[?XAE("td", [{"class", "valign"}], [?INPUT("checkbox", "selected", ID)]),
|
|
|
|
?XAE("td", [{"class", "valign"}], [?XC("pre", FPacket)])]
|
|
|
|
)
|
|
|
|
end, Msgs),
|
|
|
|
[?XC("h1", io_lib:format(?T("~s's Offline Messages Queue"),
|
|
|
|
[us_to_list(US)]))] ++
|
|
|
|
case Res of
|
2009-01-12 22:48:34 +01:00
|
|
|
ok -> [?XREST("Submitted")];
|
2007-08-23 02:51:54 +02:00
|
|
|
nothing -> []
|
|
|
|
end ++
|
|
|
|
[?XAE("form", [{"action", ""}, {"method", "post"}],
|
|
|
|
[?XE("table",
|
|
|
|
[?XE("thead",
|
|
|
|
[?XE("tr",
|
|
|
|
[?X("td"),
|
|
|
|
?XCT("td", "Packet")
|
|
|
|
])]),
|
|
|
|
?XE("tbody",
|
|
|
|
if
|
|
|
|
FMsgs == [] ->
|
|
|
|
[?XE("tr",
|
|
|
|
[?XAC("td", [{"colspan", "4"}], " ")]
|
|
|
|
)];
|
|
|
|
true ->
|
|
|
|
FMsgs
|
|
|
|
end
|
|
|
|
)]),
|
|
|
|
?BR,
|
|
|
|
?INPUTT("submit", "delete", "Delete Selected")
|
|
|
|
])].
|
|
|
|
|
|
|
|
user_queue_parse_query(Username, LServer, Query) ->
|
|
|
|
case lists:keysearch("delete", 1, Query) of
|
|
|
|
{value, _} ->
|
|
|
|
Msgs = case catch ejabberd_odbc:sql_query(
|
|
|
|
LServer,
|
|
|
|
["select xml, seq from spool"
|
|
|
|
" where username='", Username, "'"
|
|
|
|
" order by seq;"]) of
|
|
|
|
{selected, ["xml", "seq"], Rs} ->
|
|
|
|
lists:flatmap(
|
|
|
|
fun({XML, Seq}) ->
|
|
|
|
case xml_stream:parse_element(XML) of
|
|
|
|
{error, _Reason} ->
|
|
|
|
[];
|
|
|
|
El ->
|
|
|
|
[{El, Seq}]
|
|
|
|
end
|
|
|
|
end, Rs);
|
|
|
|
_ ->
|
|
|
|
[]
|
|
|
|
end,
|
|
|
|
F = fun() ->
|
|
|
|
lists:foreach(
|
|
|
|
fun({Msg, Seq}) ->
|
|
|
|
ID = jlib:encode_base64(
|
|
|
|
binary_to_list(term_to_binary(Msg))),
|
|
|
|
case lists:member({"selected", ID}, Query) of
|
|
|
|
true ->
|
|
|
|
SSeq = ejabberd_odbc:escape(Seq),
|
|
|
|
catch ejabberd_odbc:sql_query(
|
|
|
|
LServer,
|
|
|
|
["delete from spool"
|
|
|
|
" where username='", Username, "'"
|
|
|
|
" and seq='", SSeq, "';"]);
|
|
|
|
false ->
|
|
|
|
ok
|
|
|
|
end
|
|
|
|
end, Msgs)
|
|
|
|
end,
|
|
|
|
mnesia:transaction(F),
|
|
|
|
ok;
|
|
|
|
false ->
|
|
|
|
nothing
|
|
|
|
end.
|
|
|
|
|
|
|
|
us_to_list({User, Server}) ->
|
|
|
|
jlib:jid_to_string({User, Server, ""}).
|
|
|
|
|
|
|
|
webadmin_user(Acc, User, Server, Lang) ->
|
|
|
|
LUser = jlib:nodeprep(User),
|
|
|
|
LServer = jlib:nameprep(Server),
|
|
|
|
Username = ejabberd_odbc:escape(LUser),
|
|
|
|
QueueLen = case catch ejabberd_odbc:sql_query(
|
|
|
|
LServer,
|
|
|
|
["select count(*) from spool"
|
|
|
|
" where username='", Username, "';"]) of
|
|
|
|
{selected, [_], [{SCount}]} ->
|
|
|
|
SCount;
|
|
|
|
_ ->
|
|
|
|
0
|
|
|
|
end,
|
|
|
|
FQueueLen = [?AC("queue/", QueueLen)],
|
2008-10-12 16:16:05 +02:00
|
|
|
Acc ++ [?XCT("h3", "Offline Messages:")] ++ FQueueLen ++ [?C(" "), ?INPUTT("submit", "removealloffline", "Remove All Offline Messages")].
|
|
|
|
|
|
|
|
webadmin_user_parse_query(_, "removealloffline", User, Server, _Query) ->
|
|
|
|
case catch odbc_queries:del_spool_msg(Server, User) of
|
|
|
|
{'EXIT', Reason} ->
|
|
|
|
?ERROR_MSG("Failed to remove offline messages: ~p", [Reason]),
|
|
|
|
{stop, error};
|
|
|
|
{error, Reason} ->
|
|
|
|
?ERROR_MSG("Failed to remove offline messages: ~p", [Reason]),
|
|
|
|
{stop, error};
|
|
|
|
_ ->
|
|
|
|
?INFO_MSG("Removed all offline messages for ~s@~s", [User, Server]),
|
|
|
|
{stop, ok}
|
|
|
|
end;
|
|
|
|
webadmin_user_parse_query(Acc, _Action, _User, _Server, _Query) ->
|
|
|
|
Acc.
|
2007-08-28 16:36:39 +02:00
|
|
|
|
|
|
|
%% ------------------------------------------------
|
|
|
|
%% mod_offline: number of messages quota management
|
|
|
|
|
|
|
|
%% Returns as integer the number of offline messages for a given user
|
|
|
|
count_offline_messages(LUser, LServer) ->
|
2007-10-06 19:35:15 +02:00
|
|
|
Username = ejabberd_odbc:escape(LUser),
|
2007-08-28 16:36:39 +02:00
|
|
|
case catch odbc_queries:count_records_where(
|
2007-10-06 19:35:15 +02:00
|
|
|
LServer, "spool", "where username='" ++ Username ++ "'") of
|
2007-08-28 16:36:39 +02:00
|
|
|
{selected, [_], [{Res}]} ->
|
|
|
|
list_to_integer(Res);
|
|
|
|
_ ->
|
|
|
|
0
|
|
|
|
end.
|