libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

h2_conn_data.h (6304B)


      1 /* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */
      2 /*
      3   This file is part of GNU libmicrohttpd.
      4   Copyright (C) 2025 Evgeny Grin (Karlson2k)
      5 
      6   GNU libmicrohttpd is free software; you can redistribute it and/or
      7   modify it under the terms of the GNU Lesser General Public
      8   License as published by the Free Software Foundation; either
      9   version 2.1 of the License, or (at your option) any later version.
     10 
     11   GNU libmicrohttpd is distributed in the hope that it will be useful,
     12   but WITHOUT ANY WARRANTY; without even the implied warranty of
     13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14   Lesser General Public License for more details.
     15 
     16   Alternatively, you can redistribute GNU libmicrohttpd and/or
     17   modify it under the terms of the GNU General Public License as
     18   published by the Free Software Foundation; either version 2 of
     19   the License, or (at your option) any later version, together
     20   with the eCos exception, as follows:
     21 
     22     As a special exception, if other files instantiate templates or
     23     use macros or inline functions from this file, or you compile this
     24     file and link it with other works to produce a work based on this
     25     file, this file does not by itself cause the resulting work to be
     26     covered by the GNU General Public License. However the source code
     27     for this file must still be made available in accordance with
     28     section (3) of the GNU General Public License v2.
     29 
     30     This exception does not invalidate any other reasons why a work
     31     based on this file might be covered by the GNU General Public
     32     License.
     33 
     34   You should have received copies of the GNU Lesser General Public
     35   License and the GNU General Public License along with this library;
     36   if not, see <https://www.gnu.org/licenses/>.
     37 */
     38 
     39 /**
     40  * @file src/mhd2/h2/h2_conn_data.h
     41  * @brief  Definition of HTTP/2 connection-specific data
     42  * @author Karlson2k (Evgeny Grin)
     43  */
     44 
     45 #ifndef MHD_H2_CONN_DATA_H
     46 #define MHD_H2_CONN_DATA_H 1
     47 
     48 #include "mhd_sys_options.h"
     49 
     50 #include "sys_bool_type.h"
     51 #include "sys_base_types.h"
     52 
     53 #include "mhd_dlinked_list.h"
     54 
     55 #include "hpack/mhd_hpack_dec_types.h"
     56 #include "hpack/mhd_hpack_enc_types.h"
     57 
     58 /**
     59  * The size in bytes of HTTP/2 preface
     60  */
     61 #define mhd_H2_PREFACE_LEN      (24u)
     62 
     63 struct mhd_MemoryPool; /* Forward declaration */
     64 struct mhd_H2ReqItemsBlock; /* Forward declaration */
     65 struct mhd_H2Stream; /* Forward declaration */
     66 
     67 mhd_DLINKEDL_LIST_DEF (mhd_H2Stream);
     68 
     69 struct mhd_H2ConnRecvCtrlData
     70 {
     71   uint_least32_t stream_init_win_sz;
     72 
     73   uint_least32_t conn_full_win_sz;
     74 
     75   uint_least32_t max_frame_size; // TODO: implement update when ACKed by peer
     76 
     77   uint_least32_t max_header_list;
     78 
     79   uint_least32_t max_concur_streams;
     80 };
     81 
     82 struct mhd_H2ConnMemData
     83 {
     84   struct mhd_MemoryPool *send_pool;
     85 
     86   /**
     87    * Request items block (headers, footers, URI arguments, cookies etc.)
     88    */
     89   struct mhd_H2ReqItemsBlock *req_ib;
     90 };
     91 
     92 struct mhd_H2GoawayData
     93 {
     94   bool occurred;
     95 
     96   uint_least32_t code;
     97 };
     98 
     99 struct mhd_H2ConnStateInitData
    100 {
    101   /**
    102    * 'true' if the first peer settings has been received and processed
    103    */
    104   bool got_setns;
    105   /**
    106    * 'true' if the first settings frame has been sent
    107    */
    108   bool sent_setns;
    109 };
    110 
    111 struct mhd_H2ConnStateData
    112 {
    113   struct mhd_H2ConnStateInitData init;
    114   /**
    115    * Number of sent settings not ACKed yet by peer
    116    */
    117   uint_fast64_t sent_setns_noakc;
    118 
    119   int_least32_t send_window;
    120 
    121   int_least32_t recv_window;
    122   /**
    123    * Highest Stream ID of any received stream
    124    */
    125   uint_least32_t top_seen_stream_id;
    126   /**
    127    * Highest Stream ID of the stream for which application callback is called
    128    */
    129   uint_least32_t top_proc_stream_id;
    130   /**
    131    * Highest Stream ID of the stream for which RST_STREAM was sent
    132    */
    133   uint_least32_t top_rst_stream_id;
    134   /**
    135    * If set to non-zero then the next incoming frame must be a CONTINUATION
    136    * frame with specified Stream ID.
    137    */
    138   uint_least32_t continuation_stream_id;
    139 
    140   struct mhd_H2GoawayData sent_goaway;
    141 
    142   struct mhd_H2GoawayData recvd_goaway;
    143 };
    144 
    145 struct mhd_H2ConnPeerData
    146 {
    147   uint_least32_t stream_init_win_sz;
    148 
    149   /**
    150    * Maximum outgoing frame size to use.
    151    * If peer set value smaller than allowed by the settings, then this value
    152    * is in this field. Otherwise, this field indicates maximum size allowed
    153    * by the settings.
    154    */
    155   uint_least32_t max_frame_size;
    156 
    157   uint_least32_t max_header_list;
    158 
    159   uint_least32_t max_concur_streams;
    160 
    161   /**
    162    * Stream ID specified as the last stream in peer GOAWAY message
    163    */
    164   uint_least32_t stream_id_limit; // TODO check value when getting new streams
    165 };
    166 
    167 struct mhd_H2ConnStreams
    168 {
    169   /**
    170    * The list of all not finished streams
    171    */
    172   mhd_DLNKDL_LIST (mhd_H2Stream, active);
    173 
    174   /**
    175    * The sending queue
    176    */
    177   mhd_DLNKDL_LIST (mhd_H2Stream, send_q);
    178 
    179   /**
    180    * The total number streams in the @a active list
    181    */
    182   size_t num_streams;
    183 };
    184 
    185 struct mhd_H2ConnBuffData
    186 {
    187   /**
    188    * The offset in the read buffer of the frame to be processes / being processed
    189    */
    190   size_t r_cur_frame;
    191 
    192   /**
    193    * Position of unprocessed part of HEADERS/CONTINUATION payload.
    194    * Used only when the next frame is CONTINUATION.
    195    */
    196   size_t unproc_hdrs_pos;
    197 
    198   /**
    199    * Size of unprocessed part of HEADERS/CONTINUATION payload.
    200    * Must be non-zero only when the next frame is CONTINUATION.
    201    */
    202   size_t unproc_hdrs_size;
    203 };
    204 
    205 #ifndef NDEBUG
    206 struct mhd_H2ConnDebug
    207 {
    208   volatile bool w_buff_updating;
    209   volatile bool h2_deinited;
    210 };
    211 #endif /* ! NDEBUG */
    212 
    213 struct mhd_H2ConnData
    214 {
    215   struct mhd_H2ConnRecvCtrlData rcv_cfg;
    216 
    217   struct mhd_H2ConnMemData mem;
    218 
    219   struct mhd_H2ConnStateData state;
    220 
    221   struct mhd_H2ConnPeerData peer;
    222 
    223   struct mhd_HpackDecContext hk_dec;
    224 
    225   struct mhd_HpackEncContext hk_enc;
    226 
    227   struct mhd_H2ConnStreams streams;
    228 
    229   struct mhd_H2ConnBuffData buff;
    230 #ifndef NDEBUG
    231   struct mhd_H2ConnDebug dbg;
    232 #endif /* ! NDEBUG */
    233 };
    234 
    235 #ifndef NDEBUG
    236 #  define mhd_H2_W_BUFF_UPDATING_SET(h2data) \
    237         do {(h2data)->dbg.w_buff_updating = true;} while (0)
    238 #  define mhd_H2_W_BUFF_UPDATING_CLEAR(h2data) \
    239         do {(h2data)->dbg.w_buff_updating = false;} while (0)
    240 #else  /* NDEBUG */
    241 #  define mhd_H2_W_BUFF_UPDATING_SET(h2data)    ((void) 0)
    242 #  define mhd_H2_W_BUFF_UPDATING_CLEAR(h2data)  ((void) 0)
    243 #endif /* NDEBUG */
    244 
    245 #endif /* ! MHD_H2_CONN_DATA_H */