mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Before doing any routing, the router print a warning if old structures
are used. Then it converts the structures to the old format and route them. The router doesn't care about the structures format but the conversion is necesary for code called from this module. In C2S and S2S, no conversion is done before calling ejabberd_router:route/3. SVN Revision: 1392
This commit is contained in:
parent
cc033b3b98
commit
06965000a5
10
ChangeLog
10
ChangeLog
@ -16,6 +16,16 @@
|
||||
src/ejabberd_s2s_out.erl: Use the new functions from jlib. Use the new
|
||||
exmpp_xml:node_to_list/3.
|
||||
|
||||
* src/ejabberd_router.erl: Before doing any routing, the router print
|
||||
a warning if old structures are used. Then it converts the structures
|
||||
to the old format and route them. The router doesn't care about the
|
||||
structures format but the conversion is necesary for code called from
|
||||
this module.
|
||||
|
||||
* src/ejabberd_c2s.erl, src/ejabberd_s2s.erl, src/ejabberd_s2s_in.erl,
|
||||
src/ejabberd_s2s_out.erl: No conversion is done before calling
|
||||
ejabberd_router:route/3.
|
||||
|
||||
2008-06-27 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
||||
|
||||
* src/ejabberd_c2s.erl, src/ejabberd_s2s_out.erl,
|
||||
|
@ -857,9 +857,8 @@ session_established({xmlstreamelement, El}, StateData) ->
|
||||
user_send_packet,
|
||||
Server,
|
||||
[FromJIDOld, ToJIDOld, NewElOld]),
|
||||
% XXX OLD FORMAT: NewElOld.
|
||||
ejabberd_router:route(
|
||||
FromJIDOld, ToJIDOld, NewElOld),
|
||||
FromJID, ToJID, NewEl),
|
||||
StateData
|
||||
end;
|
||||
#xmlel{ns = ?NS_JABBER_CLIENT, name = 'message'} ->
|
||||
@ -871,8 +870,7 @@ session_established({xmlstreamelement, El}, StateData) ->
|
||||
ejabberd_hooks:run(user_send_packet,
|
||||
Server,
|
||||
[FromJIDOld, ToJIDOld, NewElOld]),
|
||||
% XXX OLD FORMAT: NewElOld.
|
||||
ejabberd_router:route(FromJIDOld, ToJIDOld, NewElOld),
|
||||
ejabberd_router:route(FromJID, ToJID, NewEl),
|
||||
StateData;
|
||||
_ ->
|
||||
StateData
|
||||
@ -1186,10 +1184,7 @@ handle_info({route, FromOld, ToOld, PacketOld}, StateName, StateData) ->
|
||||
[] ->
|
||||
Err = exmpp_stanza:error('feature-not-implemented'),
|
||||
Res = exmpp_iq:error(Packet, Err),
|
||||
% XXX OLD FORMAT: To, From, Res.
|
||||
ResOld = exmpp_xml:xmlel_to_xmlelement(
|
||||
Res, [?DEFAULT_NS], ?PREFIXED_NS),
|
||||
ejabberd_router:route(ToOld, FromOld, ResOld)
|
||||
ejabberd_router:route(To, From, Res)
|
||||
end,
|
||||
{false, Attrs, StateData};
|
||||
_ ->
|
||||
@ -1208,11 +1203,7 @@ handle_info({route, FromOld, ToOld, PacketOld}, StateName, StateData) ->
|
||||
Err = exmpp_stanza:error(
|
||||
'feature-not-implemented'),
|
||||
Res = exmpp_iq:error(Packet, Err),
|
||||
% XXX OLD FORMAT: To, From, Res.
|
||||
ResOld = exmpp_xml:xmlel_to_xmlelement(
|
||||
Res,
|
||||
[?DEFAULT_NS], ?PREFIXED_NS),
|
||||
ejabberd_router:route(ToOld, FromOld, ResOld),
|
||||
ejabberd_router:route(To, From, Res),
|
||||
{false, Attrs, StateData}
|
||||
end
|
||||
end;
|
||||
@ -1446,20 +1437,14 @@ process_presence_probe(From, To, StateData) ->
|
||||
%% Don't route a presence probe to oneself
|
||||
case From == To of
|
||||
false ->
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
ejabberd_router:route(ToOld, FromOld, PacketOld);
|
||||
ejabberd_router:route(To, From, Packet);
|
||||
true ->
|
||||
ok
|
||||
end
|
||||
end;
|
||||
Cond2 ->
|
||||
Packet = exmpp_presence:available(),
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
FromOld = jlib:to_old_jid(From),
|
||||
ToOld = jlib:to_old_jid(To),
|
||||
PacketOld = exmpp_xml:xmlel_to_xmlelement(Packet,
|
||||
[?DEFAULT_NS], ?PREFIXED_NS),
|
||||
ejabberd_router:route(ToOld, FromOld, PacketOld);
|
||||
ejabberd_router:route(To, From, Packet);
|
||||
true ->
|
||||
ok
|
||||
end
|
||||
@ -1584,21 +1569,19 @@ presence_track(From, To, Packet, StateData) ->
|
||||
Server = StateData#state.server,
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
FromOld = jlib:to_old_jid(From),
|
||||
BFromOld = jlib:to_old_jid(exmpp_jid:jid_to_bare_jid(From)),
|
||||
BFrom = exmpp_jid:jid_to_bare_jid(From),
|
||||
ToOld = jlib:to_old_jid(To),
|
||||
PacketOld = exmpp_xml:xmlel_to_xmlelement(Packet,
|
||||
[?DEFAULT_NS], ?PREFIXED_NS),
|
||||
case exmpp_presence:get_type(Packet) of
|
||||
'unavailable' ->
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
ejabberd_router:route(FromOld, ToOld, PacketOld),
|
||||
ejabberd_router:route(From, To, Packet),
|
||||
I = remove_element(LTo, StateData#state.pres_i),
|
||||
A = remove_element(LTo, StateData#state.pres_a),
|
||||
StateData#state{pres_i = I,
|
||||
pres_a = A};
|
||||
'invisible' ->
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
ejabberd_router:route(FromOld, ToOld, PacketOld),
|
||||
ejabberd_router:route(From, To, Packet),
|
||||
I = ?SETS:add_element(LTo, StateData#state.pres_i),
|
||||
A = remove_element(LTo, StateData#state.pres_a),
|
||||
StateData#state{pres_i = I,
|
||||
@ -1608,40 +1591,34 @@ presence_track(From, To, Packet, StateData) ->
|
||||
ejabberd_hooks:run(roster_out_subscription,
|
||||
Server,
|
||||
[User, Server, ToOld, subscribe]),
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
ejabberd_router:route(BFromOld, ToOld, PacketOld),
|
||||
ejabberd_router:route(BFrom, To, Packet),
|
||||
StateData;
|
||||
'subscribed' ->
|
||||
% XXX OLD FORMAT: To.
|
||||
ejabberd_hooks:run(roster_out_subscription,
|
||||
Server,
|
||||
[User, Server, ToOld, subscribed]),
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
ejabberd_router:route(BFromOld, ToOld, PacketOld),
|
||||
ejabberd_router:route(BFrom, To, Packet),
|
||||
StateData;
|
||||
'unsubscribe' ->
|
||||
% XXX OLD FORMAT: To.
|
||||
ejabberd_hooks:run(roster_out_subscription,
|
||||
Server,
|
||||
[User, Server, ToOld, unsubscribe]),
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
ejabberd_router:route(BFromOld, ToOld, PacketOld),
|
||||
ejabberd_router:route(BFrom, To, Packet),
|
||||
StateData;
|
||||
'unsubscribed' ->
|
||||
% XXX OLD FORMAT: To.
|
||||
ejabberd_hooks:run(roster_out_subscription,
|
||||
Server,
|
||||
[User, Server, ToOld, unsubscribed]),
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
ejabberd_router:route(BFromOld, ToOld, PacketOld),
|
||||
ejabberd_router:route(BFrom, To, Packet),
|
||||
StateData;
|
||||
'error' ->
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
ejabberd_router:route(FromOld, ToOld, PacketOld),
|
||||
ejabberd_router:route(From, To, Packet),
|
||||
StateData;
|
||||
'probe' ->
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
ejabberd_router:route(FromOld, ToOld, PacketOld),
|
||||
ejabberd_router:route(From, To, Packet),
|
||||
StateData;
|
||||
_ ->
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
@ -1656,8 +1633,7 @@ presence_track(From, To, Packet, StateData) ->
|
||||
deny ->
|
||||
ok;
|
||||
allow ->
|
||||
% XXX OLD FORMAT: From, To, Packet.
|
||||
ejabberd_router:route(FromOld, ToOld, PacketOld)
|
||||
ejabberd_router:route(From, To, Packet)
|
||||
end,
|
||||
I = remove_element(LTo, StateData#state.pres_i),
|
||||
A = ?SETS:add_element(LTo, StateData#state.pres_a),
|
||||
@ -1684,8 +1660,7 @@ presence_broadcast(StateData, From, JIDSet, Packet) ->
|
||||
deny ->
|
||||
ok;
|
||||
allow ->
|
||||
% XXX OLD FORMAT: From, FJID, Packet.
|
||||
ejabberd_router:route(FromOld, FJIDOld, PacketOld)
|
||||
ejabberd_router:route(From, FJID, Packet)
|
||||
end
|
||||
end, ?SETS:to_list(JIDSet)).
|
||||
|
||||
@ -1712,8 +1687,7 @@ presence_broadcast_to_trusted(StateData, From, T, A, Packet) ->
|
||||
deny ->
|
||||
ok;
|
||||
allow ->
|
||||
% XXX OLD FORMAT: From, FJID, Packet.
|
||||
ejabberd_router:route(FromOld, FJIDOld, PacketOld)
|
||||
ejabberd_router:route(From, FJID, Packet)
|
||||
end;
|
||||
_ ->
|
||||
ok
|
||||
@ -1727,16 +1701,12 @@ presence_broadcast_first(From, StateData, Packet) ->
|
||||
FromOld = jlib:to_old_jid(From),
|
||||
PacketOld = exmpp_xml:xmlel_to_xmlelement(Packet,
|
||||
[?DEFAULT_NS], ?PREFIXED_NS),
|
||||
ProbeOld = exmpp_xml:xmlel_to_xmlelement(Probe,
|
||||
[?DEFAULT_NS], ?PREFIXED_NS),
|
||||
?SETS:fold(fun({U, S, R}, X) ->
|
||||
FJID = exmpp_jid:make_jid(U, S, R),
|
||||
% XXX OLD FORMAT: FJID.
|
||||
FJIDOld = jlib:to_old_jid(FJID),
|
||||
ejabberd_router:route(
|
||||
FromOld,
|
||||
FJIDOld,
|
||||
ProbeOld),
|
||||
From,
|
||||
FJID,
|
||||
Probe),
|
||||
X
|
||||
end,
|
||||
[],
|
||||
@ -1761,7 +1731,7 @@ presence_broadcast_first(From, StateData, Packet) ->
|
||||
deny ->
|
||||
ok;
|
||||
allow ->
|
||||
ejabberd_router:route(FromOld, FJIDOld, PacketOld)
|
||||
ejabberd_router:route(From, FJID, Packet)
|
||||
end,
|
||||
?SETS:add_element(JID, A)
|
||||
end,
|
||||
@ -1830,8 +1800,7 @@ roster_change(IJID, ISubscription, StateData) ->
|
||||
deny ->
|
||||
ok;
|
||||
allow ->
|
||||
% XXX OLD FORMAT: From, To, P.
|
||||
ejabberd_router:route(FromOld, ToOld, POld)
|
||||
ejabberd_router:route(From, To, P)
|
||||
end,
|
||||
A = ?SETS:add_element(LIJID,
|
||||
StateData#state.pres_a),
|
||||
@ -1856,8 +1825,7 @@ roster_change(IJID, ISubscription, StateData) ->
|
||||
deny ->
|
||||
ok;
|
||||
allow ->
|
||||
% XXX OLD FORMAT: From, To, PU.
|
||||
ejabberd_router:route(FromOld, ToOld, PUOld)
|
||||
ejabberd_router:route(From, To, PU)
|
||||
end,
|
||||
I = remove_element(LIJID,
|
||||
StateData#state.pres_i),
|
||||
@ -1926,11 +1894,8 @@ process_privacy_iq(From, To,
|
||||
[?DEFAULT_NS], ?PREFIXED_NS),
|
||||
exmpp_iq:error(El, Error)
|
||||
end,
|
||||
% XXX OLD FORMAT: To, From, IQRes.
|
||||
IQResOld = exmpp_xml:xmlel_to_xmlelement(IQRes,
|
||||
[?DEFAULT_NS], ?PREFIXED_NS),
|
||||
ejabberd_router:route(
|
||||
ToOld, FromOld, IQResOld),
|
||||
To, From, IQRes),
|
||||
NewStateData.
|
||||
|
||||
|
||||
|
@ -46,8 +46,9 @@
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
terminate/2, code_change/3]).
|
||||
|
||||
-include_lib("exmpp/include/exmpp.hrl").
|
||||
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
|
||||
-record(route, {domain, pid, local_hint}).
|
||||
-record(state, {}).
|
||||
@ -64,7 +65,27 @@ start_link() ->
|
||||
|
||||
|
||||
route(From, To, Packet) ->
|
||||
case catch do_route(From, To, Packet) of
|
||||
% XXX OLD FORMAT: This code helps to detect old format routing.
|
||||
{FromOld, ToOld, PacketOld} = case Packet of
|
||||
#xmlelement{} ->
|
||||
catch throw(for_stacktrace), % To have a stacktrace.
|
||||
io:format("~nROUTE: old #xmlelement:~n~p~n~p~n~n",
|
||||
[Packet, erlang:get_stacktrace()]),
|
||||
{From, To, Packet};
|
||||
_ ->
|
||||
F = jlib:to_old_jid(From),
|
||||
T = jlib:to_old_jid(To),
|
||||
Default_NS = case lists:member({Packet#xmlel.ns, none},
|
||||
Packet#xmlel.declared_ns) of
|
||||
true -> [];
|
||||
false -> [Packet#xmlel.ns]
|
||||
end,
|
||||
P = exmpp_xml:xmlel_to_xmlelement(Packet,
|
||||
Default_NS,
|
||||
[{?NS_XMPP, ?NS_XMPP_pfx}, {?NS_DIALBACK, ?NS_DIALBACK_pfx}]),
|
||||
{F, T, P}
|
||||
end,
|
||||
case catch do_route(FromOld, ToOld, PacketOld) of
|
||||
{'EXIT', Reason} ->
|
||||
?ERROR_MSG("~p~nwhen processing: ~p",
|
||||
[Reason, {From, To, Packet}]);
|
||||
@ -237,7 +258,27 @@ handle_cast(_Msg, State) ->
|
||||
%% Description: Handling all non call/cast messages
|
||||
%%--------------------------------------------------------------------
|
||||
handle_info({route, From, To, Packet}, State) ->
|
||||
case catch do_route(From, To, Packet) of
|
||||
% XXX OLD FORMAT: This code helps to detect old format routing.
|
||||
{FromOld, ToOld, PacketOld} = case Packet of
|
||||
#xmlelement{} ->
|
||||
catch throw(for_stacktrace), % To have a stacktrace.
|
||||
io:format("~nROUTE: old #xmlelement:~n~p~n~p~n~n",
|
||||
[Packet, erlang:get_stacktrace()]),
|
||||
{From, To, Packet};
|
||||
_ ->
|
||||
F = jlib:to_old_jid(From),
|
||||
T = jlib:to_old_jid(To),
|
||||
Default_NS = case lists:member({Packet#xmlel.ns, none},
|
||||
Packet#xmlel.declared_ns) of
|
||||
true -> [];
|
||||
false -> [Packet#xmlel.ns]
|
||||
end,
|
||||
P = exmpp_xml:xmlel_to_xmlelement(Packet,
|
||||
Default_NS,
|
||||
[{?NS_XMPP, ?NS_XMPP_pfx}, {?NS_DIALBACK, ?NS_DIALBACK_pfx}]),
|
||||
{F, T, P}
|
||||
end,
|
||||
case catch do_route(FromOld, ToOld, PacketOld) of
|
||||
{'EXIT', Reason} ->
|
||||
?ERROR_MSG("~p~nwhen processing: ~p",
|
||||
[Reason, {From, To, Packet}]);
|
||||
@ -303,7 +344,7 @@ do_route(OrigFrom, OrigTo, OrigPacket) ->
|
||||
case ejabberd_hooks:run_fold(filter_packet,
|
||||
{OrigFrom, OrigTo, OrigPacket}, []) of
|
||||
{From, To, Packet} ->
|
||||
LDstDomain = To#jid.lserver,
|
||||
LDstDomain = To#jid.ldomain,
|
||||
case mnesia:dirty_read(route, LDstDomain) of
|
||||
[] ->
|
||||
ejabberd_s2s:route(From, To, Packet);
|
||||
@ -327,14 +368,14 @@ do_route(OrigFrom, OrigTo, OrigPacket) ->
|
||||
{domain_balancing, LDstDomain}) of
|
||||
undefined -> now();
|
||||
random -> now();
|
||||
source -> jlib:jid_tolower(From);
|
||||
destination -> jlib:jid_tolower(To);
|
||||
source -> jlib:short_jid(From);
|
||||
destination -> jlib:short_jid(To);
|
||||
bare_source ->
|
||||
jlib:jid_remove_resource(
|
||||
jlib:jid_tolower(From));
|
||||
jlib:short_jid(
|
||||
exmpp_jid:jid_to_bare_jid(From));
|
||||
bare_destination ->
|
||||
jlib:jid_remove_resource(
|
||||
jlib:jid_tolower(To))
|
||||
jlib:short_jid(
|
||||
exmpp_jid:jid_tl_bare_jid(To))
|
||||
end,
|
||||
case get_component_number(LDstDomain) of
|
||||
undefined ->
|
||||
|
@ -292,10 +292,7 @@ do_route(From, To, Packet) ->
|
||||
_ ->
|
||||
Err = exmpp_stanza:reply_with_error(Packet,
|
||||
exmpp_stanza:error('service-unavailable')),
|
||||
% XXX OLD FORMAT: Err.
|
||||
ErrOld = exmpp_xml:xmlel_to_xmlelement(Err,
|
||||
[?DEFAULT_NS], ?PREFIXED_NS),
|
||||
ejabberd_router:route(ToOld, FromOld, ErrOld)
|
||||
ejabberd_router:route(To, From, Err)
|
||||
end,
|
||||
false
|
||||
end.
|
||||
|
@ -415,7 +415,7 @@ stream_established({xmlstreamelement, El}, StateData) ->
|
||||
LFrom,
|
||||
[FromOld, ToOld, ElOld]),
|
||||
ejabberd_router:route(
|
||||
FromOld, ToOld, ElOld);
|
||||
From, To, El);
|
||||
true ->
|
||||
error
|
||||
end;
|
||||
@ -438,7 +438,7 @@ stream_established({xmlstreamelement, El}, StateData) ->
|
||||
LFrom,
|
||||
[FromOld, ToOld, ElOld]),
|
||||
ejabberd_router:route(
|
||||
FromOld, ToOld, ElOld);
|
||||
From, To, El);
|
||||
true ->
|
||||
error
|
||||
end;
|
||||
|
@ -816,14 +816,9 @@ bounce_element(El, Condition) ->
|
||||
Err = exmpp_stanza:reply_with_error(El, Error),
|
||||
From = exmpp_jid:string_to_jid(exmpp_stanza:get_sender(El)),
|
||||
To = exmpp_jid:string_to_jid(exmpp_stanza:get_recipient(El)),
|
||||
% XXX OLD FORMAT: From, To, Err.
|
||||
% XXX No namespace conversion (:server <-> :client) is done.
|
||||
% No namespace conversion (:server <-> :client) is done.
|
||||
% This is handled by C2S and S2S send_element functions.
|
||||
ErrOld = exmpp_xml:xmlel_to_xmlelement(Err,
|
||||
[?NS_JABBER_CLIENT], ?PREFIXED_NS),
|
||||
FromOld = jlib:to_old_jid(From),
|
||||
ToOld = jlib:to_old_jid(To),
|
||||
ejabberd_router:route(ToOld, FromOld, ErrOld)
|
||||
ejabberd_router:route(To, From, Err)
|
||||
end.
|
||||
|
||||
bounce_queue(Q, Condition) ->
|
||||
|
Loading…
Reference in New Issue
Block a user