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

Generated by: LCOV version 2.0-1