libmicrohttpd2

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

mhd_send.h (6560B)


      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) 2017-2025 Evgeny Grin (Karlson2k)
      5   Copyright (C) 2019 ng0
      6 
      7   GNU libmicrohttpd is free software; you can redistribute it and/or
      8   modify it under the terms of the GNU Lesser General Public
      9   License as published by the Free Software Foundation; either
     10   version 2.1 of the License, or (at your option) any later version.
     11 
     12   GNU libmicrohttpd is distributed in the hope that it will be useful,
     13   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15   Lesser General Public License for more details.
     16 
     17   Alternatively, you can redistribute GNU libmicrohttpd and/or
     18   modify it under the terms of the GNU General Public License as
     19   published by the Free Software Foundation; either version 2 of
     20   the License, or (at your option) any later version, together
     21   with the eCos exception, as follows:
     22 
     23     As a special exception, if other files instantiate templates or
     24     use macros or inline functions from this file, or you compile this
     25     file and link it with other works to produce a work based on this
     26     file, this file does not by itself cause the resulting work to be
     27     covered by the GNU General Public License. However the source code
     28     for this file must still be made available in accordance with
     29     section (3) of the GNU General Public License v2.
     30 
     31     This exception does not invalidate any other reasons why a work
     32     based on this file might be covered by the GNU General Public
     33     License.
     34 
     35   You should have received copies of the GNU Lesser General Public
     36   License and the GNU General Public License along with this library;
     37   if not, see <https://www.gnu.org/licenses/>.
     38 */
     39 
     40 /**
     41  * @file src/mhd2/mhd_send.h
     42  * @brief Declarations of send() wrappers.
     43  * @author Karlson2k (Evgeny Grin)
     44  * @author ng0 (N. Gillmann)
     45  */
     46 
     47 #ifndef MHD_SEND_H
     48 #define MHD_SEND_H
     49 
     50 #include "mhd_sys_options.h"
     51 
     52 #include "sys_base_types.h"
     53 #include "sys_bool_type.h"
     54 #include "mhd_socket_error.h"
     55 
     56 struct MHD_Connection; /* forward declaration */
     57 struct mhd_iovec_track; /* forward declaration */
     58 
     59 /**
     60  * Initialises static variables.
     61  * Need to be called only once.
     62  */
     63 void
     64 mhd_send_init_once (void);
     65 
     66 
     67 /**
     68  * Send buffer to the client, push data from network buffer if requested
     69  * and full buffer is sent.
     70  *
     71  * @param connection the MHD_Connection structure
     72  * @param buf_size the size of the @a buf (in bytes)
     73  * @param buf content of the buffer to send
     74  * @param push_data set to true to force push the data to the network from
     75  *                  system buffers (usually set for the last piece of data),
     76  *                  set to false to prefer holding incomplete network packets
     77  *                  (more data will be send for the same reply).
     78  * @param[out] sent the pointer to get amount of actually sent bytes
     79  * @return mhd_SOCKET_ERR_NO_ERROR if send succeed (the @a sent gets
     80  *         the sent size) or socket error
     81  */
     82 MHD_INTERNAL enum mhd_SocketError
     83 mhd_send_data (struct MHD_Connection *restrict connection,
     84                size_t buf_size,
     85                const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)],
     86                bool push_data,
     87                size_t *restrict sent)
     88 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_OUT_ (5);
     89 
     90 
     91 /**
     92  * Send reply header with optional reply body.
     93  *
     94  * @param connection the MHD_Connection structure
     95  * @param header content of header to send
     96  * @param header_size the size of the @a header (in bytes)
     97  * @param never_push_hdr set to true to disable internal algorithm
     98  *                       that can push automatically header data
     99  *                       alone to the network
    100  * @param body content of the body to send (optional, may be NULL)
    101  * @param body_size the size of the @a body (in bytes)
    102  * @param complete_response set to true if complete response
    103  *                          is provided by @a header and @a body,
    104  *                          set to false if additional body data
    105  *                          will be sent later
    106  * @param[out] sent the pointer to get amount of actually sent bytes
    107  *                  in total (from both buffers combined)
    108  * @return mhd_SOCKET_ERR_NO_ERROR if send succeed (the @a sent gets
    109  *         the sent size) or socket error
    110  */
    111 MHD_INTERNAL enum mhd_SocketError
    112 mhd_send_hdr_and_body (struct MHD_Connection *restrict connection,
    113                        size_t header_size,
    114                        const char *restrict header,
    115                        bool never_push_hdr,
    116                        size_t body_size,
    117                        const char *restrict body,
    118                        bool complete_response,
    119                        size_t *restrict sent)
    120 MHD_FN_PAR_NONNULL_(1) MHD_FN_PAR_NONNULL_(3)
    121 MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_IN_SIZE_ (6,5) MHD_FN_PAR_OUT_ (8);
    122 
    123 #if defined(mhd_USE_SENDFILE)
    124 /**
    125  * Function for sending responses backed by file FD.
    126  *
    127  * @param c the MHD connection structure
    128  * @param[out] sent the pointer to get amount of actually sent bytes
    129  *                  in total (from both buffers combined)
    130  * @return mhd_SOCKET_ERR_NO_ERROR if send succeed (the @a sent gets
    131  *         the sent size) or socket error
    132  */
    133 MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_ (2) enum mhd_SocketError
    134 mhd_send_sendfile (struct MHD_Connection *restrict c,
    135                    size_t *restrict sent)
    136 MHD_FN_PAR_NONNULL_ALL_;
    137 
    138 #endif
    139 
    140 
    141 /**
    142  * Function for sending responses backed by a an array of memory buffers.
    143  *
    144  * @param connection the MHD connection structure
    145  * @param r_iov the pointer to iov response structure with tracking
    146  * @param push_data set to true to force push the data to the network from
    147  *                  system buffers (usually set for the last piece of data),
    148  *                  set to false to prefer holding incomplete network packets
    149  *                  (more data will be send for the same reply).
    150  * @param[out] sent the pointer to get amount of actually sent bytes
    151  *                  in total (from both buffers combined)
    152  * @return mhd_SOCKET_ERR_NO_ERROR if send succeed (the @a sent gets
    153  *         the sent size) or socket error
    154  */
    155 MHD_INTERNAL enum mhd_SocketError
    156 mhd_send_iovec (struct MHD_Connection *restrict connection,
    157                 struct mhd_iovec_track *const restrict r_iov,
    158                 bool push_data,
    159                 size_t *restrict sent)
    160 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_ (4);
    161 
    162 
    163 #endif /* MHD_SEND_H */