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