update_token_family_key_expiration.c (2896B)
1 /* 2 This file is part of TALER 3 Copyright (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 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/update_token_family_key_expiration.c 18 * @brief Implementation of the update_token_family_key_expiration function for Postgres 19 * @author Christian Grothoff 20 */ 21 #include "platform.h" 22 #include <gnunet/gnunet_pq_lib.h> 23 #include <taler/taler_pq_lib.h> 24 #include "merchant-database/update_token_family_key_expiration.h" 25 #include "helper.h" 26 27 28 enum GNUNET_DB_QueryStatus 29 TALER_MERCHANTDB_update_token_family_key_expiration ( 30 struct TALER_MERCHANTDB_PostgresContext *pg, 31 const char *instance_id, 32 const char *token_family_slug, 33 struct GNUNET_TIME_Timestamp valid_at, 34 struct GNUNET_TIME_Timestamp sign_until) 35 { 36 struct GNUNET_PQ_QueryParam params[] = { 37 GNUNET_PQ_query_param_string (token_family_slug), 38 GNUNET_PQ_query_param_timestamp (&valid_at), 39 GNUNET_PQ_query_param_timestamp (&sign_until), 40 GNUNET_PQ_query_param_end 41 }; 42 enum GNUNET_DB_QueryStatus qs; 43 44 GNUNET_assert (NULL != pg->current_merchant_id); 45 GNUNET_assert (0 == strcmp (instance_id, 46 pg->current_merchant_id)); 47 TMH_PQ_prepare_anon (pg, 48 "UPDATE merchant_token_family_keys mtfk" 49 " SET private_key_deleted_at=" 50 " GREATEST (mtfk.private_key_deleted_at,$3)" 51 " FROM merchant_token_families mtf" 52 " WHERE (mtf.token_family_serial = mtfk.token_family_serial)" 53 " AND (mtf.slug=$1)" 54 " AND ($2 >= mtfk.signature_validity_start)" 55 " AND ($2 <= mtfk.signature_validity_end)" 56 " AND ($3 > mtfk.private_key_deleted_at)" 57 " AND (mtfk.priv IS NOT NULL)"); 58 qs = GNUNET_PQ_eval_prepared_non_select (pg->conn, 59 "", 60 params); 61 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 62 "Extending MTFK %s valid at %llu to sign until %llu got %d\n", 63 token_family_slug, 64 (unsigned long long) valid_at.abs_time.abs_value_us, 65 (unsigned long long) sign_until.abs_time.abs_value_us, 66 (int) qs); 67 return qs; 68 }