LCOV - code coverage report
Current view: top level - auditor - taler-auditor-httpd_wire-out-inconsistency-get.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 20 27 74.1 %
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_wire-out-inconsistency-get.h"
      26             : 
      27             : 
      28             : /**
      29             :  * Add wire-out-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          15 : process_wire_out_inconsistency (
      37             :   void *cls,
      38             :   const struct TALER_AUDITORDB_WireOutInconsistency *dc)
      39             : {
      40          15 :   json_t *list = cls;
      41             :   json_t *obj;
      42             : 
      43          15 :   obj = GNUNET_JSON_PACK (
      44             :     GNUNET_JSON_pack_int64 ("row_id",
      45             :                             dc->row_id),
      46             :     TALER_JSON_pack_full_payto ("destination_account",
      47             :                                 dc->destination_account),
      48             :     GNUNET_JSON_pack_int64 ("wire_out_row_id",
      49             :                             dc->wire_out_row_id),
      50             :     GNUNET_JSON_pack_string ("diagnostic",
      51             :                              dc->diagnostic),
      52             :     TALER_JSON_pack_amount ("expected",
      53             :                             &dc->expected),
      54             :     TALER_JSON_pack_amount ("claimed",
      55             :                             &dc->claimed),
      56             :     GNUNET_JSON_pack_bool ("suppressed",
      57             :                            dc->suppressed)
      58             :     );
      59          15 :   GNUNET_break (0 ==
      60             :                 json_array_append_new (list,
      61             :                                        obj));
      62          15 :   return GNUNET_OK;
      63             : }
      64             : 
      65             : 
      66             : MHD_RESULT
      67          15 : TAH_WIRE_OUT_INCONSISTENCY_handler_get (
      68             :   struct TAH_RequestHandler *rh,
      69             :   struct MHD_Connection *connection,
      70             :   void **connection_cls,
      71             :   const char *upload_data,
      72             :   size_t *upload_data_size,
      73             :   const char *const args[])
      74             : {
      75             :   json_t *ja;
      76             :   enum GNUNET_DB_QueryStatus qs;
      77          15 :   int64_t limit = -20;
      78             :   uint64_t offset;
      79             :   enum TALER_EXCHANGE_YesNoAll return_suppressed;
      80             : 
      81             :   (void) rh;
      82             :   (void) connection_cls;
      83             :   (void) upload_data;
      84             :   (void) upload_data_size;
      85          15 :   if (GNUNET_SYSERR ==
      86          15 :       TAH_plugin->preflight (TAH_plugin->cls))
      87             :   {
      88           0 :     GNUNET_break (0);
      89           0 :     return TALER_MHD_reply_with_error (connection,
      90             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      91             :                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
      92             :                                        NULL);
      93             :   }
      94          15 :   TALER_MHD_parse_request_snumber (connection,
      95             :                                    "limit",
      96             :                                    &limit);
      97          15 :   if (limit < 0)
      98           0 :     offset = INT64_MAX;
      99             :   else
     100          15 :     offset = 0;
     101          15 :   TALER_MHD_parse_request_number (connection,
     102             :                                   "offset",
     103             :                                   &offset);
     104             : 
     105          15 :   TALER_MHD_parse_request_yna (connection,
     106             :                                "return_suppressed",
     107             :                                false,
     108             :                                &return_suppressed);
     109          15 :   ja = json_array ();
     110          15 :   GNUNET_break (NULL != ja);
     111          15 :   qs = TAH_plugin->get_wire_out_inconsistency (
     112          15 :     TAH_plugin->cls,
     113             :     limit,
     114             :     offset,
     115             :     (TALER_EXCHANGE_YNA_NO != return_suppressed),
     116             :     &process_wire_out_inconsistency,
     117             :     ja);
     118             : 
     119          15 :   if (0 > qs)
     120             :   {
     121           0 :     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
     122           0 :     json_decref (ja);
     123           0 :     TALER_LOG_WARNING (
     124             :       "Failed to handle GET /wire-out-inconsistency");
     125           0 :     return TALER_MHD_reply_with_error (connection,
     126             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     127             :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     128             :                                        "wire-out-inconsistency");
     129             :   }
     130          15 :   return TALER_MHD_REPLY_JSON_PACK (
     131             :     connection,
     132             :     MHD_HTTP_OK,
     133             :     GNUNET_JSON_pack_array_steal ("wire_out_inconsistency",
     134             :                                   ja));
     135             : }

Generated by: LCOV version 1.16