25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Use multicast in C2S presence broadcast (EJAB-267)

This commit is contained in:
Badlop 2010-05-19 23:56:55 +02:00
parent a4cf03dbf0
commit 41484213fd

View File

@ -1777,87 +1777,69 @@ is_privacy_allow(From, To, Packet, PrivacyList) ->
{From, To, Packet}, {From, To, Packet},
in]). in]).
%% Send presence when disconnecting
presence_broadcast(StateData, From, JIDSet, Packet) -> presence_broadcast(StateData, From, JIDSet, Packet) ->
lists:foreach(fun({U, S, R}) -> JIDs = ?SETS:to_list(JIDSet),
FJID = exmpp_jid:make(U, S, R), JIDs2 = format_and_check_privacy(From, StateData, Packet, JIDs),
case ejabberd_hooks:run_fold( Server = StateData#state.server,
privacy_check_packet, StateData#state.server, send_multiple(From, Server, JIDs2, Packet).
allow,
[StateData#state.user,
StateData#state.server,
StateData#state.privacy_list,
{From, FJID, Packet},
out]) of
deny ->
ok;
allow ->
ejabberd_router:route(From, FJID, Packet)
end
end, ?SETS:to_list(JIDSet)).
presence_broadcast_to_trusted(StateData, From, T, A, Packet) ->
lists:foreach(
fun({U, S, R} = JID) ->
case ?SETS:is_element(JID, T) of
true ->
FJID = exmpp_jid:make(U, S, R),
case ejabberd_hooks:run_fold(
privacy_check_packet, StateData#state.server,
allow,
[StateData#state.user,
StateData#state.server,
StateData#state.privacy_list,
{From, FJID, Packet},
out]) of
deny ->
ok;
allow ->
ejabberd_router:route(From, FJID, Packet)
end;
_ ->
ok
end
end, ?SETS:to_list(A)).
%% Send presence when updating presence
presence_broadcast_to_trusted(StateData, From, Trusted, JIDSet, Packet) ->
JIDs = ?SETS:to_list(JIDSet),
JIDs_trusted = [JID || JID <- JIDs, ?SETS:is_element(JID, Trusted)],
JIDs2 = format_and_check_privacy(From, StateData, Packet, JIDs_trusted),
Server = StateData#state.server,
send_multiple(From, Server, JIDs2, Packet).
%% Send presence when connecting
presence_broadcast_first(From, StateData, Packet) -> presence_broadcast_first(From, StateData, Packet) ->
Probe = exmpp_presence:probe(), JIDsProbe =
?SETS:fold(fun({U, S, R}, X) -> ?SETS:fold(
FJID = exmpp_jid:make(U, S, R), fun(JID, L) -> [JID | L] end,
ejabberd_router:route( [],
From, StateData#state.pres_t),
FJID, PacketProbe = exmpp_presence:probe(),
Probe), JIDs2Probe = format_and_check_privacy(From, StateData, Packet, JIDsProbe),
X Server = StateData#state.server,
end, send_multiple(From, Server, JIDs2Probe, PacketProbe),
[],
StateData#state.pres_t),
if if
StateData#state.pres_invis -> StateData#state.pres_invis ->
StateData; StateData;
true -> true ->
As = ?SETS:fold( {As, JIDs} =
fun({U, S, R} = JID, A) -> ?SETS:fold(
FJID = exmpp_jid:make(U, S, R), fun(JID, {A, JID_list}) ->
case ejabberd_hooks:run_fold( {?SETS:add_element(JID, A), JID_list++[JID]}
privacy_check_packet, StateData#state.server, end,
allow, {StateData#state.pres_a, []},
[StateData#state.user, StateData#state.pres_f),
StateData#state.server, JIDs2 = format_and_check_privacy(From, StateData, Packet, JIDs),
StateData#state.privacy_list, Server = StateData#state.server,
{From, FJID, Packet}, send_multiple(From, Server, JIDs2, Packet),
out]) of
deny ->
ok;
allow ->
ejabberd_router:route(From, FJID, Packet)
end,
?SETS:add_element(JID, A)
end,
StateData#state.pres_a,
StateData#state.pres_f),
StateData#state{pres_a = As} StateData#state{pres_a = As}
end. end.
format_and_check_privacy(From, StateData, Packet, JIDs) ->
FJIDs = [exmpp_jid:make(JID) || JID <- JIDs],
lists:filter(
fun(FJID) ->
case ejabberd_hooks:run_fold(
privacy_check_packet, StateData#state.server,
allow,
[StateData#state.user,
StateData#state.server,
StateData#state.privacy_list,
{From, FJID, Packet},
out]) of
deny -> false;
allow -> true
end
end,
FJIDs).
send_multiple(From, Server, JIDs, Packet) ->
ejabberd_router_multicast:route_multicast(From, Server, JIDs, Packet).
remove_element(E, Set) -> remove_element(E, Set) ->