From ad2d3964ef28011e36c1cdf0d5f8696c4504a91d Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Fri, 30 May 2014 23:32:18 +0200 Subject: Don't send XEP-0280 v1 copies back to sender An earlier version of XEP-0280 specified the and tags to be siblings of the element, whereas the current version mandates them to be parents of . The mod_carboncopy module supports both variants. However, the check that makes sure clients won't receive a copy of the messages they sent didn't work for the old-style schema. This is now fixed. --- src/mod_carboncopy.erl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/mod_carboncopy.erl b/src/mod_carboncopy.erl index 124a15f35..009d17ed2 100644 --- a/src/mod_carboncopy.erl +++ b/src/mod_carboncopy.erl @@ -153,9 +153,14 @@ check_and_forward(JID, To, #xmlel{name = <<"message">>, attrs = Attrs} = Packet, if SubTag == false -> send_copies(JID, To, Packet, Direction); true -> - case xml:get_subtag(SubTag,<<"forwarded">>) of + case xml:get_subtag(Packet,<<"forwarded">>) of false-> - send_copies(JID, To, Packet, Direction); + case xml:get_subtag(SubTag,<<"forwarded">>) of + false -> + send_copies(JID, To, Packet, Direction); + _ -> + stop + end; _ -> stop end -- cgit v1.2.3 From bb952f9ecc7dac549ace3ac0d02cb5621e1749e8 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Fri, 30 May 2014 23:36:02 +0200 Subject: Let is_carbon_copy/1 recognize carbons The mod_carboncopy:is_carbon_copy/1 function now returns true not only for , but also for carbon copies. --- src/mod_carboncopy.erl | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/mod_carboncopy.erl b/src/mod_carboncopy.erl index 009d17ed2..4cf3bed71 100644 --- a/src/mod_carboncopy.erl +++ b/src/mod_carboncopy.erl @@ -57,15 +57,19 @@ version :: binary() | matchspec_atom()}). is_carbon_copy(Packet) -> - case xml:get_subtag(Packet, <<"sent">>) of - #xmlel{name= <<"sent">>, attrs = AAttrs} -> - case xml:get_attr_s(<<"xmlns">>, AAttrs) of - ?NS_CC_2 -> true; - ?NS_CC_1 -> true; - _ -> false - end; + is_carbon_copy(Packet, <<"sent">>) orelse + is_carbon_copy(Packet, <<"received">>). + +is_carbon_copy(Packet, Direction) -> + case xml:get_subtag(Packet, Direction) of + #xmlel{name = Direction, attrs = Attrs} -> + case xml:get_attr_s(<<"xmlns">>, Attrs) of + ?NS_CC_2 -> true; + ?NS_CC_1 -> true; _ -> false - end. + end; + _ -> false + end. start(Host, Opts) -> IQDisc = gen_mod:get_opt(iqdisc, Opts,fun gen_iq_handler:check_type/1, one_queue), -- cgit v1.2.3 From f45654a16a8f8b1c7704c55d9da23422d083b459 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Fri, 30 May 2014 23:44:19 +0200 Subject: Simplify mod_carboncopy:check_and_forward/4 Use the existing is_carbon_copy/1 function, and combine multiple case clauses into a single one. --- src/mod_carboncopy.erl | 52 ++++++++++++++------------------------------------ 1 file changed, 14 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/mod_carboncopy.erl b/src/mod_carboncopy.erl index 4cf3bed71..9c8494bba 100644 --- a/src/mod_carboncopy.erl +++ b/src/mod_carboncopy.erl @@ -143,44 +143,20 @@ user_receive_packet(JID, _From, To, Packet) -> % - do not support "private" message mode, and do not modify the original packet in any way % - we also replicate "read" notifications check_and_forward(JID, To, #xmlel{name = <<"message">>, attrs = Attrs} = Packet, Direction)-> - case xml:get_attr_s(<<"type">>, Attrs) of - <<"chat">> -> - case xml:get_subtag(Packet, <<"private">>) of - false -> - case xml:get_subtag(Packet, <<"no-copy">>) of - false -> - case xml:get_subtag(Packet,<<"received">>) of - false -> - %% We must check if a packet contains "" - %% tags in order to avoid receiving message back to original sender. - SubTag = xml:get_subtag(Packet,<<"sent">>), - if SubTag == false -> - send_copies(JID, To, Packet, Direction); - true -> - case xml:get_subtag(Packet,<<"forwarded">>) of - false-> - case xml:get_subtag(SubTag,<<"forwarded">>) of - false -> - send_copies(JID, To, Packet, Direction); - _ -> - stop - end; - _ -> - stop - end - end; - _ -> - %% stop the hook chain, we don't want mod_logdb to register this message (duplicate) - stop - end; - _ -> - ok - end; - _ -> - ok - end; - _ -> - ok + case xml:get_attr_s(<<"type">>, Attrs) == <<"chat">> andalso + xml:get_subtag(Packet, <<"private">>) == false andalso + xml:get_subtag(Packet, <<"no-copy">>) == false of + true -> + case is_carbon_copy(Packet) of + false -> + send_copies(JID, To, Packet, Direction); + true -> + %% stop the hook chain, we don't want mod_logdb to register + %% this message (duplicate) + stop + end; + _ -> + ok end; check_and_forward(_JID, _To, _Packet, _)-> ok. -- cgit v1.2.3