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 <gnunet/gnunet_util_lib.h>
17 : #include <gnunet/gnunet_json_lib.h>
18 : #include <jansson.h>
19 : #include <microhttpd.h>
20 : #include <pthread.h>
21 : #include "taler/taler_json_lib.h"
22 : #include "taler/taler_mhd_lib.h"
23 : #include "taler-auditor-httpd.h"
24 : #include \
25 : "taler-auditor-httpd_get-monitoring-denomination-key-validity-withdraw-inconsistency.h"
26 : #define \
27 : TALER_AUDITORDB_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_RESULT_CLOSURE \
28 : json_t
29 : #include \
30 : "auditor-database/iterate_denomination_key_validity_withdraw_inconsistencies.h"
31 : #include "auditor-database/preflight.h"
32 :
33 : /**
34 : * Add denomination-key-validity-withdraw-inconsistency to the list.
35 : *
36 : * @param[in,out] list a `json_t *` array to extend
37 : * @param dc struct of inconsistencies
38 : * @return #GNUNET_OK to continue to iterate
39 : */
40 : static enum GNUNET_GenericReturnValue
41 0 : process_denomination_key_validity_withdraw_inconsistency (
42 : json_t *list,
43 : const struct TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency *dc)
44 : {
45 : json_t *obj;
46 :
47 0 : obj = GNUNET_JSON_PACK (
48 : GNUNET_JSON_pack_uint64 ("row_id",
49 : dc->row_id),
50 : GNUNET_JSON_pack_uint64 ("problem_row_id",
51 : dc->problem_row_id),
52 : TALER_JSON_pack_time_abs_human ("execution_date",
53 : dc->execution_date),
54 : GNUNET_JSON_pack_data_auto ("reserve_pub",
55 : &dc->reserve_pub),
56 : GNUNET_JSON_pack_data_auto ("h_denom_pub",
57 : &dc->denompub_h),
58 : GNUNET_JSON_pack_bool ("suppressed",
59 : dc->suppressed)
60 : );
61 0 : GNUNET_break (0 ==
62 : json_array_append_new (list,
63 : obj));
64 :
65 :
66 0 : return GNUNET_OK;
67 : }
68 :
69 :
70 : enum MHD_Result
71 0 : TAH_get_monitoring_denomination_key_validity_withdraw_inconsistency (
72 : struct TAH_RequestHandler *rh,
73 : struct MHD_Connection *connection,
74 : void **connection_cls,
75 : const char *upload_data,
76 : size_t *upload_data_size,
77 : const char *const args[])
78 : {
79 : json_t *ja;
80 : enum GNUNET_DB_QueryStatus qs;
81 0 : int64_t limit = -20;
82 : uint64_t offset;
83 0 : bool return_suppressed = false;
84 :
85 : (void) rh;
86 : (void) connection_cls;
87 : (void) upload_data;
88 : (void) upload_data_size;
89 0 : if (GNUNET_SYSERR ==
90 0 : TALER_AUDITORDB_preflight (TAH_apg))
91 : {
92 0 : GNUNET_break (0);
93 0 : return TALER_MHD_reply_with_error (connection,
94 : MHD_HTTP_INTERNAL_SERVER_ERROR,
95 : TALER_EC_GENERIC_DB_SETUP_FAILED,
96 : NULL);
97 : }
98 0 : TAH_PARSE_REQUEST_LIMIT (connection,
99 : "limit",
100 : &limit);
101 0 : if (limit < 0)
102 0 : offset = TAH_SAFE_UINT64_MAX;
103 : else
104 0 : offset = 0;
105 0 : TAH_PARSE_SAFE_REQUEST_NUMBER (connection,
106 : "offset",
107 : &offset);
108 : {
109 : const char *ret_s
110 0 : = MHD_lookup_connection_value (connection,
111 : MHD_GET_ARGUMENT_KIND,
112 : "return_suppressed");
113 0 : if (ret_s != NULL && strcmp (ret_s, "true") == 0)
114 : {
115 0 : return_suppressed = true;
116 : }
117 : }
118 0 : ja = json_array ();
119 0 : GNUNET_break (NULL != ja);
120 : qs =
121 0 : TALER_AUDITORDB_iterate_denomination_key_validity_withdraw_inconsistencies (
122 : TAH_apg,
123 : limit,
124 : offset,
125 : return_suppressed,
126 : &process_denomination_key_validity_withdraw_inconsistency,
127 : ja);
128 0 : if (0 > qs)
129 : {
130 0 : GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
131 0 : json_decref (ja);
132 0 : TALER_LOG_WARNING (
133 : "Failed to handle GET /denomination-key-validity-withdraw-inconsistency\n");
134 0 : return TALER_MHD_reply_with_error (connection,
135 : MHD_HTTP_INTERNAL_SERVER_ERROR,
136 : TALER_EC_GENERIC_DB_FETCH_FAILED,
137 : "denomination-key-validity-withdraw-inconsistency");
138 : }
139 0 : return TAH_reply_json_records (connection,
140 : ja);
141 : }
|