taler-auditor-httpd_reserve-in-inconsistency-get.c (4626B)
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 "taler-auditor-httpd_reserve-in-inconsistency-get.h" 26 27 28 /** 29 * Add reserve-in-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, #GNUNET_SYSERR to stop iterating 34 */ 35 static enum GNUNET_GenericReturnValue 36 process_reserve_in_inconsistency ( 37 void *cls, 38 const struct TALER_AUDITORDB_ReserveInInconsistency *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->serial_id), 46 GNUNET_JSON_pack_uint64 ("bank_row_id", 47 dc->bank_row_id), 48 TALER_JSON_pack_amount ("amount_exchange_expected", 49 &dc->amount_exchange_expected), 50 TALER_JSON_pack_amount ("amount_wired", 51 &dc->amount_wired), 52 GNUNET_JSON_pack_data_auto ("reserve_pub", 53 &dc->reserve_pub), 54 TALER_JSON_pack_time_abs_human ("timestamp", 55 dc->timestamp), 56 TALER_JSON_pack_full_payto ("account", 57 dc->account), 58 GNUNET_JSON_pack_string ("diagnostic", 59 dc->diagnostic), 60 GNUNET_JSON_pack_bool ("suppressed", 61 dc->suppressed) 62 ); 63 GNUNET_break (0 == 64 json_array_append_new (list, 65 obj)); 66 67 68 return GNUNET_OK; 69 } 70 71 72 MHD_RESULT 73 TAH_RESERVE_IN_INCONSISTENCY_handler_get ( 74 struct TAH_RequestHandler *rh, 75 struct MHD_Connection *connection, 76 void **connection_cls, 77 const char *upload_data, 78 size_t *upload_data_size, 79 const char *const args[]) 80 { 81 json_t *ja; 82 enum GNUNET_DB_QueryStatus qs; 83 int64_t limit = -20; 84 uint64_t offset; 85 bool return_suppressed = false; 86 87 (void) rh; 88 (void) connection_cls; 89 (void) upload_data; 90 (void) upload_data_size; 91 if (GNUNET_SYSERR == 92 TAH_plugin->preflight (TAH_plugin->cls)) 93 { 94 GNUNET_break (0); 95 return TALER_MHD_reply_with_error (connection, 96 MHD_HTTP_INTERNAL_SERVER_ERROR, 97 TALER_EC_GENERIC_DB_SETUP_FAILED, 98 NULL); 99 } 100 TALER_MHD_parse_request_snumber (connection, 101 "limit", 102 &limit); 103 if (limit < 0) 104 offset = INT64_MAX; 105 else 106 offset = 0; 107 TALER_MHD_parse_request_number (connection, 108 "offset", 109 &offset); 110 { 111 const char *ret_s 112 = MHD_lookup_connection_value (connection, 113 MHD_GET_ARGUMENT_KIND, 114 "return_suppressed"); 115 if ( (NULL != ret_s) && 116 (0 == strcmp (ret_s, 117 "true")) ) 118 { 119 return_suppressed = true; 120 } 121 } 122 ja = json_array (); 123 GNUNET_break (NULL != ja); 124 qs = TAH_plugin->get_reserve_in_inconsistency ( 125 TAH_plugin->cls, 126 limit, 127 offset, 128 return_suppressed, 129 &process_reserve_in_inconsistency, 130 ja); 131 if (0 > qs) 132 { 133 GNUNET_break (0); 134 json_decref (ja); 135 return TALER_MHD_reply_with_error (connection, 136 MHD_HTTP_INTERNAL_SERVER_ERROR, 137 TALER_EC_GENERIC_DB_FETCH_FAILED, 138 "reserve-in-inconsistency"); 139 } 140 return TALER_MHD_REPLY_JSON_PACK ( 141 connection, 142 MHD_HTTP_OK, 143 GNUNET_JSON_pack_array_steal ("reserve_in_inconsistency", 144 ja)); 145 }