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

* src/mod_configure.erl: The command get-user-lastlogin is now

compatible with both Mnesia and ODBC (EJAB-383)
* src/mod_last.erl: Likewise
* src/mod_last_odbc.erl: Likewise

SVN Revision: 995
This commit is contained in:
Badlop 2007-11-27 18:54:06 +00:00
parent 0ef2886b7e
commit eb330ac0e0
4 changed files with 49 additions and 4 deletions

View File

@ -1,5 +1,10 @@
2007-11-27 Badlop <badlop@process-one.net>
* src/mod_configure.erl: The command get-user-lastlogin is now
compatible with both Mnesia and ODBC (EJAB-383)
* src/mod_last.erl: Likewise
* src/mod_last_odbc.erl: Likewise
* doc/guide.tex: Document ejabberd_http's
request_handlers (EJAB-372). Fixed small Latex problems.
Sort options of listening sockets.

View File

@ -1606,11 +1606,11 @@ set_form(_From, _Host, ?NS_ADMINL("get-user-lastlogin"), Lang, XData) ->
case ejabberd_sm:get_user_resources(User, Server) of
[] ->
US = {User, Server},
case mnesia:dirty_read({last_activity, US}) of
[] ->
case get_last_info(User, Server) of
not_found ->
?T(Lang, "Never");
[E] ->
Shift = element(3, E),
{ok, Timestamp, _Status} ->
Shift = Timestamp,
TimeStamp = {Shift div 1000000,
Shift rem 1000000,
0},
@ -1711,6 +1711,16 @@ stop_node(From, Host, ENode, Action, XData) ->
{result, []}.
get_last_info(User, Server) ->
ML = lists:member(mod_last, gen_mod:loaded_modules(Server)),
MLO = lists:member(mod_last_odbc, gen_mod:loaded_modules(Server)),
case {ML, MLO} of
{true, _} -> mod_last:get_last_info(User, Server);
{false, true} -> mod_last_odbc:get_last_info(User, Server);
{false, false} -> not_found
end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
adhoc_sm_commands(_Acc, From,

View File

@ -18,6 +18,7 @@
process_sm_iq/3,
on_presence_update/4,
store_last_info/4,
get_last_info/2,
remove_user/2]).
-include("ejabberd.hrl").
@ -100,6 +101,7 @@ process_sm_iq(From, To, #iq{type = Type, sub_el = SubEl} = IQ) ->
end
end.
%% TODO: This function could use get_last_info/2
get_last(IQ, SubEl, LUser, LServer) ->
case catch mnesia:dirty_read(last_activity, {LUser, LServer}) of
{'EXIT', _Reason} ->
@ -135,6 +137,16 @@ store_last_info(User, Server, TimeStamp, Status) ->
end,
mnesia:transaction(F).
%% Returns: {ok, Timestamp, Status} | not_found
get_last_info(LUser, LServer) ->
case catch mnesia:dirty_read(last_activity, {LUser, LServer}) of
{'EXIT', _Reason} ->
not_found;
[] ->
not_found;
[#last_activity{timestamp = TimeStamp, status = Status}] ->
{ok, TimeStamp, Status}
end.
remove_user(User, Server) ->
LUser = jlib:nodeprep(User),

View File

@ -18,6 +18,7 @@
process_sm_iq/3,
on_presence_update/4,
store_last_info/4,
get_last_info/2,
remove_user/2]).
-include("ejabberd.hrl").
@ -92,6 +93,7 @@ process_sm_iq(From, To, #iq{type = Type, sub_el = SubEl} = IQ) ->
end
end.
%% TODO: This function could use get_last_info/2
get_last(IQ, SubEl, LUser, LServer) ->
Username = ejabberd_odbc:escape(LUser),
case catch odbc_queries:get_last(LServer, Username) of
@ -129,6 +131,22 @@ store_last_info(User, Server, TimeStamp, Status) ->
State = ejabberd_odbc:escape(Status),
odbc_queries:set_last_t(LServer, Username, Seconds, State).
%% Returns: {ok, Timestamp, Status} | not_found
get_last_info(LUser, LServer) ->
Username = ejabberd_odbc:escape(LUser),
case catch odbc_queries:get_last(LServer, Username) of
{'EXIT', _Reason} ->
not_found;
{selected, ["seconds","state"], []} ->
not_found;
{selected, ["seconds","state"], [{STimeStamp, Status}]} ->
case catch list_to_integer(STimeStamp) of
TimeStamp when is_integer(TimeStamp) ->
{ok, TimeStamp, Status};
_ ->
not_found
end
end.
remove_user(User, Server) ->
LUser = jlib:nodeprep(User),