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

Check availability before carbon copying

Before generating a carbon copy for a resource, make sure it's actually
available.  This handles the case where, for some reason, the
'unset_presence_hook' wasn't called during logout of a resource.  Carbon
copies sent to that resource would otherwise be re-routed to another
resource (which might've received a copy of that message already).
This commit is contained in:
Holger Weiss 2015-02-11 16:12:08 +01:00
parent 9f822dd2b8
commit bc7f93ad1e

View File

@ -165,6 +165,7 @@ remove_connection(User, Server, Resource, _Status)->
send_copies(JID, To, Packet, Direction)-> send_copies(JID, To, Packet, Direction)->
{U, S, R} = jlib:jid_tolower(JID), {U, S, R} = jlib:jid_tolower(JID),
PrioRes = ejabberd_sm:get_user_present_resources(U, S), PrioRes = ejabberd_sm:get_user_present_resources(U, S),
{_, AvailRs} = lists:unzip(PrioRes),
{MaxPrio, MaxRes} = case catch lists:max(PrioRes) of {MaxPrio, MaxRes} = case catch lists:max(PrioRes) of
{Prio, Res} -> {Prio, Res}; {Prio, Res} -> {Prio, Res};
_ -> {0, undefined} _ -> {0, undefined}
@ -186,7 +187,8 @@ send_copies(JID, To, Packet, Direction)->
{true, MaxRes} -> {true, MaxRes} ->
OrigTo = fun(Res) -> lists:member({MaxPrio, Res}, PrioRes) end, OrigTo = fun(Res) -> lists:member({MaxPrio, Res}, PrioRes) end,
[ {jlib:make_jid({U, S, CCRes}), CC_Version} [ {jlib:make_jid({U, S, CCRes}), CC_Version}
|| {CCRes, CC_Version} <- list(U, S), not OrigTo(CCRes) ]; || {CCRes, CC_Version} <- list(U, S),
lists:member(CCRes, AvailRs), not OrigTo(CCRes) ];
{true, _} -> {true, _} ->
%% The message was sent to our bare JID, and we currently have %% The message was sent to our bare JID, and we currently have
%% multiple resources with the same highest priority, so the session %% multiple resources with the same highest priority, so the session
@ -196,7 +198,8 @@ send_copies(JID, To, Packet, Direction)->
[]; [];
{false, _} -> {false, _} ->
[ {jlib:make_jid({U, S, CCRes}), CC_Version} [ {jlib:make_jid({U, S, CCRes}), CC_Version}
|| {CCRes, CC_Version} <- list(U, S), CCRes /= R ] || {CCRes, CC_Version} <- list(U, S),
lists:member(CCRes, AvailRs), CCRes /= R ]
%TargetJIDs = lists:delete(JID, [ jlib:make_jid({U, S, CCRes}) || CCRes <- list(U, S) ]), %TargetJIDs = lists:delete(JID, [ jlib:make_jid({U, S, CCRes}) || CCRes <- list(U, S) ]),
end, end,