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-row-inconsistency.c (4257B)


      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-row-inconsistency.h"
     25 #include "auditor-database/get_row_inconsistency.h"
     26 #include "auditor-database/preflight.h"
     27 
     28 
     29 /**
     30  * Add deposit confirmation to the list.
     31  *
     32  * @param[in,out] cls a `json_t *` array to extend
     33  * @param serial_id location of the @a dc in the database
     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 add_row_inconsistency (
     39   void *cls,
     40   uint64_t serial_id,
     41   const struct TALER_AUDITORDB_RowInconsistency *dc)
     42 {
     43   json_t *list = cls;
     44   json_t *obj;
     45 
     46   obj = GNUNET_JSON_PACK (
     47 
     48     GNUNET_JSON_pack_int64 ("row_id", serial_id),
     49 
     50     GNUNET_JSON_pack_string ("row_table",
     51                              dc->row_table),
     52     GNUNET_JSON_pack_string ("diagnostic",
     53                              dc->diagnostic),
     54     GNUNET_JSON_pack_bool ("suppressed", dc->suppressed)
     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_row_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 = MHD_lookup_connection_value (connection,
    103                                                      MHD_GET_ARGUMENT_KIND,
    104                                                      "return_suppressed");
    105     if (ret_s != NULL && strcmp (ret_s, "true") == 0)
    106     {
    107       return_suppressed = true;
    108     }
    109   }
    110 
    111   ja = json_array ();
    112   GNUNET_break (NULL != ja);
    113   qs = TALER_AUDITORDB_get_row_inconsistency (
    114     TAH_apg,
    115     limit,
    116     offset,
    117     return_suppressed,
    118     &add_row_inconsistency,
    119     ja);
    120   if (0 > qs)
    121   {
    122     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
    123     json_decref (ja);
    124     TALER_LOG_WARNING (
    125       "Failed to handle GET /row-inconsistency in database\n");
    126     return TALER_MHD_reply_with_error (connection,
    127                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
    128                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
    129                                        "row-inconsistency");
    130   }
    131   return TALER_MHD_REPLY_JSON_PACK (
    132     connection,
    133     MHD_HTTP_OK,
    134     GNUNET_JSON_pack_array_steal ("row_inconsistency",
    135                                   ja));
    136 }