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

Generated by: LCOV version 1.16