taler-auditor-httpd_get-monitoring-kycauth-in-inconsistency.c (4998B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2026 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 /** 17 * @file src/auditor/taler-auditor-httpd_get-monitoring-kycauth-in-inconsistency.c 18 * @brief return list of KYCAUTH incoming wire transfer inconsistencies 19 * @author Christian Grothoff 20 */ 21 #include <gnunet/gnunet_util_lib.h> 22 #include <gnunet/gnunet_json_lib.h> 23 #include <jansson.h> 24 #include <microhttpd.h> 25 #include <pthread.h> 26 #include "taler/taler_json_lib.h" 27 #include "taler/taler_mhd_lib.h" 28 #include "taler-auditor-httpd.h" 29 #include "taler-auditor-httpd_get-monitoring-kycauth-in-inconsistency.h" 30 #define TALER_AUDITORDB_KYCAUTH_IN_INCONSISTENCY_RESULT_CLOSURE json_t 31 #include "auditor-database/iterate_kycauth_in_inconsistencies.h" 32 #include "auditor-database/preflight.h" 33 34 35 /** 36 * Add kycauth-in-inconsistency to the list. 37 * 38 * @param[in,out] list a `json_t *` array to extend 39 * @param dc struct of inconsistencies 40 * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating 41 */ 42 static enum GNUNET_GenericReturnValue 43 process_kycauth_in_inconsistency ( 44 json_t *list, 45 const struct TALER_AUDITORDB_KycauthInInconsistency *dc) 46 { 47 json_t *obj; 48 49 obj = GNUNET_JSON_PACK ( 50 GNUNET_JSON_pack_uint64 ("row_id", 51 dc->serial_id), 52 GNUNET_JSON_pack_uint64 ("bank_row_id", 53 dc->bank_row_id), 54 TALER_JSON_pack_amount ("amount_exchange_expected", 55 &dc->amount_exchange_expected), 56 TALER_JSON_pack_amount ("amount_wired", 57 &dc->amount_wired), 58 GNUNET_JSON_pack_data_auto ("account_pub", 59 &dc->account_pub), 60 GNUNET_JSON_pack_timestamp ("timestamp", 61 GNUNET_TIME_absolute_to_timestamp ( 62 dc->timestamp)), 63 TALER_JSON_pack_full_payto ("account", 64 dc->account), 65 GNUNET_JSON_pack_string ("diagnostic", 66 dc->diagnostic), 67 GNUNET_JSON_pack_bool ("suppressed", 68 dc->suppressed) 69 ); 70 GNUNET_break (0 == 71 json_array_append_new (list, 72 obj)); 73 return GNUNET_OK; 74 } 75 76 77 enum MHD_Result 78 TAH_get_monitoring_kycauth_in_inconsistency ( 79 struct TAH_RequestHandler *rh, 80 struct MHD_Connection *connection, 81 void **connection_cls, 82 const char *upload_data, 83 size_t *upload_data_size, 84 const char *const args[]) 85 { 86 json_t *ja; 87 enum GNUNET_DB_QueryStatus qs; 88 int64_t limit = -20; 89 uint64_t offset; 90 bool return_suppressed = false; 91 92 (void) rh; 93 (void) connection_cls; 94 (void) upload_data; 95 (void) upload_data_size; 96 if (GNUNET_SYSERR == 97 TALER_AUDITORDB_preflight (TAH_apg)) 98 { 99 GNUNET_break (0); 100 return TALER_MHD_reply_with_error (connection, 101 MHD_HTTP_INTERNAL_SERVER_ERROR, 102 TALER_EC_GENERIC_DB_SETUP_FAILED, 103 NULL); 104 } 105 TAH_PARSE_REQUEST_LIMIT (connection, 106 "limit", 107 &limit); 108 if (limit < 0) 109 offset = TAH_SAFE_UINT64_MAX; 110 else 111 offset = 0; 112 TAH_PARSE_SAFE_REQUEST_NUMBER (connection, 113 "offset", 114 &offset); 115 { 116 const char *ret_s 117 = MHD_lookup_connection_value (connection, 118 MHD_GET_ARGUMENT_KIND, 119 "return_suppressed"); 120 if ( (NULL != ret_s) && 121 (0 == strcmp (ret_s, 122 "true")) ) 123 { 124 return_suppressed = true; 125 } 126 } 127 ja = json_array (); 128 GNUNET_break (NULL != ja); 129 qs = TALER_AUDITORDB_iterate_kycauth_in_inconsistencies ( 130 TAH_apg, 131 limit, 132 offset, 133 return_suppressed, 134 &process_kycauth_in_inconsistency, 135 ja); 136 if (0 > qs) 137 { 138 GNUNET_break (0); 139 json_decref (ja); 140 return TALER_MHD_reply_with_error (connection, 141 MHD_HTTP_INTERNAL_SERVER_ERROR, 142 TALER_EC_GENERIC_DB_FETCH_FAILED, 143 "kycauth-in-inconsistency"); 144 } 145 return TAH_reply_json_records (connection, 146 ja); 147 } 148 149 150 /* end of taler-auditor-httpd_get-monitoring-kycauth-in-inconsistency.c */