From 5faae61befb9cc85b5d58d14dc5cc270c91ebdd7 Mon Sep 17 00:00:00 2001 From: Evgeny Khramtsov Date: Tue, 23 Apr 2019 16:21:06 +0300 Subject: [PATCH] Move websocket options --- src/ejabberd_http_ws.erl | 12 +----------- src/ejabberd_websocket.erl | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/ejabberd_http_ws.erl b/src/ejabberd_http_ws.erl index 2bb1e7fb4..dbde28caa 100644 --- a/src/ejabberd_http_ws.erl +++ b/src/ejabberd_http_ws.erl @@ -24,7 +24,6 @@ %%%---------------------------------------------------------------------- -module(ejabberd_http_ws). -author('ecestari@process-one.net'). --behaviour(ejabberd_config). -behaviour(xmpp_socket). -behaviour(p1_fsm). @@ -33,7 +32,7 @@ terminate/3, send_xml/2, setopts/2, sockname/1, peername/1, controlling_process/2, get_owner/1, reset_stream/1, close/1, change_shaper/2, - socket_handoff/3, get_transport/1, opt_type/1]). + socket_handoff/3, get_transport/1]). -include("logger.hrl"). @@ -367,12 +366,3 @@ parsed_items(List) -> after 0 -> lists:reverse(List) end. - -opt_type(websocket_ping_interval) -> - fun (I) when is_integer(I), I >= 0 -> I end; -opt_type(websocket_timeout) -> - fun (I) when is_integer(I), I > 0 -> I end; -opt_type(websocket_origin) -> - fun (O) -> O end; -opt_type(_) -> - [websocket_ping_interval, websocket_timeout, websocket_origin]. diff --git a/src/ejabberd_websocket.erl b/src/ejabberd_websocket.erl index 767c3837b..7a05cd0f8 100644 --- a/src/ejabberd_websocket.erl +++ b/src/ejabberd_websocket.erl @@ -37,12 +37,12 @@ %%%---------------------------------------------------------------------- -module(ejabberd_websocket). - +-behaviour(ejabberd_config). -protocol({rfc, 6455}). -author('ecestari@process-one.net'). --export([check/2, socket_handoff/5]). +-export([check/2, socket_handoff/5, opt_type/1]). -include("logger.hrl"). @@ -409,4 +409,22 @@ websocket_close(Socket, WsHandleLoopPid, SocketMode, _CloseCode) -> SocketMode:close(Socket). get_origin() -> - ejabberd_config:get_option({websocket_origin, ejabberd_config:get_myname()}, ignore). \ No newline at end of file + ejabberd_config:get_option(websocket_origin, ignore). + +opt_type(websocket_ping_interval) -> + fun (I) when is_integer(I), I >= 0 -> I end; +opt_type(websocket_timeout) -> + fun (I) when is_integer(I), I > 0 -> I end; +opt_type(websocket_origin) -> + %% Accept only values conforming to RFC6454 section 7.1 + fun (<<"null">>) -> <<"null">>; + (null) -> <<"null">>; + (Origin) -> + URIs = [_|_] = lists:flatmap( + fun(<<>>) -> []; + (URI) -> [misc:try_url(URI)] + end, re:split(Origin, "\\s")), + str:join(URIs, <<" ">>) + end; +opt_type(_) -> + [websocket_ping_interval, websocket_timeout, websocket_origin]. -- 2.40.0