summaryrefslogtreecommitdiff
path: root/src/backenddb/pg_lookup_instances.c
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2023-09-01 14:27:48 +0200
committerChristian Grothoff <grothoff@gnunet.org>2023-09-01 14:27:48 +0200
commit35dcd4514a93ba0f5353ecd1194fc9b515f2aad4 (patch)
tree399d8f8fbebf5e8ac383fc318b7be08901279a31 /src/backenddb/pg_lookup_instances.c
parent858e3047b8b595ab693e16ce0bbe0b8983b072ed (diff)
downloadmerchant-35dcd4514a93ba0f5353ecd1194fc9b515f2aad4.tar.gz
merchant-35dcd4514a93ba0f5353ecd1194fc9b515f2aad4.tar.bz2
merchant-35dcd4514a93ba0f5353ecd1194fc9b515f2aad4.zip
new CRUD APIs for OTP devices and merchant accounts (fixes #7929, #7824), one minor test is still failing...
Diffstat (limited to 'src/backenddb/pg_lookup_instances.c')
-rw-r--r--src/backenddb/pg_lookup_instances.c121
1 files changed, 3 insertions, 118 deletions
diff --git a/src/backenddb/pg_lookup_instances.c b/src/backenddb/pg_lookup_instances.c
index 15137518..323b1957 100644
--- a/src/backenddb/pg_lookup_instances.c
+++ b/src/backenddb/pg_lookup_instances.c
@@ -92,17 +92,6 @@ prepare (struct PostgresClosure *pg)
" merchant_priv"
" FROM merchant_keys"
" WHERE merchant_serial=$1");
- PREPARE (pg,
- "lookup_accounts",
- "SELECT"
- " h_wire"
- ",salt"
- ",payto_uri"
- ",credit_facade_url"
- ",credit_facade_credentials"
- ",active"
- " FROM merchant_accounts"
- " WHERE merchant_serial=$1");
return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
}
@@ -112,13 +101,9 @@ prepare (struct PostgresClosure *pg)
* 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[])
+call_cb (struct LookupInstancesContext *lic)
{
struct PostgresClosure *pg = lic->pg;
enum GNUNET_DB_QueryStatus qs;
@@ -157,91 +142,7 @@ call_with_accounts (struct LookupInstancesContext *lic,
&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 LookupInstancesContext *`
- * @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[GNUNET_NZL (num_results)];
- char *facade_urls[GNUNET_NZL (num_results)];
- json_t *credentials[GNUNET_NZL (num_results)];
- struct TALER_MERCHANTDB_AccountDetails accounts[GNUNET_NZL (num_results)];
-
- memset (facade_urls,
- 0,
- sizeof (facade_urls));
- memset (credentials,
- 0,
- sizeof (credentials));
- /* 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_allow_null (
- GNUNET_PQ_result_spec_string ("credit_facade_url",
- &facade_urls[i]),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- TALER_PQ_result_spec_json ("credit_facade_credentials",
- &credentials[i]),
- NULL),
- 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]);
- GNUNET_free (facade_urls[j]);
- json_decref (credentials[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]);
- GNUNET_free (facade_urls[i]);
- json_decref (credentials[i]);
- }
+ &lic->ias);
}
@@ -316,10 +217,6 @@ lookup_instances_cb (void *cls,
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,
@@ -337,19 +234,7 @@ lookup_instances_cb (void *cls,
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);
- }
+ call_cb (lic);
GNUNET_PQ_cleanup_result (rs);
if (0 > lic->qs)
break;