summaryrefslogtreecommitdiff
path: root/src/pq
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-02-10 23:39:00 +0100
committerChristian Grothoff <christian@grothoff.org>2022-02-10 23:39:00 +0100
commit532d4ad0dca62055056e5b6093e82daa3541f690 (patch)
tree65e2d5b783d0a84b33779b8d0e89225d0e765353 /src/pq
parentd58d89dcab91823dff208d230e1b1b3a742810bd (diff)
downloadexchange-532d4ad0dca62055056e5b6093e82daa3541f690.tar.gz
exchange-532d4ad0dca62055056e5b6093e82daa3541f690.tar.bz2
exchange-532d4ad0dca62055056e5b6093e82daa3541f690.zip
-fixes to tests, and half-baked fixes for CS-/link (still fails)
Diffstat (limited to 'src/pq')
-rw-r--r--src/pq/pq_query_helper.c88
-rw-r--r--src/pq/pq_result_helper.c108
2 files changed, 195 insertions, 1 deletions
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c
index 8d6df60ce..9bffdd320 100644
--- a/src/pq/pq_query_helper.c
+++ b/src/pq/pq_query_helper.c
@@ -531,6 +531,94 @@ TALER_PQ_query_param_blinded_planchet (
* Function called to convert input argument into SQL parameters.
*
* @param cls closure
+ * @param data pointer to input argument
+ * @param data_len number of bytes in @a data (if applicable)
+ * @param[out] param_values SQL data to set
+ * @param[out] param_lengths SQL length data to set
+ * @param[out] param_formats SQL format data to set
+ * @param param_length number of entries available in the @a param_values, @a param_lengths and @a param_formats arrays
+ * @param[out] scratch buffer for dynamic allocations (to be done via #GNUNET_malloc()
+ * @param scratch_length number of entries left in @a scratch
+ * @return -1 on error, number of offsets used in @a scratch otherwise
+ */
+static int
+qconv_exchange_withdraw_values (void *cls,
+ const void *data,
+ size_t data_len,
+ void *param_values[],
+ int param_lengths[],
+ int param_formats[],
+ unsigned int param_length,
+ void *scratch[],
+ unsigned int scratch_length)
+{
+ const struct TALER_ExchangeWithdrawValues *alg_values = data;
+ size_t tlen;
+ size_t len;
+ uint32_t be[2];
+ char *buf;
+
+ (void) cls;
+ (void) data_len;
+ GNUNET_assert (1 == param_length);
+ GNUNET_assert (scratch_length > 0);
+ GNUNET_break (NULL == cls);
+ be[0] = htonl ((uint32_t) alg_values->cipher);
+ be[1] = htonl (0x010000); /* magic marker: EWV */
+ switch (alg_values->cipher)
+ {
+ case TALER_DENOMINATION_RSA:
+ tlen = 0;
+ break;
+ case TALER_DENOMINATION_CS:
+ tlen = sizeof (struct TALER_ExchangeWithdrawCsValues);
+ break;
+ default:
+ GNUNET_assert (0);
+ }
+ len = tlen + sizeof (be);
+ buf = GNUNET_malloc (len);
+ memcpy (buf,
+ &be,
+ sizeof (be));
+ switch (alg_values->cipher)
+ {
+ case TALER_DENOMINATION_RSA:
+ break;
+ case TALER_DENOMINATION_CS:
+ memcpy (&buf[sizeof (be)],
+ &alg_values->details.cs_values,
+ tlen);
+ break;
+ default:
+ GNUNET_assert (0);
+ }
+ scratch[0] = buf;
+ param_values[0] = (void *) buf;
+ param_lengths[0] = len;
+ param_formats[0] = 1;
+ return 1;
+}
+
+
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_exchange_withdraw_values (
+ const struct TALER_ExchangeWithdrawValues *alg_values)
+{
+ struct GNUNET_PQ_QueryParam res = {
+ .conv = &qconv_exchange_withdraw_values,
+ .data = alg_values,
+ .num_params = 1
+ };
+
+ return res;
+}
+
+
+/**
+ * Function called to convert input argument into SQL parameters.
+ *
+ * @param cls closure
* @param data pointer to input argument, here a `json_t *`
* @param data_len number of bytes in @a data (if applicable)
* @param[out] param_values SQL data to set
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c
index 6ee5da53e..33edc889b 100644
--- a/src/pq/pq_result_helper.c
+++ b/src/pq/pq_result_helper.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014, 2015, 2016, 2021 Taler Systems SA
+ Copyright (C) 2014-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
@@ -855,4 +855,110 @@ TALER_PQ_result_spec_blinded_planchet (
}
+/**
+ * Extract data from a Postgres database @a result at row @a row.
+ *
+ * @param cls closure
+ * @param result where to extract data from
+ * @param int row to extract data from
+ * @param fname name (or prefix) of the fields to extract from
+ * @param[in,out] dst_size where to store size of result, may be NULL
+ * @param[out] dst where to store the result
+ * @return
+ * #GNUNET_YES if all results could be extracted
+ * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
+ */
+static enum GNUNET_GenericReturnValue
+extract_exchange_withdraw_values (void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
+{
+ struct TALER_ExchangeWithdrawValues *alg_values = dst;
+ size_t len;
+ const char *res;
+ int fnum;
+ uint32_t be[2];
+
+ (void) cls;
+ (void) dst_size;
+ fnum = PQfnumber (result,
+ fname);
+ if (fnum < 0)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (PQgetisnull (result,
+ row,
+ fnum))
+ return GNUNET_NO;
+
+ /* if a field is null, continue but
+ * remember that we now return a different result */
+ len = PQgetlength (result,
+ row,
+ fnum);
+ res = PQgetvalue (result,
+ row,
+ fnum);
+ if (len < sizeof (be))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ memcpy (&be,
+ res,
+ sizeof (be));
+ if (0x010000 != ntohl (be[1])) /* magic marker: EWV */
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ res += sizeof (be);
+ len -= sizeof (be);
+ alg_values->cipher = ntohl (be[0]);
+ switch (alg_values->cipher)
+ {
+ case TALER_DENOMINATION_RSA:
+ if (0 != len)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+ case TALER_DENOMINATION_CS:
+ if (sizeof (struct TALER_ExchangeWithdrawCsValues) != len)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ memcpy (&alg_values->details.cs_values,
+ res,
+ len);
+ return GNUNET_OK;
+ default:
+ GNUNET_break (0);
+ }
+ return GNUNET_SYSERR;
+}
+
+
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_exchange_withdraw_values (
+ const char *name,
+ struct TALER_ExchangeWithdrawValues *ewv)
+{
+ struct GNUNET_PQ_ResultSpec res = {
+ .conv = &extract_exchange_withdraw_values,
+ .dst = (void *) ewv,
+ .fname = name
+ };
+
+ return res;
+}
+
+
/* end of pq_result_helper.c */