mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-20 17:27:00 +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:
parent
795498fa45
commit
5f47860ee1
@ -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,53 +308,19 @@ 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
|
El = fxml_stream:parse_element(Data),
|
||||||
undefined ->
|
case El of
|
||||||
P = fxml_stream:new(self()),
|
#xmlel{name = <<"open">>, attrs = Attrs} ->
|
||||||
P2 = fxml_stream:parse(P, Data),
|
Attrs2 = [{<<"xmlns:stream">>, ?NS_STREAM}, {<<"xmlns">>, <<"jabber:client">>} |
|
||||||
fxml_stream:close(P2),
|
lists:keydelete(<<"xmlns">>, 1, lists:keydelete(<<"xmlns:stream">>, 1, Attrs))],
|
||||||
case parsed_items([]) of
|
{State, [{xmlstreamstart, <<"stream:stream">>, Attrs2}]};
|
||||||
error ->
|
#xmlel{name = <<"close">>} ->
|
||||||
{State#state{rfc_compliant = true}, <<"parse error">>};
|
{State, [{xmlstreamend, <<"stream:stream">>}]};
|
||||||
[] ->
|
{error, _} ->
|
||||||
{State#state{rfc_compliant = true}, <<"parse error">>};
|
{State, [{xmlstreamerror, {4, <<"not well-formed">>}}]};
|
||||||
[{xmlstreamstart, <<"open">>, _} | _] ->
|
_ ->
|
||||||
parse(State#state{rfc_compliant = true}, Data);
|
{State, [El]}
|
||||||
_ ->
|
|
||||||
parse(State#state{rfc_compliant = false}, Data)
|
|
||||||
end;
|
|
||||||
true ->
|
|
||||||
El = fxml_stream:parse_element(Data),
|
|
||||||
case El of
|
|
||||||
#xmlel{name = <<"open">>, attrs = Attrs} ->
|
|
||||||
Attrs2 = [{<<"xmlns:stream">>, ?NS_STREAM}, {<<"xmlns">>, <<"jabber:client">>} |
|
|
||||||
lists:keydelete(<<"xmlns">>, 1, lists:keydelete(<<"xmlns:stream">>, 1, Attrs))],
|
|
||||||
{State, [{xmlstreamstart, <<"stream:stream">>, Attrs2}]};
|
|
||||||
#xmlel{name = <<"close">>} ->
|
|
||||||
{State, [{xmlstreamend, <<"stream:stream">>}]};
|
|
||||||
{error, _} ->
|
|
||||||
{State, <<"parse error">>};
|
|
||||||
_ ->
|
|
||||||
{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.
|
||||||
|
Loading…
Reference in New Issue
Block a user