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-reserve-balance-summary-wrong-inconsistency.h"
26 : #define \
27 : TALER_AUDITORDB_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY_RESULT_CLOSURE \
28 : json_t
29 : #include \
30 : "auditor-database/iterate_reserve_balance_summary_wrong_inconsistencies.h"
31 : #include "auditor-database/preflight.h"
32 :
33 :
34 : /**
35 : * Add reserve-balance-summary-wrong-inconsistency to the list.
36 : *
37 : * @param[in,out] list a `json_t *` array to extend
38 : * @param dc struct of inconsistencies
39 : * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
40 : */
41 : static enum GNUNET_GenericReturnValue
42 0 : process_reserve_balance_summary_wrong_inconsistency (
43 : json_t *list,
44 : const struct TALER_AUDITORDB_ReserveBalanceSummaryWrongInconsistency *dc)
45 : {
46 : json_t *obj;
47 :
48 0 : obj = GNUNET_JSON_PACK (
49 : GNUNET_JSON_pack_int64 ("row_id", dc->row_id),
50 : GNUNET_JSON_pack_data_auto ("reserve_pub", &dc->reserve_pub),
51 : TALER_JSON_pack_amount ("exchange_amount", &dc->exchange_amount),
52 : TALER_JSON_pack_amount ("auditor_amount", &dc->auditor_amount),
53 : GNUNET_JSON_pack_bool ("suppressed", dc->suppressed)
54 : );
55 0 : GNUNET_break (0 ==
56 : json_array_append_new (list,
57 : obj));
58 0 : return GNUNET_OK;
59 : }
60 :
61 :
62 : enum MHD_Result
63 0 : TAH_get_monitoring_reserve_balance_summary_wrong_inconsistency (
64 : struct TAH_RequestHandler *rh,
65 : struct MHD_Connection *connection,
66 : void **connection_cls,
67 : const char *upload_data,
68 : size_t *upload_data_size,
69 : const char *const args[])
70 : {
71 : json_t *ja;
72 : enum GNUNET_DB_QueryStatus qs;
73 0 : int64_t limit = -20;
74 : uint64_t offset;
75 0 : bool return_suppressed = false;
76 :
77 : (void) rh;
78 : (void) connection_cls;
79 : (void) upload_data;
80 : (void) upload_data_size;
81 0 : if (GNUNET_SYSERR ==
82 0 : TALER_AUDITORDB_preflight (TAH_apg))
83 : {
84 0 : GNUNET_break (0);
85 0 : return TALER_MHD_reply_with_error (connection,
86 : MHD_HTTP_INTERNAL_SERVER_ERROR,
87 : TALER_EC_GENERIC_DB_SETUP_FAILED,
88 : NULL);
89 : }
90 0 : TAH_PARSE_REQUEST_LIMIT (connection,
91 : "limit",
92 : &limit);
93 0 : if (limit < 0)
94 0 : offset = TAH_SAFE_UINT64_MAX;
95 : else
96 0 : offset = 0;
97 0 : TAH_PARSE_SAFE_REQUEST_NUMBER (connection,
98 : "offset",
99 : &offset);
100 : {
101 0 : const char *ret_s = MHD_lookup_connection_value (connection,
102 : MHD_GET_ARGUMENT_KIND,
103 : "return_suppressed");
104 :
105 0 : if (ret_s != NULL && strcmp (ret_s, "true") == 0)
106 : {
107 0 : return_suppressed = true;
108 : }
109 : }
110 0 : ja = json_array ();
111 0 : GNUNET_break (NULL != ja);
112 0 : qs = TALER_AUDITORDB_iterate_reserve_balance_summary_wrong_inconsistencies (
113 : TAH_apg,
114 : limit,
115 : offset,
116 : return_suppressed,
117 : &process_reserve_balance_summary_wrong_inconsistency,
118 : ja);
119 :
120 0 : if (0 > qs)
121 : {
122 0 : GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
123 0 : json_decref (ja);
124 0 : TALER_LOG_WARNING (
125 : "Failed to handle GET /reserve-balance-summary-wrong-inconsistency");
126 0 : return TALER_MHD_reply_with_error (
127 : connection,
128 : MHD_HTTP_INTERNAL_SERVER_ERROR,
129 : TALER_EC_GENERIC_DB_FETCH_FAILED,
130 : "reserve-balance-summary-wrong-inconsistency");
131 : }
132 0 : return TAH_reply_json_records (connection,
133 : ja);
134 : }
|