Pass stream management options defined in http listener to http-bind and websocket

This commit is contained in:
Paweł Chmielowski 2015-09-04 12:42:53 +02:00
parent 5095fdb6b0
commit f56a9e400d
5 changed files with 34 additions and 18 deletions

View File

@ -45,4 +45,5 @@
headers = [] :: [{atom() | binary(), binary()}],
local_path = [] :: [binary()],
q = [] :: [{binary() | nokey, binary()}],
buf :: binary()}).
buf :: binary(),
http_opts = [] :: list()}).

View File

@ -16,7 +16,7 @@
-behaviour(gen_fsm).
%% External exports
-export([start_link/3,
-export([start_link/4,
init/1,
handle_event/3,
handle_sync_event/4,
@ -35,13 +35,13 @@
change_shaper/2,
monitor/1,
close/1,
start/4,
start/5,
handle_session_start/8,
handle_http_put/7,
http_put/7,
http_get/2,
prepare_response/4,
process_request/2]).
process_request/3]).
-include("ejabberd.hrl").
-include("logger.hrl").
@ -140,17 +140,17 @@
%%%----------------------------------------------------------------------
%% TODO: If compile with no supervisor option, start the session without
%% supervisor
start(XMPPDomain, Sid, Key, IP) ->
start(XMPPDomain, Sid, Key, IP, HOpts) ->
?DEBUG("Starting session", []),
SupervisorProc = gen_mod:get_module_proc(XMPPDomain, ?PROCNAME_MHB),
case catch supervisor:start_child(SupervisorProc, [Sid, Key, IP]) of
case catch supervisor:start_child(SupervisorProc, [Sid, Key, IP, HOpts]) of
{ok, Pid} -> {ok, Pid};
_ -> check_bind_module(XMPPDomain),
{error, "Cannot start HTTP bind session"}
end.
start_link(Sid, Key, IP) ->
gen_fsm:start_link(?MODULE, [Sid, Key, IP], ?FSMOPTS).
start_link(Sid, Key, IP, HOpts) ->
gen_fsm:start_link(?MODULE, [Sid, Key, IP, HOpts], ?FSMOPTS).
send({http_bind, FsmRef, _IP}, Packet) ->
gen_fsm:sync_send_all_state_event(FsmRef,
@ -197,7 +197,7 @@ peername({http_bind, _FsmRef, IP}) -> {ok, IP}.
%% Entry point for data coming from client through ejabberd HTTP server:
process_request(Data, IP) ->
process_request(Data, IP, HOpts) ->
Opts1 = ejabberd_c2s_config:get_c2s_limits(),
Opts = [{xml_socket, true} | Opts1],
MaxStanzaSize = case lists:keysearch(max_stanza_size, 1,
@ -221,7 +221,7 @@ process_request(Data, IP) ->
(?NS_HTTP_BIND)/binary, "'/>">>};
XmppDomain ->
Sid = p1_sha:sha(term_to_binary({now(), make_ref()})),
case start(XmppDomain, Sid, <<"">>, IP) of
case start(XmppDomain, Sid, <<"">>, IP, HOpts) of
{error, _} ->
{500, ?HEADER,
<<"<body type='terminate' condition='internal-se"
@ -329,10 +329,17 @@ handle_session_start(Pid, XmppDomain, Sid, Rid, Attrs,
%% ignore |
%% {stop, StopReason}
%%----------------------------------------------------------------------
init([Sid, Key, IP]) ->
init([Sid, Key, IP, HOpts]) ->
?DEBUG("started: ~p", [{Sid, Key, IP}]),
Opts1 = ejabberd_c2s_config:get_c2s_limits(),
Opts = [{xml_socket, true} | Opts1],
SOpts = lists:filtermap(fun({stream_managment, _}) -> true;
({max_ack_queue, _}) -> true;
({resume_timeout, _}) -> true;
({resend_on_timeout, _}) -> true;
(_) -> false
end, HOpts),
Opts = [{xml_socket, true} | SOpts ++ Opts1],
Shaper = none,
ShaperState = shaper:new(Shaper),
Socket = {http_bind, self(), IP},

View File

@ -111,8 +111,14 @@ socket_handoff(LocalPath, Request, Socket, SockMod, Buf, Opts) ->
%%% Internal
init([{#ws{ip = IP}, _} = WS]) ->
Opts = [{xml_socket, true} | ejabberd_c2s_config:get_c2s_limits()],
init([{#ws{ip = IP, http_opts = HOpts}, _} = WS]) ->
SOpts = lists:filtermap(fun({stream_managment, _}) -> true;
({max_ack_queue, _}) -> true;
({resume_timeout, _}) -> true;
({resend_on_timeout, _}) -> true;
(_) -> false
end, HOpts),
Opts = [{xml_socket, true} | ejabberd_c2s_config:get_c2s_limits() ++ SOpts],
PingInterval = ejabberd_config:get_option(
{websocket_ping_interval, ?MYNAME},
fun(I) when is_integer(I), I>=0 -> I end,

View File

@ -88,7 +88,8 @@ check(_Path, Headers) ->
end.
socket_handoff(LocalPath, #request{method = 'GET', ip = IP, q = Q, path = Path,
headers = Headers, host = Host, port = Port},
headers = Headers, host = Host, port = Port,
opts = HOpts},
Socket, SockMod, Buf, _Opts, HandlerModule, InfoMsgFun) ->
case check(LocalPath, Headers) of
true ->
@ -101,7 +102,8 @@ socket_handoff(LocalPath, #request{method = 'GET', ip = IP, q = Q, path = Path,
path = Path,
headers = Headers,
local_path = LocalPath,
buf = Buf},
buf = Buf,
http_opts = HOpts},
connect(WS, HandlerModule);
_ ->

View File

@ -64,9 +64,9 @@ process([], #request{method = 'POST', data = <<>>}) ->
{400, ?HEADER,
#xmlel{name = <<"h1">>, children = [{xmlcdata, <<"400 Bad Request">>}]}};
process([],
#request{method = 'POST', data = Data, ip = IP}) ->
#request{method = 'POST', data = Data, ip = IP, opts = Opts}) ->
?DEBUG("Incoming data: ~s", [Data]),
ejabberd_http_bind:process_request(Data, IP);
ejabberd_http_bind:process_request(Data, IP, Opts);
process([], #request{method = 'GET', data = <<>>}) ->
{200, ?HEADER, get_human_html_xmlel()};
process([], #request{method = 'OPTIONS', data = <<>>}) ->