LCOV - code coverage report
Current view: top level - backenddb - set_instance.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 93.3 % 30 28
Test Date: 2026-09-04 23:42:01 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   (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 Lesser 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/set_instance.c
      18              :  * @brief Implementation of TALER_MERCHANTDB_set_instance
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "platform.h"
      22              : #include <gnunet/gnunet_util_lib.h>
      23              : #include <gnunet/gnunet_pq_lib.h>
      24              : #include <taler/taler_pq_lib.h>
      25              : #include "merchant-database/set_instance.h"
      26              : #include "helper.h"
      27              : 
      28              : 
      29              : enum GNUNET_DB_QueryStatus
      30         7037 : TALER_MERCHANTDB_set_instance (
      31              :   struct TALER_MERCHANTDB_PostgresContext *pg,
      32              :   const char *instance_id)
      33              : {
      34              :   uint64_t serial;
      35              :   struct TALER_MerchantPublicKeyP merchant_pub;
      36         7037 :   struct GNUNET_PQ_ResultSpec rs[] = {
      37         7037 :     GNUNET_PQ_result_spec_uint64 ("merchant_serial",
      38              :                                   &serial),
      39         7037 :     GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
      40              :                                           &merchant_pub),
      41              :     GNUNET_PQ_result_spec_end
      42              :   };
      43              :   enum GNUNET_DB_QueryStatus qs;
      44              :   char sp_sql[128];
      45         7037 :   struct GNUNET_PQ_ExecuteStatement es[] = {
      46         7037 :     GNUNET_PQ_make_execute (sp_sql),
      47              :     GNUNET_PQ_EXECUTE_STATEMENT_END
      48              :   };
      49              : 
      50         7037 :   if (NULL == instance_id)
      51              :   {
      52         3248 :     GNUNET_free (pg->current_merchant_id);
      53         3248 :     pg->current_merchant_serial = 0;
      54         3248 :     memset (&pg->current_merchant_pub,
      55              :             0,
      56              :             sizeof (pg->current_merchant_pub));
      57         3248 :     return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
      58              :   }
      59         3789 :   if ( (NULL != pg->current_merchant_id) &&
      60          559 :        (0 == strcmp (pg->current_merchant_id,
      61              :                      instance_id)) )
      62          537 :     return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
      63         3252 :   PREPARE (pg,
      64              :            "set_instance_lookup_serial",
      65              :            "SELECT merchant_serial"
      66              :            "      ,merchant_pub"
      67              :            "  FROM merchant.merchant_instances"
      68              :            " WHERE merchant_id=$1");
      69              :   {
      70         3252 :     struct GNUNET_PQ_QueryParam params[] = {
      71         3252 :       GNUNET_PQ_query_param_string (instance_id),
      72              :       GNUNET_PQ_query_param_end
      73              :     };
      74              : 
      75         3252 :     qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
      76              :                                                    "set_instance_lookup_serial",
      77              :                                                    params,
      78              :                                                    rs);
      79              :   }
      80         3252 :   if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
      81            7 :     return qs;
      82         3245 :   GNUNET_snprintf (sp_sql,
      83              :                    sizeof (sp_sql),
      84              :                    "SET search_path TO merchant_instance_%llu",
      85              :                    (unsigned long long) serial);
      86         3245 :   if (GNUNET_OK !=
      87         3245 :       GNUNET_PQ_exec_statements (pg->conn,
      88              :                                  es))
      89              :   {
      90            0 :     GNUNET_break (0);
      91            0 :     return GNUNET_DB_STATUS_HARD_ERROR;
      92              :   }
      93         3245 :   GNUNET_free (pg->current_merchant_id);
      94         3245 :   pg->current_merchant_id = GNUNET_strdup (instance_id);
      95         3245 :   pg->current_merchant_serial = serial;
      96         3245 :   pg->current_merchant_pub = merchant_pub;
      97         3245 :   return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
      98              : }
        

Generated by: LCOV version 2.0-1