aboutsummaryrefslogtreecommitdiff
path: root/src/ejabberd_websocket.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/ejabberd_websocket.erl')
-rw-r--r--src/ejabberd_websocket.erl40
1 files changed, 8 insertions, 32 deletions
diff --git a/src/ejabberd_websocket.erl b/src/ejabberd_websocket.erl
index 2dde8add2..82443eec5 100644
--- a/src/ejabberd_websocket.erl
+++ b/src/ejabberd_websocket.erl
@@ -37,12 +37,11 @@
%%%----------------------------------------------------------------------
-module(ejabberd_websocket).
--behaviour(ejabberd_config).
-protocol({rfc, 6455}).
-author('ecestari@process-one.net').
--export([socket_handoff/5, opt_type/1]).
+-export([socket_handoff/5]).
-include("logger.hrl").
@@ -193,7 +192,7 @@ ws_loop(FrameInfo, Socket, WsHandleLoopPid, SocketMode) ->
{DataType, _Socket, Data} when DataType =:= tcp orelse DataType =:= raw ->
case handle_data(DataType, FrameInfo, Data, Socket, WsHandleLoopPid, SocketMode) of
{error, Error} ->
- ?DEBUG("tls decode error ~p", [Error]),
+ ?DEBUG("TLS decode error ~p", [Error]),
websocket_close(Socket, WsHandleLoopPid, SocketMode, 1002); % protocol error
{NewFrameInfo, ToSend} ->
lists:foreach(fun(Pkt) -> SocketMode:send(Socket, Pkt)
@@ -201,17 +200,17 @@ ws_loop(FrameInfo, Socket, WsHandleLoopPid, SocketMode) ->
ws_loop(NewFrameInfo, Socket, WsHandleLoopPid, SocketMode)
end;
{tcp_closed, _Socket} ->
- ?DEBUG("tcp connection was closed, exit", []),
+ ?DEBUG("TCP connection was closed, exit", []),
websocket_close(Socket, WsHandleLoopPid, SocketMode, 0);
{tcp_error, Socket, Reason} ->
- ?DEBUG("tcp connection error: ~s", [inet:format_error(Reason)]),
+ ?DEBUG("TCP connection error: ~s", [inet:format_error(Reason)]),
websocket_close(Socket, WsHandleLoopPid, SocketMode, 0);
{'DOWN', Ref, process, WsHandleLoopPid, Reason} ->
Code = case Reason of
normal ->
1000; % normal close
_ ->
- ?ERROR_MSG("linked websocket controlling loop crashed "
+ ?ERROR_MSG("Linked websocket controlling loop crashed "
"with reason: ~p",
[Reason]),
1011 % internal error
@@ -231,12 +230,12 @@ ws_loop(FrameInfo, Socket, WsHandleLoopPid, SocketMode) ->
ws_loop(FrameInfo, Socket, WsHandleLoopPid,
SocketMode);
shutdown ->
- ?DEBUG("shutdown request received, closing websocket "
+ ?DEBUG("Shutdown request received, closing websocket "
"with pid ~p",
[self()]),
websocket_close(Socket, WsHandleLoopPid, SocketMode, 1001); % going away
_Ignored ->
- ?WARNING_MSG("received unexpected message, ignoring: ~p",
+ ?WARNING_MSG("Received unexpected message, ignoring: ~p",
[_Ignored]),
ws_loop(FrameInfo, Socket, WsHandleLoopPid,
SocketMode)
@@ -429,27 +428,4 @@ websocket_close(Socket, WsHandleLoopPid, SocketMode, _CloseCode) ->
SocketMode:close(Socket).
get_origin() ->
- ejabberd_config:get_option(websocket_origin, []).
-
-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 Verify(V) when is_binary(V) ->
- Verify([V]);
- Verify([]) ->
- [];
- Verify([<<"null">> | R]) ->
- [<<"null">> | Verify(R)];
- Verify([null | R]) ->
- [<<"null">> | Verify(R)];
- Verify([V | R]) when is_binary(V) ->
- URIs = [_|_] = lists:filtermap(
- fun(<<>>) -> false;
- (URI) -> {true, misc:try_url(URI)}
- end, re:split(V, "\\s+")),
- [str:join(URIs, <<" ">>) | Verify(R)]
- end;
-opt_type(_) ->
- [websocket_ping_interval, websocket_timeout, websocket_origin].
+ ejabberd_option:websocket_origin().