mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
Avoid crashing of ejabberd_iq process on invalid callback
This commit is contained in:
parent
d4d352492c
commit
e8eb6bc2b4
@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
-include("xmpp.hrl").
|
-include("xmpp.hrl").
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
|
-include("ejabberd_stacktrace.hrl").
|
||||||
|
|
||||||
-record(state, {expire = infinity :: timeout()}).
|
-record(state, {expire = infinity :: timeout()}).
|
||||||
-type state() :: #state{}.
|
-type state() :: #state{}.
|
||||||
@ -74,7 +75,8 @@ init([]) ->
|
|||||||
{ok, #state{}}.
|
{ok, #state{}}.
|
||||||
|
|
||||||
handle_call(Request, From, State) ->
|
handle_call(Request, From, State) ->
|
||||||
{stop, {unexpected_call, Request, From}, State}.
|
?WARNING_MSG("Unexpected call from ~p: ~p", [From, Request]),
|
||||||
|
noreply(State).
|
||||||
|
|
||||||
handle_cast({restart_timer, Expire}, State) ->
|
handle_cast({restart_timer, Expire}, State) ->
|
||||||
State1 = State#state{expire = min(Expire, State#state.expire)},
|
State1 = State#state{expire = min(Expire, State#state.expire)},
|
||||||
@ -171,7 +173,13 @@ calc_checksum(Data) ->
|
|||||||
|
|
||||||
-spec callback(atom() | pid(), #iq{} | timeout, term()) -> any().
|
-spec callback(atom() | pid(), #iq{} | timeout, term()) -> any().
|
||||||
callback(undefined, IQRes, Fun) ->
|
callback(undefined, IQRes, Fun) ->
|
||||||
Fun(IQRes);
|
try Fun(IQRes)
|
||||||
|
catch ?EX_RULE(Class, Reason, St) ->
|
||||||
|
StackTrace = ?EX_STACK(St),
|
||||||
|
?ERROR_MSG("Failed to process iq response:~n~s~n** ~s",
|
||||||
|
[xmpp:pp(IQRes),
|
||||||
|
misc:format_exception(2, Class, Reason, StackTrace)])
|
||||||
|
end;
|
||||||
callback(Proc, IQRes, Ctx) ->
|
callback(Proc, IQRes, Ctx) ->
|
||||||
try
|
try
|
||||||
Proc ! {iq_reply, IQRes, Ctx}
|
Proc ! {iq_reply, IQRes, Ctx}
|
||||||
|
Loading…
Reference in New Issue
Block a user