LCOV - code coverage report
Current view: top level - backenddb - iterate_exchange_accounts.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 26 0
Test Date: 2026-09-04 23:42:01 Functions: 0.0 % 2 0

            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 src/backenddb/iterate_exchange_accounts.c
      18              :  * @brief Implementation of the iterate_exchange_accounts function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "platform.h"
      22              : #include <taler/taler_pq_lib.h>
      23              : #include "merchant-database/iterate_exchange_accounts.h"
      24              : #include "helper.h"
      25              : 
      26              : 
      27              : /**
      28              :  * Closure for #parse_accounts.
      29              :  */
      30              : struct SelectAccountContext
      31              : {
      32              :   /**
      33              :    * Function to call on each result.
      34              :    */
      35              :   TALER_MERCHANTDB_ExchangeAccountCallback cb;
      36              : 
      37              :   /**
      38              :    * Closure for @e cb.
      39              :    */
      40              :   void *cb_cls;
      41              : 
      42              :   /**
      43              :    * Set to true on failure.
      44              :    */
      45              :   bool failed;
      46              : };
      47              : 
      48              : /**
      49              :  * Function to be called with the results of a SELECT statement
      50              :  * that has returned @a num_results results about accounts.
      51              :  *
      52              :  * @param cls of type `struct SelectAccountContext *`
      53              :  * @param result the postgres result
      54              :  * @param num_results the number of results in @a result
      55              :  */
      56              : static void
      57            0 : parse_accounts (void *cls,
      58              :                 PGresult *result,
      59              :                 unsigned int num_results)
      60              : {
      61            0 :   struct SelectAccountContext *ctx = cls;
      62              : 
      63            0 :   for (unsigned int i = 0; i < num_results; i++)
      64              :   {
      65              :     struct TALER_FullPayto payto_uri;
      66            0 :     char *conversion_url = NULL;
      67              :     json_t *debit_restrictions;
      68              :     json_t *credit_restrictions;
      69              :     struct TALER_MasterSignatureP master_sig;
      70            0 :     struct GNUNET_PQ_ResultSpec rs[] = {
      71            0 :       GNUNET_PQ_result_spec_auto_from_type ("master_sig",
      72              :                                             &master_sig),
      73            0 :       GNUNET_PQ_result_spec_string ("payto_uri",
      74              :                                     &payto_uri.full_payto),
      75            0 :       GNUNET_PQ_result_spec_allow_null (
      76              :         GNUNET_PQ_result_spec_string ("conversion_url",
      77              :                                       &conversion_url),
      78              :         NULL),
      79            0 :       TALER_PQ_result_spec_json ("debit_restrictions",
      80              :                                  &debit_restrictions),
      81            0 :       TALER_PQ_result_spec_json ("credit_restrictions",
      82              :                                  &credit_restrictions),
      83              :       GNUNET_PQ_result_spec_end
      84              :     };
      85              : 
      86            0 :     if (GNUNET_OK !=
      87            0 :         GNUNET_PQ_extract_result (result,
      88              :                                   rs,
      89              :                                   i))
      90              :     {
      91            0 :       GNUNET_break (0);
      92            0 :       ctx->failed = true;
      93            0 :       return;
      94              :     }
      95            0 :     ctx->cb (ctx->cb_cls,
      96              :              payto_uri,
      97              :              conversion_url,
      98              :              debit_restrictions,
      99              :              credit_restrictions,
     100              :              &master_sig);
     101            0 :     GNUNET_PQ_cleanup_result (rs);
     102              :   }
     103              : }
     104              : 
     105              : 
     106              : enum GNUNET_DB_QueryStatus
     107            0 : TALER_MERCHANTDB_iterate_exchange_accounts (
     108              :   struct TALER_MERCHANTDB_PostgresContext *pg,
     109              :   const struct TALER_MasterPublicKeyP *master_pub,
     110              :   TALER_MERCHANTDB_ExchangeAccountCallback cb,
     111              :   void *cb_cls)
     112              : {
     113            0 :   struct SelectAccountContext ctx = {
     114              :     .cb = cb,
     115              :     .cb_cls = cb_cls
     116              :   };
     117            0 :   struct GNUNET_PQ_QueryParam params[] = {
     118            0 :     GNUNET_PQ_query_param_auto_from_type (master_pub),
     119              :     GNUNET_PQ_query_param_end
     120              :   };
     121              :   enum GNUNET_DB_QueryStatus qs;
     122              : 
     123            0 :   PREPARE (pg,
     124              :            "iterate_exchange_accounts",
     125              :            "SELECT"
     126              :            " payto_uri"
     127              :            ",conversion_url"
     128              :            ",debit_restrictions::TEXT"
     129              :            ",credit_restrictions::TEXT"
     130              :            ",master_sig"
     131              :            " FROM merchant_exchange_accounts"
     132              :            " WHERE master_pub=$1;");
     133            0 :   qs = GNUNET_PQ_eval_prepared_multi_select (
     134              :     pg->conn,
     135              :     "iterate_exchange_accounts",
     136              :     params,
     137              :     &parse_accounts,
     138              :     &ctx);
     139            0 :   if (ctx.failed)
     140            0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     141            0 :   return qs;
     142              : }
        

Generated by: LCOV version 2.0-1