From 8b2d3084986defd6045a0c02706415e0e7ae4b3f Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Thu, 16 Feb 2017 11:00:26 +0300 Subject: Change routing API Now 'From' and 'To' arguments must be omitted in functions and structures related to routing. The commit deprecates the following functions: ejabberd_router:route/3 in favor of ejabberd_router:route/1 ejabberd_router:route_error/4 in favor of ejabberd_router:route_error/2 ejabberd_local:route_iq/4 in favor of ejabberd_local:route_iq/2 ejabberd_local:route_iq/5 in favor of ejabberd_local:route_iq/3 The format of {route, From, To, Packet} is changed in favor of {route, Packet} --- src/ejabberd_router_multicast.erl | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'src/ejabberd_router_multicast.erl') diff --git a/src/ejabberd_router_multicast.erl b/src/ejabberd_router_multicast.erl index 19c6da14..c2a99528 100644 --- a/src/ejabberd_router_multicast.erl +++ b/src/ejabberd_router_multicast.erl @@ -66,7 +66,7 @@ start_link() -> -spec route_multicast(jid(), binary(), [jid()], stanza()) -> ok. route_multicast(From, Domain, Destinations, Packet) -> - case catch do_route(From, Domain, Destinations, Packet) of + case catch do_route(Domain, Destinations, xmpp:set_from(Packet, From)) of {'EXIT', Reason} -> ?ERROR_MSG("~p~nwhen processing: ~p", [Reason, {From, Domain, Destinations, Packet}]); @@ -162,11 +162,11 @@ handle_cast(_Msg, State) -> %% {stop, Reason, State} %% Description: Handling all non call/cast messages %%-------------------------------------------------------------------- -handle_info({route_multicast, From, Domain, Destinations, Packet}, State) -> - case catch do_route(From, Domain, Destinations, Packet) of +handle_info({route_multicast, Domain, Destinations, Packet}, State) -> + case catch do_route(Domain, Destinations, Packet) of {'EXIT', Reason} -> ?ERROR_MSG("~p~nwhen processing: ~p", - [Reason, {From, Domain, Destinations, Packet}]); + [Reason, {Domain, Destinations, Packet}]); _ -> ok end, @@ -214,25 +214,21 @@ code_change(_OldVsn, State, _Extra) -> %%-------------------------------------------------------------------- %% From = #jid %% Destinations = [#jid] --spec do_route(jid(), binary(), [jid()], stanza()) -> any(). -do_route(From, Domain, Destinations, Packet) -> - - ?DEBUG("route_multicast~n\tfrom ~s~n\tdomain ~s~n\tdestinations ~p~n\tpacket ~p~n", - [jid:to_string(From), - Domain, - [jid:to_string(To) || To <- Destinations], - Packet]), - +-spec do_route(binary(), [jid()], stanza()) -> any(). +do_route(Domain, Destinations, Packet) -> + ?DEBUG("route multicast:~n~s~nDomain: ~s~nDestinations: ~s~n", + [xmpp:pp(Packet), Domain, + str:join([jid:to_string(To) || To <- Destinations], ", ")]), %% Try to find an appropriate multicast service case mnesia:dirty_read(route_multicast, Domain) of %% If no multicast service is available in this server, send manually - [] -> do_route_normal(From, Destinations, Packet); + [] -> do_route_normal(Destinations, Packet); %% If some is available, send the packet using multicast service Rs when is_list(Rs) -> Pid = pick_multicast_pid(Rs), - Pid ! {route_trusted, From, Destinations, Packet} + Pid ! {route_trusted, Destinations, Packet} end. -spec pick_multicast_pid([#route_multicast{}]) -> pid(). @@ -243,6 +239,6 @@ pick_multicast_pid(Rs) -> end, (hd(List))#route_multicast.pid. --spec do_route_normal(jid(), [jid()], stanza()) -> any(). -do_route_normal(From, Destinations, Packet) -> - [ejabberd_router:route(From, To, Packet) || To <- Destinations]. +-spec do_route_normal([jid()], stanza()) -> any(). +do_route_normal(Destinations, Packet) -> + [ejabberd_router:route(xmpp:set_to(Packet, To)) || To <- Destinations]. -- cgit v1.2.3