frosix

Multiparty signature service (experimental)
Log | Files | Refs | README | LICENSE

frosix-httpd.h (5042B)


      1 /*
      2   This file is part of Frosix
      3   Copyright (C) 2019 Anastasis SARL
      4 
      5   Frosix 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   Frosix 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   Frosix; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file backend/frosix-httpd.h
     18  * @brief HTTP serving layer
     19  * @author Christian Grothoff
     20  */
     21 #ifndef FROSIX_HTTPD_H
     22 #define FROSIX_HTTPD_H
     23 
     24 #include "platform.h"
     25 #include "frost_high.h"
     26 #include "frosix_backend.h"
     27 #include <microhttpd.h>
     28 #include <taler/taler_mhd_lib.h>
     29 #include <gnunet/gnunet_mhd_compat.h>
     30 #include <gnunet/gnunet_util_lib.h>
     31 
     32 /**
     33  * For how many years do we allow users to store truth at most? Also
     34  * how long we store things if the cost is zero.
     35  */
     36 #define FROSIX_MAX_YEARS_STORAGE 5
     37 
     38 /**
     39  * @brief Struct describing an URL and the handler for it.
     40  */
     41 struct FH_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 FH_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 FH_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 FROSIX_DatabasePlugin *db;
    146 
    147 
    148 /**
    149  * Annual fee for the backup account.
    150  */
    151 extern struct TALER_Amount FH_annual_fee;
    152 
    153 /**
    154  * Fee for a truth upload.
    155  */
    156 extern struct TALER_Amount FH_signature_creation_fee;
    157 
    158 /**
    159  * Amount of insurance.
    160  */
    161 extern struct TALER_Amount FH_insurance;
    162 
    163 /**
    164  * Cost for secure question truth download.
    165  */
    166 extern struct TALER_Amount FH_question_cost;
    167 
    168 /**
    169  * Our Taler backend to process payments.
    170  */
    171 extern char *FH_backend_url;
    172 
    173 /**
    174  * Heap for processing timeouts of requests.
    175  */
    176 extern struct GNUNET_CONTAINER_Heap *FH_to_heap;
    177 
    178 /**
    179  * Our configuration.
    180  */
    181 extern const struct GNUNET_CONFIGURATION_Handle *FH_cfg;
    182 
    183 /**
    184  * Number of policy uploads permitted per annual fee payment.
    185  */
    186 extern unsigned long long FH_post_counter;
    187 
    188 /**
    189  * Our fulfillment URL
    190  */
    191 extern char *FH_fulfillment_url;
    192 
    193 /**
    194  * Our business name.
    195  */
    196 extern char *FH_business_name;
    197 
    198 /**
    199  * Our provider salt.
    200  */
    201 extern struct FROSIX_ProviderSaltP FH_provider_salt;
    202 
    203 /**
    204  * Our public key
    205 */
    206 extern struct GNUNET_CRYPTO_EddsaPublicKey FH_pub_sig_key;
    207 
    208 /**
    209  * Our context for making HTTP requests.
    210  */
    211 extern struct GNUNET_CURL_Context *FH_ctx;
    212 
    213 
    214 /**
    215  * Kick MHD to run now, to be called after MHD_resume_connection().
    216  * Basically, we need to explicitly resume MHD's event loop whenever
    217  * we made progress serving a request.  This function re-schedules
    218  * the task processing MHD's activities to run immediately.
    219  *
    220  * @param cls NULL
    221  */
    222 void
    223 FH_trigger_daemon (void *cls);
    224 
    225 /**
    226  * Kick GNUnet Curl scheduler to begin curl interactions.
    227  */
    228 void
    229 FH_trigger_curl (void);
    230 
    231 #endif