LCOV - code coverage report
Current view: top level - auditor - taler-auditor-httpd_purse-not-closed-inconsistencies-get.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 31 0
Test Date: 2025-12-28 14:06:02 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 "taler/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/taler_json_lib.h"
      23              : #include "taler/taler_mhd_lib.h"
      24              : #include "taler-auditor-httpd.h"
      25              : #include "taler-auditor-httpd_purse-not-closed-inconsistencies-get.h"
      26              : 
      27              : /**
      28              :  * Add purse-not-closed-inconsistencies to the list.
      29              :  *
      30              :  * @param[in,out] cls a `json_t *` array to extend
      31              :  * @param dc struct of inconsistencies
      32              :  * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
      33              :  */
      34              : static enum GNUNET_GenericReturnValue
      35            0 : process_purse_not_closed_inconsistencies (
      36              :   void *cls,
      37              :   const struct TALER_AUDITORDB_PurseNotClosedInconsistencies *dc)
      38              : {
      39            0 :   json_t *list = cls;
      40              :   json_t *obj;
      41              : 
      42            0 :   obj = GNUNET_JSON_PACK (
      43              :     GNUNET_JSON_pack_uint64 ("row_id",
      44              :                              dc->row_id),
      45              :     GNUNET_JSON_pack_data_auto ("purse_pub",
      46              :                                 &dc->purse_pub),
      47              :     TALER_JSON_pack_amount ("amount",
      48              :                             &dc->amount),
      49              :     TALER_JSON_pack_time_abs_human ("expiration_date",
      50              :                                     dc->expiration_date),
      51              :     GNUNET_JSON_pack_bool ("suppressed",
      52              :                            dc->suppressed)
      53              :     );
      54            0 :   GNUNET_break (0 ==
      55              :                 json_array_append_new (list,
      56              :                                        obj));
      57            0 :   return GNUNET_OK;
      58              : }
      59              : 
      60              : 
      61              : MHD_RESULT
      62            0 : TAH_PURSE_NOT_CLOSED_INCONSISTENCIES_handler_get (
      63              :   struct TAH_RequestHandler *rh,
      64              :   struct MHD_Connection *connection,
      65              :   void **connection_cls,
      66              :   const char *upload_data,
      67              :   size_t *upload_data_size,
      68              :   const char *const args[])
      69              : {
      70              :   json_t *ja;
      71              :   enum GNUNET_DB_QueryStatus qs;
      72            0 :   int64_t limit = -20;
      73              :   uint64_t offset;
      74            0 :   bool return_suppressed = false;
      75              : 
      76              :   (void) rh;
      77              :   (void) connection_cls;
      78              :   (void) upload_data;
      79              :   (void) upload_data_size;
      80            0 :   if (GNUNET_SYSERR ==
      81            0 :       TAH_plugin->preflight (TAH_plugin->cls))
      82              :   {
      83            0 :     GNUNET_break (0);
      84            0 :     return TALER_MHD_reply_with_error (connection,
      85              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      86              :                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
      87              :                                        NULL);
      88              :   }
      89            0 :   TALER_MHD_parse_request_snumber (connection,
      90              :                                    "limit",
      91              :                                    &limit);
      92            0 :   if (limit < 0)
      93            0 :     offset = INT64_MAX;
      94              :   else
      95            0 :     offset = 0;
      96            0 :   TALER_MHD_parse_request_number (connection,
      97              :                                   "offset",
      98              :                                   &offset);
      99              : 
     100              :   {
     101              :     const char *ret_s
     102            0 :       = MHD_lookup_connection_value (connection,
     103              :                                      MHD_GET_ARGUMENT_KIND,
     104              :                                      "return_suppressed");
     105              : 
     106            0 :     if ( (NULL != ret_s) &&
     107            0 :          (0 == strcmp (ret_s,
     108              :                        "true")) )
     109              :     {
     110            0 :       return_suppressed = true;
     111              :     }
     112              :   }
     113              : 
     114            0 :   ja = json_array ();
     115            0 :   GNUNET_break (NULL != ja);
     116            0 :   qs = TAH_plugin->get_purse_not_closed_inconsistencies (
     117            0 :     TAH_plugin->cls,
     118              :     limit,
     119              :     offset,
     120              :     return_suppressed,
     121              :     &process_purse_not_closed_inconsistencies,
     122              :     ja);
     123              : 
     124            0 :   if (0 > qs)
     125              :   {
     126            0 :     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
     127            0 :     json_decref (ja);
     128            0 :     TALER_LOG_WARNING (
     129              :       "Failed to handle GET /purse-not-closed-inconsistencies\n");
     130            0 :     return TALER_MHD_reply_with_error (connection,
     131              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     132              :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     133              :                                        "purse-not-closed-inconsistencies");
     134              :   }
     135            0 :   return TALER_MHD_REPLY_JSON_PACK (
     136              :     connection,
     137              :     MHD_HTTP_OK,
     138              :     GNUNET_JSON_pack_array_steal ("purse_not_closed_inconsistencies",
     139              :                                   ja));
     140              : }
        

Generated by: LCOV version 2.0-1