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

Remove the compatibility layer and always call modules with the new #iq

record from Exmpp.

SVN Revision: 1523
This commit is contained in:
Jean-Sébastien Pédron 2008-08-14 13:34:30 +00:00
parent 44d3e844a3
commit 5e78c53572
4 changed files with 36 additions and 102 deletions

View File

@ -3,6 +3,10 @@
* translate.erl (ascii_tolower): Accept 'undefined' as a language and
treat it as the empty string.
* src/gen_iq_handler.erl, src/ejabberd_local.erl, src/ejabberd_sm.erl:
Remove the compatibility layer and always call modules with the new
#iq record from Exmpp.
2008-08-06 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
* src/mod_offline.erl, src/mod_offline_odbc.erl, src/mod_echo.erl,

View File

@ -74,47 +74,35 @@ start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
process_iq(From, To, Packet) ->
case exmpp_iq:get_kind(Packet) of
request ->
case exmpp_iq:xmlel_to_iq(Packet) of
#iq{kind = request, ns = XMLNS} = IQ_Rec ->
Host = To#jid.ldomain,
Request = exmpp_iq:get_request(Packet),
XMLNS = exmpp_xml:get_ns_as_list(Request),
case ets:lookup(?IQTABLE, {XMLNS, Host}) of
[{_, Module, Function}] ->
% XXX OLD FORMAT: From, To.
FromOld = jlib:to_old_jid(From),
ToOld = jlib:to_old_jid(To),
% XXX OLD FORMAT: IQ_Rec is an #iq.
IQ_Rec = jlib:iq_query_info(Packet),
ResIQ = Module:Function(FromOld, ToOld, IQ_Rec),
ResIQ = Module:Function(From, To, IQ_Rec),
if
ResIQ /= ignore ->
% XXX OLD FORMAT: ResIQ.
ReplyOld = jlib:iq_to_xml(ResIQ),
Reply = exmpp_xml:xmlelement_to_xmlel(ReplyOld,
[?DEFAULT_NS], ?PREFIXED_NS),
ejabberd_router:route(
To, From, Reply);
Reply = exmpp_iq:iq_to_xmlel(ResIQ, To, From),
ejabberd_router:route(To, From, Reply);
true ->
ok
end;
[{_, Module, Function, Opts}] ->
gen_iq_handler:handle(Host, Module, Function, Opts,
From, To, Packet);
From, To, IQ_Rec);
[] ->
Err = exmpp_iq:error(Packet, 'feature-not-implemented'),
Err = exmpp_iq:error(Packet, 'feature-not-implemented'),
ejabberd_router:route(To, From, Err)
end;
response ->
process_iq_reply(From, To, Packet);
#iq{kind = response} = IQ_Rec ->
process_iq_reply(From, To, IQ_Rec);
_ ->
Err = exmpp_iq:error(Packet, 'bad-request'),
Err = exmpp_iq:error(Packet, 'bad-request'),
ejabberd_router:route(To, From, Err),
ok
end.
process_iq_reply(From, To, Packet) ->
ID = exmpp_stanza:get_id(Packet),
process_iq_reply(From, To, #iq{id = ID} = IQ_Rec) ->
case catch mnesia:dirty_read(iq_response, ID) of
[] ->
ok;
@ -131,7 +119,7 @@ process_iq_reply(From, To, Packet) ->
end,
case mnesia:transaction(F) of
{atomic, {Module, Function}} ->
Module:Function(From, To, Packet);
Module:Function(From, To, IQ_Rec);
_ ->
ok
end

View File

@ -665,37 +665,27 @@ get_max_user_sessions(LUser, Host) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
process_iq(From, To, Packet) ->
case exmpp_iq:get_kind(Packet) of
request ->
case exmpp_iq:xmlel_to_iq(Packet) of
#iq{kind = request, ns = XMLNS} = IQ_Rec ->
Host = To#jid.ldomain,
Request = exmpp_iq:get_request(Packet),
XMLNS = exmpp_xml:get_ns_as_list(Request),
case ets:lookup(sm_iqtable, {XMLNS, Host}) of
[{_, Module, Function}] ->
% XXX OLD FORMAT: From, To.
FromOld = jlib:to_old_jid(From),
ToOld = jlib:to_old_jid(To),
% XXX OLD FORMAT: IQ_Rec is an #iq.
IQ_Rec = jlib:iq_query_info(Packet),
ResIQ = Module:Function(FromOld, ToOld, IQ_Rec),
ResIQ = Module:Function(From, To, IQ_Rec),
if
ResIQ /= ignore ->
% XXX OLD FORMAT: ResIQ.
ReplyOld = jlib:iq_to_xml(ResIQ),
Reply = exmpp_xml:xmlelement_to_xmlel(ReplyOld,
[?DEFAULT_NS], ?PREFIXED_NS),
Reply = exmpp_iq:iq_to_xmlel(ResIQ, To, From),
ejabberd_router:route(To, From, Reply);
true ->
ok
end;
[{_, Module, Function, Opts}] ->
gen_iq_handler:handle(Host, Module, Function, Opts,
From, To, Packet);
From, To, IQ_Rec);
[] ->
Err = exmpp_iq:error(Packet, 'service-unavailable'),
ejabberd_router:route(To, From, Err)
end;
response ->
#iq{type = response} ->
ok;
_ ->
Err = exmpp_iq:error(Packet, 'bad-request'),

View File

@ -49,13 +49,6 @@
module,
function}).
% XXX OLD FORMAT: Re-include jlib.hrl (after clean-up).
-record(iq, {id = "",
type,
xmlns = "",
lang = "",
sub_el}).
% XXX OLD FORMAT: modules not in the following list will receive
% old format strudctures.
-define(CONVERTED_MODULES, [
@ -121,60 +114,33 @@ stop_iq_handler(_Module, _Function, Opts) ->
ok
end.
handle(Host, Module, Function, Opts, From, To, IQ) ->
handle(Host, Module, Function, Opts, From, To, IQ_Rec) ->
case Opts of
no_queue ->
process_iq(Host, Module, Function, From, To, IQ);
process_iq(Host, Module, Function, From, To, IQ_Rec);
{one_queue, Pid} ->
Pid ! {process_iq, From, To, IQ};
Pid ! {process_iq, From, To, IQ_Rec};
{queues, Pids} ->
Pid = lists:nth(erlang:phash(now(), length(Pids)), Pids),
Pid ! {process_iq, From, To, IQ};
Pid ! {process_iq, From, To, IQ_Rec};
parallel ->
spawn(?MODULE, process_iq,
[Host, Module, Function, From, To, IQ]);
[Host, Module, Function, From, To, IQ_Rec]);
_ ->
todo
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) ->
Ret = case lists:member(Module, ?CONVERTED_MODULES) 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} ->
?ERROR_MSG("~p", [Reason]);
process_iq(_Host, Module, Function, From, To, IQ_Rec) ->
try Module:Function(From, To, IQ_Rec) of
ignore ->
ok;
ResIQ when is_record(ResIQ, iq) ->
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, Reply);
Reply ->
ResIQ ->
Reply = exmpp_iq:iq_to_xmlel(ResIQ, To, From),
ejabberd_router:route(To, From, Reply)
catch
_Class:Reason ->
?ERROR_MSG("~p~n~p~n", [Reason, erlang:get_stacktrace()])
end.
%%====================================================================
@ -221,11 +187,11 @@ handle_cast(_Msg, State) ->
%% {stop, Reason, State}
%% Description: Handling all non call/cast messages
%%--------------------------------------------------------------------
handle_info({process_iq, From, To, IQ},
handle_info({process_iq, From, To, IQ_Rec},
#state{host = Host,
module = Module,
function = Function} = State) ->
process_iq(Host, Module, Function, From, To, IQ),
process_iq(Host, Module, Function, From, To, IQ_Rec),
{noreply, State};
handle_info(_Info, State) ->
{noreply, State}.
@ -250,17 +216,3 @@ code_change(_OldVsn, State, _Extra) ->
%%--------------------------------------------------------------------
%%% Internal functions
%%--------------------------------------------------------------------
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
is_record(IQ, iq) ->
{From, To, IQ};
true ->
F = jlib:to_old_jid(From),
T = jlib:to_old_jid(To),
I_Rec = jlib:iq_query_info(IQ),
{F, T, I_Rec}
end.