LCOV - code coverage report
Current view: top level - backenddb - get_token_family.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 84.8 % 33 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              :    Copyright (C) 2023, 2024, 2025 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/get_token_family.c
      18              :  * @brief Implementation of the get_token_family function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "platform.h"
      22              : #include <taler/taler_pq_lib.h>
      23              : #include "merchant-database/get_token_family.h"
      24              : #include "helper.h"
      25              : 
      26              : 
      27              : enum GNUNET_DB_QueryStatus
      28            7 : TALER_MERCHANTDB_get_token_family (
      29              :   struct TALER_MERCHANTDB_PostgresContext *pg,
      30              :   const char *instance_id,
      31              :   const char *token_family_slug,
      32              :   struct TALER_MERCHANTDB_TokenFamilyDetails *details)
      33              : {
      34            7 :   struct GNUNET_PQ_QueryParam params[] = {
      35            7 :     GNUNET_PQ_query_param_string (token_family_slug),
      36              :     GNUNET_PQ_query_param_end
      37              :   };
      38              :   char *kind;
      39            7 :   struct GNUNET_PQ_ResultSpec rs[] = {
      40            7 :     GNUNET_PQ_result_spec_string ("slug",
      41              :                                   &details->slug),
      42            7 :     GNUNET_PQ_result_spec_string ("name",
      43              :                                   &details->name),
      44            7 :     GNUNET_PQ_result_spec_string ("cipher_choice",
      45              :                                   &details->cipher_spec),
      46            7 :     GNUNET_PQ_result_spec_string ("description",
      47              :                                   &details->description),
      48            7 :     TALER_PQ_result_spec_json ("description_i18n",
      49              :                                &details->description_i18n),
      50            7 :     GNUNET_PQ_result_spec_allow_null (
      51              :       TALER_PQ_result_spec_json ("extra_data",
      52              :                                  &details->extra_data),
      53              :       NULL),
      54            7 :     GNUNET_PQ_result_spec_timestamp ("valid_after",
      55              :                                      &details->valid_after),
      56            7 :     GNUNET_PQ_result_spec_timestamp ("valid_before",
      57              :                                      &details->valid_before),
      58            7 :     GNUNET_PQ_result_spec_relative_time ("duration",
      59              :                                          &details->duration),
      60            7 :     GNUNET_PQ_result_spec_relative_time ("validity_granularity",
      61              :                                          &details->validity_granularity),
      62            7 :     GNUNET_PQ_result_spec_relative_time ("start_offset",
      63              :                                          &details->start_offset),
      64            7 :     GNUNET_PQ_result_spec_string ("kind",
      65              :                                   &kind),
      66            7 :     GNUNET_PQ_result_spec_uint64 ("issued",
      67              :                                   &details->issued),
      68            7 :     GNUNET_PQ_result_spec_uint64 ("used",
      69              :                                   &details->used),
      70              :     GNUNET_PQ_result_spec_end
      71              :   };
      72              :   enum GNUNET_DB_QueryStatus qs;
      73              : 
      74            7 :   GNUNET_assert (NULL != pg->current_merchant_id);
      75            7 :   GNUNET_assert (0 == strcmp (instance_id,
      76              :                               pg->current_merchant_id));
      77            7 :   TMH_PQ_prepare_anon (pg,
      78              :                        "SELECT"
      79              :                        " slug"
      80              :                        ",name"
      81              :                        ",cipher_choice"
      82              :                        ",description"
      83              :                        ",description_i18n::TEXT"
      84              :                        ",extra_data::TEXT"
      85              :                        ",valid_after"
      86              :                        ",valid_before"
      87              :                        ",duration"
      88              :                        ",validity_granularity"
      89              :                        ",start_offset"
      90              :                        ",kind"
      91              :                        ",issued"
      92              :                        ",used"
      93              :                        " FROM merchant_token_families"
      94              :                        " WHERE slug=$1");
      95            7 :   memset (details,
      96              :           0,
      97              :           sizeof (*details));
      98            7 :   qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
      99              :                                                  "",
     100              :                                                  params,
     101              :                                                  rs);
     102            7 :   if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
     103              :   {
     104            7 :     if (0 == strcmp (kind,
     105              :                      "discount"))
     106            7 :       details->kind = TALER_MERCHANTDB_TFK_Discount;
     107            0 :     else if (0 == strcmp (kind,
     108              :                           "subscription"))
     109            0 :       details->kind = TALER_MERCHANTDB_TFK_Subscription;
     110              :     else
     111              :     {
     112            0 :       GNUNET_break (0);
     113            0 :       GNUNET_PQ_cleanup_result (rs);
     114            0 :       return GNUNET_DB_STATUS_HARD_ERROR;
     115              :     }
     116            7 :     GNUNET_free (kind);
     117              :   }
     118            7 :   return qs;
     119              : }
        

Generated by: LCOV version 2.0-1