anastasis

Credential backup and recovery protocol and service
Log | Files | Refs | Submodules | README | LICENSE

anastasis-httpd.h (5039B)


      1 /*
      2   This file is part of Anastasis
      3   Copyright (C) 2019 Anastasis SARL
      4 
      5   Anastasis 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   Anastasis 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   Anastasis; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file backend/anastasis-httpd.h
     18  * @brief HTTP serving layer
     19  * @author Christian Grothoff
     20  */
     21 #ifndef ANASTASIS_HTTPD_H
     22 #define ANASTASIS_HTTPD_H
     23 
     24 #include "platform.h"
     25 #include "anastasis_database_lib.h"
     26 #include <microhttpd.h>
     27 #include <taler/taler_mhd_lib.h>
     28 #include <gnunet/gnunet_mhd_compat.h>
     29 
     30 
     31 /**
     32  * For how many years do we allow users to store truth at most? Also
     33  * how long we store things if the cost is zero.
     34  */
     35 #define ANASTASIS_MAX_YEARS_STORAGE 5
     36 
     37 
     38 /**
     39  * @brief Struct describing an URL and the handler for it.
     40  */
     41 struct AH_RequestHandler
     42 {
     43 
     44   /**
     45    * URL the handler is for.
     46    */
     47   const char *url;
     48 
     49   /**
     50    * Method the handler is for, NULL for "all".
     51    */
     52   const char *method;
     53 
     54   /**
     55    * Mime type to use in reply (hint, can be NULL).
     56    */
     57   const char *mime_type;
     58 
     59   /**
     60    * Raw data for the @e handler
     61    */
     62   const void *data;
     63 
     64   /**
     65    * Number of bytes in @e data, 0 for 0-terminated.
     66    */
     67   size_t data_size;
     68 
     69 
     70   /**
     71    * Function to call to handle the request.
     72    *
     73    * @param rh this struct
     74    * @param connection the MHD connection to handle
     75    * @return MHD result code
     76    */
     77   MHD_RESULT (*handler)(struct AH_RequestHandler *rh,
     78                         struct MHD_Connection *connection);
     79 
     80   /**
     81    * Default response code.
     82    */
     83   unsigned int response_code;
     84 };
     85 
     86 
     87 /**
     88  * Each MHD response handler that sets the "connection_cls" to a
     89  * non-NULL value must use a struct that has this struct as its first
     90  * member.  This struct contains a single callback, which will be
     91  * invoked to clean up the memory when the contection is completed.
     92  */
     93 struct TM_HandlerContext;
     94 
     95 /**
     96  * Signature of a function used to clean up the context
     97  * we keep in the "connection_cls" of MHD when handling
     98  * a request.
     99  *
    100  * @param hc header of the context to clean up.
    101  */
    102 typedef void
    103 (*TM_ContextCleanup)(struct TM_HandlerContext *hc);
    104 
    105 
    106 /**
    107  * Each MHD response handler that sets the "connection_cls" to a
    108  * non-NULL value must use a struct that has this struct as its first
    109  * member.  This struct contains a single callback, which will be
    110  * invoked to clean up the memory when the connection is completed.
    111  */
    112 struct TM_HandlerContext
    113 {
    114 
    115   /**
    116    * Function to execute the handler-specific cleanup of the
    117    * (typically larger) context.
    118    */
    119   TM_ContextCleanup cc;
    120 
    121   /**
    122    * Handler-specific context.
    123    */
    124   void *ctx;
    125 
    126   /**
    127    * Which request handler is handling this request?
    128    */
    129   const struct AH_RequestHandler *rh;
    130 
    131   /**
    132    * URL requested by the client, for logging.
    133    */
    134   const char *url;
    135 
    136   /**
    137    * Asynchronous request context id.
    138    */
    139   struct GNUNET_AsyncScopeId async_scope_id;
    140 };
    141 
    142 /**
    143  * Handle to the database backend.
    144  */
    145 extern struct ANASTASIS_DatabasePlugin *db;
    146 
    147 /**
    148  * Upload limit to the service, in megabytes.
    149  */
    150 extern unsigned long long AH_upload_limit_mb;
    151 
    152 /**
    153  * Annual fee for the backup account.
    154  */
    155 extern struct TALER_Amount AH_annual_fee;
    156 
    157 /**
    158  * Fee for a truth upload.
    159  */
    160 extern struct TALER_Amount AH_truth_upload_fee;
    161 
    162 /**
    163  * Amount of insurance.
    164  */
    165 extern struct TALER_Amount AH_insurance;
    166 
    167 /**
    168  * Cost for secure question truth download.
    169  */
    170 extern struct TALER_Amount AH_question_cost;
    171 
    172 /**
    173  * Our Taler backend to process payments.
    174  */
    175 extern char *AH_backend_url;
    176 
    177 /**
    178  * Heap for processing timeouts of requests.
    179  */
    180 extern struct GNUNET_CONTAINER_Heap *AH_to_heap;
    181 
    182 /**
    183  * Our configuration.
    184  */
    185 extern const struct GNUNET_CONFIGURATION_Handle *AH_cfg;
    186 
    187 /**
    188  * Number of policy uploads permitted per annual fee payment.
    189  */
    190 extern unsigned long long AH_post_counter;
    191 
    192 /**
    193  * Our fulfillment URL
    194  */
    195 extern char *AH_fulfillment_url;
    196 
    197 /**
    198  * Our business name.
    199  */
    200 extern char *AH_business_name;
    201 
    202 /**
    203  * Our provider salt.
    204  */
    205 extern struct ANASTASIS_CRYPTO_ProviderSaltP AH_provider_salt;
    206 
    207 /**
    208  * Our context for making HTTP requests.
    209  */
    210 extern struct GNUNET_CURL_Context *AH_ctx;
    211 
    212 
    213 /**
    214  * Kick MHD to run now, to be called after MHD_resume_connection().
    215  * Basically, we need to explicitly resume MHD's event loop whenever
    216  * we made progress serving a request.  This function re-schedules
    217  * the task processing MHD's activities to run immediately.
    218  *
    219  * @param cls NULL
    220  */
    221 void
    222 AH_trigger_daemon (void *cls);
    223 
    224 /**
    225  * Kick GNUnet Curl scheduler to begin curl interactions.
    226  */
    227 void
    228 AH_trigger_curl (void);
    229 
    230 #endif