LCOV - code coverage report
Current view: top level - auditordb - iterate_fee_time_inconsistencies.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 34 0
Test Date: 2026-09-09 15:11:34 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/taler_pq_lib.h"
      17              : #include "pg_helper.h"
      18              : #include "auditor-database/iterate_fee_time_inconsistencies.h"
      19              : 
      20              : 
      21              : /**
      22              :  * Hard upper bound on the number of records returned by a single
      23              :  * call, regardless of the limit requested by the client.
      24              :  */
      25              : #define MAX_RECORDS 50000
      26              : 
      27              : 
      28              : /**
      29              :  * Closure for #feetimeinconsistency_cb().
      30              :  */
      31              : struct FeeTimeInconsistencyContext
      32              : {
      33              : 
      34              :   /**
      35              :    * Function to call for each fee time inconsistency
      36              :    */
      37              :   TALER_AUDITORDB_FeeTimeInconsistencyCallback cb;
      38              : 
      39              :   /**
      40              :    * Closure for @e cb
      41              :    */
      42              :   void *cb_cls;
      43              : 
      44              :   /**
      45              :    * Plugin context.
      46              :    */
      47              :   struct TALER_AUDITORDB_PostgresContext *pg;
      48              : 
      49              :   /**
      50              :    * Query status to return.
      51              :    */
      52              :   enum GNUNET_DB_QueryStatus qs;
      53              : };
      54              : 
      55              : 
      56              : /**
      57              :  * Helper function for #TALER_AUDITORDB_iterate_fee_time_inconsistencies().
      58              :  * To be called with the results of a SELECT statement
      59              :  * that has returned @a num_results results.
      60              :  *
      61              :  * @param cls closure of type `struct Emergency *`
      62              :  * @param result the postgres result
      63              :  * @param num_results the number of results in @a result
      64              :  */
      65              : static void
      66            0 : fee_time_inconsistency_cb (void *cls,
      67              :                            PGresult *result,
      68              :                            unsigned int num_results)
      69              : {
      70            0 :   struct FeeTimeInconsistencyContext *dcc = cls;
      71            0 :   for (unsigned int i = 0; i < num_results; i++)
      72              :   {
      73              :     struct TALER_AUDITORDB_FeeTimeInconsistency dc;
      74            0 :     struct GNUNET_PQ_ResultSpec rs[] = {
      75            0 :       GNUNET_PQ_result_spec_uint64 ("row_id",
      76              :                                     &dc.row_id),
      77            0 :       GNUNET_PQ_result_spec_uint64 ("problem_row_id",
      78              :                                     &dc.problem_row_id),
      79            0 :       GNUNET_PQ_result_spec_string ("fee_type",
      80              :                                     &dc.type),
      81            0 :       GNUNET_PQ_result_spec_absolute_time ("fee_time",
      82              :                                            &dc.time),
      83            0 :       GNUNET_PQ_result_spec_string ("diagnostic",
      84              :                                     &dc.diagnostic),
      85            0 :       GNUNET_PQ_result_spec_bool ("suppressed",
      86              :                                   &dc.suppressed),
      87              :       GNUNET_PQ_result_spec_end
      88              :     };
      89              :     enum GNUNET_GenericReturnValue rval;
      90              : 
      91            0 :     if (GNUNET_OK !=
      92            0 :         GNUNET_PQ_extract_result (result,
      93              :                                   rs,
      94              :                                   i))
      95              :     {
      96            0 :       GNUNET_break (0);
      97            0 :       dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
      98            0 :       return;
      99              :     }
     100            0 :     dcc->qs = i + 1;
     101            0 :     rval = dcc->cb (dcc->cb_cls,
     102              :                     &dc);
     103            0 :     GNUNET_PQ_cleanup_result (rs);
     104            0 :     if (GNUNET_OK != rval)
     105            0 :       break;
     106              :   }
     107              : }
     108              : 
     109              : 
     110              : enum GNUNET_DB_QueryStatus
     111            0 : TALER_AUDITORDB_iterate_fee_time_inconsistencies (
     112              :   struct TALER_AUDITORDB_PostgresContext *pg,
     113              :   int64_t limit,
     114              :   uint64_t offset,
     115              :   bool return_suppressed,
     116              :   TALER_AUDITORDB_FeeTimeInconsistencyCallback cb,
     117              :   void *cb_cls)
     118              : {
     119            0 :   uint64_t plimit = GNUNET_MIN ((uint64_t) MAX_RECORDS,
     120              :                                 TALER_AUDITORDB_abs_limit (limit));
     121            0 :   struct GNUNET_PQ_QueryParam params[] = {
     122            0 :     GNUNET_PQ_query_param_uint64 (&offset),
     123            0 :     GNUNET_PQ_query_param_bool (return_suppressed),
     124            0 :     GNUNET_PQ_query_param_uint64 (&plimit),
     125              :     GNUNET_PQ_query_param_end
     126              :   };
     127            0 :   struct FeeTimeInconsistencyContext dcc = {
     128              :     .cb = cb,
     129              :     .cb_cls = cb_cls,
     130              :     .pg = pg
     131              :   };
     132              :   enum GNUNET_DB_QueryStatus qs;
     133              : 
     134            0 :   PREPARE (pg,
     135              :            "iterate_fee_time_inconsistencies_inconsistency_get_desc",
     136              :            "SELECT"
     137              :            " row_id"
     138              :            ",problem_row_id"
     139              :            ",fee_type"
     140              :            ",fee_time"
     141              :            ",diagnostic"
     142              :            ",suppressed"
     143              :            " FROM auditor_fee_time_inconsistency"
     144              :            " WHERE (row_id < $1)"
     145              :            " AND ($2 OR NOT suppressed)"
     146              :            " ORDER BY row_id DESC"
     147              :            " LIMIT $3"
     148              :            );
     149            0 :   PREPARE (pg,
     150              :            "iterate_fee_time_inconsistencies_inconsistency_get_asc",
     151              :            "SELECT"
     152              :            " row_id"
     153              :            ",problem_row_id"
     154              :            ",fee_type"
     155              :            ",fee_time"
     156              :            ",diagnostic"
     157              :            ",suppressed"
     158              :            " FROM auditor_fee_time_inconsistency"
     159              :            " WHERE (row_id > $1)"
     160              :            " AND ($2 OR NOT suppressed)"
     161              :            " ORDER BY row_id ASC"
     162              :            " LIMIT $3"
     163              :            );
     164            0 :   qs = GNUNET_PQ_eval_prepared_multi_select (
     165              :     pg->conn,
     166              :     (limit > 0)
     167              :     ? "iterate_fee_time_inconsistencies_inconsistency_get_asc"
     168              :     : "iterate_fee_time_inconsistencies_inconsistency_get_desc",
     169              :     params,
     170              :     &fee_time_inconsistency_cb,
     171              :     &dcc);
     172            0 :   if (qs > 0)
     173            0 :     return dcc.qs;
     174            0 :   GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
     175            0 :   return qs;
     176              : }
        

Generated by: LCOV version 2.0-1