response.h (4518B)
1 /* 2 This file is part of libmicrohttpd 3 Copyright (C) 2007 Daniel Pittman and Christian Grothoff 4 Copyright (C) 2015-2022 Karlson2k (Evgeny Grin) 5 6 This library 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 This library 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 You should have received a copy of the GNU Lesser General Public 17 License along with this library; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 21 /** 22 * @file response.h 23 * @brief Methods for managing response objects 24 * @author Daniel Pittman 25 * @author Christian Grothoff 26 * @author Karlson2k (Evgeny Grin) 27 */ 28 29 #ifndef RESPONSE_H 30 #define RESPONSE_H 31 32 /** 33 * Increments the reference counter for the @a response. 34 * 35 * @param response object to modify 36 */ 37 void 38 MHD_increment_response_rc (struct MHD_Response *response); 39 40 41 /** 42 * We are done sending the header of a given response 43 * to the client. Now it is time to perform the upgrade 44 * and hand over the connection to the application. 45 * @remark To be called only from thread that process connection's 46 * recv(), send() and response. Must be called right after sending 47 * response headers. 48 * 49 * @param response the response that was created for an upgrade 50 * @param connection the specific connection we are upgrading 51 * @return #MHD_YES on success, #MHD_NO on failure (will cause 52 * connection to be closed) 53 */ 54 enum MHD_Result 55 MHD_response_execute_upgrade_ (struct MHD_Response *response, 56 struct MHD_Connection *connection); 57 58 59 /** 60 * Get a particular header (or footer) element from the response. 61 * 62 * Function returns the first found element. 63 * @param response response to query 64 * @param kind the kind of element: header or footer 65 * @param key the key which header to get 66 * @param key_len the length of the @a key 67 * @return NULL if header element does not exist 68 * @ingroup response 69 */ 70 struct MHD_HTTP_Res_Header * 71 MHD_get_response_element_n_ (struct MHD_Response *response, 72 enum MHD_ValueKind kind, 73 const char *key, 74 size_t key_len); 75 76 /** 77 * Add a header or footer line to the response without checking. 78 * 79 * It is assumed that parameters are correct. 80 * 81 * @param response response to add a header to 82 * @param kind header or footer 83 * @param name the header name to add, does not need to be zero-terminated 84 * @param name_len the length of the @a name 85 * @param value the header value to add, does not need to be zero-terminated 86 * @param value_len the length of the @a value 87 * @return false on error (like out-of-memory), 88 * true if succeed 89 */ 90 bool 91 MHD_add_response_entry_no_check_ (struct MHD_Response *response, 92 enum MHD_ValueKind kind, 93 const char *name, 94 size_t name_len, 95 const char *value, 96 size_t value_len); 97 98 /** 99 * Add preallocated strings a header or footer line to the response without 100 * checking. 101 * 102 * Header/footer strings are not checked and assumed to be correct. 103 * 104 * The string must not be statically allocated! 105 * The strings must be malloc()'ed and zero terminated. The strings will 106 * be free()'ed when the response is destroyed. 107 * 108 * @param response response to add a header to 109 * @param kind header or footer 110 * @param name the header name string to add, must be malloc()'ed and 111 * zero-terminated 112 * @param name_len the length of the @a name 113 * @param value the header value string to add, must be malloc()'ed and 114 * zero-terminated 115 * @param value_len the length of the @a value 116 */ 117 bool 118 MHD_add_response_entry_no_alloc_ (struct MHD_Response *response, 119 enum MHD_ValueKind kind, 120 char *name, 121 size_t name_len, 122 char *value, 123 size_t value_len); 124 125 #endif