LCOV - code coverage report
Current view: top level - exchangedb - pg_wire_prepare_data_get.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 84.6 % 26 22
Test Date: 2025-12-28 14:06:02 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 2022 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 exchangedb/pg_wire_prepare_data_get.c
      18              :  * @brief Implementation of the wire_prepare_data_get function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/platform.h"
      22              : #include "taler/taler_error_codes.h"
      23              : #include "taler/taler_dbevents.h"
      24              : #include "taler/taler_pq_lib.h"
      25              : #include "pg_wire_prepare_data_get.h"
      26              : #include "pg_helper.h"
      27              : 
      28              : /**
      29              :  * Closure for #prewire_cb().
      30              :  */
      31              : struct PrewireContext
      32              : {
      33              :   /**
      34              :    * Function to call on each result.
      35              :    */
      36              :   TALER_EXCHANGEDB_WirePreparationIterator cb;
      37              : 
      38              :   /**
      39              :    * Closure for @a cb.
      40              :    */
      41              :   void *cb_cls;
      42              : 
      43              :   /**
      44              :    * #GNUNET_OK if everything went fine.
      45              :    */
      46              :   enum GNUNET_GenericReturnValue status;
      47              : };
      48              : 
      49              : 
      50              : /**
      51              :  * Invoke the callback for each result.
      52              :  *
      53              :  * @param cls a `struct MissingWireContext *`
      54              :  * @param result SQL result
      55              :  * @param num_results number of rows in @a result
      56              :  */
      57              : static void
      58          108 : prewire_cb (void *cls,
      59              :             PGresult *result,
      60              :             unsigned int num_results)
      61              : {
      62          108 :   struct PrewireContext *pc = cls;
      63              : 
      64          169 :   for (unsigned int i = 0; i < num_results; i++)
      65              :   {
      66              :     uint64_t prewire_uuid;
      67              :     char *wire_method;
      68           61 :     void *buf = NULL;
      69              :     size_t buf_size;
      70           61 :     struct GNUNET_PQ_ResultSpec rs[] = {
      71           61 :       GNUNET_PQ_result_spec_uint64 ("prewire_uuid",
      72              :                                     &prewire_uuid),
      73           61 :       GNUNET_PQ_result_spec_string ("wire_method",
      74              :                                     &wire_method),
      75           61 :       GNUNET_PQ_result_spec_variable_size ("buf",
      76              :                                            &buf,
      77              :                                            &buf_size),
      78              :       GNUNET_PQ_result_spec_end
      79              :     };
      80              : 
      81           61 :     if (GNUNET_OK !=
      82           61 :         GNUNET_PQ_extract_result (result,
      83              :                                   rs,
      84              :                                   i))
      85              :     {
      86            0 :       GNUNET_break (0);
      87            0 :       pc->status = GNUNET_SYSERR;
      88            0 :       return;
      89              :     }
      90           61 :     pc->cb (pc->cb_cls,
      91              :             prewire_uuid,
      92              :             wire_method,
      93              :             buf,
      94              :             buf_size);
      95           61 :     GNUNET_PQ_cleanup_result (rs);
      96              :   }
      97              : }
      98              : 
      99              : 
     100              : enum GNUNET_DB_QueryStatus
     101          108 : TEH_PG_wire_prepare_data_get (void *cls,
     102              :                               uint64_t start_row,
     103              :                               uint64_t limit,
     104              :                               TALER_EXCHANGEDB_WirePreparationIterator cb,
     105              :                               void *cb_cls)
     106              : {
     107          108 :   struct PostgresClosure *pg = cls;
     108          108 :   struct GNUNET_PQ_QueryParam params[] = {
     109          108 :     GNUNET_PQ_query_param_uint64 (&start_row),
     110          108 :     GNUNET_PQ_query_param_uint64 (&limit),
     111              :     GNUNET_PQ_query_param_end
     112              :   };
     113          108 :   struct PrewireContext pc = {
     114              :     .cb = cb,
     115              :     .cb_cls = cb_cls,
     116              :     .status = GNUNET_OK
     117              :   };
     118              :   enum GNUNET_DB_QueryStatus qs;
     119              : 
     120          108 :   PREPARE (pg,
     121              :            "wire_prepare_data_get",
     122              :            "SELECT"
     123              :            " prewire_uuid"
     124              :            ",wire_method"
     125              :            ",buf"
     126              :            " FROM prewire"
     127              :            " WHERE prewire_uuid >= $1"
     128              :            "   AND finished=FALSE"
     129              :            "   AND failed=FALSE"
     130              :            " ORDER BY prewire_uuid ASC"
     131              :            " LIMIT $2;");
     132          108 :   qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
     133              :                                              "wire_prepare_data_get",
     134              :                                              params,
     135              :                                              &prewire_cb,
     136              :                                              &pc);
     137          108 :   if (GNUNET_OK != pc.status)
     138            0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     139          108 :   return qs;
     140              : }
        

Generated by: LCOV version 2.0-1