request_get_value.h (5859B)
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) 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/request_get_value.h 41 * @brief The declaration of internal mhd_request_get_value* functions 42 * @author Karlson2k (Evgeny Grin) 43 */ 44 45 #ifndef MHD_REQUEST_GET_VALUE_H 46 #define MHD_REQUEST_GET_VALUE_H 1 47 48 #include "mhd_sys_options.h" 49 #include "sys_base_types.h" 50 #include "sys_bool_type.h" 51 #include "mhd_str_macros.h" 52 53 #include "mhd_public_api.h" 54 55 /** 56 * Get specified field value from request 57 * If multiple values match the kind, return first found. 58 * 59 * The returned pointer is valid until any action is set. 60 * If the data is needed beyond this point, it should be copied. 61 * 62 * @param request request to get values from 63 * @param kind what kind of value are we looking for 64 * @param key_len the length of the @a key string 65 * @param key the header to look for, empty to lookup 'trailing' value 66 * without a key 67 * @param[out] value_out set to the value of the filed if succeed, 68 * the @a cstr pointer could be NULL even if succeed 69 * if the requested filed found, but has no value 70 * @return 'true' if succeed, the @a value_out is set; 71 * 'false' if no such field was found, the @a value_out string pointer 72 * set to NULL 73 * @ingroup request 74 */ 75 MHD_INTERNAL 76 bool 77 mhd_request_get_value_n (struct MHD_Request *restrict request, 78 enum MHD_ValueKind kind, 79 size_t key_len, 80 const char *restrict key, 81 struct MHD_StringNullable *restrict value_out) 82 MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_IN_SIZE_ (4,3) 83 MHD_FN_PAR_NONNULL_ (4) MHD_FN_PAR_CSTR_ (4) 84 MHD_FN_PAR_OUT_ (5); 85 86 /** 87 * Get specified field value from request 88 * If multiple values match the kind, return any one of them. 89 * 90 * The returned pointer is valid until the response is queued. 91 * If the data is needed beyond this point, it should be copied. 92 * 93 * @param request request to get values from 94 * @param kind what kind of value are we looking for 95 * @param key the header to look for, empty to lookup 'trailing' value 96 * without a key; must be a static string or array 97 * @return NULL if no such item was found 98 * @ingroup request 99 */ 100 #define mhd_request_get_value_st(r,k,str,v_out) \ 101 mhd_request_get_value_n ((r),(k),mhd_SSTR_LEN (str),(str),(v_out)) 102 103 #endif /* ! MHD_REQUEST_GET_VALUE_H */ 104 105 106 /** 107 * Check whether the request header contains particular token. 108 * 109 * Token could be surrounded by spaces and tabs and delimited by comma. 110 * Case-insensitive match used for header names and tokens. 111 * @param c the connection to check values 112 * @param header_len the length of header, not including optional 113 * terminating null-character 114 * @param header the header name 115 * @param token_len the length of token, not including optional 116 * terminating null-character. 117 * @param token the token to find 118 * @return true if the token is found in the specified header, 119 * false otherwise 120 */ 121 MHD_INTERNAL bool 122 mhd_stream_has_header_token (const struct MHD_Connection *restrict c, 123 size_t header_len, 124 const char *restrict header, 125 size_t token_len, 126 const char *restrict token) 127 MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_CSTR_ (5); 128 129 /** 130 * Check whether the request header contains particular token. 131 * 132 * Token could be surrounded by spaces and tabs and delimited by comma. 133 * Case-insensitive match used for header names and tokens. 134 * @param c the connection to check values 135 * @param hdr the statically allocated header name string 136 * @param token the statically allocated string of token to find 137 * @return true if the token is found in the specified header, 138 * false otherwise 139 */ 140 #define mhd_stream_has_header_token_st(c,hdr,tkn) \ 141 mhd_stream_has_header_token ((c), mhd_SSTR_LEN (hdr), (hdr), \ 142 mhd_SSTR_LEN (tkn), (tkn))