taler-auditor-httpd_get-monitoring-closure-lags.c (4360B)
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-closure-lags.h" 25 #include "auditor-database/get_auditor_closure_lags.h" 26 #include "auditor-database/preflight.h" 27 28 29 /** 30 * Add closure-lags 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 process_closure_lags ( 38 void *cls, 39 const struct TALER_AUDITORDB_ClosureLags *dc) 40 { 41 json_t *list = cls; 42 json_t *obj; 43 44 obj = GNUNET_JSON_PACK ( 45 GNUNET_JSON_pack_uint64 ("row_id", 46 dc->row_id), 47 GNUNET_JSON_pack_uint64 ("problem_row_id", 48 dc->problem_row_id), 49 TALER_JSON_pack_amount ("amount", 50 &dc->amount), 51 TALER_JSON_pack_time_abs_human ("deadline", 52 dc->deadline), 53 GNUNET_JSON_pack_data_auto ("wtid", 54 &dc->wtid), 55 TALER_JSON_pack_full_payto ("account", 56 dc->account), 57 GNUNET_JSON_pack_bool ("suppressed", 58 dc->suppressed) 59 ); 60 GNUNET_break (0 == 61 json_array_append_new (list, 62 obj)); 63 64 65 return GNUNET_OK; 66 } 67 68 69 MHD_RESULT 70 TAH_get_monitoring_closure_lags ( 71 struct TAH_RequestHandler *rh, 72 struct MHD_Connection *connection, 73 void **connection_cls, 74 const char *upload_data, 75 size_t *upload_data_size, 76 const char *const args[]) 77 { 78 json_t *ja; 79 enum GNUNET_DB_QueryStatus qs; 80 int64_t limit = -20; 81 uint64_t offset; 82 bool return_suppressed = false; 83 84 if (GNUNET_SYSERR == 85 TALER_AUDITORDB_preflight (TAH_apg)) 86 { 87 GNUNET_break (0); 88 return TALER_MHD_reply_with_error (connection, 89 MHD_HTTP_INTERNAL_SERVER_ERROR, 90 TALER_EC_GENERIC_DB_SETUP_FAILED, 91 NULL); 92 } 93 TALER_MHD_parse_request_snumber (connection, 94 "limit", 95 &limit); 96 if (limit < 0) 97 offset = INT64_MAX; 98 else 99 offset = 0; 100 TALER_MHD_parse_request_number (connection, 101 "offset", 102 &offset); 103 { 104 const char *ret_s 105 = MHD_lookup_connection_value (connection, 106 MHD_GET_ARGUMENT_KIND, 107 "return_suppressed"); 108 if (ret_s != NULL && strcmp (ret_s, "true") == 0) 109 { 110 return_suppressed = true; 111 } 112 } 113 ja = json_array (); 114 GNUNET_break (NULL != ja); 115 qs = TALER_AUDITORDB_get_auditor_closure_lags ( 116 TAH_apg, 117 limit, 118 offset, 119 return_suppressed, 120 &process_closure_lags, 121 ja); 122 if (0 > qs) 123 { 124 GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); 125 json_decref (ja); 126 TALER_LOG_WARNING ( 127 "Failed to handle GET /closure-lags\n"); 128 return TALER_MHD_reply_with_error (connection, 129 MHD_HTTP_INTERNAL_SERVER_ERROR, 130 TALER_EC_GENERIC_DB_FETCH_FAILED, 131 "get_auditor_closure_lags"); 132 } 133 return TALER_MHD_REPLY_JSON_PACK ( 134 connection, 135 MHD_HTTP_OK, 136 GNUNET_JSON_pack_array_steal ("closure_lags", 137 ja)); 138 }