iterate_active_signing_keys.c (4002B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2024 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/donaudb/iterate_active_signing_keys.c 18 * @brief Implementation of the iterate_active_signing_keys function for Postgres 19 * @author Christian Grothoff 20 */ 21 #include <donau_config.h> 22 #include <taler/taler_error_codes.h> 23 #include <taler/taler_dbevents.h> 24 #include <taler/taler_pq_lib.h> 25 #include "iterate_active_signing_keys.h" 26 #include "helper.h" 27 28 /** 29 * Closure for #signkeys_cb_helper(). 30 */ 31 struct IterateActiveSigningKeysContext 32 { 33 /** 34 * Function to call per result. 35 */ 36 DONAUDB_IterateActiveSigningKeysCallback cb; 37 38 /** 39 * Closure for @e cb. 40 */ 41 void *cb_cls; 42 43 /** 44 * Flag set to #GNUNET_OK as long as everything is fine. 45 */ 46 enum GNUNET_GenericReturnValue status; 47 48 }; 49 50 /** 51 * Invoke the callback for each result. 52 * 53 * @param cls a `struct IterateActiveSigningKeysContext *` 54 * @param result SQL result 55 * @param num_results number of rows in @a result 56 */ 57 static void 58 signkeys_cb_helper (void *cls, 59 PGresult *result, 60 unsigned int num_results) 61 { 62 struct IterateActiveSigningKeysContext *ctx = cls; 63 64 for (unsigned int i = 0; i < num_results; i++) 65 { 66 struct DONAU_DonauPublicKeyP donau_pub; 67 struct DONAUDB_SignkeyMetaData meta; 68 69 struct GNUNET_PQ_ResultSpec rs[] = { 70 GNUNET_PQ_result_spec_auto_from_type ("donau_pub", 71 &donau_pub), 72 GNUNET_PQ_result_spec_timestamp ("valid_from", 73 &meta.valid_from), 74 GNUNET_PQ_result_spec_timestamp ("expire_sign", 75 &meta.expire_sign), 76 GNUNET_PQ_result_spec_timestamp ("expire_legal", 77 &meta.expire_legal), 78 GNUNET_PQ_result_spec_end 79 }; 80 81 if (GNUNET_OK != 82 GNUNET_PQ_extract_result (result, 83 rs, 84 i)) 85 { 86 GNUNET_break (0); 87 ctx->status = GNUNET_SYSERR; 88 return; 89 } 90 ctx->cb (ctx->cb_cls, 91 &donau_pub, 92 &meta); 93 GNUNET_PQ_cleanup_result (rs); 94 } 95 } 96 97 98 enum GNUNET_DB_QueryStatus 99 DONAUDB_iterate_active_signing_keys ( 100 struct DONAUDB_PostgresContext *ctx, 101 DONAUDB_IterateActiveSigningKeysCallback cb, 102 void *cb_cls) 103 { 104 struct GNUNET_TIME_Absolute now 105 = GNUNET_TIME_absolute_get (); 106 struct IterateActiveSigningKeysContext ictx = { 107 .cb = cb, 108 .cb_cls = cb_cls, 109 .status = GNUNET_OK 110 }; 111 struct GNUNET_PQ_QueryParam params[] = { 112 GNUNET_PQ_query_param_absolute_time (&now), 113 GNUNET_PQ_query_param_end 114 }; 115 enum GNUNET_DB_QueryStatus qs; 116 117 PREPARE (ctx, 118 "iterate_active_signing_keys", 119 "SELECT" 120 " donau_pub" 121 ",valid_from" 122 ",expire_sign" 123 ",expire_legal" 124 " FROM donau_sign_keys dsk" 125 " WHERE" 126 " expire_sign > $1"); 127 qs = GNUNET_PQ_eval_prepared_multi_select (ctx->conn, 128 "iterate_active_signing_keys", 129 params, 130 &signkeys_cb_helper, 131 &ictx); 132 if (GNUNET_OK != ictx.status) 133 { 134 GNUNET_break (0); 135 return GNUNET_DB_STATUS_HARD_ERROR; 136 } 137 return qs; 138 }