5
5
%%% Created : 30 Nov 2002 by Alexey Shchepin <alexey@process-one.net>
8
%%% ejabberd, Copyright (C) 2002-2010 ProcessOne
8
%%% ejabberd, Copyright (C) 2002-2011 ProcessOne
10
10
%%% This program is free software; you can redistribute it and/or
11
11
%%% modify it under the terms of the GNU General Public License as
126
route_iq(From, To, #iq{type = Type} = IQ, F) when is_function(F) ->
128
route_iq(From, To, IQ, F) ->
129
route_iq(From, To, IQ, F, undefined).
131
route_iq(From, To, #iq{type = Type} = IQ, F, Timeout) when is_function(F) ->
127
132
Packet = if Type == set; Type == get ->
128
133
ID = randoms:get_string(),
129
134
Host = From#jid.lserver,
130
register_iq_response_handler(Host, ID, undefined, F),
135
register_iq_response_handler(Host, ID, undefined, F, Timeout),
131
136
jlib:iq_to_xml(IQ#iq{id = ID});
133
138
jlib:iq_to_xml(IQ)
135
140
ejabberd_router:route(From, To, Packet).
137
register_iq_response_handler(_Host, ID, Module, Function) ->
138
TRef = erlang:start_timer(?IQ_TIMEOUT, ejabberd_local, ID),
142
register_iq_response_handler(Host, ID, Module, Function) ->
143
register_iq_response_handler(Host, ID, Module, Function, undefined).
145
register_iq_response_handler(_Host, ID, Module, Function, Timeout0) ->
146
Timeout = case Timeout0 of
149
N when is_integer(N), N > 0 ->
152
TRef = erlang:start_timer(Timeout, ejabberd_local, ID),
139
153
mnesia:dirty_write(#iq_response{id = ID,
141
155
function = Function,