25
1
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:
Jean-Sébastien Pédron 2008-06-30 16:55:03 +00:00
parent cc033b3b98
commit 06965000a5
6 changed files with 91 additions and 83 deletions

View File

@ -16,6 +16,16 @@
src/ejabberd_s2s_out.erl: Use the new functions from jlib. Use the new src/ejabberd_s2s_out.erl: Use the new functions from jlib. Use the new
exmpp_xml:node_to_list/3. 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> 2008-06-27 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
* src/ejabberd_c2s.erl, src/ejabberd_s2s_out.erl, * src/ejabberd_c2s.erl, src/ejabberd_s2s_out.erl,

View File

@ -857,9 +857,8 @@ session_established({xmlstreamelement, El}, StateData) ->
user_send_packet, user_send_packet,
Server, Server,
[FromJIDOld, ToJIDOld, NewElOld]), [FromJIDOld, ToJIDOld, NewElOld]),
% XXX OLD FORMAT: NewElOld.
ejabberd_router:route( ejabberd_router:route(
FromJIDOld, ToJIDOld, NewElOld), FromJID, ToJID, NewEl),
StateData StateData
end; end;
#xmlel{ns = ?NS_JABBER_CLIENT, name = 'message'} -> #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message'} ->
@ -871,8 +870,7 @@ session_established({xmlstreamelement, El}, StateData) ->
ejabberd_hooks:run(user_send_packet, ejabberd_hooks:run(user_send_packet,
Server, Server,
[FromJIDOld, ToJIDOld, NewElOld]), [FromJIDOld, ToJIDOld, NewElOld]),
% XXX OLD FORMAT: NewElOld. ejabberd_router:route(FromJID, ToJID, NewEl),
ejabberd_router:route(FromJIDOld, ToJIDOld, NewElOld),
StateData; StateData;
_ -> _ ->
StateData StateData
@ -1186,10 +1184,7 @@ handle_info({route, FromOld, ToOld, PacketOld}, StateName, StateData) ->
[] -> [] ->
Err = exmpp_stanza:error('feature-not-implemented'), Err = exmpp_stanza:error('feature-not-implemented'),
Res = exmpp_iq:error(Packet, Err), Res = exmpp_iq:error(Packet, Err),
% XXX OLD FORMAT: To, From, Res. ejabberd_router:route(To, From, Res)
ResOld = exmpp_xml:xmlel_to_xmlelement(
Res, [?DEFAULT_NS], ?PREFIXED_NS),
ejabberd_router:route(ToOld, FromOld, ResOld)
end, end,
{false, Attrs, StateData}; {false, Attrs, StateData};
_ -> _ ->
@ -1208,11 +1203,7 @@ handle_info({route, FromOld, ToOld, PacketOld}, StateName, StateData) ->
Err = exmpp_stanza:error( Err = exmpp_stanza:error(
'feature-not-implemented'), 'feature-not-implemented'),
Res = exmpp_iq:error(Packet, Err), Res = exmpp_iq:error(Packet, Err),
% XXX OLD FORMAT: To, From, Res. ejabberd_router:route(To, From, Res),
ResOld = exmpp_xml:xmlel_to_xmlelement(
Res,
[?DEFAULT_NS], ?PREFIXED_NS),
ejabberd_router:route(ToOld, FromOld, ResOld),
{false, Attrs, StateData} {false, Attrs, StateData}
end end
end; end;
@ -1446,20 +1437,14 @@ process_presence_probe(From, To, StateData) ->
%% Don't route a presence probe to oneself %% Don't route a presence probe to oneself
case From == To of case From == To of
false -> false ->
% XXX OLD FORMAT: From, To, Packet. ejabberd_router:route(To, From, Packet);
ejabberd_router:route(ToOld, FromOld, PacketOld);
true -> true ->
ok ok
end end
end; end;
Cond2 -> Cond2 ->
Packet = exmpp_presence:available(), Packet = exmpp_presence:available(),
% XXX OLD FORMAT: From, To, Packet. ejabberd_router:route(To, From, 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);
true -> true ->
ok ok
end end
@ -1584,21 +1569,19 @@ presence_track(From, To, Packet, StateData) ->
Server = StateData#state.server, Server = StateData#state.server,
% XXX OLD FORMAT: From, To, Packet. % XXX OLD FORMAT: From, To, Packet.
FromOld = jlib:to_old_jid(From), 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), ToOld = jlib:to_old_jid(To),
PacketOld = exmpp_xml:xmlel_to_xmlelement(Packet, PacketOld = exmpp_xml:xmlel_to_xmlelement(Packet,
[?DEFAULT_NS], ?PREFIXED_NS), [?DEFAULT_NS], ?PREFIXED_NS),
case exmpp_presence:get_type(Packet) of case exmpp_presence:get_type(Packet) of
'unavailable' -> 'unavailable' ->
% XXX OLD FORMAT: From, To, Packet. ejabberd_router:route(From, To, Packet),
ejabberd_router:route(FromOld, ToOld, PacketOld),
I = remove_element(LTo, StateData#state.pres_i), I = remove_element(LTo, StateData#state.pres_i),
A = remove_element(LTo, StateData#state.pres_a), A = remove_element(LTo, StateData#state.pres_a),
StateData#state{pres_i = I, StateData#state{pres_i = I,
pres_a = A}; pres_a = A};
'invisible' -> 'invisible' ->
% XXX OLD FORMAT: From, To, Packet. ejabberd_router:route(From, To, Packet),
ejabberd_router:route(FromOld, ToOld, PacketOld),
I = ?SETS:add_element(LTo, StateData#state.pres_i), I = ?SETS:add_element(LTo, StateData#state.pres_i),
A = remove_element(LTo, StateData#state.pres_a), A = remove_element(LTo, StateData#state.pres_a),
StateData#state{pres_i = I, StateData#state{pres_i = I,
@ -1608,40 +1591,34 @@ presence_track(From, To, Packet, StateData) ->
ejabberd_hooks:run(roster_out_subscription, ejabberd_hooks:run(roster_out_subscription,
Server, Server,
[User, Server, ToOld, subscribe]), [User, Server, ToOld, subscribe]),
% XXX OLD FORMAT: From, To, Packet. ejabberd_router:route(BFrom, To, Packet),
ejabberd_router:route(BFromOld, ToOld, PacketOld),
StateData; StateData;
'subscribed' -> 'subscribed' ->
% XXX OLD FORMAT: To. % XXX OLD FORMAT: To.
ejabberd_hooks:run(roster_out_subscription, ejabberd_hooks:run(roster_out_subscription,
Server, Server,
[User, Server, ToOld, subscribed]), [User, Server, ToOld, subscribed]),
% XXX OLD FORMAT: From, To, Packet. ejabberd_router:route(BFrom, To, Packet),
ejabberd_router:route(BFromOld, ToOld, PacketOld),
StateData; StateData;
'unsubscribe' -> 'unsubscribe' ->
% XXX OLD FORMAT: To. % XXX OLD FORMAT: To.
ejabberd_hooks:run(roster_out_subscription, ejabberd_hooks:run(roster_out_subscription,
Server, Server,
[User, Server, ToOld, unsubscribe]), [User, Server, ToOld, unsubscribe]),
% XXX OLD FORMAT: From, To, Packet. ejabberd_router:route(BFrom, To, Packet),
ejabberd_router:route(BFromOld, ToOld, PacketOld),
StateData; StateData;
'unsubscribed' -> 'unsubscribed' ->
% XXX OLD FORMAT: To. % XXX OLD FORMAT: To.
ejabberd_hooks:run(roster_out_subscription, ejabberd_hooks:run(roster_out_subscription,
Server, Server,
[User, Server, ToOld, unsubscribed]), [User, Server, ToOld, unsubscribed]),
% XXX OLD FORMAT: From, To, Packet. ejabberd_router:route(BFrom, To, Packet),
ejabberd_router:route(BFromOld, ToOld, PacketOld),
StateData; StateData;
'error' -> 'error' ->
% XXX OLD FORMAT: From, To, Packet. ejabberd_router:route(From, To, Packet),
ejabberd_router:route(FromOld, ToOld, PacketOld),
StateData; StateData;
'probe' -> 'probe' ->
% XXX OLD FORMAT: From, To, Packet. ejabberd_router:route(From, To, Packet),
ejabberd_router:route(FromOld, ToOld, PacketOld),
StateData; StateData;
_ -> _ ->
% XXX OLD FORMAT: From, To, Packet. % XXX OLD FORMAT: From, To, Packet.
@ -1656,8 +1633,7 @@ presence_track(From, To, Packet, StateData) ->
deny -> deny ->
ok; ok;
allow -> allow ->
% XXX OLD FORMAT: From, To, Packet. ejabberd_router:route(From, To, Packet)
ejabberd_router:route(FromOld, ToOld, PacketOld)
end, end,
I = remove_element(LTo, StateData#state.pres_i), I = remove_element(LTo, StateData#state.pres_i),
A = ?SETS:add_element(LTo, StateData#state.pres_a), A = ?SETS:add_element(LTo, StateData#state.pres_a),
@ -1684,8 +1660,7 @@ presence_broadcast(StateData, From, JIDSet, Packet) ->
deny -> deny ->
ok; ok;
allow -> allow ->
% XXX OLD FORMAT: From, FJID, Packet. ejabberd_router:route(From, FJID, Packet)
ejabberd_router:route(FromOld, FJIDOld, PacketOld)
end end
end, ?SETS:to_list(JIDSet)). end, ?SETS:to_list(JIDSet)).
@ -1712,8 +1687,7 @@ presence_broadcast_to_trusted(StateData, From, T, A, Packet) ->
deny -> deny ->
ok; ok;
allow -> allow ->
% XXX OLD FORMAT: From, FJID, Packet. ejabberd_router:route(From, FJID, Packet)
ejabberd_router:route(FromOld, FJIDOld, PacketOld)
end; end;
_ -> _ ->
ok ok
@ -1727,16 +1701,12 @@ presence_broadcast_first(From, StateData, Packet) ->
FromOld = jlib:to_old_jid(From), FromOld = jlib:to_old_jid(From),
PacketOld = exmpp_xml:xmlel_to_xmlelement(Packet, PacketOld = exmpp_xml:xmlel_to_xmlelement(Packet,
[?DEFAULT_NS], ?PREFIXED_NS), [?DEFAULT_NS], ?PREFIXED_NS),
ProbeOld = exmpp_xml:xmlel_to_xmlelement(Probe,
[?DEFAULT_NS], ?PREFIXED_NS),
?SETS:fold(fun({U, S, R}, X) -> ?SETS:fold(fun({U, S, R}, X) ->
FJID = exmpp_jid:make_jid(U, S, R), FJID = exmpp_jid:make_jid(U, S, R),
% XXX OLD FORMAT: FJID.
FJIDOld = jlib:to_old_jid(FJID),
ejabberd_router:route( ejabberd_router:route(
FromOld, From,
FJIDOld, FJID,
ProbeOld), Probe),
X X
end, end,
[], [],
@ -1761,7 +1731,7 @@ presence_broadcast_first(From, StateData, Packet) ->
deny -> deny ->
ok; ok;
allow -> allow ->
ejabberd_router:route(FromOld, FJIDOld, PacketOld) ejabberd_router:route(From, FJID, Packet)
end, end,
?SETS:add_element(JID, A) ?SETS:add_element(JID, A)
end, end,
@ -1830,8 +1800,7 @@ roster_change(IJID, ISubscription, StateData) ->
deny -> deny ->
ok; ok;
allow -> allow ->
% XXX OLD FORMAT: From, To, P. ejabberd_router:route(From, To, P)
ejabberd_router:route(FromOld, ToOld, POld)
end, end,
A = ?SETS:add_element(LIJID, A = ?SETS:add_element(LIJID,
StateData#state.pres_a), StateData#state.pres_a),
@ -1856,8 +1825,7 @@ roster_change(IJID, ISubscription, StateData) ->
deny -> deny ->
ok; ok;
allow -> allow ->
% XXX OLD FORMAT: From, To, PU. ejabberd_router:route(From, To, PU)
ejabberd_router:route(FromOld, ToOld, PUOld)
end, end,
I = remove_element(LIJID, I = remove_element(LIJID,
StateData#state.pres_i), StateData#state.pres_i),
@ -1926,11 +1894,8 @@ process_privacy_iq(From, To,
[?DEFAULT_NS], ?PREFIXED_NS), [?DEFAULT_NS], ?PREFIXED_NS),
exmpp_iq:error(El, Error) exmpp_iq:error(El, Error)
end, end,
% XXX OLD FORMAT: To, From, IQRes.
IQResOld = exmpp_xml:xmlel_to_xmlelement(IQRes,
[?DEFAULT_NS], ?PREFIXED_NS),
ejabberd_router:route( ejabberd_router:route(
ToOld, FromOld, IQResOld), To, From, IQRes),
NewStateData. NewStateData.

View File

@ -46,8 +46,9 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]). terminate/2, code_change/3]).
-include_lib("exmpp/include/exmpp.hrl").
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("jlib.hrl").
-record(route, {domain, pid, local_hint}). -record(route, {domain, pid, local_hint}).
-record(state, {}). -record(state, {}).
@ -64,7 +65,27 @@ start_link() ->
route(From, To, Packet) -> 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} -> {'EXIT', Reason} ->
?ERROR_MSG("~p~nwhen processing: ~p", ?ERROR_MSG("~p~nwhen processing: ~p",
[Reason, {From, To, Packet}]); [Reason, {From, To, Packet}]);
@ -237,7 +258,27 @@ handle_cast(_Msg, State) ->
%% Description: Handling all non call/cast messages %% Description: Handling all non call/cast messages
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
handle_info({route, From, To, Packet}, State) -> 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} -> {'EXIT', Reason} ->
?ERROR_MSG("~p~nwhen processing: ~p", ?ERROR_MSG("~p~nwhen processing: ~p",
[Reason, {From, To, Packet}]); [Reason, {From, To, Packet}]);
@ -303,7 +344,7 @@ do_route(OrigFrom, OrigTo, OrigPacket) ->
case ejabberd_hooks:run_fold(filter_packet, case ejabberd_hooks:run_fold(filter_packet,
{OrigFrom, OrigTo, OrigPacket}, []) of {OrigFrom, OrigTo, OrigPacket}, []) of
{From, To, Packet} -> {From, To, Packet} ->
LDstDomain = To#jid.lserver, LDstDomain = To#jid.ldomain,
case mnesia:dirty_read(route, LDstDomain) of case mnesia:dirty_read(route, LDstDomain) of
[] -> [] ->
ejabberd_s2s:route(From, To, Packet); ejabberd_s2s:route(From, To, Packet);
@ -327,14 +368,14 @@ do_route(OrigFrom, OrigTo, OrigPacket) ->
{domain_balancing, LDstDomain}) of {domain_balancing, LDstDomain}) of
undefined -> now(); undefined -> now();
random -> now(); random -> now();
source -> jlib:jid_tolower(From); source -> jlib:short_jid(From);
destination -> jlib:jid_tolower(To); destination -> jlib:short_jid(To);
bare_source -> bare_source ->
jlib:jid_remove_resource( jlib:short_jid(
jlib:jid_tolower(From)); exmpp_jid:jid_to_bare_jid(From));
bare_destination -> bare_destination ->
jlib:jid_remove_resource( jlib:short_jid(
jlib:jid_tolower(To)) exmpp_jid:jid_tl_bare_jid(To))
end, end,
case get_component_number(LDstDomain) of case get_component_number(LDstDomain) of
undefined -> undefined ->

View File

@ -292,10 +292,7 @@ do_route(From, To, Packet) ->
_ -> _ ->
Err = exmpp_stanza:reply_with_error(Packet, Err = exmpp_stanza:reply_with_error(Packet,
exmpp_stanza:error('service-unavailable')), exmpp_stanza:error('service-unavailable')),
% XXX OLD FORMAT: Err. ejabberd_router:route(To, From, Err)
ErrOld = exmpp_xml:xmlel_to_xmlelement(Err,
[?DEFAULT_NS], ?PREFIXED_NS),
ejabberd_router:route(ToOld, FromOld, ErrOld)
end, end,
false false
end. end.

View File

@ -415,7 +415,7 @@ stream_established({xmlstreamelement, El}, StateData) ->
LFrom, LFrom,
[FromOld, ToOld, ElOld]), [FromOld, ToOld, ElOld]),
ejabberd_router:route( ejabberd_router:route(
FromOld, ToOld, ElOld); From, To, El);
true -> true ->
error error
end; end;
@ -438,7 +438,7 @@ stream_established({xmlstreamelement, El}, StateData) ->
LFrom, LFrom,
[FromOld, ToOld, ElOld]), [FromOld, ToOld, ElOld]),
ejabberd_router:route( ejabberd_router:route(
FromOld, ToOld, ElOld); From, To, El);
true -> true ->
error error
end; end;

View File

@ -816,14 +816,9 @@ bounce_element(El, Condition) ->
Err = exmpp_stanza:reply_with_error(El, Error), Err = exmpp_stanza:reply_with_error(El, Error),
From = exmpp_jid:string_to_jid(exmpp_stanza:get_sender(El)), From = exmpp_jid:string_to_jid(exmpp_stanza:get_sender(El)),
To = exmpp_jid:string_to_jid(exmpp_stanza:get_recipient(El)), To = exmpp_jid:string_to_jid(exmpp_stanza:get_recipient(El)),
% XXX OLD FORMAT: From, To, Err. % No namespace conversion (:server <-> :client) is done.
% XXX No namespace conversion (:server <-> :client) is done.
% This is handled by C2S and S2S send_element functions. % This is handled by C2S and S2S send_element functions.
ErrOld = exmpp_xml:xmlel_to_xmlelement(Err, ejabberd_router:route(To, From, Err)
[?NS_JABBER_CLIENT], ?PREFIXED_NS),
FromOld = jlib:to_old_jid(From),
ToOld = jlib:to_old_jid(To),
ejabberd_router:route(ToOld, FromOld, ErrOld)
end. end.
bounce_queue(Q, Condition) -> bounce_queue(Q, Condition) ->