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:
parent
44d3e844a3
commit
5e78c53572
@ -3,6 +3,10 @@
|
|||||||
* translate.erl (ascii_tolower): Accept 'undefined' as a language and
|
* translate.erl (ascii_tolower): Accept 'undefined' as a language and
|
||||||
treat it as the empty string.
|
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>
|
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,
|
* src/mod_offline.erl, src/mod_offline_odbc.erl, src/mod_echo.erl,
|
||||||
|
@ -74,47 +74,35 @@ start_link() ->
|
|||||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||||
|
|
||||||
process_iq(From, To, Packet) ->
|
process_iq(From, To, Packet) ->
|
||||||
case exmpp_iq:get_kind(Packet) of
|
case exmpp_iq:xmlel_to_iq(Packet) of
|
||||||
request ->
|
#iq{kind = request, ns = XMLNS} = IQ_Rec ->
|
||||||
Host = To#jid.ldomain,
|
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
|
case ets:lookup(?IQTABLE, {XMLNS, Host}) of
|
||||||
[{_, Module, Function}] ->
|
[{_, Module, Function}] ->
|
||||||
% XXX OLD FORMAT: From, To.
|
ResIQ = Module:Function(From, To, IQ_Rec),
|
||||||
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),
|
|
||||||
if
|
if
|
||||||
ResIQ /= ignore ->
|
ResIQ /= ignore ->
|
||||||
% XXX OLD FORMAT: ResIQ.
|
Reply = exmpp_iq:iq_to_xmlel(ResIQ, To, From),
|
||||||
ReplyOld = jlib:iq_to_xml(ResIQ),
|
ejabberd_router:route(To, From, Reply);
|
||||||
Reply = exmpp_xml:xmlelement_to_xmlel(ReplyOld,
|
|
||||||
[?DEFAULT_NS], ?PREFIXED_NS),
|
|
||||||
ejabberd_router:route(
|
|
||||||
To, From, Reply);
|
|
||||||
true ->
|
true ->
|
||||||
ok
|
ok
|
||||||
end;
|
end;
|
||||||
[{_, Module, Function, Opts}] ->
|
[{_, Module, Function, Opts}] ->
|
||||||
gen_iq_handler:handle(Host, 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)
|
ejabberd_router:route(To, From, Err)
|
||||||
end;
|
end;
|
||||||
response ->
|
#iq{kind = response} = IQ_Rec ->
|
||||||
process_iq_reply(From, To, Packet);
|
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),
|
ejabberd_router:route(To, From, Err),
|
||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
process_iq_reply(From, To, Packet) ->
|
process_iq_reply(From, To, #iq{id = ID} = IQ_Rec) ->
|
||||||
ID = exmpp_stanza:get_id(Packet),
|
|
||||||
case catch mnesia:dirty_read(iq_response, ID) of
|
case catch mnesia:dirty_read(iq_response, ID) of
|
||||||
[] ->
|
[] ->
|
||||||
ok;
|
ok;
|
||||||
@ -131,7 +119,7 @@ process_iq_reply(From, To, Packet) ->
|
|||||||
end,
|
end,
|
||||||
case mnesia:transaction(F) of
|
case mnesia:transaction(F) of
|
||||||
{atomic, {Module, Function}} ->
|
{atomic, {Module, Function}} ->
|
||||||
Module:Function(From, To, Packet);
|
Module:Function(From, To, IQ_Rec);
|
||||||
_ ->
|
_ ->
|
||||||
ok
|
ok
|
||||||
end
|
end
|
||||||
|
@ -665,37 +665,27 @@ get_max_user_sessions(LUser, Host) ->
|
|||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
process_iq(From, To, Packet) ->
|
process_iq(From, To, Packet) ->
|
||||||
case exmpp_iq:get_kind(Packet) of
|
case exmpp_iq:xmlel_to_iq(Packet) of
|
||||||
request ->
|
#iq{kind = request, ns = XMLNS} = IQ_Rec ->
|
||||||
Host = To#jid.ldomain,
|
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
|
case ets:lookup(sm_iqtable, {XMLNS, Host}) of
|
||||||
[{_, Module, Function}] ->
|
[{_, Module, Function}] ->
|
||||||
% XXX OLD FORMAT: From, To.
|
ResIQ = Module:Function(From, To, IQ_Rec),
|
||||||
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),
|
|
||||||
if
|
if
|
||||||
ResIQ /= ignore ->
|
ResIQ /= ignore ->
|
||||||
% XXX OLD FORMAT: ResIQ.
|
Reply = exmpp_iq:iq_to_xmlel(ResIQ, To, From),
|
||||||
ReplyOld = jlib:iq_to_xml(ResIQ),
|
|
||||||
Reply = exmpp_xml:xmlelement_to_xmlel(ReplyOld,
|
|
||||||
[?DEFAULT_NS], ?PREFIXED_NS),
|
|
||||||
ejabberd_router:route(To, From, Reply);
|
ejabberd_router:route(To, From, Reply);
|
||||||
true ->
|
true ->
|
||||||
ok
|
ok
|
||||||
end;
|
end;
|
||||||
[{_, Module, Function, Opts}] ->
|
[{_, Module, Function, Opts}] ->
|
||||||
gen_iq_handler:handle(Host, 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'),
|
Err = exmpp_iq:error(Packet, 'service-unavailable'),
|
||||||
ejabberd_router:route(To, From, Err)
|
ejabberd_router:route(To, From, Err)
|
||||||
end;
|
end;
|
||||||
response ->
|
#iq{type = response} ->
|
||||||
ok;
|
ok;
|
||||||
_ ->
|
_ ->
|
||||||
Err = exmpp_iq:error(Packet, 'bad-request'),
|
Err = exmpp_iq:error(Packet, 'bad-request'),
|
||||||
|
@ -49,13 +49,6 @@
|
|||||||
module,
|
module,
|
||||||
function}).
|
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
|
% XXX OLD FORMAT: modules not in the following list will receive
|
||||||
% old format strudctures.
|
% old format strudctures.
|
||||||
-define(CONVERTED_MODULES, [
|
-define(CONVERTED_MODULES, [
|
||||||
@ -121,60 +114,33 @@ stop_iq_handler(_Module, _Function, Opts) ->
|
|||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
handle(Host, Module, Function, Opts, From, To, IQ) ->
|
handle(Host, Module, Function, Opts, From, To, IQ_Rec) ->
|
||||||
case Opts of
|
case Opts of
|
||||||
no_queue ->
|
no_queue ->
|
||||||
process_iq(Host, Module, Function, From, To, IQ);
|
process_iq(Host, Module, Function, From, To, IQ_Rec);
|
||||||
{one_queue, Pid} ->
|
{one_queue, Pid} ->
|
||||||
Pid ! {process_iq, From, To, IQ};
|
Pid ! {process_iq, From, To, 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};
|
Pid ! {process_iq, From, To, IQ_Rec};
|
||||||
parallel ->
|
parallel ->
|
||||||
spawn(?MODULE, process_iq,
|
spawn(?MODULE, process_iq,
|
||||||
[Host, Module, Function, From, To, IQ]);
|
[Host, Module, Function, From, To, IQ_Rec]);
|
||||||
_ ->
|
_ ->
|
||||||
todo
|
todo
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
process_iq(Host, Module, Function, FromOld, ToOld, IQ_Rec)
|
process_iq(_Host, Module, Function, From, To, IQ_Rec) ->
|
||||||
when is_record(IQ_Rec, iq) ->
|
try Module:Function(From, To, IQ_Rec) of
|
||||||
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]);
|
|
||||||
ignore ->
|
ignore ->
|
||||||
ok;
|
ok;
|
||||||
ResIQ when is_record(ResIQ, iq) ->
|
ResIQ ->
|
||||||
ReplyOld = jlib:iq_to_xml(ResIQ),
|
Reply = exmpp_iq:iq_to_xmlel(ResIQ, To, From),
|
||||||
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 ->
|
|
||||||
ejabberd_router:route(To, From, Reply)
|
ejabberd_router:route(To, From, Reply)
|
||||||
|
catch
|
||||||
|
_Class:Reason ->
|
||||||
|
?ERROR_MSG("~p~n~p~n", [Reason, erlang:get_stacktrace()])
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
@ -221,11 +187,11 @@ handle_cast(_Msg, State) ->
|
|||||||
%% {stop, Reason, State}
|
%% {stop, Reason, State}
|
||||||
%% Description: Handling all non call/cast messages
|
%% 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,
|
#state{host = Host,
|
||||||
module = Module,
|
module = Module,
|
||||||
function = Function} = State) ->
|
function = Function} = State) ->
|
||||||
process_iq(Host, Module, Function, From, To, IQ),
|
process_iq(Host, Module, Function, From, To, IQ_Rec),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_info(_Info, State) ->
|
handle_info(_Info, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
@ -250,17 +216,3 @@ code_change(_OldVsn, State, _Extra) ->
|
|||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%%% Internal functions
|
%%% 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.
|
|
||||||
|
Loading…
Reference in New Issue
Block a user