taler-auditor-httpd_get-monitoring-denomination-key-validity-withdraw-inconsistency.c (4717B)
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-denomination-key-validity-withdraw-inconsistency.h" 26 #include \ 27 "auditor-database/get_denomination_key_validity_withdraw_inconsistency.h" 28 #include "auditor-database/preflight.h" 29 30 /** 31 * Add denomination-key-validity-withdraw-inconsistency to the list. 32 * 33 * @param[in,out] cls a `json_t *` array to extend 34 * @param dc struct of inconsistencies 35 * @return #GNUNET_OK to continue to iterate 36 */ 37 static enum GNUNET_GenericReturnValue 38 process_denomination_key_validity_withdraw_inconsistency ( 39 void *cls, 40 const struct TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency *dc) 41 { 42 json_t *list = cls; 43 json_t *obj; 44 45 obj = GNUNET_JSON_PACK ( 46 GNUNET_JSON_pack_uint64 ("row_id", 47 dc->row_id), 48 GNUNET_JSON_pack_uint64 ("problem_row_id", 49 dc->problem_row_id), 50 TALER_JSON_pack_time_abs_human ("execution_date", 51 dc->execution_date), 52 GNUNET_JSON_pack_data_auto ("reserve_pub", 53 &dc->reserve_pub), 54 GNUNET_JSON_pack_data_auto ("denompub_h", 55 &dc->denompub_h), 56 GNUNET_JSON_pack_bool ("suppressed", 57 dc->suppressed) 58 ); 59 GNUNET_break (0 == 60 json_array_append_new (list, 61 obj)); 62 63 64 return GNUNET_OK; 65 } 66 67 68 MHD_RESULT 69 TAH_get_monitoring_denomination_key_validity_withdraw_inconsistency ( 70 struct TAH_RequestHandler *rh, 71 struct MHD_Connection *connection, 72 void **connection_cls, 73 const char *upload_data, 74 size_t *upload_data_size, 75 const char *const args[]) 76 { 77 json_t *ja; 78 enum GNUNET_DB_QueryStatus qs; 79 int64_t limit = -20; 80 uint64_t offset; 81 bool return_suppressed = false; 82 83 (void) rh; 84 (void) connection_cls; 85 (void) upload_data; 86 (void) upload_data_size; 87 if (GNUNET_SYSERR == 88 TALER_AUDITORDB_preflight (TAH_apg)) 89 { 90 GNUNET_break (0); 91 return TALER_MHD_reply_with_error (connection, 92 MHD_HTTP_INTERNAL_SERVER_ERROR, 93 TALER_EC_GENERIC_DB_SETUP_FAILED, 94 NULL); 95 } 96 TALER_MHD_parse_request_snumber (connection, 97 "limit", 98 &limit); 99 if (limit < 0) 100 offset = INT64_MAX; 101 else 102 offset = 0; 103 TALER_MHD_parse_request_number (connection, 104 "offset", 105 &offset); 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_denomination_key_validity_withdraw_inconsistency ( 119 TAH_apg, 120 limit, 121 offset, 122 return_suppressed, 123 &process_denomination_key_validity_withdraw_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 /denomination-key-validity-withdraw-inconsistency\n"); 131 return TALER_MHD_reply_with_error (connection, 132 MHD_HTTP_INTERNAL_SERVER_ERROR, 133 TALER_EC_GENERIC_DB_FETCH_FAILED, 134 "denomination-key-validity-withdraw-inconsistency"); 135 } 136 return TALER_MHD_REPLY_JSON_PACK ( 137 connection, 138 MHD_HTTP_OK, 139 GNUNET_JSON_pack_array_steal ( 140 "denomination_key_validity_withdraw_inconsistency", 141 ja)); 142 }