mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Merge 1881 from trunk.
* src/mod_privacy.erl: Privacy List: deny presence-out all + send presence to: presence is sent (EJAB-255) * src/ejabberd_c2s.erl: Likewise SVN Revision: 1948
This commit is contained in:
parent
890b1c4f60
commit
5bfdb71b4c
@ -1,5 +1,9 @@
|
|||||||
2009-03-03 Badlop <badlop@process-one.net>
|
2009-03-03 Badlop <badlop@process-one.net>
|
||||||
|
|
||||||
|
* src/mod_privacy.erl: Privacy List: deny presence-out all + send
|
||||||
|
presence to: presence is sent (EJAB-255)
|
||||||
|
* src/ejabberd_c2s.erl: Likewise
|
||||||
|
|
||||||
* src/mod_privacy.erl: Only run roster_get_jid_info if privacy
|
* src/mod_privacy.erl: Only run roster_get_jid_info if privacy
|
||||||
list has subscription or group (thanks to George Hazan)(EJAB-851).
|
list has subscription or group (thanks to George Hazan)(EJAB-851).
|
||||||
Sort items in privacy list by order before storing (EJAB-848)
|
Sort items in privacy list by order before storing (EJAB-848)
|
||||||
|
@ -877,8 +877,8 @@ session_established2(El, StateData) ->
|
|||||||
user_send_packet,
|
user_send_packet,
|
||||||
Server,
|
Server,
|
||||||
[FromJID, ToJID, NewEl]),
|
[FromJID, ToJID, NewEl]),
|
||||||
ejabberd_router:route(
|
check_privacy_route(FromJID, StateData, FromJID,
|
||||||
FromJID, ToJID, NewEl),
|
ToJID, NewEl),
|
||||||
StateData
|
StateData
|
||||||
end;
|
end;
|
||||||
#xmlel{ns = ?NS_JABBER_CLIENT, name = 'message'} ->
|
#xmlel{ns = ?NS_JABBER_CLIENT, name = 'message'} ->
|
||||||
@ -1500,16 +1500,16 @@ presence_update(From, Packet, StateData) ->
|
|||||||
%% User sends a directed presence packet
|
%% User sends a directed presence packet
|
||||||
presence_track(From, To, Packet, StateData) ->
|
presence_track(From, To, Packet, StateData) ->
|
||||||
LTo = jlib:short_prepd_jid(To),
|
LTo = jlib:short_prepd_jid(To),
|
||||||
BFrom = exmpp_jid:jid_to_bare_jid(From),
|
|
||||||
case exmpp_presence:get_type(Packet) of
|
case exmpp_presence:get_type(Packet) of
|
||||||
'unavailable' ->
|
'unavailable' ->
|
||||||
ejabberd_router:route(From, To, Packet),
|
check_privacy_route(From, StateData, From, To, Packet),
|
||||||
I = remove_element(LTo, StateData#state.pres_i),
|
I = remove_element(LTo, StateData#state.pres_i),
|
||||||
A = remove_element(LTo, StateData#state.pres_a),
|
A = remove_element(LTo, StateData#state.pres_a),
|
||||||
StateData#state{pres_i = I,
|
StateData#state{pres_i = I,
|
||||||
pres_a = A};
|
pres_a = A};
|
||||||
'invisible' ->
|
'invisible' ->
|
||||||
ejabberd_router:route(From, To, Packet),
|
ejabberd_router:route(From, To, Packet),
|
||||||
|
check_privacy_route(From, StateData, From, To, Packet),
|
||||||
I = ?SETS:add_element(LTo, StateData#state.pres_i),
|
I = ?SETS:add_element(LTo, StateData#state.pres_i),
|
||||||
A = remove_element(LTo, StateData#state.pres_a),
|
A = remove_element(LTo, StateData#state.pres_a),
|
||||||
StateData#state{pres_i = I,
|
StateData#state{pres_i = I,
|
||||||
@ -1518,52 +1518,59 @@ presence_track(From, To, Packet, StateData) ->
|
|||||||
ejabberd_hooks:run(roster_out_subscription,
|
ejabberd_hooks:run(roster_out_subscription,
|
||||||
StateData#state.server,
|
StateData#state.server,
|
||||||
[StateData#state.user, StateData#state.server, To, subscribe]),
|
[StateData#state.user, StateData#state.server, To, subscribe]),
|
||||||
ejabberd_router:route(BFrom, To, Packet),
|
check_privacy_route(From, StateData, exmpp_jid:jid_to_bare_jid(From),
|
||||||
|
To, Packet),
|
||||||
StateData;
|
StateData;
|
||||||
'subscribed' ->
|
'subscribed' ->
|
||||||
ejabberd_hooks:run(roster_out_subscription,
|
ejabberd_hooks:run(roster_out_subscription,
|
||||||
StateData#state.server,
|
StateData#state.server,
|
||||||
[StateData#state.user, StateData#state.server, To, subscribed]),
|
[StateData#state.user, StateData#state.server, To, subscribed]),
|
||||||
ejabberd_router:route(BFrom, To, Packet),
|
check_privacy_route(From, StateData, exmpp_jid:jid_to_bare_jid(From),
|
||||||
|
To, Packet),
|
||||||
StateData;
|
StateData;
|
||||||
'unsubscribe' ->
|
'unsubscribe' ->
|
||||||
ejabberd_hooks:run(roster_out_subscription,
|
ejabberd_hooks:run(roster_out_subscription,
|
||||||
StateData#state.server,
|
StateData#state.server,
|
||||||
[StateData#state.user, StateData#state.server, To, unsubscribe]),
|
[StateData#state.user, StateData#state.server, To, unsubscribe]),
|
||||||
ejabberd_router:route(BFrom, To, Packet),
|
check_privacy_route(From, StateData, exmpp_jid:jid_to_bare_jid(From),
|
||||||
|
To, Packet),
|
||||||
StateData;
|
StateData;
|
||||||
'unsubscribed' ->
|
'unsubscribed' ->
|
||||||
ejabberd_hooks:run(roster_out_subscription,
|
ejabberd_hooks:run(roster_out_subscription,
|
||||||
StateData#state.server,
|
StateData#state.server,
|
||||||
[StateData#state.user, StateData#state.server, To, unsubscribed]),
|
[StateData#state.user, StateData#state.server, To, unsubscribed]),
|
||||||
ejabberd_router:route(BFrom, To, Packet),
|
check_privacy_route(From, StateData, exmpp_jid:jid_to_bare_jid(From),
|
||||||
|
To, Packet),
|
||||||
StateData;
|
StateData;
|
||||||
'error' ->
|
'error' ->
|
||||||
ejabberd_router:route(From, To, Packet),
|
check_privacy_route(From, StateData, From, To, Packet),
|
||||||
StateData;
|
StateData;
|
||||||
'probe' ->
|
'probe' ->
|
||||||
ejabberd_router:route(From, To, Packet),
|
check_privacy_route(From, StateData, From, To, Packet),
|
||||||
StateData;
|
StateData;
|
||||||
_ ->
|
_ ->
|
||||||
case ejabberd_hooks:run_fold(
|
check_privacy_route(From, StateData, From, To, Packet),
|
||||||
privacy_check_packet, StateData#state.server,
|
|
||||||
allow,
|
|
||||||
[StateData#state.user,
|
|
||||||
StateData#state.server,
|
|
||||||
StateData#state.privacy_list,
|
|
||||||
{From, To, Packet},
|
|
||||||
out]) of
|
|
||||||
deny ->
|
|
||||||
ok;
|
|
||||||
allow ->
|
|
||||||
ejabberd_router:route(From, To, Packet)
|
|
||||||
end,
|
|
||||||
I = remove_element(LTo, StateData#state.pres_i),
|
I = remove_element(LTo, StateData#state.pres_i),
|
||||||
A = ?SETS:add_element(LTo, StateData#state.pres_a),
|
A = ?SETS:add_element(LTo, StateData#state.pres_a),
|
||||||
StateData#state{pres_i = I,
|
StateData#state{pres_i = I,
|
||||||
pres_a = A}
|
pres_a = A}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
check_privacy_route(From, StateData, FromRoute, To, Packet) ->
|
||||||
|
case ejabberd_hooks:run_fold(
|
||||||
|
privacy_check_packet, StateData#state.server,
|
||||||
|
allow,
|
||||||
|
[StateData#state.user,
|
||||||
|
StateData#state.server,
|
||||||
|
StateData#state.privacy_list,
|
||||||
|
{From, To, Packet},
|
||||||
|
out]) of
|
||||||
|
deny ->
|
||||||
|
ok;
|
||||||
|
allow ->
|
||||||
|
ejabberd_router:route(FromRoute, To, Packet)
|
||||||
|
end.
|
||||||
|
|
||||||
presence_broadcast(StateData, From, JIDSet, Packet) ->
|
presence_broadcast(StateData, From, JIDSet, Packet) ->
|
||||||
lists:foreach(fun({U, S, R}) ->
|
lists:foreach(fun({U, S, R}) ->
|
||||||
FJID = exmpp_jid:make_jid(U, S, R),
|
FJID = exmpp_jid:make_jid(U, S, R),
|
||||||
|
@ -561,9 +561,12 @@ get_user_list(_, User, Server)
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
%% From is the sender, To is the destination.
|
||||||
|
%% If Dir = out, User@Server is the sender account (From).
|
||||||
|
%% If Dir = in, User@Server is the destination account (To).
|
||||||
check_packet(_, User, Server,
|
check_packet(_, User, Server,
|
||||||
#userlist{list = List, needdb = NeedDb},
|
#userlist{list = List, needdb = NeedDb},
|
||||||
{From, To, #xmlel{name = PName}},
|
{From, To, #xmlel{name = PName, attrs = Attrs}},
|
||||||
Dir) when
|
Dir) when
|
||||||
PName =:= message ;
|
PName =:= message ;
|
||||||
PName =:= iq ;
|
PName =:= iq ;
|
||||||
@ -572,48 +575,42 @@ check_packet(_, User, Server,
|
|||||||
[] ->
|
[] ->
|
||||||
allow;
|
allow;
|
||||||
_ ->
|
_ ->
|
||||||
case {PName, Dir} of
|
PType = case PName of
|
||||||
{message, in} ->
|
'message' -> message;
|
||||||
LJID = jlib:short_prepd_jid(From),
|
'iq' -> iq;
|
||||||
{Subscription, Groups} =
|
'presence' ->
|
||||||
case NeedDb of
|
case xml:get_attr_s("type", Attrs) of
|
||||||
true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, From]);
|
%% notification
|
||||||
false -> {[], []}
|
'' -> presence;
|
||||||
end,
|
'unavailable' -> presence;
|
||||||
check_packet_aux(List, message,
|
%% subscribe, subscribed, unsubscribe,
|
||||||
LJID, Subscription, Groups);
|
%% unsubscribed, error, probe, or other
|
||||||
{iq, in} ->
|
_ -> other
|
||||||
LJID = jlib:short_prepd_jid(From),
|
end
|
||||||
{Subscription, Groups} =
|
end,
|
||||||
case NeedDb of
|
PType2 = case {PType, Dir} of
|
||||||
true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, From]);
|
{message, in} -> message;
|
||||||
false -> {[], []}
|
{iq, in} -> iq;
|
||||||
end,
|
{presence, in} -> presence_in;
|
||||||
check_packet_aux(List, iq,
|
{presence, out} -> presence_out;
|
||||||
LJID, Subscription, Groups);
|
{_, _} -> other
|
||||||
{presence, in} ->
|
end,
|
||||||
LJID = jlib:short_prepd_jid(From),
|
LJID = case Dir of
|
||||||
{Subscription, Groups} =
|
in -> From;
|
||||||
case NeedDb of
|
out -> To
|
||||||
true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, From]);
|
end,
|
||||||
false -> {[], []}
|
{Subscription, Groups} =
|
||||||
end,
|
case NeedDb of
|
||||||
check_packet_aux(List, presence_in,
|
true -> ejabberd_hooks:run_fold(roster_get_jid_info,
|
||||||
LJID, Subscription, Groups);
|
exmpp_stringprep:nameprep(Server),
|
||||||
{presence, out} ->
|
{none, []},
|
||||||
LJID = jlib:short_prepd_jid(To),
|
[User, Server, LJID]);
|
||||||
{Subscription, Groups} =
|
false -> {[], []}
|
||||||
case NeedDb of
|
end,
|
||||||
true -> ejabberd_hooks:run_fold(roster_get_jid_info, Server, {none, []}, [User, Server, From]);
|
check_packet_aux(List, PType2, LJID, Subscription, Groups)
|
||||||
false -> {[], []}
|
|
||||||
end,
|
|
||||||
check_packet_aux(List, presence_out,
|
|
||||||
LJID, Subscription, Groups);
|
|
||||||
_ ->
|
|
||||||
allow
|
|
||||||
end
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
%% Ptype = mesage | iq | presence_in | presence_out | other
|
||||||
check_packet_aux([], _PType, _JID, _Subscription, _Groups) ->
|
check_packet_aux([], _PType, _JID, _Subscription, _Groups) ->
|
||||||
allow;
|
allow;
|
||||||
check_packet_aux([Item | List], PType, JID, Subscription, Groups) ->
|
check_packet_aux([Item | List], PType, JID, Subscription, Groups) ->
|
||||||
@ -651,7 +648,9 @@ is_ptype_match(Item, PType) ->
|
|||||||
presence_in ->
|
presence_in ->
|
||||||
Item#listitem.match_presence_in;
|
Item#listitem.match_presence_in;
|
||||||
presence_out ->
|
presence_out ->
|
||||||
Item#listitem.match_presence_out
|
Item#listitem.match_presence_out;
|
||||||
|
other ->
|
||||||
|
false
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user