LCOV - code coverage report
Current view: top level - auditor - taler-auditor-httpd_bad-sig-losses-get.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 32 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_bad-sig-losses-get.h"
      26              : 
      27              : 
      28              : /**
      29              :  * Add bad-sig-losses 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            0 : add_bad_sig_losses (
      37              :   void *cls,
      38              :   const struct TALER_AUDITORDB_BadSigLosses *dc)
      39              : {
      40            0 :   json_t *list = cls;
      41              :   json_t *obj;
      42              : 
      43            0 :   obj = GNUNET_JSON_PACK (
      44              :     GNUNET_JSON_pack_uint64 ("row_id",
      45              :                              dc->row_id),
      46              :     GNUNET_JSON_pack_uint64 ("problem_row_id",
      47              :                              dc->problem_row_id),
      48              :     GNUNET_JSON_pack_string ("operation",
      49              :                              dc->operation),
      50              :     TALER_JSON_pack_amount ("loss",
      51              :                             &dc->loss),
      52              :     GNUNET_JSON_pack_data_auto ("operation_specific_pub",
      53              :                                 &dc->operation_specific_pub),
      54              :     GNUNET_JSON_pack_bool ("suppressed",
      55              :                            dc->suppressed)
      56              :     );
      57            0 :   GNUNET_break (0 ==
      58              :                 json_array_append_new (list,
      59              :                                        obj));
      60            0 :   return GNUNET_OK;
      61              : }
      62              : 
      63              : 
      64              : MHD_RESULT
      65            0 : TAH_BAD_SIG_LOSSES_handler_get (
      66              :   struct TAH_RequestHandler *rh,
      67              :   struct MHD_Connection *connection,
      68              :   void **connection_cls,
      69              :   const char *upload_data,
      70              :   size_t *upload_data_size,
      71              :   const char *const args[])
      72              : {
      73              :   json_t *ja;
      74              :   enum GNUNET_DB_QueryStatus qs;
      75            0 :   int64_t limit = -20;
      76              :   uint64_t offset;
      77            0 :   bool return_suppressed = false;
      78              :   struct GNUNET_CRYPTO_EddsaPublicKey op_spec_pub;
      79            0 :   bool filter_spec_pub = false;
      80              :   const char *op;
      81              : 
      82              :   (void) rh;
      83              :   (void) connection_cls;
      84              :   (void) upload_data;
      85              :   (void) upload_data_size;
      86            0 :   if (GNUNET_SYSERR ==
      87            0 :       TAH_plugin->preflight (TAH_plugin->cls))
      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 :   TALER_MHD_parse_request_snumber (connection,
      96              :                                    "limit",
      97              :                                    &limit);
      98            0 :   if (limit < 0)
      99            0 :     offset = INT64_MAX;
     100              :   else
     101            0 :     offset = 0;
     102            0 :   TALER_MHD_parse_request_number (connection,
     103              :                                   "offset",
     104              :                                   &offset);
     105              :   {
     106            0 :     const char *ret_s = MHD_lookup_connection_value (connection,
     107              :                                                      MHD_GET_ARGUMENT_KIND,
     108              :                                                      "return_suppressed");
     109            0 :     if (ret_s != NULL && strcmp (ret_s, "true") == 0)
     110              :     {
     111            0 :       return_suppressed = true;
     112              :     }
     113              :   }
     114              : 
     115            0 :   op = MHD_lookup_connection_value (connection,
     116              :                                     MHD_GET_ARGUMENT_KIND,
     117              :                                     "op");
     118            0 :   TALER_MHD_parse_request_arg_auto (connection,
     119              :                                     "op_spec_pub",
     120              :                                     &op_spec_pub,
     121              :                                     filter_spec_pub);
     122            0 :   ja = json_array ();
     123            0 :   GNUNET_break (NULL != ja);
     124            0 :   qs = TAH_plugin->get_bad_sig_losses (
     125            0 :     TAH_plugin->cls,
     126              :     limit,
     127              :     offset,
     128              :     return_suppressed,
     129              :     filter_spec_pub ? &op_spec_pub : NULL,
     130              :     op,
     131              :     &add_bad_sig_losses,
     132              :     ja);
     133            0 :   if (0 > qs)
     134              :   {
     135            0 :     GNUNET_break (0);
     136            0 :     json_decref (ja);
     137            0 :     return TALER_MHD_reply_with_error (connection,
     138              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     139              :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     140              :                                        "bad-sig-losses");
     141              :   }
     142            0 :   return TALER_MHD_REPLY_JSON_PACK (
     143              :     connection,
     144              :     MHD_HTTP_OK,
     145              :     GNUNET_JSON_pack_array_steal ("bad_sig_losses",
     146              :                                   ja));
     147              : }
        

Generated by: LCOV version 2.0-1