Line data Source code
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/auditordb/iterate_aml_staff.c
18 : * @brief Implementation of the iterate_aml_staff function for Postgres
19 : * @author Christian Grothoff
20 : */
21 : #include "taler/taler_error_codes.h"
22 : #include "taler/taler_pq_lib.h"
23 : #include "pg_helper.h"
24 : #include "auditor-database/iterate_aml_staff.h"
25 :
26 :
27 : /**
28 : * Closure for #aml_staff_cb().
29 : */
30 : struct AmlStaffContext
31 : {
32 : /**
33 : * Function to call for each status change.
34 : */
35 : TALER_AUDITORDB_AmlStaffCallback cb;
36 :
37 : /**
38 : * Closure for @e cb.
39 : */
40 : void *cb_cls;
41 :
42 : /**
43 : * Query status to return.
44 : */
45 : enum GNUNET_DB_QueryStatus qs;
46 : };
47 :
48 :
49 : /**
50 : * Helper function for #TALER_AUDITORDB_iterate_aml_staff().
51 : * To be called with the results of a SELECT statement
52 : * that has returned @a num_results results.
53 : *
54 : * @param cls closure of type `struct AmlStaffContext *`
55 : * @param result the postgres result
56 : * @param num_results the number of results in @a result
57 : */
58 : static void
59 0 : aml_staff_cb (void *cls,
60 : PGresult *result,
61 : unsigned int num_results)
62 : {
63 0 : struct AmlStaffContext *asc = cls;
64 :
65 0 : for (unsigned int i = 0; i < num_results; i++)
66 : {
67 : struct TALER_AmlOfficerPublicKeyP decider_pub;
68 0 : char *decider_name = NULL;
69 : bool is_active;
70 : bool read_only;
71 : bool master_sig_valid;
72 : struct GNUNET_TIME_Timestamp last_change;
73 0 : struct GNUNET_PQ_ResultSpec rs[] = {
74 0 : GNUNET_PQ_result_spec_auto_from_type ("decider_pub",
75 : &decider_pub),
76 0 : GNUNET_PQ_result_spec_string ("decider_name",
77 : &decider_name),
78 0 : GNUNET_PQ_result_spec_bool ("is_active",
79 : &is_active),
80 0 : GNUNET_PQ_result_spec_bool ("read_only",
81 : &read_only),
82 0 : GNUNET_PQ_result_spec_bool ("master_sig_valid",
83 : &master_sig_valid),
84 0 : GNUNET_PQ_result_spec_timestamp ("last_change",
85 : &last_change),
86 : GNUNET_PQ_result_spec_end
87 : };
88 : enum GNUNET_GenericReturnValue rval;
89 :
90 0 : if (GNUNET_OK !=
91 0 : GNUNET_PQ_extract_result (result,
92 : rs,
93 : i))
94 : {
95 0 : GNUNET_break (0);
96 0 : asc->qs = GNUNET_DB_STATUS_HARD_ERROR;
97 0 : return;
98 : }
99 0 : asc->qs = i + 1;
100 0 : rval = asc->cb (asc->cb_cls,
101 : &decider_pub,
102 : decider_name,
103 : is_active,
104 : read_only,
105 : master_sig_valid,
106 : last_change);
107 0 : GNUNET_PQ_cleanup_result (rs);
108 0 : if (GNUNET_OK != rval)
109 0 : break;
110 : }
111 : }
112 :
113 :
114 : enum GNUNET_DB_QueryStatus
115 0 : TALER_AUDITORDB_iterate_aml_staff (
116 : struct TALER_AUDITORDB_PostgresContext *pg,
117 : TALER_AUDITORDB_AmlStaffCallback cb,
118 : TALER_AUDITORDB_AML_STAFF_RESULT_CLOSURE *cb_cls)
119 : {
120 0 : struct GNUNET_PQ_QueryParam params[] = {
121 : GNUNET_PQ_query_param_end
122 : };
123 0 : struct AmlStaffContext asc = {
124 : .cb = cb,
125 : .cb_cls = cb_cls
126 : };
127 : enum GNUNET_DB_QueryStatus qs;
128 :
129 0 : PREPARE (pg,
130 : "iterate_aml_staff",
131 : "SELECT"
132 : " decider_pub"
133 : ",decider_name"
134 : ",is_active"
135 : ",read_only"
136 : ",master_sig_valid"
137 : ",last_change"
138 : " FROM auditor_aml_staff"
139 : " ORDER BY last_change ASC, row_id ASC;");
140 0 : qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
141 : "iterate_aml_staff",
142 : params,
143 : &aml_staff_cb,
144 : &asc);
145 0 : if (qs > 0)
146 0 : return asc.qs;
147 0 : GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
148 0 : return qs;
149 : }
|