From 614f13714c9f17fb6348cd9245231177177f8595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=B6hler?= Date: Fri, 5 Nov 2010 03:29:32 +0100 Subject: [PATCH] Use c2s state data as user and server in ejabberd_c2s:is_privacy_allow is_privacy_allow is only used in ejabberd_c2s:handle_info/3 to determine for a few presence types whether the packet is allowed to be forwarded to the user's client. This only makes sense if To#jid.user and To#jid.server match StateData#state.user and StateData#state.server. Also, add the atom in as parameter to a new argument Dir of is_privacy_allow and extract from that function privacy_check_packet(StateData, From, To, Packet, Dir) which runs the privavcy check without converting allow/deny to true/false. --- src/ejabberd_c2s.erl | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index b894a59e8..0b119a414 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -1203,16 +1203,16 @@ handle_info({route, From, To, Packet}, StateName, StateData) -> StateData#state.pres_a), {true, Attrs, StateData#state{pres_a = NewA}}; 'subscribe' -> - SRes = is_privacy_allow(From, To, Packet, StateData#state.privacy_list), + SRes = is_privacy_allow(StateData, From, To, Packet, in), {SRes, Attrs, StateData}; 'subscribed' -> - SRes = is_privacy_allow(From, To, Packet, StateData#state.privacy_list), + SRes = is_privacy_allow(StateData, From, To, Packet, in), {SRes, Attrs, StateData}; 'unsubscribe' -> - SRes = is_privacy_allow(From, To, Packet, StateData#state.privacy_list), + SRes = is_privacy_allow(StateData, From, To, Packet, in), {SRes, Attrs, StateData}; 'unsubscribed' -> - SRes = is_privacy_allow(From, To, Packet, StateData#state.privacy_list), + SRes = is_privacy_allow(StateData, From, To, Packet, in), {SRes, Attrs, StateData}; _ -> case ejabberd_hooks:run_fold( @@ -1852,18 +1852,19 @@ check_privacy_route(From, StateData, FromRoute, To, Packet) -> ejabberd_router:route(FromRoute, To, Packet) end. +privacy_check_packet(StateData, From, To, Packet, Dir) -> + ejabberd_hooks:run_fold( + privacy_check_packet, StateData#state.server, + allow, + [StateData#state.user, + StateData#state.server, + StateData#state.privacy_list, + {From, To, Packet}, + Dir]). + %% Check if privacy rules allow this delivery -is_privacy_allow(From, To, Packet, PrivacyList) -> - User = exmpp_jid:prep_node(To), - Server = exmpp_jid:prep_domain(To), - allow == ejabberd_hooks:run_fold( - privacy_check_packet, Server, - allow, - [User, - Server, - PrivacyList, - {From, To, Packet}, - in]). +is_privacy_allow(StateData, From, To, Packet, Dir) -> + allow == privacy_check_packet(StateData, From, To, Packet, Dir). %% Send presence when disconnecting presence_broadcast(StateData, From, JIDSet, Packet) ->