aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2024-08-14 11:54:27 +0200
committerChristian Grothoff <grothoff@gnunet.org>2024-08-14 11:54:27 +0200
commitaa32787f20ee7a08775c5412608067a4ced17d98 (patch)
tree3476991e6448b267b33ddbd7b2ae341fb2c15c7f /src
parent93b4b8819d2de6adec46e3275deaa9004173d92a (diff)
add generic suppression sql code
Diffstat (limited to 'src')
-rw-r--r--src/auditor/Makefile.am1
-rw-r--r--src/auditor/taler-auditor-httpd.c16
-rw-r--r--src/auditor/taler-auditor-httpd.h2
-rw-r--r--src/auditor/taler-auditor-httpd_patch_generic_suppressed.c138
-rw-r--r--src/auditor/taler-auditor-httpd_patch_generic_suppressed.h34
-rw-r--r--src/auditordb/Makefile.am1
-rw-r--r--src/auditordb/auditordb_plugin.c17
-rw-r--r--src/auditordb/pg_update_generic_suppressed.c91
-rw-r--r--src/auditordb/pg_update_generic_suppressed.h40
-rw-r--r--src/auditordb/plugin_auditordb_postgres.c4
-rw-r--r--src/include/taler_auditordb_lib.h18
-rw-r--r--src/include/taler_auditordb_plugin.h7
12 files changed, 364 insertions, 5 deletions
diff --git a/src/auditor/Makefile.am b/src/auditor/Makefile.am
index 866f5992e..67bed9c7c 100644
--- a/src/auditor/Makefile.am
+++ b/src/auditor/Makefile.am
@@ -182,6 +182,7 @@ taler_auditor_httpd_SOURCES = \
taler-auditor-httpd_purse-not-closed-inconsistencies-get.c taler-auditor-httpd_purse-not-closed-inconsistencies-get.h \
taler-auditor-httpd_purse-not-closed-inconsistencies-del.c taler-auditor-httpd_purse-not-closed-inconsistencies-del.h \
taler-auditor-httpd_reserve-balance-insufficient-inconsistency-get.c taler-auditor-httpd_reserve-balance-insufficient-inconsistency-get.h \
+ taler-auditor-httpd_patch_generic_suppressed.c taler-auditor-httpd_patch_generic_suppressed.h \
taler-auditor-httpd_reserve-balance-insufficient-inconsistency-del.c taler-auditor-httpd_reserve-balance-insufficient-inconsistency-del.h \
taler-auditor-httpd_bad-sig-losses-get.c taler-auditor-httpd_bad-sig-losses-get.h \
taler-auditor-httpd_bad-sig-losses-del.c taler-auditor-httpd_bad-sig-losses-del.h \
diff --git a/src/auditor/taler-auditor-httpd.c b/src/auditor/taler-auditor-httpd.c
index 48667390d..bda028faf 100644
--- a/src/auditor/taler-auditor-httpd.c
+++ b/src/auditor/taler-auditor-httpd.c
@@ -73,6 +73,7 @@
#include "taler-auditor-httpd_mhd.h"
#include "taler-auditor-httpd.h"
+#include "taler-auditor-httpd_patch_generic_suppressed.h"
#include "taler-auditor-httpd_emergency-by-count-upd.h"
#include "taler-auditor-httpd_row-inconsistency-upd.h"
#include "taler-auditor-httpd_purse-not-closed-inconsistencies-upd.h"
@@ -429,10 +430,17 @@ handle_mhd_request (void *cls,
"application/json",
NULL, 0,
&TAH_AMOUNT_ARITHMETIC_INCONSISTENCY_handler_delete, MHD_HTTP_OK, true },
- { "/monitoring/amount-arithmetic-inconsistency", MHD_HTTP_METHOD_PATCH,
- "application/json",
- NULL, 0,
- &TAH_AMOUNT_ARITHMETIC_INCONSISTENCY_handler_update, MHD_HTTP_OK, true },
+ {
+ "/monitoring/amount-arithmetic-inconsistency",
+ MHD_HTTP_METHOD_PATCH,
+ .mime_type = "application/json",
+ .data = NULL,
+ .data_size = 0,
+ &TAH_patch_handler_generic_suppressed,
+ MHD_HTTP_OK,
+ true,
+ .table = TALER_AUDITORDB_AMOUNT_ARITHMETIC_INCONSISTENCY
+ },
{ "/monitoring/coin-inconsistency", MHD_HTTP_METHOD_GET,
"application/json",
NULL, 0,
diff --git a/src/auditor/taler-auditor-httpd.h b/src/auditor/taler-auditor-httpd.h
index 9da0601ba..374963cca 100644
--- a/src/auditor/taler-auditor-httpd.h
+++ b/src/auditor/taler-auditor-httpd.h
@@ -108,6 +108,8 @@ struct TAH_RequestHandler
* Is client authentication required for this endpoint?
*/
bool requires_auth;
+
+ enum TALER_AUDITORDB_SuppressableTables table;
};
diff --git a/src/auditor/taler-auditor-httpd_patch_generic_suppressed.c b/src/auditor/taler-auditor-httpd_patch_generic_suppressed.c
new file mode 100644
index 000000000..f58635c5b
--- /dev/null
+++ b/src/auditor/taler-auditor-httpd_patch_generic_suppressed.c
@@ -0,0 +1,138 @@
+/*
+ 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_amount-arithmetic-inconsistency-upd.h"
+
+
+MHD_RESULT
+TAH_patch_handler_generic_suppressed (
+ struct TAH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ void **connection_cls,
+ const char *upload_data,
+ size_t *upload_data_size,
+ const char *const args[])
+{
+ enum GNUNET_DB_QueryStatus qs;
+ unsigned long long row_id;
+ char dummy;
+ bool suppressed;
+
+ (void) connection_cls;
+ 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);
+ }
+
+ if ( (NULL == args[1]) ||
+ (1 != sscanf (args[1],
+ "%llu%c",
+ &row_id,
+ &dummy)) )
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_AUDITOR_RESOURCE_NOT_FOUND,
+ "no row id specified");
+ }
+
+ {
+ enum GNUNET_GenericReturnValue res;
+ json_t *json;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_bool ("suppressed", &suppressed),
+ GNUNET_JSON_spec_end ()
+ };
+
+ 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)
+ {
+ GNUNET_break (0);
+ json_decref (json);
+ return MHD_NO; /* hard failure */
+ }
+ if (GNUNET_NO == res)
+ {
+ GNUNET_break_op (0);
+ json_decref (json);
+ return MHD_YES; /* failure */
+ }
+ json_decref (json);
+ }
+
+ /* execute transaction */
+ qs = TAH_plugin->update_generic_suppressed (TAH_plugin->cls,
+ rh->table,
+ row_id,
+ suppressed);
+
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "update_account");
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+ "unexpected serialization problem");
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_AUDITOR_RESOURCE_NOT_FOUND,
+ "no updates executed");
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ return TALER_MHD_reply_static (connection,
+ MHD_HTTP_NO_CONTENT,
+ NULL,
+ NULL,
+ 0);
+ }
+ GNUNET_break (0);
+ return MHD_NO;
+}
diff --git a/src/auditor/taler-auditor-httpd_patch_generic_suppressed.h b/src/auditor/taler-auditor-httpd_patch_generic_suppressed.h
new file mode 100644
index 000000000..55bcd75af
--- /dev/null
+++ b/src/auditor/taler-auditor-httpd_patch_generic_suppressed.h
@@ -0,0 +1,34 @@
+/*
+ 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_PATCH_GENERIC_SUPPRESSED_H
+#define SRC_TALER_AUDITOR_HTTPD_PATCH_GENERIC_SUPPRESSED_H
+
+
+#include <microhttpd.h>
+#include "taler-auditor-httpd.h"
+
+MHD_RESULT
+TAH_patch_handler_generic_suppressed (
+ 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/auditordb/Makefile.am b/src/auditordb/Makefile.am
index a38691b1c..919d4b94b 100644
--- a/src/auditordb/Makefile.am
+++ b/src/auditordb/Makefile.am
@@ -84,6 +84,7 @@ libtaler_plugin_auditordb_postgres_la_SOURCES = \
pg_select_historic_reserve_revenue.c pg_select_historic_reserve_revenue.h \
pg_select_pending_deposits.c pg_select_pending_deposits.h \
pg_select_purse_expired.c pg_select_purse_expired.h \
+ pg_update_generic_suppressed.c pg_update_generic_suppressed.h \
pg_update_auditor_progress.c pg_update_auditor_progress.h \
pg_update_balance.c pg_update_balance.h \
pg_update_denomination_balance.c pg_update_denomination_balance.h \
diff --git a/src/auditordb/auditordb_plugin.c b/src/auditordb/auditordb_plugin.c
index 635247aa3..d84158deb 100644
--- a/src/auditordb/auditordb_plugin.c
+++ b/src/auditordb/auditordb_plugin.c
@@ -24,6 +24,23 @@
#include <ltdl.h>
+const char *
+TALER_AUDITORDB_get_table_name (enum TALER_AUDITORDB_SuppressableTables table)
+{
+ const char *tables[] = {
+ "auditor_amount_arithmetic_inconsistency",
+ };
+
+ if ( (table < 0) ||
+ (table >= TALER_AUDITORDB_SUPPRESSABLE_TABLES_MAX))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ return tables[table];
+}
+
+
struct TALER_AUDITORDB_Plugin *
TALER_AUDITORDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
diff --git a/src/auditordb/pg_update_generic_suppressed.c b/src/auditordb/pg_update_generic_suppressed.c
new file mode 100644
index 000000000..b44f6025c
--- /dev/null
+++ b/src/auditordb/pg_update_generic_suppressed.c
@@ -0,0 +1,91 @@
+/*
+ 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 "taler_pq_lib.h"
+#include "pg_helper.h"
+#include "pg_update_closure_lags.h"
+
+struct Preparations
+{
+ /**
+ * Database reconnect counter.
+ */
+ unsigned long long cnt;
+
+ /**
+ * Which DB did we do prepare for.
+ */
+ struct PostgresClosure *pg;
+
+};
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_update_generic_suppressed (
+ void *cls,
+ enum TALER_AUDITORDB_SuppressableTables table,
+ uint64_t row_id,
+ bool suppressed)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&row_id),
+ GNUNET_PQ_query_param_bool (suppressed),
+ GNUNET_PQ_query_param_end
+ };
+ static struct Preparations preps[
+ TALER_AUDITORDB_SUPPRESSABLE_TABLES_MAX];
+
+ struct Preparations *prep = &preps[table];
+ const char *table_name = TALER_AUDITORDB_get_table_name (table);
+ char statement_name[256];
+
+ GNUNET_snprintf (statement_name,
+ sizeof (statement_name),
+ "update_%s",
+ table_name);
+ if ( (pg != prep->pg) ||
+ (prep->cnt < pg->prep_gen) )
+ {
+ char sql[256];
+ struct GNUNET_PQ_PreparedStatement ps[] = {
+ GNUNET_PQ_make_prepare (statement_name,
+ sql),
+ GNUNET_PQ_PREPARED_STATEMENT_END
+ };
+
+ GNUNET_snprintf (sql,
+ sizeof (sql),
+ "UPDATE %s SET"
+ " suppressed=$2"
+ " WHERE row_id=$1",
+ table_name);
+ if (GNUNET_OK !=
+ GNUNET_PQ_prepare_statements (pg->conn,
+ ps))
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ prep->pg = pg;
+ prep->cnt = pg->prep_gen;
+ }
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ statement_name,
+ params);
+}
diff --git a/src/auditordb/pg_update_generic_suppressed.h b/src/auditordb/pg_update_generic_suppressed.h
new file mode 100644
index 000000000..fffea794a
--- /dev/null
+++ b/src/auditordb/pg_update_generic_suppressed.h
@@ -0,0 +1,40 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 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 pg_update_auditor_progress.h
+ * @brief implementation of the update_auditor_progress function
+ * @author Christian Grothoff
+ */
+#ifndef PG_UPDATE_GENERIC_SUPPRESSED_H
+#define PG_UPDATE_GENERIC_SUPPRESSED_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ // FIXME: add comments
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_update_generic_suppressed (
+ void *cls,
+ enum TALER_AUDITORDB_SuppressableTables table,
+ uint64_t row_id,
+ bool suppressed);
+
+#endif
diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c
index 8db88ca6e..e4c952eca 100644
--- a/src/auditordb/plugin_auditordb_postgres.c
+++ b/src/auditordb/plugin_auditordb_postgres.c
@@ -50,6 +50,7 @@
#include "pg_select_historic_reserve_revenue.h"
#include "pg_select_pending_deposits.h"
#include "pg_select_purse_expired.h"
+#include "pg_update_generic_suppressed.h"
#include "pg_update_auditor_progress.h"
#include "pg_update_balance.h"
#include "pg_update_denomination_balance.h"
@@ -613,6 +614,9 @@ libtaler_plugin_auditordb_postgres_init (void *cls)
= &TAH_PG_insert_auditor_progress;
plugin->insert_balance
= &TAH_PG_insert_balance;
+ plugin->update_generic_suppressed
+ = &TAH_PG_update_generic_suppressed;
+
plugin->update_auditor_progress
= &TAH_PG_update_auditor_progress;
plugin->update_balance
diff --git a/src/include/taler_auditordb_lib.h b/src/include/taler_auditordb_lib.h
index 3ba3bb376..a05f59fc7 100644
--- a/src/include/taler_auditordb_lib.h
+++ b/src/include/taler_auditordb_lib.h
@@ -23,7 +23,23 @@
#ifndef TALER_AUDITORDB_LIB_H
#define TALER_AUDITORDB_LIB_H
-#include "taler_auditordb_plugin.h"
+
+enum TALER_AUDITORDB_SuppressableTables
+{
+ /**
+ * For auditor_amount_arithmetic_inconsistency table.
+ */
+ TALER_AUDITORDB_AMOUNT_ARITHMETIC_INCONSISTENCY,
+ /**
+ * Terminal.
+ */
+ TALER_AUDITORDB_SUPPRESSABLE_TABLES_MAX
+};
+
+
+// FIXME: comment
+const char *
+TALER_AUDITORDB_get_table_name (enum TALER_AUDITORDB_SuppressableTables table);
/**
* Initialize the plugin.
diff --git a/src/include/taler_auditordb_plugin.h b/src/include/taler_auditordb_plugin.h
index c4186e50f..2c9f94f86 100644
--- a/src/include/taler_auditordb_plugin.h
+++ b/src/include/taler_auditordb_plugin.h
@@ -1540,6 +1540,13 @@ struct TALER_AUDITORDB_Plugin
void *cls,
const struct TALER_AUDITORDB_Generic_Update *gu);
+ enum GNUNET_DB_QueryStatus
+ (*update_generic_suppressed)(
+ void *cls,
+ enum TALER_AUDITORDB_SuppressableTables table,
+ uint64_t row_id,
+ bool suppressed);
+
enum GNUNET_DB_QueryStatus
(*update_emergency_by_count)(