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-progress.h"
25 : #include "auditor-database/get_progress_points.h"
26 : #include "auditor-database/preflight.h"
27 :
28 :
29 : /**
30 : * Add progress to the list.
31 : *
32 : * @param[in,out] cls a `json_t *` array to extend
33 : * @param dc struct with progress data
34 : * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
35 : */
36 : static enum GNUNET_GenericReturnValue
37 0 : process_progress (
38 : void *cls,
39 : const struct TALER_AUDITORDB_Progress *dc)
40 : {
41 0 : json_t *list = cls;
42 : json_t *obj;
43 :
44 0 : obj = GNUNET_JSON_PACK (
45 : GNUNET_JSON_pack_string ("progress_key",
46 : dc->progress_key),
47 : GNUNET_JSON_pack_int64 ("progress_offset",
48 : dc->progress_offset)
49 : );
50 0 : GNUNET_break (0 ==
51 : json_array_append_new (list,
52 : obj));
53 0 : return GNUNET_OK;
54 : }
55 :
56 :
57 : MHD_RESULT
58 0 : TAH_get_monitoring_progress (
59 : struct TAH_RequestHandler *rh,
60 : struct MHD_Connection *connection,
61 : void **connection_cls,
62 : const char *upload_data,
63 : size_t *upload_data_size,
64 : const char *const args[])
65 : {
66 : json_t *ja;
67 : enum GNUNET_DB_QueryStatus qs;
68 : const char *progress_key;
69 :
70 : (void) rh;
71 : (void) connection_cls;
72 : (void) upload_data;
73 : (void) upload_data_size;
74 0 : if (GNUNET_SYSERR ==
75 0 : TALER_AUDITORDB_preflight (TAH_apg))
76 : {
77 0 : GNUNET_break (0);
78 0 : return TALER_MHD_reply_with_error (connection,
79 : MHD_HTTP_INTERNAL_SERVER_ERROR,
80 : TALER_EC_GENERIC_DB_SETUP_FAILED,
81 : NULL);
82 : }
83 : progress_key
84 0 : = MHD_lookup_connection_value (connection,
85 : MHD_GET_ARGUMENT_KIND,
86 : "progress_key");
87 0 : ja = json_array ();
88 0 : GNUNET_break (NULL != ja);
89 0 : qs = TALER_AUDITORDB_get_progress_points (
90 : TAH_apg,
91 : progress_key,
92 : &process_progress,
93 : ja);
94 0 : if (0 > qs)
95 : {
96 0 : GNUNET_break (0);
97 0 : json_decref (ja);
98 0 : return TALER_MHD_reply_with_error (connection,
99 : MHD_HTTP_INTERNAL_SERVER_ERROR,
100 : TALER_EC_GENERIC_DB_FETCH_FAILED,
101 : "progress");
102 : }
103 0 : return TALER_MHD_REPLY_JSON_PACK (
104 : connection,
105 : MHD_HTTP_OK,
106 : GNUNET_JSON_pack_array_steal ("progress",
107 : ja));
108 : }
|