summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2023-05-08 20:46:03 -0600
committerIván Ávalos <avalos@disroot.org>2023-05-08 20:53:59 -0600
commit1b39e3bced6f3c8d9b7ffa885179dd9877e7ed0d (patch)
tree3455dc73be0549bd9db3ca112cba02e85f3f0678 /src
parent0ea0684f80f1dbbb9c4eadef03cd3af01412ccdd (diff)
downloadmerchant-1b39e3bced6f3c8d9b7ffa885179dd9877e7ed0d.tar.gz
merchant-1b39e3bced6f3c8d9b7ffa885179dd9877e7ed0d.tar.bz2
merchant-1b39e3bced6f3c8d9b7ffa885179dd9877e7ed0d.zip
Factor out lookup_instance_auth (shit job)
Diffstat (limited to 'src')
-rw-r--r--src/backenddb/Makefile.am1
-rw-r--r--src/backenddb/pg_lookup_instance_auth.c66
-rw-r--r--src/backenddb/pg_lookup_instance_auth.h40
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c47
4 files changed, 111 insertions, 43 deletions
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 <http://www.gnu.org/licenses/>
+ */
+/**
+ * @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 <taler/taler_error_codes.h>
+#include <taler/taler_dbevents.h>
+#include <taler/taler_pq_lib.h>
+#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 <http://www.gnu.org/licenses/>
+ */
+/**
+ * @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 <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
+#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 <gnunet/gnunet_util_lib.h>
@@ -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;