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