%%%----------------------------------------------------------------------
-module(ejabberd_http_ws).
-author('ecestari@process-one.net').
--behaviour(ejabberd_config).
-behaviour(xmpp_socket).
-behaviour(p1_fsm).
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").
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].
%%%----------------------------------------------------------------------
-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").
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].