diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-09-14 21:03:31 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-09-14 21:03:31 +0200 |
commit | 371947180da6964f4b665a6bdc196a4d35e1657f (patch) | |
tree | 0ca480a77b95b4fafd3f64c7c9f27ef644620ac2 | |
parent | ef90982edebf7cfd0937156128a9ce58f81a741a (diff) |
santity for /balances and /progress endpoints, fix various leaks and other bugs
24 files changed, 453 insertions, 687 deletions
diff --git a/src/auditor/taler-auditor-httpd.c b/src/auditor/taler-auditor-httpd.c index 7a96e4163..f9d7e2591 100644 --- a/src/auditor/taler-auditor-httpd.c +++ b/src/auditor/taler-auditor-httpd.c @@ -66,8 +66,6 @@ #include "taler-auditor-httpd_closure-lags-get.h" #include "taler-auditor-httpd_closure-lags-del.h" -#include "taler-auditor-httpd_progress-get.h" - #include "taler-auditor-httpd_refreshes-hanging-get.h" #include "taler-auditor-httpd_refreshes-hanging-del.h" @@ -134,6 +132,8 @@ #include "taler-auditor-httpd_fee-time-inconsistency-upd.h" #include "taler-auditor-httpd_balances-get.h" +#include "taler-auditor-httpd_progress-get.h" + /** * Auditor protocol version string. @@ -542,11 +542,6 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY_handler_update, MHD_HTTP_OK, true }, - { "/monitoring/progress", MHD_HTTP_METHOD_GET, - "application/json", - NULL, 0, - &TAH_PROGRESS_handler_get, - MHD_HTTP_OK, true }, { "/monitoring/reserve-balance-insufficient-inconsistency", MHD_HTTP_METHOD_GET, "application/json", @@ -768,6 +763,11 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_BALANCES_handler_get, MHD_HTTP_OK, true }, + { "/monitoring/progress", MHD_HTTP_METHOD_GET, + "application/json", + NULL, 0, + &TAH_PROGRESS_handler_get, + MHD_HTTP_OK, true }, { "/config", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, &handle_config, MHD_HTTP_OK, false }, diff --git a/src/auditor/taler-auditor-httpd_bad-sig-losses-get.c b/src/auditor/taler-auditor-httpd_bad-sig-losses-get.c index cf53173ce..826dce435 100644 --- a/src/auditor/taler-auditor-httpd_bad-sig-losses-get.c +++ b/src/auditor/taler-auditor-httpd_bad-sig-losses-get.c @@ -13,8 +13,6 @@ You should have received a copy of the GNU General Public License along with TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ - - #include "platform.h" #include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_json_lib.h> @@ -26,14 +24,15 @@ #include "taler-auditor-httpd.h" #include "taler-auditor-httpd_bad-sig-losses-get.h" + /** -* Add bad-sig-losses to the list. -* -* @param[in,out] cls a `json_t *` array to extend -* @param serial_id location of the @a dc in the database -* @param dc struct of inconsistencies -* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating -*/ + * Add bad-sig-losses to the list. + * + * @param[in,out] cls a `json_t *` array to extend + * @param serial_id location of the @a dc in the database + * @param dc struct of inconsistencies + * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating + */ static enum GNUNET_GenericReturnValue add_bad_sig_losses ( void *cls, @@ -44,18 +43,18 @@ add_bad_sig_losses ( json_t *obj; obj = GNUNET_JSON_PACK ( - - GNUNET_JSON_pack_uint64 ("row_id", serial_id), - GNUNET_JSON_pack_string ("operation", dc->operation), - TALER_JSON_pack_amount ("loss", &dc->loss), + GNUNET_JSON_pack_uint64 ("row_id", + serial_id), + GNUNET_JSON_pack_string ("operation", + dc->operation), + TALER_JSON_pack_amount ("loss", + &dc->loss), GNUNET_JSON_pack_data_auto ("operation_specific_pub", &dc->operation_specific_pub) ); GNUNET_break (0 == json_array_append_new (list, obj)); - - return GNUNET_OK; } @@ -71,6 +70,12 @@ TAH_BAD_SIG_LOSSES_handler_get ( { json_t *ja; enum GNUNET_DB_QueryStatus qs; + int64_t limit = -20; + uint64_t offset; + bool return_suppressed = false; + struct GNUNET_CRYPTO_EddsaPublicKey op_spec_pub; + bool filter_spec_pub = false; + const char *op; (void) rh; (void) connection_cls; @@ -85,12 +90,6 @@ TAH_BAD_SIG_LOSSES_handler_get ( TALER_EC_GENERIC_DB_SETUP_FAILED, NULL); } - ja = json_array (); - GNUNET_break (NULL != ja); - - int64_t limit = -20; - uint64_t offset; - TALER_MHD_parse_request_snumber (connection, "limit", &limit); @@ -103,88 +102,39 @@ TAH_BAD_SIG_LOSSES_handler_get ( TALER_MHD_parse_request_number (connection, "offset", &offset); - - bool return_suppressed = false; - const char *ret_s = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "return_suppressed"); - if (ret_s != NULL && strcmp (ret_s, "true") == 0) { - return_suppressed = true; - } - - const char *op = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "op"); - - - struct GNUNET_CRYPTO_EddsaPublicKey op_spec_pub; - memset (&op_spec_pub,0, sizeof(op_spec_pub)); - - bool filter_spec_pub = false; - const char *ret_osp = MHD_lookup_connection_value (connection, + const char *ret_s = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, - "use_op_spec_pub"); - if (ret_osp != NULL && strcmp (ret_osp, "true") == 0) - { - filter_spec_pub = true; - - - struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_fixed_auto ("operation_specific_pub", &op_spec_pub), - GNUNET_JSON_spec_end () - }; - - - json_t *json; + "return_suppressed"); + if (ret_s != NULL && strcmp (ret_s, "true") == 0) { - enum GNUNET_GenericReturnValue res; - - res = TALER_MHD_parse_post_json (connection, - connection_cls, - upload_data, - upload_data_size, - &json); - if (GNUNET_SYSERR == res) - return MHD_NO; - if ((GNUNET_NO == res) || - (NULL == json)) - return MHD_YES; - res = TALER_MHD_parse_json_data (connection, - json, - spec); - if (GNUNET_SYSERR == res) - { - json_decref (json); - return MHD_NO; /* hard failure */ - } - if (GNUNET_NO == res) - { - json_decref (json); - return MHD_YES; /* failure */ - } + return_suppressed = true; } - } - + op = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "op"); + TALER_MHD_parse_request_arg_auto (connection, + "op_spec_pub", + &op_spec_pub, + filter_spec_pub); + ja = json_array (); + GNUNET_break (NULL != ja); qs = TAH_plugin->get_bad_sig_losses ( TAH_plugin->cls, limit, offset, return_suppressed, - filter_spec_pub, - op_spec_pub, + filter_spec_pub ? &op_spec_pub : NULL, op, &add_bad_sig_losses, ja); if (0 > qs) { - GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + GNUNET_break (0); json_decref (ja); - TALER_LOG_WARNING ( - "Failed to handle GET /bad-sig-losses\n"); return TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_FETCH_FAILED, diff --git a/src/auditor/taler-auditor-httpd_balances-get.c b/src/auditor/taler-auditor-httpd_balances-get.c index 3ca8e6f0c..7bf148a96 100644 --- a/src/auditor/taler-auditor-httpd_balances-get.c +++ b/src/auditor/taler-auditor-httpd_balances-get.c @@ -28,22 +28,18 @@ * Add balance to the list. * * @param[in,out] cls a `json_t *` array to extend - * @param serial_id location of the @a dc in the database - * @param dc struct of inconsistencies + * @param dc struct of with balance data * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating */ static enum GNUNET_GenericReturnValue process_balances ( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_Balances *dc) { json_t *list = cls; json_t *obj; obj = GNUNET_JSON_PACK ( - GNUNET_JSON_pack_uint64 ("row_id", - serial_id), GNUNET_JSON_pack_string ("balance_key", dc->balance_key), TALER_JSON_pack_amount ("balance_value", @@ -52,8 +48,6 @@ process_balances ( GNUNET_break (0 == json_array_append_new (list, obj)); - - return GNUNET_OK; } @@ -69,8 +63,6 @@ TAH_BALANCES_handler_get ( { json_t *ja; enum GNUNET_DB_QueryStatus qs; - int64_t limit = -20; - uint64_t offset; const char *balance_key; (void) rh; @@ -86,17 +78,6 @@ TAH_BALANCES_handler_get ( TALER_EC_GENERIC_DB_SETUP_FAILED, NULL); } - TALER_MHD_parse_request_snumber (connection, - "limit", - &limit); - - if (limit < 0) - offset = INT64_MAX; - else - offset = 0; - TALER_MHD_parse_request_number (connection, - "offset", - &offset); balance_key = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, @@ -105,8 +86,6 @@ TAH_BALANCES_handler_get ( GNUNET_break (NULL != ja); qs = TAH_plugin->get_balances ( TAH_plugin->cls, - limit, - offset, balance_key, &process_balances, ja); diff --git a/src/auditor/taler-auditor-httpd_balances-get.h b/src/auditor/taler-auditor-httpd_balances-get.h index 1d2fed6ca..c4b224641 100644 --- a/src/auditor/taler-auditor-httpd_balances-get.h +++ b/src/auditor/taler-auditor-httpd_balances-get.h @@ -13,24 +13,13 @@ You should have received a copy of the GNU General Public License along with TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -#ifndef SRC_TALER_AUDITOR_HTTPD_BALANCES_GET_H -#define SRC_TALER_AUDITOR_HTTPD_BALANCES_GET_H +#ifndef TALER_AUDITOR_HTTPD_BALANCES_GET_H +#define TALER_AUDITOR_HTTPD_BALANCES_GET_H #include <gnunet/gnunet_util_lib.h> #include <microhttpd.h> #include "taler-auditor-httpd.h" -/** -* Initialize subsystem. -*/ -void -TEAH_BALANCES_GET_init (void); - -/** -* Shut down subsystem. -*/ -void -TEAH_BAD_BALANCES_GET_done (void); /** * Handle a "/balances" request. diff --git a/src/auditor/taler-auditor-httpd_denominations-without-sigs-get.c b/src/auditor/taler-auditor-httpd_denominations-without-sigs-get.c index d3e9d405e..bbe50ca52 100644 --- a/src/auditor/taler-auditor-httpd_denominations-without-sigs-get.c +++ b/src/auditor/taler-auditor-httpd_denominations-without-sigs-get.c @@ -13,8 +13,6 @@ You should have received a copy of the GNU General Public License along with TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ - - #include "platform.h" #include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_json_lib.h> @@ -26,39 +24,39 @@ #include "taler-auditor-httpd.h" #include "taler-auditor-httpd_denominations-without-sigs-get.h" + /** -* Add denominations-without-sigs to the list. -* -* @param[in,out] cls a `json_t *` array to extend -* @param serial_id location of the @a dc in the database -* @param dc struct of inconsistencies -* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating -*/ + * Add denominations-without-sigs to the list. + * + * @param[in,out] cls a `json_t *` array to extend + * @param dc struct of inconsistencies + * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating + */ static enum GNUNET_GenericReturnValue process_denominations_without_sigs ( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_DenominationsWithoutSigs *dc) { json_t *list = cls; json_t *obj; obj = GNUNET_JSON_PACK ( - - GNUNET_JSON_pack_int64 ("row_id", serial_id), - GNUNET_JSON_pack_data_auto ("denompub_h", &dc->denompub_h), - TALER_JSON_pack_amount ("value", &dc->value), - TALER_JSON_pack_time_abs_human ("start_time", dc->start_time), - TALER_JSON_pack_time_abs_human ("end_time", dc->end_time), - GNUNET_JSON_pack_bool ("suppressed", dc->suppressed) - - + GNUNET_JSON_pack_int64 ("row_id", + dc->row_id), + GNUNET_JSON_pack_data_auto ("denompub_h", + &dc->denompub_h), + TALER_JSON_pack_amount ("value", + &dc->value), + TALER_JSON_pack_time_abs_human ("start_time", + dc->start_time), + TALER_JSON_pack_time_abs_human ("end_time", + dc->end_time), + GNUNET_JSON_pack_bool ("suppressed", + dc->suppressed) ); GNUNET_break (0 == json_array_append_new (list, obj)); - - return GNUNET_OK; } @@ -74,6 +72,9 @@ TAH_DENOMINATIONS_WITHOUT_SIGS_handler_get ( { json_t *ja; enum GNUNET_DB_QueryStatus qs; + int64_t limit = -20; + uint64_t offset; + bool return_suppressed = false; (void) rh; (void) connection_cls; @@ -88,34 +89,28 @@ TAH_DENOMINATIONS_WITHOUT_SIGS_handler_get ( TALER_EC_GENERIC_DB_SETUP_FAILED, NULL); } - ja = json_array (); - GNUNET_break (NULL != ja); - - int64_t limit = -20; - uint64_t offset; - TALER_MHD_parse_request_snumber (connection, "limit", &limit); - if (limit < 0) offset = INT64_MAX; else offset = 0; - TALER_MHD_parse_request_number (connection, "offset", &offset); - - bool return_suppressed = false; - const char *ret_s = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "return_suppressed"); - if (ret_s != NULL && strcmp (ret_s, "true") == 0) { - return_suppressed = true; + const char *ret_s = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "return_suppressed"); + if (ret_s != NULL && strcmp (ret_s, "true") == 0) + { + return_suppressed = true; + } } + ja = json_array (); + GNUNET_break (NULL != ja); qs = TAH_plugin->get_denominations_without_sigs ( TAH_plugin->cls, limit, diff --git a/src/auditor/taler-auditor-httpd_misattribution-in-inconsistency-get.c b/src/auditor/taler-auditor-httpd_misattribution-in-inconsistency-get.c index 7225be9aa..9c1950fa0 100644 --- a/src/auditor/taler-auditor-httpd_misattribution-in-inconsistency-get.c +++ b/src/auditor/taler-auditor-httpd_misattribution-in-inconsistency-get.c @@ -13,8 +13,6 @@ You should have received a copy of the GNU General Public License along with TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ - - #include "platform.h" #include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_json_lib.h> @@ -26,38 +24,38 @@ #include "taler-auditor-httpd.h" #include "taler-auditor-httpd_misattribution-in-inconsistency-get.h" + /** -* Add misattribution-in-inconsistency to the list. -* -* @param[in,out] cls a `json_t *` array to extend -* @param serial_id location of the @a dc in the database -* @param dc struct of inconsistencies -* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating -*/ + * Add misattribution-in-inconsistency to the list. + * + * @param[in,out] cls a `json_t *` array to extend + * @param serial_id location of the @a dc in the database + * @param dc struct of inconsistencies + * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating + */ static enum GNUNET_GenericReturnValue process_misattribution_in_inconsistency ( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_MisattributionInInconsistency *dc) { json_t *list = cls; json_t *obj; obj = GNUNET_JSON_PACK ( - - GNUNET_JSON_pack_int64 ("row_id", serial_id), - TALER_JSON_pack_amount ("amount", &dc->amount), - GNUNET_JSON_pack_int64 ("bank_row", dc->bank_row), - GNUNET_JSON_pack_data_auto ("reserve_pub", &dc->reserve_pub), - GNUNET_JSON_pack_bool ("suppressed", dc->suppressed) - - + GNUNET_JSON_pack_uint64 ("row_id", + dc->row_id), + TALER_JSON_pack_amount ("amount", + &dc->amount), + GNUNET_JSON_pack_uint64 ("bank_row", + dc->bank_row), + GNUNET_JSON_pack_data_auto ("reserve_pub", + &dc->reserve_pub), + GNUNET_JSON_pack_bool ("suppressed", + dc->suppressed) ); GNUNET_break (0 == json_array_append_new (list, obj)); - - return GNUNET_OK; } @@ -73,6 +71,9 @@ TAH_MISATTRIBUTION_IN_INCONSISTENCY_handler_get ( { json_t *ja; enum GNUNET_DB_QueryStatus qs; + int64_t limit = -20; + uint64_t offset; + bool return_suppressed = false; (void) rh; (void) connection_cls; @@ -87,34 +88,29 @@ TAH_MISATTRIBUTION_IN_INCONSISTENCY_handler_get ( TALER_EC_GENERIC_DB_SETUP_FAILED, NULL); } - ja = json_array (); - GNUNET_break (NULL != ja); - - int64_t limit = -20; - uint64_t offset; - TALER_MHD_parse_request_snumber (connection, "limit", &limit); - if (limit < 0) offset = INT64_MAX; else offset = 0; - TALER_MHD_parse_request_number (connection, "offset", &offset); - - bool return_suppressed = false; - const char *ret_s = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "return_suppressed"); - if (ret_s != NULL && strcmp (ret_s, "true") == 0) { - return_suppressed = true; + const char *ret_s + = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "return_suppressed"); + if (ret_s != NULL && strcmp (ret_s, "true") == 0) + { + return_suppressed = true; + } } + ja = json_array (); + GNUNET_break (NULL != ja); qs = TAH_plugin->get_misattribution_in_inconsistency ( TAH_plugin->cls, limit, @@ -122,7 +118,6 @@ TAH_MISATTRIBUTION_IN_INCONSISTENCY_handler_get ( return_suppressed, &process_misattribution_in_inconsistency, ja); - if (0 > qs) { GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); @@ -137,6 +132,6 @@ TAH_MISATTRIBUTION_IN_INCONSISTENCY_handler_get ( return TALER_MHD_REPLY_JSON_PACK ( connection, MHD_HTTP_OK, - GNUNET_JSON_pack_array_steal ("misattribution-in-inconsistency", + GNUNET_JSON_pack_array_steal ("misattribution_in_inconsistency", ja)); } diff --git a/src/auditor/taler-auditor-httpd_progress-get.c b/src/auditor/taler-auditor-httpd_progress-get.c index 06933e53c..06bc69124 100644 --- a/src/auditor/taler-auditor-httpd_progress-get.c +++ b/src/auditor/taler-auditor-httpd_progress-get.c @@ -24,34 +24,31 @@ #include "taler-auditor-httpd.h" #include "taler-auditor-httpd_progress-get.h" + /** * Add progress to the list. * * @param[in,out] cls a `json_t *` array to extend - * @param serial_id location of the @a dc in the database - * @param dc struct of inconsistencies + * @param dc struct with progress data * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating */ static enum GNUNET_GenericReturnValue process_progress ( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_Progress *dc) { json_t *list = cls; json_t *obj; obj = GNUNET_JSON_PACK ( - - GNUNET_JSON_pack_string ("progress_key", dc->progress_key), - GNUNET_JSON_pack_int64 ("progress_offset", dc->progress_offset) - + GNUNET_JSON_pack_string ("progress_key", + dc->progress_key), + GNUNET_JSON_pack_int64 ("progress_offset", + dc->progress_offset) ); GNUNET_break (0 == json_array_append_new (list, obj)); - - return GNUNET_OK; } @@ -67,6 +64,7 @@ TAH_PROGRESS_handler_get ( { json_t *ja; enum GNUNET_DB_QueryStatus qs; + const char *progress_key; (void) rh; (void) connection_cls; @@ -81,42 +79,21 @@ TAH_PROGRESS_handler_get ( TALER_EC_GENERIC_DB_SETUP_FAILED, NULL); } + progress_key + = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + "progress_key"); ja = json_array (); GNUNET_break (NULL != ja); - - int64_t limit = -20; - uint64_t offset; - - TALER_MHD_parse_request_snumber (connection, - "limit", - &limit); - - if (limit < 0) - offset = INT64_MAX; - else - offset = 0; - - TALER_MHD_parse_request_number (connection, - "offset", - &offset); - - bool return_suppressed = false; - - - qs = TAH_plugin->get_progress ( + qs = TAH_plugin->get_progress_points ( TAH_plugin->cls, - limit, - offset, - return_suppressed, + progress_key, &process_progress, ja); - if (0 > qs) { - GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + GNUNET_break (0); json_decref (ja); - TALER_LOG_WARNING ( - "Failed to handle GET /progress\n"); return TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_FETCH_FAILED, diff --git a/src/auditor/taler-auditor-httpd_progress-get.h b/src/auditor/taler-auditor-httpd_progress-get.h index 0a3d6b9c5..46d38846d 100644 --- a/src/auditor/taler-auditor-httpd_progress-get.h +++ b/src/auditor/taler-auditor-httpd_progress-get.h @@ -13,37 +13,14 @@ You should have received a copy of the GNU General Public License along with TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -#ifndef SRC_TALER_AUDITOR_HTTPD_PROGRESS_GET_H -#define SRC_TALER_AUDITOR_HTTPD_PROGRESS_GET_H +#ifndef TALER_AUDITOR_HTTPD_PROGRESS_GET_H +#define TALER_AUDITOR_HTTPD_PROGRESS_GET_H #include <gnunet/gnunet_util_lib.h> #include <microhttpd.h> #include "taler-auditor-httpd.h" -/** -* Initialize subsystem. -*/ -void -TEAH_PROGRESS_GET_init (void); -/** -* Shut down subsystem. -*/ -void -TEAH_PROGRESS_GET_done (void); - -/** - * Handle a "/progress" request. - * - * @param rh context of the handler - * @param connection the MHD connection to handle - * @param[in,out] connection_cls the connection's closure (can be updated) - * @param upload_data upload data - * @param[in,out] upload_data_size number of bytes (left) in @a upload_data - * @param args NULL-terminated array of remaining parts of the URI broken up at '/' - * @return MHD result code - */ -// FIXME: very bad name! MHD_RESULT TAH_PROGRESS_handler_get ( struct TAH_RequestHandler *rh, @@ -53,5 +30,4 @@ TAH_PROGRESS_handler_get ( size_t *upload_data_size, const char *const args[]); - #endif diff --git a/src/auditor/taler-auditor-httpd_progress-put.c b/src/auditor/taler-auditor-httpd_progress-put.c deleted file mode 100644 index 67f19f150..000000000 --- a/src/auditor/taler-auditor-httpd_progress-put.c +++ /dev/null @@ -1,156 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2024 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ - - -#include "platform.h" -#include <gnunet/gnunet_util_lib.h> -#include <gnunet/gnunet_json_lib.h> -#include <jansson.h> -#include <microhttpd.h> -#include <pthread.h> -#include "taler_json_lib.h" -#include "taler_mhd_lib.h" -#include "taler-auditor-httpd.h" -#include "taler-auditor-httpd_progress-put.h" - -/** -* We have parsed the JSON information about the progress, do some -* basic sanity checks and then execute the -* transaction. -* -* @param connection the MHD connection to handle -* @param dc information about the progress -* @return MHD result code -*/ -static MHD_RESULT -process_inconsistency ( - struct MHD_Connection *connection, - const struct TALER_AUDITORDB_Progress *dc) -{ - - enum GNUNET_DB_QueryStatus qs; - - if (GNUNET_SYSERR == - TAH_plugin->preflight (TAH_plugin->cls)) - { - GNUNET_break (0); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_SETUP_FAILED, - NULL); - } - - /* execute transaction */ - qs = TAH_plugin->insert_progress (TAH_plugin->cls, - dc); - if (0 > qs) - { - GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); - TALER_LOG_WARNING ( - "Failed to store /progress in database\n"); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GENERIC_DB_STORE_FAILED, - "progress"); - } - return TALER_MHD_REPLY_JSON_PACK (connection, - MHD_HTTP_OK, - GNUNET_JSON_pack_string ("status", - "PROGRESS_OK")); -} - - -MHD_RESULT -TAH_PROGRESS_PUT_handler ( - struct TAH_RequestHandler *rh, - struct MHD_Connection *connection, - void **connection_cls, - const char *upload_data, - size_t *upload_data_size, - const char *const args[]) -{ - - struct TALER_AUDITORDB_Progress dc; - - - struct GNUNET_JSON_Specification spec[] = { - - GNUNET_JSON_spec_string ("progress_key", (const char **) &dc.progress_key), - GNUNET_JSON_spec_string ("progress_offset", (const - char **) &dc.progress_offset), - - - GNUNET_JSON_spec_end () - }; - - - json_t *json; - - (void) rh; - (void) connection_cls; - (void) upload_data; - (void) upload_data_size; - { - enum GNUNET_GenericReturnValue res; - - res = TALER_MHD_parse_post_json (connection, - connection_cls, - upload_data, - upload_data_size, - &json); - if (GNUNET_SYSERR == res) - return MHD_NO; - if ((GNUNET_NO == res) || - (NULL == json)) - return MHD_YES; - res = TALER_MHD_parse_json_data (connection, - json, - spec); - if (GNUNET_SYSERR == res) - { - json_decref (json); - return MHD_NO; /* hard failure */ - } - if (GNUNET_NO == res) - { - json_decref (json); - return MHD_YES; /* failure */ - } - } - - MHD_RESULT res; - - res = process_inconsistency (connection, &dc); - GNUNET_JSON_parse_free (spec); - - json_decref (json); - return res; - -} - - -void -TEAH_PROGRESS_PUT_init (void) -{ - -} - - -void -TEAH_PROGRESS_PUT_done (void) -{ - -} diff --git a/src/auditor/taler-auditor-httpd_progress-put.h b/src/auditor/taler-auditor-httpd_progress-put.h deleted file mode 100644 index d7e3db0b3..000000000 --- a/src/auditor/taler-auditor-httpd_progress-put.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2024 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> - */ -#ifndef SRC_TALER_AUDITOR_HTTPD_PROGRESS_PUT_H -#define SRC_TALER_AUDITOR_HTTPD_PROGRESS_PUT_H - -#include <microhttpd.h> -#include "taler-auditor-httpd.h" - -/** -* Initialize subsystem. -*/ -void -TEAH_PROGRESS_PUT_init (void); - -/** -* Shut down subsystem. -*/ -void -TEAH_PROGRESS_PUT_done (void); - - -/** - * Handle a "/progress" request. Parses the JSON, and, if - * successful, checks the signatures and stores the result in the DB. - * - * @param rh context of the handler - * @param connection the MHD connection to handle - * @param[in,out] connection_cls the connection's closure (can be updated) - * @param upload_data upload data - * @param[in,out] upload_data_size number of bytes (left) in @a upload_data - * @param args NULL-terminated array of remaining parts of the URI broken up at '/' - * @return MHD result code - */ -MHD_RESULT -TAH_PROGRESS_PUT_handler ( - struct TAH_RequestHandler *rh, - struct MHD_Connection *connection, - void **connection_cls, - const char *upload_data, - size_t *upload_data_size, - const char *const args[]); - - -#endif diff --git a/src/auditor/taler-auditor-httpd_reserve-in-inconsistency-get.c b/src/auditor/taler-auditor-httpd_reserve-in-inconsistency-get.c index 3a2b6def3..0ec7b82ba 100644 --- a/src/auditor/taler-auditor-httpd_reserve-in-inconsistency-get.c +++ b/src/auditor/taler-auditor-httpd_reserve-in-inconsistency-get.c @@ -132,10 +132,8 @@ TAH_RESERVE_IN_INCONSISTENCY_handler_get ( ja); if (0 > qs) { - GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs); + GNUNET_break (0); json_decref (ja); - TALER_LOG_WARNING ( - "Failed to handle GET /reserve-in-inconsistency"); return TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_FETCH_FAILED, @@ -144,6 +142,6 @@ TAH_RESERVE_IN_INCONSISTENCY_handler_get ( return TALER_MHD_REPLY_JSON_PACK ( connection, MHD_HTTP_OK, - GNUNET_JSON_pack_array_steal ("reserve-in-inconsistency", + GNUNET_JSON_pack_array_steal ("reserve_in_inconsistency", ja)); } diff --git a/src/auditor/taler-helper-auditor-reserves.c b/src/auditor/taler-helper-auditor-reserves.c index 54fa043f5..41ce9ff5b 100644 --- a/src/auditor/taler-helper-auditor-reserves.c +++ b/src/auditor/taler-helper-auditor-reserves.c @@ -580,7 +580,8 @@ handle_reserve_out ( <, execution_date)) { - struct TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency dkvwi ={ + struct TALER_AUDITORDB_DenominationKeyValidityWithdrawInconsistency dkvwi = + { .problem_row_id = rowid, .execution_date = execution_date.abs_time, .denompub_h = *&h_denom_pub, @@ -1540,8 +1541,8 @@ verify_reserve_balance (void *cls, struct TALER_AUDITORDB_ReserveNotClosedInconsistency rnci = { .reserve_pub = rs->reserve_pub, .expiration_time = rs->a_expiration_date.abs_time, - .balance = nbalance - + .balance = nbalance, + .diagnostic = rs->sender_account }; /* remaining balance (according to us) exceeds closing fee */ @@ -1712,18 +1713,18 @@ verify_reserve_balance (void *cls, #define CHECK_DB() do { \ - if (qs < 0) { \ - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); \ - return qs; \ - } \ - if (global_qs < 0) { \ - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == global_qs); \ - return global_qs; \ - } \ - if (rc.qs < 0) { \ - GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == rc.qs); \ - return rc.qs; \ - } \ + if (qs < 0) { \ + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); \ + return qs; \ + } \ + if (global_qs < 0) { \ + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == global_qs); \ + return global_qs; \ + } \ + if (rc.qs < 0) { \ + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == rc.qs); \ + return rc.qs; \ + } \ } while (0) diff --git a/src/auditor/test-auditor.sh b/src/auditor/test-auditor.sh index 1c60fc7b5..f72edbb81 100755 --- a/src/auditor/test-auditor.sh +++ b/src/auditor/test-auditor.sh @@ -485,7 +485,8 @@ function check_not_balance() { function check_report() { call_endpoint "$1" - VAL=$(jq -r .\"${1}\"[0].\"$2\" < "${MY_TMP_DIR}/${1}.json") + NAME=$(echo "$1" | tr '-' '_') + VAL=$(jq -r .\"${NAME}\"[0].\"$2\" < "${MY_TMP_DIR}/${1}.json") if [ "$VAL" != "$3" ] then exit_fail "$1::$2 (got $VAL, wanted $3)" @@ -495,7 +496,7 @@ function check_report() { function check_row() { call_endpoint "$1" - NAME="$1" + NAME=$(echo "$1" | tr '-' '_') if [ -n "${3+x}" ] then RID="$2" @@ -756,6 +757,11 @@ function test_3() { run_audit check_auditor_running + echo "Checking reserve balance summary inconsistency detection ..." + check_report \ + "reserve-balance-summary-wrong-inconsistency" \ + "auditor_amount" "TESTKUDOS:5.01" + call_endpoint "reserve-balance-summary-wrong-inconsistency" EXPECTED=$(jq -e .reserve_balance_summary_wrong_inconsistency[0].auditor_amount \ < "${MY_TMP_DIR}/reserve-balance-summary-wrong-inconsistency.json") diff --git a/src/auditordb/Makefile.am b/src/auditordb/Makefile.am index 3f43a5492..10649e9e4 100644 --- a/src/auditordb/Makefile.am +++ b/src/auditordb/Makefile.am @@ -77,6 +77,7 @@ libtaler_plugin_auditordb_postgres_la_SOURCES = \ pg_insert_balance.c pg_insert_balance.h \ pg_insert_denomination_balance.c pg_insert_denomination_balance.h \ pg_insert_deposit_confirmation.c pg_insert_deposit_confirmation.h \ + pg_get_progress_points.h pg_get_progress_points.c \ pg_insert_historic_reserve_revenue.c pg_insert_historic_reserve_revenue.h \ pg_insert_pending_deposit.c pg_insert_pending_deposit.h \ pg_insert_purse_info.c pg_insert_purse_info.h \ diff --git a/src/auditordb/pg_get_bad_sig_losses.c b/src/auditordb/pg_get_bad_sig_losses.c index a40f01046..4691df84d 100644 --- a/src/auditordb/pg_get_bad_sig_losses.c +++ b/src/auditordb/pg_get_bad_sig_losses.c @@ -108,27 +108,23 @@ TAH_PG_get_bad_sig_losses ( int64_t limit, uint64_t offset, bool return_suppressed, - bool filter_spec_pub, - struct GNUNET_CRYPTO_EddsaPublicKey op_spec_pub, + const struct GNUNET_CRYPTO_EddsaPublicKey *op_spec_pub, const char *op, TALER_AUDITORDB_BadSigLossesCallback cb, void *cb_cls) { struct PostgresClosure *pg = cls; uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - /*if true, does not filter for an operation specific key*/ - bool any_spec_pub = ! filter_spec_pub; - /*if true, does not filter for an operation*/ - bool any_op = (NULL == op) ? true : false; - const char *o = (NULL == op) ? "" : op; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&offset), GNUNET_PQ_query_param_bool (return_suppressed), GNUNET_PQ_query_param_uint64 (&plimit), - GNUNET_PQ_query_param_bool (any_spec_pub), - GNUNET_PQ_query_param_auto_from_type (&op_spec_pub), - GNUNET_PQ_query_param_bool (any_op), - GNUNET_PQ_query_param_string (o), + NULL == op_spec_pub + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_auto_from_type (op_spec_pub), + NULL == op + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (op), GNUNET_PQ_query_param_end }; struct BadSigLossesContext dcc = { @@ -147,9 +143,9 @@ TAH_PG_get_bad_sig_losses ( ",operation_specific_pub" " FROM auditor_bad_sig_losses" " WHERE (row_id < $1)" - " AND ($2 OR suppressed is false)" - " AND ($4 OR operation_specific_pub = $5)" - " AND ($6 OR operation = $7)" + " AND ($2 OR suppressed IS FALSE)" + " AND ($4::BYTEA IS NULL OR operation_specific_pub = $4)" + " AND ($5::TEXT IS NULL OR operation = $5)" " ORDER BY row_id DESC" " LIMIT $3" ); @@ -162,20 +158,20 @@ TAH_PG_get_bad_sig_losses ( ",operation_specific_pub" " FROM auditor_bad_sig_losses" " WHERE (row_id > $1)" - " AND ($2 OR suppressed is false)" - " AND ($4 OR operation_specific_pub = $5)" - " AND ($6 OR operation = $7)" + " AND ($2 OR suppressed IS FALSE)" + " AND ($4::BYTEA IS NULL OR operation_specific_pub = $4)" + " AND ($5::TEXT IS NULL OR operation = $5)" " ORDER BY row_id ASC" " LIMIT $3" ); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - (limit > 0) - ? "auditor_bad_sig_losses_get_asc" - : "auditor_bad_sig_losses_get_desc", - params, - &bad_sig_losses_cb, - &dcc); - + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + (limit > 0) + ? "auditor_bad_sig_losses_get_asc" + : "auditor_bad_sig_losses_get_desc", + params, + &bad_sig_losses_cb, + &dcc); if (qs > 0) return dcc.qs; GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs); diff --git a/src/auditordb/pg_get_bad_sig_losses.h b/src/auditordb/pg_get_bad_sig_losses.h index 8cf04eddd..45d871636 100644 --- a/src/auditordb/pg_get_bad_sig_losses.h +++ b/src/auditordb/pg_get_bad_sig_losses.h @@ -13,9 +13,8 @@ You should have received a copy of the GNU General Public License along with TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ - -#ifndef SRC_PG_GET_BAD_SIG_LOSSES_H -#define SRC_PG_GET_BAD_SIG_LOSSES_H +#ifndef PG_GET_BAD_SIG_LOSSES_H +#define PG_GET_BAD_SIG_LOSSES_H #include "taler_util.h" #include "taler_json_lib.h" @@ -28,7 +27,6 @@ * @param limit number of records to return, negative for descending * @param offset table row to start from, exclusive, direction determined by @a limit * @param return_suppressed should suppressed rows be returned anyway? - * @param filter_spec_pub filter by @a op_spec_pub * @param op_spec_pub public key to filter by; FIXME: replace by pointer * @param op operation to filter by * @param cb function to call with results @@ -41,8 +39,7 @@ TAH_PG_get_bad_sig_losses ( int64_t limit, uint64_t offset, bool return_suppressed, - bool filter_spec_pub, - struct GNUNET_CRYPTO_EddsaPublicKey op_spec_pub, + const struct GNUNET_CRYPTO_EddsaPublicKey *op_spec_pub, const char *op, TALER_AUDITORDB_BadSigLossesCallback cb, void *cb_cls); diff --git a/src/auditordb/pg_get_balances.c b/src/auditordb/pg_get_balances.c index da729bf38..4ddb9eb49 100644 --- a/src/auditordb/pg_get_balances.c +++ b/src/auditordb/pg_get_balances.c @@ -65,11 +65,8 @@ balances_cb (void *cls, for (unsigned int i = 0; i < num_results; i++) { - uint64_t serial_id; struct TALER_AUDITORDB_Balances dc; struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("row_id", - &serial_id), GNUNET_PQ_result_spec_string ("balance_key", &dc.balance_key), TALER_PQ_RESULT_SPEC_AMOUNT ("balance_value", @@ -89,7 +86,6 @@ balances_cb (void *cls, } dcc->qs = i + 1; rval = dcc->cb (dcc->cb_cls, - serial_id, &dc); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != rval) @@ -101,21 +97,15 @@ balances_cb (void *cls, enum GNUNET_DB_QueryStatus TAH_PG_get_balances ( void *cls, - int64_t limit, - uint64_t offset, const char *balance_key, TALER_AUDITORDB_BalancesCallback cb, void *cb_cls) { struct PostgresClosure *pg = cls; - bool any_balance = (NULL == balance_key); - uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - const char *bk = (any_balance) ? "" : balance_key; struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (&offset), - GNUNET_PQ_query_param_uint64 (&plimit), - GNUNET_PQ_query_param_bool (any_balance), - GNUNET_PQ_query_param_string (bk), + NULL == balance_key + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (balance_key), GNUNET_PQ_query_param_end }; struct BalancesContext dcc = { @@ -126,34 +116,16 @@ TAH_PG_get_balances ( enum GNUNET_DB_QueryStatus qs; PREPARE (pg, - "auditor_balances_get_desc", + "auditor_balances_get", "SELECT" - " row_id," - " balance_key," - " balance_value" + " balance_key" + ",balance_value" " FROM auditor_balances" - " WHERE (row_id < $1)" - " AND ($3 OR balance_key = $4)" - " ORDER BY row_id DESC" - " LIMIT $2" - ); - PREPARE (pg, - "auditor_balances_get_asc", - "SELECT" - " row_id," - " balance_key," - " balance_value" - " FROM auditor_balances" - " WHERE (row_id > $1)" - " AND ($3 OR balance_key = $4)" - " ORDER BY row_id ASC" - " LIMIT $2" + " WHERE ($1::TEXT IS NULL OR balance_key = $1)" ); qs = GNUNET_PQ_eval_prepared_multi_select ( pg->conn, - (limit > 0) - ? "auditor_balances_get_asc" - : "auditor_balances_get_desc", + "auditor_balances_get", params, &balances_cb, &dcc); diff --git a/src/auditordb/pg_get_balances.h b/src/auditordb/pg_get_balances.h index ff17847c1..affc20072 100644 --- a/src/auditordb/pg_get_balances.h +++ b/src/auditordb/pg_get_balances.h @@ -24,8 +24,6 @@ * Get information about balances from the database. * * @param cls the @e cls of this struct with the plugin-specific state - * @param limit return at most this number of results, negative to descend from @a offset - * @param offset row from which to return @a limit results * @param balance_key key to filter by, NULL to match all balance keys * @param cb function to call with results * @param cb_cls closure for @a cb @@ -34,8 +32,6 @@ enum GNUNET_DB_QueryStatus TAH_PG_get_balances ( void *cls, - int64_t limit, - uint64_t offset, const char *balance_key, TALER_AUDITORDB_BalancesCallback cb, void *cb_cls); diff --git a/src/auditordb/pg_get_denominations_without_sigs.c b/src/auditordb/pg_get_denominations_without_sigs.c index 2bc3e5dc0..d12f00971 100644 --- a/src/auditordb/pg_get_denominations_without_sigs.c +++ b/src/auditordb/pg_get_denominations_without_sigs.c @@ -13,14 +13,11 @@ You should have received a copy of the GNU General Public License along with TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ - - #include "platform.h" #include "taler_error_codes.h" #include "taler_dbevents.h" #include "taler_pq_lib.h" #include "pg_helper.h" - #include "pg_get_denominations_without_sigs.h" @@ -68,21 +65,20 @@ denominations_without_sigs_cb (void *cls, for (unsigned int i = 0; i < num_results; i++) { - uint64_t serial_id; - struct TALER_AUDITORDB_DenominationsWithoutSigs dc; - struct GNUNET_PQ_ResultSpec rs[] = { - - GNUNET_PQ_result_spec_uint64 ("row_id", &serial_id), - - GNUNET_PQ_result_spec_auto_from_type ("denompub_h", &dc.denompub_h), - TALER_PQ_RESULT_SPEC_AMOUNT ("value", &dc.value), - GNUNET_PQ_result_spec_absolute_time ("start_time", &dc.start_time), - GNUNET_PQ_result_spec_absolute_time ("end_time", &dc.end_time), - GNUNET_PQ_result_spec_bool ("suppressed", &dc.suppressed), - - + GNUNET_PQ_result_spec_uint64 ("row_id", + &dc.row_id), + GNUNET_PQ_result_spec_auto_from_type ("denompub_h", + &dc.denompub_h), + TALER_PQ_RESULT_SPEC_AMOUNT ("value", + &dc.value), + GNUNET_PQ_result_spec_absolute_time ("start_time", + &dc.start_time), + GNUNET_PQ_result_spec_absolute_time ("end_time", + &dc.end_time), + GNUNET_PQ_result_spec_bool ("suppressed", + &dc.suppressed), GNUNET_PQ_result_spec_end }; enum GNUNET_GenericReturnValue rval; @@ -100,7 +96,6 @@ denominations_without_sigs_cb (void *cls, dcc->qs = i + 1; rval = dcc->cb (dcc->cb_cls, - serial_id, &dc); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != rval) @@ -114,14 +109,12 @@ TAH_PG_get_denominations_without_sigs ( void *cls, int64_t limit, uint64_t offset, - bool return_suppressed, // maybe not needed + bool return_suppressed, TALER_AUDITORDB_DenominationsWithoutSigsCallback cb, void *cb_cls) { - - uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - struct PostgresClosure *pg = cls; + uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&offset), GNUNET_PQ_query_param_bool (return_suppressed), @@ -146,7 +139,7 @@ TAH_PG_get_denominations_without_sigs ( " suppressed" " FROM auditor_denominations_without_sigs" " WHERE (row_id < $1)" - " AND ($2 OR suppressed is false)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id DESC" " LIMIT $3" ); @@ -161,20 +154,18 @@ TAH_PG_get_denominations_without_sigs ( " suppressed" " FROM auditor_denominations_without_sigs" " WHERE (row_id > $1)" - " AND ($2 OR suppressed is false)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id ASC" " LIMIT $3" ); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - (limit > 0) - ? - "auditor_denominations_without_sigs_get_asc" - : - "auditor_denominations_without_sigs_get_desc", - params, - &denominations_without_sigs_cb, - &dcc); - + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + (limit > 0) + ? "auditor_denominations_without_sigs_get_asc" + : "auditor_denominations_without_sigs_get_desc", + params, + &denominations_without_sigs_cb, + &dcc); if (qs > 0) return dcc.qs; GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs); diff --git a/src/auditordb/pg_get_misattribution_in_inconsistency.c b/src/auditordb/pg_get_misattribution_in_inconsistency.c index 1b31d1a4e..d7c12fc9a 100644 --- a/src/auditordb/pg_get_misattribution_in_inconsistency.c +++ b/src/auditordb/pg_get_misattribution_in_inconsistency.c @@ -68,14 +68,18 @@ misattribution_in_inconsistency_cb (void *cls, for (unsigned int i = 0; i < num_results; i++) { - uint64_t serial_id; struct TALER_AUDITORDB_MisattributionInInconsistency dc; struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("row_id", &serial_id), - TALER_PQ_RESULT_SPEC_AMOUNT ("amount", &dc.amount), - GNUNET_PQ_result_spec_uint64 ("bank_row", &dc.bank_row), - GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", &dc.reserve_pub), - GNUNET_PQ_result_spec_bool ("suppressed", &dc.suppressed), + GNUNET_PQ_result_spec_uint64 ("row_id", + &dc.row_id), + TALER_PQ_RESULT_SPEC_AMOUNT ("amount", + &dc.amount), + GNUNET_PQ_result_spec_uint64 ("bank_row", + &dc.bank_row), + GNUNET_PQ_result_spec_auto_from_type ("reserve_pub", + &dc.reserve_pub), + GNUNET_PQ_result_spec_bool ("suppressed", + &dc.suppressed), GNUNET_PQ_result_spec_end }; enum GNUNET_GenericReturnValue rval; @@ -91,7 +95,6 @@ misattribution_in_inconsistency_cb (void *cls, } dcc->qs = i + 1; rval = dcc->cb (dcc->cb_cls, - serial_id, &dc); GNUNET_PQ_cleanup_result (rs); if (GNUNET_OK != rval) @@ -105,14 +108,12 @@ TAH_PG_get_misattribution_in_inconsistency ( void *cls, int64_t limit, uint64_t offset, - bool return_suppressed, // maybe not needed + bool return_suppressed, TALER_AUDITORDB_MisattributionInInconsistencyCallback cb, void *cb_cls) { - - uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); - struct PostgresClosure *pg = cls; + uint64_t plimit = (uint64_t) ((limit < 0) ? -limit : limit); struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&offset), GNUNET_PQ_query_param_bool (return_suppressed), @@ -129,42 +130,39 @@ TAH_PG_get_misattribution_in_inconsistency ( PREPARE (pg, "auditor_misattribution_in_inconsistency_get_desc", "SELECT" - " row_id," - " amount," - " bank_row," - " reserve_pub," - " suppressed" + " row_id" + ",amount" + ",bank_row" + ",reserve_pub" + ",suppressed" " FROM auditor_misattribution_in_inconsistency" " WHERE (row_id < $1)" - " AND ($2 OR suppressed is false)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id DESC" " LIMIT $3" ); PREPARE (pg, "auditor_misattribution_in_inconsistency_get_asc", "SELECT" - " row_id," - " amount," - " bank_row," - " reserve_pub," - " suppressed" + " row_id" + ",amount" + ",bank_row" + ",reserve_pub" + ",suppressed" " FROM auditor_misattribution_in_inconsistency" " WHERE (row_id > $1)" - " AND ($2 OR suppressed is false)" + " AND ($2 OR NOT suppressed)" " ORDER BY row_id ASC" " LIMIT $3" ); - qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, - (limit > 0) - ? - "auditor_misattribution_in_inconsistency_get_asc" - : - "auditor_misattribution_in_inconsistency_get_desc", - params, - &misattribution_in_inconsistency_cb - , - &dcc); - + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + (limit > 0) + ? "auditor_misattribution_in_inconsistency_get_asc" + : "auditor_misattribution_in_inconsistency_get_desc", + params, + &misattribution_in_inconsistency_cb, + &dcc); if (qs > 0) return dcc.qs; GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs); diff --git a/src/auditordb/pg_get_progress_points.c b/src/auditordb/pg_get_progress_points.c new file mode 100644 index 000000000..624c44643 --- /dev/null +++ b/src/auditordb/pg_get_progress_points.c @@ -0,0 +1,140 @@ +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file auditordb/pg_get_progress_points.c + * @brief Implementation of the get_progress_points function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include "taler_error_codes.h" +#include "taler_dbevents.h" +#include "taler_pq_lib.h" +#include "pg_get_progress_points.h" +#include "pg_helper.h" + + +struct ProgressContext +{ + + /** + * Function to call for each progress point. + */ + TALER_AUDITORDB_ProgressPointsCallback cb; + + /** + * Closure for @e cb + */ + void *cb_cls; + + /** + * Plugin context. + */ + struct PostgresClosure *pg; + + /** + * Query status to return. + */ + enum GNUNET_DB_QueryStatus qs; +}; + + +/** + * Helper function for #TAH_PG_get_progress(). + * To be called with the results of a SELECT statement + * that has returned @a num_results results. + * + * @param cls closure of type `struct ProgressContext *` + * @param result the postgres result + * @param num_results the number of results in @a result + */ +static void +progress_cb (void *cls, + PGresult *result, + unsigned int num_results) +{ + struct ProgressContext *dcc = cls; + + for (unsigned int i = 0; i < num_results; i++) + { + struct TALER_AUDITORDB_Progress dc; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("progress_key", + &dc.progress_key), + GNUNET_PQ_result_spec_uint64 ("progress_offset", + &dc.progress_offset), + GNUNET_PQ_result_spec_end + }; + enum GNUNET_GenericReturnValue rval; + + if (GNUNET_OK != + GNUNET_PQ_extract_result (result, + rs, + i)) + { + GNUNET_break (0); + dcc->qs = GNUNET_DB_STATUS_HARD_ERROR; + return; + } + dcc->qs = i + 1; + rval = dcc->cb (dcc->cb_cls, + &dc); + GNUNET_PQ_cleanup_result (rs); + if (GNUNET_OK != rval) + break; + } +} + + +enum GNUNET_DB_QueryStatus +TAH_PG_get_progress_points ( + void *cls, + const char *progress_key, + TALER_AUDITORDB_ProgressPointsCallback cb, + void *cb_cls) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + NULL == progress_key + ? GNUNET_PQ_query_param_null () + : GNUNET_PQ_query_param_string (progress_key), + GNUNET_PQ_query_param_end + }; + struct ProgressContext dcc = { + .cb = cb, + .cb_cls = cb_cls, + .pg = pg + }; + enum GNUNET_DB_QueryStatus qs; + + PREPARE (pg, + "auditor_progress_points_get", + "SELECT" + " progress_key" + ",progress_offset" + " FROM auditor_progress" + " WHERE ($1::TEXT IS NULL OR progress_key = $1)" + ); + qs = GNUNET_PQ_eval_prepared_multi_select ( + pg->conn, + "auditor_progress_points_get", + params, + &progress_cb, + &dcc); + if (qs > 0) + return dcc.qs; + GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs); + return qs; +} diff --git a/src/auditordb/pg_get_progress_points.h b/src/auditordb/pg_get_progress_points.h new file mode 100644 index 000000000..c044d3e2f --- /dev/null +++ b/src/auditordb/pg_get_progress_points.h @@ -0,0 +1,46 @@ +/* + This file is part of TALER + Copyright (C) 2024 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file auditordb/pg_get_progress_points.h + * @brief implementation of the get_progress_points function for Postgres + * @author Christian Grothoff + */ +#ifndef PG_GET_PROGRESS_POINTS_H +#define PG_GET_PROGRESS_POINTS_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + + +/** + * Get information about progress from the database. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param progress_key only return this particular progress point + * @param cb function to call with results + * @param cb_cls closure for @a cb + * @return query result status + */ +enum GNUNET_DB_QueryStatus +TAH_PG_get_progress_points ( + void *cls, + const char *progress_key, + TALER_AUDITORDB_ProgressPointsCallback cb, + void *cb_cls); + + +#endif diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c index af30b5648..877475d17 100644 --- a/src/auditordb/plugin_auditordb_postgres.c +++ b/src/auditordb/plugin_auditordb_postgres.c @@ -49,6 +49,7 @@ #include "pg_insert_reserve_info.h" #include "pg_select_historic_denom_revenue.h" #include "pg_select_historic_reserve_revenue.h" +#include "pg_get_progress_points.h" #include "pg_select_pending_deposits.h" #include "pg_select_purse_expired.h" #include "pg_update_generic_suppressed.h" @@ -770,6 +771,9 @@ libtaler_plugin_auditordb_postgres_init (void *cls) plugin->update_denominations_without_sigs = &TAH_PG_update_denominations_without_sigs; + plugin->get_progress_points + = &TAH_PG_get_progress_points; + plugin->delete_misattribution_in_inconsistency = &TAH_PG_del_misattribution_in_inconsistency; diff --git a/src/include/taler_auditordb_plugin.h b/src/include/taler_auditordb_plugin.h index 2ec09c1b7..026351964 100644 --- a/src/include/taler_auditordb_plugin.h +++ b/src/include/taler_auditordb_plugin.h @@ -304,11 +304,10 @@ struct TALER_AUDITORDB_EmergenciesByCount }; /** - * Information about a refreshes hanging + * Information about progress of the audit. */ struct TALER_AUDITORDB_Progress { - uint64_t row_id; char *progress_key; uint64_t progress_offset; }; @@ -502,20 +501,6 @@ typedef enum GNUNET_GenericReturnValue uint64_t serial_id, const struct TALER_AUDITORDB_EmergenciesByCount *dc); -/** - * Function called with progress stored in - * the auditor's database. - * - * @param cls closure - * @param serial_id location of the @a dc in the database - * @param dc the structure itself - * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating - */ -typedef enum GNUNET_GenericReturnValue -(*TALER_AUDITORDB_ProgressCallback)( - void *cls, - uint64_t serial_id, - const struct TALER_AUDITORDB_Progress *dc); /** * Function called with refreshes hanging stored in @@ -591,21 +576,16 @@ typedef enum GNUNET_GenericReturnValue uint64_t serial_id, const struct TALER_AUDITORDB_ReserveBalanceInsufficientInconsistency *dc); -/** - * Function called with reserve balance insufficient inconsistency stored in - * the auditor's database. - * - * @param cls closure - * @param serial_id location of the @a dc in the database - * @param dc the balance itself - * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating - */ typedef enum GNUNET_GenericReturnValue (*TALER_AUDITORDB_BalancesCallback)( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_Balances *dc); +typedef enum GNUNET_GenericReturnValue +(*TALER_AUDITORDB_ProgressPointsCallback)( + void *cls, + const struct TALER_AUDITORDB_Progress *pp); + /** * Balance values for a reserve (or all reserves). */ @@ -898,14 +878,11 @@ typedef enum GNUNET_GenericReturnValue typedef enum GNUNET_GenericReturnValue (*TALER_AUDITORDB_DenominationsWithoutSigsCallback)( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_DenominationsWithoutSigs *dc); - typedef enum GNUNET_GenericReturnValue (*TALER_AUDITORDB_MisattributionInInconsistencyCallback)( void *cls, - uint64_t serial_id, const struct TALER_AUDITORDB_MisattributionInInconsistency *dc); typedef enum GNUNET_GenericReturnValue @@ -1224,10 +1201,7 @@ struct TALER_AUDITORDB_Plugin * Get information about balances from the database. * * @param cls the @e cls of this struct with the plugin-specific state - * @param limit number of balances to return at most, - * negative value to descend from @a offset - * @param offset row/serial ID where to start the iteration (0 from - * the start, exclusive, i.e. serial_ids must start from 1) + * @param balance_key only return this particular balance * @param cb function to call with results * @param cb_cls closure for @a cb * @return query result status @@ -1235,13 +1209,27 @@ struct TALER_AUDITORDB_Plugin enum GNUNET_DB_QueryStatus (*get_balances)( void *cls, - int64_t limit, - uint64_t offset, const char *balance_key, TALER_AUDITORDB_BalancesCallback cb, void *cb_cls); /** + * Get information about progress from the database. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param progress_key only return this particular progress point + * @param cb function to call with results + * @param cb_cls closure for @a cb + * @return query result status + */ + enum GNUNET_DB_QueryStatus + (*get_progress_points)( + void *cls, + const char *progress_key, + TALER_AUDITORDB_ProgressPointsCallback cb, + void *cb_cls); + + /** * Insert information about a signing key of the exchange. * * @param cls the @e cls of this struct with the plugin-specific state @@ -1391,8 +1379,7 @@ struct TALER_AUDITORDB_Plugin int64_t limit, uint64_t offset, bool return_suppressed, - bool filter_spec_pub, - struct GNUNET_CRYPTO_EddsaPublicKey op_spec_pub, + const struct GNUNET_CRYPTO_EddsaPublicKey *op_spec_pub, const char *op, TALER_AUDITORDB_BadSigLossesCallback cb, void *cb_cls); @@ -1407,15 +1394,6 @@ struct TALER_AUDITORDB_Plugin void *cb_cls); enum GNUNET_DB_QueryStatus - (*get_progress)( - void *cls, - int64_t limit, - uint64_t offset, - bool return_suppressed, - TALER_AUDITORDB_ProgressCallback cb, - void *cb_cls); - - enum GNUNET_DB_QueryStatus (*get_refreshes_hanging)( void *cls, int64_t limit, @@ -1550,12 +1528,6 @@ struct TALER_AUDITORDB_Plugin void *cls, const struct TALER_AUDITORDB_ClosureLags *dc); - - enum GNUNET_DB_QueryStatus - (*insert_progress)( - void *cls, - const struct TALER_AUDITORDB_Progress *dc); - enum GNUNET_DB_QueryStatus (*insert_refreshes_hanging)( void *cls, |