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/backenddb/iterate_outdated_kyc_statuses.c
18 : * @brief Implementation of the iterate_outdated_kyc_statuses function for Postgres
19 : * @author Christian Grothoff
20 : */
21 : #include "platform.h"
22 : #include <taler/taler_error_codes.h>
23 : #include <taler/taler_dbevents.h>
24 : #include <taler/taler_pq_lib.h>
25 : #include "merchant-database/iterate_outdated_kyc_statuses.h"
26 : #include "helper.h"
27 :
28 : /**
29 : * Closure for kyc_status_cb().
30 : */
31 : struct KycStatusContext
32 : {
33 : /**
34 : * Function to call with results.
35 : */
36 : TALER_MERCHANTDB_KycOutdatedCallback kyc_cb;
37 :
38 : /**
39 : * Closure for @e kyc_cb.
40 : */
41 : void *kyc_cb_cls;
42 :
43 : /**
44 : * Number of results found.
45 : */
46 : unsigned int count;
47 :
48 : /**
49 : * Set to true on failure(s).
50 : */
51 : bool failure;
52 : };
53 :
54 :
55 : /**
56 : * Function to be called with the results of a SELECT statement
57 : * that has returned @a num_results results about accounts.
58 : *
59 : * @param[in,out] cls of type `struct KycStatusContext *`
60 : * @param result the postgres result
61 : * @param num_results the number of results in @a result
62 : */
63 : static void
64 0 : kyc_status_cb (void *cls,
65 : PGresult *result,
66 : unsigned int num_results)
67 : {
68 0 : struct KycStatusContext *ksc = cls;
69 :
70 0 : GNUNET_log (GNUNET_ERROR_TYPE_INFO,
71 : "Got %u outdated KYC records\n",
72 : num_results);
73 0 : for (unsigned int i = 0; i < num_results; i++)
74 : {
75 : struct TALER_MerchantWireHashP h_wire;
76 : char *exchange_url;
77 : char *instance_id;
78 0 : struct GNUNET_PQ_ResultSpec rs[] = {
79 0 : GNUNET_PQ_result_spec_auto_from_type ("out_h_wire",
80 : &h_wire),
81 0 : GNUNET_PQ_result_spec_string ("out_exchange_url",
82 : &exchange_url),
83 0 : GNUNET_PQ_result_spec_string ("out_merchant_id",
84 : &instance_id),
85 : GNUNET_PQ_result_spec_end
86 : };
87 :
88 0 : if (GNUNET_OK !=
89 0 : GNUNET_PQ_extract_result (result,
90 : rs,
91 : i))
92 : {
93 0 : GNUNET_break (0);
94 0 : ksc->failure = true;
95 0 : return;
96 : }
97 0 : ksc->count++;
98 0 : ksc->kyc_cb (ksc->kyc_cb_cls,
99 : instance_id,
100 : exchange_url,
101 : &h_wire);
102 0 : GNUNET_PQ_cleanup_result (rs);
103 : }
104 : }
105 :
106 :
107 : enum GNUNET_DB_QueryStatus
108 0 : TALER_MERCHANTDB_iterate_outdated_kyc_statuses (
109 : struct TALER_MERCHANTDB_PostgresContext *pg,
110 : TALER_MERCHANTDB_KycOutdatedCallback kyc_cb,
111 : void *kyc_cb_cls)
112 : {
113 0 : struct KycStatusContext ksc = {
114 : .kyc_cb = kyc_cb,
115 : .kyc_cb_cls = kyc_cb_cls
116 : };
117 : struct GNUNET_TIME_Absolute now
118 0 : = GNUNET_TIME_absolute_get ();
119 0 : struct GNUNET_PQ_QueryParam params[] = {
120 0 : GNUNET_PQ_query_param_absolute_time (&now),
121 : GNUNET_PQ_query_param_end
122 : };
123 : enum GNUNET_DB_QueryStatus qs;
124 :
125 0 : PREPARE (pg,
126 : "iterate_outdated_kyc_statuses",
127 : "SELECT"
128 : " out_merchant_id"
129 : " ,out_h_wire"
130 : " ,out_exchange_url"
131 : " FROM merchant.account_kyc_get_outdated($1)");
132 0 : qs = GNUNET_PQ_eval_prepared_multi_select (
133 : pg->conn,
134 : "iterate_outdated_kyc_statuses",
135 : params,
136 : &kyc_status_cb,
137 : &ksc);
138 0 : if (ksc.failure)
139 : {
140 0 : GNUNET_break (0);
141 0 : return GNUNET_DB_STATUS_HARD_ERROR;
142 : }
143 0 : if (0 > qs)
144 0 : return qs;
145 0 : return ksc.count;
146 : }
|