25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

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()}], headers = [] :: [{atom() | binary(), binary()}],
local_path = [] :: [binary()], local_path = [] :: [binary()],
q = [] :: [{binary() | nokey, binary()}], q = [] :: [{binary() | nokey, binary()}],
buf :: binary()}). buf :: binary(),
http_opts = [] :: list()}).

View File

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

View File

@ -111,8 +111,14 @@ socket_handoff(LocalPath, Request, Socket, SockMod, Buf, Opts) ->
%%% Internal %%% Internal
init([{#ws{ip = IP}, _} = WS]) -> init([{#ws{ip = IP, http_opts = HOpts}, _} = WS]) ->
Opts = [{xml_socket, true} | ejabberd_c2s_config:get_c2s_limits()], 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( PingInterval = ejabberd_config:get_option(
{websocket_ping_interval, ?MYNAME}, {websocket_ping_interval, ?MYNAME},
fun(I) when is_integer(I), I>=0 -> I end, fun(I) when is_integer(I), I>=0 -> I end,

View File

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

View File

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