LCOV - code coverage report
Current view: top level - auditor - taler-auditor-httpd_coin-inconsistency-get.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 22 30 73.3 %
Date: 2025-06-05 21:03:14 Functions: 2 2 100.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 "platform.h"
      17             : #include <gnunet/gnunet_util_lib.h>
      18             : #include <gnunet/gnunet_json_lib.h>
      19             : #include <jansson.h>
      20             : #include <microhttpd.h>
      21             : #include <pthread.h>
      22             : #include "taler_json_lib.h"
      23             : #include "taler_mhd_lib.h"
      24             : #include "taler-auditor-httpd.h"
      25             : #include "taler-auditor-httpd_coin-inconsistency-get.h"
      26             : 
      27             : 
      28             : /**
      29             :  * Add deposit confirmation to the list.
      30             :  *
      31             :  * @param[in,out] cls a `json_t *` array to extend
      32             :  * @param serial_id location of the @a dc in the database
      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           1 : add_coin_inconsistency (
      38             :   void *cls,
      39             :   uint64_t serial_id,
      40             :   const struct TALER_AUDITORDB_CoinInconsistency *dc)
      41             : {
      42           1 :   json_t *list = cls;
      43             :   json_t *obj;
      44             : 
      45           1 :   obj = GNUNET_JSON_PACK (
      46             :     GNUNET_JSON_pack_string ("operation", dc->operation),
      47             :     TALER_JSON_pack_amount ("exchange_amount", &dc->exchange_amount),
      48             :     TALER_JSON_pack_amount ("auditor_amount", &dc->auditor_amount),
      49             :     GNUNET_JSON_pack_data_auto ("coin_pub",&dc->coin_pub),
      50             :     GNUNET_JSON_pack_bool ("profitable", dc->profitable)
      51             :     );
      52           1 :   GNUNET_break (0 ==
      53             :                 json_array_append_new (list,
      54             :                                        obj));
      55           1 :   return GNUNET_OK;
      56             : }
      57             : 
      58             : 
      59             : MHD_RESULT
      60           1 : TAH_COIN_INCONSISTENCY_handler_get (
      61             :   struct TAH_RequestHandler *rh,
      62             :   struct MHD_Connection *connection,
      63             :   void **connection_cls,
      64             :   const char *upload_data,
      65             :   size_t *upload_data_size,
      66             :   const char *const args[])
      67             : {
      68             :   json_t *ja;
      69             :   enum GNUNET_DB_QueryStatus qs;
      70           1 :   int64_t limit = -20;
      71             :   uint64_t offset;
      72           1 :   bool return_suppressed = false;
      73             : 
      74           1 :   if (GNUNET_SYSERR ==
      75           1 :       TAH_plugin->preflight (TAH_plugin->cls))
      76             :   {
      77           0 :     GNUNET_break (0);
      78           0 :     return TALER_MHD_reply_with_error (connection,
      79             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      80             :                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
      81             :                                        NULL);
      82             :   }
      83           1 :   TALER_MHD_parse_request_snumber (connection,
      84             :                                    "limit",
      85             :                                    &limit);
      86           1 :   if (limit < 0)
      87           0 :     offset = INT64_MAX;
      88             :   else
      89           1 :     offset = 0;
      90           1 :   TALER_MHD_parse_request_number (connection,
      91             :                                   "offset",
      92             :                                   &offset);
      93             :   {
      94           1 :     const char *ret_s = MHD_lookup_connection_value (connection,
      95             :                                                      MHD_GET_ARGUMENT_KIND,
      96             :                                                      "return_suppressed");
      97           1 :     if (ret_s != NULL && strcmp (ret_s, "true") == 0)
      98             :     {
      99           0 :       return_suppressed = true;
     100             :     }
     101             :   }
     102           1 :   ja = json_array ();
     103           1 :   GNUNET_break (NULL != ja);
     104           1 :   qs = TAH_plugin->get_coin_inconsistency (
     105           1 :     TAH_plugin->cls,
     106             :     limit,
     107             :     offset,
     108             :     return_suppressed,
     109             :     &add_coin_inconsistency,
     110             :     ja);
     111           1 :   if (0 > qs)
     112             :   {
     113           0 :     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
     114           0 :     json_decref (ja);
     115           0 :     TALER_LOG_WARNING (
     116             :       "Failed to handle GET /coin-inconsistency in database\n");
     117           0 :     return TALER_MHD_reply_with_error (connection,
     118             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     119             :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     120             :                                        "coin-inconsistency");
     121             :   }
     122           1 :   return TALER_MHD_REPLY_JSON_PACK (
     123             :     connection,
     124             :     MHD_HTTP_OK,
     125             :     GNUNET_JSON_pack_array_steal ("coin_inconsistency",
     126             :                                   ja));
     127             : }

Generated by: LCOV version 1.16