]> granicus.if.org Git - ejabberd/commitdiff
Check availability before carbon copying
authorHolger Weiss <holger@zedat.fu-berlin.de>
Wed, 11 Feb 2015 15:12:08 +0000 (16:12 +0100)
committerHolger Weiss <holger@zedat.fu-berlin.de>
Wed, 11 Feb 2015 15:12:08 +0000 (16:12 +0100)
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).

src/mod_carboncopy.erl

index 6efa69f72b3329163691fae5cdad5db76fcbda40..08725ba5e099c53d70141099dccd4e53cdc203df 100644 (file)
@@ -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,