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

Generated by: LCOV version 2.0-1