25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-26 16:26:24 +01:00

Prepare gen_iq_handler to pass arguments in the new format to a built-in

list of modules known to support them. Other modules will still receive
arguments in the old format.

SVN Revision: 1462
This commit is contained in:
Jean-Sébastien Pédron 2008-07-21 15:28:44 +00:00
parent 07b1210b50
commit 75a8be230b
2 changed files with 60 additions and 31 deletions

View File

@ -1,3 +1,9 @@
2008-07-21 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
* src/gen_iq_handler.erl: Prepare gen_iq_handler to pass arguments in
the new format to a built-in list of modules known to support them.
Other modules will still receive arguments in the old format.
2008-07-17 Jean-Sébastien Pédron <js.pedron@meetic-corp.com> 2008-07-17 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
Merge revisions from 1444 to revision 1457 from trunk. Merge revisions from 1444 to revision 1457 from trunk.

View File

@ -56,6 +56,11 @@
lang = "", lang = "",
sub_el}). sub_el}).
% XXX OLD FORMAT: modules not in the following list will receive
% old format strudctures.
-define(CONVERTED_MODULES, [
]).
%%==================================================================== %%====================================================================
%% API %% API
%%==================================================================== %%====================================================================
@ -110,37 +115,55 @@ handle(Host, Module, Function, Opts, From, To, IQ) ->
no_queue -> no_queue ->
process_iq(Host, Module, Function, From, To, IQ); process_iq(Host, Module, Function, From, To, IQ);
{one_queue, Pid} -> {one_queue, Pid} ->
{FromOld, ToOld, IQ_Rec} = convert_to_old_structs(From, To, IQ), Pid ! {process_iq, From, To, IQ};
Pid ! {process_iq, FromOld, ToOld, IQ_Rec};
{queues, Pids} -> {queues, Pids} ->
Pid = lists:nth(erlang:phash(now(), length(Pids)), Pids), Pid = lists:nth(erlang:phash(now(), length(Pids)), Pids),
{FromOld, ToOld, IQ_Rec} = convert_to_old_structs(From, To, IQ), Pid ! {process_iq, From, To, IQ};
Pid ! {process_iq, FromOld, ToOld, IQ_Rec};
parallel -> parallel ->
spawn(?MODULE, process_iq, [Host, Module, Function, From, To, IQ]); spawn(?MODULE, process_iq,
[Host, Module, Function, From, To, IQ]);
_ -> _ ->
todo todo
end. end.
process_iq(Host, Module, Function, FromOld, ToOld, IQ_Rec)
when is_record(IQ_Rec, iq) ->
catch throw(for_stacktrace), % To have a stacktrace.
io:format("~nIQ HANDLER: old #iq for ~s:~s:~n~p~n~p~n~n",
[Module, Function, IQ_Rec, erlang:get_stacktrace()]),
From = jlib:from_old_jid(FromOld),
To = jlib:from_old_jid(ToOld),
IQOld = jlib:iq_to_xml(IQ_Rec),
IQOld1 = IQOld#xmlelement{children = [IQOld#xmlelement.children]},
IQ = exmpp_xml:xmlelement_to_xmlel(IQOld1,
[?NS_JABBER_CLIENT],
[{?NS_XMPP, ?NS_XMPP_pfx},
{?NS_DIALBACK, ?NS_DIALBACK_pfx}]),
process_iq(Host, Module, Function, From, To, IQ);
process_iq(_Host, Module, Function, From, To, IQ) -> process_iq(_Host, Module, Function, From, To, IQ) ->
{FromOld, ToOld, IQ_Rec} = convert_to_old_structs(From, To, IQ), Ret = case lists:member(Module, ?CONVERTED_MODULES) of
case catch Module:Function(FromOld, ToOld, IQ_Rec) of true ->
catch Module:Function(From, To, IQ);
false ->
{FromOld, ToOld, IQ_Rec} = convert_to_old_structs(
Module, Function, From, To, IQ),
catch Module:Function(FromOld, ToOld, IQ_Rec)
end,
case Ret of
{'EXIT', Reason} -> {'EXIT', Reason} ->
?ERROR_MSG("~p", [Reason]); ?ERROR_MSG("~p", [Reason]);
ResIQ -> ignore ->
if ok;
ResIQ /= ignore -> ResIQ when is_record(ResIQ, iq) ->
ReplyOld = jlib:iq_to_xml(ResIQ), ReplyOld = jlib:iq_to_xml(ResIQ),
Reply = exmpp_xml:xmlelement_to_xmlel(ReplyOld, Reply = exmpp_xml:xmlelement_to_xmlel(ReplyOld,
[?NS_JABBER_CLIENT], [?NS_JABBER_CLIENT],
[{?NS_XMPP, ?NS_XMPP_pfx}, [{?NS_XMPP, ?NS_XMPP_pfx},
{?NS_DIALBACK, ?NS_DIALBACK_pfx}]), {?NS_DIALBACK, ?NS_DIALBACK_pfx}]),
ejabberd_router:route(To, From, ejabberd_router:route(To, From, Reply);
Reply); Reply ->
true -> ejabberd_router:route(To, From, Reply)
ok
end
end. end.
%%==================================================================== %%====================================================================
@ -217,12 +240,12 @@ code_change(_OldVsn, State, _Extra) ->
%%% Internal functions %%% Internal functions
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
convert_to_old_structs(From, To, IQ) -> convert_to_old_structs(Mod, Fun, From, To, IQ) ->
catch throw(for_stacktrace), % To have a stacktrace.
io:format("~nIQ HANDLER: ~s:~s expects old #iq:~n~p~n~p~n~n",
[Mod, Fun, IQ, erlang:get_stacktrace()]),
if if
is_record(IQ, iq) -> is_record(IQ, iq) ->
catch throw(for_stacktrace), % To have a stacktrace.
io:format("~nIQ HANDLER: old #iq:~n~p~n~p~n~n",
[IQ, erlang:get_stacktrace()]),
{From, To, IQ}; {From, To, IQ};
true -> true ->
F = jlib:to_old_jid(From), F = jlib:to_old_jid(From),