aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBadlop <badlop@process-one.net>2007-11-27 18:54:06 +0000
committerBadlop <badlop@process-one.net>2007-11-27 18:54:06 +0000
commiteb330ac0e0db29c6e6dc4108f33490dec349d0b9 (patch)
tree503d45b661c1bd60852c3b0aa8db1cfb7f59cd7e
parent* doc/guide.tex: Document ejabberd_http's (diff)
* 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
-rw-r--r--ChangeLog5
-rw-r--r--src/mod_configure.erl18
-rw-r--r--src/mod_last.erl12
-rw-r--r--src/mod_last_odbc.erl18
4 files changed, 49 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 6f1a62623..0e378a08a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/src/mod_configure.erl b/src/mod_configure.erl
index 24f40b33c..e49dc7007 100644
--- a/src/mod_configure.erl
+++ b/src/mod_configure.erl
@@ -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,
diff --git a/src/mod_last.erl b/src/mod_last.erl
index 4a61f3b53..d5ee25fb7 100644
--- a/src/mod_last.erl
+++ b/src/mod_last.erl
@@ -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),
diff --git a/src/mod_last_odbc.erl b/src/mod_last_odbc.erl
index 0b0119126..3c2ab21ba 100644
--- a/src/mod_last_odbc.erl
+++ b/src/mod_last_odbc.erl
@@ -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),