taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-get.c (4612B)
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 "taler/platform.h" 17 #include <gnunet/gnunet_util_lib.h> 18 #include <gnunet/gnunet_json_lib.h> 19 #include <jansson.h> 20 #include <microhttpd.h> 21 #include <pthread.h> 22 #include "taler/taler_json_lib.h" 23 #include "taler/taler_mhd_lib.h" 24 #include "taler-auditor-httpd.h" 25 #include \ 26 "taler-auditor-httpd_denomination-key-validity-withdraw-inconsistency-get.h" 27 28 /** 29 * Add denomination-key-validity-withdraw-inconsistency to the list. 30 * 31 * @param[in,out] cls a `json_t *` array to extend 32 * @param dc struct of inconsistencies 33 * @return #GNUNET_OK to continue to iterate 34 */ 35 static enum GNUNET_GenericReturnValue 36 process_denomination_key_validity_withdraw_inconsistency ( 37 void *cls, 38 const struct TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency *dc) 39 { 40 json_t *list = cls; 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_uint64 ("problem_row_id", 47 dc->problem_row_id), 48 TALER_JSON_pack_time_abs_human ("execution_date", 49 dc->execution_date), 50 GNUNET_JSON_pack_data_auto ("reserve_pub", 51 &dc->reserve_pub), 52 GNUNET_JSON_pack_data_auto ("denompub_h", 53 &dc->denompub_h), 54 GNUNET_JSON_pack_bool ("suppressed", 55 dc->suppressed) 56 ); 57 GNUNET_break (0 == 58 json_array_append_new (list, 59 obj)); 60 61 62 return GNUNET_OK; 63 } 64 65 66 MHD_RESULT 67 TAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_handler_get ( 68 struct TAH_RequestHandler *rh, 69 struct MHD_Connection *connection, 70 void **connection_cls, 71 const char *upload_data, 72 size_t *upload_data_size, 73 const char *const args[]) 74 { 75 json_t *ja; 76 enum GNUNET_DB_QueryStatus qs; 77 int64_t limit = -20; 78 uint64_t offset; 79 bool return_suppressed = false; 80 81 (void) rh; 82 (void) connection_cls; 83 (void) upload_data; 84 (void) upload_data_size; 85 if (GNUNET_SYSERR == 86 TAH_plugin->preflight (TAH_plugin->cls)) 87 { 88 GNUNET_break (0); 89 return TALER_MHD_reply_with_error (connection, 90 MHD_HTTP_INTERNAL_SERVER_ERROR, 91 TALER_EC_GENERIC_DB_SETUP_FAILED, 92 NULL); 93 } 94 TALER_MHD_parse_request_snumber (connection, 95 "limit", 96 &limit); 97 if (limit < 0) 98 offset = INT64_MAX; 99 else 100 offset = 0; 101 TALER_MHD_parse_request_number (connection, 102 "offset", 103 &offset); 104 { 105 const char *ret_s 106 = MHD_lookup_connection_value (connection, 107 MHD_GET_ARGUMENT_KIND, 108 "return_suppressed"); 109 if (ret_s != NULL && strcmp (ret_s, "true") == 0) 110 { 111 return_suppressed = true; 112 } 113 } 114 ja = json_array (); 115 GNUNET_break (NULL != ja); 116 qs = TAH_plugin->get_denomination_key_validity_withdraw_inconsistency ( 117 TAH_plugin->cls, 118 limit, 119 offset, 120 return_suppressed, 121 &process_denomination_key_validity_withdraw_inconsistency, 122 ja); 123 if (0 > qs) 124 { 125 GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); 126 json_decref (ja); 127 TALER_LOG_WARNING ( 128 "Failed to handle GET /denomination-key-validity-withdraw-inconsistency\n"); 129 return TALER_MHD_reply_with_error (connection, 130 MHD_HTTP_INTERNAL_SERVER_ERROR, 131 TALER_EC_GENERIC_DB_FETCH_FAILED, 132 "denomination-key-validity-withdraw-inconsistency"); 133 } 134 return TALER_MHD_REPLY_JSON_PACK ( 135 connection, 136 MHD_HTTP_OK, 137 GNUNET_JSON_pack_array_steal ( 138 "denomination_key_validity_withdraw_inconsistency", 139 ja)); 140 }