mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
Better solution for a previous fix
This commit is contained in:
parent
51aa9d98a7
commit
e5ba7c3f3c
@ -190,15 +190,7 @@ c2s_handle_recv(#{lang := Lang} = State, El, {error, Why}) ->
|
|||||||
<<"result">> -> State;
|
<<"result">> -> State;
|
||||||
<<"error">> -> State;
|
<<"error">> -> State;
|
||||||
_ ->
|
_ ->
|
||||||
Txt = xmpp:io_format_error(Why),
|
State#{mgmt_is_resent => false}
|
||||||
Lang1 = select_lang(Lang, xmpp:get_lang(El)),
|
|
||||||
Err = xmpp:err_bad_request(Txt, Lang1),
|
|
||||||
case mgmt_queue_add(State, Err) of
|
|
||||||
#{mgmt_max_queue := exceeded} = State1 ->
|
|
||||||
send_policy_violation(State1);
|
|
||||||
State1 ->
|
|
||||||
State1
|
|
||||||
end
|
|
||||||
end;
|
end;
|
||||||
true ->
|
true ->
|
||||||
State
|
State
|
||||||
@ -206,24 +198,27 @@ c2s_handle_recv(#{lang := Lang} = State, El, {error, Why}) ->
|
|||||||
c2s_handle_recv(State, _, _) ->
|
c2s_handle_recv(State, _, _) ->
|
||||||
State.
|
State.
|
||||||
|
|
||||||
c2s_handle_send(#{mgmt_state := MgmtState, mod := Mod} = State,
|
c2s_handle_send(#{mgmt_state := MgmtState, mod := Mod,
|
||||||
Pkt, SendResult)
|
lang := Lang} = State, Pkt, SendResult)
|
||||||
when MgmtState == pending; MgmtState == active ->
|
when MgmtState == pending; MgmtState == active ->
|
||||||
|
IsStanza = xmpp:is_stanza(Pkt),
|
||||||
case Pkt of
|
case Pkt of
|
||||||
_ when ?is_stanza(Pkt) ->
|
_ when IsStanza ->
|
||||||
Meta = xmpp:get_meta(Pkt),
|
case need_to_queue(State, Pkt) of
|
||||||
case maps:get(mgmt_is_resent, Meta, false) of
|
{true, State1} ->
|
||||||
false ->
|
case mgmt_queue_add(State1, Pkt) of
|
||||||
case mgmt_queue_add(State, Pkt) of
|
#{mgmt_max_queue := exceeded} = State2 ->
|
||||||
#{mgmt_max_queue := exceeded} = State1 ->
|
State3 = State2#{mgmt_resend => false},
|
||||||
send_policy_violation(State1);
|
Err = xmpp:serr_policy_violation(
|
||||||
State1 when SendResult == ok ->
|
<<"Too many unacked stanzas">>, Lang),
|
||||||
send_rack(State1);
|
send(State3, Err);
|
||||||
State1 ->
|
State2 when SendResult == ok ->
|
||||||
State1
|
send_rack(State2);
|
||||||
|
State2 ->
|
||||||
|
State2
|
||||||
end;
|
end;
|
||||||
true ->
|
{false, State1} ->
|
||||||
State
|
State1
|
||||||
end;
|
end;
|
||||||
#stream_error{} ->
|
#stream_error{} ->
|
||||||
case MgmtState of
|
case MgmtState of
|
||||||
@ -730,15 +725,13 @@ bounce_message_queue() ->
|
|||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec send_policy_violation(state()) -> state().
|
-spec need_to_queue(state(), xmlel() | stanza()) -> {boolean(), state()}.
|
||||||
send_policy_violation(#{lang := Lang} = State) ->
|
need_to_queue(State, Pkt) when ?is_stanza(Pkt) ->
|
||||||
State1 = State#{mgmt_resend => false},
|
{not xmpp:get_meta(Pkt, mgmt_is_resent, false), State};
|
||||||
Err = xmpp:serr_policy_violation(<<"Too many unacked stanzas">>, Lang),
|
need_to_queue(#{mgmt_is_resent := false} = State, #xmlel{}) ->
|
||||||
send(State1, Err).
|
{true, maps:remove(mgmt_is_resent, State)};
|
||||||
|
need_to_queue(State, _) ->
|
||||||
-spec select_lang(binary(), binary()) -> binary().
|
{false, State}.
|
||||||
select_lang(Lang, <<"">>) -> Lang;
|
|
||||||
select_lang(_, Lang) -> Lang.
|
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Configuration processing
|
%%% Configuration processing
|
||||||
|
Loading…
Reference in New Issue
Block a user