sync-httpd.h (4262B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2019-2021 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file sync/sync-httpd.h 18 * @brief HTTP serving layer 19 * @author Christian Grothoff 20 */ 21 #ifndef sync_HTTPD_H 22 #define sync_HTTPD_H 23 24 #include "platform.h" 25 #include <microhttpd.h> 26 #include <taler/taler_mhd_lib.h> 27 #include "sync/sync_database_lib.h" 28 #include <gnunet/gnunet_mhd_compat.h> 29 30 /** 31 * @brief Struct describing an URL and the handler for it. 32 */ 33 struct SH_RequestHandler 34 { 35 36 /** 37 * URL the handler is for. 38 */ 39 const char *url; 40 41 /** 42 * Method the handler is for, NULL for "all". 43 */ 44 const char *method; 45 46 /** 47 * Mime type to use in reply (hint, can be NULL). 48 */ 49 const char *mime_type; 50 51 /** 52 * Raw data for the @e handler 53 */ 54 const void *data; 55 56 /** 57 * Number of bytes in @e data, 0 for 0-terminated. 58 */ 59 size_t data_size; 60 61 /** 62 * Function to call to handle the request. 63 * 64 * @param rh this struct 65 * @param mime_type the @e mime_type for the reply (hint, can be NULL) 66 * @param connection the MHD connection to handle 67 * @param[in,out] connection_cls the connection's closure (can be updated) 68 * @param upload_data upload data 69 * @param[in,out] upload_data_size number of bytes (left) in @a upload_data 70 * @return MHD result code 71 */ 72 enum MHD_Result (*handler)(struct SH_RequestHandler *rh, 73 struct MHD_Connection *connection, 74 void **connection_cls, 75 const char *upload_data, 76 size_t *upload_data_size); 77 78 /** 79 * Default response code. 80 */ 81 unsigned int response_code; 82 }; 83 84 85 /** 86 * Each MHD response handler that sets the "connection_cls" to a 87 * non-NULL value must use a struct that has this struct as its first 88 * member. This struct contains a single callback, which will be 89 * invoked to clean up the memory when the contection is completed. 90 */ 91 struct TM_HandlerContext; 92 93 /** 94 * Signature of a function used to clean up the context 95 * we keep in the "connection_cls" of MHD when handling 96 * a request. 97 * 98 * @param hc header of the context to clean up. 99 */ 100 typedef void 101 (*TM_ContextCleanup)(struct TM_HandlerContext *hc); 102 103 104 /** 105 * Each MHD response handler that sets the "connection_cls" to a 106 * non-NULL value must use a struct that has this struct as its first 107 * member. This struct contains a single callback, which will be 108 * invoked to clean up the memory when the connection is completed. 109 */ 110 struct TM_HandlerContext 111 { 112 113 /** 114 * Function to execute the handler-specific cleanup of the 115 * (typically larger) context. 116 */ 117 TM_ContextCleanup cc; 118 119 /** 120 * Asynchronous request context id. 121 */ 122 struct GNUNET_AsyncScopeId async_scope_id; 123 }; 124 125 126 /** 127 * Upload limit to the service, in megabytes. 128 */ 129 extern unsigned long long SH_upload_limit_mb; 130 131 /** 132 * Annual fee for the backup account. 133 */ 134 extern struct TALER_Amount SH_annual_fee; 135 136 /** 137 * Our Taler backend to process payments. 138 */ 139 extern char *SH_backend_url; 140 141 /** 142 * Our fulfillment URL 143 */ 144 extern char *SH_fulfillment_url; 145 146 /** 147 * Our context for making HTTP requests. 148 */ 149 extern struct GNUNET_CURL_Context *SH_ctx; 150 151 /** 152 * Amount of insurance. 153 */ 154 extern struct TALER_Amount SH_insurance; 155 156 /** 157 * Kick MHD to run now, to be called after MHD_resume_connection(). 158 * Basically, we need to explicitly resume MHD's event loop whenever 159 * we made progress serving a request. This function re-schedules 160 * the task processing MHD's activities to run immediately. 161 */ 162 void 163 SH_trigger_daemon (void); 164 165 166 /** 167 * Kick GNUnet Curl scheduler to begin curl interactions. 168 */ 169 void 170 SH_trigger_curl (void); 171 172 173 #endif