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