25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

New XEP-0198 option: "max_resume_timeout"

In the past, the "resume_timeout" option defined both the default resume
timeout and the maximum resume timeout clients are permitted to request.
Admins might want to allow clients to request a timeout value that's
larger than the default, though.  This can now be done by specifying the
"max_resume_timeout" option.
This commit is contained in:
Holger Weiss 2015-09-03 21:20:15 +02:00
parent 8d1ea87e02
commit 5095fdb6b0

View File

@ -110,6 +110,7 @@
mgmt_max_queue,
mgmt_pending_since,
mgmt_timeout,
mgmt_max_timeout,
mgmt_resend,
mgmt_stanzas_in = 0,
mgmt_stanzas_out = 0,
@ -314,6 +315,10 @@ init([{SockMod, Socket}, Opts]) ->
Timeout when is_integer(Timeout), Timeout >= 0 -> Timeout;
_ -> 300
end,
MaxResumeTimeout = case proplists:get_value(max_resume_timeout, Opts) of
Max when is_integer(Max), Max >= ResumeTimeout -> Max;
_ -> ResumeTimeout
end,
ResendOnTimeout = case proplists:get_value(resend_on_timeout, Opts) of
Resend when is_boolean(Resend) -> Resend;
if_offline -> if_offline;
@ -336,6 +341,7 @@ init([{SockMod, Socket}, Opts]) ->
mgmt_state = StreamMgmtState,
mgmt_max_queue = MaxAckQueue,
mgmt_timeout = ResumeTimeout,
mgmt_max_timeout = MaxResumeTimeout,
mgmt_resend = ResendOnTimeout},
{ok, wait_for_stream, StateData, ?C2S_OPEN_TIMEOUT}.
@ -2688,16 +2694,17 @@ perform_stream_mgmt(#xmlel{name = Name, attrs = Attrs}, StateData) ->
StateData
end.
handle_enable(#state{mgmt_timeout = ConfigTimeout} = StateData, Attrs) ->
handle_enable(#state{mgmt_timeout = DefaultTimeout,
mgmt_max_timeout = MaxTimeout} = StateData, Attrs) ->
Timeout = case xml:get_attr_s(<<"resume">>, Attrs) of
ResumeAttr when ResumeAttr == <<"true">>;
ResumeAttr == <<"1">> ->
MaxAttr = xml:get_attr_s(<<"max">>, Attrs),
case catch jlib:binary_to_integer(MaxAttr) of
Max when is_integer(Max), Max > 0, Max =< ConfigTimeout ->
Max when is_integer(Max), Max > 0, Max =< MaxTimeout ->
Max;
_ ->
ConfigTimeout
DefaultTimeout
end;
_ ->
0