challenger-httpd.h (5033B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2023 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 challenger/challenger-httpd.h 18 * @brief OAuth 2.0 address validation server 19 * @author Christian Grothoff 20 */ 21 #ifndef challenger_HTTPD_H 22 #define challenger_HTTPD_H 23 24 #include "platform.h" 25 #include <microhttpd.h> 26 #include <taler/taler_mhd_lib.h> 27 #include "challenger_database_lib.h" 28 #include "challenger_util.h" 29 #include <gnunet/gnunet_mhd_compat.h> 30 31 32 /** 33 * @brief Struct describing an URL and the handler for it. 34 */ 35 struct CH_RequestHandler; 36 37 /** 38 * Signature of a function used to clean up the context 39 * of this handler. 40 * 41 * @param cls closure to clean up. 42 */ 43 typedef void 44 (*CH_ContextCleanup)(void *cls); 45 46 47 /** 48 * Each MHD response handler that sets the "connection_cls" to a 49 * non-NULL value must use a struct that has this struct as its first 50 * member. This struct contains a single callback, which will be 51 * invoked to clean up the memory when the connection is completed. 52 */ 53 struct CH_HandlerContext 54 { 55 56 /** 57 * Function to execute the handler-specific cleanup of the 58 * (typically larger) context. 59 */ 60 CH_ContextCleanup cc; 61 62 /** 63 * Handler-specific context, will be passed to @e cc 64 * upon completion. 65 */ 66 void *ctx; 67 68 /** 69 * Connection being processed. 70 */ 71 struct MHD_Connection *connection; 72 73 /** 74 * remaining URL path 75 */ 76 const char *path; 77 78 /** 79 * Copy of our original full URL with query parameters. 80 */ 81 char *full_url; 82 83 /** 84 * Request handler for this request. 85 */ 86 const struct CH_RequestHandler *rh; 87 88 /** 89 * Asynchronous request context id. 90 */ 91 struct GNUNET_AsyncScopeId async_scope_id; 92 93 }; 94 95 96 /** 97 * @brief Struct describing an URL and the handler for it. 98 */ 99 struct CH_RequestHandler 100 { 101 102 /** 103 * URL the handler is for. End with a '/' to make 104 * this only a prefix to match. However, "/" will 105 * only match "/" and not be treated as a prefix. 106 */ 107 const char *url; 108 109 /** 110 * HTTP method the handler is for. 111 */ 112 const char *method; 113 114 /** 115 * Function to call to handle the request. 116 * 117 * @param hc handler context 118 * @param upload_data upload data 119 * @param[in,out] upload_data_size number of bytes (left) in @a upload_data 120 * @return MHD result code 121 */ 122 enum MHD_Result (*handler)(struct CH_HandlerContext *hc, 123 const char *upload_data, 124 size_t *upload_data_size); 125 126 }; 127 128 129 /** 130 * Handle to the database backend. 131 */ 132 extern struct CHALLENGERDB_PostgresContext *CH_context; 133 134 /** 135 * Our context for making HTTP requests. 136 */ 137 extern struct GNUNET_CURL_Context *CH_ctx; 138 139 /** 140 * Helper command to run for transmission of 141 * challenge values. 142 */ 143 extern char *CH_auth_command; 144 145 /** 146 * Type of addresses this challenger validates. 147 */ 148 extern char *CH_address_type; 149 150 /** 151 * Hint to show to users on what address to enter. 152 */ 153 extern char *CH_address_hint; 154 155 /** 156 * (external) base URL of this service. 157 */ 158 extern char *CH_base_url; 159 160 /** 161 * Mustach template for the letter to send. 162 * WARNING: not 0-terminated! Allocated via mmap(), free with munmap()! 163 */ 164 extern void *CH_message_template; 165 166 /** 167 * Number of bytes in #CH_message_template 168 */ 169 extern size_t CH_message_template_len; 170 171 /** 172 * How long is an individual validation request valid? 173 */ 174 extern struct GNUNET_TIME_Relative CH_validation_duration; 175 176 /** 177 * How long validated data considered to be valid? 178 */ 179 extern struct GNUNET_TIME_Relative CH_validation_expiration; 180 181 /** 182 * How often do we retransmit the challenge. 183 */ 184 extern struct GNUNET_TIME_Relative CH_pin_retransmission_frequency; 185 186 /** 187 * JSON object with key-object pairs mapping address keys (from the 188 * form) to an object with a field "regex" containing a regular 189 * expressions expressing restrictions on values for the address and a 190 * field "hint" (and possibly "hint_i18n") containing a human-readable 191 * message explaining the restriction. Missing map entries indicate 192 * that the input is unrestricted. 193 */ 194 extern json_t *CH_restrictions; 195 196 /** 197 * Kick MHD to run now, to be called after MHD_resume_connection(). 198 * Basically, we need to explicitly resume MHD's event loop whenever 199 * we made progress serving a request. This function re-schedules 200 * the task processing MHD's activities to run immediately. 201 */ 202 void 203 CH_trigger_daemon (void); 204 205 206 /** 207 * Kick GNUnet Curl scheduler to begin curl interactions. 208 */ 209 void 210 CH_trigger_curl (void); 211 212 213 #endif