mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-26 16:26:24 +01:00
Convert to exmpp.
SVN Revision: 1402
This commit is contained in:
parent
094fa47f9f
commit
d6e6432a46
@ -31,6 +31,8 @@
|
|||||||
* src/ejabberd_sm.erl, src/ejabberd_c2s.erl: Don't convert <iq/>
|
* src/ejabberd_sm.erl, src/ejabberd_c2s.erl: Don't convert <iq/>
|
||||||
before calling gen_iq_handler:handle/7.
|
before calling gen_iq_handler:handle/7.
|
||||||
|
|
||||||
|
* src/ejabberd_local.erl: Convert to exmpp.
|
||||||
|
|
||||||
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
|
||||||
|
@ -45,8 +45,9 @@
|
|||||||
-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").
|
||||||
-include("jlib.hrl").
|
|
||||||
|
|
||||||
-record(state, {}).
|
-record(state, {}).
|
||||||
|
|
||||||
@ -54,6 +55,13 @@
|
|||||||
|
|
||||||
-define(IQTABLE, local_iqtable).
|
-define(IQTABLE, local_iqtable).
|
||||||
|
|
||||||
|
% These are the namespace already declared by the stream opening. This is
|
||||||
|
% used at serialization time.
|
||||||
|
-define(DEFAULT_NS, ?NS_JABBER_CLIENT).
|
||||||
|
-define(PREFIXED_NS, [
|
||||||
|
{?NS_XMPP, ?NS_XMPP_pfx}, {?NS_DIALBACK, ?NS_DIALBACK_pfx}
|
||||||
|
]).
|
||||||
|
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
%% API
|
%% API
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
@ -65,39 +73,51 @@ 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) ->
|
||||||
IQ = jlib:iq_query_info(Packet),
|
case exmpp_iq:get_kind(Packet) of
|
||||||
case IQ of
|
request ->
|
||||||
#iq{xmlns = XMLNS} ->
|
Host = To#jid.ldomain,
|
||||||
Host = To#jid.lserver,
|
Request = exmpp_iq:get_request(Packet),
|
||||||
|
XMLNS = case Request#xmlel.ns of
|
||||||
|
NS when is_atom(NS) -> atom_to_list(NS);
|
||||||
|
NS -> NS
|
||||||
|
end,
|
||||||
case ets:lookup(?IQTABLE, {XMLNS, Host}) of
|
case ets:lookup(?IQTABLE, {XMLNS, Host}) of
|
||||||
[{_, Module, Function}] ->
|
[{_, Module, Function}] ->
|
||||||
ResIQ = Module:Function(From, To, IQ),
|
% XXX OLD FORMAT: From, To, Packet.
|
||||||
|
FromOld = jlib:to_old_jid(From),
|
||||||
|
ToOld = jlib:to_old_jid(To),
|
||||||
|
PacketOld = exmpp_xml:xmlel_to_xmlelement(Packet,
|
||||||
|
[?DEFAULT_NS], ?PREFIXED_NS),
|
||||||
|
IQ_Rec = jlib:iq_query_info(PacketOld),
|
||||||
|
ResIQ = Module:Function(FromOld, ToOld, IQ_Rec),
|
||||||
if
|
if
|
||||||
ResIQ /= ignore ->
|
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(
|
ejabberd_router:route(
|
||||||
To, From, jlib:iq_to_xml(ResIQ));
|
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, IQ);
|
From, To, Packet);
|
||||||
[] ->
|
[] ->
|
||||||
Err = jlib:make_error_reply(
|
Err = exmpp_iq:error(Packet, 'feature-not-implemented'),
|
||||||
Packet, ?ERR_FEATURE_NOT_IMPLEMENTED),
|
|
||||||
ejabberd_router:route(To, From, Err)
|
ejabberd_router:route(To, From, Err)
|
||||||
end;
|
end;
|
||||||
reply ->
|
response ->
|
||||||
process_iq_reply(From, To, Packet);
|
process_iq_reply(From, To, Packet);
|
||||||
_ ->
|
_ ->
|
||||||
Err = jlib:make_error_reply(Packet, ?ERR_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, Packet) ->
|
||||||
IQ = jlib:iq_query_or_response_info(Packet),
|
ID = exmpp_stanza:get_id(Packet),
|
||||||
#iq{id = ID} = IQ,
|
|
||||||
case catch mnesia:dirty_read(iq_response, ID) of
|
case catch mnesia:dirty_read(iq_response, ID) of
|
||||||
[] ->
|
[] ->
|
||||||
ok;
|
ok;
|
||||||
@ -114,13 +134,24 @@ 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, IQ);
|
% XXX OLD FORMAT: From, To, Packet.
|
||||||
|
FromOld = jlib:to_old_jid(From),
|
||||||
|
ToOld = jlib:to_old_jid(To),
|
||||||
|
PacketOld = exmpp_xml:xmlel_to_xmlelement(Packet,
|
||||||
|
[?DEFAULT_NS], ?PREFIXED_NS),
|
||||||
|
IQ_Rec = jlib:iq_query_or_response_info(PacketOld),
|
||||||
|
Module:Function(FromOld, ToOld, IQ_Rec);
|
||||||
_ ->
|
_ ->
|
||||||
ok
|
ok
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
route(From, To, Packet) ->
|
route(FromOld, ToOld, PacketOld) ->
|
||||||
|
% XXX OLD FORMAT: From, To, Packet.
|
||||||
|
From = jlib:from_old_jid(FromOld),
|
||||||
|
To = jlib:from_old_jid(ToOld),
|
||||||
|
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld,
|
||||||
|
[?DEFAULT_NS], ?PREFIXED_NS),
|
||||||
case catch do_route(From, To, Packet) of
|
case catch do_route(From, To, Packet) of
|
||||||
{'EXIT', Reason} ->
|
{'EXIT', Reason} ->
|
||||||
?ERROR_MSG("~p~nwhen processing: ~p",
|
?ERROR_MSG("~p~nwhen processing: ~p",
|
||||||
@ -145,7 +176,7 @@ refresh_iq_handlers() ->
|
|||||||
ejabberd_local ! refresh_iq_handlers.
|
ejabberd_local ! refresh_iq_handlers.
|
||||||
|
|
||||||
bounce_resource_packet(From, To, Packet) ->
|
bounce_resource_packet(From, To, Packet) ->
|
||||||
Err = jlib:make_error_reply(Packet, ?ERR_ITEM_NOT_FOUND),
|
Err = exmpp_stanza:error(Packet, 'item-not-found'),
|
||||||
ejabberd_router:route(To, From, Err),
|
ejabberd_router:route(To, From, Err),
|
||||||
stop.
|
stop.
|
||||||
|
|
||||||
@ -202,7 +233,12 @@ 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({route, From, To, Packet}, State) ->
|
handle_info({route, FromOld, ToOld, PacketOld}, State) ->
|
||||||
|
% XXX OLD FORMAT: From, To, Packet.
|
||||||
|
From = jlib:from_old_jid(FromOld),
|
||||||
|
To = jlib:from_old_jid(ToOld),
|
||||||
|
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld,
|
||||||
|
[?DEFAULT_NS], ?PREFIXED_NS),
|
||||||
case catch do_route(From, To, Packet) of
|
case catch do_route(From, To, Packet) of
|
||||||
{'EXIT', Reason} ->
|
{'EXIT', Reason} ->
|
||||||
?ERROR_MSG("~p~nwhen processing: ~p",
|
?ERROR_MSG("~p~nwhen processing: ~p",
|
||||||
@ -272,29 +308,32 @@ do_route(From, To, Packet) ->
|
|||||||
?DEBUG("local route~n\tfrom ~p~n\tto ~p~n\tpacket ~P~n",
|
?DEBUG("local route~n\tfrom ~p~n\tto ~p~n\tpacket ~P~n",
|
||||||
[From, To, Packet, 8]),
|
[From, To, Packet, 8]),
|
||||||
if
|
if
|
||||||
To#jid.luser /= "" ->
|
To#jid.lnode /= undefined ->
|
||||||
ejabberd_sm:route(From, To, Packet);
|
ejabberd_sm:route(From, To, Packet);
|
||||||
To#jid.lresource == "" ->
|
To#jid.lresource == undefined ->
|
||||||
{xmlelement, Name, _Attrs, _Els} = Packet,
|
case Packet of
|
||||||
case Name of
|
_ when ?IS_IQ(Packet) ->
|
||||||
"iq" ->
|
|
||||||
process_iq(From, To, Packet);
|
process_iq(From, To, Packet);
|
||||||
"message" ->
|
_ when ?IS_MESSAGE(Packet) ->
|
||||||
ok;
|
ok;
|
||||||
"presence" ->
|
_ when ?IS_PRESENCE(Packet) ->
|
||||||
ok;
|
ok;
|
||||||
_ ->
|
_ ->
|
||||||
ok
|
ok
|
||||||
end;
|
end;
|
||||||
true ->
|
true ->
|
||||||
{xmlelement, _Name, Attrs, _Els} = Packet,
|
case exmpp_stanza:get_type(Packet) of
|
||||||
case xml:get_attr_s("type", Attrs) of
|
|
||||||
"error" -> ok;
|
"error" -> ok;
|
||||||
"result" -> ok;
|
"result" -> ok;
|
||||||
_ ->
|
_ ->
|
||||||
|
% XXX OLD FORMAT: From, To, Packet.
|
||||||
|
FromOld = jlib:to_old_jid(From),
|
||||||
|
ToOld = jlib:to_old_jid(To),
|
||||||
|
PacketOld = exmpp_xml:xmlel_to_xmlelement(Packet,
|
||||||
|
[?DEFAULT_NS], ?PREFIXED_NS),
|
||||||
ejabberd_hooks:run(local_send_to_resource_hook,
|
ejabberd_hooks:run(local_send_to_resource_hook,
|
||||||
To#jid.lserver,
|
To#jid.ldomain,
|
||||||
[From, To, Packet])
|
[FromOld, ToOld, PacketOld])
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user