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