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-fee-time-inconsistency.c (4347B)


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