exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

taler-auditor-httpd.h (4546B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2014, 2015, 2018 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-auditor-httpd.h
     18  * @brief Global declarations for the auditor
     19  * @author Florian Dold
     20  * @author Benedikt Mueller
     21  * @author Christian Grothoff
     22  */
     23 #ifndef TALER_AUDITOR_HTTPD_H
     24 #define TALER_AUDITOR_HTTPD_H
     25 
     26 #include <jansson.h>
     27 #include <microhttpd.h>
     28 #include "taler/taler_error_codes.h"
     29 #include "taler/taler_mhd_lib.h"
     30 #include "auditordb_lib.h"
     31 #include "exchangedb_lib.h"
     32 
     33 
     34 /**
     35  * Largest integer exactly representable by JSON consumers using IEEE-754.
     36  */
     37 #define TAH_SAFE_UINT64_MAX UINT64_C (9007199254740991)
     38 
     39 
     40 /**
     41  * Parse an optional unsigned request argument as a SafeUint64.
     42  */
     43 #define TAH_PARSE_SAFE_REQUEST_NUMBER(connection,name,off) do { \
     44           TALER_MHD_parse_request_number (connection, name, off); \
     45           if (*(off) > TAH_SAFE_UINT64_MAX) \
     46             return TALER_MHD_reply_with_error ( \
     47               connection, \
     48               MHD_HTTP_BAD_REQUEST, \
     49               TALER_EC_GENERIC_PARAMETER_MALFORMED, \
     50               name); \
     51         } while (0)
     52 
     53 
     54 /**
     55  * Parse the signed, non-zero limit used by row-ID pagination.
     56  */
     57 #define TAH_PARSE_REQUEST_LIMIT(connection,name,limit) do { \
     58           TALER_MHD_parse_request_snumber (connection, name, limit); \
     59           if (0 == *(limit)) \
     60             return TALER_MHD_reply_with_error ( \
     61               connection, \
     62               MHD_HTTP_BAD_REQUEST, \
     63               TALER_EC_GENERIC_PARAMETER_MALFORMED, \
     64               name); \
     65         } while (0)
     66 
     67 
     68 /**
     69  * Our auditor database context.
     70  */
     71 extern struct TALER_AUDITORDB_PostgresContext *TAH_apg;
     72 
     73 /**
     74  * Our exchange database context.
     75  */
     76 extern struct TALER_EXCHANGEDB_PostgresContext *TAH_epg;
     77 
     78 /**
     79  * Exchange master public key (according to the
     80  * configuration).  (global)
     81  */
     82 extern struct TALER_MasterPublicKeyP TAH_master_public_key;
     83 
     84 /**
     85  * Absolute directory path where the auditor SPA data is located.
     86  *
     87  * Can be NULL.
     88  */
     89 extern char *TAH_spa_dir;
     90 
     91 /**
     92  * Our currency.
     93  */
     94 extern char *TAH_currency;
     95 
     96 
     97 /**
     98  * Return a monitoring response after checking that all JSON integers satisfy
     99  * the API's SafeUint64 invariant.  Takes ownership of @a records.
    100  *
    101  * @param connection connection to respond on
    102  * @param records monitoring records to return
    103  * @return MHD result code
    104  */
    105 enum MHD_Result
    106 TAH_reply_json_records (struct MHD_Connection *connection,
    107                         json_t *records);
    108 
    109 /**
    110  * @brief Struct describing an URL and the handler for it.
    111  */
    112 struct TAH_RequestHandler
    113 {
    114 
    115   /**
    116    * URL the handler is for.
    117    */
    118   const char *url;
    119 
    120   /**
    121    * Method the handler is for, NULL for "all".
    122    */
    123   const char *method;
    124 
    125   /**
    126    * Mime type to use in reply (hint, can be NULL).
    127    */
    128   const char *mime_type;
    129 
    130   /**
    131    * Raw data for the @e handler
    132    */
    133   const void *data;
    134 
    135   /**
    136    * Number of bytes in @e data, 0 for 0-terminated.
    137    */
    138   size_t data_size;
    139 
    140   /**
    141    * Function to call to handle the request.
    142    *
    143    * @param rh this struct
    144    * @param connection the MHD connection to handle
    145    * @param[in,out] connection_cls the connection's closure (can be updated)
    146    * @param upload_data upload data
    147    * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
    148    * @param args NULL-terminated array with the '/'-separated segments of the
    149    *        requested URL, including those that are part of @e url
    150    * @return MHD result code
    151    */
    152   enum MHD_Result (*handler)(
    153     /* const */ struct TAH_RequestHandler *rh,
    154     struct MHD_Connection *connection,
    155     void **connection_cls,
    156     const char *upload_data,
    157     size_t *upload_data_size,
    158     const char *const args[]);
    159 
    160   /**
    161    * Default response code.
    162    */
    163   unsigned int response_code;
    164 
    165   /**
    166    * Is client authentication required for this endpoint?
    167    */
    168   bool requires_auth;
    169 
    170   enum TALER_AUDITORDB_DeletableSuppressableTables table;
    171 };
    172 
    173 
    174 #endif