LCOV - code coverage report
Current view: top level - auditor - taler-auditor-httpd_row-inconsistency-get.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 22 30 73.3 %
Date: 2025-06-05 21:03:14 Functions: 2 2 100.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 "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_json_lib.h"
      23             : #include "taler_mhd_lib.h"
      24             : #include "taler-auditor-httpd.h"
      25             : #include "taler-auditor-httpd_row-inconsistency-get.h"
      26             : 
      27             : 
      28             : /**
      29             :  * Add deposit confirmation to the list.
      30             :  *
      31             :  * @param[in,out] cls a `json_t *` array to extend
      32             :  * @param serial_id location of the @a dc in the database
      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           4 : add_row_inconsistency (
      38             :   void *cls,
      39             :   uint64_t serial_id,
      40             :   const struct TALER_AUDITORDB_RowInconsistency *dc)
      41             : {
      42           4 :   json_t *list = cls;
      43             :   json_t *obj;
      44             : 
      45           4 :   obj = GNUNET_JSON_PACK (
      46             : 
      47             :     GNUNET_JSON_pack_int64 ("row_id", serial_id),
      48             : 
      49             :     GNUNET_JSON_pack_string ("row_table",
      50             :                              dc->row_table),
      51             :     GNUNET_JSON_pack_string ("diagnostic",
      52             :                              dc->diagnostic),
      53             :     GNUNET_JSON_pack_bool ("suppressed", dc->suppressed)
      54             :     );
      55           4 :   GNUNET_break (0 ==
      56             :                 json_array_append_new (list,
      57             :                                        obj));
      58           4 :   return GNUNET_OK;
      59             : }
      60             : 
      61             : 
      62             : MHD_RESULT
      63           4 : TAH_ROW_INCONSISTENCY_handler_get (
      64             :   struct TAH_RequestHandler *rh,
      65             :   struct MHD_Connection *connection,
      66             :   void **connection_cls,
      67             :   const char *upload_data,
      68             :   size_t *upload_data_size,
      69             :   const char *const args[])
      70             : {
      71             :   json_t *ja;
      72             :   enum GNUNET_DB_QueryStatus qs;
      73           4 :   int64_t limit = -20;
      74             :   uint64_t offset;
      75           4 :   bool return_suppressed = false;
      76             : 
      77             :   (void) rh;
      78             :   (void) connection_cls;
      79             :   (void) upload_data;
      80             :   (void) upload_data_size;
      81           4 :   if (GNUNET_SYSERR ==
      82           4 :       TAH_plugin->preflight (TAH_plugin->cls))
      83             :   {
      84           0 :     GNUNET_break (0);
      85           0 :     return TALER_MHD_reply_with_error (connection,
      86             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      87             :                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
      88             :                                        NULL);
      89             :   }
      90           4 :   TALER_MHD_parse_request_snumber (connection,
      91             :                                    "limit",
      92             :                                    &limit);
      93           4 :   if (limit < 0)
      94           0 :     offset = INT64_MAX;
      95             :   else
      96           4 :     offset = 0;
      97           4 :   TALER_MHD_parse_request_number (connection,
      98             :                                   "offset",
      99             :                                   &offset);
     100             :   {
     101           4 :     const char *ret_s = MHD_lookup_connection_value (connection,
     102             :                                                      MHD_GET_ARGUMENT_KIND,
     103             :                                                      "return_suppressed");
     104           4 :     if (ret_s != NULL && strcmp (ret_s, "true") == 0)
     105             :     {
     106           0 :       return_suppressed = true;
     107             :     }
     108             :   }
     109             : 
     110           4 :   ja = json_array ();
     111           4 :   GNUNET_break (NULL != ja);
     112           4 :   qs = TAH_plugin->get_row_inconsistency (
     113           4 :     TAH_plugin->cls,
     114             :     limit,
     115             :     offset,
     116             :     return_suppressed,
     117             :     &add_row_inconsistency,
     118             :     ja);
     119           4 :   if (0 > qs)
     120             :   {
     121           0 :     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
     122           0 :     json_decref (ja);
     123           0 :     TALER_LOG_WARNING (
     124             :       "Failed to handle GET /row-inconsistency in database\n");
     125           0 :     return TALER_MHD_reply_with_error (connection,
     126             :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     127             :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     128             :                                        "row-inconsistency");
     129             :   }
     130           4 :   return TALER_MHD_REPLY_JSON_PACK (
     131             :     connection,
     132             :     MHD_HTTP_OK,
     133             :     GNUNET_JSON_pack_array_steal ("row_inconsistency",
     134             :                                   ja));
     135             : }

Generated by: LCOV version 1.16