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:
parent
9605e2b2a4
commit
f14a966680
@ -74,8 +74,17 @@ start_link() ->
|
|||||||
|
|
||||||
-spec route(jid(), jid(), xmlel() | stanza()) -> ok.
|
-spec route(jid(), jid(), xmlel() | stanza()) -> ok.
|
||||||
|
|
||||||
route(From, To, Packet) ->
|
route(#jid{} = From, #jid{} = To, #xmlel{} = El) ->
|
||||||
case catch do_route(From, To, Packet) of
|
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} ->
|
{'EXIT', Reason} ->
|
||||||
?ERROR_MSG("~p~nwhen processing: ~p",
|
?ERROR_MSG("~p~nwhen processing: ~p",
|
||||||
[Reason, {From, To, Packet}]);
|
[Reason, {From, To, Packet}]);
|
||||||
@ -390,12 +399,7 @@ do_route(OrigFrom, OrigTo, OrigPacket) ->
|
|||||||
LDstDomain = To#jid.lserver,
|
LDstDomain = To#jid.lserver,
|
||||||
case mnesia:dirty_read(route, LDstDomain) of
|
case mnesia:dirty_read(route, LDstDomain) of
|
||||||
[] ->
|
[] ->
|
||||||
try xmpp:decode(Packet, ?NS_CLIENT, [ignore_els]) of
|
ejabberd_s2s:route(From, To, Packet);
|
||||||
Pkt ->
|
|
||||||
ejabberd_s2s:route(From, To, Pkt)
|
|
||||||
catch _:{xmpp_codec, Why} ->
|
|
||||||
log_decoding_error(From, To, Packet, Why)
|
|
||||||
end;
|
|
||||||
[R] ->
|
[R] ->
|
||||||
do_route(From, To, Packet, R);
|
do_route(From, To, Packet, R);
|
||||||
Rs ->
|
Rs ->
|
||||||
@ -422,27 +426,15 @@ do_route(OrigFrom, OrigTo, OrigPacket) ->
|
|||||||
-spec do_route(jid(), jid(), xmlel() | xmpp_element(), #route{}) -> any().
|
-spec do_route(jid(), jid(), xmlel() | xmpp_element(), #route{}) -> any().
|
||||||
do_route(From, To, Packet, #route{local_hint = LocalHint,
|
do_route(From, To, Packet, #route{local_hint = LocalHint,
|
||||||
pid = Pid}) when is_pid(Pid) ->
|
pid = Pid}) when is_pid(Pid) ->
|
||||||
try xmpp:decode(Packet, ?NS_CLIENT, [ignore_els]) of
|
case LocalHint of
|
||||||
Pkt ->
|
{apply, Module, Function} when node(Pid) == node() ->
|
||||||
case LocalHint of
|
Module:Function(From, To, Packet);
|
||||||
{apply, Module, Function} when node(Pid) == node() ->
|
_ ->
|
||||||
Module:Function(From, To, Pkt);
|
Pid ! {route, From, To, Packet}
|
||||||
_ ->
|
|
||||||
Pid ! {route, From, To, Pkt}
|
|
||||||
end
|
|
||||||
catch error:{xmpp_codec, Why} ->
|
|
||||||
log_decoding_error(From, To, Packet, Why)
|
|
||||||
end;
|
end;
|
||||||
do_route(_From, _To, _Packet, _Route) ->
|
do_route(_From, _To, _Packet, _Route) ->
|
||||||
drop.
|
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.
|
-spec get_component_number(binary()) -> pos_integer() | undefined.
|
||||||
get_component_number(LDomain) ->
|
get_component_number(LDomain) ->
|
||||||
ejabberd_config:get_option(
|
ejabberd_config:get_option(
|
||||||
|
Loading…
Reference in New Issue
Block a user