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 % 28 0
Test Date: 2026-09-09 15:11:34 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              : #define TALER_AUDITORDB_COIN_INCONSISTENCY_RESULT_CLOSURE json_t
      26              : #include "auditor-database/iterate_coin_inconsistencies.h"
      27              : #include "auditor-database/preflight.h"
      28              : 
      29              : 
      30              : /**
      31              :  * Add deposit confirmation to the list.
      32              :  *
      33              :  * @param[in,out] list a `json_t *` array to extend
      34              :  * @param serial_id location of the @a dc in the database
      35              :  * @param dc struct of inconsistencies
      36              :  * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
      37              :  */
      38              : static enum GNUNET_GenericReturnValue
      39            0 : add_coin_inconsistency (
      40              :   json_t *list,
      41              :   uint64_t serial_id,
      42              :   const struct TALER_AUDITORDB_CoinInconsistency *dc)
      43              : {
      44              :   json_t *obj;
      45              : 
      46            0 :   obj = GNUNET_JSON_PACK (
      47              :     GNUNET_JSON_pack_uint64 ("row_id", serial_id),
      48              :     GNUNET_JSON_pack_string ("operation", dc->operation),
      49              :     TALER_JSON_pack_amount ("exchange_amount", &dc->exchange_amount),
      50              :     TALER_JSON_pack_amount ("auditor_amount", &dc->auditor_amount),
      51              :     GNUNET_JSON_pack_data_auto ("coin_pub",&dc->coin_pub),
      52              :     GNUNET_JSON_pack_bool ("profitable", dc->profitable),
      53              :     GNUNET_JSON_pack_bool ("suppressed", dc->suppressed)
      54              :     );
      55            0 :   GNUNET_break (0 ==
      56              :                 json_array_append_new (list,
      57              :                                        obj));
      58            0 :   return GNUNET_OK;
      59              : }
      60              : 
      61              : 
      62              : enum MHD_Result
      63            0 : TAH_get_monitoring_coin_inconsistency (
      64              :   struct TAH_RequestHandler *rh,
      65              :   struct MHD_Connection *connection,
      66              :   void **connection_cls,
      67              :   const char *upload_data,
      68              :   size_t *upload_data_size,
      69              :   const char *const args[])
      70              : {
      71              :   json_t *ja;
      72              :   enum GNUNET_DB_QueryStatus qs;
      73            0 :   int64_t limit = -20;
      74              :   uint64_t offset;
      75            0 :   bool return_suppressed = false;
      76              : 
      77            0 :   if (GNUNET_SYSERR ==
      78            0 :       TALER_AUDITORDB_preflight (TAH_apg))
      79              :   {
      80            0 :     GNUNET_break (0);
      81            0 :     return TALER_MHD_reply_with_error (connection,
      82              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      83              :                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
      84              :                                        NULL);
      85              :   }
      86            0 :   TAH_PARSE_REQUEST_LIMIT (connection,
      87              :                                    "limit",
      88              :                                    &limit);
      89            0 :   if (limit < 0)
      90            0 :     offset = TAH_SAFE_UINT64_MAX;
      91              :   else
      92            0 :     offset = 0;
      93            0 :   TAH_PARSE_SAFE_REQUEST_NUMBER (connection,
      94              :                                   "offset",
      95              :                                   &offset);
      96              :   {
      97            0 :     const char *ret_s = MHD_lookup_connection_value (connection,
      98              :                                                      MHD_GET_ARGUMENT_KIND,
      99              :                                                      "return_suppressed");
     100            0 :     if (ret_s != NULL && strcmp (ret_s, "true") == 0)
     101              :     {
     102            0 :       return_suppressed = true;
     103              :     }
     104              :   }
     105            0 :   ja = json_array ();
     106            0 :   GNUNET_break (NULL != ja);
     107            0 :   qs = TALER_AUDITORDB_iterate_coin_inconsistencies (
     108              :     TAH_apg,
     109              :     limit,
     110              :     offset,
     111              :     return_suppressed,
     112              :     &add_coin_inconsistency,
     113              :     ja);
     114            0 :   if (0 > qs)
     115              :   {
     116            0 :     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
     117            0 :     json_decref (ja);
     118            0 :     TALER_LOG_WARNING (
     119              :       "Failed to handle GET /coin-inconsistency in database\n");
     120            0 :     return TALER_MHD_reply_with_error (connection,
     121              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     122              :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     123              :                                        "coin-inconsistency");
     124              :   }
     125            0 :   return TAH_reply_json_records (connection,
     126              :                                  ja);
     127              : }
        

Generated by: LCOV version 2.0-1