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_get-monitoring-reserve-not-closed-inconsistency.c (4722B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2024 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 #include <gnunet/gnunet_util_lib.h>
     17 #include <gnunet/gnunet_json_lib.h>
     18 #include <jansson.h>
     19 #include <microhttpd.h>
     20 #include <pthread.h>
     21 #include "taler/taler_json_lib.h"
     22 #include "taler/taler_mhd_lib.h"
     23 #include "taler-auditor-httpd.h"
     24 #include "taler-auditor-httpd_get-monitoring-reserve-not-closed-inconsistency.h"
     25 #define TALER_AUDITORDB_RESERVE_NOT_CLOSED_INCONSISTENCY_RESULT_CLOSURE json_t
     26 #include "auditor-database/iterate_reserve_not_closed_inconsistencies.h"
     27 #include "auditor-database/preflight.h"
     28 
     29 
     30 /**
     31  * Add reserve-not-closed-inconsistency to the list.
     32  *
     33  * @param[in,out] list a `json_t *` array to extend
     34  * @param dc struct of inconsistencies
     35  * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
     36  */
     37 static enum GNUNET_GenericReturnValue
     38 process_reserve_not_closed_inconsistency (
     39   json_t *list,
     40   const struct TALER_AUDITORDB_ReserveNotClosedInconsistency *dc)
     41 {
     42   json_t *obj;
     43 
     44   obj = GNUNET_JSON_PACK (
     45     GNUNET_JSON_pack_uint64 ("row_id",
     46                              dc->row_id),
     47     GNUNET_JSON_pack_data_auto ("reserve_pub",
     48                                 &dc->reserve_pub),
     49     TALER_JSON_pack_amount ("balance",
     50                             &dc->balance),
     51     TALER_JSON_pack_time_abs_human ("expiration_time",
     52                                     dc->expiration_time),
     53     GNUNET_JSON_pack_allow_null (
     54       GNUNET_JSON_pack_string ("diagnostic",
     55                                dc->diagnostic)),
     56     GNUNET_JSON_pack_bool ("suppressed",
     57                            dc->suppressed)
     58     );
     59   GNUNET_break (0 ==
     60                 json_array_append_new (list,
     61                                        obj));
     62   return GNUNET_OK;
     63 }
     64 
     65 
     66 enum MHD_Result
     67 TAH_get_monitoring_reserve_not_closed_inconsistency (
     68   struct TAH_RequestHandler *rh,
     69   struct MHD_Connection *connection,
     70   void **connection_cls,
     71   const char *upload_data,
     72   size_t *upload_data_size,
     73   const char *const args[])
     74 {
     75   json_t *ja;
     76   enum GNUNET_DB_QueryStatus qs;
     77   int64_t limit = -20;
     78   uint64_t offset;
     79   bool return_suppressed = false;
     80 
     81   (void) rh;
     82   (void) connection_cls;
     83   (void) upload_data;
     84   (void) upload_data_size;
     85   if (GNUNET_SYSERR ==
     86       TALER_AUDITORDB_preflight (TAH_apg))
     87   {
     88     GNUNET_break (0);
     89     return TALER_MHD_reply_with_error (connection,
     90                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     91                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
     92                                        NULL);
     93   }
     94   TALER_MHD_parse_request_snumber (connection,
     95                                    "limit",
     96                                    &limit);
     97   if (limit < 0)
     98     offset = INT64_MAX;
     99   else
    100     offset = 0;
    101   TALER_MHD_parse_request_number (connection,
    102                                   "offset",
    103                                   &offset);
    104   {
    105     const char *ret_s
    106       = MHD_lookup_connection_value (connection,
    107                                      MHD_GET_ARGUMENT_KIND,
    108                                      "return_suppressed");
    109     if ( (NULL != ret_s) &&
    110          (0 == strcmp (ret_s,
    111                        "true")) )
    112     {
    113       return_suppressed = true;
    114     }
    115   }
    116 
    117   ja = json_array ();
    118   GNUNET_break (NULL != ja);
    119   qs = TALER_AUDITORDB_iterate_reserve_not_closed_inconsistencies (
    120     TAH_apg,
    121     limit,
    122     offset,
    123     return_suppressed,
    124     &process_reserve_not_closed_inconsistency,
    125     ja);
    126   if (0 > qs)
    127   {
    128     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
    129     json_decref (ja);
    130     TALER_LOG_WARNING (
    131       "Failed to handle GET /reserve-not-closed-inconsistency");
    132     return TALER_MHD_reply_with_error (connection,
    133                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
    134                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
    135                                        "reserve-not-closed-inconsistency");
    136   }
    137   return TALER_MHD_REPLY_JSON_PACK (
    138     connection,
    139     MHD_HTTP_OK,
    140     GNUNET_JSON_pack_array_steal ("reserve_not_closed_inconsistency",
    141                                   ja));
    142 }