LCOV - code coverage report
Current view: top level - auditor - taler-auditor-httpd_emergency-by-count-get.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 30 0
Test Date: 2026-01-18 12:54: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 "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_emergency-by-count-get.h"
      26              : 
      27              : /**
      28              :  * Add emergency-by-count 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_emergency_by_count (
      36              :   void *cls,
      37              :   const struct TALER_AUDITORDB_EmergenciesByCount *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 ("denompub_h",
      46              :                                 &dc->denompub_h),
      47              :     GNUNET_JSON_pack_int64 ("num_issued",
      48              :                             dc->num_issued),
      49              :     GNUNET_JSON_pack_int64 ("num_known",
      50              :                             dc->num_known),
      51              :     TALER_JSON_pack_amount ("risk",
      52              :                             &dc->risk),
      53              :     TALER_JSON_pack_time_abs_human ("start",
      54              :                                     dc->start),
      55              :     TALER_JSON_pack_time_abs_human ("deposit_end",
      56              :                                     dc->deposit_end),
      57              :     TALER_JSON_pack_amount ("value",
      58              :                             &dc->value),
      59              :     GNUNET_JSON_pack_bool ("suppressed",
      60              :                            dc->suppressed)
      61              :     );
      62            0 :   GNUNET_break (0 ==
      63              :                 json_array_append_new (list,
      64              :                                        obj));
      65            0 :   return GNUNET_OK;
      66              : }
      67              : 
      68              : 
      69              : MHD_RESULT
      70            0 : TAH_EMERGENCY_BY_COUNT_handler_get (
      71              :   struct TAH_RequestHandler *rh,
      72              :   struct MHD_Connection *connection,
      73              :   void **connection_cls,
      74              :   const char *upload_data,
      75              :   size_t *upload_data_size,
      76              :   const char *const args[])
      77              : {
      78              :   json_t *ja;
      79              :   enum GNUNET_DB_QueryStatus qs;
      80            0 :   int64_t limit = -20;
      81              :   uint64_t offset;
      82            0 :   bool return_suppressed = false;
      83              : 
      84              :   (void) rh;
      85              :   (void) connection_cls;
      86              :   (void) upload_data;
      87              :   (void) upload_data_size;
      88            0 :   if (GNUNET_SYSERR ==
      89            0 :       TAH_plugin->preflight (TAH_plugin->cls))
      90              :   {
      91            0 :     GNUNET_break (0);
      92            0 :     return TALER_MHD_reply_with_error (connection,
      93              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      94              :                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
      95              :                                        NULL);
      96              :   }
      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            0 :       = MHD_lookup_connection_value (connection,
     110              :                                      MHD_GET_ARGUMENT_KIND,
     111              :                                      "return_suppressed");
     112            0 :     if (ret_s != NULL && strcmp (ret_s, "true") == 0)
     113              :     {
     114            0 :       return_suppressed = true;
     115              :     }
     116              :   }
     117              : 
     118            0 :   ja = json_array ();
     119            0 :   GNUNET_break (NULL != ja);
     120            0 :   qs = TAH_plugin->get_emergency_by_count (
     121            0 :     TAH_plugin->cls,
     122              :     limit,
     123              :     offset,
     124              :     return_suppressed,
     125              :     &process_emergency_by_count,
     126              :     ja);
     127            0 :   if (0 > qs)
     128              :   {
     129            0 :     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
     130            0 :     json_decref (ja);
     131            0 :     TALER_LOG_WARNING (
     132              :       "Failed to handle GET /emergency-by-count\n");
     133            0 :     return TALER_MHD_reply_with_error (connection,
     134              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     135              :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     136              :                                        "emergency-by-count");
     137              :   }
     138            0 :   return TALER_MHD_REPLY_JSON_PACK (
     139              :     connection,
     140              :     MHD_HTTP_OK,
     141              :     GNUNET_JSON_pack_array_steal ("emergency_by_count",
     142              :                                   ja));
     143              : }
        

Generated by: LCOV version 2.0-1