gnunet_rest_lib.h (3167B)
1 /* 2 This file is part of GNUnet 3 Copyright (C) 2010-2015 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 /** 22 * @addtogroup rest_l2 REST service and libraries 23 * @{ 24 * 25 * @author Martin Schanzenbach 26 * 27 * @file 28 * API for helper library to parse/create REST 29 * 30 * @defgroup rest REST library 31 * Helper library to parse/create REST 32 * @{ 33 */ 34 #ifndef GNUNET_REST_LIB_H 35 #define GNUNET_REST_LIB_H 36 37 38 #include "gnunet_util_lib.h" 39 #include <microhttpd.h> 40 41 #define GNUNET_REST_HANDLER_END { NULL, NULL, NULL } 42 43 struct GNUNET_REST_RequestHandle 44 { 45 /** 46 * Map of url parameters 47 */ 48 struct GNUNET_CONTAINER_MultiHashMap *url_param_map; 49 50 /** 51 * Map of headers 52 */ 53 struct GNUNET_CONTAINER_MultiHashMap *header_param_map; 54 55 /** 56 * The HTTP method as MHD value (see microhttpd.h) 57 */ 58 const char *method; 59 60 /** 61 * The url as string 62 */ 63 const char *url; 64 65 /** 66 * The POST data 67 */ 68 const char *data; 69 70 /** 71 * The POST data size 72 */ 73 size_t data_size; 74 }; 75 76 struct GNUNET_REST_RequestHandlerError 77 { 78 int error_code; 79 char*error_text; 80 }; 81 82 struct GNUNET_REST_RequestHandler 83 { 84 /** 85 * Http method to handle 86 */ 87 const char *method; 88 89 /** 90 * Namespace to handle 91 */ 92 const char *namespace; 93 94 /** 95 * callback handler 96 */ 97 void (*proc) (struct GNUNET_REST_RequestHandle *handle, 98 const char *url, 99 void *cls); 100 }; 101 102 103 /** 104 * Iterator called on obtained result for a REST result. 105 * 106 * @param cls closure 107 * @param resp the response 108 * @param status status code (HTTP) 109 */ 110 typedef void (*GNUNET_REST_ResultProcessor) (void *cls, 111 struct MHD_Response *resp, 112 int status); 113 114 /** 115 * Check if namespace is in URL. 116 * 117 * @param url URL to check 118 * @param namespace namespace to check against 119 * @return GNUNET_YES if namespace matches 120 */ 121 int 122 GNUNET_REST_namespace_match (const char *url, const char *namespace); 123 124 /** 125 * Create REST MHD response 126 * 127 * @param data result 128 * @return MHD response 129 */ 130 struct MHD_Response* 131 GNUNET_REST_create_response (const char *data); 132 133 134 int 135 GNUNET_REST_handle_request (struct GNUNET_REST_RequestHandle *conn, 136 const struct GNUNET_REST_RequestHandler *handlers, 137 struct GNUNET_REST_RequestHandlerError *err, 138 void *cls); 139 140 141 #endif 142 143 /** @} */ /* end of group */ 144 145 /** @} */ /* end of group addition */