25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-26 16:26:24 +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,68 +1777,53 @@ 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,
FJID,
Probe),
X
end,
[], [],
StateData#state.pres_t), StateData#state.pres_t),
PacketProbe = exmpp_presence:probe(),
JIDs2Probe = format_and_check_privacy(From, StateData, Packet, JIDsProbe),
Server = StateData#state.server,
send_multiple(From, Server, JIDs2Probe, PacketProbe),
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}) ->
{?SETS:add_element(JID, A), JID_list++[JID]}
end,
{StateData#state.pres_a, []},
StateData#state.pres_f),
JIDs2 = format_and_check_privacy(From, StateData, Packet, JIDs),
Server = StateData#state.server,
send_multiple(From, Server, JIDs2, Packet),
StateData#state{pres_a = As}
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( case ejabberd_hooks:run_fold(
privacy_check_packet, StateData#state.server, privacy_check_packet, StateData#state.server,
allow, allow,
@ -1847,17 +1832,14 @@ presence_broadcast_first(From, StateData, Packet) ->
StateData#state.privacy_list, StateData#state.privacy_list,
{From, FJID, Packet}, {From, FJID, Packet},
out]) of out]) of
deny -> deny -> false;
ok; allow -> true
allow -> end
ejabberd_router:route(From, FJID, Packet)
end, end,
?SETS:add_element(JID, A) FJIDs).
end,
StateData#state.pres_a, send_multiple(From, Server, JIDs, Packet) ->
StateData#state.pres_f), ejabberd_router_multicast:route_multicast(From, Server, JIDs, Packet).
StateData#state{pres_a = As}
end.
remove_element(E, Set) -> remove_element(E, Set) ->