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

Convert gen_iq_handler to exmpp.

SVN Revision: 1401
This commit is contained in:
Jean-Sébastien Pédron 2008-07-01 10:21:35 +00:00
parent 6f7cf2e58b
commit 094fa47f9f
4 changed files with 51 additions and 10 deletions

View File

@ -26,6 +26,11 @@
* src/ejabberd_router.erl: Use a function to convert to old * src/ejabberd_router.erl: Use a function to convert to old
structures instead of duplicating code inside the module. structures instead of duplicating code inside the module.
* src/gen_iq_handler.erl: Convert to exmpp.
* src/ejabberd_sm.erl, src/ejabberd_c2s.erl: Don't convert <iq/>
before calling gen_iq_handler:handle/7.
2008-06-30 Jean-Sébastien Pédron <js.pedron@meetic-corp.com> 2008-06-30 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
* src/Makefile.in: Remove the -I flag for exmpp includes; the * src/Makefile.in: Remove the -I flag for exmpp includes; the

View File

@ -1158,11 +1158,8 @@ handle_info({route, FromOld, ToOld, PacketOld}, StateName, StateData) ->
% for namespaces. % for namespaces.
case ets:lookup(sm_iqtable, {atom_to_list(?NS_VCARD), Host}) of case ets:lookup(sm_iqtable, {atom_to_list(?NS_VCARD), Host}) of
[{_, Module, Function, Opts}] -> [{_, Module, Function, Opts}] ->
% XXX OLD FORMAT: IQ is an old #iq,
% From, To.
IQ = jlib:iq_query_info(PacketOld),
gen_iq_handler:handle(Host, Module, Function, Opts, gen_iq_handler:handle(Host, Module, Function, Opts,
FromOld, ToOld, IQ); From, To, Packet);
[] -> [] ->
Res = exmpp_iq:error(Packet, 'feature-not-implemented'), Res = exmpp_iq:error(Packet, 'feature-not-implemented'),
ejabberd_router:route(To, From, Res) ejabberd_router:route(To, From, Res)
@ -1935,7 +1932,7 @@ resend_subscription_requests(#state{user = User,
process_unauthenticated_stanza(StateData, El) -> process_unauthenticated_stanza(StateData, El) ->
ElOld = exmpp_xml:xmlel_to_xmlelement(El, [?DEFAULT_NS], ?PREFIXED_NS), ElOld = exmpp_xml:xmlel_to_xmlelement(El, [?DEFAULT_NS], ?PREFIXED_NS),
case jlib:iq_query_info(ElOld) of case jlib:iq_query_info(ElOld) of
#iq{} = IQ -> IQ when is_record(IQ, iq) ->
ResOld = ejabberd_hooks:run_fold(c2s_unauthenticated_iq, ResOld = ejabberd_hooks:run_fold(c2s_unauthenticated_iq,
StateData#state.server, StateData#state.server,
empty, empty,

View File

@ -688,7 +688,7 @@ process_iq(From, To, Packet) ->
[{_, Module, Function, Opts}] -> [{_, Module, Function, Opts}] ->
% XXX OLD FORMAT: From, To, IQ. % XXX OLD FORMAT: From, To, IQ.
gen_iq_handler:handle(Host, Module, Function, Opts, gen_iq_handler:handle(Host, Module, Function, Opts,
FromOld, ToOld, IQ); From, To, Packet);
[] -> [] ->
Err = exmpp_iq:error(Packet, 'service-unavailable'), Err = exmpp_iq:error(Packet, 'service-unavailable'),
ejabberd_router:route(To, From, Err) ejabberd_router:route(To, From, Err)

View File

@ -41,12 +41,21 @@
-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").
-record(state, {host, -record(state, {host,
module, module,
function}). function}).
% XXX OLD FORMAT: Re-include jlib.hrl (after clean-up).
-record(iq, {id = "",
type,
xmlns = "",
lang = "",
sub_el}).
%%==================================================================== %%====================================================================
%% API %% API
%%==================================================================== %%====================================================================
@ -101,10 +110,12 @@ 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} ->
Pid ! {process_iq, From, To, IQ}; {FromOld, ToOld, IQ_Rec} = convert_to_old_structs(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),
Pid ! {process_iq, From, To, IQ}; {FromOld, ToOld, IQ_Rec} = convert_to_old_structs(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]);
_ -> _ ->
@ -113,14 +124,20 @@ handle(Host, Module, Function, Opts, From, To, IQ) ->
process_iq(_Host, Module, Function, From, To, IQ) -> process_iq(_Host, Module, Function, From, To, IQ) ->
case catch Module:Function(From, To, IQ) of {FromOld, ToOld, IQ_Rec} = convert_to_old_structs(From, To, IQ),
case catch Module:Function(FromOld, ToOld, IQ_Rec) of
{'EXIT', Reason} -> {'EXIT', Reason} ->
?ERROR_MSG("~p", [Reason]); ?ERROR_MSG("~p", [Reason]);
ResIQ -> ResIQ ->
if if
ResIQ /= ignore -> ResIQ /= ignore ->
ReplyOld = jlib:iq_to_xml(ResIQ),
Reply = exmpp_xml:xmlelement_to_xmlel(ReplyOld,
[?NS_JABBER_CLIENT],
[{?NS_XMPP, ?NS_XMPP_pfx},
{?NS_DIALBACK, ?NS_DIALBACK_pfx}]),
ejabberd_router:route(To, From, ejabberd_router:route(To, From,
jlib:iq_to_xml(ResIQ)); Reply);
true -> true ->
ok ok
end end
@ -199,3 +216,25 @@ code_change(_OldVsn, State, _Extra) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%%% Internal functions %%% Internal functions
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
convert_to_old_structs(From, To, IQ) ->
if
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};
true ->
F = jlib:to_old_jid(From),
T = jlib:to_old_jid(To),
Default_NS = case lists:member({IQ#xmlel.ns, none},
IQ#xmlel.declared_ns) of
true -> [];
false -> [IQ#xmlel.ns]
end,
IQOld = exmpp_xml:xmlel_to_xmlelement(IQ,
Default_NS,
[{?NS_XMPP, ?NS_XMPP_pfx}, {?NS_DIALBACK, ?NS_DIALBACK_pfx}]),
I = jlib:iq_query_info(IQOld),
{F, T, I}
end.