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 "platform.h"
17 : #include <gnunet/gnunet_util_lib.h>
18 : #include <gnunet/gnunet_json_lib.h>
19 : #include <jansson.h>
20 : #include <microhttpd.h>
21 : #include <pthread.h>
22 : #include "taler_json_lib.h"
23 : #include "taler_mhd_lib.h"
24 : #include "taler-auditor-httpd.h"
25 : #include "taler-auditor-httpd_misattribution-in-inconsistency-get.h"
26 :
27 :
28 : /**
29 : * Add misattribution-in-inconsistency to the list.
30 : *
31 : * @param[in,out] cls a `json_t *` array to extend
32 : * @param dc struct of inconsistencies
33 : * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
34 : */
35 : static enum GNUNET_GenericReturnValue
36 1 : process_misattribution_in_inconsistency (
37 : void *cls,
38 : const struct TALER_AUDITORDB_MisattributionInInconsistency *dc)
39 : {
40 1 : json_t *list = cls;
41 : json_t *obj;
42 :
43 1 : obj = GNUNET_JSON_PACK (
44 : GNUNET_JSON_pack_uint64 ("row_id",
45 : dc->row_id),
46 : TALER_JSON_pack_amount ("amount",
47 : &dc->amount),
48 : GNUNET_JSON_pack_uint64 ("bank_row",
49 : dc->bank_row),
50 : GNUNET_JSON_pack_data_auto ("reserve_pub",
51 : &dc->reserve_pub),
52 : GNUNET_JSON_pack_bool ("suppressed",
53 : dc->suppressed)
54 : );
55 1 : GNUNET_break (0 ==
56 : json_array_append_new (list,
57 : obj));
58 1 : return GNUNET_OK;
59 : }
60 :
61 :
62 : MHD_RESULT
63 1 : TAH_MISATTRIBUTION_IN_INCONSISTENCY_handler_get (
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 1 : int64_t limit = -20;
74 : uint64_t offset;
75 1 : bool return_suppressed = false;
76 :
77 : (void) rh;
78 : (void) connection_cls;
79 : (void) upload_data;
80 : (void) upload_data_size;
81 1 : if (GNUNET_SYSERR ==
82 1 : TAH_plugin->preflight (TAH_plugin->cls))
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 1 : TALER_MHD_parse_request_snumber (connection,
91 : "limit",
92 : &limit);
93 1 : if (limit < 0)
94 0 : offset = INT64_MAX;
95 : else
96 1 : offset = 0;
97 1 : TALER_MHD_parse_request_number (connection,
98 : "offset",
99 : &offset);
100 : {
101 : const char *ret_s
102 1 : = MHD_lookup_connection_value (connection,
103 : MHD_GET_ARGUMENT_KIND,
104 : "return_suppressed");
105 1 : if (ret_s != NULL && strcmp (ret_s, "true") == 0)
106 : {
107 0 : return_suppressed = true;
108 : }
109 : }
110 :
111 1 : ja = json_array ();
112 1 : GNUNET_break (NULL != ja);
113 1 : qs = TAH_plugin->get_misattribution_in_inconsistency (
114 1 : TAH_plugin->cls,
115 : limit,
116 : offset,
117 : return_suppressed,
118 : &process_misattribution_in_inconsistency,
119 : ja);
120 1 : 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 /misattribution-in-inconsistency");
126 0 : return TALER_MHD_reply_with_error (connection,
127 : MHD_HTTP_INTERNAL_SERVER_ERROR,
128 : TALER_EC_GENERIC_DB_FETCH_FAILED,
129 : "misattribution-in-inconsistency");
130 : }
131 1 : return TALER_MHD_REPLY_JSON_PACK (
132 : connection,
133 : MHD_HTTP_OK,
134 : GNUNET_JSON_pack_array_steal ("misattribution_in_inconsistency",
135 : ja));
136 : }
|