diff options
author | Badlop <badlop@process-one.net> | 2011-02-21 13:44:30 +0100 |
---|---|---|
committer | Badlop <badlop@process-one.net> | 2011-02-21 13:44:39 +0100 |
commit | 1c899143822feeeb95097774b81a5e8cb31829da (patch) | |
tree | ff82bc9272d6cc9a69f2d3cd0afb990abf6de1ba /src | |
parent | New DIST_USE_INTERFACE to restrict IP where erlang connections are listened (... (diff) |
New route_iq/5 accepting Timeout (thanks to Edwin Fine)(EJAB-1398)
Also new register_iq_response_handler/5
Diffstat (limited to 'src')
-rw-r--r-- | src/ejabberd_local.erl | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/ejabberd_local.erl b/src/ejabberd_local.erl index 0cfc97b3..1ff0f48b 100644 --- a/src/ejabberd_local.erl +++ b/src/ejabberd_local.erl @@ -34,10 +34,12 @@ -export([route/3, route_iq/4, + route_iq/5, process_iq_reply/3, register_iq_handler/4, register_iq_handler/5, register_iq_response_handler/4, + register_iq_response_handler/5, unregister_iq_handler/2, unregister_iq_response_handler/2, refresh_iq_handlers/0, @@ -123,19 +125,31 @@ route(From, To, Packet) -> ok end. -route_iq(From, To, #iq{type = Type} = IQ, F) when is_function(F) -> +route_iq(From, To, IQ, F) -> + route_iq(From, To, IQ, F, undefined). + +route_iq(From, To, #iq{type = Type} = IQ, F, Timeout) when is_function(F) -> Packet = if Type == set; Type == get -> ID = randoms:get_string(), Host = From#jid.lserver, - register_iq_response_handler(Host, ID, undefined, F), + register_iq_response_handler(Host, ID, undefined, F, Timeout), jlib:iq_to_xml(IQ#iq{id = ID}); true -> jlib:iq_to_xml(IQ) end, ejabberd_router:route(From, To, Packet). -register_iq_response_handler(_Host, ID, Module, Function) -> - TRef = erlang:start_timer(?IQ_TIMEOUT, ejabberd_local, ID), +register_iq_response_handler(Host, ID, Module, Function) -> + register_iq_response_handler(Host, ID, Module, Function, undefined). + +register_iq_response_handler(_Host, ID, Module, Function, Timeout0) -> + Timeout = case Timeout0 of + undefined -> + ?IQ_TIMEOUT; + N when is_integer(N), N > 0 -> + N + end, + TRef = erlang:start_timer(Timeout, ejabberd_local, ID), mnesia:dirty_write(#iq_response{id = ID, module = Module, function = Function, |