libmicrohttpd2

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

h2_conn_streams.h (6153B)


      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_streams.h
     41  * @brief  Declarations of HTTP/2 connection streams processing functions
     42  * @author Karlson2k (Evgeny Grin)
     43  */
     44 
     45 #ifndef MHD_H2_CONN_STREAMS_H
     46 #define MHD_H2_CONN_STREAMS_H 1
     47 
     48 #include "mhd_sys_options.h"
     49 
     50 #include "sys_bool_type.h"
     51 
     52 #include "h2_err_codes.h"
     53 
     54 struct MHD_Connection;  /* forward declaration */
     55 struct mhd_Buffer;      /* forward declaration */
     56 struct mhd_H2Stream;    /* forward declaration */
     57 
     58 enum mhd_H2RequestProblemType
     59 {
     60   mhd_H2_REQ_PRBLM_FIELD_CHARS
     61   ,
     62   mhd_H2_REQ_PRBLM_FORBIDDEN_HEADER
     63   ,
     64   mhd_H2_REQ_PRBLM_CNTNT_LEN_WRONG
     65   ,
     66   mhd_H2_REQ_PRBLM_HOST_HDR_WRONG_EXTRA
     67   ,
     68   mhd_H2_REQ_PRBLM_HEADERS_NO_ENDSTREAM
     69   ,
     70   mhd_H2_REQ_PRBLM_PSEUDOHDR_IN_TRAILER
     71   ,
     72   mhd_H2_REQ_PRBLM_UNKNOWN_PSEUDOHDR
     73   ,
     74   mhd_H2_REQ_PRBLM_PSEUDOHDR_AFTER_HDR
     75   ,
     76   mhd_H2_REQ_PRBLM_PSEUDOHDR_MISSING
     77   ,
     78   mhd_H2_REQ_PRBLM_PSEUDOHDR_DUP
     79   ,
     80   mhd_H2_REQ_PRBLM_PSEUDOHDR_EXTRA
     81   ,
     82   mhd_H2_REQ_PRBLM_FLOW_CONTROL
     83   ,
     84 
     85   mhd_H2_REQ_PRBLM_HEADERS_TOO_LARGE
     86   ,
     87   mhd_H2_REQ_PRBLM_INT_ERROR
     88 };
     89 
     90 /**
     91  * Handle malformed request.
     92  * Send error reply, if possible; abort the request.
     93  * @param s the stream to handle
     94  * @param problem_type the type of the problem
     95  * @return always 'false'
     96  */
     97 MHD_INTERNAL bool
     98 mhd_h2_stream_req_problem (struct mhd_H2Stream *restrict s,
     99                            enum mhd_H2RequestProblemType problem_type)
    100 MHD_FN_PAR_NONNULL_ALL_;
    101 
    102 
    103 /**
    104  * Perform early abort of the stream, typically due to some error in processing.
    105  * @param s the stream to abort
    106  * @param err the error code to use
    107  * @return always 'false'
    108  */
    109 MHD_INTERNAL bool
    110 mhd_h2_stream_abort (struct mhd_H2Stream *restrict s,
    111                      enum mhd_H2ErrorCode err)
    112 MHD_FN_PAR_NONNULL_ALL_;
    113 
    114 MHD_INTERNAL bool
    115 mhd_h2_conn_streamid_in_headers (struct MHD_Connection *restrict c,
    116                                  uint_least32_t stream_id,
    117                                  bool end_stream,
    118                                  bool end_headers,
    119                                  struct mhd_Buffer *restrict payload)
    120 MHD_FN_PAR_NONNULL_ALL_;
    121 
    122 MHD_INTERNAL bool
    123 mhd_h2_conn_streamid_in_continuation (struct MHD_Connection *restrict c,
    124                                       uint_least32_t stream_id,
    125                                       bool end_headers,
    126                                       struct mhd_Buffer *payload)
    127 MHD_FN_PAR_NONNULL_ALL_;
    128 
    129 MHD_INTERNAL bool
    130 mhd_h2_conn_streamid_in_data (struct MHD_Connection *restrict c,
    131                               uint_least32_t stream_id,
    132                               bool end_stream,
    133                               struct mhd_Buffer *restrict payload)
    134 MHD_FN_PAR_NONNULL_ALL_;
    135 
    136 MHD_INTERNAL bool
    137 mhd_h2_conn_streamid_in_rst_stream (struct MHD_Connection *restrict c,
    138                                     uint_least32_t stream_id,
    139                                     enum mhd_H2ErrorCode err)
    140 MHD_FN_PAR_NONNULL_ALL_;
    141 
    142 MHD_INTERNAL bool
    143 mhd_h2_conn_streamid_window_incr (struct MHD_Connection *restrict c,
    144                                   uint_least32_t stream_id,
    145                                   uint_least32_t incr)
    146 MHD_FN_PAR_NONNULL_ALL_;
    147 
    148 MHD_INTERNAL bool
    149 mhd_h2_conn_streamid_abort (struct MHD_Connection *restrict c,
    150                             uint_least32_t stream_id,
    151                             enum mhd_H2ErrorCode err)
    152 MHD_FN_PAR_NONNULL_ALL_;
    153 
    154 /**
    155  * Process maintenance of all streams in the connection
    156  * @param c the connection to use
    157  * @return 'true' if all connections have been processed,
    158  *         'false' is output buffer has no space for required frame or
    159  *                 if connection is broken
    160  */
    161 MHD_INTERNAL bool
    162 mhd_h2_conn_maintain_streams_all  (struct MHD_Connection *restrict c)
    163 MHD_FN_PAR_NONNULL_ALL_;
    164 
    165 /**
    166  * Process sending queue, send replies.
    167  * @param c the connection to use
    168  * @return 'true' if all connections have been processed,
    169  *         'false' is output buffer has no space for required frame or
    170  *                 if connection is broken
    171  */
    172 MHD_INTERNAL bool
    173 mhd_h2_conn_process_streams_sending_queue (struct MHD_Connection *restrict c)
    174 MHD_FN_PAR_NONNULL_ALL_;
    175 
    176 /**
    177  * Force close of all connection's streams.
    178  * @param c the connection to use
    179  */
    180 MHD_INTERNAL void
    181 mhd_h2_conn_close_streams_all  (struct MHD_Connection *restrict c)
    182 MHD_FN_PAR_NONNULL_ALL_;
    183 
    184 #endif /* ! MHD_H2_CONN_STREAMS_H */