gnunet_mhd_lib.h (2901B)
1 /* 2 This file is part of GNUnet 3 Copyright (C) 2014, 2015, 2016, 2020, 2024 GNUnet e.V. 4 5 GNUnet is free software: you can redistribute it and/or modify it 6 under the terms of the GNU Affero General Public License as published 7 by the Free Software Foundation, either version 3 of the License, 8 or (at your option) any later version. 9 10 GNUnet is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Affero General Public License for more details. 14 15 You should have received a copy of the GNU Affero General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 SPDX-License-Identifier: AGPL3.0-or-later 19 */ 20 /** 21 * @file gnunet_mhd_lib.h 22 * @brief functions to parse HTTP uploads with MHD 23 * @author Christian Grothoff 24 */ 25 #ifndef GNUNET_MHD_LIB_H 26 #define GNUNET_MHD_LIB_H 27 28 #include "gnunet_util_lib.h" 29 #include <microhttpd.h> 30 #include <jansson.h> 31 32 33 /** 34 * Return codes from #GNUNET_MHD_post_parser(). 35 */ 36 enum GNUNET_MHD_PostResult 37 { 38 /** 39 * Parsing successful, JSON result is in `*json`. 40 */ 41 GNUNET_MHD_PR_SUCCESS, 42 43 /** 44 * Parsing continues, call again soon! 45 */ 46 GNUNET_MHD_PR_CONTINUE, 47 48 /** 49 * Sorry, memory allocation (malloc()) failed. 50 */ 51 GNUNET_MHD_PR_OUT_OF_MEMORY, 52 53 /** 54 * Request size exceeded `buffer_max` argument. 55 */ 56 GNUNET_MHD_PR_REQUEST_TOO_LARGE, 57 58 /** 59 * JSON parsing failed. This was not a JSON upload. 60 */ 61 GNUNET_MHD_PR_JSON_INVALID 62 }; 63 64 65 /** 66 * Process a POST request containing a JSON object. This function 67 * realizes an MHD POST processor that will (incrementally) process 68 * JSON data uploaded to the HTTP server. It will store the required 69 * state in the @a con_cls, which must be cleaned up using 70 * #GNUNET_MHD_post_parser_callback(). 71 * 72 * @param buffer_max maximum allowed size for the buffer 73 * @param connection MHD connection handle (for meta data about the upload) 74 * @param con_cls the closure (will point to a `struct Buffer *`) 75 * @param upload_data the POST data 76 * @param upload_data_size number of bytes in @a upload_data 77 * @param json the JSON object for a completed request 78 * @return result code indicating the status of the operation 79 */ 80 enum GNUNET_MHD_PostResult 81 GNUNET_MHD_post_parser (size_t buffer_max, 82 struct MHD_Connection *connection, 83 void **con_cls, 84 const char *upload_data, 85 size_t *upload_data_size, 86 json_t **json); 87 88 89 /** 90 * Function called whenever we are done with a request 91 * to clean up our state. 92 * 93 * @param con_cls value as it was left by 94 * #GNUNET_MHD_post_parser(), to be cleaned up 95 */ 96 void 97 GNUNET_MHD_post_parser_cleanup (void *con_cls); 98 99 100 #endif 101 /* end of gnunet_mhd_lib.h */