Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/processone/ejabberd.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2015-02-11 18:12:08 +0300
committerHolger Weiss <holger@zedat.fu-berlin.de>2015-02-11 18:12:08 +0300
commitbc7f93ad1ee86c10f19cde6882b5524f410c4c11 (patch)
tree05955b10631d71337f6779585a8d4b6d33fc896f /src/mod_carboncopy.erl
parent9f822dd2b89cba5cb1c69848a30cb271c6045a4d (diff)
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).
Diffstat (limited to 'src/mod_carboncopy.erl')
-rw-r--r--src/mod_carboncopy.erl7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/mod_carboncopy.erl b/src/mod_carboncopy.erl
index 6efa69f72..08725ba5e 100644
--- a/src/mod_carboncopy.erl
+++ b/src/mod_carboncopy.erl
@@ -165,6 +165,7 @@ remove_connection(User, Server, Resource, _Status)->
send_copies(JID, To, Packet, Direction)->
{U, S, R} = jlib:jid_tolower(JID),
PrioRes = ejabberd_sm:get_user_present_resources(U, S),
+ {_, AvailRs} = lists:unzip(PrioRes),
{MaxPrio, MaxRes} = case catch lists:max(PrioRes) of
{Prio, Res} -> {Prio, Res};
_ -> {0, undefined}
@@ -186,7 +187,8 @@ send_copies(JID, To, Packet, Direction)->
{true, MaxRes} ->
OrigTo = fun(Res) -> lists:member({MaxPrio, Res}, PrioRes) end,
[ {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, _} ->
%% The message was sent to our bare JID, and we currently have
%% multiple resources with the same highest priority, so the session
@@ -196,7 +198,8 @@ send_copies(JID, To, Packet, Direction)->
[];
{false, _} ->
[ {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) ]),
end,