mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
Merge pull request #222 from weiss/keep-session-on-failed-resume
XEP-0198: Don't drop session on failed resume
This commit is contained in:
commit
4d1332c30f
@ -1311,8 +1311,8 @@ handle_sync_event(get_subscribed, _From, StateName,
|
|||||||
StateData) ->
|
StateData) ->
|
||||||
Subscribed = (?SETS):to_list(StateData#state.pres_f),
|
Subscribed = (?SETS):to_list(StateData#state.pres_f),
|
||||||
{reply, Subscribed, StateName, StateData};
|
{reply, Subscribed, StateName, StateData};
|
||||||
handle_sync_event(resume_session, _From, _StateName,
|
handle_sync_event({resume_session, Time}, _From, _StateName,
|
||||||
StateData) ->
|
StateData) when element(1, StateData#state.sid) == Time ->
|
||||||
%% The old session should be closed before the new one is opened, so we do
|
%% The old session should be closed before the new one is opened, so we do
|
||||||
%% this here instead of leaving it to the terminate callback
|
%% this here instead of leaving it to the terminate callback
|
||||||
ejabberd_sm:close_session(StateData#state.sid,
|
ejabberd_sm:close_session(StateData#state.sid,
|
||||||
@ -1320,6 +1320,9 @@ handle_sync_event(resume_session, _From, _StateName,
|
|||||||
StateData#state.server,
|
StateData#state.server,
|
||||||
StateData#state.resource),
|
StateData#state.resource),
|
||||||
{stop, normal, {ok, StateData}, StateData#state{mgmt_state = resumed}};
|
{stop, normal, {ok, StateData}, StateData#state{mgmt_state = resumed}};
|
||||||
|
handle_sync_event({resume_session, _Time}, _From, StateName,
|
||||||
|
StateData) ->
|
||||||
|
{reply, {error, <<"Previous session not found">>}, StateName, StateData};
|
||||||
handle_sync_event(_Event, _From, StateName,
|
handle_sync_event(_Event, _From, StateName,
|
||||||
StateData) ->
|
StateData) ->
|
||||||
Reply = ok, fsm_reply(Reply, StateName, StateData).
|
Reply = ok, fsm_reply(Reply, StateName, StateData).
|
||||||
@ -2891,8 +2894,8 @@ inherit_session_state(#state{user = U, server = S} = StateData, ResumeID) ->
|
|||||||
{error, <<"Previous session PID not found">>};
|
{error, <<"Previous session PID not found">>};
|
||||||
OldPID ->
|
OldPID ->
|
||||||
OldSID = {Time, OldPID},
|
OldSID = {Time, OldPID},
|
||||||
case catch resume_session(OldPID) of
|
case catch resume_session(OldSID) of
|
||||||
{ok, #state{sid = OldSID} = OldStateData} ->
|
{ok, OldStateData} ->
|
||||||
NewSID = {Time, self()}, % Old time, new PID
|
NewSID = {Time, self()}, % Old time, new PID
|
||||||
Priority = case OldStateData#state.pres_last of
|
Priority = case OldStateData#state.pres_last of
|
||||||
undefined ->
|
undefined ->
|
||||||
@ -2924,6 +2927,8 @@ inherit_session_state(#state{user = U, server = S} = StateData, ResumeID) ->
|
|||||||
mgmt_stanzas_in = OldStateData#state.mgmt_stanzas_in,
|
mgmt_stanzas_in = OldStateData#state.mgmt_stanzas_in,
|
||||||
mgmt_stanzas_out = OldStateData#state.mgmt_stanzas_out,
|
mgmt_stanzas_out = OldStateData#state.mgmt_stanzas_out,
|
||||||
mgmt_state = active}};
|
mgmt_state = active}};
|
||||||
|
{error, Msg} ->
|
||||||
|
{error, Msg};
|
||||||
_ ->
|
_ ->
|
||||||
{error, <<"Cannot grab session state">>}
|
{error, <<"Cannot grab session state">>}
|
||||||
end
|
end
|
||||||
@ -2932,8 +2937,8 @@ inherit_session_state(#state{user = U, server = S} = StateData, ResumeID) ->
|
|||||||
{error, <<"Invalid 'previd' value">>}
|
{error, <<"Invalid 'previd' value">>}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
resume_session(FsmRef) ->
|
resume_session({Time, PID}) ->
|
||||||
(?GEN_FSM):sync_send_all_state_event(FsmRef, resume_session, 3000).
|
(?GEN_FSM):sync_send_all_state_event(PID, {resume_session, Time}, 3000).
|
||||||
|
|
||||||
make_resume_id(StateData) ->
|
make_resume_id(StateData) ->
|
||||||
{Time, _} = StateData#state.sid,
|
{Time, _} = StateData#state.sid,
|
||||||
|
Loading…
Reference in New Issue
Block a user