Skip to content

Commit 499ae96

Browse files
committed
Don't use 'unsupported-version' inside SM <failed/> element
This error condition is defined within stream errors, however, XEP-0198 says: > This element SHOULD contain an error condition, which MUST > be one of the **stanza** error conditions defined in RFC 6120.
1 parent ac31c85 commit 499ae96

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/mod_stream_mgmt.erl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,15 @@ c2s_stream_features(Acc, Host) ->
142142
Acc
143143
end.
144144

145-
c2s_unauthenticated_packet(State, Pkt) when ?is_sm_packet(Pkt) ->
145+
c2s_unauthenticated_packet(#{lang := Lang} = State, Pkt) when ?is_sm_packet(Pkt) ->
146146
%% XEP-0198 says: "For client-to-server connections, the client MUST NOT
147147
%% attempt to enable stream management until after it has completed Resource
148148
%% Binding unless it is resuming a previous session". However, it also
149149
%% says: "Stream management errors SHOULD be considered recoverable", so we
150150
%% won't bail out.
151-
Err = #sm_failed{reason = 'unexpected-request', xmlns = ?NS_STREAM_MGMT_3},
151+
Err = #sm_failed{reason = 'not-authorized',
152+
text = xmpp:mk_text(<<"Unauthorized">>, Lang),
153+
xmlns = ?NS_STREAM_MGMT_3},
152154
{stop, send(State, Err)};
153155
c2s_unauthenticated_packet(State, _Pkt) ->
154156
State.
@@ -351,7 +353,7 @@ negotiate_stream_mgmt(Pkt, State) ->
351353
end.
352354

353355
-spec perform_stream_mgmt(xmpp_element(), state()) -> state().
354-
perform_stream_mgmt(Pkt, #{mgmt_xmlns := Xmlns} = State) ->
356+
perform_stream_mgmt(Pkt, #{mgmt_xmlns := Xmlns, lang := Lang} = State) ->
355357
case xmpp:get_ns(Pkt) of
356358
Xmlns ->
357359
case Pkt of
@@ -368,7 +370,10 @@ perform_stream_mgmt(Pkt, #{mgmt_xmlns := Xmlns} = State) ->
368370
xmlns = Xmlns})
369371
end;
370372
_ ->
371-
send(State, #sm_failed{reason = 'unsupported-version', xmlns = Xmlns})
373+
Txt = <<"Unsupported version">>,
374+
send(State, #sm_failed{reason = 'unexpected-request',
375+
text = xmpp:mk_text(Txt, Lang),
376+
xmlns = Xmlns})
372377
end.
373378

374379
-spec handle_enable(state(), sm_enable()) -> state().

0 commit comments

Comments
 (0)