From f56a9e400dd1857484c9898f0b746f0a44ad2ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Chmielowski?= Date: Fri, 4 Sep 2015 12:42:53 +0200 Subject: [PATCH] Pass stream management options defined in http listener to http-bind and websocket --- include/ejabberd_http.hrl | 3 ++- src/ejabberd_http_bind.erl | 29 ++++++++++++++++++----------- src/ejabberd_http_ws.erl | 10 ++++++++-- src/ejabberd_websocket.erl | 6 ++++-- src/mod_http_bind.erl | 4 ++-- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/include/ejabberd_http.hrl b/include/ejabberd_http.hrl index 50c9d4ad7..404427d7f 100644 --- a/include/ejabberd_http.hrl +++ b/include/ejabberd_http.hrl @@ -45,4 +45,5 @@ headers = [] :: [{atom() | binary(), binary()}], local_path = [] :: [binary()], q = [] :: [{binary() | nokey, binary()}], - buf :: binary()}). + buf :: binary(), + http_opts = [] :: list()}). diff --git a/src/ejabberd_http_bind.erl b/src/ejabberd_http_bind.erl index 620c8f1d3..21c6887f0 100644 --- a/src/ejabberd_http_bind.erl +++ b/src/ejabberd_http_bind.erl @@ -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, <<" 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); _ -> diff --git a/src/mod_http_bind.erl b/src/mod_http_bind.erl index c3a62aa3c..fbf43e80f 100644 --- a/src/mod_http_bind.erl +++ b/src/mod_http_bind.erl @@ -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 = <<>>}) ->