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-denomination-key-validity-withdraw-inconsistency.c (4819B)


      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 \
     25   "taler-auditor-httpd_get-monitoring-denomination-key-validity-withdraw-inconsistency.h"
     26 #define \
     27         TALER_AUDITORDB_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_RESULT_CLOSURE \
     28         json_t
     29 #include \
     30   "auditor-database/get_denomination_key_validity_withdraw_inconsistency.h"
     31 #include "auditor-database/preflight.h"
     32 
     33 /**
     34  * Add denomination-key-validity-withdraw-inconsistency to the list.
     35  *
     36  * @param[in,out] list a `json_t *` array to extend
     37  * @param dc struct of inconsistencies
     38  * @return #GNUNET_OK to continue to iterate
     39  */
     40 static enum GNUNET_GenericReturnValue
     41 process_denomination_key_validity_withdraw_inconsistency (
     42   json_t *list,
     43   const struct TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency *dc)
     44 {
     45   json_t *obj;
     46 
     47   obj = GNUNET_JSON_PACK (
     48     GNUNET_JSON_pack_uint64 ("row_id",
     49                              dc->row_id),
     50     GNUNET_JSON_pack_uint64 ("problem_row_id",
     51                              dc->problem_row_id),
     52     TALER_JSON_pack_time_abs_human ("execution_date",
     53                                     dc->execution_date),
     54     GNUNET_JSON_pack_data_auto ("reserve_pub",
     55                                 &dc->reserve_pub),
     56     GNUNET_JSON_pack_data_auto ("denompub_h",
     57                                 &dc->denompub_h),
     58     GNUNET_JSON_pack_bool ("suppressed",
     59                            dc->suppressed)
     60     );
     61   GNUNET_break (0 ==
     62                 json_array_append_new (list,
     63                                        obj));
     64 
     65 
     66   return GNUNET_OK;
     67 }
     68 
     69 
     70 enum MHD_Result
     71 TAH_get_monitoring_denomination_key_validity_withdraw_inconsistency (
     72   struct TAH_RequestHandler *rh,
     73   struct MHD_Connection *connection,
     74   void **connection_cls,
     75   const char *upload_data,
     76   size_t *upload_data_size,
     77   const char *const args[])
     78 {
     79   json_t *ja;
     80   enum GNUNET_DB_QueryStatus qs;
     81   int64_t limit = -20;
     82   uint64_t offset;
     83   bool return_suppressed = false;
     84 
     85   (void) rh;
     86   (void) connection_cls;
     87   (void) upload_data;
     88   (void) upload_data_size;
     89   if (GNUNET_SYSERR ==
     90       TALER_AUDITORDB_preflight (TAH_apg))
     91   {
     92     GNUNET_break (0);
     93     return TALER_MHD_reply_with_error (connection,
     94                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     95                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
     96                                        NULL);
     97   }
     98   TALER_MHD_parse_request_snumber (connection,
     99                                    "limit",
    100                                    &limit);
    101   if (limit < 0)
    102     offset = INT64_MAX;
    103   else
    104     offset = 0;
    105   TALER_MHD_parse_request_number (connection,
    106                                   "offset",
    107                                   &offset);
    108   {
    109     const char *ret_s
    110       = MHD_lookup_connection_value (connection,
    111                                      MHD_GET_ARGUMENT_KIND,
    112                                      "return_suppressed");
    113     if (ret_s != NULL && strcmp (ret_s, "true") == 0)
    114     {
    115       return_suppressed = true;
    116     }
    117   }
    118   ja = json_array ();
    119   GNUNET_break (NULL != ja);
    120   qs = TALER_AUDITORDB_get_denomination_key_validity_withdraw_inconsistency (
    121     TAH_apg,
    122     limit,
    123     offset,
    124     return_suppressed,
    125     &process_denomination_key_validity_withdraw_inconsistency,
    126     ja);
    127   if (0 > qs)
    128   {
    129     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
    130     json_decref (ja);
    131     TALER_LOG_WARNING (
    132       "Failed to handle GET /denomination-key-validity-withdraw-inconsistency\n");
    133     return TALER_MHD_reply_with_error (connection,
    134                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
    135                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
    136                                        "denomination-key-validity-withdraw-inconsistency");
    137   }
    138   return TALER_MHD_REPLY_JSON_PACK (
    139     connection,
    140     MHD_HTTP_OK,
    141     GNUNET_JSON_pack_array_steal (
    142       "denomination_key_validity_withdraw_inconsistency",
    143       ja));
    144 }