Line data Source code
1 : /* 2 : This file is part of TALER 3 : Copyright (C) 2022 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 exchangedb/pg_iterate_auditor_denominations.c 18 : * @brief Implementation of the iterate_auditor_denominations function for Postgres 19 : * @author Christian Grothoff 20 : */ 21 : #include "platform.h" 22 : #include "taler_error_codes.h" 23 : #include "taler_dbevents.h" 24 : #include "taler_pq_lib.h" 25 : #include "pg_iterate_auditor_denominations.h" 26 : #include "pg_helper.h" 27 : 28 : /** 29 : * Closure for #auditor_denoms_cb_helper() 30 : */ 31 : struct AuditorDenomsIteratorContext 32 : { 33 : /** 34 : * Function to call with the results. 35 : */ 36 : TALER_EXCHANGEDB_AuditorDenominationsCallback cb; 37 : 38 : /** 39 : * Closure to pass to @e cb 40 : */ 41 : void *cb_cls; 42 : }; 43 : 44 : 45 : /** 46 : * Helper function for #TEH_PG_iterate_auditor_denominations(). 47 : * Calls the callback with each auditor and denomination pair. 48 : * 49 : * @param cls a `struct AuditorDenomsIteratorContext` 50 : * @param result db results 51 : * @param num_results number of results in @a result 52 : */ 53 : static void 54 89 : auditor_denoms_cb_helper (void *cls, 55 : PGresult *result, 56 : unsigned int num_results) 57 : { 58 89 : struct AuditorDenomsIteratorContext *dic = cls; 59 : 60 89 : for (unsigned int i = 0; i<num_results; i++) 61 : { 62 : struct TALER_AuditorPublicKeyP auditor_pub; 63 : struct TALER_DenominationHashP h_denom_pub; 64 : struct TALER_AuditorSignatureP auditor_sig; 65 0 : struct GNUNET_PQ_ResultSpec rs[] = { 66 0 : GNUNET_PQ_result_spec_auto_from_type ("auditor_pub", 67 : &auditor_pub), 68 0 : GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash", 69 : &h_denom_pub), 70 0 : GNUNET_PQ_result_spec_auto_from_type ("auditor_sig", 71 : &auditor_sig), 72 : GNUNET_PQ_result_spec_end 73 : }; 74 : 75 0 : if (GNUNET_OK != 76 0 : GNUNET_PQ_extract_result (result, 77 : rs, 78 : i)) 79 : { 80 0 : GNUNET_break (0); 81 0 : return; 82 : } 83 0 : dic->cb (dic->cb_cls, 84 : &auditor_pub, 85 : &h_denom_pub, 86 : &auditor_sig); 87 : } 88 : } 89 : 90 : 91 : enum GNUNET_DB_QueryStatus 92 89 : TEH_PG_iterate_auditor_denominations ( 93 : void *cls, 94 : TALER_EXCHANGEDB_AuditorDenominationsCallback cb, 95 : void *cb_cls) 96 : { 97 89 : struct PostgresClosure *pg = cls; 98 89 : struct GNUNET_PQ_QueryParam params[] = { 99 : GNUNET_PQ_query_param_end 100 : }; 101 89 : struct AuditorDenomsIteratorContext dic = { 102 : .cb = cb, 103 : .cb_cls = cb_cls, 104 : }; 105 : /* Used in #postgres_iterate_auditor_denominations() */ 106 89 : PREPARE (pg, 107 : "select_auditor_denoms", 108 : "SELECT" 109 : " auditors.auditor_pub" 110 : ",denominations.denom_pub_hash" 111 : ",auditor_denom_sigs.auditor_sig" 112 : " FROM auditor_denom_sigs" 113 : " JOIN auditors USING (auditor_uuid)" 114 : " JOIN denominations USING (denominations_serial)" 115 : " WHERE auditors.is_active;"); 116 89 : return GNUNET_PQ_eval_prepared_multi_select (pg->conn, 117 : "select_auditor_denoms", 118 : params, 119 : &auditor_denoms_cb_helper, 120 : &dic); 121 : }