From d940480cb794296c63f7f692cf242f63b8ddb17e Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 18 Apr 2023 19:35:42 +0200 Subject: work around gcc bug. Fixes #7585. --- src/backenddb/plugin_merchantdb_postgres.c | 412 +---------------------------- 1 file changed, 5 insertions(+), 407 deletions(-) (limited to 'src/backenddb/plugin_merchantdb_postgres.c') 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 #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" @@ -310,349 +311,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. * @@ -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 -- cgit v1.2.3