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

Guard agains sm:get_user_info returning offline

This fixes issue #2765
This commit is contained in:
Paweł Chmielowski 2019-01-15 10:04:15 +01:00
parent 63259f5cc9
commit 7183fe6b80

View File

@ -987,11 +987,15 @@ get_status_list(Host, Status_required) ->
apply(Fstatus, [Status, Status_required])]. apply(Fstatus, [Status, Status_required])].
connected_users_info() -> connected_users_info() ->
lists:map( lists:filtermap(
fun({U, S, R}) -> fun({U, S, R}) ->
Info = user_session_info(U, S, R), case user_session_info(U, S, R) of
Jid = jid:encode(jid:make(U, S, R)), offline ->
erlang:insert_element(1, Info, Jid) false;
Info ->
Jid = jid:encode(jid:make(U, S, R)),
{true, erlang:insert_element(1, Info, Jid)}
end
end, end,
ejabberd_sm:dirty_get_sessions_list()). ejabberd_sm:dirty_get_sessions_list()).
@ -1054,23 +1058,31 @@ set_presence(User, Host, Resource, Type, Show, Status, Priority0) ->
ejabberd_c2s:set_presence(Ref, Pres). ejabberd_c2s:set_presence(Ref, Pres).
user_sessions_info(User, Host) -> user_sessions_info(User, Host) ->
[user_session_info(User, Host, Resource) || lists:filtermap(fun(Resource) ->
Resource <- ejabberd_sm:get_user_resources(User, Host)]. case user_session_info(User, Host, Resource) of
offline -> false;
Info -> {true, Info}
end
end, ejabberd_sm:get_user_resources(User, Host)).
user_session_info(User, Host, Resource) -> user_session_info(User, Host, Resource) ->
CurrentSec = calendar:datetime_to_gregorian_seconds({date(), time()}), CurrentSec = calendar:datetime_to_gregorian_seconds({date(), time()}),
Info = ejabberd_sm:get_user_info(User, Host, Resource), case ejabberd_sm:get_user_info(User, Host, Resource) of
Now = proplists:get_value(ts, Info), offline ->
Pid = proplists:get_value(pid, Info), offline;
{_U, _Resource, Status, StatusText} = get_presence(Pid), Info ->
Priority = proplists:get_value(priority, Info), Now = proplists:get_value(ts, Info),
Conn = proplists:get_value(conn, Info), Pid = proplists:get_value(pid, Info),
{Ip, Port} = proplists:get_value(ip, Info), {_U, _Resource, Status, StatusText} = get_presence(Pid),
IPS = inet_parse:ntoa(Ip), Priority = proplists:get_value(priority, Info),
NodeS = atom_to_list(node(Pid)), Conn = proplists:get_value(conn, Info),
Uptime = CurrentSec - calendar:datetime_to_gregorian_seconds( {Ip, Port} = proplists:get_value(ip, Info),
calendar:now_to_local_time(Now)), IPS = inet_parse:ntoa(Ip),
{atom_to_list(Conn), IPS, Port, num_prio(Priority), NodeS, Uptime, Status, Resource, StatusText}. NodeS = atom_to_list(node(Pid)),
Uptime = CurrentSec - calendar:datetime_to_gregorian_seconds(
calendar:now_to_local_time(Now)),
{atom_to_list(Conn), IPS, Port, num_prio(Priority), NodeS, Uptime, Status, Resource, StatusText}
end.
%%% %%%