LCOV - code coverage report
Current view: top level - auditor - taler-auditor-httpd_get-monitoring-row-inconsistency.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 57.1 % 28 16
Test Date: 2026-10-17 15:46:49 Functions: 50.0 % 2 1

            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-row-inconsistency.h"
      25              : #define TALER_AUDITORDB_ROW_INCONSISTENCY_RESULT_CLOSURE json_t
      26              : #include "auditor-database/iterate_row_inconsistencies.h"
      27              : #include "auditor-database/preflight.h"
      28              : 
      29              : 
      30              : /**
      31              :  * Add deposit confirmation to the list.
      32              :  *
      33              :  * @param[in,out] list a `json_t *` array to extend
      34              :  * @param serial_id location of the @a dc in the database
      35              :  * @param dc struct of inconsistencies
      36              :  * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
      37              :  */
      38              : static enum GNUNET_GenericReturnValue
      39            0 : add_row_inconsistency (
      40              :   json_t *list,
      41              :   uint64_t serial_id,
      42              :   const struct TALER_AUDITORDB_RowInconsistency *dc)
      43              : {
      44              :   json_t *obj;
      45              : 
      46            0 :   obj = GNUNET_JSON_PACK (
      47              : 
      48              :     GNUNET_JSON_pack_int64 ("row_id", serial_id),
      49              :     GNUNET_JSON_pack_uint64 ("problem_row_id",
      50              :                              dc->problem_row_id),
      51              : 
      52              :     GNUNET_JSON_pack_string ("row_table",
      53              :                              dc->row_table),
      54              :     GNUNET_JSON_pack_string ("diagnostic",
      55              :                              dc->diagnostic),
      56              :     GNUNET_JSON_pack_bool ("suppressed", dc->suppressed)
      57              :     );
      58            0 :   GNUNET_break (0 ==
      59              :                 json_array_append_new (list,
      60              :                                        obj));
      61            0 :   return GNUNET_OK;
      62              : }
      63              : 
      64              : 
      65              : enum MHD_Result
      66            6 : TAH_get_monitoring_row_inconsistency (
      67              :   struct TAH_RequestHandler *rh,
      68              :   struct MHD_Connection *connection,
      69              :   void **connection_cls,
      70              :   const char *upload_data,
      71              :   size_t *upload_data_size,
      72              :   const char *const args[])
      73              : {
      74              :   json_t *ja;
      75              :   enum GNUNET_DB_QueryStatus qs;
      76            6 :   int64_t limit = -20;
      77              :   uint64_t offset;
      78            6 :   bool return_suppressed = false;
      79              : 
      80              :   (void) rh;
      81              :   (void) connection_cls;
      82              :   (void) upload_data;
      83              :   (void) upload_data_size;
      84            6 :   if (GNUNET_SYSERR ==
      85            6 :       TALER_AUDITORDB_preflight (TAH_apg))
      86              :   {
      87            0 :     GNUNET_break (0);
      88            0 :     return TALER_MHD_reply_with_error (connection,
      89              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
      90              :                                        TALER_EC_GENERIC_DB_SETUP_FAILED,
      91              :                                        NULL);
      92              :   }
      93            6 :   TAH_PARSE_REQUEST_LIMIT (connection,
      94              :                            "limit",
      95              :                            &limit);
      96            6 :   if (limit < 0)
      97            6 :     offset = TAH_SAFE_UINT64_MAX;
      98              :   else
      99            0 :     offset = 0;
     100            6 :   TAH_PARSE_SAFE_REQUEST_NUMBER (connection,
     101              :                                  "offset",
     102              :                                  &offset);
     103              :   {
     104            6 :     const char *ret_s = MHD_lookup_connection_value (connection,
     105              :                                                      MHD_GET_ARGUMENT_KIND,
     106              :                                                      "return_suppressed");
     107            6 :     if (ret_s != NULL && strcmp (ret_s, "true") == 0)
     108              :     {
     109            0 :       return_suppressed = true;
     110              :     }
     111              :   }
     112              : 
     113            6 :   ja = json_array ();
     114            6 :   GNUNET_break (NULL != ja);
     115            6 :   qs = TALER_AUDITORDB_iterate_row_inconsistencies (
     116              :     TAH_apg,
     117              :     limit,
     118              :     offset,
     119              :     return_suppressed,
     120              :     &add_row_inconsistency,
     121              :     ja);
     122            6 :   if (0 > qs)
     123              :   {
     124            0 :     GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
     125            0 :     json_decref (ja);
     126            0 :     TALER_LOG_WARNING (
     127              :       "Failed to handle GET /row-inconsistency in database\n");
     128            0 :     return TALER_MHD_reply_with_error (connection,
     129              :                                        MHD_HTTP_INTERNAL_SERVER_ERROR,
     130              :                                        TALER_EC_GENERIC_DB_FETCH_FAILED,
     131              :                                        "row-inconsistency");
     132              :   }
     133            6 :   return TAH_reply_json_records (connection,
     134              :                                  ja);
     135              : }
        

Generated by: LCOV version 2.0-1