LCOV - code coverage report
Current view: top level - auditor - taler-auditor-httpd_get-monitoring-reserves.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 25 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-reserves.h"
      25              : #include "auditor-database/get_reserves.h"
      26              : #include "auditor-database/preflight.h"
      27              : 
      28              : 
      29              : /**
      30              :  * Add reserves to the list.
      31              :  *
      32              :  * @param[in,out] cls a `json_t *` array to extend
      33              :  * @param serial_id location of the @a dc in the database
      34              :  * @param dc struct of inconsistencies
      35              :  * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
      36              :  */
      37              : static enum GNUNET_GenericReturnValue
      38            0 : process_reserves (
      39              :   void *cls,
      40              :   uint64_t serial_id,
      41              :   const struct TALER_AUDITORDB_Reserves *dc)
      42              : {
      43            0 :   json_t *list = cls;
      44              :   json_t *obj;
      45              : 
      46            0 :   obj = GNUNET_JSON_PACK (
      47              :     GNUNET_JSON_pack_int64 ("auditor_reserves_rowid",
      48              :                             dc->auditor_reserves_rowid),
      49              :     GNUNET_JSON_pack_data_auto ("reserve_pub",
      50              :                                 &dc->reserve_pub),
      51              :     TALER_JSON_pack_amount ("reserve_balance",
      52              :                             &dc->reserve_balance),
      53              :     TALER_JSON_pack_amount ("reserve_loss",
      54              :                             &dc->reserve_loss),
      55              :     TALER_JSON_pack_amount ("withdraw_fee_balance",
      56              :                             &dc->withdraw_fee_balance),
      57              :     TALER_JSON_pack_amount ("close_fee_balance",
      58              :                             &dc->close_fee_balance),
      59              :     TALER_JSON_pack_amount ("purse_fee_balance",
      60              :                             &dc->purse_fee_balance),
      61              :     TALER_JSON_pack_amount ("open_fee_balance",
      62              :                             &dc->open_fee_balance),
      63              :     TALER_JSON_pack_amount ("history_fee_balance",
      64              :                             &dc->history_fee_balance),
      65              :     TALER_JSON_pack_time_abs_human ("expiration_date",
      66              :                                     dc->expiration_date),
      67              :     TALER_JSON_pack_full_payto ("origin_account",
      68              :                                 dc->origin_account)
      69              :     );
      70            0 :   GNUNET_break (0 ==
      71              :                 json_array_append_new (list,
      72              :                                        obj));
      73            0 :   return GNUNET_OK;
      74              : }
      75              : 
      76              : 
      77              : MHD_RESULT
      78            0 : TAH_get_monitoring_reserves (
      79              :   struct TAH_RequestHandler *rh,
      80              :   struct MHD_Connection *connection,
      81              :   void **connection_cls,
      82              :   const char *upload_data,
      83              :   size_t *upload_data_size,
      84              :   const char *const args[])
      85              : {
      86              :   json_t *ja;
      87              :   enum GNUNET_DB_QueryStatus qs;
      88            0 :   int64_t limit = -20;
      89              :   uint64_t offset;
      90              : 
      91              :   (void) rh;
      92              :   (void) connection_cls;
      93              :   (void) upload_data;
      94              :   (void) upload_data_size;
      95            0 :   if (GNUNET_SYSERR ==
      96            0 :       TALER_AUDITORDB_preflight (TAH_apg))
      97              :   {
      98            0 :     GNUNET_break (0);
      99            0 :     return TALER_MHD_reply_with_error (connection,
     100              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     101              :                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
     102              :                                        NULL);
     103              :   }
     104            0 :   TALER_MHD_parse_request_snumber (connection,
     105              :                                    "limit",
     106              :                                    &limit);
     107              : 
     108            0 :   if (limit < 0)
     109            0 :     offset = INT64_MAX;
     110              :   else
     111            0 :     offset = 0;
     112            0 :   TALER_MHD_parse_request_number (connection,
     113              :                                   "offset",
     114              :                                   &offset);
     115            0 :   ja = json_array ();
     116            0 :   GNUNET_break (NULL != ja);
     117            0 :   qs = TALER_AUDITORDB_get_reserves (
     118              :     TAH_apg,
     119              :     limit,
     120              :     offset,
     121              :     &process_reserves,
     122              :     ja);
     123            0 :   if (0 > qs)
     124              :   {
     125            0 :     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
     126            0 :     json_decref (ja);
     127            0 :     TALER_LOG_WARNING (
     128              :       "Failed to handle GET /reserves");
     129            0 :     return TALER_MHD_reply_with_error (connection,
     130              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     131              :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     132              :                                        "reserves");
     133              :   }
     134            0 :   return TALER_MHD_REPLY_JSON_PACK (
     135              :     connection,
     136              :     MHD_HTTP_OK,
     137              :     GNUNET_JSON_pack_array_steal ("reserves",
     138              :                                   ja));
     139              : }
        

Generated by: LCOV version 2.0-1