LCOV - code coverage report
Current view: top level - auditor - taler-auditor-httpd_get-monitoring-coin-inconsistency.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 29 0
Test Date: 2026-04-14 15:39:31 Functions: 0.0 % 2 0

            Line data    Source code
       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-coin-inconsistency.h"
      25              : #include "auditor-database/get_coin_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            0 : add_coin_inconsistency (
      39              :   void *cls,
      40              :   uint64_t serial_id,
      41              :   const struct TALER_AUDITORDB_CoinInconsistency *dc)
      42              : {
      43            0 :   json_t *list = cls;
      44              :   json_t *obj;
      45              : 
      46            0 :   obj = GNUNET_JSON_PACK (
      47              :     GNUNET_JSON_pack_string ("operation", dc->operation),
      48              :     TALER_JSON_pack_amount ("exchange_amount", &dc->exchange_amount),
      49              :     TALER_JSON_pack_amount ("auditor_amount", &dc->auditor_amount),
      50              :     GNUNET_JSON_pack_data_auto ("coin_pub",&dc->coin_pub),
      51              :     GNUNET_JSON_pack_bool ("profitable", dc->profitable)
      52              :     );
      53            0 :   GNUNET_break (0 ==
      54              :                 json_array_append_new (list,
      55              :                                        obj));
      56            0 :   return GNUNET_OK;
      57              : }
      58              : 
      59              : 
      60              : MHD_RESULT
      61            0 : TAH_get_monitoring_coin_inconsistency (
      62              :   struct TAH_RequestHandler *rh,
      63              :   struct MHD_Connection *connection,
      64              :   void **connection_cls,
      65              :   const char *upload_data,
      66              :   size_t *upload_data_size,
      67              :   const char *const args[])
      68              : {
      69              :   json_t *ja;
      70              :   enum GNUNET_DB_QueryStatus qs;
      71            0 :   int64_t limit = -20;
      72              :   uint64_t offset;
      73            0 :   bool return_suppressed = false;
      74              : 
      75            0 :   if (GNUNET_SYSERR ==
      76            0 :       TALER_AUDITORDB_preflight (TAH_apg))
      77              :   {
      78            0 :     GNUNET_break (0);
      79            0 :     return TALER_MHD_reply_with_error (connection,
      80              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      81              :                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
      82              :                                        NULL);
      83              :   }
      84            0 :   TALER_MHD_parse_request_snumber (connection,
      85              :                                    "limit",
      86              :                                    &limit);
      87            0 :   if (limit < 0)
      88            0 :     offset = INT64_MAX;
      89              :   else
      90            0 :     offset = 0;
      91            0 :   TALER_MHD_parse_request_number (connection,
      92              :                                   "offset",
      93              :                                   &offset);
      94              :   {
      95            0 :     const char *ret_s = MHD_lookup_connection_value (connection,
      96              :                                                      MHD_GET_ARGUMENT_KIND,
      97              :                                                      "return_suppressed");
      98            0 :     if (ret_s != NULL && strcmp (ret_s, "true") == 0)
      99              :     {
     100            0 :       return_suppressed = true;
     101              :     }
     102              :   }
     103            0 :   ja = json_array ();
     104            0 :   GNUNET_break (NULL != ja);
     105            0 :   qs = TALER_AUDITORDB_get_coin_inconsistency (
     106              :     TAH_apg,
     107              :     limit,
     108              :     offset,
     109              :     return_suppressed,
     110              :     &add_coin_inconsistency,
     111              :     ja);
     112            0 :   if (0 > qs)
     113              :   {
     114            0 :     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
     115            0 :     json_decref (ja);
     116            0 :     TALER_LOG_WARNING (
     117              :       "Failed to handle GET /coin-inconsistency in database\n");
     118            0 :     return TALER_MHD_reply_with_error (connection,
     119              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     120              :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     121              :                                        "coin-inconsistency");
     122              :   }
     123            0 :   return TALER_MHD_REPLY_JSON_PACK (
     124              :     connection,
     125              :     MHD_HTTP_OK,
     126              :     GNUNET_JSON_pack_array_steal ("coin_inconsistency",
     127              :                                   ja));
     128              : }
        

Generated by: LCOV version 2.0-1