Skip to content

Commit 6c65265

Browse files
committed
mod_privacy: honor the 'order' attribute
When checking a packet against the active privacy list, make sure that the matching item with the lowest 'order' attribute is used. Bug-url: #2529 Signed-off-by: Eugene Crosser [email protected]
1 parent 2539be1 commit 6c65265

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/mod_privacy.erl

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -584,30 +584,37 @@ do_check_packet(#jid{luser = LUser, lserver = LServer}, List, Packet, Dir) ->
584584
roster_get_jid_info, LServer,
585585
{none, none, []},
586586
[LUser, LServer, LJID]),
587-
check_packet_aux(List, PType2, LJID, Subscription, Groups)
587+
{Action, _Order} = check_packet_aux(allow, last, List, PType2, LJID,
588+
Subscription, Groups),
589+
Action
588590
end.
589591

590-
-spec check_packet_aux([listitem()],
592+
-spec check_packet_aux(allow | deny, last | integer(), [listitem()],
591593
message | iq | presence_in | presence_out | other,
592594
ljid(), none | both | from | to, [binary()]) ->
593595
allow | deny.
594596
%% Ptype = mesage | iq | presence_in | presence_out | other
595-
check_packet_aux([], _PType, _JID, _Subscription,
597+
check_packet_aux(Lastaction, Lastorder, [], _PType, _JID, _Subscription,
596598
_Groups) ->
597-
allow;
598-
check_packet_aux([Item | List], PType, JID,
599+
{Lastaction, Lastorder};
600+
check_packet_aux(Lastaction, Lastorder, [Item | List], PType, JID,
599601
Subscription, Groups) ->
600-
#listitem{type = Type, value = Value, action = Action} =
602+
#listitem{type = Type, value = Value, action = Action, order = Order} =
601603
Item,
602-
case is_ptype_match(Item, PType) of
603-
true ->
604-
case is_type_match(Type, Value, JID, Subscription, Groups) of
605-
true -> Action;
606-
false ->
607-
check_packet_aux(List, PType, JID, Subscription, Groups)
604+
Usethis = case Lastorder of
605+
last -> true;
606+
_ when Lastorder > Order ->
607+
case is_ptype_match(Item, PType) of
608+
true -> is_type_match(Type, Value, JID, Subscription, Groups);
609+
false -> false
608610
end;
609-
false ->
610-
check_packet_aux(List, PType, JID, Subscription, Groups)
611+
_ -> false
612+
end,
613+
case Usethis of
614+
true -> check_packet_aux(Action, Order,
615+
List, PType, JID, Subscription, Groups);
616+
false -> check_packet_aux(Lastaction, Lastorder,
617+
List, PType, JID, Subscription, Groups)
611618
end.
612619

613620
-spec is_ptype_match(listitem(),

0 commit comments

Comments
 (0)