From 2bdf34b5563725c6ba6b643a021ddeb7649360a8 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Mon, 8 May 2023 21:35:21 -0600 Subject: Factor out update_instance_auth (shit_job) --- src/backenddb/Makefile.am | 1 + src/backenddb/pg_update_instance_auth.c | 52 ++++++++++++++++++++++++++++++ src/backenddb/pg_update_instance_auth.h | 42 ++++++++++++++++++++++++ src/backenddb/plugin_merchantdb_postgres.c | 40 ++--------------------- 4 files changed, 98 insertions(+), 37 deletions(-) create mode 100644 src/backenddb/pg_update_instance_auth.c create mode 100644 src/backenddb/pg_update_instance_auth.h diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am index da0b4a5b..36cfef51 100644 --- a/src/backenddb/Makefile.am +++ b/src/backenddb/Makefile.am @@ -72,6 +72,7 @@ libtaler_plugin_merchantdb_postgres_la_SOURCES = \ pg_delete_instance_private_key.h pg_delete_instance_private_key.c \ pg_purge_instance.h pg_purge_instance.c \ pg_update_instance.h pg_update_instance.c \ + pg_update_instance_auth.h pg_update_instance_auth.c \ plugin_merchantdb_postgres.c pg_helper.h libtaler_plugin_merchantdb_postgres_la_LIBADD = \ $(LTLIBINTL) diff --git a/src/backenddb/pg_update_instance_auth.c b/src/backenddb/pg_update_instance_auth.c new file mode 100644 index 00000000..d7077761 --- /dev/null +++ b/src/backenddb/pg_update_instance_auth.c @@ -0,0 +1,52 @@ +/* + 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 + */ +/** + * @file backenddb/pg_update_instance_auth.c + * @brief Implementation of the update_instance_auth function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include +#include +#include +#include "pg_update_instance_auth.h" +#include "pg_helper.h" + +enum GNUNET_DB_QueryStatus +TMH_PG_update_instance_auth ( + void *cls, + const char *merchant_id, + const struct TALER_MERCHANTDB_InstanceAuthSettings *is) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (merchant_id), + GNUNET_PQ_query_param_auto_from_type (&is->auth_hash), + GNUNET_PQ_query_param_auto_from_type (&is->auth_salt), + GNUNET_PQ_query_param_end + }; + + check_connection (pg); + PREPARE (pg, + "update_instance_auth", + "UPDATE merchant_instances SET" + " auth_hash=$2" + ",auth_salt=$3" + " WHERE merchant_id=$1"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "update_instance_auth", + params); +} diff --git a/src/backenddb/pg_update_instance_auth.h b/src/backenddb/pg_update_instance_auth.h new file mode 100644 index 00000000..cf0bc963 --- /dev/null +++ b/src/backenddb/pg_update_instance_auth.h @@ -0,0 +1,42 @@ +/* + 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 + */ +/** + * @file backenddb/pg_update_instance_auth.h + * @brief implementation of the update_instance_auth function for Postgres + * @author Iván Ávalos + */ +#ifndef PG_UPDATE_INSTANCE_AUTH_H +#define PG_UPDATE_INSTANCE_AUTH_H + +#include +#include +#include "taler_merchantdb_plugin.h" + +/** + * Update information about an instance's authentication settings + * into our database. + * + * @param cls closure + * @param merchant_id identity of the instance + * @param is authentication details about the instance + * @return database result code + */ +enum GNUNET_DB_QueryStatus +TMH_PG_update_instance_auth (void *cls, + const char *merchant_id, + const struct TALER_MERCHANTDB_InstanceAuthSettings *is); + +#endif diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 61e35837..463a8328 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -50,6 +50,7 @@ #include "pg_delete_instance_private_key.h" #include "pg_purge_instance.h" #include "pg_update_instance.h" +#include "pg_update_instance_auth.h" #include "pg_set_transfer_status_to_confirmed.h" @@ -327,36 +328,6 @@ postgres_commit (void *cls) } -/** - * Update information about an instance's authentication settings - * into our database. - * - * @param cls closure - * @param merchant_id identity of the instance - * @param is authentication details about the instance - * @return database result code - */ -static enum GNUNET_DB_QueryStatus -postgres_update_instance_auth ( - void *cls, - const char *merchant_id, - const struct TALER_MERCHANTDB_InstanceAuthSettings *is) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (merchant_id), - GNUNET_PQ_query_param_auto_from_type (&is->auth_hash), - GNUNET_PQ_query_param_auto_from_type (&is->auth_salt), - GNUNET_PQ_query_param_end - }; - - check_connection (pg); - return GNUNET_PQ_eval_prepared_non_select (pg->conn, - "update_instance_auth", - params); -} - - /** * Set an instance's account in our database to "inactive". * @@ -6621,12 +6592,6 @@ postgres_connect (void *cls) struct GNUNET_PQ_PreparedStatement ps[] = { GNUNET_PQ_make_prepare ("end_transaction", "COMMIT"), - /* for postgres_update_instance_auth() */ - GNUNET_PQ_make_prepare ("update_instance_auth", - "UPDATE merchant_instances SET" - " auth_hash=$2" - ",auth_salt=$3" - " WHERE merchant_id=$1"), /* for postgres_inactivate_account(); the merchant instance is implied from the random salt that is part of the h_wire calculation */ @@ -8960,7 +8925,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) = &TMH_PG_purge_instance; plugin->update_instance = &TMH_PG_update_instance; - plugin->update_instance_auth = &postgres_update_instance_auth; + plugin->update_instance_auth + = &TMH_PG_update_instance_auth; plugin->activate_account = &postgres_activate_account; plugin->inactivate_account = &postgres_inactivate_account; plugin->update_transfer_status -- cgit v1.2.3