libmicrohttpd2

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

mhd_handle_tag.h (4424B)


      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) 2026 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/mhd_handle_tag.h
     41  * @brief  The handle tag and the related macros
     42  * @author Karlson2k (Evgeny Grin)
     43  *
     44  * The public handles (#MHD_Request, #MHD_Stream) are used for both HTTP/1.x
     45  * and HTTP/2 data. The actual type is detected by the leading member, which
     46  * is the same in both halves of every such pair.
     47  */
     48 
     49 #ifndef MHD_HANDLE_TAG_H
     50 #define MHD_HANDLE_TAG_H 1
     51 
     52 #include "mhd_sys_options.h"
     53 
     54 #include "sys_bool_type.h"
     55 
     56 /* Note: HTTP/1.x support is mandatory in the current code */
     57 
     58 /* Sanity check */
     59 #ifndef mhd_MULTI_HTTP_VER_BUILD
     60 #  ifdef MHD_SUPPORT_HTTP2
     61 #    error MHD_SUPPORT_HTTP2 is defined, but mhd_MULTI_HTTP_VER_BUILD is not
     62 #  endif
     63 #else  /* ! mhd_MULTI_HTTP_VER_BUILD */
     64 #  ifndef MHD_SUPPORT_HTTP2
     65 #    error mhd_MULTI_HTTP_VER_BUILD is defined, but MHD_SUPPORT_HTTP2 is not
     66 #  endif
     67 #endif /* ! mhd_MULTI_HTTP_VER_BUILD */
     68 
     69 #ifdef mhd_MULTI_HTTP_VER_BUILD
     70 /**
     71  * The handle tag.
     72  *
     73  * MUST be the first member of both halves of every pair: #MHD_Request and
     74  * #mhd_H2RequestData, #MHD_Stream and #mhd_H2Stream.
     75  * Do not access the members directly, use #mhd_HNDL_IS_HTTP2() and
     76  * the related macros.
     77  */
     78 struct mhd_HandleTag
     79 {
     80   /**
     81    * 'true' for HTTP/2 handles, 'false' for HTTP/1.x handles
     82    */
     83   bool is_http2;
     84 };
     85 
     86 /**
     87  * Get the pointer to the tag of the handle.
     88  * A pointer to a structure points to its initial member, therefore the tag of
     89  * any half of the pair is reachable by this conversion.
     90  */
     91 #  define mhd_HNDL_TAG_(handle) \
     92         ((const struct mhd_HandleTag *) (const void *) (handle))
     93 
     94 /**
     95  * Check whether the handle is an HTTP/2 handle
     96  */
     97 #  define mhd_HNDL_IS_HTTP2(handle)     (mhd_HNDL_TAG_ (handle)->is_http2)
     98 
     99 /**
    100  * Set the tag of the handle to HTTP/1.x
    101  */
    102 #  define mhd_HNDL_TAG_SET_HTTP1(handle) \
    103           ((void) ((handle)->tag.is_http2 = false))
    104 /**
    105  * Set the tag of the handle to HTTP/2
    106  */
    107 #  define mhd_HNDL_TAG_SET_HTTP2(handle) \
    108           ((void) ((handle)->tag.is_http2 = true))
    109 #else  /* ! mhd_MULTI_HTTP_VER_BUILD */
    110 
    111 /**
    112  * Check whether the handle is an HTTP/2 handle
    113  */
    114 #  define mhd_HNDL_IS_HTTP2(handle)     (((void) (handle)), (! ! 0))
    115 
    116 /**
    117  * Set the tag of the handle to HTTP/1.x. No-op, the tag is not used.
    118  */
    119 #  define mhd_HNDL_TAG_SET_HTTP1(handle) ((void) (handle))
    120 /**
    121  * Set the tag of the handle to HTTP/2. No-op, the tag is not used.
    122  */
    123 #  define mhd_HNDL_TAG_SET_HTTP2(handle) ((void) (handle))
    124 #endif /* ! mhd_MULTI_HTTP_VER_BUILD */
    125 
    126 /**
    127  * Check whether the handle is an HTTP/1.x handle
    128  */
    129 #define mhd_HNDL_IS_HTTP1(handle)       (! mhd_HNDL_IS_HTTP2 (handle))
    130 
    131 
    132 #endif /* ! MHD_HANDLE_TAG_H */