]> granicus.if.org Git - ejabberd/commitdiff
Let mod_carboncopy mark copied messages
authorHolger Weiss <holger@zedat.fu-berlin.de>
Tue, 22 Nov 2016 21:21:34 +0000 (22:21 +0100)
committerHolger Weiss <holger@zedat.fu-berlin.de>
Tue, 22 Nov 2016 21:21:34 +0000 (22:21 +0100)
Carbon copies are now marked with a 'carbon_copy' flag.  This makes it
easier to identify them.

src/ejabberd_c2s.erl
src/mod_carboncopy.erl

index 7ef708d314088e32b6b67395c452ca56ed1da285..6d84d8d93724529d324eb6973b76ad6f24137d2e 100644 (file)
@@ -2645,44 +2645,30 @@ handle_unacked_stanzas(#state{mgmt_state = MgmtState} = StateData)
                Txt = <<"User session terminated">>,
                ejabberd_router:route_error(
                  To, From, El, xmpp:err_service_unavailable(Txt, Lang));
+          (From, _To, #message{meta = #{carbon_copy := true}}, _Time) ->
+               %% XEP-0280 says: "When a receiving server attempts to deliver a
+               %% forked message, and that message bounces with an error for
+               %% any reason, the receiving server MUST NOT forward that error
+               %% back to the original sender."  Resending such a stanza could
+               %% easily lead to unexpected results as well.
+               ?DEBUG("Dropping forwarded message stanza from ~s",
+                      [jid:to_string(From)]);
           (From, To, El, Time) ->
-               %% We'll drop the stanza if it was <forwarded/> by some
-               %% encapsulating protocol as per XEP-0297.  One such protocol is
-               %% XEP-0280, which says: "When a receiving server attempts to
-               %% deliver a forked message, and that message bounces with an
-               %% error for any reason, the receiving server MUST NOT forward
-               %% that error back to the original sender."  Resending such a
-               %% stanza could easily lead to unexpected results as well.
-               case is_encapsulated_forward(El) of
+               case ejabberd_hooks:run_fold(message_is_archived,
+                                            StateData#state.server, false,
+                                            [StateData, From,
+                                             StateData#state.jid, El]) of
                  true ->
-                     ?DEBUG("Dropping forwarded message stanza from ~s",
-                            [jid:to_string(From)]);
+                     ?DEBUG("Dropping archived message stanza from ~p",
+                            [jid:to_string(xmpp:get_from(El))]);
                  false ->
-                     case ejabberd_hooks:run_fold(message_is_archived,
-                                                  StateData#state.server,
-                                                  false,
-                                                  [StateData, From,
-                                                   StateData#state.jid, El]) of
-                       true ->
-                           ?DEBUG("Dropping archived message stanza from ~p",
-                                  [jid:to_string(xmpp:get_from(El))]);
-                       false ->
-                           ReRoute(From, To, El, Time)
-                     end
+                     ReRoute(From, To, El, Time)
                end
        end,
     handle_unacked_stanzas(StateData, F);
 handle_unacked_stanzas(_StateData) ->
     ok.
 
--spec is_encapsulated_forward(stanza()) -> boolean().
-is_encapsulated_forward(#message{} = Msg) ->
-    xmpp:has_subtag(Msg, #forwarded{}) orelse
-       xmpp:has_subtag(Msg, #carbons_sent{}) orelse
-       xmpp:has_subtag(Msg, #carbons_received{});
-is_encapsulated_forward(_El) ->
-    false.
-
 -spec inherit_session_state(state(), binary()) -> {ok, state()} |
                                                  {error, binary()} |
                                                  {error, binary(), non_neg_integer()}.
index f1eb3e7900a4e687f0c86eadc45c41bffa465190..5839a65b29c08e28a335c6be015ae66a4e12acc7 100644 (file)
 -callback list(binary(), binary()) -> [{binary(), binary()}].
 
 -spec is_carbon_copy(stanza()) -> boolean().
-is_carbon_copy(Packet) ->
-    xmpp:has_subtag(Packet, #carbons_sent{}) orelse
-       xmpp:has_subtag(Packet, #carbons_received{}).
+is_carbon_copy(#message{meta = #{carbon_copy := true}}) ->
+    true;
+is_carbon_copy(_) ->
+    false.
 
 start(Host, Opts) ->
     IQDisc = gen_mod:get_opt(iqdisc, Opts,fun gen_iq_handler:check_type/1, one_queue),
@@ -203,7 +204,8 @@ build_forward_packet(JID, #message{type = T} = Msg, Sender, Dest, Direction) ->
                 sent -> #carbons_sent{forwarded = Forwarded};
                 received -> #carbons_received{forwarded = Forwarded}
             end,
-    #message{from = Sender, to = Dest, type = T, sub_els = [Carbon]}.
+    #message{from = Sender, to = Dest, type = T, sub_els = [Carbon],
+            meta = #{carbon_copy => true}}.
 
 -spec enable(binary(), binary(), binary(), binary()) -> ok | {error, any()}.
 enable(Host, U, R, CC)->