Line data Source code
1 : /*
2 : This file is part of TALER
3 : Copyright (C) 2025 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_order_token_blinded_sigs.c
18 : * @brief Implementation of the select blinded sigs by order_id function for Postgres
19 : * @author Bohdan Potuzhnyi
20 : */
21 : #include "platform.h"
22 : #include <taler/taler_pq_lib.h>
23 : #include "merchant-database/iterate_order_token_blinded_sigs.h"
24 : #include "helper.h"
25 :
26 : /**
27 : * @brief Context for the callback to handle the result of the blinded sigs selection.
28 : */
29 : struct SelectBlindedSigsContext
30 : {
31 : /**
32 : * @brief Callback to be called with the result of the blinded sigs selection.
33 : */
34 : void *cb_cls;
35 :
36 : /**
37 : * @brief Callback to be called with the result of the blinded sigs selection.
38 : */
39 : TALER_MERCHANTDB_BlindedSigCallback cb;
40 :
41 : /**
42 : * @brief Result status of the query.
43 : */
44 : enum GNUNET_DB_QueryStatus qs;
45 : };
46 :
47 :
48 : /**
49 : * @brief Callback to handle the result of the blinded sigs selection.
50 : *
51 : * @param cls the closure containing the callback and its context
52 : * @param result the result of the query
53 : * @param num_results number of results in the result set
54 : */
55 : static void
56 4 : restore_sig_cb (void *cls,
57 : PGresult *result,
58 : unsigned int num_results)
59 : {
60 4 : struct SelectBlindedSigsContext *ctx = cls;
61 :
62 4 : for (unsigned int i = 0; i < num_results; i++)
63 : {
64 : struct GNUNET_HashCode h_issue;
65 : struct GNUNET_CRYPTO_BlindedSignature *sig;
66 0 : struct GNUNET_PQ_ResultSpec rs[] = {
67 0 : GNUNET_PQ_result_spec_auto_from_type ("token_hash",
68 : &h_issue),
69 0 : GNUNET_PQ_result_spec_blinded_sig ("token_blinded_signature",
70 : &sig),
71 : GNUNET_PQ_result_spec_end
72 : };
73 :
74 0 : if (GNUNET_OK !=
75 0 : GNUNET_PQ_extract_result (result,
76 : rs,
77 : i))
78 : {
79 0 : ctx->qs = GNUNET_DB_STATUS_HARD_ERROR;
80 0 : return;
81 : }
82 0 : ctx->cb (ctx->cb_cls,
83 : &h_issue,
84 : sig);
85 0 : GNUNET_PQ_cleanup_result (rs);
86 : }
87 : }
88 :
89 :
90 : enum GNUNET_DB_QueryStatus
91 4 : TALER_MERCHANTDB_iterate_order_token_blinded_sigs (
92 : struct TALER_MERCHANTDB_PostgresContext *pg,
93 : const char *order_id,
94 : TALER_MERCHANTDB_BlindedSigCallback cb,
95 : void *cb_cls)
96 : {
97 4 : struct SelectBlindedSigsContext ctx = {
98 : .cb = cb,
99 : .cb_cls = cb_cls,
100 : .qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
101 : };
102 4 : struct GNUNET_PQ_QueryParam params[] = {
103 4 : GNUNET_PQ_query_param_string (order_id),
104 : GNUNET_PQ_query_param_end
105 : };
106 : enum GNUNET_DB_QueryStatus qs;
107 :
108 4 : GNUNET_assert (NULL != pg->current_merchant_id);
109 4 : TMH_PQ_prepare_anon (pg,
110 : "SELECT"
111 : " motbs.token_blinded_signature"
112 : " ,motbs.token_hash"
113 : " FROM merchant_order_token_blinded_sigs AS motbs"
114 : " JOIN merchant_contract_terms AS mct USING (order_serial)"
115 : " WHERE mct.order_id = $1"
116 : " ORDER BY motbs.token_index ASC");
117 4 : qs = GNUNET_PQ_eval_prepared_multi_select (
118 : pg->conn,
119 : "",
120 : params,
121 : &restore_sig_cb,
122 : &ctx);
123 : /* propagate an extraction failure recorded by the row callback */
124 4 : if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != ctx.qs)
125 0 : return ctx.qs;
126 4 : return qs;
127 : }
|