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