taler-auditor-httpd_get-monitoring-bad-sig-losses.c (4788B)
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-bad-sig-losses.h" 25 #include "auditor-database/get_bad_sig_losses.h" 26 #include "auditor-database/preflight.h" 27 28 29 /** 30 * Add bad-sig-losses to the list. 31 * 32 * @param[in,out] cls 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 add_bad_sig_losses ( 38 void *cls, 39 const struct TALER_AUDITORDB_BadSigLosses *dc) 40 { 41 json_t *list = cls; 42 json_t *obj; 43 44 obj = GNUNET_JSON_PACK ( 45 GNUNET_JSON_pack_uint64 ("row_id", 46 dc->row_id), 47 GNUNET_JSON_pack_uint64 ("problem_row_id", 48 dc->problem_row_id), 49 GNUNET_JSON_pack_string ("operation", 50 dc->operation), 51 TALER_JSON_pack_amount ("loss", 52 &dc->loss), 53 GNUNET_JSON_pack_data_auto ("operation_specific_pub", 54 &dc->operation_specific_pub), 55 GNUNET_JSON_pack_bool ("suppressed", 56 dc->suppressed) 57 ); 58 GNUNET_break (0 == 59 json_array_append_new (list, 60 obj)); 61 return GNUNET_OK; 62 } 63 64 65 MHD_RESULT 66 TAH_get_monitoring_bad_sig_losses ( 67 struct TAH_RequestHandler *rh, 68 struct MHD_Connection *connection, 69 void **connection_cls, 70 const char *upload_data, 71 size_t *upload_data_size, 72 const char *const args[]) 73 { 74 json_t *ja; 75 enum GNUNET_DB_QueryStatus qs; 76 int64_t limit = -20; 77 uint64_t offset; 78 bool return_suppressed = false; 79 struct GNUNET_CRYPTO_EddsaPublicKey op_spec_pub; 80 bool filter_spec_pub = false; 81 const char *op; 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 = MHD_lookup_connection_value (connection, 108 MHD_GET_ARGUMENT_KIND, 109 "return_suppressed"); 110 if (ret_s != NULL && strcmp (ret_s, "true") == 0) 111 { 112 return_suppressed = true; 113 } 114 } 115 116 op = MHD_lookup_connection_value (connection, 117 MHD_GET_ARGUMENT_KIND, 118 "op"); 119 TALER_MHD_parse_request_arg_auto (connection, 120 "op_spec_pub", 121 &op_spec_pub, 122 filter_spec_pub); 123 ja = json_array (); 124 GNUNET_break (NULL != ja); 125 qs = TALER_AUDITORDB_get_bad_sig_losses ( 126 TAH_apg, 127 limit, 128 offset, 129 return_suppressed, 130 filter_spec_pub ? &op_spec_pub : NULL, 131 op, 132 &add_bad_sig_losses, 133 ja); 134 if (0 > qs) 135 { 136 GNUNET_break (0); 137 json_decref (ja); 138 return TALER_MHD_reply_with_error (connection, 139 MHD_HTTP_INTERNAL_SERVER_ERROR, 140 TALER_EC_GENERIC_DB_FETCH_FAILED, 141 "bad-sig-losses"); 142 } 143 return TALER_MHD_REPLY_JSON_PACK ( 144 connection, 145 MHD_HTTP_OK, 146 GNUNET_JSON_pack_array_steal ("bad_sig_losses", 147 ja)); 148 }