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 (4802B)


      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/iterate_denomination_key_validity_withdraw_inconsistencies.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     GNUNET_JSON_pack_timestamp ("execution_date",
     53                                 GNUNET_TIME_absolute_to_timestamp (
     54                                   dc->execution_date)),
     55     GNUNET_JSON_pack_data_auto ("reserve_pub",
     56                                 &dc->reserve_pub),
     57     GNUNET_JSON_pack_data_auto ("h_denom_pub",
     58                                 &dc->denompub_h),
     59     GNUNET_JSON_pack_bool ("suppressed",
     60                            dc->suppressed)
     61     );
     62   GNUNET_break (0 ==
     63                 json_array_append_new (list,
     64                                        obj));
     65 
     66 
     67   return GNUNET_OK;
     68 }
     69 
     70 
     71 enum MHD_Result
     72 TAH_get_monitoring_denomination_key_validity_withdraw_inconsistency (
     73   struct TAH_RequestHandler *rh,
     74   struct MHD_Connection *connection,
     75   void **connection_cls,
     76   const char *upload_data,
     77   size_t *upload_data_size,
     78   const char *const args[])
     79 {
     80   json_t *ja;
     81   enum GNUNET_DB_QueryStatus qs;
     82   int64_t limit = -20;
     83   uint64_t offset;
     84   bool return_suppressed = false;
     85 
     86   (void) rh;
     87   (void) connection_cls;
     88   (void) upload_data;
     89   (void) upload_data_size;
     90   if (GNUNET_SYSERR ==
     91       TALER_AUDITORDB_preflight (TAH_apg))
     92   {
     93     GNUNET_break (0);
     94     return TALER_MHD_reply_with_error (connection,
     95                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     96                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
     97                                        NULL);
     98   }
     99   TAH_PARSE_REQUEST_LIMIT (connection,
    100                            "limit",
    101                            &limit);
    102   if (limit < 0)
    103     offset = TAH_SAFE_UINT64_MAX;
    104   else
    105     offset = 0;
    106   TAH_PARSE_SAFE_REQUEST_NUMBER (connection,
    107                                  "offset",
    108                                  &offset);
    109   {
    110     const char *ret_s
    111       = MHD_lookup_connection_value (connection,
    112                                      MHD_GET_ARGUMENT_KIND,
    113                                      "return_suppressed");
    114     if (ret_s != NULL && strcmp (ret_s, "true") == 0)
    115     {
    116       return_suppressed = true;
    117     }
    118   }
    119   ja = json_array ();
    120   GNUNET_break (NULL != ja);
    121   qs =
    122     TALER_AUDITORDB_iterate_denomination_key_validity_withdraw_inconsistencies (
    123       TAH_apg,
    124       limit,
    125       offset,
    126       return_suppressed,
    127       &process_denomination_key_validity_withdraw_inconsistency,
    128       ja);
    129   if (0 > qs)
    130   {
    131     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
    132     json_decref (ja);
    133     TALER_LOG_WARNING (
    134       "Failed to handle GET /denomination-key-validity-withdraw-inconsistency\n");
    135     return TALER_MHD_reply_with_error (connection,
    136                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
    137                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
    138                                        "denomination-key-validity-withdraw-inconsistency");
    139   }
    140   return TAH_reply_json_records (connection,
    141                                  ja);
    142 }