From 6f7cf2e58b770af7eb109856e4eeedd4f5e8389c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Tue, 1 Jul 2008 10:20:01 +0000 Subject: [PATCH] Use a function to convert to old structures instead of duplicating code inside the module. SVN Revision: 1400 --- ChangeLog | 3 ++ src/ejabberd_router.erl | 62 +++++++++++++++-------------------------- 2 files changed, 26 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9c98b3e51..a73436b6c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -23,6 +23,9 @@ * src/ejabberd_c2s.erl, src/ejabberd_s2s_in.erl: acl doesn't require conversion anymore. + * src/ejabberd_router.erl: Use a function to convert to old + structures instead of duplicating code inside the module. + 2008-06-30 Jean-Sébastien Pédron * src/Makefile.in: Remove the -I flag for exmpp includes; the diff --git a/src/ejabberd_router.erl b/src/ejabberd_router.erl index d31c90132..26c494ba0 100644 --- a/src/ejabberd_router.erl +++ b/src/ejabberd_router.erl @@ -66,25 +66,7 @@ start_link() -> route(From, To, Packet) -> % 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, + {FromOld, ToOld, PacketOld} = convert_to_old_structs(From, To, Packet), case catch do_route(FromOld, ToOld, PacketOld) of {'EXIT', Reason} -> ?ERROR_MSG("~p~nwhen processing: ~p", @@ -258,26 +240,7 @@ handle_cast(_Msg, State) -> %% Description: Handling all non call/cast messages %%-------------------------------------------------------------------- handle_info({route, From, To, Packet}, State) -> - % 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, + {FromOld, ToOld, PacketOld} = convert_to_old_structs(From, To, Packet), case catch do_route(FromOld, ToOld, PacketOld) of {'EXIT', Reason} -> ?ERROR_MSG("~p~nwhen processing: ~p", @@ -443,3 +406,24 @@ update_tables() -> 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("~nROUTE: 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.