lookup_token_family.c (4547B)
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/lookup_token_family.c 18 * @brief Implementation of the lookup_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/lookup_token_family.h" 24 #include "helper.h" 25 26 27 enum GNUNET_DB_QueryStatus 28 TALER_MERCHANTDB_lookup_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 struct GNUNET_PQ_QueryParam params[] = { 35 GNUNET_PQ_query_param_string (token_family_slug), 36 GNUNET_PQ_query_param_end 37 }; 38 char *kind; 39 struct GNUNET_PQ_ResultSpec rs[] = { 40 GNUNET_PQ_result_spec_string ("slug", 41 &details->slug), 42 GNUNET_PQ_result_spec_string ("name", 43 &details->name), 44 GNUNET_PQ_result_spec_string ("cipher_choice", 45 &details->cipher_spec), 46 GNUNET_PQ_result_spec_string ("description", 47 &details->description), 48 TALER_PQ_result_spec_json ("description_i18n", 49 &details->description_i18n), 50 GNUNET_PQ_result_spec_allow_null ( 51 TALER_PQ_result_spec_json ("extra_data", 52 &details->extra_data), 53 NULL), 54 GNUNET_PQ_result_spec_timestamp ("valid_after", 55 &details->valid_after), 56 GNUNET_PQ_result_spec_timestamp ("valid_before", 57 &details->valid_before), 58 GNUNET_PQ_result_spec_relative_time ("duration", 59 &details->duration), 60 GNUNET_PQ_result_spec_relative_time ("validity_granularity", 61 &details->validity_granularity), 62 GNUNET_PQ_result_spec_relative_time ("start_offset", 63 &details->start_offset), 64 GNUNET_PQ_result_spec_string ("kind", 65 &kind), 66 GNUNET_PQ_result_spec_uint64 ("issued", 67 &details->issued), 68 GNUNET_PQ_result_spec_uint64 ("used", 69 &details->used), 70 GNUNET_PQ_result_spec_end 71 }; 72 enum GNUNET_DB_QueryStatus qs; 73 74 GNUNET_assert (NULL != pg->current_merchant_id); 75 GNUNET_assert (0 == strcmp (instance_id, 76 pg->current_merchant_id)); 77 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 memset (details, 96 0, 97 sizeof (*details)); 98 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 99 "", 100 params, 101 rs); 102 if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) 103 { 104 if (0 == strcmp (kind, 105 "discount")) 106 details->kind = TALER_MERCHANTDB_TFK_Discount; 107 else if (0 == strcmp (kind, 108 "subscription")) 109 details->kind = TALER_MERCHANTDB_TFK_Subscription; 110 else 111 { 112 GNUNET_break (0); 113 return GNUNET_DB_STATUS_HARD_ERROR; 114 } 115 } 116 return qs; 117 }