From 2589d6ec6fe197d7d6b0061b1978695e972b68e4 Mon Sep 17 00:00:00 2001 From: Badlop Date: Wed, 12 Nov 2014 17:50:40 +0100 Subject: [PATCH] Reapply multicast patch to stock ejabberd files --- mod_multicast/src/ejabberd_c2s.erl | 23 +++++++------------- mod_multicast/src/ejabberd_sup.erl | 8 +++++++ mod_multicast/src/mod_muc_room.erl | 35 +++++++++++++++--------------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/mod_multicast/src/ejabberd_c2s.erl b/mod_multicast/src/ejabberd_c2s.erl index 72ebdb5..6fdbcb7 100644 --- a/mod_multicast/src/ejabberd_c2s.erl +++ b/mod_multicast/src/ejabberd_c2s.erl @@ -2187,14 +2187,16 @@ try_roster_subscribe(Type, User, Server, From, To, Packet, StateData) -> presence_broadcast(StateData, From, JIDSet, Packet) -> JIDs = ?SETS:to_list(JIDSet), JIDs2 = format_and_check_privacy(From, StateData, Packet, JIDs, out), - send_multiple(StateData, From, JIDs2, Packet). + Server = StateData#state.server, + send_multiple(From, Server, JIDs2, Packet). %% 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, out), - send_multiple(StateData, From, JIDs2, Packet). + Server = StateData#state.server, + send_multiple(From, Server, JIDs2, Packet). %% Send presence when connecting presence_broadcast_first(From, StateData, Packet) -> @@ -2206,7 +2208,7 @@ presence_broadcast_first(From, StateData, Packet) -> PacketProbe = #xmlel{name = <<"presence">>, attrs = [{<<"type">>,<<"probe">>}], children = []}, JIDs2Probe = format_and_check_privacy(From, StateData, PacketProbe, JIDsProbe, out), Server = StateData#state.server, - send_multiple(StateData, From, JIDs2Probe, PacketProbe), + send_multiple(From, Server, JIDs2Probe, PacketProbe), {As, JIDs} = ?SETS:fold( fun(JID, {A, JID_list}) -> @@ -2215,8 +2217,7 @@ presence_broadcast_first(From, StateData, Packet) -> {StateData#state.pres_a, []}, StateData#state.pres_f), JIDs2 = format_and_check_privacy(From, StateData, Packet, JIDs, out), - Server = StateData#state.server, - send_multiple(StateData, From, JIDs2, Packet), + send_multiple(From, Server, JIDs2, Packet), StateData#state{pres_a = As}. format_and_check_privacy(From, StateData, Packet, JIDs, Dir) -> @@ -2237,16 +2238,8 @@ format_and_check_privacy(From, StateData, Packet, JIDs, Dir) -> end, FJIDs). -send_multiple(StateData, From, JIDs, Packet) -> - lists:foreach( - fun(JID) -> - case privacy_check_packet(StateData, From, JID, Packet, out) of - deny -> - ok; - allow -> - ejabberd_router:route(From, JID, Packet) - end - end, JIDs). +send_multiple(From, Server, JIDs, Packet) -> + ejabberd_router_multicast:route_multicast(From, Server, JIDs, Packet). remove_element(E, Set) -> case (?SETS):is_element(E, Set) of diff --git a/mod_multicast/src/ejabberd_sup.erl b/mod_multicast/src/ejabberd_sup.erl index c89a068..7a25bde 100644 --- a/mod_multicast/src/ejabberd_sup.erl +++ b/mod_multicast/src/ejabberd_sup.erl @@ -62,6 +62,13 @@ init([]) -> brutal_kill, worker, [ejabberd_router]}, + Router_multicast = + {ejabberd_router_multicast, + {ejabberd_router_multicast, start_link, []}, + permanent, + brutal_kill, + worker, + [ejabberd_router_multicast]}, SM = {ejabberd_sm, {ejabberd_sm, start_link, []}, @@ -173,6 +180,7 @@ init([]) -> NodeGroups, SystemMonitor, Router, + Router_multicast, SM, S2S, Local, diff --git a/mod_multicast/src/mod_muc_room.erl b/mod_multicast/src/mod_muc_room.erl index 6a2a91d..3ea7f34 100644 --- a/mod_multicast/src/mod_muc_room.erl +++ b/mod_multicast/src/mod_muc_room.erl @@ -681,14 +681,11 @@ handle_event({service_message, Msg}, _StateName, children = [#xmlel{name = <<"body">>, attrs = [], children = [{xmlcdata, Msg}]}]}, - lists:foreach( - fun({_LJID, Info}) -> - ejabberd_router:route( - StateData#state.jid, - Info#user.jid, - MessagePkt) - end, - ?DICT:to_list(StateData#state.users)), + send_multiple( + StateData#state.jid, + StateData#state.server_host, + StateData#state.users, + MessagePkt), NSD = add_message_to_history(<<"">>, StateData#state.jid, MessagePkt, StateData), {next_state, normal_state, NSD}; @@ -942,16 +939,11 @@ process_groupchat_message(From, end, case IsAllowed of true -> - lists:foreach( - fun({_LJID, Info}) -> - ejabberd_router:route( - jlib:jid_replace_resource( - StateData#state.jid, - FromNick), - Info#user.jid, - Packet) - end, - ?DICT:to_list(StateData#state.users)), + send_multiple( + jlib:jid_replace_resource(StateData#state.jid, FromNick), + StateData#state.server_host, + StateData#state.users, + Packet), NewStateData2 = case has_body_or_subject(Packet) of true -> add_message_to_history(FromNick, From, @@ -4525,3 +4517,10 @@ has_body_or_subject(Packet) -> (#xmlel{name = <<"subject">>}) -> false; (_) -> true end, Packet#xmlel.children). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% Multicast + +send_multiple(From, Server, Users, Packet) -> + JIDs = [ User#user.jid || {_, User} <- ?DICT:to_list(Users)], + ejabberd_router_multicast:route_multicast(From, Server, JIDs, Packet).