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_patch-generic-suppressed.h"
25 : #include "auditor-database/preflight.h"
26 : #include "auditor-database/update_to_suppressed.h"
27 :
28 :
29 : enum MHD_Result
30 0 : TAH_patch_generic_suppressed (
31 : struct TAH_RequestHandler *rh,
32 : struct MHD_Connection *connection,
33 : void **connection_cls,
34 : const char *upload_data,
35 : size_t *upload_data_size,
36 : const char *const args[])
37 : {
38 : enum GNUNET_DB_QueryStatus qs;
39 : unsigned long long row_id;
40 : char dummy;
41 : bool suppressed;
42 :
43 : (void) connection_cls;
44 0 : if (GNUNET_SYSERR ==
45 0 : TALER_AUDITORDB_preflight (TAH_apg))
46 : {
47 0 : GNUNET_break (0);
48 0 : return TALER_MHD_reply_with_error (connection,
49 : MHD_HTTP_INTERNAL_SERVER_ERROR,
50 : TALER_EC_GENERIC_DB_SETUP_FAILED,
51 : NULL);
52 : }
53 :
54 : /* The URL is "/monitoring/$TABLE/$ROW_ID", so the row ID is args[2]. */
55 0 : if ( (NULL == args[2]) ||
56 0 : (1 != sscanf (args[2],
57 : "%llu%c",
58 : &row_id,
59 0 : &dummy)) ||
60 0 : (row_id > TAH_SAFE_UINT64_MAX) )
61 : {
62 0 : GNUNET_break_op (0);
63 0 : return TALER_MHD_reply_with_error (connection,
64 : MHD_HTTP_BAD_REQUEST,
65 : TALER_EC_GENERIC_PARAMETER_MALFORMED,
66 : "no row id specified");
67 : }
68 :
69 : {
70 : enum GNUNET_GenericReturnValue res;
71 : json_t *json;
72 : struct GNUNET_JSON_Specification spec[] = {
73 0 : GNUNET_JSON_spec_bool ("suppressed", &suppressed),
74 0 : GNUNET_JSON_spec_end ()
75 : };
76 :
77 0 : res = TALER_MHD_parse_post_json (connection,
78 : connection_cls,
79 : upload_data,
80 : upload_data_size,
81 : &json);
82 0 : if (GNUNET_SYSERR == res)
83 0 : return MHD_NO;
84 0 : if ((GNUNET_NO == res) ||
85 0 : (NULL == json))
86 0 : return MHD_YES;
87 0 : res = TALER_MHD_parse_json_data (connection,
88 : json,
89 : spec);
90 0 : if (GNUNET_SYSERR == res)
91 : {
92 0 : GNUNET_break (0);
93 0 : json_decref (json);
94 0 : return MHD_NO; /* hard failure */
95 : }
96 0 : if (GNUNET_NO == res)
97 : {
98 0 : GNUNET_break_op (0);
99 0 : json_decref (json);
100 0 : return MHD_YES; /* failure */
101 : }
102 0 : json_decref (json);
103 : }
104 :
105 : /* execute transaction */
106 0 : qs = TALER_AUDITORDB_update_to_suppressed (TAH_apg,
107 : rh->table,
108 : row_id,
109 : suppressed);
110 :
111 0 : switch (qs)
112 : {
113 0 : case GNUNET_DB_STATUS_HARD_ERROR:
114 0 : GNUNET_break (0);
115 0 : return TALER_MHD_reply_with_error (connection,
116 : MHD_HTTP_INTERNAL_SERVER_ERROR,
117 : TALER_EC_GENERIC_DB_STORE_FAILED,
118 : "update_to_suppressed");
119 0 : case GNUNET_DB_STATUS_SOFT_ERROR:
120 0 : GNUNET_break (0);
121 0 : return TALER_MHD_reply_with_error (connection,
122 : MHD_HTTP_INTERNAL_SERVER_ERROR,
123 : TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
124 : "unexpected serialization problem");
125 0 : case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
126 0 : return TALER_MHD_reply_with_error (connection,
127 : MHD_HTTP_NOT_FOUND,
128 : TALER_EC_AUDITOR_RESOURCE_NOT_FOUND,
129 : "no updates executed");
130 0 : case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
131 0 : return TALER_MHD_reply_static (connection,
132 : MHD_HTTP_NO_CONTENT,
133 : NULL,
134 : NULL,
135 : 0);
136 : }
137 0 : GNUNET_break (0);
138 0 : return MHD_NO;
139 : }
|