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

Remove support for old websocket connection protocol

This removes handling of pre-rfc7395 encapsulation of xmpp in websocket
(where data send in websocket was using just raw data as send in regular
socket). This didn't work correctly for last 5 years, and as we didn't
see complains about this, we can assume it's not used anymore.
This commit is contained in:
Paweł Chmielowski 2024-09-02 11:55:46 +02:00
parent 795498fa45
commit 5f47860ee1

View File

@ -50,8 +50,7 @@
input = [] :: list(), input = [] :: list(),
active = false :: boolean(), active = false :: boolean(),
c2s_pid :: pid(), c2s_pid :: pid(),
ws :: {#ws{}, pid()}, ws :: {#ws{}, pid()}}).
rfc_compliant = undefined :: boolean() | undefined}).
%-define(DBGFSM, true). %-define(DBGFSM, true).
@ -166,18 +165,18 @@ handle_event({new_shaper, Shaper}, StateName, #state{ws = {_, WsPid}} = StateDat
{next_state, StateName, StateData}. {next_state, StateName, StateData}.
handle_sync_event({send_xml, Packet}, _From, StateName, handle_sync_event({send_xml, Packet}, _From, StateName,
#state{ws = {_, WsPid}, rfc_compliant = R} = StateData) -> #state{ws = {_, WsPid}} = StateData) ->
Packet2 = case {case R of undefined -> true; V -> V end, Packet} of Packet2 = case Packet of
{true, {xmlstreamstart, _, Attrs}} -> {xmlstreamstart, _, Attrs} ->
Attrs2 = [{<<"xmlns">>, <<"urn:ietf:params:xml:ns:xmpp-framing">>} | Attrs2 = [{<<"xmlns">>, <<"urn:ietf:params:xml:ns:xmpp-framing">>} |
lists:keydelete(<<"xmlns">>, 1, lists:keydelete(<<"xmlns:stream">>, 1, Attrs))], lists:keydelete(<<"xmlns">>, 1, lists:keydelete(<<"xmlns:stream">>, 1, Attrs))],
{xmlstreamelement, #xmlel{name = <<"open">>, attrs = Attrs2}}; {xmlstreamelement, #xmlel{name = <<"open">>, attrs = Attrs2}};
{true, {xmlstreamend, _}} -> {xmlstreamend, _} ->
{xmlstreamelement, #xmlel{name = <<"close">>, {xmlstreamelement, #xmlel{name = <<"close">>,
attrs = [{<<"xmlns">>, <<"urn:ietf:params:xml:ns:xmpp-framing">>}]}}; attrs = [{<<"xmlns">>, <<"urn:ietf:params:xml:ns:xmpp-framing">>}]}};
{true, {xmlstreamraw, <<"\r\n\r\n">>}} -> % cdata ping {xmlstreamraw, <<"\r\n\r\n">>} -> % cdata ping
skip; skip;
{true, {xmlstreamelement, #xmlel{name=Name2} = El2}} -> {xmlstreamelement, #xmlel{name=Name2} = El2} ->
El3 = case Name2 of El3 = case Name2 of
<<"stream:", _/binary>> -> <<"stream:", _/binary>> ->
fxml:replace_tag_attr(<<"xmlns:stream">>, ?NS_STREAM, El2); fxml:replace_tag_attr(<<"xmlns:stream">>, ?NS_STREAM, El2);
@ -189,9 +188,7 @@ handle_sync_event({send_xml, Packet}, _From, StateName,
El2 El2
end end
end, end,
{xmlstreamelement, El3}; {xmlstreamelement, El3}
_ ->
Packet
end, end,
case Packet2 of case Packet2 of
{xmlstreamstart, Name, Attrs3} -> {xmlstreamstart, Name, Attrs3} ->
@ -215,13 +212,11 @@ handle_sync_event({send_xml, Packet}, _From, StateName,
StateName StateName
end, end,
{reply, ok, SN2, StateData}; {reply, ok, SN2, StateData};
handle_sync_event(close, _From, StateName, #state{ws = {_, WsPid}, rfc_compliant = true} = StateData) handle_sync_event(close, _From, StateName, #state{ws = {_, WsPid}} = StateData)
when StateName /= stream_end_sent -> when StateName /= stream_end_sent ->
Close = #xmlel{name = <<"close">>, Close = #xmlel{name = <<"close">>,
attrs = [{<<"xmlns">>, <<"urn:ietf:params:xml:ns:xmpp-framing">>}]}, attrs = [{<<"xmlns">>, <<"urn:ietf:params:xml:ns:xmpp-framing">>}]},
route_text(WsPid, fxml:element_to_binary(Close)), route_text(WsPid, fxml:element_to_binary(Close)),
{stop, normal, StateData};
handle_sync_event(close, _From, _StateName, StateData) ->
{stop, normal, StateData}. {stop, normal, StateData}.
handle_info(closed, _StateName, StateData) -> handle_info(closed, _StateName, StateData) ->
@ -313,23 +308,7 @@ get_human_html_xmlel() ->
"client that supports it.">>}]}]}]}. "client that supports it.">>}]}]}]}.
parse(#state{rfc_compliant = C} = State, Data) -> parse(State, Data) ->
case C of
undefined ->
P = fxml_stream:new(self()),
P2 = fxml_stream:parse(P, Data),
fxml_stream:close(P2),
case parsed_items([]) of
error ->
{State#state{rfc_compliant = true}, <<"parse error">>};
[] ->
{State#state{rfc_compliant = true}, <<"parse error">>};
[{xmlstreamstart, <<"open">>, _} | _] ->
parse(State#state{rfc_compliant = true}, Data);
_ ->
parse(State#state{rfc_compliant = false}, Data)
end;
true ->
El = fxml_stream:parse_element(Data), El = fxml_stream:parse_element(Data),
case El of case El of
#xmlel{name = <<"open">>, attrs = Attrs} -> #xmlel{name = <<"open">>, attrs = Attrs} ->
@ -339,27 +318,9 @@ parse(#state{rfc_compliant = C} = State, Data) ->
#xmlel{name = <<"close">>} -> #xmlel{name = <<"close">>} ->
{State, [{xmlstreamend, <<"stream:stream">>}]}; {State, [{xmlstreamend, <<"stream:stream">>}]};
{error, _} -> {error, _} ->
{State, <<"parse error">>}; {State, [{xmlstreamerror, {4, <<"not well-formed">>}}]};
_ -> _ ->
{State, [El]} {State, [El]}
end;
false ->
{State, Data}
end.
parsed_items(List) ->
receive
{'$gen_event', El}
when element(1, El) == xmlel;
element(1, El) == xmlstreamstart;
element(1, El) == xmlstreamelement;
element(1, El) == xmlstreamcdata;
element(1, El) == xmlstreamend ->
parsed_items([El | List]);
{'$gen_event', {xmlstreamerror, _}} ->
error
after 0 ->
lists:reverse(List)
end. end.
-spec route_text(pid(), binary()) -> ok. -spec route_text(pid(), binary()) -> ok.