LCOV - code coverage report
Current view: top level - auditor - taler-auditor-httpd_reserve-in-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_reserve-in-inconsistency-get.h"
      26             : 
      27             : 
      28             : /**
      29             :  * Add reserve-in-inconsistency to the list.
      30             :  *
      31             :  * @param[in,out] cls a `json_t *` array to extend
      32             :  * @param dc struct of inconsistencies
      33             :  * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
      34             :  */
      35             : static enum GNUNET_GenericReturnValue
      36           9 : process_reserve_in_inconsistency (
      37             :   void *cls,
      38             :   const struct TALER_AUDITORDB_ReserveInInconsistency *dc)
      39             : {
      40           9 :   json_t *list = cls;
      41             :   json_t *obj;
      42             : 
      43           9 :   obj = GNUNET_JSON_PACK (
      44             :     GNUNET_JSON_pack_uint64 ("row_id",
      45             :                              dc->serial_id),
      46             :     GNUNET_JSON_pack_uint64 ("bank_row_id",
      47             :                              dc->bank_row_id),
      48             :     TALER_JSON_pack_amount ("amount_exchange_expected",
      49             :                             &dc->amount_exchange_expected),
      50             :     TALER_JSON_pack_amount ("amount_wired",
      51             :                             &dc->amount_wired),
      52             :     GNUNET_JSON_pack_data_auto ("reserve_pub",
      53             :                                 &dc->reserve_pub),
      54             :     TALER_JSON_pack_time_abs_human ("timestamp",
      55             :                                     dc->timestamp),
      56             :     TALER_JSON_pack_full_payto ("account",
      57             :                                 dc->account),
      58             :     GNUNET_JSON_pack_string ("diagnostic",
      59             :                              dc->diagnostic),
      60             :     GNUNET_JSON_pack_bool ("suppressed",
      61             :                            dc->suppressed)
      62             :     );
      63           9 :   GNUNET_break (0 ==
      64             :                 json_array_append_new (list,
      65             :                                        obj));
      66             : 
      67             : 
      68           9 :   return GNUNET_OK;
      69             : }
      70             : 
      71             : 
      72             : MHD_RESULT
      73           9 : TAH_RESERVE_IN_INCONSISTENCY_handler_get (
      74             :   struct TAH_RequestHandler *rh,
      75             :   struct MHD_Connection *connection,
      76             :   void **connection_cls,
      77             :   const char *upload_data,
      78             :   size_t *upload_data_size,
      79             :   const char *const args[])
      80             : {
      81             :   json_t *ja;
      82             :   enum GNUNET_DB_QueryStatus qs;
      83           9 :   int64_t limit = -20;
      84             :   uint64_t offset;
      85           9 :   bool return_suppressed = false;
      86             : 
      87             :   (void) rh;
      88             :   (void) connection_cls;
      89             :   (void) upload_data;
      90             :   (void) upload_data_size;
      91           9 :   if (GNUNET_SYSERR ==
      92           9 :       TAH_plugin->preflight (TAH_plugin->cls))
      93             :   {
      94           0 :     GNUNET_break (0);
      95           0 :     return TALER_MHD_reply_with_error (connection,
      96             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      97             :                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
      98             :                                        NULL);
      99             :   }
     100           9 :   TALER_MHD_parse_request_snumber (connection,
     101             :                                    "limit",
     102             :                                    &limit);
     103           9 :   if (limit < 0)
     104           0 :     offset = INT64_MAX;
     105             :   else
     106           9 :     offset = 0;
     107           9 :   TALER_MHD_parse_request_number (connection,
     108             :                                   "offset",
     109             :                                   &offset);
     110             :   {
     111             :     const char *ret_s
     112           9 :       = MHD_lookup_connection_value (connection,
     113             :                                      MHD_GET_ARGUMENT_KIND,
     114             :                                      "return_suppressed");
     115           9 :     if ( (NULL != ret_s) &&
     116           0 :          (0 == strcmp (ret_s,
     117             :                        "true")) )
     118             :     {
     119           0 :       return_suppressed = true;
     120             :     }
     121             :   }
     122           9 :   ja = json_array ();
     123           9 :   GNUNET_break (NULL != ja);
     124           9 :   qs = TAH_plugin->get_reserve_in_inconsistency (
     125           9 :     TAH_plugin->cls,
     126             :     limit,
     127             :     offset,
     128             :     return_suppressed,
     129             :     &process_reserve_in_inconsistency,
     130             :     ja);
     131           9 :   if (0 > qs)
     132             :   {
     133           0 :     GNUNET_break (0);
     134           0 :     json_decref (ja);
     135           0 :     return TALER_MHD_reply_with_error (connection,
     136             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     137             :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     138             :                                        "reserve-in-inconsistency");
     139             :   }
     140           9 :   return TALER_MHD_REPLY_JSON_PACK (
     141             :     connection,
     142             :     MHD_HTTP_OK,
     143             :     GNUNET_JSON_pack_array_steal ("reserve_in_inconsistency",
     144             :                                   ja));
     145             : }

Generated by: LCOV version 1.16