From 1b39e3bced6f3c8d9b7ffa885179dd9877e7ed0d Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Mon, 8 May 2023 20:46:03 -0600 Subject: Factor out lookup_instance_auth (shit job) --- src/backenddb/Makefile.am | 1 + src/backenddb/pg_lookup_instance_auth.c | 66 ++++++++++++++++++++++++++++++ src/backenddb/pg_lookup_instance_auth.h | 40 ++++++++++++++++++ src/backenddb/plugin_merchantdb_postgres.c | 47 ++------------------- 4 files changed, 111 insertions(+), 43 deletions(-) create mode 100644 src/backenddb/pg_lookup_instance_auth.c create mode 100644 src/backenddb/pg_lookup_instance_auth.h (limited to 'src') diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am index ab46a59e..10c362d8 100644 --- a/src/backenddb/Makefile.am +++ b/src/backenddb/Makefile.am @@ -65,6 +65,7 @@ libtaler_plugin_merchantdb_postgres_la_SOURCES = \ pg_set_transfer_status_to_confirmed.h pg_set_transfer_status_to_confirmed.c \ pg_insert_exchange_account.h pg_insert_exchange_account.c \ pg_lookup_reserves.h pg_lookup_reserves.c \ + pg_lookup_instance_auth.h pg_lookup_instance_auth.c \ plugin_merchantdb_postgres.c pg_helper.h libtaler_plugin_merchantdb_postgres_la_LIBADD = \ $(LTLIBINTL) diff --git a/src/backenddb/pg_lookup_instance_auth.c b/src/backenddb/pg_lookup_instance_auth.c new file mode 100644 index 00000000..a78ba361 --- /dev/null +++ b/src/backenddb/pg_lookup_instance_auth.c @@ -0,0 +1,66 @@ +/* + 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_lookup_instance_auth.c + * @brief Implementation of the lookup_instance_auth function for Postgres + * @author Iván Ávalos + */ +#include "platform.h" +#include +#include +#include +#include "pg_lookup_instance_auth.h" +#include "pg_helper.h" + +/** + * Lookup authentication data of an instance. + * + * @param cls closure + * @param instance_id instance to query + * @param[out] ias where to store the auth data + */ +enum GNUNET_DB_QueryStatus +TMH_PG_lookup_instance_auth ( + void *cls, + const char *instance_id, + struct TALER_MERCHANTDB_InstanceAuthSettings *ias) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (instance_id), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_auto_from_type ("auth_hash", + &ias->auth_hash), + GNUNET_PQ_result_spec_auto_from_type ("auth_salt", + &ias->auth_salt), + GNUNET_PQ_result_spec_end + }; + + check_connection (pg); + PREPARE (pg, + "lookup_instance_auth", + "SELECT" + " auth_hash" + ",auth_salt" + " FROM merchant_instances" + " WHERE merchant_id=$1"); + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "lookup_instance_auth", + params, + rs); +} diff --git a/src/backenddb/pg_lookup_instance_auth.h b/src/backenddb/pg_lookup_instance_auth.h new file mode 100644 index 00000000..ff788a79 --- /dev/null +++ b/src/backenddb/pg_lookup_instance_auth.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 + */ +/** + * @file backenddb/pg_lookup_instance_auth.h + * @brief implementation of the lookup_instance_auth function for Postgres + * @author Iván Ávalos + */ +#ifndef PG_LOOKUP_INSTANCE_AUTH_H +#define PG_LOOKUP_INSTANCE_AUTH_H + +#include +#include +#include "taler_merchantdb_plugin.h" + +/** + * Lookup authentication data of an instance. + * + * @param cls closure + * @param instance_id instance to query + * @param[out] ias where to store the auth data + */ +enum GNUNET_DB_QueryStatus +TMH_PG_lookup_instance_auth (void *cls, + const char *instance_id, + struct TALER_MERCHANTDB_InstanceAuthSettings *ias); + +#endif diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 710fbdb3..a28fd716 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -20,6 +20,7 @@ * @author Christian Grothoff * @author Marcello Stanisci * @author Priscilla Huang + * @author Iván Ávalos */ #include "platform.h" #include @@ -41,6 +42,7 @@ #include "pg_select_accounts_by_exchange.h" #include "pg_insert_exchange_account.h" #include "pg_lookup_reserves.h" +#include "pg_lookup_instance_auth.h" #include "pg_update_transfer_status.h" #include "pg_set_transfer_status_to_confirmed.h" @@ -318,41 +320,6 @@ postgres_commit (void *cls) params); } - -/** - * Lookup authentication data of an instance. - * - * @param cls closure - * @param instance_id instance to query - * @param[out] ias where to store the auth data - */ -static enum GNUNET_DB_QueryStatus -postgres_lookup_instance_auth ( - void *cls, - const char *instance_id, - struct TALER_MERCHANTDB_InstanceAuthSettings *ias) -{ - struct PostgresClosure *pg = cls; - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (instance_id), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_auto_from_type ("auth_hash", - &ias->auth_hash), - GNUNET_PQ_result_spec_auto_from_type ("auth_salt", - &ias->auth_salt), - GNUNET_PQ_result_spec_end - }; - - check_connection (pg); - return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_instance_auth", - params, - rs); -} - - /** * Insert information about an instance into our database. * @@ -7027,13 +6994,6 @@ postgres_connect (void *cls) struct GNUNET_PQ_PreparedStatement ps[] = { GNUNET_PQ_make_prepare ("end_transaction", "COMMIT"), - /* for call_with_accounts(), part of postgres_lookup_instances() */ - GNUNET_PQ_make_prepare ("lookup_instance_auth", - "SELECT" - " auth_hash" - ",auth_salt" - " FROM merchant_instances" - " WHERE merchant_id=$1"), /* for postgres_insert_instance() */ GNUNET_PQ_make_prepare ("insert_instance", "INSERT INTO merchant_instances" @@ -9455,7 +9415,8 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) plugin->start_read_committed = &postgres_start_read_committed; plugin->rollback = &postgres_rollback; plugin->commit = &postgres_commit; - plugin->lookup_instance_auth = &postgres_lookup_instance_auth; + plugin->lookup_instance_auth + = &TMH_PG_lookup_instance_auth; plugin->insert_instance = &postgres_insert_instance; plugin->insert_account = &TMH_PG_insert_account; -- cgit v1.2.3