Pass stream management options defined in http listener to http-bind and websocket
authorPaweł Chmielowski <pchmielowski@process-one.net>
Fri, 4 Sep 2015 10:42:53 +0000 (12:42 +0200)
committerPaweł Chmielowski <pchmielowski@process-one.net>
Fri, 4 Sep 2015 10:42:53 +0000 (12:42 +0200)
include/ejabberd_http.hrl
src/ejabberd_http_bind.erl
src/ejabberd_http_ws.erl
src/ejabberd_websocket.erl
src/mod_http_bind.erl

index 50c9d4ad727b91df1483d2fd1c8e8298dabae251..404427d7f225b16e07f11f0f0c56bbca2fecbdde 100644 (file)
@@ -45,4 +45,5 @@
         headers = []            :: [{atom() | binary(), binary()}],
         local_path = []         :: [binary()],
         q = []                  :: [{binary() | nokey, binary()}],
-        buf                     :: binary()}).
+        buf                     :: binary(),
+         http_opts = []          :: list()}).
index 620c8f1d37eab4bd46460b3b0081db6c769252bd..21c6887f00de8a3b782463b13e07702bf053a601 100644 (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,
         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").
 %%%----------------------------------------------------------------------
 %% 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},
index 902c32f256bf3ce0a2f7def5cb82ba75f59cff40..dd6854f8c32a9d5ffda530d24c90d2b4cf4a5a9d 100644 (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,
index c45d157bbfb2893b66a51732cee7d49eaffc5ec1..d922787b5ef2935272b6b40114de2501689b1c78 100644 (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);
         _ ->
index c3a62aa3c5967ff438df6ea7139bd892e959b8c9..fbf43e80fe89002ef86a3b54fd5aad2cd620bed0 100644 (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 = <<>>}) ->