LCOV - code coverage report
Current view: top level - exchangedb - pg_select_reserve_open_above_serial_id.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 41.9 % 31 13
Test Date: 2026-01-18 12:54:31 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 pg_select_reserve_open_above_serial_id.c
      18              :  * @brief Low-level (statement-level) Postgres database access for the exchange
      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_select_reserve_open_above_serial_id.h"
      26              : #include "plugin_exchangedb_common.h"
      27              : #include "pg_helper.h"
      28              : 
      29              : 
      30              : /**
      31              :  * Closure for #reserve_open_serial_helper_cb().
      32              :  */
      33              : struct ReserveOpenSerialContext
      34              : {
      35              : 
      36              :   /**
      37              :    * Callback to call.
      38              :    */
      39              :   TALER_EXCHANGEDB_ReserveOpenCallback cb;
      40              : 
      41              :   /**
      42              :    * Closure for @e cb.
      43              :    */
      44              :   void *cb_cls;
      45              : 
      46              :   /**
      47              :    * Plugin's context.
      48              :    */
      49              :   struct PostgresClosure *pg;
      50              : 
      51              :   /**
      52              :    * Status code, set to #GNUNET_SYSERR on hard errors.
      53              :    */
      54              :   enum GNUNET_GenericReturnValue status;
      55              : };
      56              : 
      57              : 
      58              : /**
      59              :  * Helper function to be called with the results of a SELECT statement
      60              :  * that has returned @a num_results results.
      61              :  *
      62              :  * @param cls closure of type `struct ReserveOpenSerialContext`
      63              :  * @param result the postgres result
      64              :  * @param num_results the number of results in @a result
      65              :  */
      66              : static void
      67            4 : reserve_open_serial_helper_cb (void *cls,
      68              :                                PGresult *result,
      69              :                                unsigned int num_results)
      70              : {
      71            4 :   struct ReserveOpenSerialContext *rcsc = cls;
      72            4 :   struct PostgresClosure *pg = rcsc->pg;
      73              : 
      74            4 :   for (unsigned int i = 0; i<num_results; i++)
      75              :   {
      76              :     uint64_t rowid;
      77              :     struct TALER_ReservePublicKeyP reserve_pub;
      78              :     struct TALER_ReserveSignatureP reserve_sig;
      79              :     uint32_t requested_purse_limit;
      80              :     struct GNUNET_TIME_Timestamp request_timestamp;
      81              :     struct GNUNET_TIME_Timestamp reserve_expiration;
      82              :     struct TALER_Amount reserve_payment;
      83            0 :     struct GNUNET_PQ_ResultSpec rs[] = {
      84            0 :       GNUNET_PQ_result_spec_uint64 ("open_request_uuid",
      85              :                                     &rowid),
      86            0 :       GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
      87              :                                             &reserve_pub),
      88            0 :       GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
      89              :                                             &reserve_sig),
      90            0 :       GNUNET_PQ_result_spec_timestamp ("request_timestamp",
      91              :                                        &request_timestamp),
      92            0 :       GNUNET_PQ_result_spec_timestamp ("expiration_date",
      93              :                                        &reserve_expiration),
      94            0 :       GNUNET_PQ_result_spec_uint32 ("requested_purse_limit",
      95              :                                     &requested_purse_limit),
      96            0 :       TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_payment",
      97              :                                    &reserve_payment),
      98              :       GNUNET_PQ_result_spec_end
      99              :     };
     100              :     enum GNUNET_GenericReturnValue ret;
     101              : 
     102            0 :     if (GNUNET_OK !=
     103            0 :         GNUNET_PQ_extract_result (result,
     104              :                                   rs,
     105              :                                   i))
     106              :     {
     107            0 :       GNUNET_break (0);
     108            0 :       rcsc->status = GNUNET_SYSERR;
     109            0 :       return;
     110              :     }
     111            0 :     ret = rcsc->cb (rcsc->cb_cls,
     112              :                     rowid,
     113              :                     &reserve_payment,
     114              :                     request_timestamp,
     115              :                     reserve_expiration,
     116              :                     requested_purse_limit,
     117              :                     &reserve_pub,
     118              :                     &reserve_sig);
     119            0 :     GNUNET_PQ_cleanup_result (rs);
     120            0 :     if (GNUNET_OK != ret)
     121            0 :       break;
     122              :   }
     123              : }
     124              : 
     125              : 
     126              : enum GNUNET_DB_QueryStatus
     127            4 : TEH_PG_select_reserve_open_above_serial_id (
     128              :   void *cls,
     129              :   uint64_t serial_id,
     130              :   TALER_EXCHANGEDB_ReserveOpenCallback cb,
     131              :   void *cb_cls)
     132              : {
     133            4 :   struct PostgresClosure *pg = cls;
     134            4 :   struct GNUNET_PQ_QueryParam params[] = {
     135            4 :     GNUNET_PQ_query_param_uint64 (&serial_id),
     136              :     GNUNET_PQ_query_param_end
     137              :   };
     138            4 :   struct ReserveOpenSerialContext rcsc = {
     139              :     .cb = cb,
     140              :     .cb_cls = cb_cls,
     141              :     .pg = pg,
     142              :     .status = GNUNET_OK
     143              :   };
     144              :   enum GNUNET_DB_QueryStatus qs;
     145              : 
     146            4 :   PREPARE (
     147              :     pg,
     148              :     "reserves_open_get_incr",
     149              :     "SELECT"
     150              :     " open_request_uuid"
     151              :     ",reserve_pub"
     152              :     ",request_timestamp"
     153              :     ",expiration_date"
     154              :     ",reserve_sig"
     155              :     ",reserve_payment"
     156              :     ",requested_purse_limit"
     157              :     " FROM reserves_open_requests"
     158              :     " WHERE open_request_uuid>=$1"
     159              :     " ORDER BY open_request_uuid ASC;");
     160            4 :   qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
     161              :                                              "reserves_open_get_incr",
     162              :                                              params,
     163              :                                              &reserve_open_serial_helper_cb,
     164              :                                              &rcsc);
     165            4 :   if (GNUNET_OK != rcsc.status)
     166            0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     167            4 :   return qs;
     168              : }
        

Generated by: LCOV version 2.0-1