libmicrohttpd2

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

mhd_reply.h (5148B)


      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) 2021-2024 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_reply.h
     41  * @brief  The definition of the working reply data
     42  * @author Karlson2k (Evgeny Grin)
     43  *
     44  * Data structures in this header are used when responding to client's request.
     45  * Do not be confused with terms "response" and "reply" using in MHD code.
     46  * The "MHD_Response" is an connection-independent object that have all
     47  * data required to form a respond.
     48  * The "MHD_Reply" is working connection-specific data used to format
     49  * the respond based on provided data in "MHD_Response".
     50  */
     51 
     52 #ifndef MHD_REPLY_H
     53 #define MHD_REPLY_H 1
     54 
     55 #include "mhd_sys_options.h"
     56 
     57 #include "sys_bool_type.h"
     58 
     59 #include "mhd_dcc_action.h"
     60 
     61 #include "mhd_iovec.h"
     62 
     63 struct MHD_Response; /* forward declaration */
     64 
     65 /**
     66  * Reply-specific properties.
     67  */
     68 struct MHD_Reply_Properties
     69 {
     70 #ifndef NDEBUG
     71   bool set; /**< Indicates that other members are set and valid */
     72 #endif /* _DEBUG */
     73   bool use_reply_body_headers; /**< Use reply body-specific headers */
     74   bool send_reply_body; /**< Send reply body (can be zero-sized) */
     75   bool chunked; /**< Use chunked encoding for reply */
     76   bool end_by_closing; /**< Signal end of content (only) by closing connection */
     77 };
     78 
     79 /**
     80  * The location of the reply content
     81  */
     82 enum MHD_FIXED_ENUM_ mhd_ReplyContentLocation
     83 {
     84   /**
     85    * Reply content is absent
     86    */
     87   mhd_REPLY_CNTN_LOC_NOWHERE = 0
     88   ,
     89   /**
     90    * Reply content is in the response buffer
     91    */
     92   mhd_REPLY_CNTN_LOC_RESP_BUF
     93   ,
     94   /**
     95    * Reply content is in the connection buffer
     96    */
     97   mhd_REPLY_CNTN_LOC_CONN_BUF
     98   ,
     99   /**
    100    * Reply content is in the vector data
    101    */
    102   mhd_REPLY_CNTN_LOC_IOV
    103   ,
    104   /**
    105    * Reply content is in the file, to be used with sendfile() function
    106    */
    107   mhd_REPLY_CNTN_LOC_FILE
    108 };
    109 
    110 
    111 /**
    112  * Reply-specific values.
    113  *
    114  * Meaningful for the current reply only.
    115  */
    116 struct MHD_Reply
    117 {
    118   /**
    119    * The action provided by application when content is dynamically created.
    120    * Used only when mhd_RESPONSE_CONTENT_DATA_CALLBACK == response->cntn_dtype
    121    */
    122   struct MHD_DynamicContentCreatorAction app_act;
    123 
    124   /**
    125    * The context provided for application callback for dynamic content.
    126    * Used only when mhd_RESPONSE_CONTENT_DATA_CALLBACK == response->cntn_dtype
    127    */
    128   struct MHD_DynamicContentCreatorContext app_act_ctx;
    129 
    130 #ifdef MHD_SUPPORT_UPGRADE
    131   /**
    132    * Set to 'true' when "100 Continue" response has been sent
    133    */
    134   bool sent_100_cntn;
    135 #endif /* MHD_SUPPORT_UPGRADE */
    136 
    137   /**
    138    * Response to transmit (initially NULL).
    139    */
    140   struct MHD_Response *response;
    141 
    142   /**
    143    * The "ICY" response.
    144    * Reply begins with the SHOUTcast "ICY" line instead of "HTTP".
    145    */
    146   bool responseIcy;
    147 
    148   /**
    149    * Current rest position in the actual content (should be 0 while
    150    * sending headers).
    151    * When sending buffers located in the connection buffers, it is updated
    152    * when the data copied to the buffers. In other cases it is updated when
    153    * data is actually sent.
    154    */
    155   uint_fast64_t rsp_cntn_read_pos;
    156 
    157   /**
    158    * The copy of iov response.
    159    * Valid if iovec response is used.
    160    * Updated during send.
    161    * Members are allocated in the pool.
    162    */
    163   struct mhd_iovec_track resp_iov;
    164 
    165   /**
    166    * The location of the reply content
    167    */
    168   enum mhd_ReplyContentLocation cntn_loc;
    169 
    170   /**
    171    * Reply-specific properties
    172    */
    173   struct MHD_Reply_Properties props;
    174 };
    175 
    176 #endif /* ! MHD_REPLY_H */