26
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-26 17:38:45 +01:00

Let mod_carboncopy mark copied messages

Carbon copies are now marked with a 'carbon_copy' flag.  This makes it
easier to identify them.
This commit is contained in:
Holger Weiss 2016-11-22 22:21:34 +01:00
parent 114ca786ee
commit 3325e69ae6
2 changed files with 21 additions and 33 deletions

View File

@ -2645,44 +2645,30 @@ handle_unacked_stanzas(#state{mgmt_state = MgmtState} = StateData)
Txt = <<"User session terminated">>, Txt = <<"User session terminated">>,
ejabberd_router:route_error( ejabberd_router:route_error(
To, From, El, xmpp:err_service_unavailable(Txt, Lang)); 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) -> (From, To, El, Time) ->
%% We'll drop the stanza if it was <forwarded/> by some case ejabberd_hooks:run_fold(message_is_archived,
%% encapsulating protocol as per XEP-0297. One such protocol is StateData#state.server, false,
%% XEP-0280, which says: "When a receiving server attempts to [StateData, From,
%% deliver a forked message, and that message bounces with an StateData#state.jid, El]) of
%% 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
true -> true ->
?DEBUG("Dropping forwarded message stanza from ~s", ?DEBUG("Dropping archived message stanza from ~p",
[jid:to_string(From)]); [jid:to_string(xmpp:get_from(El))]);
false -> false ->
case ejabberd_hooks:run_fold(message_is_archived, ReRoute(From, To, El, Time)
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
end end
end, end,
handle_unacked_stanzas(StateData, F); handle_unacked_stanzas(StateData, F);
handle_unacked_stanzas(_StateData) -> handle_unacked_stanzas(_StateData) ->
ok. 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()} | -spec inherit_session_state(state(), binary()) -> {ok, state()} |
{error, binary()} | {error, binary()} |
{error, binary(), non_neg_integer()}. {error, binary(), non_neg_integer()}.

View File

@ -52,9 +52,10 @@
-callback list(binary(), binary()) -> [{binary(), binary()}]. -callback list(binary(), binary()) -> [{binary(), binary()}].
-spec is_carbon_copy(stanza()) -> boolean(). -spec is_carbon_copy(stanza()) -> boolean().
is_carbon_copy(Packet) -> is_carbon_copy(#message{meta = #{carbon_copy := true}}) ->
xmpp:has_subtag(Packet, #carbons_sent{}) orelse true;
xmpp:has_subtag(Packet, #carbons_received{}). is_carbon_copy(_) ->
false.
start(Host, Opts) -> start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts,fun gen_iq_handler:check_type/1, one_queue), 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}; sent -> #carbons_sent{forwarded = Forwarded};
received -> #carbons_received{forwarded = Forwarded} received -> #carbons_received{forwarded = Forwarded}
end, 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()}. -spec enable(binary(), binary(), binary(), binary()) -> ok | {error, any()}.
enable(Host, U, R, CC)-> enable(Host, U, R, CC)->