25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-30 16:36:29 +01:00

Patch core for GS (thanks to Stephan Maka)

This commit is contained in:
Badlop 2010-07-22 18:44:00 +02:00
parent a7d9fa7301
commit 511f73812d
3 changed files with 41 additions and 4 deletions

View File

@ -36,6 +36,9 @@
%% Accounts
register/3, unregister/2,
registered_users/1,
%% For debugging gen_storage
get_last_info/0,
get_last_info/2,
%% Migration jabberd1.4
import_file/1, import_dir/1,
%% Purge DB
@ -124,6 +127,21 @@ commands() ->
args = [{host, string}],
result = {users, {list, {username, string}}}},
#ejabberd_commands{name = gli, tags = [accounts],
desc = "Get information about last access of an account",
module = ?MODULE, function = get_last_info,
args = [],
result = {lastinfo, {tuple, [{timestamp, integer},
{status, string}
]}}},
#ejabberd_commands{name = get_last_info, tags = [accounts],
desc = "Get information about last access of an account",
module = ?MODULE, function = get_last_info,
args = [{user, string}, {host, string}],
result = {lastinfo, {tuple, [{timestamp, integer},
{status, string}
]}}},
#ejabberd_commands{name = import_file, tags = [mnesia],
desc = "Import user data from jabberd14 spool file",
module = ?MODULE, function = import_file,
@ -333,6 +351,12 @@ registered_users(Host) ->
SUsers = lists:sort(Users),
lists:map(fun({U, _S}) -> U end, SUsers).
get_last_info() -> get_last_info("badlop", "localhost").
get_last_info(User, Server) ->
case mod_last:get_last_info(User, Server) of
{ok, TimeStamp, Status} -> {TimeStamp, Status};
not_found -> {"never", ""}
end.
%%%
%%% Migration management

View File

@ -214,7 +214,7 @@ now_to_local_string({MegaSecs, Secs, MicroSecs}) ->
[Year, Month, Day, Hour, Minute, Second, MicroSecs, Sign, H, M])).
% yyyy-mm-ddThh:mm:ss[.sss]{Z|{+|-}hh:mm} -> {MegaSecs, Secs, MicroSecs}
% {yyyy-mm-dd|yyyymmdd}Thh:mm:ss[.sss]{|Z|{+|-}hh:mm} -> {MegaSecs, Secs, MicroSecs} | undefined
datetime_string_to_timestamp(TimeStr) ->
case catch parse_datetime(TimeStr) of
{'EXIT', _Err} ->
@ -232,9 +232,13 @@ parse_datetime(TimeStr) ->
Seconds = (S - S1) - TZH * 60 * 60 - TZM * 60,
{Seconds div 1000000, Seconds rem 1000000, MS}.
% yyyy-mm-dd
% yyyy-mm-dd | yyyymmdd
parse_date(Date) ->
[Y, M, D] = string:tokens(Date, "-"),
{Y, M, D} =
case string:tokens(Date, "-") of
[Y1, M1, D1] -> {Y1, M1, D1};
[[Y1, Y2, Y3, Y4, M1, M2, D1, D2]] -> {[Y1, Y2, Y3, Y4], [M1, M2], [D1, D2]}
end,
Date1 = {list_to_integer(Y), list_to_integer(M), list_to_integer(D)},
case calendar:valid_date(Date1) of
true ->
@ -259,7 +263,8 @@ parse_time_with_timezone(Time) ->
0 ->
case string:str(Time, "-") of
0 ->
false;
{TT, MS} = parse_time1(Time),
{TT, MS, 0, 0};
_ ->
parse_time_with_timezone(Time, "-")
end;

View File

@ -38,6 +38,7 @@
sql_query_t/1,
sql_transaction/2,
sql_bloc/2,
db_type/1,
escape/1,
escape_like/1,
to_bool/1,
@ -164,6 +165,10 @@ sql_query_t(Query) ->
QRes
end.
db_type(Host) ->
?GEN_FSM:sync_send_event(ejabberd_odbc_sup:get_random_pid(Host),
db_type, 60000).
%% Escape character that will confuse an SQL engine
escape(S) when is_list(S) ->
[odbc_queries:escape(C) || C <- S];
@ -277,6 +282,9 @@ session_established(Request, {Who, _Ref}, State) ->
session_established({sql_cmd, Command, From, Timestamp}, State) ->
run_sql_cmd(Command, From, State, Timestamp);
session_established(db_type, State) ->
Reply = State#state.db_type,
{reply, Reply, session_established, State};
session_established(Event, State) ->
?WARNING_MSG("unexpected event in 'session_established': ~p", [Event]),
{next_state, session_established, State}.