25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

Set from/to in every routed packet

This commit is contained in:
Evgeniy Khramtsov 2017-01-09 17:51:08 +03:00
parent 9605e2b2a4
commit f14a966680

View File

@ -74,8 +74,17 @@ start_link() ->
-spec route(jid(), jid(), xmlel() | stanza()) -> ok.
route(From, To, Packet) ->
case catch do_route(From, To, Packet) of
route(#jid{} = From, #jid{} = To, #xmlel{} = El) ->
try xmpp:decode(El, ?NS_CLIENT, [ignore_els]) of
Pkt -> route(From, To, xmpp:set_from_to(Pkt, From, To))
catch _:{xmpp_codec, Why} ->
?ERROR_MSG("failed to decode xml element ~p when "
"routing from ~s to ~s: ~s",
[El, jid:to_string(From), jid:to_string(To),
xmpp:format_error(Why)])
end;
route(#jid{} = From, #jid{} = To, Packet) ->
case catch do_route(From, To, xmpp:set_from_to(Packet, From, To)) of
{'EXIT', Reason} ->
?ERROR_MSG("~p~nwhen processing: ~p",
[Reason, {From, To, Packet}]);
@ -390,12 +399,7 @@ do_route(OrigFrom, OrigTo, OrigPacket) ->
LDstDomain = To#jid.lserver,
case mnesia:dirty_read(route, LDstDomain) of
[] ->
try xmpp:decode(Packet, ?NS_CLIENT, [ignore_els]) of
Pkt ->
ejabberd_s2s:route(From, To, Pkt)
catch _:{xmpp_codec, Why} ->
log_decoding_error(From, To, Packet, Why)
end;
ejabberd_s2s:route(From, To, Packet);
[R] ->
do_route(From, To, Packet, R);
Rs ->
@ -422,27 +426,15 @@ do_route(OrigFrom, OrigTo, OrigPacket) ->
-spec do_route(jid(), jid(), xmlel() | xmpp_element(), #route{}) -> any().
do_route(From, To, Packet, #route{local_hint = LocalHint,
pid = Pid}) when is_pid(Pid) ->
try xmpp:decode(Packet, ?NS_CLIENT, [ignore_els]) of
Pkt ->
case LocalHint of
{apply, Module, Function} when node(Pid) == node() ->
Module:Function(From, To, Pkt);
Module:Function(From, To, Packet);
_ ->
Pid ! {route, From, To, Pkt}
end
catch error:{xmpp_codec, Why} ->
log_decoding_error(From, To, Packet, Why)
Pid ! {route, From, To, Packet}
end;
do_route(_From, _To, _Packet, _Route) ->
drop.
-spec log_decoding_error(jid(), jid(), xmlel() | xmpp_element(), term()) -> ok.
log_decoding_error(From, To, Packet, Reason) ->
?ERROR_MSG("failed to decode xml element ~p when "
"routing from ~s to ~s: ~s",
[Packet, jid:to_string(From), jid:to_string(To),
xmpp:format_error(Reason)]).
-spec get_component_number(binary()) -> pos_integer() | undefined.
get_component_number(LDomain) ->
ejabberd_config:get_option(