Line data Source code
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 : #include "platform.h"
17 : #include "taler_error_codes.h"
18 : #include "taler_dbevents.h"
19 : #include "taler_pq_lib.h"
20 : #include "pg_helper.h"
21 : #include "pg_get_fee_time_inconsistency.h"
22 :
23 :
24 : /**
25 : * Closure for #feetimeinconsistency_cb().
26 : */
27 : struct FeeTimeInconsistencyContext
28 : {
29 :
30 : /**
31 : * Function to call for each fee time inconsistency
32 : */
33 : TALER_AUDITORDB_FeeTimeInconsistencyCallback cb;
34 :
35 : /**
36 : * Closure for @e cb
37 : */
38 : void *cb_cls;
39 :
40 : /**
41 : * Plugin context.
42 : */
43 : struct PostgresClosure *pg;
44 :
45 : /**
46 : * Query status to return.
47 : */
48 : enum GNUNET_DB_QueryStatus qs;
49 : };
50 :
51 :
52 : /**
53 : * Helper function for #TAH_PG_get_emergency().
54 : * To be called with the results of a SELECT statement
55 : * that has returned @a num_results results.
56 : *
57 : * @param cls closure of type `struct Emergency *`
58 : * @param result the postgres result
59 : * @param num_results the number of results in @a result
60 : */
61 : static void
62 0 : fee_time_inconsistency_cb (void *cls,
63 : PGresult *result,
64 : unsigned int num_results)
65 : {
66 0 : struct FeeTimeInconsistencyContext *dcc = cls;
67 0 : for (unsigned int i = 0; i < num_results; i++)
68 : {
69 : struct TALER_AUDITORDB_FeeTimeInconsistency dc;
70 0 : struct GNUNET_PQ_ResultSpec rs[] = {
71 0 : GNUNET_PQ_result_spec_uint64 ("row_id",
72 : &dc.row_id),
73 0 : GNUNET_PQ_result_spec_uint64 ("problem_row_id",
74 : &dc.problem_row_id),
75 0 : GNUNET_PQ_result_spec_string ("fee_type",
76 : &dc.type),
77 0 : GNUNET_PQ_result_spec_absolute_time ("fee_time",
78 : &dc.time),
79 0 : GNUNET_PQ_result_spec_string ("diagnostic",
80 : &dc.diagnostic),
81 : GNUNET_PQ_result_spec_end
82 : };
83 : enum GNUNET_GenericReturnValue rval;
84 :
85 0 : if (GNUNET_OK !=
86 0 : GNUNET_PQ_extract_result (result,
87 : rs,
88 : i))
89 : {
90 0 : GNUNET_break (0);
91 0 : dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
92 0 : return;
93 : }
94 0 : dcc->qs = i + 1;
95 0 : rval = dcc->cb (dcc->cb_cls,
96 : &dc);
97 0 : GNUNET_PQ_cleanup_result (rs);
98 0 : if (GNUNET_OK != rval)
99 0 : break;
100 : }
101 : }
102 :
103 :
104 : enum GNUNET_DB_QueryStatus
105 0 : TAH_PG_get_fee_time_inconsistency (
106 : void *cls,
107 : int64_t limit,
108 : uint64_t offset,
109 : bool return_suppressed,
110 : TALER_AUDITORDB_FeeTimeInconsistencyCallback cb,
111 : void *cb_cls)
112 : {
113 0 : struct PostgresClosure *pg = cls;
114 0 : uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit);
115 0 : struct GNUNET_PQ_QueryParam params[] = {
116 0 : GNUNET_PQ_query_param_uint64 (&offset),
117 0 : GNUNET_PQ_query_param_bool (return_suppressed),
118 0 : GNUNET_PQ_query_param_uint64 (&plimit),
119 : GNUNET_PQ_query_param_end
120 : };
121 0 : struct FeeTimeInconsistencyContext dcc = {
122 : .cb = cb,
123 : .cb_cls = cb_cls,
124 : .pg = pg
125 : };
126 : enum GNUNET_DB_QueryStatus qs;
127 :
128 0 : PREPARE (pg,
129 : "auditor_fee_time_inconsistency_get_desc",
130 : "SELECT"
131 : " row_id"
132 : ",problem_row_id"
133 : ",fee_type"
134 : ",fee_time"
135 : ",diagnostic"
136 : " FROM auditor_fee_time_inconsistency"
137 : " WHERE (row_id < $1)"
138 : " AND ($2 OR NOT suppressed)"
139 : " ORDER BY row_id DESC"
140 : " LIMIT $3"
141 : );
142 0 : PREPARE (pg,
143 : "auditor_fee_time_inconsistency_get_asc",
144 : "SELECT"
145 : " row_id"
146 : ",problem_row_id"
147 : ",fee_type"
148 : ",fee_time"
149 : ",diagnostic"
150 : " FROM auditor_fee_time_inconsistency"
151 : " WHERE (row_id > $1)"
152 : " AND ($2 OR NOT suppressed)"
153 : " ORDER BY row_id ASC"
154 : " LIMIT $3"
155 : );
156 0 : qs = GNUNET_PQ_eval_prepared_multi_select (
157 : pg->conn,
158 : (limit > 0)
159 : ? "auditor_fee_time_inconsistency_get_asc"
160 : : "auditor_fee_time_inconsistency_get_desc",
161 : params,
162 : &fee_time_inconsistency_cb,
163 : &dcc);
164 0 : if (qs > 0)
165 0 : return dcc.qs;
166 0 : GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
167 0 : return qs;
168 : }
|