taler-auditor-httpd_get-monitoring-purse-not-closed-inconsistencies.c (4537B)
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-purse-not-closed-inconsistencies.h" 25 #define TALER_AUDITORDB_PURSE_NOT_CLOSED_INCONSISTENCIES_RESULT_CLOSURE json_t 26 #include "auditor-database/iterate_purse_not_closed_inconsistencies.h" 27 #include "auditor-database/preflight.h" 28 29 /** 30 * Add purse-not-closed-inconsistencies to the list. 31 * 32 * @param[in,out] list 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_purse_not_closed_inconsistencies ( 38 json_t *list, 39 const struct TALER_AUDITORDB_PurseNotClosedInconsistencies *dc) 40 { 41 json_t *obj; 42 43 obj = GNUNET_JSON_PACK ( 44 GNUNET_JSON_pack_uint64 ("row_id", 45 dc->row_id), 46 GNUNET_JSON_pack_data_auto ("purse_pub", 47 &dc->purse_pub), 48 TALER_JSON_pack_amount ("amount", 49 &dc->amount), 50 GNUNET_JSON_pack_timestamp ("expiration_date", 51 GNUNET_TIME_absolute_to_timestamp ( 52 dc->expiration_date)), 53 GNUNET_JSON_pack_bool ("suppressed", 54 dc->suppressed) 55 ); 56 GNUNET_break (0 == 57 json_array_append_new (list, 58 obj)); 59 return GNUNET_OK; 60 } 61 62 63 enum MHD_Result 64 TAH_get_monitoring_purse_not_closed_inconsistencies ( 65 struct TAH_RequestHandler *rh, 66 struct MHD_Connection *connection, 67 void **connection_cls, 68 const char *upload_data, 69 size_t *upload_data_size, 70 const char *const args[]) 71 { 72 json_t *ja; 73 enum GNUNET_DB_QueryStatus qs; 74 int64_t limit = -20; 75 uint64_t offset; 76 bool return_suppressed = false; 77 78 (void) rh; 79 (void) connection_cls; 80 (void) upload_data; 81 (void) upload_data_size; 82 if (GNUNET_SYSERR == 83 TALER_AUDITORDB_preflight (TAH_apg)) 84 { 85 GNUNET_break (0); 86 return TALER_MHD_reply_with_error (connection, 87 MHD_HTTP_INTERNAL_SERVER_ERROR, 88 TALER_EC_GENERIC_DB_SETUP_FAILED, 89 NULL); 90 } 91 TAH_PARSE_REQUEST_LIMIT (connection, 92 "limit", 93 &limit); 94 if (limit < 0) 95 offset = TAH_SAFE_UINT64_MAX; 96 else 97 offset = 0; 98 TAH_PARSE_SAFE_REQUEST_NUMBER (connection, 99 "offset", 100 &offset); 101 102 { 103 const char *ret_s 104 = MHD_lookup_connection_value (connection, 105 MHD_GET_ARGUMENT_KIND, 106 "return_suppressed"); 107 108 if ( (NULL != ret_s) && 109 (0 == strcmp (ret_s, 110 "true")) ) 111 { 112 return_suppressed = true; 113 } 114 } 115 116 ja = json_array (); 117 GNUNET_break (NULL != ja); 118 qs = TALER_AUDITORDB_iterate_purse_not_closed_inconsistencies ( 119 TAH_apg, 120 limit, 121 offset, 122 return_suppressed, 123 &process_purse_not_closed_inconsistencies, 124 ja); 125 126 if (0 > qs) 127 { 128 GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); 129 json_decref (ja); 130 TALER_LOG_WARNING ( 131 "Failed to handle GET /purse-not-closed-inconsistencies\n"); 132 return TALER_MHD_reply_with_error (connection, 133 MHD_HTTP_INTERNAL_SERVER_ERROR, 134 TALER_EC_GENERIC_DB_FETCH_FAILED, 135 "purse-not-closed-inconsistencies"); 136 } 137 return TAH_reply_json_records (connection, 138 ja); 139 }