lookup_token_family.c (4572B)
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 check_connection (pg); 78 TMH_PQ_prepare_anon (pg, 79 "SELECT" 80 " slug" 81 ",name" 82 ",cipher_choice" 83 ",description" 84 ",description_i18n::TEXT" 85 ",extra_data::TEXT" 86 ",valid_after" 87 ",valid_before" 88 ",duration" 89 ",validity_granularity" 90 ",start_offset" 91 ",kind" 92 ",issued" 93 ",used" 94 " FROM merchant_token_families" 95 " WHERE slug=$1"); 96 memset (details, 97 0, 98 sizeof (*details)); 99 qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, 100 "", 101 params, 102 rs); 103 if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) 104 { 105 if (0 == strcmp (kind, 106 "discount")) 107 details->kind = TALER_MERCHANTDB_TFK_Discount; 108 else if (0 == strcmp (kind, 109 "subscription")) 110 details->kind = TALER_MERCHANTDB_TFK_Subscription; 111 else 112 { 113 GNUNET_break (0); 114 return GNUNET_DB_STATUS_HARD_ERROR; 115 } 116 } 117 return qs; 118 }