LCOV - code coverage report
Current view: top level - auditor - taler-auditor-httpd_get-monitoring-amount-arithmetic-inconsistency.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 30 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-amount-arithmetic-inconsistency.h"
      25              : #include "auditor-database/get_amount_arithmetic_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 dc struct of inconsistencies
      34              :  * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
      35              :  */
      36              : static enum GNUNET_GenericReturnValue
      37            0 : add_amount_arithmetic_inconsistency (
      38              :   void *cls,
      39              :   const struct TALER_AUDITORDB_AmountArithmeticInconsistency *dc)
      40              : {
      41            0 :   json_t *list = cls;
      42              :   json_t *obj;
      43              : 
      44            0 :   obj = GNUNET_JSON_PACK (
      45              :     GNUNET_JSON_pack_uint64 ("row_id",
      46              :                              dc->row_id),
      47              :     GNUNET_JSON_pack_uint64 ("problem_row_id",
      48              :                              dc->problem_row_id),
      49              :     GNUNET_JSON_pack_string ("operation",
      50              :                              dc->operation),
      51              :     TALER_JSON_pack_amount ("exchange_amount",
      52              :                             &dc->exchange_amount),
      53              :     TALER_JSON_pack_amount ("auditor_amount",
      54              :                             &dc->auditor_amount),
      55              :     GNUNET_JSON_pack_bool ("profitable",
      56              :                            dc->profitable),
      57              :     GNUNET_JSON_pack_bool ("suppressed",
      58              :                            dc->suppressed)
      59              :     );
      60            0 :   GNUNET_break (0 ==
      61              :                 json_array_append_new (list,
      62              :                                        obj));
      63            0 :   return GNUNET_OK;
      64              : }
      65              : 
      66              : 
      67              : MHD_RESULT
      68            0 : TAH_get_monitoring_amount_arithmetic_inconsistency (
      69              :   struct TAH_RequestHandler *rh,
      70              :   struct MHD_Connection *connection,
      71              :   void **connection_cls,
      72              :   const char *upload_data,
      73              :   size_t *upload_data_size,
      74              :   const char *const args[])
      75              : {
      76              :   json_t *ja;
      77              :   enum GNUNET_DB_QueryStatus qs;
      78            0 :   int64_t limit = -20;
      79              :   uint64_t offset;
      80            0 :   bool return_suppressed = false;
      81              : 
      82              :   (void) rh;
      83              :   (void) connection_cls;
      84              :   (void) upload_data;
      85              :   (void) upload_data_size;
      86            0 :   if (GNUNET_SYSERR ==
      87            0 :       TALER_AUDITORDB_preflight (TAH_apg))
      88              :   {
      89            0 :     GNUNET_break (0);
      90            0 :     return TALER_MHD_reply_with_error (connection,
      91              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      92              :                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
      93              :                                        NULL);
      94              :   }
      95            0 :   ja = json_array ();
      96            0 :   GNUNET_break (NULL != ja);
      97            0 :   TALER_MHD_parse_request_snumber (connection,
      98              :                                    "limit",
      99              :                                    &limit);
     100            0 :   if (limit < 0)
     101            0 :     offset = INT64_MAX;
     102              :   else
     103            0 :     offset = 0;
     104            0 :   TALER_MHD_parse_request_number (connection,
     105              :                                   "offset",
     106              :                                   &offset);
     107              :   {
     108              :     const char *ret_s;
     109              : 
     110            0 :     ret_s = MHD_lookup_connection_value (connection,
     111              :                                          MHD_GET_ARGUMENT_KIND,
     112              :                                          "return_suppressed");
     113            0 :     if ( (ret_s != NULL) &&
     114            0 :          (0 == strcmp (ret_s,
     115              :                        "true")) )
     116              :     {
     117            0 :       return_suppressed = true;
     118              :     }
     119              :   }
     120              : 
     121            0 :   qs = TALER_AUDITORDB_get_amount_arithmetic_inconsistency (
     122              :     TAH_apg,
     123              :     limit,
     124              :     offset,
     125              :     return_suppressed,
     126              :     &add_amount_arithmetic_inconsistency,
     127              :     ja);
     128            0 :   if (0 > qs)
     129              :   {
     130            0 :     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
     131            0 :     json_decref (ja);
     132            0 :     TALER_LOG_WARNING (
     133              :       "Failed to handle GET /amount-arithmetic-inconsistency in database\n");
     134            0 :     return TALER_MHD_reply_with_error (
     135              :       connection,
     136              :       MHD_HTTP_INTERNAL_SERVER_ERROR,
     137              :       TALER_EC_GENERIC_DB_FETCH_FAILED,
     138              :       "amount-arithmetic-inconsistency");
     139              :   }
     140            0 :   return TALER_MHD_REPLY_JSON_PACK (
     141              :     connection,
     142              :     MHD_HTTP_OK,
     143              :     GNUNET_JSON_pack_array_steal ("amount_arithmetic_inconsistency",
     144              :                                   ja));
     145              : }
        

Generated by: LCOV version 2.0-1