diff options
author | Evgeny Khramtsov <ekhramtsov@process-one.net> | 2019-04-25 14:30:42 +0300 |
---|---|---|
committer | Evgeny Khramtsov <ekhramtsov@process-one.net> | 2019-04-25 14:30:42 +0300 |
commit | a0c8c70c9cbe7b8cb35d799c8504157bb75e7486 (patch) | |
tree | 76ec599f8a7d7486a8204aec0137a07ce1078e56 | |
parent | Merge pull request #2868 from rstgroup/fix-rfc-6455-violation (diff) |
Use binary framing in MQTT WebSockets
-rw-r--r-- | src/ejabberd_http_ws.erl | 12 | ||||
-rw-r--r-- | src/ejabberd_websocket.erl | 6 | ||||
-rw-r--r-- | src/mod_mqtt_ws.erl | 2 |
3 files changed, 12 insertions, 8 deletions
diff --git a/src/ejabberd_http_ws.erl b/src/ejabberd_http_ws.erl index dbde28caa..26e68fdaa 100644 --- a/src/ejabberd_http_ws.erl +++ b/src/ejabberd_http_ws.erl @@ -201,15 +201,15 @@ handle_sync_event({send_xml, Packet}, _From, StateName, case Packet2 of {xmlstreamstart, Name, Attrs3} -> B = fxml:element_to_binary(#xmlel{name = Name, attrs = Attrs3}), - WsPid ! {send, <<(binary:part(B, 0, byte_size(B)-2))/binary, ">">>}; + WsPid ! {text, <<(binary:part(B, 0, byte_size(B)-2))/binary, ">">>}; {xmlstreamend, Name} -> - WsPid ! {send, <<"</", Name/binary, ">">>}; + WsPid ! {text, <<"</", Name/binary, ">">>}; {xmlstreamelement, El} -> - WsPid ! {send, fxml:element_to_binary(El)}; + WsPid ! {text, fxml:element_to_binary(El)}; {xmlstreamraw, Bin} -> - WsPid ! {send, Bin}; + WsPid ! {text, Bin}; {xmlstreamcdata, Bin2} -> - WsPid ! {send, Bin2}; + WsPid ! {text, Bin2}; skip -> ok end, @@ -224,7 +224,7 @@ handle_sync_event(close, _From, StateName, #state{ws = {_, WsPid}, rfc_compilant when StateName /= stream_end_sent -> Close = #xmlel{name = <<"close">>, attrs = [{<<"xmlns">>, <<"urn:ietf:params:xml:ns:xmpp-framing">>}]}, - WsPid ! {send, fxml:element_to_binary(Close)}, + WsPid ! {text, fxml:element_to_binary(Close)}, {stop, normal, StateData}; handle_sync_event(close, _From, _StateName, StateData) -> {stop, normal, StateData}. diff --git a/src/ejabberd_websocket.erl b/src/ejabberd_websocket.erl index edc602f55..2b5a01460 100644 --- a/src/ejabberd_websocket.erl +++ b/src/ejabberd_websocket.erl @@ -202,10 +202,14 @@ ws_loop(FrameInfo, Socket, WsHandleLoopPid, SocketMode) -> end, erlang:demonitor(Ref), websocket_close(Socket, WsHandleLoopPid, SocketMode, Code); - {send, Data} -> + {text, Data} -> SocketMode:send(Socket, encode_frame(Data, 1)), ws_loop(FrameInfo, Socket, WsHandleLoopPid, SocketMode); + {data, Data} -> + SocketMode:send(Socket, encode_frame(Data, 2)), + ws_loop(FrameInfo, Socket, WsHandleLoopPid, + SocketMode); {ping, Data} -> SocketMode:send(Socket, encode_frame(Data, 9)), ws_loop(FrameInfo, Socket, WsHandleLoopPid, diff --git a/src/mod_mqtt_ws.erl b/src/mod_mqtt_ws.erl index 872553445..820b09d62 100644 --- a/src/mod_mqtt_ws.erl +++ b/src/mod_mqtt_ws.erl @@ -98,7 +98,7 @@ init([{#ws{ip = IP, http_opts = ListenOpts}, WsPid}]) -> end. handle_call({send, Data}, _From, #state{ws_pid = WsPid} = State) -> - WsPid ! {send, Data}, + WsPid ! {data, Data}, {reply, ok, State}; handle_call(Request, From, State) -> ?WARNING_MSG("Got unexpected call from ~p: ~p", [From, Request]), |