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

Move websocket options

This commit is contained in:
Evgeny Khramtsov 2019-04-23 16:21:06 +03:00
parent cc892ddc01
commit 5faae61bef
2 changed files with 22 additions and 14 deletions

View File

@ -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].

View File

@ -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).
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].