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

Routing is now done with #xmlel. A warning is printed if those modules

have to route an old #xmlelement.

SVN Revision: 1406
This commit is contained in:
Jean-Sébastien Pédron 2008-07-01 15:51:34 +00:00
parent 48cf5cb84a
commit 13b78b1ad2
5 changed files with 94 additions and 59 deletions

View File

@ -43,6 +43,11 @@
src/gen_iq_handler.erl: Do not use the #iq record anymore internally.
However it's still created and passed to other modules.
* src/ejabberd_router.erl, src/ejabberd_sm.erl,
src/ejabberd_local.erl, src/ejabberd_s2s.erl: Routing is now done with
#xmlel. A warning is printed if those modules have to route an old
#xmlelement.
2008-06-30 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
* src/Makefile.in: Remove the -I flag for exmpp includes; the

View File

@ -133,21 +133,24 @@ process_iq_reply(From, To, Packet) ->
% 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),
IQ_Rec = jlib:iq_query_or_response_info(PacketOld),
IQ_Rec = jlib:iq_query_or_response_info(Packet),
Module:Function(FromOld, ToOld, IQ_Rec);
_ ->
ok
end
end.
route(FromOld, ToOld, PacketOld) ->
route(FromOld, ToOld, #xmlelement{} = PacketOld) ->
catch throw(for_stacktrace), % To have a stacktrace.
io:format("~nLOCAL: old #xmlelement:~n~p~n~p~n~n",
[PacketOld, erlang:get_stacktrace()]),
% XXX OLD FORMAT: From, To, Packet.
From = jlib:from_old_jid(FromOld),
To = jlib:from_old_jid(ToOld),
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld,
[?DEFAULT_NS], ?PREFIXED_NS),
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld, [?NS_JABBER_CLIENT],
[{?NS_XMPP, ?NS_XMPP_pfx}]),
route(From, To, Packet);
route(From, To, Packet) ->
case catch do_route(From, To, Packet) of
{'EXIT', Reason} ->
?ERROR_MSG("~p~nwhen processing: ~p",
@ -229,12 +232,17 @@ handle_cast(_Msg, State) ->
%% {stop, Reason, State}
%% Description: Handling all non call/cast messages
%%--------------------------------------------------------------------
handle_info({route, FromOld, ToOld, PacketOld}, State) ->
handle_info({route, FromOld, ToOld, #xmlelement{} = PacketOld}, State) ->
catch throw(for_stacktrace), % To have a stacktrace.
io:format("~nLOCAL: old #xmlelement:~n~p~n~p~n~n",
[PacketOld, erlang:get_stacktrace()]),
% XXX OLD FORMAT: From, To, Packet.
From = jlib:from_old_jid(FromOld),
To = jlib:from_old_jid(ToOld),
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld,
[?DEFAULT_NS], ?PREFIXED_NS),
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld, [?NS_JABBER_CLIENT],
[{?NS_XMPP, ?NS_XMPP_pfx}]),
handle_info({route, From, To, Packet}, State);
handle_info({route, From, To, Packet}, State) ->
case catch do_route(From, To, Packet) of
{'EXIT', Reason} ->
?ERROR_MSG("~p~nwhen processing: ~p",

View File

@ -64,10 +64,18 @@ start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
route(FromOld, ToOld, #xmlelement{} = PacketOld) ->
catch throw(for_stacktrace), % To have a stacktrace.
io:format("~nROUTER: old #xmlelement:~n~p~n~p~n~n",
[PacketOld, erlang:get_stacktrace()]),
% XXX OLD FORMAT: From, To, Packet.
From = jlib:from_old_jid(FromOld),
To = jlib:from_old_jid(ToOld),
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld, [?NS_JABBER_CLIENT],
[{?NS_XMPP, ?NS_XMPP_pfx}]),
route(From, To, Packet);
route(From, To, Packet) ->
% XXX OLD FORMAT: This code helps to detect old format routing.
{FromOld, ToOld, PacketOld} = convert_to_old_structs(From, To, Packet),
case catch do_route(FromOld, ToOld, PacketOld) of
case catch do_route(From, To, Packet) of
{'EXIT', Reason} ->
?ERROR_MSG("~p~nwhen processing: ~p",
[Reason, {From, To, Packet}]);
@ -239,9 +247,18 @@ handle_cast(_Msg, State) ->
%% {stop, Reason, State}
%% Description: Handling all non call/cast messages
%%--------------------------------------------------------------------
handle_info({route, FromOld, ToOld, #xmlelement{} = PacketOld}, State) ->
catch throw(for_stacktrace), % To have a stacktrace.
io:format("~nROUTER: old #xmlelement:~n~p~n~p~n~n",
[PacketOld, erlang:get_stacktrace()]),
% XXX OLD FORMAT: From, To, Packet.
From = jlib:from_old_jid(FromOld),
To = jlib:from_old_jid(ToOld),
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld, [?NS_JABBER_CLIENT],
[{?NS_XMPP, ?NS_XMPP_pfx}]),
handle_info({route, From, To, Packet}, State);
handle_info({route, From, To, Packet}, State) ->
{FromOld, ToOld, PacketOld} = convert_to_old_structs(From, To, Packet),
case catch do_route(FromOld, ToOld, PacketOld) of
case catch do_route(From, To, Packet) of
{'EXIT', Reason} ->
?ERROR_MSG("~p~nwhen processing: ~p",
[Reason, {From, To, Packet}]);
@ -304,9 +321,19 @@ code_change(_OldVsn, State, _Extra) ->
do_route(OrigFrom, OrigTo, OrigPacket) ->
?DEBUG("route~n\tfrom ~p~n\tto ~p~n\tpacket ~p~n",
[OrigFrom, OrigTo, OrigPacket]),
% XXX OLD FORMAT: OrigFrom, OrigTo, OrigPacket.
OrigFromOld = jlib:to_old_jid(OrigFrom),
OrigToOld = jlib:to_old_jid(OrigTo),
OrigPacketOld = exmpp_xml:xmlel_to_xmlelement(OrigPacket,
[?NS_JABBER_CLIENT], [{?NS_XMPP, ?NS_XMPP_pfx}]),
case ejabberd_hooks:run_fold(filter_packet,
{OrigFrom, OrigTo, OrigPacket}, []) of
{From, To, Packet} ->
{OrigFromOld, OrigToOld, OrigPacketOld}, []) of
{FromOld, ToOld, PacketOld} ->
% XXX OLD FORMAT: From, To, Packet.
From = jlib:from_old_jid(FromOld),
To = jlib:from_old_jid(ToOld),
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld,
[?NS_JABBER_CLIENT], [{?NS_XMPP, ?NS_XMPP_pfx}]),
LDstDomain = To#jid.ldomain,
case mnesia:dirty_read(route, LDstDomain) of
[] ->
@ -334,11 +361,9 @@ do_route(OrigFrom, OrigTo, OrigPacket) ->
source -> jlib:short_jid(From);
destination -> jlib:short_jid(To);
bare_source ->
jlib:short_jid(
exmpp_jid:jid_to_bare_jid(From));
jlib:short_bare_jid(From);
bare_destination ->
jlib:short_jid(
exmpp_jid:jid_tl_bare_jid(To))
jlib:short_bare_jid(To)
end,
case get_component_number(LDstDomain) of
undefined ->
@ -405,25 +430,3 @@ update_tables() ->
false ->
ok
end.
convert_to_old_structs(From, To, Packet) ->
% XXX OLD FORMAT: This code helps to detect old format routing.
if
is_record(Packet, xmlelement) ->
catch throw(for_stacktrace), % To have a stacktrace.
io:format("~nROUTER: old #xmlelement:~n~p~n~p~n~n",
[Packet, erlang:get_stacktrace()]),
{From, To, Packet};
true ->
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.

View File

@ -74,12 +74,17 @@
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
route(FromOld, ToOld, PacketOld) ->
route(FromOld, ToOld, #xmlelement{} = PacketOld) ->
catch throw(for_stacktrace), % To have a stacktrace.
io:format("~nS2S: old #xmlelement:~n~p~n~p~n~n",
[PacketOld, erlang:get_stacktrace()]),
% XXX OLD FORMAT: From, To, Packet.
From = jlib:from_old_jid(FromOld),
To = jlib:from_old_jid(ToOld),
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld,
[?DEFAULT_NS], ?PREFIXED_NS),
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld, [?NS_JABBER_CLIENT],
[{?NS_XMPP, ?NS_XMPP_pfx}]),
route(From, To, Packet);
route(From, To, Packet) ->
case catch do_route(From, To, Packet) of
{'EXIT', Reason} ->
?ERROR_MSG("~p~nwhen processing: ~p",
@ -214,12 +219,17 @@ handle_cast(_Msg, State) ->
handle_info({mnesia_system_event, {mnesia_down, Node}}, State) ->
clean_table_from_bad_node(Node),
{noreply, State};
handle_info({route, FromOld, ToOld, PacketOld}, State) ->
% XXX OLD FORMAT: From, To, Packet
handle_info({route, FromOld, ToOld, #xmlelement{} = PacketOld}, State) ->
catch throw(for_stacktrace), % To have a stacktrace.
io:format("~nS2S: old #xmlelement:~n~p~n~p~n~n",
[PacketOld, erlang:get_stacktrace()]),
% XXX OLD FORMAT: From, To, Packet.
From = jlib:from_old_jid(FromOld),
To = jlib:from_old_jid(ToOld),
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld,
[?NS_JABBER_CLIENT], [{?NS_XMPP, ?NS_XMPP_pfx}]),
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld, [?NS_JABBER_CLIENT],
[{?NS_XMPP, ?NS_XMPP_pfx}]),
handle_info({route, From, To, Packet}, State);
handle_info({route, From, To, Packet}, State) ->
case catch do_route(From, To, Packet) of
{'EXIT', Reason} ->
?ERROR_MSG("~p~nwhen processing: ~p",
@ -267,16 +277,15 @@ clean_table_from_bad_node(Node) ->
do_route(From, To, Packet) ->
?DEBUG("s2s manager~n\tfrom ~p~n\tto ~p~n\tpacket ~P~n",
[From, To, Packet, 8]),
% XXX OLD FORMAT: From, To.
FromOld = jlib:to_old_jid(From),
ToOld = jlib:to_old_jid(To),
case find_connection(From, To) of
{atomic, Pid} when pid(Pid) ->
?DEBUG("sending to process ~p~n", [Pid]),
NewPacket1 = exmpp_stanza:set_sender(Packet, From),
NewPacket = exmpp_stanza:set_recipient(NewPacket1, To),
#jid{ldomain = MyServer} = From,
% XXX OLD FORMAT: NewPacket.
% XXX OLD FORMAT: From, To, NewPacket.
FromOld = jlib:to_old_jid(From),
ToOld = jlib:to_old_jid(To),
NewPacketOld = exmpp_xml:xmlel_to_xmlelement(NewPacket,
[?DEFAULT_NS], ?PREFIXED_NS),
ejabberd_hooks:run(

View File

@ -84,12 +84,17 @@
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
route(FromOld, ToOld, PacketOld) ->
route(FromOld, ToOld, #xmlelement{} = PacketOld) ->
catch throw(for_stacktrace), % To have a stacktrace.
io:format("~nSM: old #xmlelement:~n~p~n~p~n~n",
[PacketOld, erlang:get_stacktrace()]),
% XXX OLD FORMAT: From, To, Packet.
From = jlib:from_old_jid(FromOld),
To = jlib:from_old_jid(ToOld),
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld,
[?DEFAULT_NS], ?PREFIXED_NS),
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld, [?NS_JABBER_CLIENT],
[{?NS_XMPP, ?NS_XMPP_pfx}]),
route(From, To, Packet);
route(From, To, Packet) ->
case catch do_route(From, To, Packet) of
{'EXIT', Reason} ->
?ERROR_MSG("~p~nwhen processing: ~p",
@ -307,12 +312,17 @@ handle_cast(_Msg, State) ->
%% {stop, Reason, State}
%% Description: Handling all non call/cast messages
%%--------------------------------------------------------------------
handle_info({route, FromOld, ToOld, PacketOld}, State) ->
handle_info({route, FromOld, ToOld, #xmlelement{} = PacketOld}, State) ->
catch throw(for_stacktrace), % To have a stacktrace.
io:format("~nSM: old #xmlelement:~n~p~n~p~n~n",
[PacketOld, erlang:get_stacktrace()]),
% XXX OLD FORMAT: From, To, Packet.
From = jlib:from_old_jid(FromOld),
To = jlib:from_old_jid(ToOld),
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld,
[?DEFAULT_NS], ?PREFIXED_NS),
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld, [?NS_JABBER_CLIENT],
[{?NS_XMPP, ?NS_XMPP_pfx}]),
handle_info({route, From, To, Packet}, State);
handle_info({route, From, To, Packet}, State) ->
case catch do_route(From, To, Packet) of
{'EXIT', Reason} ->
?ERROR_MSG("~p~nwhen processing: ~p",