summaryrefslogtreecommitdiff
path: root/src/backenddb
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2023-04-18 19:35:42 +0200
committerChristian Grothoff <grothoff@gnunet.org>2023-04-18 19:35:42 +0200
commitd940480cb794296c63f7f692cf242f63b8ddb17e (patch)
tree453c3e5999c0c438ed399977c3b57588aba24b0a /src/backenddb
parentccfd643cdfe7120f2f6c21c5b90f9bb309fe9608 (diff)
downloadmerchant-d940480cb794296c63f7f692cf242f63b8ddb17e.tar.gz
merchant-d940480cb794296c63f7f692cf242f63b8ddb17e.tar.bz2
merchant-d940480cb794296c63f7f692cf242f63b8ddb17e.zip
work around gcc bug. Fixes #7585.
Diffstat (limited to 'src/backenddb')
-rw-r--r--src/backenddb/Makefile.am1
-rw-r--r--src/backenddb/pg_helper.h1
-rw-r--r--src/backenddb/pg_lookup_instances.c445
-rw-r--r--src/backenddb/pg_lookup_instances.h60
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c412
5 files changed, 512 insertions, 407 deletions
diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am
index b8d2cbbf..01947a81 100644
--- a/src/backenddb/Makefile.am
+++ b/src/backenddb/Makefile.am
@@ -55,6 +55,7 @@ libtaler_plugin_merchantdb_postgres_la_SOURCES = \
pg_insert_wirewatch_progress.h pg_insert_wirewatch_progress.c \
pg_update_wirewatch_progress.h pg_update_wirewatch_progress.c \
pg_select_wirewatch_progress.h pg_select_wirewatch_progress.c \
+ pg_lookup_instances.h pg_lookup_instances.c \
pg_lookup_transfers.h pg_lookup_transfers.c \
plugin_merchantdb_postgres.c pg_helper.h
libtaler_plugin_merchantdb_postgres_la_LIBADD = \
diff --git a/src/backenddb/pg_helper.h b/src/backenddb/pg_helper.h
index b058d2f4..28636577 100644
--- a/src/backenddb/pg_helper.h
+++ b/src/backenddb/pg_helper.h
@@ -21,6 +21,7 @@
#ifndef PG_HELPER_H
#define PG_HELPER_H
+#include <gnunet/gnunet_db_lib.h>
/**
* Type of the "cls" argument given to each of the functions in
diff --git a/src/backenddb/pg_lookup_instances.c b/src/backenddb/pg_lookup_instances.c
new file mode 100644
index 00000000..acf3ada3
--- /dev/null
+++ b/src/backenddb/pg_lookup_instances.c
@@ -0,0 +1,445 @@
+/*
+ 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_instances.c
+ * @brief Implementation of the lookup_instances function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <taler/taler_error_codes.h>
+#include <taler/taler_pq_lib.h>
+#include "pg_lookup_instances.h"
+#include "pg_helper.h"
+
+
+/**
+ * Context for lookup_instances().
+ */
+struct LookupInstancesContext
+{
+ /**
+ * Function to call with the results.
+ */
+ TALER_MERCHANTDB_InstanceCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Database context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Instance settings, valid only during find_instances_cb().
+ */
+ struct TALER_MERCHANTDB_InstanceSettings is;
+
+ /**
+ * Instance authentication settings, valid only during find_instances_cb().
+ */
+ struct TALER_MERCHANTDB_InstanceAuthSettings ias;
+
+ /**
+ * Instance serial number, valid only during find_instances_cb().
+ */
+ uint64_t instance_serial;
+
+ /**
+ * Public key of the current instance, valid only during find_instances_cb().
+ */
+ struct TALER_MerchantPublicKeyP merchant_pub;
+
+ /**
+ * Set to the return value on errors.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+
+ /**
+ * true if we only are interested in instances for which we have the private key.
+ */
+ bool active_only;
+};
+
+
+/**
+ * Helper function to run PREPARE() macro.
+ *
+ * @param pg closure to pass
+ * @return status of the preparation
+ */
+static enum GNUNET_DB_QueryStatus
+prepare (struct PostgresClosure *pg)
+{
+ PREPARE (pg,
+ "lookup_instance_private_key",
+ "SELECT"
+ " merchant_priv"
+ " FROM merchant_keys"
+ " WHERE merchant_serial=$1");
+ PREPARE (pg,
+ "lookup_accounts",
+ "SELECT"
+ " h_wire"
+ ",salt"
+ ",payto_uri"
+ ",active"
+ " FROM merchant_accounts"
+ " WHERE merchant_serial=$1");
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+}
+
+
+/**
+ * We are processing an instances lookup and have the @a accounts.
+ * Find the private key if possible, and invoke the callback.
+ *
+ * @param lic context we are handling
+ * @param num_accounts length of @a accounts array
+ * @param accounts information about accounts of the instance in @a lic
+ */
+static void
+call_with_accounts (struct LookupInstancesContext *lic,
+ unsigned int num_accounts,
+ const struct TALER_MERCHANTDB_AccountDetails accounts[])
+{
+ struct PostgresClosure *pg = lic->pg;
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&lic->instance_serial),
+ GNUNET_PQ_query_param_end
+ };
+ struct TALER_MerchantPrivateKeyP merchant_priv;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_priv",
+ &merchant_priv),
+ GNUNET_PQ_result_spec_end
+ };
+
+ qs = prepare (pg);
+ if (qs < 0)
+ {
+ GNUNET_break (0);
+ lic->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "lookup_instance_private_key",
+ params,
+ rs);
+ if (qs < 0)
+ {
+ GNUNET_break (0);
+ lic->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ if ( (0 == qs) &&
+ (lic->active_only) )
+ return; /* skip, not interesting */
+ lic->cb (lic->cb_cls,
+ &lic->merchant_pub,
+ (0 == qs) ? NULL : &merchant_priv,
+ &lic->is,
+ &lic->ias,
+ num_accounts,
+ accounts);
+}
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results about accounts.
+ *
+ * @param cls of type `struct FindInstancesContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lookup_accounts_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupInstancesContext *lic = cls;
+ char *paytos[num_results];
+ struct TALER_MERCHANTDB_AccountDetails accounts[num_results];
+
+ /* Note: this memset is completely superfluous, but gcc-11 (and gcc-12) have
+ a bug creating a warning without it! See #7585 */
+ memset (accounts,
+ 0,
+ sizeof (accounts));
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_MERCHANTDB_AccountDetails *account = &accounts[i];
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("h_wire",
+ &account->h_wire),
+ GNUNET_PQ_result_spec_auto_from_type ("salt",
+ &account->salt),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &paytos[i]),
+ GNUNET_PQ_result_spec_bool ("active",
+ &account->active),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ lic->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ for (unsigned int j = 0; j < i; j++)
+ GNUNET_free (paytos[j]);
+ return;
+ }
+ account->payto_uri = paytos[i];
+ }
+ call_with_accounts (lic,
+ num_results,
+ accounts);
+ for (unsigned int i = 0; i < num_results; i++)
+ GNUNET_free (paytos[i]);
+}
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results about instances.
+ *
+ * @param cls of type `struct FindInstancesContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lookup_instances_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupInstancesContext *lic = cls;
+ struct PostgresClosure *pg = lic->pg;
+
+ lic->qs = prepare (pg);
+ if (lic->qs < 0)
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ bool no_auth;
+ bool no_salt;
+ uint32_t ut32;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("merchant_serial",
+ &lic->instance_serial),
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
+ &lic->merchant_pub),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("auth_hash",
+ &lic->ias.auth_hash),
+ &no_auth),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("auth_salt",
+ &lic->ias.auth_salt),
+ &no_salt),
+ GNUNET_PQ_result_spec_string ("merchant_id",
+ &lic->is.id),
+ GNUNET_PQ_result_spec_string ("merchant_name",
+ &lic->is.name),
+ GNUNET_PQ_result_spec_uint32 ("user_type",
+ &ut32),
+ TALER_PQ_result_spec_json ("address",
+ &lic->is.address),
+ TALER_PQ_result_spec_json ("jurisdiction",
+ &lic->is.jurisdiction),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("default_max_deposit_fee",
+ &lic->is.default_max_deposit_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("default_max_wire_fee",
+ &lic->is.default_max_wire_fee),
+ GNUNET_PQ_result_spec_uint32 ("default_wire_fee_amortization",
+ &lic->is.default_wire_fee_amortization),
+ GNUNET_PQ_result_spec_relative_time ("default_wire_transfer_delay",
+ &lic->is.default_wire_transfer_delay),
+ GNUNET_PQ_result_spec_relative_time ("default_pay_delay",
+ &lic->is.default_pay_delay),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("website",
+ &lic->is.website),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("email",
+ &lic->is.email),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("logo",
+ &lic->is.logo),
+ NULL),
+ GNUNET_PQ_result_spec_end
+ };
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&lic->instance_serial),
+ GNUNET_PQ_query_param_end
+ };
+
+ memset (&lic->ias.auth_salt,
+ 0,
+ sizeof (lic->ias.auth_salt));
+ memset (&lic->ias.auth_hash,
+ 0,
+ sizeof (lic->ias.auth_hash));
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ lic->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ lic->is.ut = (enum TALER_KYCLOGIC_KycUserType) ut32;
+ lic->qs = GNUNET_PQ_eval_prepared_multi_select (lic->pg->conn,
+ "lookup_accounts",
+ params,
+ &lookup_accounts_cb,
+ lic);
+ if (0 > lic->qs)
+ {
+ /* lookup_accounts_cb() did not run, still notify about the
+ account-less instance! */
+ call_with_accounts (lic,
+ 0,
+ NULL);
+ }
+ GNUNET_PQ_cleanup_result (rs);
+ if (0 > lic->qs)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_instances (void *cls,
+ bool active_only,
+ TALER_MERCHANTDB_InstanceCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct LookupInstancesContext lic = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .active_only = active_only,
+ .pg = pg
+ };
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ check_connection (pg);
+ PREPARE (pg,
+ "lookup_instances",
+ "SELECT"
+ " merchant_serial"
+ ",merchant_pub"
+ ",auth_hash"
+ ",auth_salt"
+ ",merchant_id"
+ ",merchant_name"
+ ",user_type"
+ ",address"
+ ",jurisdiction"
+ ",default_max_deposit_fee_val"
+ ",default_max_deposit_fee_frac"
+ ",default_max_wire_fee_val"
+ ",default_max_wire_fee_frac"
+ ",default_wire_fee_amortization"
+ ",default_wire_transfer_delay"
+ ",default_pay_delay"
+ ",website"
+ ",email"
+ ",logo"
+ " FROM merchant_instances");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "lookup_instances",
+ params,
+ &lookup_instances_cb,
+ &lic);
+ if (0 > lic.qs)
+ return lic.qs;
+ return qs;
+}
+
+
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_instance (void *cls,
+ const char *id,
+ bool active_only,
+ TALER_MERCHANTDB_InstanceCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct LookupInstancesContext lic = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .active_only = active_only,
+ .pg = pg
+ };
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (id),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ check_connection (pg);
+ PREPARE (pg,
+ "lookup_instance",
+ "SELECT"
+ " merchant_serial"
+ ",merchant_pub"
+ ",auth_hash"
+ ",auth_salt"
+ ",merchant_id"
+ ",merchant_name"
+ ",user_type"
+ ",address"
+ ",jurisdiction"
+ ",default_max_deposit_fee_val"
+ ",default_max_deposit_fee_frac"
+ ",default_max_wire_fee_val"
+ ",default_max_wire_fee_frac"
+ ",default_wire_fee_amortization"
+ ",default_wire_transfer_delay"
+ ",default_pay_delay"
+ ",website"
+ ",email"
+ ",logo"
+ " FROM merchant_instances"
+ " WHERE merchant_id=$1");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "lookup_instance",
+ params,
+ &lookup_instances_cb,
+ &lic);
+ if (0 > lic.qs)
+ return lic.qs;
+ return qs;
+}
+
diff --git a/src/backenddb/pg_lookup_instances.h b/src/backenddb/pg_lookup_instances.h
new file mode 100644
index 00000000..e3b20ff1
--- /dev/null
+++ b/src/backenddb/pg_lookup_instances.h
@@ -0,0 +1,60 @@
+/*
+ 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_instances.h
+ * @brief implementation of the lookup_instances function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_INSTANCES_H
+#define PG_LOOKUP_INSTANCES_H
+
+#include <taler/taler_util.h>
+#include <taler/taler_json_lib.h>
+#include "taler_merchantdb_plugin.h"
+
+
+/**
+ * Lookup all of the instances this backend has configured.
+ *
+ * @param cls closure
+ * @param active_only only find 'active' instances
+ * @param cb function to call on all instances found
+ * @param cb_cls closure for @a cb
+ */
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_instances (void *cls,
+ bool active_only,
+ TALER_MERCHANTDB_InstanceCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Lookup one of the instances this backend has configured.
+ *
+ * @param cls closure
+ * @param id instance ID to resolve
+ * @param active_only only find 'active' instances
+ * @param cb function to call on all instances found
+ * @param cb_cls closure for @a cb
+ */
+enum GNUNET_DB_QueryStatus
+TMH_PG_lookup_instance (void *cls,
+ const char *id,
+ bool active_only,
+ TALER_MERCHANTDB_InstanceCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c
index 6f3789a6..4728801f 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -30,6 +30,7 @@
#include <taler/taler_mhd_lib.h>
#include "taler_merchantdb_plugin.h"
#include "pg_helper.h"
+#include "pg_lookup_instances.h"
#include "pg_lookup_transfers.h"
#include "pg_insert_wirewatch_progress.h"
#include "pg_update_wirewatch_progress.h"
@@ -311,349 +312,6 @@ postgres_commit (void *cls)
/**
- * Context for lookup_instances().
- */
-struct LookupInstancesContext
-{
- /**
- * Function to call with the results.
- */
- TALER_MERCHANTDB_InstanceCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Database context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Instance settings, valid only during find_instances_cb().
- */
- struct TALER_MERCHANTDB_InstanceSettings is;
-
- /**
- * Instance authentication settings, valid only during find_instances_cb().
- */
- struct TALER_MERCHANTDB_InstanceAuthSettings ias;
-
- /**
- * Instance serial number, valid only during find_instances_cb().
- */
- uint64_t instance_serial;
-
- /**
- * Public key of the current instance, valid only during find_instances_cb().
- */
- struct TALER_MerchantPublicKeyP merchant_pub;
-
- /**
- * Set to the return value on errors.
- */
- enum GNUNET_DB_QueryStatus qs;
-
- /**
- * true if we only are interested in instances for which we have the private key.
- */
- bool active_only;
-};
-
-
-/**
- * We are processing an instances lookup and have the @a accounts.
- * Find the private key if possible, and invoke the callback.
- *
- * @param lic context we are handling
- * @param num_accounts length of @a accounts array
- * @param accounts information about accounts of the instance in @a lic
- */
-static void
-call_with_accounts (struct LookupInstancesContext *lic,
- unsigned int num_accounts,
- const struct TALER_MERCHANTDB_AccountDetails accounts[])
-{
- struct PostgresClosure *pg = lic->pg;
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&lic->instance_serial),
- GNUNET_PQ_query_param_end
- };
- struct TALER_MerchantPrivateKeyP merchant_priv;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("merchant_priv",
- &merchant_priv),
- GNUNET_PQ_result_spec_end
- };
-
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_instance_private_key",
- params,
- rs);
- if (qs < 0)
- {
- GNUNET_break (0);
- lic->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- if ( (0 == qs) &&
- (lic->active_only) )
- return; /* skip, not interesting */
- lic->cb (lic->cb_cls,
- &lic->merchant_pub,
- (0 == qs) ? NULL : &merchant_priv,
- &lic->is,
- &lic->ias,
- num_accounts,
- accounts);
-}
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results about accounts.
- *
- * @param cls of type `struct FindInstancesContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lookup_accounts_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupInstancesContext *lic = cls;
- char *paytos[num_results];
- struct TALER_MERCHANTDB_AccountDetails accounts[num_results];
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- uint8_t active;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("h_wire",
- &accounts[i].h_wire),
- GNUNET_PQ_result_spec_auto_from_type ("salt",
- &accounts[i].salt),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &paytos[i]),
- GNUNET_PQ_result_spec_auto_from_type ("active",
- &active),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- lic->qs = GNUNET_DB_STATUS_HARD_ERROR;
- for (unsigned int j = 0; j < i; j++)
- GNUNET_free (paytos[j]);
- return;
- }
- accounts[i].active = (0 != active);
- accounts[i].payto_uri = paytos[i];
- }
- call_with_accounts (lic,
- num_results,
- accounts);
- for (unsigned int i = 0; i < num_results; i++)
- GNUNET_free (paytos[i]);
-}
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results about instances.
- *
- * @param cls of type `struct FindInstancesContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-lookup_instances_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LookupInstancesContext *lic = cls;
- struct PostgresClosure *pg = lic->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- bool no_auth;
- bool no_salt;
- uint32_t ut32;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("merchant_serial",
- &lic->instance_serial),
- GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
- &lic->merchant_pub),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("auth_hash",
- &lic->ias.auth_hash),
- &no_auth),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("auth_salt",
- &lic->ias.auth_salt),
- &no_salt),
- GNUNET_PQ_result_spec_string ("merchant_id",
- &lic->is.id),
- GNUNET_PQ_result_spec_string ("merchant_name",
- &lic->is.name),
- GNUNET_PQ_result_spec_uint32 ("user_type",
- &ut32),
- TALER_PQ_result_spec_json ("address",
- &lic->is.address),
- TALER_PQ_result_spec_json ("jurisdiction",
- &lic->is.jurisdiction),
- TALER_PQ_RESULT_SPEC_AMOUNT ("default_max_deposit_fee",
- &lic->is.default_max_deposit_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT ("default_max_wire_fee",
- &lic->is.default_max_wire_fee),
- GNUNET_PQ_result_spec_uint32 ("default_wire_fee_amortization",
- &lic->is.default_wire_fee_amortization),
- GNUNET_PQ_result_spec_relative_time ("default_wire_transfer_delay",
- &lic->is.default_wire_transfer_delay),
- GNUNET_PQ_result_spec_relative_time ("default_pay_delay",
- &lic->is.default_pay_delay),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("website",
- &lic->is.website),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("email",
- &lic->is.email),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("logo",
- &lic->is.logo),
- NULL),
- GNUNET_PQ_result_spec_end
- };
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&lic->instance_serial),
- GNUNET_PQ_query_param_end
- };
-
- memset (&lic->ias.auth_salt,
- 0,
- sizeof (lic->ias.auth_salt));
- memset (&lic->ias.auth_hash,
- 0,
- sizeof (lic->ias.auth_hash));
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- lic->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- lic->is.ut = (enum TALER_KYCLOGIC_KycUserType) ut32;
- lic->qs = GNUNET_PQ_eval_prepared_multi_select (lic->pg->conn,
- "lookup_accounts",
- params,
- &lookup_accounts_cb,
- lic);
- if (0 > lic->qs)
- {
- /* lookup_accounts_cb() did not run, still notify about the
- account-less instance! */
- call_with_accounts (lic,
- 0,
- NULL);
- }
- GNUNET_PQ_cleanup_result (rs);
- if (0 > lic->qs)
- break;
- }
-}
-
-
-/**
- * Lookup all of the instances this backend has configured.
- *
- * @param cls closure
- * @param active_only only find 'active' instances
- * @param cb function to call on all instances found
- * @param cb_cls closure for @a cb
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_instances (void *cls,
- bool active_only,
- TALER_MERCHANTDB_InstanceCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct LookupInstancesContext lic = {
- .cb = cb,
- .cb_cls = cb_cls,
- .active_only = active_only,
- .pg = pg
- };
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- check_connection (pg);
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "lookup_instances",
- params,
- &lookup_instances_cb,
- &lic);
- if (0 > lic.qs)
- return lic.qs;
- return qs;
-}
-
-
-/**
- * Lookup all one of the instances this backend has configured.
- *
- * @param cls closure
- * @param id instance ID to resolve
- * @param active_only only find 'active' instances
- * @param cb function to call on all instances found
- * @param cb_cls closure for @a cb
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_instance (void *cls,
- const char *id,
- bool active_only,
- TALER_MERCHANTDB_InstanceCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct LookupInstancesContext lic = {
- .cb = cb,
- .cb_cls = cb_cls,
- .active_only = active_only,
- .pg = pg
- };
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (id),
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- check_connection (pg);
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "lookup_instance",
- params,
- &lookup_instances_cb,
- &lic);
- if (0 > lic.qs)
- return lic.qs;
- return qs;
-}
-
-
-/**
* Lookup authentication data of an instance.
*
* @param cls closure
@@ -7608,74 +7266,12 @@ postgres_connect (void *cls)
GNUNET_PQ_make_prepare ("end_transaction",
"COMMIT"),
/* for call_with_accounts(), part of postgres_lookup_instances() */
- GNUNET_PQ_make_prepare ("lookup_instance_private_key",
- "SELECT"
- " merchant_priv"
- " FROM merchant_keys"
- " WHERE merchant_serial=$1"),
- /* for find_instances_cb(), part of postgres_lookup_instances() */
- GNUNET_PQ_make_prepare ("lookup_accounts",
- "SELECT"
- " h_wire"
- ",salt"
- ",payto_uri"
- ",active"
- " FROM merchant_accounts"
- " WHERE merchant_serial=$1"),
- /* for postgres_lookup_instances() */
GNUNET_PQ_make_prepare ("lookup_instance_auth",
"SELECT"
" auth_hash"
",auth_salt"
" FROM merchant_instances"
" WHERE merchant_id=$1"),
- /* for postgres_lookup_instances() */
- GNUNET_PQ_make_prepare ("lookup_instances",
- "SELECT"
- " merchant_serial"
- ",merchant_pub"
- ",auth_hash"
- ",auth_salt"
- ",merchant_id"
- ",merchant_name"
- ",user_type"
- ",address"
- ",jurisdiction"
- ",default_max_deposit_fee_val"
- ",default_max_deposit_fee_frac"
- ",default_max_wire_fee_val"
- ",default_max_wire_fee_frac"
- ",default_wire_fee_amortization"
- ",default_wire_transfer_delay"
- ",default_pay_delay"
- ",website"
- ",email"
- ",logo"
- " FROM merchant_instances"),
- /* for postgres_lookup_instance() */
- GNUNET_PQ_make_prepare ("lookup_instance",
- "SELECT"
- " merchant_serial"
- ",merchant_pub"
- ",auth_hash"
- ",auth_salt"
- ",merchant_id"
- ",merchant_name"
- ",user_type"
- ",address"
- ",jurisdiction"
- ",default_max_deposit_fee_val"
- ",default_max_deposit_fee_frac"
- ",default_max_wire_fee_val"
- ",default_max_wire_fee_frac"
- ",default_wire_fee_amortization"
- ",default_wire_transfer_delay"
- ",default_pay_delay"
- ",website"
- ",email"
- ",logo"
- " FROM merchant_instances"
- " WHERE merchant_id=$1"),
/* for postgres_insert_instance() */
GNUNET_PQ_make_prepare ("insert_instance",
"INSERT INTO merchant_instances"
@@ -10135,8 +9731,6 @@ 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_instances = &postgres_lookup_instances;
- plugin->lookup_instance = &postgres_lookup_instance;
plugin->lookup_instance_auth = &postgres_lookup_instance_auth;
plugin->insert_instance = &postgres_insert_instance;
plugin->insert_account = &postgres_insert_account;
@@ -10202,6 +9796,10 @@ libtaler_plugin_merchantdb_postgres_init (void *cls)
&postgres_set_transfer_status_to_verified;
plugin->lookup_transfer_summary = &postgres_lookup_transfer_summary;
plugin->lookup_transfer_details = &postgres_lookup_transfer_details;
+ plugin->lookup_instances
+ = &TMH_PG_lookup_instances;
+ plugin->lookup_instance
+ = &TMH_PG_lookup_instance;
plugin->lookup_transfers
= &TMH_PG_lookup_transfers;
plugin->insert_wirewatch_progress