taler-exchange-httpd.h (8775B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2014-2022 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU Affero 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 Affero General Public License for more details. 12 13 You should have received a copy of the GNU Affero General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file taler-exchange-httpd.h 18 * @brief Global declarations for the exchange 19 * @author Florian Dold 20 * @author Benedikt Mueller 21 * @author Christian Grothoff 22 */ 23 #ifndef TALER_EXCHANGE_HTTPD_H 24 #define TALER_EXCHANGE_HTTPD_H 25 26 #include <microhttpd.h> 27 #include "taler/taler_json_lib.h" 28 #include "taler/taler_util.h" 29 #include "taler/taler_kyclogic_plugin.h" 30 #include <gnunet/gnunet_mhd_compat.h> 31 #include "exchangedb_lib.h" 32 33 34 /** 35 * How long is caching /keys allowed at most? 36 */ 37 extern struct GNUNET_TIME_Relative TEH_max_keys_caching; 38 39 /** 40 * How long is the delay before we close reserves? 41 */ 42 extern struct GNUNET_TIME_Relative TEH_reserve_closing_delay; 43 44 /** 45 * How long should P2P push payments be valid for by default. 46 */ 47 extern struct GNUNET_TIME_Relative TEH_default_p2p_expiration; 48 49 /** 50 * How long do we allow AML programs to run? 51 */ 52 extern struct GNUNET_TIME_Relative TEH_aml_program_timeout; 53 54 /** 55 * The exchange's configuration. 56 */ 57 extern const struct GNUNET_CONFIGURATION_Handle *TEH_cfg; 58 59 /** 60 * Main directory with exchange data. 61 */ 62 extern char *TEH_exchange_directory; 63 64 /** 65 * -I command-line flag given? 66 */ 67 extern int TEH_check_invariants_flag; 68 69 /** 70 * Are clients allowed to request /keys for times other than the 71 * current time? Allowing this could be abused in a DoS-attack 72 * as building new /keys responses is expensive. Should only be 73 * enabled for testcases, development and test systems. 74 */ 75 extern int TEH_allow_keys_timetravel; 76 77 /** 78 * Option set to #GNUNET_YES if KYC/AML are enabled. 79 */ 80 extern int TEH_enable_kyc; 81 82 /** 83 * Option set to #GNUNET_YES to disable direct deposits. 84 */ 85 extern int TEH_disable_direct_deposit; 86 87 /** 88 * Option set to #GNUNET_YES to signal to the merchant 89 * backend that it should swap the terms-of-service and 90 * KYC auth authentication steps in the user experience. 91 */ 92 extern int TEH_kyc_swap_tos_acceptance; 93 94 /** 95 * Main directory with revocation data. 96 */ 97 extern char *TEH_revocation_directory; 98 99 /** 100 * True if we should commit suicide once all active 101 * connections are finished. Also forces /keys requests 102 * to terminate if they are long-polling. 103 */ 104 extern bool TEH_suicide; 105 106 /** 107 * Master public key (according to the 108 * configuration in the exchange directory). 109 */ 110 extern struct TALER_MasterPublicKeyP TEH_master_public_key; 111 112 /** 113 * Key used to encrypt KYC attribute data in our database. 114 */ 115 extern struct TALER_AttributeEncryptionKeyP TEH_attribute_key; 116 117 /** 118 * Our DB plugin. 119 */ 120 extern struct TALER_EXCHANGEDB_PostgresContext *TEH_pg; 121 122 /** 123 * Allows banks to select a custom UI/UX for certain bank-specific 124 * wallet functions, such as specific texts for buttons based on 125 * legal requirements. 126 */ 127 extern char *TEH_bank_compliance_language; 128 129 /** 130 * Determines the set of AML forms (and other bank-specific settings) 131 * to be selected for the AML SPA. 132 * legal requirements. 133 */ 134 extern char *TEH_aml_spa_dialect; 135 136 /** 137 * JSON array with hard limits for /keys response. 138 */ 139 extern json_t *TEH_hard_limits; 140 141 /** 142 * JSON array with zero limits for /keys response. 143 */ 144 extern json_t *TEH_zero_limits; 145 146 /** 147 * Absolute STEFAN parameter. 148 */ 149 extern struct TALER_Amount TEH_stefan_abs; 150 151 /** 152 * Logarithmic STEFAN parameter. 153 */ 154 extern struct TALER_Amount TEH_stefan_log; 155 156 /** 157 * Smallest amount that can be transferred. Used for the 158 * KYC auth transfers by default. 159 */ 160 extern struct TALER_Amount TEH_tiny_amount; 161 162 /** 163 * ETag of the terms of service we are currently using. 164 */ 165 extern char *TEH_tos_etag; 166 167 /** 168 * URL where users can discover shops accepting digital cash 169 * issued by this exchange. Can be NULL. 170 */ 171 extern char *TEH_shopping_url; 172 173 /** 174 * Absolute directory path where the aml SPA data is located. 175 * 176 * Can be NULL. 177 */ 178 extern char *TEH_aml_spa_dir; 179 180 /** 181 * Absolute directory path where the aml SPA data is located. 182 * 183 * Can be NULL. 184 */ 185 extern char *TEH_kyc_spa_dir; 186 187 /** 188 * Linear STEFAN parameter. 189 */ 190 extern float TEH_stefan_lin; 191 192 /** 193 * Default ways how to render #TEH_currency amounts. 194 */ 195 extern const struct TALER_CurrencySpecification *TEH_cspec; 196 197 /** 198 * Form data to inject into any Typst form generation. 199 */ 200 extern json_t *TEH_global_pdf_form_data; 201 202 /** 203 * Our currency. 204 */ 205 extern char *TEH_currency; 206 207 /** 208 * Our (externally visible) base URL. 209 */ 210 extern char *TEH_base_url; 211 212 /** 213 * Are we shutting down? 214 */ 215 extern volatile bool MHD_terminating; 216 217 /** 218 * Context for all CURL operations (useful to the event loop) 219 */ 220 extern struct GNUNET_CURL_Context *TEH_curl_ctx; 221 222 /** 223 * @brief Struct describing an URL and the handler for it. 224 */ 225 struct TEH_RequestHandler; 226 227 228 /** 229 * @brief Context in which the exchange is processing 230 * all requests 231 */ 232 struct TEH_RequestContext 233 { 234 235 /** 236 * Async Scope ID associated with this request. 237 */ 238 struct GNUNET_AsyncScopeId async_scope_id; 239 240 /** 241 * When was this request started? 242 */ 243 struct GNUNET_TIME_Absolute start_time; 244 245 /** 246 * Opaque parsing context. 247 */ 248 void *opaque_post_parsing_context; 249 250 /** 251 * Request handler responsible for this request. 252 */ 253 const struct TEH_RequestHandler *rh; 254 255 /** 256 * Request URL (for logging). 257 */ 258 const char *url; 259 260 /** 261 * Connection we are processing. 262 */ 263 struct MHD_Connection *connection; 264 265 /** 266 * JSON root of uploaded data (or NULL, if none). 267 */ 268 json_t *root; 269 270 /** 271 * @e rh-specific cleanup routine. Function called 272 * upon completion of the request that should 273 * clean up @a rh_ctx. Can be NULL. 274 */ 275 void 276 (*rh_cleaner)(struct TEH_RequestContext *rc); 277 278 /** 279 * @e rh-specific context. Place where the request 280 * handler can associate state with this request. 281 * Can be NULL. 282 */ 283 void *rh_ctx; 284 }; 285 286 287 /** 288 * @brief Struct describing an URL and the handler for it. 289 */ 290 struct TEH_RequestHandler 291 { 292 293 /** 294 * URL the handler is for (first part only). 295 */ 296 const char *url; 297 298 /** 299 * Method the handler is for. 300 */ 301 const char *method; 302 303 /** 304 * Callbacks for handling of the request. Which one is used 305 * depends on @e method. 306 */ 307 union 308 { 309 /** 310 * Function to call to handle GET requests (and those 311 * with @e method NULL). 312 * 313 * @param rc context for the request 314 * @param args array of arguments, needs to be of length @e args_expected 315 * @return MHD result code 316 */ 317 enum MHD_Result 318 (*get)(struct TEH_RequestContext *rc, 319 const char *const args[]); 320 321 322 /** 323 * Function to call to handle POST requests. 324 * 325 * @param rc context for the request 326 * @param json uploaded JSON data 327 * @param args array of arguments, needs to be of length @e nargs 328 * @return MHD result code 329 */ 330 enum MHD_Result 331 (*post)(struct TEH_RequestContext *rc, 332 const json_t *root, 333 const char *const args[]); 334 335 /** 336 * Function to call to handle DELETE requests. 337 * 338 * @param rc context for the request 339 * @param args array of arguments, needs to be of length @e nargs 340 * @return MHD result code 341 */ 342 enum MHD_Result 343 (*delete)(struct TEH_RequestContext *rc, 344 const char *const args[]); 345 346 } handler; 347 348 /** 349 * Mime type to use in reply (hint, can be NULL). 350 */ 351 const char *mime_type; 352 353 /** 354 * Raw data for the @e handler, can be NULL for none provided. 355 */ 356 const void *data; 357 358 /** 359 * Number of bytes in @e data, 0 for data is 0-terminated (!). 360 */ 361 size_t data_size; 362 363 /** 364 * Default response code. 0 for none provided. 365 */ 366 unsigned int response_code; 367 368 /** 369 * Number of arguments this handler expects in the @a args array. 370 */ 371 unsigned int nargs; 372 373 /** 374 * Is the number of arguments given in @e nargs only an upper bound, 375 * and calling with fewer arguments could be OK? 376 */ 377 bool nargs_is_upper_bound; 378 379 }; 380 381 382 /** 383 * Is age restriction enabled on this exchange? 384 */ 385 extern bool TEH_age_restriction_enabled; 386 387 /** 388 * Age mask for the exchange; all age-restricted denominations use this mask. 389 * Only meaningful when @e TEH_age_restriction_enabled is true. 390 */ 391 extern struct TALER_AgeMask TEH_age_restriction_mask; 392 393 #endif