Skip to content

Commit

Permalink
mod_privacy: honor the 'order' attribute
Browse files Browse the repository at this point in the history
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 crosser@average.org
  • Loading branch information
crosser committed Jul 16, 2018
1 parent 2539be1 commit 6c65265
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/mod_privacy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -584,30 +584,37 @@ do_check_packet(#jid{luser = LUser, lserver = LServer}, List, Packet, Dir) ->
roster_get_jid_info, LServer,
{none, none, []},
[LUser, LServer, LJID]),
check_packet_aux(List, PType2, LJID, Subscription, Groups)
{Action, _Order} = check_packet_aux(allow, last, List, PType2, LJID,
Subscription, Groups),
Action
end.

-spec check_packet_aux([listitem()],
-spec check_packet_aux(allow | deny, last | integer(), [listitem()],
message | iq | presence_in | presence_out | other,
ljid(), none | both | from | to, [binary()]) ->
allow | deny.
%% Ptype = mesage | iq | presence_in | presence_out | other
check_packet_aux([], _PType, _JID, _Subscription,
check_packet_aux(Lastaction, Lastorder, [], _PType, _JID, _Subscription,
_Groups) ->
allow;
check_packet_aux([Item | List], PType, JID,
{Lastaction, Lastorder};
check_packet_aux(Lastaction, Lastorder, [Item | List], PType, JID,
Subscription, Groups) ->
#listitem{type = Type, value = Value, action = Action} =
#listitem{type = Type, value = Value, action = Action, order = Order} =
Item,
case is_ptype_match(Item, PType) of
true ->
case is_type_match(Type, Value, JID, Subscription, Groups) of
true -> Action;
false ->
check_packet_aux(List, PType, JID, Subscription, Groups)
Usethis = case Lastorder of
last -> true;
_ when Lastorder > Order ->
case is_ptype_match(Item, PType) of
true -> is_type_match(Type, Value, JID, Subscription, Groups);
false -> false
end;
false ->
check_packet_aux(List, PType, JID, Subscription, Groups)
_ -> false
end,
case Usethis of
true -> check_packet_aux(Action, Order,
List, PType, JID, Subscription, Groups);
false -> check_packet_aux(Lastaction, Lastorder,
List, PType, JID, Subscription, Groups)
end.

-spec is_ptype_match(listitem(),
Expand Down

0 comments on commit 6c65265

Please sign in to comment.