LCOV - code coverage report
Current view: top level - auditordb - iterate_aml_holds.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 33 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) 2026 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              : /**
      17              :  * @file src/auditordb/iterate_aml_holds.c
      18              :  * @brief Implementation of the iterate_aml_holds function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/taler_pq_lib.h"
      22              : #include "auditor-database/iterate_aml_holds.h"
      23              : #include "pg_helper.h"
      24              : 
      25              : 
      26              : /**
      27              :  * Closure for #aml_holds_cb().
      28              :  */
      29              : struct AmlHoldsContext
      30              : {
      31              :   /**
      32              :    * Function to call for each hold.
      33              :    */
      34              :   TALER_AUDITORDB_AmlHoldCallback cb;
      35              : 
      36              :   /**
      37              :    * Closure for @e cb.
      38              :    */
      39              :   void *cb_cls;
      40              : 
      41              :   /**
      42              :    * Plugin context.
      43              :    */
      44              :   struct TALER_AUDITORDB_PostgresContext *pg;
      45              : 
      46              :   /**
      47              :    * Query status to return.
      48              :    */
      49              :   enum GNUNET_DB_QueryStatus qs;
      50              : };
      51              : 
      52              : 
      53              : /**
      54              :  * Helper function for #TALER_AUDITORDB_iterate_aml_holds().
      55              :  * To be called with the results of a SELECT statement
      56              :  * that has returned @a num_results results.
      57              :  *
      58              :  * @param cls closure of type `struct AmlHoldsContext *`
      59              :  * @param result the postgres result
      60              :  * @param num_results the number of results in @a result
      61              :  */
      62              : static void
      63            0 : aml_holds_cb (void *cls,
      64              :               PGresult *result,
      65              :               unsigned int num_results)
      66              : {
      67            0 :   struct AmlHoldsContext *ahc = cls;
      68            0 :   struct TALER_AUDITORDB_PostgresContext *pg = ahc->pg;
      69              : 
      70            0 :   for (unsigned int i = 0; i < num_results; i++)
      71              :   {
      72              :     struct TALER_AUDITORDB_AmlHold ah;
      73            0 :     struct GNUNET_PQ_ResultSpec rs[] = {
      74            0 :       GNUNET_PQ_result_spec_uint64 ("row_id",
      75              :                                     &ah.row_id),
      76            0 :       GNUNET_PQ_result_spec_auto_from_type ("wtid",
      77              :                                             &ah.wtid),
      78            0 :       GNUNET_PQ_result_spec_auto_from_type ("wire_target_h_payto",
      79              :                                             &ah.wire_target_h_payto),
      80            0 :       GNUNET_PQ_result_spec_string ("account",
      81              :                                     &ah.account.full_payto),
      82            0 :       TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
      83              :                                    &ah.amount),
      84            0 :       GNUNET_PQ_result_spec_uint32 ("deferral_reason",
      85              :                                     &ah.deferral_reason),
      86            0 :       GNUNET_PQ_result_spec_uint64 ("legitimization_measure_serial_id",
      87              :                                     &ah.legitimization_measure_serial_id),
      88            0 :       GNUNET_PQ_result_spec_absolute_time ("creation_date",
      89              :                                            &ah.creation_date),
      90            0 :       GNUNET_PQ_result_spec_bool ("suppressed",
      91              :                                   &ah.suppressed),
      92              :       GNUNET_PQ_result_spec_end
      93              :     };
      94              :     enum GNUNET_GenericReturnValue rval;
      95              : 
      96            0 :     if (GNUNET_OK !=
      97            0 :         GNUNET_PQ_extract_result (result,
      98              :                                   rs,
      99              :                                   i))
     100              :     {
     101            0 :       GNUNET_break (0);
     102            0 :       ahc->qs = GNUNET_DB_STATUS_HARD_ERROR;
     103            0 :       return;
     104              :     }
     105            0 :     ahc->qs = i + 1;
     106            0 :     rval = ahc->cb (ahc->cb_cls,
     107              :                     &ah);
     108            0 :     GNUNET_PQ_cleanup_result (rs);
     109            0 :     if (GNUNET_OK != rval)
     110            0 :       break;
     111              :   }
     112              : }
     113              : 
     114              : 
     115              : enum GNUNET_DB_QueryStatus
     116            0 : TALER_AUDITORDB_iterate_aml_holds (
     117              :   struct TALER_AUDITORDB_PostgresContext *pg,
     118              :   TALER_AUDITORDB_AmlHoldCallback cb,
     119              :   TALER_AUDITORDB_AML_HOLD_RESULT_CLOSURE *cb_cls)
     120              : {
     121            0 :   struct GNUNET_PQ_QueryParam params[] = {
     122              :     GNUNET_PQ_query_param_end
     123              :   };
     124            0 :   struct AmlHoldsContext ahc = {
     125              :     .cb = cb,
     126              :     .cb_cls = cb_cls,
     127              :     .pg = pg
     128              :   };
     129              :   enum GNUNET_DB_QueryStatus qs;
     130              : 
     131            0 :   PREPARE (pg,
     132              :            "iterate_aml_holds",
     133              :            "SELECT"
     134              :            " row_id"
     135              :            ",wtid"
     136              :            ",wire_target_h_payto"
     137              :            ",account"
     138              :            ",amount"
     139              :            ",deferral_reason"
     140              :            ",legitimization_measure_serial_id"
     141              :            ",creation_date"
     142              :            ",suppressed"
     143              :            " FROM auditor_aml_holds"
     144              :            " ORDER BY row_id ASC;");
     145            0 :   qs = GNUNET_PQ_eval_prepared_multi_select (
     146              :     pg->conn,
     147              :     "iterate_aml_holds",
     148              :     params,
     149              :     &aml_holds_cb,
     150              :     &ahc);
     151            0 :   if (qs > 0)
     152            0 :     return ahc.qs;
     153            0 :   GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
     154            0 :   return qs;
     155              : }
        

Generated by: LCOV version 2.0-1