2002-11-30 19:46:16 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : ejabberd_local.erl
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2004-11-05 22:14:31 +01:00
|
|
|
%%% Purpose : Route local packets
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Created : 30 Nov 2002 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2010-01-12 17:15:16 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2010 ProcessOne
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
2009-01-19 15:47:33 +01:00
|
|
|
%%%
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% You should have received a copy of the GNU General Public License
|
|
|
|
%%% along with this program; if not, write to the Free Software
|
|
|
|
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
%%% 02111-1307 USA
|
|
|
|
%%%
|
2002-11-30 19:46:16 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(ejabberd_local).
|
2007-12-24 12:41:41 +01:00
|
|
|
-author('alexey@process-one.net').
|
2002-11-30 19:46:16 +01:00
|
|
|
|
2006-01-29 05:38:31 +01:00
|
|
|
-behaviour(gen_server).
|
|
|
|
|
|
|
|
%% API
|
|
|
|
-export([start_link/0]).
|
2002-11-30 19:46:16 +01:00
|
|
|
|
2004-11-05 22:14:31 +01:00
|
|
|
-export([route/3,
|
2009-08-03 21:33:42 +02:00
|
|
|
route_iq/4,
|
|
|
|
process_iq_reply/3,
|
2003-01-29 18:12:23 +01:00
|
|
|
register_iq_handler/4,
|
2005-06-20 05:18:13 +02:00
|
|
|
register_iq_handler/5,
|
2007-12-01 06:16:30 +01:00
|
|
|
register_iq_response_handler/4,
|
2005-06-20 05:18:13 +02:00
|
|
|
unregister_iq_handler/2,
|
2008-07-11 14:48:27 +02:00
|
|
|
unregister_iq_response_handler/2,
|
2004-08-13 00:34:19 +02:00
|
|
|
refresh_iq_handlers/0,
|
|
|
|
bounce_resource_packet/3
|
2003-01-29 18:12:23 +01:00
|
|
|
]).
|
2002-11-30 19:46:16 +01:00
|
|
|
|
2006-01-29 05:38:31 +01:00
|
|
|
%% gen_server callbacks
|
|
|
|
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
|
|
|
terminate/2, code_change/3]).
|
|
|
|
|
2008-07-01 15:34:51 +02:00
|
|
|
-include_lib("exmpp/include/exmpp.hrl").
|
|
|
|
|
2002-11-30 19:46:16 +01:00
|
|
|
-include("ejabberd.hrl").
|
|
|
|
|
2006-01-29 05:38:31 +01:00
|
|
|
-record(state, {}).
|
|
|
|
|
2009-08-03 21:33:42 +02:00
|
|
|
-record(iq_response, {id, module, function, timer}).
|
2007-12-01 06:16:30 +01:00
|
|
|
|
2004-11-05 22:14:31 +01:00
|
|
|
-define(IQTABLE, local_iqtable).
|
2002-11-30 19:46:16 +01:00
|
|
|
|
2009-08-03 21:33:42 +02:00
|
|
|
%% This value is used in SIP and Megaco for a transaction lifetime.
|
|
|
|
-define(IQ_TIMEOUT, 32000).
|
|
|
|
|
2008-07-01 15:34:51 +02:00
|
|
|
% These are the namespace already declared by the stream opening. This is
|
|
|
|
% used at serialization time.
|
|
|
|
-define(DEFAULT_NS, ?NS_JABBER_CLIENT).
|
2010-10-07 17:38:18 +02:00
|
|
|
-define(PREFIXED_NS,
|
|
|
|
[{?NS_XMPP, ?NS_XMPP_pfx}, {?NS_DIALBACK, ?NS_DIALBACK_pfx}]).
|
2008-07-01 15:34:51 +02:00
|
|
|
|
2006-01-29 05:38:31 +01:00
|
|
|
%%====================================================================
|
|
|
|
%% API
|
|
|
|
%%====================================================================
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
%% Function: start_link() -> {ok,Pid} | ignore | {error,Error}
|
|
|
|
%% Description: Starts the server
|
|
|
|
%%--------------------------------------------------------------------
|
2003-02-01 21:21:28 +01:00
|
|
|
start_link() ->
|
2006-01-29 05:38:31 +01:00
|
|
|
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
2002-12-11 21:57:45 +01:00
|
|
|
|
2004-11-05 22:14:31 +01:00
|
|
|
process_iq(From, To, Packet) ->
|
2008-08-14 15:34:30 +02:00
|
|
|
case exmpp_iq:xmlel_to_iq(Packet) of
|
|
|
|
#iq{kind = request, ns = XMLNS} = IQ_Rec ->
|
2009-06-01 18:37:15 +02:00
|
|
|
Host = exmpp_jid:prep_domain(To),
|
2010-07-22 18:41:53 +02:00
|
|
|
case ets:lookup(?IQTABLE, {XMLNS, ejabberd:normalize_host(Host)}) of
|
2003-12-17 21:13:21 +01:00
|
|
|
[{_, Module, Function}] ->
|
2008-08-14 15:34:30 +02:00
|
|
|
ResIQ = Module:Function(From, To, IQ_Rec),
|
2003-12-17 21:13:21 +01:00
|
|
|
if
|
|
|
|
ResIQ /= ignore ->
|
2008-08-14 15:34:30 +02:00
|
|
|
Reply = exmpp_iq:iq_to_xmlel(ResIQ, To, From),
|
|
|
|
ejabberd_router:route(To, From, Reply);
|
2003-12-17 21:13:21 +01:00
|
|
|
true ->
|
|
|
|
ok
|
2002-12-11 21:57:45 +01:00
|
|
|
end;
|
2003-12-17 21:13:21 +01:00
|
|
|
[{_, Module, Function, Opts}] ->
|
2005-06-20 05:18:13 +02:00
|
|
|
gen_iq_handler:handle(Host, Module, Function, Opts,
|
2008-08-14 15:34:30 +02:00
|
|
|
From, To, IQ_Rec);
|
2003-12-17 21:13:21 +01:00
|
|
|
[] ->
|
2010-07-22 18:41:53 +02:00
|
|
|
case ets:lookup(?IQTABLE, {XMLNS, global}) of
|
|
|
|
[{_, Module, Function, Opts}] ->
|
|
|
|
gen_iq_handler:handle(
|
|
|
|
global, Module, Function, Opts,
|
|
|
|
From, To, IQ_Rec);
|
|
|
|
[] ->
|
|
|
|
Err = exmpp_iq:error(Packet, 'feature-not-implemented'),
|
|
|
|
ejabberd_router:route(To, From, Err)
|
|
|
|
end
|
2002-12-11 21:57:45 +01:00
|
|
|
end;
|
2009-08-03 21:33:42 +02:00
|
|
|
#iq{kind = response} = IQReply ->
|
|
|
|
%%IQReply = jlib:iq_query_or_response_info(IQ_Rec),
|
|
|
|
process_iq_reply(From, To, IQReply);
|
2002-12-11 21:57:45 +01:00
|
|
|
_ ->
|
2008-08-14 15:34:30 +02:00
|
|
|
Err = exmpp_iq:error(Packet, 'bad-request'),
|
2003-10-19 18:19:55 +02:00
|
|
|
ejabberd_router:route(To, From, Err),
|
2002-12-11 21:57:45 +01:00
|
|
|
ok
|
|
|
|
end.
|
2002-11-30 19:46:16 +01:00
|
|
|
|
2009-08-03 21:33:42 +02:00
|
|
|
process_iq_reply(From, To, #iq{id = ID} = IQ) ->
|
|
|
|
case get_iq_callback(ID) of
|
|
|
|
{ok, undefined, Function} ->
|
|
|
|
Function(IQ),
|
|
|
|
ok;
|
|
|
|
{ok, Module, Function} ->
|
|
|
|
Module:Function(From, To, IQ),
|
2007-12-01 06:16:30 +01:00
|
|
|
ok;
|
|
|
|
_ ->
|
2009-08-03 21:33:42 +02:00
|
|
|
nothing
|
2007-12-01 06:16:30 +01:00
|
|
|
end.
|
2009-08-03 21:33:42 +02:00
|
|
|
|
2010-01-27 19:53:56 +01:00
|
|
|
%% #xmlelement{} used for retro-compatibility
|
2008-07-01 17:51:34 +02:00
|
|
|
route(FromOld, ToOld, #xmlelement{} = PacketOld) ->
|
|
|
|
catch throw(for_stacktrace), % To have a stacktrace.
|
|
|
|
io:format("~nLOCAL: old #xmlelement:~n~p~n~p~n~n",
|
|
|
|
[PacketOld, erlang:get_stacktrace()]),
|
2008-07-01 15:34:51 +02:00
|
|
|
% XXX OLD FORMAT: From, To, Packet.
|
|
|
|
From = jlib:from_old_jid(FromOld),
|
|
|
|
To = jlib:from_old_jid(ToOld),
|
2008-07-01 17:51:34 +02:00
|
|
|
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld, [?NS_JABBER_CLIENT],
|
|
|
|
[{?NS_XMPP, ?NS_XMPP_pfx}]),
|
|
|
|
route(From, To, Packet);
|
|
|
|
route(From, To, Packet) ->
|
2004-11-05 22:14:31 +01:00
|
|
|
case catch do_route(From, To, Packet) of
|
|
|
|
{'EXIT', Reason} ->
|
|
|
|
?ERROR_MSG("~p~nwhen processing: ~p",
|
|
|
|
[Reason, {From, To, Packet}]);
|
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end.
|
|
|
|
|
2009-08-03 21:33:42 +02:00
|
|
|
route_iq(From, To, #iq{type = Type} = IQ, F) when is_function(F) ->
|
|
|
|
Packet = if Type == set; Type == get ->
|
2010-06-02 16:01:36 +02:00
|
|
|
ID = list_to_binary(ejabberd_router:make_id()),
|
2009-08-03 21:33:42 +02:00
|
|
|
Host = exmpp_jid:prep_domain(From),
|
|
|
|
register_iq_response_handler(Host, ID, undefined, F),
|
|
|
|
exmpp_iq:iq_to_xmlel(IQ#iq{id = ID});
|
|
|
|
true ->
|
|
|
|
exmpp_iq:iq_to_xmlel(IQ)
|
|
|
|
end,
|
|
|
|
ejabberd_router:route(From, To, Packet).
|
|
|
|
|
2009-08-13 12:02:04 +02:00
|
|
|
register_iq_response_handler(_Host, ID, Module, Function) ->
|
|
|
|
TRef = erlang:start_timer(?IQ_TIMEOUT, ejabberd_local, ID),
|
2010-06-02 16:01:36 +02:00
|
|
|
ets:insert(iq_response, #iq_response{id = ID,
|
|
|
|
module = Module,
|
|
|
|
function = Function,
|
|
|
|
timer = TRef}).
|
2007-12-01 06:16:30 +01:00
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
register_iq_handler(Host, XMLNS, Module, Fun) ->
|
|
|
|
ejabberd_local ! {register_iq_handler, Host, XMLNS, Module, Fun}.
|
2003-01-22 21:40:40 +01:00
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
register_iq_handler(Host, XMLNS, Module, Fun, Opts) ->
|
|
|
|
ejabberd_local ! {register_iq_handler, Host, XMLNS, Module, Fun, Opts}.
|
2003-01-29 18:12:23 +01:00
|
|
|
|
2009-08-03 21:33:42 +02:00
|
|
|
unregister_iq_response_handler(_Host, ID) ->
|
|
|
|
catch get_iq_callback(ID),
|
|
|
|
ok.
|
2008-07-11 14:48:27 +02:00
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
unregister_iq_handler(Host, XMLNS) ->
|
|
|
|
ejabberd_local ! {unregister_iq_handler, Host, XMLNS}.
|
2003-01-29 18:12:23 +01:00
|
|
|
|
2004-07-10 00:34:26 +02:00
|
|
|
refresh_iq_handlers() ->
|
|
|
|
ejabberd_local ! refresh_iq_handlers.
|
2003-10-19 18:19:55 +02:00
|
|
|
|
2004-08-13 00:34:19 +02:00
|
|
|
bounce_resource_packet(From, To, Packet) ->
|
2008-10-07 11:54:53 +02:00
|
|
|
Err = exmpp_stanza:reply_with_error(Packet, 'item-not-found'),
|
2004-08-13 00:34:19 +02:00
|
|
|
ejabberd_router:route(To, From, Err),
|
|
|
|
stop.
|
2006-01-29 05:38:31 +01:00
|
|
|
|
|
|
|
%%====================================================================
|
|
|
|
%% gen_server callbacks
|
|
|
|
%%====================================================================
|
|
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
%% Function: init(Args) -> {ok, State} |
|
|
|
|
%% {ok, State, Timeout} |
|
|
|
|
%% ignore |
|
|
|
|
%% {stop, Reason}
|
|
|
|
%% Description: Initiates the server
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
init([]) ->
|
|
|
|
lists:foreach(
|
|
|
|
fun(Host) ->
|
2010-07-22 18:41:53 +02:00
|
|
|
ejabberd_router:register_route(Host, {apply, ?MODULE, route})
|
2006-01-29 05:38:31 +01:00
|
|
|
end, ?MYHOSTS),
|
2010-07-22 18:41:53 +02:00
|
|
|
ejabberd_hooks:add(local_send_to_resource_hook, global,
|
|
|
|
?MODULE, bounce_resource_packet, 100),
|
2006-01-29 05:38:31 +01:00
|
|
|
catch ets:new(?IQTABLE, [named_table, public]),
|
2010-06-02 16:01:36 +02:00
|
|
|
mnesia:delete_table(iq_response),
|
|
|
|
catch ets:new(iq_response, [named_table, public,
|
|
|
|
{keypos, #iq_response.id}]),
|
2006-01-29 05:38:31 +01:00
|
|
|
{ok, #state{}}.
|
|
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
%% Function: %% handle_call(Request, From, State) -> {reply, Reply, State} |
|
|
|
|
%% {reply, Reply, State, Timeout} |
|
|
|
|
%% {noreply, State} |
|
|
|
|
%% {noreply, State, Timeout} |
|
|
|
|
%% {stop, Reason, Reply, State} |
|
|
|
|
%% {stop, Reason, State}
|
|
|
|
%% Description: Handling call messages
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
handle_call(_Request, _From, State) ->
|
|
|
|
Reply = ok,
|
|
|
|
{reply, Reply, State}.
|
|
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
%% Function: handle_cast(Msg, State) -> {noreply, State} |
|
|
|
|
%% {noreply, State, Timeout} |
|
|
|
|
%% {stop, Reason, State}
|
|
|
|
%% Description: Handling cast messages
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
handle_cast(_Msg, State) ->
|
|
|
|
{noreply, State}.
|
|
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
%% Function: handle_info(Info, State) -> {noreply, State} |
|
|
|
|
%% {noreply, State, Timeout} |
|
|
|
|
%% {stop, Reason, State}
|
|
|
|
%% Description: Handling all non call/cast messages
|
|
|
|
%%--------------------------------------------------------------------
|
2010-01-27 19:53:56 +01:00
|
|
|
|
|
|
|
%% #xmlelement{} used for retro-compatibility
|
2008-07-01 17:51:34 +02:00
|
|
|
handle_info({route, FromOld, ToOld, #xmlelement{} = PacketOld}, State) ->
|
|
|
|
catch throw(for_stacktrace), % To have a stacktrace.
|
|
|
|
io:format("~nLOCAL: old #xmlelement:~n~p~n~p~n~n",
|
|
|
|
[PacketOld, erlang:get_stacktrace()]),
|
2008-07-01 15:34:51 +02:00
|
|
|
% XXX OLD FORMAT: From, To, Packet.
|
|
|
|
From = jlib:from_old_jid(FromOld),
|
|
|
|
To = jlib:from_old_jid(ToOld),
|
2008-07-01 17:51:34 +02:00
|
|
|
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld, [?NS_JABBER_CLIENT],
|
|
|
|
[{?NS_XMPP, ?NS_XMPP_pfx}]),
|
|
|
|
handle_info({route, From, To, Packet}, State);
|
|
|
|
handle_info({route, From, To, Packet}, State) ->
|
2006-01-29 05:38:31 +01:00
|
|
|
case catch do_route(From, To, Packet) of
|
|
|
|
{'EXIT', Reason} ->
|
|
|
|
?ERROR_MSG("~p~nwhen processing: ~p",
|
|
|
|
[Reason, {From, To, Packet}]);
|
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end,
|
|
|
|
{noreply, State};
|
|
|
|
handle_info({register_iq_handler, Host, XMLNS, Module, Function}, State) ->
|
2010-07-22 18:41:53 +02:00
|
|
|
ets:insert(?IQTABLE, {{XMLNS, ejabberd:normalize_host(Host)}, Module, Function}),
|
2006-01-29 05:38:31 +01:00
|
|
|
catch mod_disco:register_feature(Host, XMLNS),
|
|
|
|
{noreply, State};
|
|
|
|
handle_info({register_iq_handler, Host, XMLNS, Module, Function, Opts}, State) ->
|
2010-07-22 18:41:53 +02:00
|
|
|
ets:insert(?IQTABLE, {{XMLNS, ejabberd:normalize_host(Host)}, Module, Function, Opts}),
|
2006-01-29 05:38:31 +01:00
|
|
|
catch mod_disco:register_feature(Host, XMLNS),
|
|
|
|
{noreply, State};
|
|
|
|
handle_info({unregister_iq_handler, Host, XMLNS}, State) ->
|
2010-07-22 18:41:53 +02:00
|
|
|
case ets:lookup(?IQTABLE, {XMLNS, ejabberd:normalize_host(Host)}) of
|
2006-01-29 05:38:31 +01:00
|
|
|
[{_, Module, Function, Opts}] ->
|
|
|
|
gen_iq_handler:stop_iq_handler(Module, Function, Opts);
|
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end,
|
2010-07-22 18:41:53 +02:00
|
|
|
ets:delete(?IQTABLE, {XMLNS, ejabberd:normalize_host(Host)}),
|
2006-01-29 05:38:31 +01:00
|
|
|
catch mod_disco:unregister_feature(Host, XMLNS),
|
|
|
|
{noreply, State};
|
|
|
|
handle_info(refresh_iq_handlers, State) ->
|
|
|
|
lists:foreach(
|
|
|
|
fun(T) ->
|
|
|
|
case T of
|
|
|
|
{{XMLNS, Host}, _Module, _Function, _Opts} ->
|
|
|
|
catch mod_disco:register_feature(Host, XMLNS);
|
|
|
|
{{XMLNS, Host}, _Module, _Function} ->
|
|
|
|
catch mod_disco:register_feature(Host, XMLNS);
|
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end
|
|
|
|
end, ets:tab2list(?IQTABLE)),
|
|
|
|
{noreply, State};
|
2009-08-03 21:33:42 +02:00
|
|
|
handle_info({timeout, _TRef, ID}, State) ->
|
2010-06-02 16:01:36 +02:00
|
|
|
spawn(fun() -> process_iq_timeout(ID) end),
|
2009-08-03 21:33:42 +02:00
|
|
|
{noreply, State};
|
2006-01-29 05:38:31 +01:00
|
|
|
handle_info(_Info, State) ->
|
|
|
|
{noreply, State}.
|
|
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
%% Function: terminate(Reason, State) -> void()
|
|
|
|
%% Description: This function is called by a gen_server when it is about to
|
|
|
|
%% terminate. It should be the opposite of Module:init/1 and do any necessary
|
|
|
|
%% cleaning up. When it returns, the gen_server terminates with Reason.
|
|
|
|
%% The return value is ignored.
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
terminate(_Reason, _State) ->
|
|
|
|
ok.
|
|
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
%% Func: code_change(OldVsn, State, Extra) -> {ok, NewState}
|
|
|
|
%% Description: Convert process state when code is changed
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
code_change(_OldVsn, State, _Extra) ->
|
|
|
|
{ok, State}.
|
|
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
%%% Internal functions
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
do_route(From, To, Packet) ->
|
|
|
|
?DEBUG("local route~n\tfrom ~p~n\tto ~p~n\tpacket ~P~n",
|
|
|
|
[From, To, Packet, 8]),
|
2009-01-03 16:15:38 +01:00
|
|
|
|
2009-06-01 18:39:36 +02:00
|
|
|
LNode = exmpp_jid:prep_node(To),
|
2009-06-01 18:42:07 +02:00
|
|
|
LResource = exmpp_jid:prep_resource(To),
|
2006-01-29 05:38:31 +01:00
|
|
|
if
|
2009-01-03 16:15:38 +01:00
|
|
|
LNode /= undefined ->
|
2006-01-29 05:38:31 +01:00
|
|
|
ejabberd_sm:route(From, To, Packet);
|
2009-01-03 16:15:38 +01:00
|
|
|
LResource == undefined ->
|
2008-07-01 15:34:51 +02:00
|
|
|
case Packet of
|
|
|
|
_ when ?IS_IQ(Packet) ->
|
2006-01-29 05:38:31 +01:00
|
|
|
process_iq(From, To, Packet);
|
2008-07-01 15:34:51 +02:00
|
|
|
_ when ?IS_MESSAGE(Packet) ->
|
2006-01-29 05:38:31 +01:00
|
|
|
ok;
|
2008-07-01 15:34:51 +02:00
|
|
|
_ when ?IS_PRESENCE(Packet) ->
|
2006-01-29 05:38:31 +01:00
|
|
|
ok;
|
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end;
|
|
|
|
true ->
|
2008-07-01 15:34:51 +02:00
|
|
|
case exmpp_stanza:get_type(Packet) of
|
2009-01-09 20:18:46 +01:00
|
|
|
<<"error">> -> ok;
|
|
|
|
<<"result">> -> ok;
|
2006-01-29 05:38:31 +01:00
|
|
|
_ ->
|
|
|
|
ejabberd_hooks:run(local_send_to_resource_hook,
|
2009-06-01 18:37:15 +02:00
|
|
|
exmpp_jid:prep_domain(To),
|
2008-08-26 15:38:49 +02:00
|
|
|
[From, To, Packet])
|
2006-01-29 05:38:31 +01:00
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
2009-08-03 21:33:42 +02:00
|
|
|
get_iq_callback(ID) ->
|
2010-06-02 16:01:36 +02:00
|
|
|
case ets:lookup(iq_response, ID) of
|
2009-08-03 21:33:42 +02:00
|
|
|
[#iq_response{module = Module, timer = TRef,
|
|
|
|
function = Function}] ->
|
|
|
|
cancel_timer(TRef),
|
2010-06-02 16:01:36 +02:00
|
|
|
ets:delete(iq_response, ID),
|
2009-08-03 21:33:42 +02:00
|
|
|
{ok, Module, Function};
|
|
|
|
_ ->
|
|
|
|
error
|
|
|
|
end.
|
|
|
|
|
|
|
|
process_iq_timeout(ID) ->
|
2010-06-02 16:01:36 +02:00
|
|
|
case get_iq_callback(ID) of
|
|
|
|
{ok, undefined, Function} ->
|
|
|
|
Function(timeout);
|
|
|
|
_ ->
|
2009-08-03 21:33:42 +02:00
|
|
|
ok
|
|
|
|
end.
|
|
|
|
|
|
|
|
cancel_timer(TRef) ->
|
|
|
|
case erlang:cancel_timer(TRef) of
|
|
|
|
false ->
|
|
|
|
receive
|
|
|
|
{timeout, TRef, _} ->
|
|
|
|
ok
|
|
|
|
after 0 ->
|
|
|
|
ok
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end.
|