mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
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.
This commit is contained in:
parent
f96074057c
commit
c47252aea1
@ -1156,16 +1156,16 @@ handle_info({route, From, To, Packet}, StateName, StateData) ->
|
||||
Attrs1 = lists:keydelete("type", 1, Attrs),
|
||||
{true, [{"type", "unavailable"} | Attrs1], StateData};
|
||||
"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(
|
||||
@ -1824,18 +1824,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 = To#jid.user,
|
||||
Server = To#jid.server,
|
||||
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).
|
||||
|
||||
presence_broadcast(StateData, From, JIDSet, Packet) ->
|
||||
lists:foreach(fun(JID) ->
|
||||
|
Loading…
Reference in New Issue
Block a user