summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-02-06 17:39:18 +0100
committerChristian Grothoff <christian@grothoff.org>2016-02-06 17:39:18 +0100
commit2b5a7c8748405fd8f28c840c3142e5ff35f2fa36 (patch)
tree24d23d53d4adf915815a557c97831a7e3caeb602
parenta396f4e7fa39f17aec35360eb12098629649c831 (diff)
downloadexchange-2b5a7c8748405fd8f28c840c3142e5ff35f2fa36.tar.gz
exchange-2b5a7c8748405fd8f28c840c3142e5ff35f2fa36.tar.bz2
exchange-2b5a7c8748405fd8f28c840c3142e5ff35f2fa36.zip
move to new libgnunetpq library, simplifying libtalerpq
-rw-r--r--src/include/taler_pq_lib.h532
-rw-r--r--src/mintdb/Makefile.am1
-rw-r--r--src/mintdb/plugin_mintdb_postgres.c740
-rw-r--r--src/pq/Makefile.am8
-rw-r--r--src/pq/db_pq.c883
-rw-r--r--src/pq/pq_helper.c370
-rw-r--r--src/pq/pq_query_helper.c208
-rw-r--r--src/pq/pq_result_helper.c358
-rw-r--r--src/pq/test_pq.c153
9 files changed, 974 insertions, 2279 deletions
diff --git a/src/include/taler_pq_lib.h b/src/include/taler_pq_lib.h
index c9a9ebdc5..49e067846 100644
--- a/src/include/taler_pq_lib.h
+++ b/src/include/taler_pq_lib.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014, 2015 GNUnet e.V.
+ Copyright (C) 2014, 2015, 2016 GNUnet e.V.
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
@@ -24,130 +24,10 @@
#define TALER_PQ_LIB_H_
#include <libpq-fe.h>
+#include <gnunet/gnunet_pq_lib.h>
#include "taler_util.h"
/**
- * Different formats of results that can be added to a query.
- */
-enum TALER_PQ_QueryFormat
-{
-
- /**
- * List terminator.
- */
- TALER_PQ_QF_END,
-
- /**
- * We have a fixed-size result (binary blob, no endianess conversion).
- */
- TALER_PQ_QF_FIXED_BLOB,
-
- /**
- * We have a variable-size result (binary blob, no endianess conversion).
- */
- TALER_PQ_QF_VARSIZE_BLOB,
-
- /**
- * We have a currency amount (with endianess conversion).
- * Data points to a `struct TALER_AmountNBO`, size is only used to check.
- */
- TALER_PQ_QF_AMOUNT_NBO,
-
- /**
- * We have a currency amount (with endianess conversion).
- * Data points to a `struct TALER_Amount`, size is only used to check.
- */
- TALER_PQ_QF_AMOUNT,
-
- /**
- * We have an RSA public key.
- * Data points to a `struct GNUNET_CRYPTO_rsa_PublicKey`, size is not used.
- */
- TALER_PQ_QF_RSA_PUBLIC_KEY,
-
- /**
- * We have an RSA signature.
- * Data points to a `struct GNUNET_CRYPTO_rsa_Signature`, size is not used.
- */
- TALER_PQ_QF_RSA_SIGNATURE,
-
- /**
- * We have an absolute time.
- * Data points to a `struct GNUNET_TIME_Absolute`, size is only used to check.
- */
- TALER_PQ_QF_TIME_ABSOLUTE,
-
- /**
- * We expect an uint16_t (in host byte order).
- */
- TALER_PQ_QF_UINT16,
-
- /**
- * We expect an uint32_t (in host byte order).
- */
- TALER_PQ_QF_UINT32,
-
- /**
- * We expect an uint64_t (in host byte order).
- */
- TALER_PQ_QF_UINT64,
-
- /**
- * We expect a JSON object (json_t).
- */
- TALER_PQ_QF_JSON
-};
-
-
-/**
- * @brief Description of a DB query parameter.
- */
-struct TALER_PQ_QueryParam
-{
-
- /**
- * Format of the rest of the entry, determines the data
- * type that is being added to the query.
- */
- enum TALER_PQ_QueryFormat format;
-
- /**
- * Data or NULL.
- */
- const void *data;
-
- /**
- * Size of @e data
- */
- size_t size;
-
-};
-
-
-/**
- * End of query parameter specification.
- */
-#define TALER_PQ_query_param_end { TALER_PQ_QF_END, NULL, 0 }
-
-/**
- * Generate fixed-size query parameter with size given explicitly.
- *
- * @param x pointer to the query parameter to pass
- * @param s number of bytes of @a x to use for the query
- */
-#define TALER_PQ_query_param_fixed_size(x,s) { TALER_PQ_QF_FIXED_BLOB, (x), (s) }
-
-
-/**
- * Generate fixed-size query parameter with size determined
- * by variable type.
- *
- * @param x pointer to the query parameter to pass.
- */
-#define TALER_PQ_query_param_auto_from_type(x) { TALER_PQ_QF_VARSIZE_BLOB, x, sizeof (*(x)) }
-
-
-/**
* Generate query parameter for a currency, consisting of the three
* components "value", "fraction" and "currency" in this order. The
* types must be a 64-bit integer, 32-bit integer and a
@@ -155,7 +35,7 @@ struct TALER_PQ_QueryParam
*
* @param x pointer to the query parameter to pass
*/
-struct TALER_PQ_QueryParam
+struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_amount_nbo (const struct TALER_AmountNBO *x);
@@ -167,78 +47,11 @@ TALER_PQ_query_param_amount_nbo (const struct TALER_AmountNBO *x);
*
* @param x pointer to the query parameter to pass
*/
-struct TALER_PQ_QueryParam
+struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_amount (const struct TALER_Amount *x);
/**
- * Generate query parameter for an RSA public key. The
- * database must contain a BLOB type in the respective position.
- *
- * @param x the query parameter to pass.
- */
-struct TALER_PQ_QueryParam
-TALER_PQ_query_param_rsa_public_key (const struct GNUNET_CRYPTO_rsa_PublicKey *x);
-
-
-/**
- * Generate query parameter for an RSA signature. The
- * database must contain a BLOB type in the respective position.
- *
- * @param x the query parameter to pass
- */
-struct TALER_PQ_QueryParam
-TALER_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_rsa_Signature *x);
-
-
-/**
- * Generate query parameter for an absolute time value.
- * The database must store a 64-bit integer.
- *
- * @param x pointer to the query parameter to pass
- */
-struct TALER_PQ_QueryParam
-TALER_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x);
-
-
-/**
- * Generate query parameter for an absolute time value.
- * The database must store a 64-bit integer.
- *
- * @param x pointer to the query parameter to pass
- */
-struct TALER_PQ_QueryParam
-TALER_PQ_query_param_absolute_time_nbo (const struct GNUNET_TIME_AbsoluteNBO *x);
-
-
-/**
- * Generate query parameter for an uint16_t in host byte order.
- *
- * @param x pointer to the query parameter to pass
- */
-struct TALER_PQ_QueryParam
-TALER_PQ_query_param_uint16 (const uint16_t *x);
-
-
-/**
- * Generate query parameter for an uint32_t in host byte order.
- *
- * @param x pointer to the query parameter to pass
- */
-struct TALER_PQ_QueryParam
-TALER_PQ_query_param_uint32 (const uint32_t *x);
-
-
-/**
- * Generate query parameter for an uint16_t in host byte order.
- *
- * @param x pointer to the query parameter to pass
- */
-struct TALER_PQ_QueryParam
-TALER_PQ_query_param_uint64 (const uint64_t *x);
-
-
-/**
* Generate query parameter for a JSON object (stored as a string
* in the DB). Note that @a x must really be a JSON object or array,
* passing just a value (string, integer) is not supported and will
@@ -246,170 +59,18 @@ TALER_PQ_query_param_uint64 (const uint64_t *x);
*
* @param x pointer to the json object to pass
*/
-struct TALER_PQ_QueryParam
+struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_json (const json_t *x);
/**
- * Different formats of results that can be extracted.
- */
-enum TALER_PQ_ResultFormat
-{
-
- /**
- * List terminator.
- */
- TALER_PQ_RF_END,
-
- /**
- * We expect a fixed-size result (binary blob, no endianess conversion).
- */
- TALER_PQ_RF_FIXED_BLOB,
-
- /**
- * We expect a variable-size result (binary blob, no endianess conversion).
- */
- TALER_PQ_RF_VARSIZE_BLOB,
-
- /**
- * We expect a currency amount.
- * Data points to a `struct TALER_AmountNBO`, size only used for checking.
- */
- TALER_PQ_RF_AMOUNT_NBO,
-
- /**
- * We expect a currency amount.
- * Data points to a `struct TALER_Amount`, size only used for checking.
- */
- TALER_PQ_RF_AMOUNT,
-
- /**
- * We expect an RSA public key.
- * Data points to a `struct GNUNET_CRYPTO_rsa_PublicKey **`, size is not used.
- */
- TALER_PQ_RF_RSA_PUBLIC_KEY,
-
- /**
- * We expect an RSA signature.
- * Data points to a `struct GNUNET_CRYPTO_rsa_Signature **`, size is not used.
- */
- TALER_PQ_RF_RSA_SIGNATURE,
-
- /**
- * We expect an absolute time.
- * Data points to a `struct GNUNET_TIME_Absolute`, size is only used for checking.
- */
- TALER_PQ_RF_TIME_ABSOLUTE,
-
- /**
- * We expect an uint16_t (in host byte order).
- */
- TALER_PQ_RF_UINT16,
-
- /**
- * We expect an uint32_t (in host byte order).
- */
- TALER_PQ_RF_UINT32,
-
- /**
- * We expect an uint64_t (in host byte order).
- */
- TALER_PQ_RF_UINT64,
-
- /**
- * We expect a JSON object (json_t).
- */
- TALER_PQ_RF_JSON
-
-};
-
-
-/**
- * @brief Description of a DB result cell.
- */
-struct TALER_PQ_ResultSpec
-{
-
- /**
- * What is the format of the result?
- */
- enum TALER_PQ_ResultFormat format;
-
- /**
- * Destination for the data.
- */
- void *dst;
-
- /**
- * Allowed size for the data, 0 for variable-size
- * (in this case, the type of @e dst is a `void **`
- * and we need to allocate a buffer of the right size).
- */
- size_t dst_size;
-
- /**
- * Field name of the desired result.
- */
- const char *fname;
-
- /**
- * Where to store actual size of the result.
- */
- size_t *result_size;
-
-};
-
-
-/**
- * End of result parameter specification.
- *
- * @return array last entry for the result specification to use
- */
-#define TALER_PQ_result_spec_end { TALER_PQ_RF_END, NULL, 0, NULL, NULL }
-
-/**
- * We expect a fixed-size result, with size given explicitly
- *
- * @param name name of the field in the table
- * @param dst point to where to store the result
- * @param s number of bytes we should use in @a dst
- * @return array entry for the result specification to use
- */
-#define TALER_PQ_result_spec_fixed_size(name, dst, s) { TALER_PQ_RF_FIXED_BLOB, (void *) (dst), (s), (name), NULL }
-
-
-/**
- * We expect a fixed-size result, with size determined by the type of `* dst`
- *
- * @param name name of the field in the table
- * @param dst point to where to store the result, type fits expected result size
- * @return array entry for the result specification to use
- */
-#define TALER_PQ_result_spec_auto_from_type(name, dst) { TALER_PQ_RF_FIXED_BLOB, (void *) (dst), sizeof (*(dst)), name, NULL }
-
-
-/**
- * Variable-size result expected.
- *
- * @param name name of the field in the table
- * @param[out] dst where to store the result, allocated
- * @param[out] sptr where to store the size of @a dst
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_variable_size (const char *name,
- void **dst,
- size_t *sptr);
-
-
-/**
* Currency amount expected.
*
* @param name name of the field in the table
* @param[out] amount where to store the result
* @return array entry for the result specification to use
*/
-struct TALER_PQ_ResultSpec
+struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_amount_nbo (const char *name,
struct TALER_AmountNBO *amount);
@@ -421,200 +82,23 @@ TALER_PQ_result_spec_amount_nbo (const char *name,
* @param[out] amount where to store the result
* @return array entry for the result specification to use
*/
-struct TALER_PQ_ResultSpec
+struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_amount (const char *name,
struct TALER_Amount *amount);
/**
- * RSA public key expected.
- *
- * @param name name of the field in the table
- * @param[out] rsa where to store the result
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_rsa_public_key (const char *name,
- struct GNUNET_CRYPTO_rsa_PublicKey **rsa);
-
-
-/**
- * RSA signature expected.
- *
- * @param name name of the field in the table
- * @param[out] sig where to store the result;
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_rsa_signature (const char *name,
- struct GNUNET_CRYPTO_rsa_Signature **sig);
-
-
-/**
- * Absolute time expected.
- *
- * @param name name of the field in the table
- * @param[out] at where to store the result
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_absolute_time (const char *name,
- struct GNUNET_TIME_Absolute *at);
-
-
-/**
- * Absolute time expected.
- *
- * @param name name of the field in the table
- * @param[out] at where to store the result
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_absolute_time_nbo (const char *name,
- struct GNUNET_TIME_AbsoluteNBO *at);
-
-
-/**
- * uint16_t expected.
- *
- * @param name name of the field in the table
- * @param[out] u16 where to store the result
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_uint16 (const char *name,
- uint16_t *u16);
-
-
-/**
- * uint32_t expected.
- *
- * @param name name of the field in the table
- * @param[out] u32 where to store the result
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_uint32 (const char *name,
- uint32_t *u32);
-
-
-/**
- * uint64_t expected.
- *
- * @param name name of the field in the table
- * @param[out] u64 where to store the result
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_uint64 (const char *name,
- uint64_t *u64);
-
-
-/**
* json_t expected.
*
* @param name name of the field in the table
* @param[out] jp where to store the result
* @return array entry for the result specification to use
*/
-struct TALER_PQ_ResultSpec
+struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_json (const char *name,
json_t **jp);
-/**
- * Execute a prepared statement.
- *
- * @param db_conn database connection
- * @param name name of the prepared statement
- * @param params parameters to the statement
- * @return postgres result
- */
-PGresult *
-TALER_PQ_exec_prepared (PGconn *db_conn,
- const char *name,
- const struct TALER_PQ_QueryParam *params);
-
-
-/**
- * Extract results from a query result according to the given specification.
- * If colums are NULL, the destination is not modified, and #GNUNET_NO
- * is returned.
- *
- * @param result result to process
- * @param[in,out] rs result specification to extract for
- * @param row row from the result to extract
- * @return
- * #GNUNET_YES if all results could be extracted
- * #GNUNET_NO if at least one result was NULL
- * #GNUNET_SYSERR if a result was invalid (non-existing field)
- */
-int
-TALER_PQ_extract_result (PGresult *result,
- struct TALER_PQ_ResultSpec *rs,
- int row);
-
-
-/**
- * Free all memory that was allocated in @a rs during
- * #TALER_PQ_extract_result().
- *
- * @param rs reult specification to clean up
- */
-void
-TALER_PQ_cleanup_result (struct TALER_PQ_ResultSpec *rs);
-
-
-/**
- * Extract a currency amount from a query result according to the
- * given specification.
- *
- * @param result the result to extract the amount from
- * @param row which row of the result to extract the amount from (needed as results can have multiple rows)
- * @param val_name name of the column with the amount's "value", must include the substring "_val".
- * @param frac_name name of the column with the amount's "fractional" value, must include the substring "_frac".
- * @param curr_name name of the column with the amount's currency name, must include the substring "_curr".
- * @param[out] r_amount_nbo where to store the amount, in network byte order
- * @return
- * #GNUNET_YES if all results could be extracted
- * #GNUNET_NO if at least one result was NULL
- * #GNUNET_SYSERR if a result was invalid (non-existing field)
- */
-int
-TALER_PQ_extract_amount_nbo (PGresult *result,
- int row,
- const char *val_name,
- const char *frac_name,
- const char *curr_name,
- struct TALER_AmountNBO *r_amount_nbo);
-
-
-/**
- * Extract a currency amount from a query result according to the
- * given specification.
- *
- * @param result the result to extract the amount from
- * @param row which row of the result to extract the amount from (needed as results can have multiple rows)
- * @param val_name name of the column with the amount's "value", must include the substring "_val".
- * @param frac_name name of the column with the amount's "fractional" value, must include the substring "_frac".
- * @param curr_name name of the column with the amount's currency name, must include the substring "_curr".
- * @param[out] r_amount where to store the amount, in host byte order
- * @return
- * #GNUNET_YES if all results could be extracted
- * #GNUNET_NO if at least one result was NULL
- * #GNUNET_SYSERR if a result was invalid (non-existing field)
- */
-int
-TALER_PQ_extract_amount (PGresult *result,
- int row,
- const char *val_name,
- const char *frac_name,
- const char *curr_name,
- struct TALER_Amount *r_amount);
-
-
-
-
#endif /* TALER_PQ_LIB_H_ */
/* end of include/taler_pq_lib.h */
diff --git a/src/mintdb/Makefile.am b/src/mintdb/Makefile.am
index 54f865429..e3d37b2e5 100644
--- a/src/mintdb/Makefile.am
+++ b/src/mintdb/Makefile.am
@@ -26,6 +26,7 @@ libtaler_plugin_mintdb_postgres_la_LDFLAGS = \
$(top_builddir)/src/pq/libtalerpq.la \
$(top_builddir)/src/util/libtalerutil.la \
-lpq \
+ -lgnunetpq \
-lgnunetutil $(XLIB)
lib_LTLIBRARIES = \
diff --git a/src/mintdb/plugin_mintdb_postgres.c b/src/mintdb/plugin_mintdb_postgres.c
index 2ab3e81ac..5015f4770 100644
--- a/src/mintdb/plugin_mintdb_postgres.c
+++ b/src/mintdb/plugin_mintdb_postgres.c
@@ -1365,19 +1365,19 @@ postgres_insert_denomination_info (void *cls,
PGresult *result;
int ret;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_rsa_public_key (denom_pub->rsa_public_key),
- TALER_PQ_query_param_auto_from_type (&issue->properties.master),
- TALER_PQ_query_param_auto_from_type (&issue->signature),
- TALER_PQ_query_param_absolute_time_nbo (&issue->properties.start),
- TALER_PQ_query_param_absolute_time_nbo (&issue->properties.expire_withdraw),
- TALER_PQ_query_param_absolute_time_nbo (&issue->properties.expire_spend),
- TALER_PQ_query_param_absolute_time_nbo (&issue->properties.expire_legal),
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_rsa_public_key (denom_pub->rsa_public_key),
+ GNUNET_PQ_query_param_auto_from_type (&issue->properties.master),
+ GNUNET_PQ_query_param_auto_from_type (&issue->signature),
+ GNUNET_PQ_query_param_absolute_time_nbo (&issue->properties.start),
+ GNUNET_PQ_query_param_absolute_time_nbo (&issue->properties.expire_withdraw),
+ GNUNET_PQ_query_param_absolute_time_nbo (&issue->properties.expire_spend),
+ GNUNET_PQ_query_param_absolute_time_nbo (&issue->properties.expire_legal),
TALER_PQ_query_param_amount_nbo (&issue->properties.value),
TALER_PQ_query_param_amount_nbo (&issue->properties.fee_withdraw),
TALER_PQ_query_param_amount_nbo (&issue->properties.fee_deposit),
TALER_PQ_query_param_amount_nbo (&issue->properties.fee_refresh),
- TALER_PQ_query_param_end
+ GNUNET_PQ_query_param_end
};
/* check fees match coin currency */
GNUNET_assert (GNUNET_YES ==
@@ -1390,7 +1390,7 @@ postgres_insert_denomination_info (void *cls,
TALER_amount_cmp_currency_nbo (&issue->properties.value,
&issue->properties.fee_refresh));
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"denomination_insert",
params);
if (PGRES_COMMAND_OK != PQresultStatus (result))
@@ -1423,12 +1423,12 @@ postgres_get_denomination_info (void *cls,
struct TALER_MINTDB_DenominationKeyInformationP *issue)
{
PGresult *result;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_rsa_public_key (denom_pub->rsa_public_key),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_rsa_public_key (denom_pub->rsa_public_key),
+ GNUNET_PQ_query_param_end
};
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"denomination_get",
params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
@@ -1454,18 +1454,18 @@ postgres_get_denomination_info (void *cls,
return GNUNET_OK;
}
{
- struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_auto_from_type ("master_pub",
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("master_pub",
&issue->properties.master),
- TALER_PQ_result_spec_auto_from_type ("master_sig",
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
&issue->signature),
- TALER_PQ_result_spec_absolute_time_nbo ("valid_from",
+ GNUNET_PQ_result_spec_absolute_time_nbo ("valid_from",
&issue->properties.start),
- TALER_PQ_result_spec_absolute_time_nbo ("expire_withdraw",
+ GNUNET_PQ_result_spec_absolute_time_nbo ("expire_withdraw",
&issue->properties.expire_withdraw),
- TALER_PQ_result_spec_absolute_time_nbo ("expire_spend",
+ GNUNET_PQ_result_spec_absolute_time_nbo ("expire_spend",
&issue->properties.expire_spend),
- TALER_PQ_result_spec_absolute_time_nbo ("expire_legal",
+ GNUNET_PQ_result_spec_absolute_time_nbo ("expire_legal",
&issue->properties.expire_legal),
TALER_PQ_result_spec_amount_nbo ("coin",
&issue->properties.value),
@@ -1475,11 +1475,11 @@ postgres_get_denomination_info (void *cls,
&issue->properties.fee_deposit),
TALER_PQ_result_spec_amount_nbo ("fee_refresh",
&issue->properties.fee_refresh),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
EXITIF (GNUNET_OK !=
- TALER_PQ_extract_result (result,
+ GNUNET_PQ_extract_result (result,
rs,
0));
}
@@ -1508,12 +1508,12 @@ postgres_reserve_get (void *cls,
struct TALER_MINTDB_Reserve *reserve)
{
PGresult *result;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type(&reserve->pub),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type(&reserve->pub),
+ GNUNET_PQ_query_param_end
};
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"reserve_get",
params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
@@ -1528,14 +1528,14 @@ postgres_reserve_get (void *cls,
return GNUNET_NO;
}
{
- struct TALER_PQ_ResultSpec rs[] = {
+ struct GNUNET_PQ_ResultSpec rs[] = {
TALER_PQ_result_spec_amount("current_balance", &reserve->balance),
- TALER_PQ_result_spec_absolute_time("expiration_date", &reserve->expiry),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_absolute_time("expiration_date", &reserve->expiry),
+ GNUNET_PQ_result_spec_end
};
EXITIF (GNUNET_OK !=
- TALER_PQ_extract_result (result,
+ GNUNET_PQ_extract_result (result,
rs,
0));
}
@@ -1567,13 +1567,13 @@ reserves_update (void *cls,
if (NULL == reserve)
return GNUNET_SYSERR;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_absolute_time (&reserve->expiry),
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_absolute_time (&reserve->expiry),
TALER_PQ_query_param_amount (&reserve->balance),
- TALER_PQ_query_param_auto_from_type (&reserve->pub),
- TALER_PQ_query_param_end
+ GNUNET_PQ_query_param_auto_from_type (&reserve->pub),
+ GNUNET_PQ_query_param_end
};
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"reserve_update",
params);
if (PGRES_COMMAND_OK != PQresultStatus(result))
@@ -1643,16 +1643,16 @@ postgres_reserves_in_insert (void *cls,
for a new reserve it can't be a duplicate 'add' operation,
and as the 'add' operation may need the reserve entry
as a foreign key. */
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (reserve_pub),
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
TALER_PQ_query_param_amount (balance),
- TALER_PQ_query_param_absolute_time (&expiry),
- TALER_PQ_query_param_end
+ GNUNET_PQ_query_param_absolute_time (&expiry),
+ GNUNET_PQ_query_param_end
};
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Reserve does not exist; creating a new one\n");
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"reserve_create",
params);
if (PGRES_COMMAND_OK != PQresultStatus(result))
@@ -1669,15 +1669,15 @@ postgres_reserves_in_insert (void *cls,
anything) and return #GNUNET_NO to indicate that this failure
is kind-of harmless (already executed). */
{
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (&reserve.pub),
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&reserve.pub),
TALER_PQ_query_param_amount (balance),
TALER_PQ_query_param_json (details),
- TALER_PQ_query_param_absolute_time (&execution_time),
- TALER_PQ_query_param_end
+ GNUNET_PQ_query_param_absolute_time (&execution_time),
+ GNUNET_PQ_query_param_end
};
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"reserves_in_add_transaction",
params);
}
@@ -1764,14 +1764,14 @@ postgres_get_withdraw_info (void *cls,
struct TALER_MINTDB_CollectableBlindcoin *collectable)
{
PGresult *result;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (h_blind),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_blind),
+ GNUNET_PQ_query_param_end
};
int ret;
ret = GNUNET_SYSERR;
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"get_withdraw_info",
params);
@@ -1786,24 +1786,24 @@ postgres_get_withdraw_info (void *cls,
goto cleanup;
}
{
- struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_rsa_public_key ("denom_pub",
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_rsa_public_key ("denom_pub",
&collectable->denom_pub.rsa_public_key),
- TALER_PQ_result_spec_rsa_signature ("denom_sig",
+ GNUNET_PQ_result_spec_rsa_signature ("denom_sig",
&collectable->sig.rsa_signature),
- TALER_PQ_result_spec_auto_from_type ("reserve_sig",
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
&collectable->reserve_sig),
- TALER_PQ_result_spec_auto_from_type ("reserve_pub",
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
&collectable->reserve_pub),
TALER_PQ_result_spec_amount ("amount_with_fee",
&collectable->amount_with_fee),
TALER_PQ_result_spec_amount ("withdraw_fee",
&collectable->withdraw_fee),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
if (GNUNET_OK !=
- TALER_PQ_extract_result (result, rs, 0))
+ GNUNET_PQ_extract_result (result, rs, 0))
{
GNUNET_break (0);
goto cleanup;
@@ -1840,20 +1840,20 @@ postgres_insert_withdraw_info (void *cls,
int ret = GNUNET_SYSERR;
struct GNUNET_TIME_Absolute now;
struct GNUNET_TIME_Absolute expiry;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (&collectable->h_coin_envelope),
- TALER_PQ_query_param_rsa_public_key (collectable->denom_pub.rsa_public_key),
- TALER_PQ_query_param_rsa_signature (collectable->sig.rsa_signature),
- TALER_PQ_query_param_auto_from_type (&collectable->reserve_pub),
- TALER_PQ_query_param_auto_from_type (&collectable->reserve_sig),
- TALER_PQ_query_param_absolute_time (&now),
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&collectable->h_coin_envelope),
+ GNUNET_PQ_query_param_rsa_public_key (collectable->denom_pub.rsa_public_key),
+ GNUNET_PQ_query_param_rsa_signature (collectable->sig.rsa_signature),
+ GNUNET_PQ_query_param_auto_from_type (&collectable->reserve_pub),
+ GNUNET_PQ_query_param_auto_from_type (&collectable->reserve_sig),
+ GNUNET_PQ_query_param_absolute_time (&now),
TALER_PQ_query_param_amount (&collectable->amount_with_fee),
TALER_PQ_query_param_amount (&collectable->withdraw_fee),
- TALER_PQ_query_param_end
+ GNUNET_PQ_query_param_end
};
now = GNUNET_TIME_absolute_get ();
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"insert_withdraw_info",
params);
if (PGRES_COMMAND_OK != PQresultStatus (result))
@@ -1922,12 +1922,12 @@ postgres_get_reserve_history (void *cls,
ret = GNUNET_SYSERR;
{
struct TALER_MINTDB_BankTransfer *bt;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (reserve_pub),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_end
};
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"reserves_in_get_transactions",
params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
@@ -1945,17 +1945,17 @@ postgres_get_reserve_history (void *cls,
{
bt = GNUNET_new (struct TALER_MINTDB_BankTransfer);
{
- struct TALER_PQ_ResultSpec rs[] = {
+ struct GNUNET_PQ_ResultSpec rs[] = {
TALER_PQ_result_spec_amount ("balance",
&bt->amount),
- TALER_PQ_result_spec_absolute_time ("execution_date",
+ GNUNET_PQ_result_spec_absolute_time ("execution_date",
&bt->execution_date),
TALER_PQ_result_spec_json ("details",
&bt->wire),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
if (GNUNET_YES !=
- TALER_PQ_extract_result (result, rs, --rows))
+ GNUNET_PQ_extract_result (result, rs, --rows))
{
GNUNET_break (0);
GNUNET_free (bt);
@@ -1980,15 +1980,15 @@ postgres_get_reserve_history (void *cls,
PQclear (result);
}
{
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (reserve_pub),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_end
};
GNUNET_assert (NULL != rh);
GNUNET_assert (NULL != rh_tail);
GNUNET_assert (NULL == rh_tail->next);
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"get_reserves_out",
params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
@@ -2004,23 +2004,23 @@ postgres_get_reserve_history (void *cls,
cbc = GNUNET_new (struct TALER_MINTDB_CollectableBlindcoin);
{
- struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_auto_from_type ("h_blind_ev",
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("h_blind_ev",
&cbc->h_coin_envelope),
- TALER_PQ_result_spec_rsa_public_key ("denom_pub",
+ GNUNET_PQ_result_spec_rsa_public_key ("denom_pub",
&cbc->denom_pub.rsa_public_key),
- TALER_PQ_result_spec_rsa_signature ("denom_sig",
+ GNUNET_PQ_result_spec_rsa_signature ("denom_sig",
&cbc->sig.rsa_signature),
- TALER_PQ_result_spec_auto_from_type ("reserve_sig",
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
&cbc->reserve_sig),
TALER_PQ_result_spec_amount ("amount_with_fee",
&cbc->amount_with_fee),
TALER_PQ_result_spec_amount ("withdraw_fee",
&cbc->withdraw_fee),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
if (GNUNET_YES !=
- TALER_PQ_extract_result (result, rs, --rows))
+ GNUNET_PQ_extract_result (result, rs, --rows))
{
GNUNET_break (0);
GNUNET_free (cbc);
@@ -2063,15 +2063,15 @@ postgres_have_deposit (void *cls,
struct TALER_MINTDB_Session *session,
const struct TALER_MINTDB_Deposit *deposit)
{
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (&deposit->coin.coin_pub),
- TALER_PQ_query_param_uint64 (&deposit->transaction_id),
- TALER_PQ_query_param_auto_from_type (&deposit->merchant_pub),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&deposit->coin.coin_pub),
+ GNUNET_PQ_query_param_uint64 (&deposit->transaction_id),
+ GNUNET_PQ_query_param_auto_from_type (&deposit->merchant_pub),
+ GNUNET_PQ_query_param_end
};
PGresult *result;
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"get_deposit",
params);
if (PGRES_TUPLES_OK !=
@@ -2091,23 +2091,23 @@ postgres_have_deposit (void *cls,
also matches, and if not report inconsistencies. */
{
struct TALER_MINTDB_Deposit deposit2;
- struct TALER_PQ_ResultSpec rs[] = {
+ struct GNUNET_PQ_ResultSpec rs[] = {
TALER_PQ_result_spec_amount ("amount_with_fee",
&deposit2.amount_with_fee),
- TALER_PQ_result_spec_absolute_time ("timestamp",
+ GNUNET_PQ_result_spec_absolute_time ("timestamp",
&deposit2.timestamp),
- TALER_PQ_result_spec_absolute_time ("refund_deadline",
+ GNUNET_PQ_result_spec_absolute_time ("refund_deadline",
&deposit2.refund_deadline),
- TALER_PQ_result_spec_absolute_time ("wire_deadline",
+ GNUNET_PQ_result_spec_absolute_time ("wire_deadline",
&deposit2.wire_deadline),
- TALER_PQ_result_spec_auto_from_type ("h_contract",
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract",
&deposit2.h_contract),
- TALER_PQ_result_spec_auto_from_type ("h_wire",
+ GNUNET_PQ_result_spec_auto_from_type ("h_wire",
&deposit2.h_wire),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
if (GNUNET_OK !=
- TALER_PQ_extract_result (result, rs, 0))
+ GNUNET_PQ_extract_result (result, rs, 0))
{
GNUNET_break (0);
PQclear (result);
@@ -2155,13 +2155,13 @@ postgres_mark_deposit_tiny (void *cls,
unsigned long long rowid)
{
uint64_t serial_id = rowid;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_uint64 (&serial_id),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
};
PGresult *result;
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"mark_deposit_tiny",
params);
if (PGRES_COMMAND_OK !=
@@ -2192,13 +2192,13 @@ postgres_mark_deposit_done (void *cls,
unsigned long long rowid)
{
uint64_t serial_id = rowid;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_uint64 (&serial_id),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
};
PGresult *result;
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"mark_deposit_done",
params);
if (PGRES_COMMAND_OK !=
@@ -2231,14 +2231,14 @@ postgres_get_ready_deposit (void *cls,
TALER_MINTDB_DepositIterator deposit_cb,
void *deposit_cb_cls)
{
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
};
PGresult *result;
unsigned int n;
int ret;
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"deposits_get_ready",
params);
if (PGRES_TUPLES_OK !=
@@ -2264,29 +2264,29 @@ postgres_get_ready_deposit (void *cls,
uint64_t transaction_id;
uint64_t serial_id;
json_t *wire;
- struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_uint64 ("serial_id",
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial_id",
&serial_id),
- TALER_PQ_result_spec_uint64 ("transaction_id",
+ GNUNET_PQ_result_spec_uint64 ("transaction_id",
&transaction_id),
TALER_PQ_result_spec_amount ("amount_with_fee",
&amount_with_fee),
TALER_PQ_result_spec_amount ("deposit_fee",
&deposit_fee),
- TALER_PQ_result_spec_absolute_time ("wire_deadline",
+ GNUNET_PQ_result_spec_absolute_time ("wire_deadline",
&wire_deadline),
- TALER_PQ_result_spec_auto_from_type ("h_contract",
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract",
&h_contract),
- TALER_PQ_result_spec_auto_from_type ("merchant_pub",
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
&merchant_pub),
- TALER_PQ_result_spec_auto_from_type ("coin_pub",
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
&coin_pub),
TALER_PQ_result_spec_json ("wire",
&wire),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
if (GNUNET_OK !=
- TALER_PQ_extract_result (result, rs, 0))
+ GNUNET_PQ_extract_result (result, rs, 0))
{
GNUNET_break (0);
PQclear (result);
@@ -2302,7 +2302,7 @@ postgres_get_ready_deposit (void *cls,
&h_contract,
wire_deadline,
wire);
- TALER_PQ_cleanup_result (rs);
+ GNUNET_PQ_cleanup_result (rs);
PQclear (result);
}
return (GNUNET_OK == ret) ? 1 : 0;
@@ -2332,17 +2332,17 @@ postgres_iterate_matching_deposits (void *cls,
void *deposit_cb_cls,
uint32_t limit)
{
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (merchant_pub),
- TALER_PQ_query_param_auto_from_type (h_wire),
- TALER_PQ_query_param_uint32 (&limit),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_wire),
+ GNUNET_PQ_query_param_uint32 (&limit),
+ GNUNET_PQ_query_param_end
};
PGresult *result;
unsigned int i;
unsigned int n;
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"deposits_iterate_matching",
params);
if (PGRES_TUPLES_OK !=
@@ -2370,27 +2370,27 @@ postgres_iterate_matching_deposits (void *cls,
uint64_t transaction_id;
uint64_t serial_id;
int ret;
- struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_uint64 ("serial_id",
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial_id",
&serial_id),
- TALER_PQ_result_spec_uint64 ("transaction_id",
+ GNUNET_PQ_result_spec_uint64 ("transaction_id",
&transaction_id),
TALER_PQ_result_spec_amount ("amount_with_fee",
&amount_with_fee),
TALER_PQ_result_spec_amount ("deposit_fee",
&deposit_fee),
- TALER_PQ_result_spec_absolute_time ("wire_deadline",
+ GNUNET_PQ_result_spec_absolute_time ("wire_deadline",
&wire_deadline),
- TALER_PQ_result_spec_auto_from_type ("h_contract",
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract",
&h_contract),
- TALER_PQ_result_spec_auto_from_type ("merchant_pub",
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
&merchant_pub),
- TALER_PQ_result_spec_auto_from_type ("coin_pub",
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
&coin_pub),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
if (GNUNET_OK !=
- TALER_PQ_extract_result (result, rs, i))
+ GNUNET_PQ_extract_result (result, rs, i))
{
GNUNET_break (0);
PQclear (result);
@@ -2406,7 +2406,7 @@ postgres_iterate_matching_deposits (void *cls,
&h_contract,
wire_deadline,
NULL);
- TALER_PQ_cleanup_result (rs);
+ GNUNET_PQ_cleanup_result (rs);
PQclear (result);
if (GNUNET_OK != ret)
break;
@@ -2432,24 +2432,24 @@ postgres_insert_deposit (void *cls,
int ret;
{
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (&deposit->coin.coin_pub),
- TALER_PQ_query_param_rsa_public_key (deposit->coin.denom_pub.rsa_public_key),
- TALER_PQ_query_param_rsa_signature (deposit->coin.denom_sig.rsa_signature),
- TALER_PQ_query_param_uint64 (&deposit->transaction_id),
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&deposit->coin.coin_pub),
+ GNUNET_PQ_query_param_rsa_public_key (deposit->coin.denom_pub.rsa_public_key),
+ GNUNET_PQ_query_param_rsa_signature (deposit->coin.denom_sig.rsa_signature),
+ GNUNET_PQ_query_param_uint64 (&deposit->transaction_id),
TALER_PQ_query_param_amount (&deposit->amount_with_fee),
TALER_PQ_query_param_amount (&deposit->deposit_fee),
- TALER_PQ_query_param_absolute_time (&deposit->timestamp),
- TALER_PQ_query_param_absolute_time (&deposit->refund_deadline),
- TALER_PQ_query_param_absolute_time (&deposit->wire_deadline),
- TALER_PQ_query_param_auto_from_type (&deposit->merchant_pub),
- TALER_PQ_query_param_auto_from_type (&deposit->h_contract),
- TALER_PQ_query_param_auto_from_type (&deposit->h_wire),
- TALER_PQ_query_param_auto_from_type (&deposit->csig),
+ GNUNET_PQ_query_param_absolute_time (&deposit->timestamp),
+ GNUNET_PQ_query_param_absolute_time (&deposit->refund_deadline),
+ GNUNET_PQ_query_param_absolute_time (&deposit->wire_deadline),
+ GNUNET_PQ_query_param_auto_from_type (&deposit->merchant_pub),
+ GNUNET_PQ_query_param_auto_from_type (&deposit->h_contract),
+ GNUNET_PQ_query_param_auto_from_type (&deposit->h_wire),
+ GNUNET_PQ_query_param_auto_from_type (&deposit->csig),
TALER_PQ_query_param_json (deposit->wire),
- TALER_PQ_query_param_end
+ GNUNET_PQ_query_param_end
};
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"insert_deposit",
params);
}
@@ -2486,12 +2486,12 @@ postgres_get_refresh_session (void *cls,
struct TALER_MINTDB_RefreshSession *refresh_session)
{
PGresult *result;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (session_hash),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (session_hash),
+ GNUNET_PQ_query_param_end
};
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"get_refresh_session",
params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
@@ -2517,17 +2517,17 @@ postgres_get_refresh_session (void *cls,
0,
sizeof (struct TALER_MINTDB_RefreshSession));
{
- struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_uint16 ("num_oldcoins",
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint16 ("num_oldcoins",
&refresh_session->num_oldcoins),
- TALER_PQ_result_spec_uint16 ("num_newcoins",
+ GNUNET_PQ_result_spec_uint16 ("num_newcoins",
&refresh_session->num_newcoins),
- TALER_PQ_result_spec_uint16 ("noreveal_index",
+ GNUNET_PQ_result_spec_uint16 ("noreveal_index",
&refresh_session->noreveal_index),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
if (GNUNET_OK !=
- TALER_PQ_extract_result (result, rs, 0))
+ GNUNET_PQ_extract_result (result, rs, 0))
{
GNUNET_break (0);
PQclear (result);
@@ -2556,15 +2556,15 @@ postgres_create_refresh_session (void *cls,
const struct TALER_MINTDB_RefreshSession *refresh_session)
{
PGresult *result;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (session_hash),
- TALER_PQ_query_param_uint16 (&refresh_session->num_oldcoins),
- TALER_PQ_query_param_uint16 (&refresh_session->num_newcoins),
- TALER_PQ_query_param_uint16 (&refresh_session->noreveal_index),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (session_hash),
+ GNUNET_PQ_query_param_uint16 (&refresh_session->num_oldcoins),
+ GNUNET_PQ_query_param_uint16 (&refresh_session->num_newcoins),
+ GNUNET_PQ_query_param_uint16 (&refresh_session->noreveal_index),
+ GNUNET_PQ_query_param_end
};
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"insert_refresh_session",
params);
if (PGRES_COMMAND_OK != PQresultStatus (result))
@@ -2593,13 +2593,13 @@ insert_known_coin (void *cls,
const struct TALER_CoinPublicInfo *coin_info)
{
PGresult *result;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (&coin_info->coin_pub),
- TALER_PQ_query_param_rsa_public_key (coin_info->denom_pub.rsa_public_key),
- TALER_PQ_query_param_rsa_signature (coin_info->denom_sig.rsa_signature),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&coin_info->coin_pub),
+ GNUNET_PQ_query_param_rsa_public_key (coin_info->denom_pub.rsa_public_key),
+ GNUNET_PQ_query_param_rsa_signature (coin_info->denom_sig.rsa_signature),
+ GNUNET_PQ_query_param_end
};
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"insert_known_coin",
params);
if (PGRES_COMMAND_OK != PQresultStatus (result))
@@ -2631,13 +2631,13 @@ get_known_coin (void *cls,
struct TALER_CoinPublicInfo *coin_info)
{
PGresult *result;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (coin_pub),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_end
};
int nrows;
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"get_known_coin",
params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
@@ -2656,16 +2656,16 @@ get_known_coin (void *cls,
if (NULL == coin_info)
return GNUNET_YES;
{
- struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_rsa_public_key ("denom_pub",
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_rsa_public_key ("denom_pub",
&coin_info->denom_pub.rsa_public_key),
- TALER_PQ_result_spec_rsa_signature ("denom_sig",
+ GNUNET_PQ_result_spec_rsa_signature ("denom_sig",
&coin_info->denom_sig.rsa_signature),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
if (GNUNET_OK !=
- TALER_PQ_extract_result (result, rs, 0))
+ GNUNET_PQ_extract_result (result, rs, 0))
{
PQclear (result);
GNUNET_break (0);
@@ -2696,14 +2696,14 @@ postgres_insert_refresh_melt (void *cls,
const struct TALER_MINTDB_RefreshMelt *melt)
{
PGresult *result;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (&melt->coin.coin_pub),
- TALER_PQ_query_param_auto_from_type (&melt->session_hash),
- TALER_PQ_query_param_uint16 (&oldcoin_index),
- TALER_PQ_query_param_auto_from_type (&melt->coin_sig),
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&melt->coin.coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (&melt->session_hash),
+ GNUNET_PQ_query_param_uint16 (&oldcoin_index),
+ GNUNET_PQ_query_param_auto_from_type (&melt->coin_sig),
TALER_PQ_query_param_amount (&melt->amount_with_fee),
TALER_PQ_query_param_amount (&melt->melt_fee),
- TALER_PQ_query_param_end
+ GNUNET_PQ_query_param_end
};
int ret;
@@ -2729,7 +2729,7 @@ postgres_insert_refresh_melt (void *cls,
}
}
/* insert the melt */
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"insert_refresh_melt",
params);
if (PGRES_COMMAND_OK != PQresultStatus (result))
@@ -2766,15 +2766,15 @@ postgres_get_refresh_melt (void *cls,
struct TALER_CoinSpendSignatureP coin_sig;
struct TALER_Amount amount_with_fee;
struct TALER_Amount melt_fee;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (session_hash),
- TALER_PQ_query_param_uint16 (&oldcoin_index),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (session_hash),
+ GNUNET_PQ_query_param_uint16 (&oldcoin_index),
+ GNUNET_PQ_query_param_end
};
int nrows;
/* check if the melt record exists and get it */
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"get_refresh_melt",
params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
@@ -2793,14 +2793,14 @@ postgres_get_refresh_melt (void *cls,
}
GNUNET_assert (1 == nrows); /* due to primary key constraint */
{
- struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_auto_from_type ("coin_pub", &coin.coin_pub),
- TALER_PQ_result_spec_auto_from_type ("coin_sig", &coin_sig),
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub", &coin.coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig", &coin_sig),
TALER_PQ_result_spec_amount ("amount_with_fee", &amount_with_fee),
TALER_PQ_result_spec_amount ("melt_fee", &melt_fee),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
- if (GNUNET_OK != TALER_PQ_extract_result (result, rs, 0))
+ if (GNUNET_OK != GNUNET_PQ_extract_result (result, rs, 0))
{
GNUNET_break (0);
PQclear (result);
@@ -2856,13 +2856,13 @@ postgres_insert_refresh_order (void *cls,
PGresult *result;
{
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_uint16 (&newcoin_off),
- TALER_PQ_query_param_auto_from_type (session_hash),
- TALER_PQ_query_param_rsa_public_key (denom_pubs[i].rsa_public_key),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint16 (&newcoin_off),
+ GNUNET_PQ_query_param_auto_from_type (session_hash),
+ GNUNET_PQ_query_param_rsa_public_key (denom_pubs[i].rsa_public_key),
+ GNUNET_PQ_query_param_end
};
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"insert_refresh_order",
params);
}
@@ -2931,13 +2931,13 @@ postgres_get_refresh_order (void *cls,
PGresult *result;
{
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (session_hash),
- TALER_PQ_query_param_uint16 (&newcoin_off),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (session_hash),
+ GNUNET_PQ_query_param_uint16 (&newcoin_off),
+ GNUNET_PQ_query_param_end
};
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"get_refresh_order",
params);
}
@@ -2957,13 +2957,13 @@ postgres_get_refresh_order (void *cls,
}
GNUNET_assert (1 == PQntuples (result));
{
- struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_rsa_public_key ("denom_pub",
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_rsa_public_key ("denom_pub",
&denom_pubs[i].rsa_public_key),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
if (GNUNET_OK !=
- TALER_PQ_extract_result (result, rs, 0))
+ GNUNET_PQ_extract_result (result, rs, 0))
{
PQclear (result);
GNUNET_break (0);
@@ -3015,17 +3015,17 @@ postgres_insert_refresh_commit_coins (void *cls,
}
coin_off = (uint16_t) i;
{
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (session_hash),
- TALER_PQ_query_param_uint16 (&cnc_index),
- TALER_PQ_query_param_uint16 (&coin_off),
- TALER_PQ_query_param_fixed_size (rle,
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (session_hash),
+ GNUNET_PQ_query_param_uint16 (&cnc_index),
+ GNUNET_PQ_query_param_uint16 (&coin_off),
+ GNUNET_PQ_query_param_fixed_size (rle,
rle_size),
- TALER_PQ_query_param_fixed_size (commit_coins[i].coin_ev,
+ GNUNET_PQ_query_param_fixed_size (commit_coins[i].coin_ev,
commit_coins[i].coin_ev_size),
- TALER_PQ_query_param_end
+ GNUNET_PQ_query_param_end
};
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"insert_refresh_commit_coin",
params);
}
@@ -3099,11 +3099,11 @@ postgres_get_refresh_commit_coins (void *cls,
for (i=0;i<(unsigned int) num_newcoins;i++)
{
uint16_t newcoin_off = (uint16_t) i;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (session_hash),
- TALER_PQ_query_param_uint16 (&cnc_index),
- TALER_PQ_query_param_uint16 (&newcoin_off),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (session_hash),
+ GNUNET_PQ_query_param_uint16 (&cnc_index),
+ GNUNET_PQ_query_param_uint16 (&newcoin_off),
+ GNUNET_PQ_query_param_end
};
void *c_buf;
size_t c_buf_size;
@@ -3112,7 +3112,7 @@ postgres_get_refresh_commit_coins (void *cls,
struct TALER_RefreshLinkEncrypted *rl;
PGresult *result;
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"get_refresh_commit_coin",
params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
@@ -3129,18 +3129,18 @@ postgres_get_refresh_commit_coins (void *cls,
return GNUNET_NO;
}
{
- struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_variable_size ("link_vector_enc",
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_variable_size ("link_vector_enc",
&rl_buf,
&rl_buf_size),
- TALER_PQ_result_spec_variable_size ("coin_ev",
+ GNUNET_PQ_result_spec_variable_size ("coin_ev",
&c_buf,
&c_buf_size),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
if (GNUNET_YES !=
- TALER_PQ_extract_result (result, rs, 0))
+ GNUNET_PQ_extract_result (result, rs, 0))
{
PQclear (result);
free_cc_result (commit_coins, i);
@@ -3190,16 +3190,16 @@ postgres_insert_refresh_commit_links (void *cls,
for (i=0;i<num_links;i++)
{
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (session_hash),
- TALER_PQ_query_param_auto_from_type (&links[i].transfer_pub),
- TALER_PQ_query_param_uint16 (&cnc_index),
- TALER_PQ_query_param_uint16 (&i),
- TALER_PQ_query_param_auto_from_type (&links[i].shared_secret_enc),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (session_hash),
+ GNUNET_PQ_query_param_auto_from_type (&links[i].transfer_pub),
+ GNUNET_PQ_query_param_uint16 (&cnc_index),
+ GNUNET_PQ_query_param_uint16 (&i),
+ GNUNET_PQ_query_param_auto_from_type (&links[i].shared_secret_enc),
+ GNUNET_PQ_query_param_end
};
- PGresult *result = TALER_PQ_exec_prepared (session->conn,
+ PGresult *result = GNUNET_PQ_exec_prepared (session->conn,
"insert_refresh_commit_link",
params);
if (PGRES_COMMAND_OK != PQresultStatus (result))
@@ -3246,15 +3246,15 @@ postgres_get_refresh_commit_links (void *cls,
for (i=0;i<num_links;i++)
{
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (session_hash),
- TALER_PQ_query_param_uint16 (&cnc_index),
- TALER_PQ_query_param_uint16 (&i),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (session_hash),
+ GNUNET_PQ_query_param_uint16 (&cnc_index),
+ GNUNET_PQ_query_param_uint16 (&i),
+ GNUNET_PQ_query_param_end
};
PGresult *result;
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"get_refresh_commit_link",
params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
@@ -3269,16 +3269,16 @@ postgres_get_refresh_commit_links (void *cls,
return GNUNET_NO;
}
{
- struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_auto_from_type ("transfer_pub",
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("transfer_pub",
&links[i].transfer_pub),
- TALER_PQ_result_spec_auto_from_type ("link_secret_enc",
+ GNUNET_PQ_result_spec_auto_from_type ("link_secret_enc",
&links[i].shared_secret_enc),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
if (GNUNET_YES !=
- TALER_PQ_extract_result (result, rs, 0))
+ GNUNET_PQ_extract_result (result, rs, 0))
{
PQclear (result);
return GNUNET_SYSERR;
@@ -3391,14 +3391,14 @@ postgres_insert_refresh_out (void *cls,
const struct TALER_DenominationSignature *ev_sig)
{
PGresult *result;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (session_hash),
- TALER_PQ_query_param_uint16 (&newcoin_index),
- TALER_PQ_query_param_rsa_signature (ev_sig->rsa_signature),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (session_hash),
+ GNUNET_PQ_query_param_uint16 (&newcoin_index),
+ GNUNET_PQ_query_param_rsa_signature (ev_sig->rsa_signature),
+ GNUNET_PQ_query_param_end
};
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"insert_refresh_out",
params);
if (PGRES_COMMAND_OK != PQresultStatus (result))
@@ -3430,13 +3430,13 @@ postgres_get_link_data_list (void *cls,
struct TALER_MINTDB_LinkDataList *pos;
int i;
int nrows;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (session_hash),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (session_hash),
+ GNUNET_PQ_query_param_end
};
PGresult *result;
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"get_link",
params);
@@ -3461,19 +3461,19 @@ postgres_get_link_data_list (void *cls,
struct GNUNET_CRYPTO_rsa_Signature *sig;
void *ld_buf;
size_t ld_buf_size;
- struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_variable_size ("link_vector_enc",
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_variable_size ("link_vector_enc",
&ld_buf,
&ld_buf_size),
- TALER_PQ_result_spec_rsa_signature ("ev_sig",
+ GNUNET_PQ_result_spec_rsa_signature ("ev_sig",
&sig),
- TALER_PQ_result_spec_rsa_public_key ("denom_pub",
+ GNUNET_PQ_result_spec_rsa_public_key ("denom_pub",
&denom_pub),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
if (GNUNET_OK !=
- TALER_PQ_extract_result (result, rs, i))
+ GNUNET_PQ_extract_result (result, rs, i))
{
PQclear (result);
GNUNET_break (0);
@@ -3525,15 +3525,15 @@ postgres_get_transfer (void *cls,
TALER_MINTDB_TransferDataCallback tdc,
void *tdc_cls)
{
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (coin_pub),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_end
};
PGresult *result;
int nrows;
int i;
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"get_transfer",
params);
if (PGRES_TUPLES_OK !=
@@ -3555,15 +3555,15 @@ postgres_get_transfer (void *cls,
struct GNUNET_HashCode session_hash;
struct TALER_TransferPublicKeyP transfer_pub;
struct TALER_EncryptedLinkSecretP shared_secret_enc;
- struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_auto_from_type ("transfer_pub", &transfer_pub),
- TALER_PQ_result_spec_auto_from_type ("link_secret_enc", &shared_secret_enc),
- TALER_PQ_result_spec_auto_from_type ("session_hash", &session_hash),
- TALER_PQ_result_spec_end
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("transfer_pub", &transfer_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("link_secret_enc", &shared_secret_enc),
+ GNUNET_PQ_result_spec_auto_from_type ("session_hash", &session_hash),
+ GNUNET_PQ_result_spec_end
};
if (GNUNET_OK !=
- TALER_PQ_extract_result (result, rs, 0))
+ GNUNET_PQ_extract_result (result, rs, 0))
{
PQclear (result);
GNUNET_break (0);
@@ -3598,16 +3598,16 @@ postgres_get_coin_transactions (void *cls,
head = NULL;
/* check deposits */
{
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (&coin_pub->eddsa_pub),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&coin_pub->eddsa_pub),
+ GNUNET_PQ_query_param_end
};
int nrows;
int i;
PGresult *result;
struct TALER_MINTDB_TransactionList *tl;
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"get_deposit_with_coin_pub",
params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
@@ -3623,36 +3623,36 @@ postgres_get_coin_transactions (void *cls,
deposit = GNUNET_new (struct TALER_MINTDB_Deposit);
{
- struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_rsa_public_key ("denom_pub",
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_rsa_public_key ("denom_pub",
&deposit->coin.denom_pub.rsa_public_key),
- TALER_PQ_result_spec_rsa_signature ("denom_sig",
+ GNUNET_PQ_result_spec_rsa_signature ("denom_sig",
&deposit->coin.denom_sig.rsa_signature),
- TALER_PQ_result_spec_uint64 ("transaction_id",
+ GNUNET_PQ_result_spec_uint64 ("transaction_id",
&deposit->transaction_id),
TALER_PQ_result_spec_amount ("amount_with_fee",
&deposit->amount_with_fee),
TALER_PQ_result_spec_amount ("deposit_fee",
&deposit->deposit_fee),
- TALER_PQ_result_spec_absolute_time ("timestamp",
+ GNUNET_PQ_result_spec_absolute_time ("timestamp",
&deposit->timestamp),
- TALER_PQ_result_spec_absolute_time ("refund_deadline",
+ GNUNET_PQ_result_spec_absolute_time ("refund_deadline",
&deposit->refund_deadline),
- TALER_PQ_result_spec_auto_from_type ("merchant_pub",
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
&deposit->merchant_pub),
- TALER_PQ_result_spec_auto_from_type ("h_contract",
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract",
&deposit->h_contract),
- TALER_PQ_result_spec_auto_from_type ("h_wire",
+ GNUNET_PQ_result_spec_auto_from_type ("h_wire",
&deposit->h_wire),
TALER_PQ_result_spec_json ("wire",
&deposit->wire),
- TALER_PQ_result_spec_auto_from_type ("coin_sig",
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
&deposit->csig),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
if (GNUNET_OK !=
- TALER_PQ_extract_result (result, rs, i))
+ GNUNET_PQ_extract_result (result, rs, i))
{
GNUNET_break (0);
GNUNET_free (deposit);
@@ -3672,9 +3672,9 @@ postgres_get_coin_transactions (void *cls,
}
/* Handle refreshing */
{
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (&coin_pub->eddsa_pub),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&coin_pub->eddsa_pub),
+ GNUNET_PQ_query_param_end
};
int nrows;
int i;
@@ -3682,7 +3682,7 @@ postgres_get_coin_transactions (void *cls,
struct TALER_MINTDB_TransactionList *tl;
/* check if the melt record exists and get it */
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"get_refresh_melt_by_coin",
params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
@@ -3698,20 +3698,20 @@ postgres_get_coin_transactions (void *cls,
melt = GNUNET_new (struct TALER_MINTDB_RefreshMelt);
{
- struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_auto_from_type ("session_hash",
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("session_hash",
&melt->session_hash),
/* oldcoin_index not needed */
- TALER_PQ_result_spec_auto_from_type ("coin_sig",
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
&melt->coin_sig),
TALER_PQ_result_spec_amount ("amount_with_fee",
&melt->amount_with_fee),
TALER_PQ_result_spec_amount ("melt_fee",
&melt->melt_fee),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
if (GNUNET_OK !=
- TALER_PQ_extract_result (result, rs, 0))
+ GNUNET_PQ_extract_result (result, rs, 0))
{
GNUNET_break (0);
GNUNET_free (melt);
@@ -3758,15 +3758,15 @@ postgres_lookup_wire_transfer (void *cls,
void *cb_cls)
{
PGresult *result;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (wtid),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_end
};
int nrows;
int i;
/* check if the melt record exists and get it */
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"lookup_transactions",
params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
@@ -3794,19 +3794,19 @@ postgres_lookup_wire_transfer (void *cls,
struct TALER_Amount coin_amount;
struct TALER_Amount coin_fee;
struct TALER_Amount transfer_amount;
- struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_auto_from_type ("h_contract", &h_contract),
- TALER_PQ_result_spec_auto_from_type ("h_wire", &h_wire),
- TALER_PQ_result_spec_auto_from_type ("coin_pub", &coin_pub),
- TALER_PQ_result_spec_auto_from_type ("merchant_pub", &merchant_pub),
- TALER_PQ_result_spec_uint64 ("transaction_id", &transaction_id),
- TALER_PQ_result_spec_absolute_time ("execution_time", &exec_time),
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract", &h_contract),
+ GNUNET_PQ_result_spec_auto_from_type ("h_wire", &h_wire),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub", &coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_pub", &merchant_pub),
+ GNUNET_PQ_result_spec_uint64 ("transaction_id", &transaction_id),
+ GNUNET_PQ_result_spec_absolute_time ("execution_time", &exec_time),
TALER_PQ_result_spec_amount ("coin_amount", &coin_amount),
TALER_PQ_result_spec_amount ("coin_fee", &coin_fee),
TALER_PQ_result_spec_amount ("transfer_total", &transfer_amount),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
- if (GNUNET_OK != TALER_PQ_extract_result (result, rs, i))
+ if (GNUNET_OK != GNUNET_PQ_extract_result (result, rs, i))
{
GNUNET_break (0);
PQclear (result);
@@ -3856,18 +3856,18 @@ postgres_wire_lookup_deposit_wtid (void *cls,
void *cb_cls)
{
PGresult *result;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (coin_pub),
- TALER_PQ_query_param_auto_from_type (h_contract),
- TALER_PQ_query_param_auto_from_type (h_wire),
- TALER_PQ_query_param_uint64 (&transaction_id),
- TALER_PQ_query_param_auto_from_type (merchant_pub),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_contract),
+ GNUNET_PQ_query_param_auto_from_type (h_wire),
+ GNUNET_PQ_query_param_uint64 (&transaction_id),
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
+ GNUNET_PQ_query_param_end
};
int nrows;
/* check if the melt record exists and get it */
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"lookup_deposit_wtid",
params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
@@ -3887,16 +3887,16 @@ postgres_wire_lookup_deposit_wtid (void *cls,
do not have a WTID yet, if so, do call the CB with a NULL wtid
and return GNUNET_YES! */
{
- struct TALER_PQ_QueryParam params2[] = {
- TALER_PQ_query_param_auto_from_type (coin_pub),
- TALER_PQ_query_param_uint64 (&transaction_id),
- TALER_PQ_query_param_auto_from_type (merchant_pub),
- TALER_PQ_query_param_auto_from_type (h_contract),
- TALER_PQ_query_param_auto_from_type (h_wire),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params2[] = {
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_uint64 (&transaction_id),
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_contract),
+ GNUNET_PQ_query_param_auto_from_type (h_wire),
+ GNUNET_PQ_query_param_end
};
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"get_deposit_for_wtid",
params2);
if (PGRES_TUPLES_OK != PQresultStatus (result))
@@ -3921,14 +3921,14 @@ postgres_wire_lookup_deposit_wtid (void *cls,
struct GNUNET_TIME_Absolute exec_time;
struct TALER_Amount coin_amount;
struct TALER_Amount coin_fee;
- struct TALER_PQ_ResultSpec rs[] = {
+ struct GNUNET_PQ_ResultSpec rs[] = {
TALER_PQ_result_spec_amount ("amount_with_fee", &coin_amount),
TALER_PQ_result_spec_amount ("deposit_fee", &coin_fee),
- TALER_PQ_result_spec_absolute_time ("wire_deadline", &exec_time),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_absolute_time ("wire_deadline", &exec_time),
+ GNUNET_PQ_result_spec_end
};
- if (GNUNET_OK != TALER_PQ_extract_result (result, rs, 0))
+ if (GNUNET_OK != GNUNET_PQ_extract_result (result, rs, 0))
{
GNUNET_break (0);
PQclear (result);
@@ -3954,14 +3954,14 @@ postgres_wire_lookup_deposit_wtid (void *cls,
struct GNUNET_TIME_Absolute exec_time;
struct TALER_Amount coin_amount;
struct TALER_Amount coin_fee;
- struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_auto_from_type ("wtid_raw", &wtid),
- TALER_PQ_result_spec_absolute_time ("execution_time", &exec_time),
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("wtid_raw", &wtid),
+ GNUNET_PQ_result_spec_absolute_time ("execution_time", &exec_time),
TALER_PQ_result_spec_amount ("coin_amount", &coin_amount),
TALER_PQ_result_spec_amount ("coin_fee", &coin_fee),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
- if (GNUNET_OK != TALER_PQ_extract_result (result, rs, 0))
+ if (GNUNET_OK != GNUNET_PQ_extract_result (result, rs, 0))
{
GNUNET_break (0);
PQclear (result);
@@ -4006,21 +4006,21 @@ postgres_insert_aggregation_tracking (void *cls,
const struct TALER_Amount *coin_value,
const struct TALER_Amount *coin_fee)
{
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_auto_from_type (h_contract),
- TALER_PQ_query_param_auto_from_type (h_wire),
- TALER_PQ_query_param_auto_from_type (coin_pub),
- TALER_PQ_query_param_auto_from_type (merchant_pub),
- TALER_PQ_query_param_uint64 (&transaction_id),
- TALER_PQ_query_param_auto_from_type (wtid),
- TALER_PQ_query_param_absolute_time (&execution_time),
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_contract),
+ GNUNET_PQ_query_param_auto_from_type (h_wire),
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
+ GNUNET_PQ_query_param_uint64 (&transaction_id),
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_absolute_time (&execution_time),
TALER_PQ_query_param_amount (coin_value),
TALER_PQ_query_param_amount (coin_fee),
- TALER_PQ_query_param_end
+ GNUNET_PQ_query_param_end
};
PGresult *result;
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"insert_aggregation_tracking",
params);
if (PGRES_COMMAND_OK != PQresultStatus (result))
@@ -4058,13 +4058,13 @@ postgres_wire_prepare_data_insert (void *cls,
size_t buf_size)
{
PGresult *result;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_fixed_size (type, strlen (type) + 1),
- TALER_PQ_query_param_fixed_size (buf, buf_size),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_fixed_size (type, strlen (type) + 1),
+ GNUNET_PQ_query_param_fixed_size (buf, buf_size),
+ GNUNET_PQ_query_param_end
};
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"wire_prepare_data_insert",
params);
if (PGRES_COMMAND_OK != PQresultStatus (result))
@@ -4092,13 +4092,13 @@ postgres_wire_prepare_data_mark_finished (void *cls,
unsigned long long rowid)
{
uint64_t serial_id = rowid;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_uint64 (&serial_id),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
};
PGresult *result;
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"wire_prepare_data_mark_done",
params);
if (PGRES_COMMAND_OK !=
@@ -4134,12 +4134,12 @@ postgres_wire_prepare_data_get (void *cls,
void *cb_cls)
{
PGresult *result;
- struct TALER_PQ_QueryParam params[] = {
- TALER_PQ_query_param_fixed_size (type, strlen (type) + 1),
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_fixed_size (type, strlen (type) + 1),
+ GNUNET_PQ_query_param_end
};
- result = TALER_PQ_exec_prepared (session->conn,
+ result = GNUNET_PQ_exec_prepared (session->conn,
"wire_prepare_data_get",
params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
@@ -4164,17 +4164,17 @@ postgres_wire_prepare_data_get (void *cls,
uint64_t serial_id;
void *buf = NULL;
size_t buf_size;
- struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_uint64 ("serial_id",
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial_id",
&serial_id),
- TALER_PQ_result_spec_variable_size ("buf",
+ GNUNET_PQ_result_spec_variable_size ("buf",
&buf,
&buf_size),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
if (GNUNET_OK !=
- TALER_PQ_extract_result (result,
+ GNUNET_PQ_extract_result (result,
rs,
0))
{
@@ -4186,7 +4186,7 @@ postgres_wire_prepare_data_get (void *cls,
serial_id,
buf,
buf_size);
- TALER_PQ_cleanup_result (rs);
+ GNUNET_PQ_cleanup_result (rs);
}
PQclear (result);
return GNUNET_OK;
diff --git a/src/pq/Makefile.am b/src/pq/Makefile.am
index 2187d494b..810aa47b3 100644
--- a/src/pq/Makefile.am
+++ b/src/pq/Makefile.am
@@ -12,8 +12,8 @@ lib_LTLIBRARIES = \
libtalerpq.la
libtalerpq_la_SOURCES = \
- db_pq.c \
- pq_helper.c
+ pq_query_helper.c \
+ pq_result_helper.c
libtalerpq_la_LIBADD = \
$(top_builddir)/src/util/libtalerutil.la \
@@ -36,5 +36,7 @@ test_pq_SOURCES = \
test_pq_LDADD = \
libtalerpq.la \
$(top_builddir)/src/util/libtalerutil.la \
- -lgnunetutil -ljansson \
+ -lgnunetpq \
+ -lgnunetutil \
+ -ljansson \
-lpq $(XLIB)
diff --git a/src/pq/db_pq.c b/src/pq/db_pq.c
deleted file mode 100644
index 59a1db022..000000000
--- a/src/pq/db_pq.c
+++ /dev/null
@@ -1,883 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014, 2015 GNUnet e.V.
-
- 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, If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file pq/db_pq.c
- * @brief helper functions for libpq (PostGres) interactions
- * @author Sree Harsha Totakura <sreeharsha@totakura.in>
- * @author Florian Dold
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <gnunet/gnunet_util_lib.h>
-#include "taler_pq_lib.h"
-
-
-/**
- * Execute a prepared statement.
- *
- * @param db_conn database connection
- * @param name name of the prepared statement
- * @param params parameters to the statement
- * @return postgres result
- */
-PGresult *
-TALER_PQ_exec_prepared (PGconn *db_conn,
- const char *name,
- const struct TALER_PQ_QueryParam *params)
-{
- unsigned int len;
- unsigned int i;
-
- /* count the number of parameters */
- i = 0;
- len = 0;
- while (TALER_PQ_QF_END != params[i].format)
- {
- const struct TALER_PQ_QueryParam *x = &params[i];
-
- switch (x->format)
- {
- case TALER_PQ_QF_FIXED_BLOB:
- case TALER_PQ_QF_VARSIZE_BLOB:
- len++;
- break;
- case TALER_PQ_QF_AMOUNT_NBO:
- case TALER_PQ_QF_AMOUNT:
- len += 3;
- break;
- case TALER_PQ_QF_RSA_PUBLIC_KEY:
- case TALER_PQ_QF_RSA_SIGNATURE:
- case TALER_PQ_QF_TIME_ABSOLUTE:
- case TALER_PQ_QF_UINT16:
- case TALER_PQ_QF_UINT32:
- case TALER_PQ_QF_UINT64:
- case TALER_PQ_QF_JSON:
- len++;
- break;
- default:
- /* format not supported */
- GNUNET_assert (0);
- break;
- }
- i++;
- }
-
- /* new scope to allow stack allocation without alloca */
- {
- /* Scratch buffer for temporary storage */
- void *scratch[len];
- /* Parameter array we are building for the query */
- void *param_values[len];
- int param_lengths[len];
- int param_formats[len];
- unsigned int off;
- /* How many entries in the scratch buffer are in use? */
- unsigned int soff;
- PGresult *res;
-
- i = 0;
- off = 0;
- soff = 0;
- while (TALER_PQ_QF_END != params[i].format)
- {
- const struct TALER_PQ_QueryParam *x = &params[i];
-
- switch (x->format)
- {
- case TALER_PQ_QF_FIXED_BLOB:
- case TALER_PQ_QF_VARSIZE_BLOB:
- param_values[off] = (void *) x->data;
- param_lengths[off] = x->size;
- param_formats[off] = 1;
- off++;
- break;
- case TALER_PQ_QF_AMOUNT_NBO:
- {
- const struct TALER_Amount *amount = x->data;
-
- param_values[off] = (void *) &amount->value;
- param_lengths[off] = sizeof (amount->value);
- param_formats[off] = 1;
- off++;
- param_values[off] = (void *) &amount->fraction;
- param_lengths[off] = sizeof (amount->fraction);
- param_formats[off] = 1;
- off++;
- param_values[off] = (void *) amount->currency;
- param_lengths[off] = strlen (amount->currency);
- param_formats[off] = 1;
- off++;
- }
- break;
- case TALER_PQ_QF_AMOUNT:
- {
- const struct TALER_Amount *amount_hbo = x->data;
- struct TALER_AmountNBO *amount;
-
- amount = GNUNET_new (struct TALER_AmountNBO);
- scratch[soff++] = amount;
- TALER_amount_hton (amount,
- amount_hbo);
- param_values[off] = (void *) &amount->value;
- param_lengths[off] = sizeof (amount->value);
- param_formats[off] = 1;
- off++;
- param_values[off] = (void *) &amount->fraction;
- param_lengths[off] = sizeof (amount->fraction);
- param_formats[off] = 1;
- off++;
- param_values[off] = (void *) amount->currency;
- param_lengths[off] = strlen (amount->currency);
- param_formats[off] = 1;
- off++;
- }
- break;
- case TALER_PQ_QF_RSA_PUBLIC_KEY:
- {
- const struct GNUNET_CRYPTO_rsa_PublicKey *rsa = x->data;
- char *buf;
- size_t buf_size;
-
- buf_size = GNUNET_CRYPTO_rsa_public_key_encode (rsa,
- &buf);
- scratch[soff++] = buf;
- param_values[off] = (void *) buf;
- param_lengths[off] = buf_size - 1; /* DB doesn't like the trailing \0 */
- param_formats[off] = 1;
- off++;
- }
- break;
- case TALER_PQ_QF_RSA_SIGNATURE:
- {
- const struct GNUNET_CRYPTO_rsa_Signature *sig = x->data;
- char *buf;
- size_t buf_size;
-
- buf_size = GNUNET_CRYPTO_rsa_signature_encode (sig,
- &buf);
- scratch[soff++] = buf;
- param_values[off] = (void *) buf;
- param_lengths[off] = buf_size - 1; /* DB doesn't like the trailing \0 */
- param_formats[off] = 1;
- off++;
- }
- break;
- case TALER_PQ_QF_TIME_ABSOLUTE:
- {
- const struct GNUNET_TIME_Absolute *at_hbo = x->data;
- struct GNUNET_TIME_AbsoluteNBO *at_nbo;
-
- at_nbo = GNUNET_new (struct GNUNET_TIME_AbsoluteNBO);
- scratch[soff++] = at_nbo;
- *at_nbo = GNUNET_TIME_absolute_hton (*at_hbo);
- param_values[off] = (void *) at_nbo;
- param_lengths[off] = sizeof (struct GNUNET_TIME_AbsoluteNBO);
- param_formats[off] = 1;
- off++;
- }
- break;
- case TALER_PQ_QF_UINT16:
- {
- const uint16_t *u_hbo = x->data;
- uint16_t *u_nbo;
-
- u_nbo = GNUNET_new (uint16_t);
- scratch[soff++] = u_nbo;
- *u_nbo = htons (*u_hbo);
- param_values[off] = (void *) u_nbo;
- param_lengths[off] = sizeof (uint16_t);
- param_formats[off] = 1;
- off++;
- }
- break;
- case TALER_PQ_QF_UINT32:
- {
- const uint32_t *u_hbo = x->data;
- uint32_t *u_nbo;
-
- u_nbo = GNUNET_new (uint32_t);
- scratch[soff++] = u_nbo;
- *u_nbo = htonl (*u_hbo);
- param_values[off] = (void *) u_nbo;
- param_lengths[off] = sizeof (uint32_t);
- param_formats[off] = 1;
- off++;
- }
- break;
- case TALER_PQ_QF_UINT64:
- {
- const uint64_t *u_hbo = x->data;
- uint64_t *u_nbo;
-
- u_nbo = GNUNET_new (uint64_t);
- scratch[soff++] = u_nbo;
- *u_nbo = GNUNET_htonll (*u_hbo);
- param_values[off] = (void *) u_nbo;
- param_lengths[off] = sizeof (uint64_t);
- param_formats[off] = 1;
- off++;
- }
- break;
- case TALER_PQ_QF_JSON:
- {
- const json_t *json = x->data;
- char *str;
-
- str = json_dumps (json, JSON_COMPACT);
- GNUNET_assert (NULL != str);
- scratch[soff++] = str;
- param_values[off] = (void *) str;
- param_lengths[off] = strlen (str);
- param_formats[off] = 1;
- off++;
- }
- break;
- default:
- /* format not supported */
- GNUNET_assert (0);
- break;
- }
- i++;
- }
- GNUNET_assert (off == len);
- res = PQexecPrepared (db_conn,
- name,
- len,
- (const char **) param_values,
- param_lengths,
- param_formats,
- 1);
- for (off = 0; off < soff; off++)
- GNUNET_free (scratch[off]);
- return res;
- }
-}
-
-
-/**
- * Free all memory that was allocated in @a rs during
- * #TALER_PQ_extract_result().
- *
- * @param rs reult specification to clean up
- */
-void
-TALER_PQ_cleanup_result (struct TALER_PQ_ResultSpec *rs)
-{
- unsigned int i;
-
- for (i=0; TALER_PQ_RF_END != rs[i].format; i++)
- {
- switch (rs[i].format)
- {
- case TALER_PQ_RF_VARSIZE_BLOB:
- {
- void **dst = rs[i].dst;
- if (NULL != *dst)
- {
- GNUNET_free (*dst);
- *dst = NULL;
- *rs[i].result_size = 0;
- }
- break;
- }
- case TALER_PQ_RF_RSA_PUBLIC_KEY:
- {
- void **dst = rs[i].dst;
- if (NULL != *dst)
- {
- GNUNET_CRYPTO_rsa_public_key_free (*dst);
- *dst = NULL;
- }
- break;
- }
- case TALER_PQ_RF_RSA_SIGNATURE:
- {
- void **dst = rs[i].dst;
- if (NULL != *dst)
- {
- GNUNET_CRYPTO_rsa_signature_free (*dst);
- *dst = NULL;
- }
- }
- break;
- default:
- break;
- }
- }
-}
-
-
-/**
- * Extract results from a query result according to the given specification.
- * If colums are NULL, the destination is not modified, and #GNUNET_NO
- * is returned.
- *
- * @param result result to process
- * @param[in,out] rs result specification to extract for
- * @param row row from the result to extract
- * @return
- * #GNUNET_YES if all results could be extracted
- * #GNUNET_NO if at least one result was NULL
- * #GNUNET_SYSERR if a result was invalid (non-existing field)
- */
-int
-TALER_PQ_extract_result (PGresult *result,
- struct TALER_PQ_ResultSpec *rs,
- int row)
-{
- unsigned int i;
- int had_null = GNUNET_NO;
-
- for (i=0; TALER_PQ_RF_END != rs[i].format; i++)
- {
- struct TALER_PQ_ResultSpec *spec;
-
- spec = &rs[i];
- switch (spec->format)
- {
- case TALER_PQ_RF_FIXED_BLOB:
- case TALER_PQ_RF_VARSIZE_BLOB:
- {
- size_t len;
- const char *res;
- void *dst;
- int fnum;
-
- fnum = PQfnumber (result,
- spec->fname);
- if (fnum < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Field `%s' does not exist in result\n",
- spec->fname);
- return GNUNET_SYSERR;
- }
- if (PQgetisnull (result,
- row,
- fnum))
- {
- had_null = GNUNET_YES;
- continue;
- }
-
- /* if a field is null, continue but
- * remember that we now return a different result */
- len = PQgetlength (result,
- row,
- fnum);
- if ( (0 != spec->dst_size) &&
- (spec->dst_size != len) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Field `%s' has wrong size (got %u, expected %u)\n",
- spec->fname,
- (unsigned int) len,
- (unsigned int) spec->dst_size);
- TALER_PQ_cleanup_result (rs);
- return GNUNET_SYSERR;
- }
- res = PQgetvalue (result,
- row,
- fnum);
- GNUNET_assert (NULL != res);
- if (0 == spec->dst_size)
- {
- if (NULL != spec->result_size)
- *spec->result_size = len;
- spec->dst_size = len;
- dst = GNUNET_malloc (len);
- *((void **) spec->dst) = dst;
- }
- else
- dst = spec->dst;
- memcpy (dst,
- res,
- len);
- break;
- }
- case TALER_PQ_RF_AMOUNT_NBO:
- {
- char *val_name;
- char *frac_name;
- char *curr_name;
- const char *name = spec->fname;
- int ret;
-
- GNUNET_assert (NULL != spec->dst);
- GNUNET_assert (sizeof (struct TALER_AmountNBO) ==
- spec->dst_size);
- GNUNET_asprintf (&val_name,
- "%s_val",
- name);
- GNUNET_asprintf (&frac_name,
- "%s_frac",
- name);
- GNUNET_asprintf (&curr_name,
- "%s_curr",
- name);
- ret = TALER_PQ_extract_amount_nbo (result,
- row,
- val_name,
- frac_name,
- curr_name,
- spec->dst);
- GNUNET_free (val_name);
- GNUNET_free (frac_name);
- GNUNET_free (curr_name);
- if (GNUNET_SYSERR == ret)
- return GNUNET_SYSERR;
- if (GNUNET_OK != ret)
- had_null = GNUNET_YES;
- break;
- }
- case TALER_PQ_RF_AMOUNT:
- {
- char *val_name;
- char *frac_name;
- char *curr_name;
- const char *name = spec->fname;
- int ret;
-
- GNUNET_assert (NULL != spec->dst);
- GNUNET_assert (sizeof (struct TALER_Amount) ==
- spec->dst_size);
- GNUNET_asprintf (&val_name,
- "%s_val",
- name);
- GNUNET_asprintf (&frac_name,
- "%s_frac",
- name);
- GNUNET_asprintf (&curr_name,
- "%s_curr",
- name);
- ret = TALER_PQ_extract_amount (result,
- row,
- val_name,
- frac_name,
- curr_name,
- spec->dst);
- GNUNET_free (val_name);
- GNUNET_free (frac_name);
- GNUNET_free (curr_name);
- if (GNUNET_SYSERR == ret)
- return GNUNET_SYSERR;
- if (GNUNET_OK != ret)
- had_null = GNUNET_YES;
- break;
- }
- case TALER_PQ_RF_RSA_PUBLIC_KEY:
- {
- struct GNUNET_CRYPTO_rsa_PublicKey **pk = spec->dst;
- size_t len;
- const char *res;
- int fnum;
-
- *pk = NULL;
- fnum = PQfnumber (result,
- spec->fname);
- if (fnum < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Field `%s' does not exist in result\n",
- spec->fname);
- return GNUNET_SYSERR;
- }
- if (PQgetisnull (result,
- row,
- fnum))
- {
- had_null = GNUNET_YES;
- continue;
- }
-
- /* 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);
- *pk = GNUNET_CRYPTO_rsa_public_key_decode (res,
- len);
- if (NULL == *pk)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Field `%s' contains bogus value (fails to decode)\n",
- spec->fname);
- return GNUNET_SYSERR;
- }
- break;
- }
- case TALER_PQ_RF_RSA_SIGNATURE:
- {
- struct GNUNET_CRYPTO_rsa_Signature **sig = spec->dst;
- size_t len;
- const char *res;
- int fnum;
-
- *sig = NULL;
- fnum = PQfnumber (result,
- spec->fname);
- if (fnum < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Field `%s' does not exist in result\n",
- spec->fname);
- return GNUNET_SYSERR;
- }
- if (PQgetisnull (result,
- row,
- fnum))
- {
- had_null = GNUNET_YES;
- continue;
- }
-
- /* 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);
- *sig = GNUNET_CRYPTO_rsa_signature_decode (res,
- len);
- if (NULL == *sig)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Field `%s' contains bogus value (fails to decode)\n",
- spec->fname);
- return GNUNET_SYSERR;
- }
- break;
- }
- case TALER_PQ_RF_TIME_ABSOLUTE:
- {
- struct GNUNET_TIME_Absolute *dst = spec->dst;
- const struct GNUNET_TIME_AbsoluteNBO *res;
- int fnum;
-
- fnum = PQfnumber (result,
- spec->fname);
- if (fnum < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Field `%s' does not exist in result\n",
- spec->fname);
- return GNUNET_SYSERR;
- }
- if (PQgetisnull (result,
- row,
- fnum))
- {
- had_null = GNUNET_YES;
- continue;
- }
- GNUNET_assert (NULL != dst);
- GNUNET_assert (sizeof (struct GNUNET_TIME_AbsoluteNBO) ==
- spec->dst_size);
- res = (const struct GNUNET_TIME_AbsoluteNBO *)
- PQgetvalue (result,
- row,
- fnum);
- *dst = GNUNET_TIME_absolute_ntoh (*res);
- break;
- }
- case TALER_PQ_RF_UINT16:
- {
- uint16_t *dst = spec->dst;
- const uint16_t *res;
- int fnum;
-
- fnum = PQfnumber (result,
- spec->fname);
- if (fnum < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Field `%s' does not exist in result\n",
- spec->fname);
- return GNUNET_SYSERR;
- }
- if (PQgetisnull (result,
- row,
- fnum))
- {
- had_null = GNUNET_YES;
- continue;
- }
- GNUNET_assert (NULL != dst);
- GNUNET_assert (sizeof (uint16_t) ==
- spec->dst_size);
- res = (uint16_t *) PQgetvalue (result,
- row,
- fnum);
- *dst = ntohs (*res);
- break;
- }
- case TALER_PQ_RF_UINT32:
- {
- uint32_t *dst = spec->dst;
- const uint32_t *res;
- int fnum;
-
- fnum = PQfnumber (result,
- spec->fname);
- if (fnum < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Field `%s' does not exist in result\n",
- spec->fname);
- return GNUNET_SYSERR;
- }
- if (PQgetisnull (result,
- row,
- fnum))
- {
- had_null = GNUNET_YES;
- continue;
- }
- GNUNET_assert (NULL != dst);
- GNUNET_assert (sizeof (uint32_t) ==
- spec->dst_size);
- res = (uint32_t *) PQgetvalue (result,
- row,
- fnum);
- *dst = ntohl (*res);
- break;
- }
- case TALER_PQ_RF_UINT64:
- {
- uint64_t *dst = spec->dst;
- const uint64_t *res;
- int fnum;
-
- fnum = PQfnumber (result,
- spec->fname);
- if (fnum < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Field `%s' does not exist in result\n",
- spec->fname);
- return GNUNET_SYSERR;
- }
- if (PQgetisnull (result,
- row,
- fnum))
- {
- had_null = GNUNET_YES;
- continue;
- }
- GNUNET_assert (NULL != dst);
- GNUNET_assert (sizeof (uint64_t) ==
- spec->dst_size);
- res = (uint64_t *) PQgetvalue (result,
- row,
- fnum);
- *dst = GNUNET_ntohll (*res);
- break;
- }
- case TALER_PQ_RF_JSON:
- {
- json_t **dst = spec->dst;
- char *res;
- int fnum;
- json_error_t json_error;
- size_t slen;
-
- fnum = PQfnumber (result,
- spec->fname);
- if (fnum < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Field `%s' does not exist in result\n",
- spec->fname);
- return GNUNET_SYSERR;
- }
- if (PQgetisnull (result,
- row,
- fnum))
- {
- had_null = GNUNET_YES;
- continue;
- }
- GNUNET_assert (NULL != dst);
- GNUNET_break (0 == spec->dst_size);
- slen = PQgetlength (result,
- row,
- fnum);
- res = (char *) PQgetvalue (result,
- row,
- fnum);
- *dst = json_loadb (res,
- slen,
- JSON_REJECT_DUPLICATES,
- &json_error);
- if (NULL == *dst)
- {
- TALER_json_warn (json_error);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to parse JSON result for field `%s'\n",
- spec->fname);
- return GNUNET_SYSERR;
- }
- break;
- }
- default:
- GNUNET_assert (0);
- break;
- }
- }
- if (GNUNET_YES == had_null)
- return GNUNET_NO;
- return GNUNET_YES;
-}
-
-
-/**
- * Extract a currency amount from a query result according to the
- * given specification.
- *
- * @param result the result to extract the amount from
- * @param row which row of the result to extract the amount from (needed as results can have multiple rows)
- * @param val_name name of the column with the amount's "value", must include the substring "_val".
- * @param frac_name name of the column with the amount's "fractional" value, must include the substring "_frac".
- * @param curr_name name of the column with the amount's currency name, must include the substring "_curr".
- * @param[out] r_amount_nbo where to store the amount, in network byte order
- * @return
- * #GNUNET_YES if all results could be extracted
- * #GNUNET_NO if at least one result was NULL
- * #GNUNET_SYSERR if a result was invalid (non-existing field)
- */
-int
-TALER_PQ_extract_amount_nbo (PGresult *result,
- int row,
- const char *val_name,
- const char *frac_name,
- const char *curr_name,
- struct TALER_AmountNBO *r_amount_nbo)
-{
- int val_num;
- int frac_num;
- int curr_num;
- int len;
-
- /* These checks are simply to check that clients obey by our naming
- conventions, and not for any functional reason */
- GNUNET_assert (NULL !=
- strstr (val_name,
- "_val"));
- GNUNET_assert (NULL !=
- strstr (frac_name,
- "_frac"));
- GNUNET_assert (NULL !=
- strstr (curr_name,
- "_curr"));
- /* Set return value to invalid in case we don't finish */
- memset (r_amount_nbo,
- 0,
- sizeof (struct TALER_AmountNBO));
- val_num = PQfnumber (result,
- val_name);
- frac_num = PQfnumber (result,
- frac_name);
- curr_num = PQfnumber (result,
- curr_name);
- if ( (val_num < 0) ||
- (frac_num < 0) ||
- (curr_num < 0) )
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- if ( (PQgetisnull (result,
- row,
- val_num)) ||
- (PQgetisnull (result,
- row,
- frac_num)) ||
- (PQgetisnull (result,
- row,
- curr_num)) )
- {
- GNUNET_break (0);
- return GNUNET_NO;
- }
- /* Note that Postgres stores value in NBO internally,
- so no conversion needed in this case */
- r_amount_nbo->value = *(uint64_t *) PQgetvalue (result,
- row,
- val_num);
- r_amount_nbo->fraction = *(uint32_t *) PQgetvalue (result,
- row,
- frac_num);
- len = GNUNET_MIN (TALER_CURRENCY_LEN - 1,
- PQgetlength (result,
- row,
- curr_num));
- memcpy (r_amount_nbo->currency,
- PQgetvalue (result,
- row,
- curr_num),
- len);
- return GNUNET_OK;
-}
-
-
-/**
- * Extract a currency amount from a query result according to the
- * given specification.
- *
- * @param result the result to extract the amount from
- * @param row which row of the result to extract the amount from (needed as
- * results can have multiple rows)
- * @param val_name name of the column with the amount's "value", must include
- * the substring "_val".
- * @param frac_name name of the column with the amount's "fractional" value,
- * must include the substring "_frac".
- * @param curr_name name of the column with the amount's currency name, must
- * include the substring "_curr".
- * @param[out] r_amount where to store the amount, in host byte order
- * @return
- * #GNUNET_YES if all results could be extracted
- * #GNUNET_NO if at least one result was NULL
- * #GNUNET_SYSERR if a result was invalid (non-existing field)
- */
-int
-TALER_PQ_extract_amount (PGresult *result,
- int row,
- const char *val_name,
- const char *frac_name,
- const char *curr_name,
- struct TALER_Amount *r_amount)
-{
- struct TALER_AmountNBO amount_nbo;
- int ret;
-
- ret = TALER_PQ_extract_amount_nbo (result,
- row,
- val_name,
- frac_name,
- curr_name,
- &amount_nbo);
- TALER_amount_ntoh (r_amount,
- &amount_nbo);
- return ret;
-}
-
-
-/* end of pq/db_pq.c */
diff --git a/src/pq/pq_helper.c b/src/pq/pq_helper.c
deleted file mode 100644
index d245ffdb8..000000000
--- a/src/pq/pq_helper.c
+++ /dev/null
@@ -1,370 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014, 2015 GNUnet e.V.
-
- 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, If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file pq/pq_helper.c
- * @brief functions to initialize parameter arrays
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <gnunet/gnunet_util_lib.h>
-#include "taler_pq_lib.h"
-
-
-/**
- * Generate query parameter for a currency, consisting of the three
- * components "value", "fraction" and "currency" in this order. The
- * types must be a 64-bit integer, 32-bit integer and a
- * #TALER_CURRENCY_LEN-sized BLOB/VARCHAR respectively.
- *
- * @param x pointer to the query parameter to pass
- * @return array entry for the query parameters to use
- */
-struct TALER_PQ_QueryParam
-TALER_PQ_query_param_amount_nbo (const struct TALER_AmountNBO *x)
-{
- struct TALER_PQ_QueryParam res =
- { TALER_PQ_QF_AMOUNT_NBO, x, sizeof (*x) };
- return res;
-}
-
-
-/**
- * Generate query parameter for a currency, consisting of the three
- * components "value", "fraction" and "currency" in this order. The
- * types must be a 64-bit integer, 32-bit integer and a
- * #TALER_CURRENCY_LEN-sized BLOB/VARCHAR respectively.
- *
- * @param x pointer to the query parameter to pass
- * @return array entry for the query parameters to use
- */
-struct TALER_PQ_QueryParam
-TALER_PQ_query_param_amount (const struct TALER_Amount *x)
-{
- struct TALER_PQ_QueryParam res =
- { TALER_PQ_QF_AMOUNT, x, sizeof (*x) };
- return res;
-}
-
-
-/**
- * Generate query parameter for an RSA public key. The
- * database must contain a BLOB type in the respective position.
- *
- * @param x the query parameter to pass
- * @return array entry for the query parameters to use
- */
-struct TALER_PQ_QueryParam
-TALER_PQ_query_param_rsa_public_key (const struct GNUNET_CRYPTO_rsa_PublicKey *x)
-{
- struct TALER_PQ_QueryParam res =
- { TALER_PQ_QF_RSA_PUBLIC_KEY, (x), 0 };
- return res;
-}
-
-
-/**
- * Generate query parameter for an RSA signature. The
- * database must contain a BLOB type in the respective position.
- *
- * @param x the query parameter to pass
- * @return array entry for the query parameters to use
- */
-struct TALER_PQ_QueryParam
-TALER_PQ_query_param_rsa_signature (const struct GNUNET_CRYPTO_rsa_Signature *x)
-{
- struct TALER_PQ_QueryParam res =
- { TALER_PQ_QF_RSA_SIGNATURE, (x), 0 };
- return res;
-}
-
-
-/**
- * Generate query parameter for an absolute time value.
- * The database must store a 64-bit integer.
- *
- * @param x pointer to the query parameter to pass
- * @return array entry for the query parameters to use
- */
-struct TALER_PQ_QueryParam
-TALER_PQ_query_param_absolute_time (const struct GNUNET_TIME_Absolute *x)
-{
- struct TALER_PQ_QueryParam res =
- { TALER_PQ_QF_TIME_ABSOLUTE, x, sizeof (*x) };
- return res;
-}
-
-
-/**
- * Generate query parameter for an absolute time value.
- * The database must store a 64-bit integer.
- *
- * @param x pointer to the query parameter to pass
- */
-struct TALER_PQ_QueryParam
-TALER_PQ_query_param_absolute_time_nbo(const struct GNUNET_TIME_AbsoluteNBO *x)
-{
- struct TALER_PQ_QueryParam res =
- TALER_PQ_query_param_auto_from_type (&x->abs_value_us__);
- return res;
-}
-
-
-/**
- * Generate query parameter for an uint16_t in host byte order.
- *
- * @param x pointer to the query parameter to pass
- */
-struct TALER_PQ_QueryParam
-TALER_PQ_query_param_uint16 (const uint16_t *x)
-{
- struct TALER_PQ_QueryParam res =
- { TALER_PQ_QF_UINT16, x, sizeof (*x) };
- return res;
-}
-
-
-/**
- * Generate query parameter for an uint32_t in host byte order.
- *
- * @param x pointer to the query parameter to pass
- */
-struct TALER_PQ_QueryParam
-TALER_PQ_query_param_uint32 (const uint32_t *x)
-{
- struct TALER_PQ_QueryParam res =
- { TALER_PQ_QF_UINT32, x, sizeof (*x) };
- return res;
-}
-
-
-/**
- * Generate query parameter for an uint16_t in host byte order.
- *
- * @param x pointer to the query parameter to pass
- */
-struct TALER_PQ_QueryParam
-TALER_PQ_query_param_uint64 (const uint64_t *x)
-{
- struct TALER_PQ_QueryParam res =
- { TALER_PQ_QF_UINT64, x, sizeof (*x) };
- return res;
-}
-
-
-/**
- * Generate query parameter for a JSON object (stored as a string
- * in the DB).
- *
- * @param x pointer to the json object to pass
- */
-struct TALER_PQ_QueryParam
-TALER_PQ_query_param_json (const json_t *x)
-{
- struct TALER_PQ_QueryParam res =
- { TALER_PQ_QF_JSON, x, 0 };
- return res;
-}
-
-
-/**
- * Variable-size result expected.
- *
- * @param name name of the field in the table
- * @param[out] dst where to store the result, allocated
- * @param[out] sptr where to store the size of @a dst
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_variable_size (const char *name,
- void **dst,
- size_t *sptr)
-{
- struct TALER_PQ_ResultSpec res =
- { TALER_PQ_RF_VARSIZE_BLOB, (void *) (dst), 0, name, sptr };
- return res;
-}
-
-
-/**
- * Currency amount expected.
- *
- * @param name name of the field in the table
- * @param[out] amount where to store the result
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_amount_nbo (const char *name,
- struct TALER_AmountNBO *amount)
-{
- struct TALER_PQ_ResultSpec res =
- {TALER_PQ_RF_AMOUNT_NBO, (void *) amount, sizeof (*amount), name, NULL };
- return res;
-}
-
-
-/**
- * Currency amount expected.
- *
- * @param name name of the field in the table
- * @param[out] amount where to store the result
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_amount (const char *name,
- struct TALER_Amount *amount)
-{
- struct TALER_PQ_ResultSpec res =
- {TALER_PQ_RF_AMOUNT, (void *) amount, sizeof (*amount), name, NULL };
- return res;
-}
-
-
-/**
- * RSA public key expected.
- *
- * @param name name of the field in the table
- * @param[out] rsa where to store the result
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_rsa_public_key (const char *name,
- struct GNUNET_CRYPTO_rsa_PublicKey **rsa)
-{
- struct TALER_PQ_ResultSpec res =
- {TALER_PQ_RF_RSA_PUBLIC_KEY, (void *) rsa, 0, name, NULL };
- return res;
-}
-
-
-/**
- * RSA signature expected.
- *
- * @param name name of the field in the table
- * @param[out] sig where to store the result;
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_rsa_signature (const char *name,
- struct GNUNET_CRYPTO_rsa_Signature **sig)
-{
- struct TALER_PQ_ResultSpec res =
- {TALER_PQ_RF_RSA_SIGNATURE, (void *) sig, 0, (name), NULL };
- return res;
-}
-
-
-/**
- * Absolute time expected.
- *
- * @param name name of the field in the table
- * @param[out] at where to store the result
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_absolute_time (const char *name,
- struct GNUNET_TIME_Absolute *at)
-{
- struct TALER_PQ_ResultSpec res =
- {TALER_PQ_RF_TIME_ABSOLUTE, (void *) at, sizeof (*at), (name), NULL };
- return res;
-}
-
-
-/**
- * Absolute time expected.
- *
- * @param name name of the field in the table
- * @param[out] at where to store the result
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_absolute_time_nbo (const char *name,
- struct GNUNET_TIME_AbsoluteNBO *at)
-{
- struct TALER_PQ_ResultSpec res =
- TALER_PQ_result_spec_auto_from_type(name, &at->abs_value_us__);
- return res;
-}
-
-
-/**
- * uint16_t expected.
- *
- * @param name name of the field in the table
- * @param[out] u16 where to store the result
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_uint16 (const char *name,
- uint16_t *u16)
-{
- struct TALER_PQ_ResultSpec res =
- {TALER_PQ_RF_UINT16, (void *) u16, sizeof (*u16), (name), NULL };
- return res;
-}
-
-
-/**
- * uint32_t expected.
- *
- * @param name name of the field in the table
- * @param[out] u32 where to store the result
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_uint32 (const char *name,
- uint32_t *u32)
-{
- struct TALER_PQ_ResultSpec res =
- {TALER_PQ_RF_UINT32, (void *) u32, sizeof (*u32), (name), NULL };
- return res;
-}
-
-
-/**
- * uint64_t expected.
- *
- * @param name name of the field in the table
- * @param[out] u64 where to store the result
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_uint64 (const char *name,
- uint64_t *u64)
-{
- struct TALER_PQ_ResultSpec res =
- {TALER_PQ_RF_UINT64, (void *) u64, sizeof (*u64), (name), NULL };
- return res;
-}
-
-
-/**
- * json_t expected.
- *
- * @param name name of the field in the table
- * @param[out] jp where to store the result
- * @return array entry for the result specification to use
- */
-struct TALER_PQ_ResultSpec
-TALER_PQ_result_spec_json (const char *name,
- json_t **jp)
-{
- struct TALER_PQ_ResultSpec res =
- {TALER_PQ_RF_JSON, (void *) jp, 0, (name), NULL };
- return res;
-}
-
-/* end of pq_helper.c */
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c
new file mode 100644
index 000000000..5d2e9ce06
--- /dev/null
+++ b/src/pq/pq_query_helper.c
@@ -0,0 +1,208 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014, 2015, 2016 GNUnet e.V.
+
+ 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, If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file pq/pq_query_helper.c
+ * @brief helper functions for Taler-specific libpq (PostGres) interactions
+ * @author Sree Harsha Totakura <sreeharsha@totakura.in>
+ * @author Florian Dold
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_pq_lib.h>
+#include "taler_pq_lib.h"
+
+
+/**
+ * Function called to convert input argument into SQL parameters.
+ *
+ * @param cls closure
+ * @param data pointer to input argument, here a `struct TALER_AmountNBO`
+ * @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_amount_nbo (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_AmountNBO *amount = data;
+ unsigned int off = 0;
+
+ GNUNET_assert (3 == param_length);
+ param_values[off] = (void *) &amount->value;
+ param_lengths[off] = sizeof (amount->value);
+ param_formats[off] = 1;
+ off++;
+ param_values[off] = (void *) &amount->fraction;
+ param_lengths[off] = sizeof (amount->fraction);
+ param_formats[off] = 1;
+ off++;
+ param_values[off] = (void *) amount->currency;
+ param_lengths[off] = strlen (amount->currency);
+ param_formats[off] = 1;
+ return 0;
+}
+
+
+/**
+ * Generate query parameter for a currency, consisting of the three
+ * components "value", "fraction" and "currency" in this order. The
+ * types must be a 64-bit integer, 32-bit integer and a
+ * #TALER_CURRENCY_LEN-sized BLOB/VARCHAR respectively.
+ *
+ * @param x pointer to the query parameter to pass
+ * @return array entry for the query parameters to use
+ */
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_amount_nbo (const struct TALER_AmountNBO *x)
+{
+ struct GNUNET_PQ_QueryParam res =
+ { &qconv_amount_nbo, NULL, x, sizeof (*x), 3 };
+ return res;
+}
+
+
+/**
+ * Function called to convert input argument into SQL parameters.
+ *
+ * @param cls closure
+ * @param data pointer to input argument, here a `struct TALER_Amount`
+ * @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_amount (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_Amount *amount_hbo = data;
+ struct TALER_AmountNBO *amount;
+
+ amount = GNUNET_new (struct TALER_AmountNBO);
+ scratch[0] = amount;
+ TALER_amount_hton (amount,
+ amount_hbo);
+ qconv_amount_nbo (cls,
+ amount,
+ sizeof (struct TALER_AmountNBO),
+ param_values,
+ param_lengths,
+ param_formats,
+ param_length,
+ &scratch[1],
+ scratch_length - 1);
+ return 1;
+}
+
+
+/**
+ * Generate query parameter for a currency, consisting of the three
+ * components "value", "fraction" and "currency" in this order. The
+ * types must be a 64-bit integer, 32-bit integer and a
+ * #TALER_CURRENCY_LEN-sized BLOB/VARCHAR respectively.
+ *
+ * @param x pointer to the query parameter to pass
+ * @return array entry for the query parameters to use
+ */
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_amount (const struct TALER_Amount *x)
+{
+ struct GNUNET_PQ_QueryParam res =
+ { &qconv_amount, NULL, x, sizeof (*x), 3 };
+ 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
+ * @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_json (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 json_t *json = data;
+ char *str;
+
+ str = json_dumps (json, JSON_COMPACT);
+ if (NULL == str)
+ return -1;
+ scratch[0] = str;
+ param_values[0] = (void *) str;
+ param_lengths[0] = strlen (str);
+ param_formats[0] = 1;
+ return 1;
+}
+
+
+/**
+ * Generate query parameter for a JSON object (stored as a string
+ * in the DB).
+ *
+ * @param x pointer to the json object to pass
+ */
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_json (const json_t *x)
+{
+ struct GNUNET_PQ_QueryParam res =
+ { &qconv_json, NULL, x, 0, 1 };
+ return res;
+}
+
+
+/* end of pq/pq_query_helper.c */
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c
new file mode 100644
index 000000000..c8b3b01fc
--- /dev/null
+++ b/src/pq/pq_result_helper.c
@@ -0,0 +1,358 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014, 2015, 2016 GNUnet e.V.
+
+ 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, If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file pq/pq_result_helper.c
+ * @brief functions to initialize parameter arrays
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include "taler_pq_lib.h"
+
+
+/**
+ * Extract a currency amount from a query result according to the
+ * given specification.
+ *
+ * @param result the result to extract the amount from
+ * @param row which row of the result to extract the amount from (needed as results can have multiple rows)
+ * @param val_name name of the column with the amount's "value", must include the substring "_val".
+ * @param frac_name name of the column with the amount's "fractional" value, must include the substring "_frac".
+ * @param curr_name name of the column with the amount's currency name, must include the substring "_curr".
+ * @param[out] r_amount_nbo where to store the amount, in network byte order
+ * @return
+ * #GNUNET_YES if all results could be extracted
+ * #GNUNET_NO if at least one result was NULL
+ * #GNUNET_SYSERR if a result was invalid (non-existing field)
+ */
+static int
+extract_amount_nbo_helper (PGresult *result,
+ int row,
+ const char *val_name,
+ const char *frac_name,
+ const char *curr_name,
+ struct TALER_AmountNBO *r_amount_nbo)
+{
+ int val_num;
+ int frac_num;
+ int curr_num;
+ int len;
+
+ /* These checks are simply to check that clients obey by our naming
+ conventions, and not for any functional reason */
+ GNUNET_assert (NULL !=
+ strstr (val_name,
+ "_val"));
+ GNUNET_assert (NULL !=
+ strstr (frac_name,
+ "_frac"));
+ GNUNET_assert (NULL !=
+ strstr (curr_name,
+ "_curr"));
+ /* Set return value to invalid in case we don't finish */
+ memset (r_amount_nbo,
+ 0,
+ sizeof (struct TALER_AmountNBO));
+ val_num = PQfnumber (result,
+ val_name);
+ frac_num = PQfnumber (result,
+ frac_name);
+ curr_num = PQfnumber (result,
+ curr_name);
+ if ( (val_num < 0) ||
+ (frac_num < 0) ||
+ (curr_num < 0) )
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if ( (PQgetisnull (result,
+ row,
+ val_num)) ||
+ (PQgetisnull (result,
+ row,
+ frac_num)) ||
+ (PQgetisnull (result,
+ row,
+ curr_num)) )
+ {
+ GNUNET_break (0);
+ return GNUNET_NO;
+ }
+ /* Note that Postgres stores value in NBO internally,
+ so no conversion needed in this case */
+ r_amount_nbo->value = *(uint64_t *) PQgetvalue (result,
+ row,
+ val_num);
+ r_amount_nbo->fraction = *(uint32_t *) PQgetvalue (result,
+ row,
+ frac_num);
+ len = GNUNET_MIN (TALER_CURRENCY_LEN - 1,
+ PQgetlength (result,
+ row,
+ curr_num));
+ memcpy (r_amount_nbo->currency,
+ PQgetvalue (result,
+ row,
+ curr_num),
+ len);
+ return GNUNET_OK;
+}
+
+
+/**
+ * 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_NO if at least one result was NULL
+ * #GNUNET_SYSERR if a result was invalid (non-existing field)
+ */
+static int
+extract_amount_nbo (void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
+{
+ char *val_name;
+ char *frac_name;
+ char *curr_name;
+ int ret;
+
+ GNUNET_asprintf (&val_name,
+ "%s_val",
+ fname);
+ GNUNET_asprintf (&frac_name,
+ "%s_frac",
+ fname);
+ GNUNET_asprintf (&curr_name,
+ "%s_curr",
+ fname);
+ ret = extract_amount_nbo_helper (result,
+ row,
+ val_name,
+ frac_name,
+ curr_name,
+ dst);
+ GNUNET_free (val_name);
+ GNUNET_free (frac_name);
+ GNUNET_free (curr_name);
+ return ret;
+}
+
+
+/**
+ * Currency amount expected.
+ *
+ * @param name name of the field in the table
+ * @param[out] amount where to store the result
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_amount_nbo (const char *name,
+ struct TALER_AmountNBO *amount)
+{
+ struct GNUNET_PQ_ResultSpec res =
+ { &extract_amount_nbo, NULL, NULL,
+ (void *) amount, sizeof (*amount),
+ name, NULL };
+ return res;
+}
+
+
+/**
+ * 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_NO if at least one result was NULL
+ * #GNUNET_SYSERR if a result was invalid (non-existing field)
+ */
+static int
+extract_amount (void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
+{
+ struct TALER_Amount *r_amount = dst;
+ char *val_name;
+ char *frac_name;
+ char *curr_name;
+ struct TALER_AmountNBO amount_nbo;
+ int ret;
+
+ GNUNET_asprintf (&val_name,
+ "%s_val",
+ fname);
+ GNUNET_asprintf (&frac_name,
+ "%s_frac",
+ fname);
+ GNUNET_asprintf (&curr_name,
+ "%s_curr",
+ fname);
+ ret = extract_amount_nbo_helper (result,
+ row,
+ val_name,
+ frac_name,
+ curr_name,
+ &amount_nbo);
+ TALER_amount_ntoh (r_amount,
+ &amount_nbo);
+ GNUNET_free (val_name);
+ GNUNET_free (frac_name);
+ GNUNET_free (curr_name);
+ return ret;
+}
+
+
+/**
+ * Currency amount expected.
+ *
+ * @param name name of the field in the table
+ * @param[out] amount where to store the result
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_amount (const char *name,
+ struct TALER_Amount *amount)
+{
+ struct GNUNET_PQ_ResultSpec res =
+ { &extract_amount, NULL, NULL,
+ (void *) amount, sizeof (*amount),
+ name, NULL };
+ return res;
+}
+
+
+/**
+ * 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_NO if at least one result was NULL
+ * #GNUNET_SYSERR if a result was invalid (non-existing field)
+ */
+static int
+extract_json (void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
+{
+ json_t **j_dst = dst;
+ const char *res;
+ int fnum;
+ json_error_t json_error;
+ size_t slen;
+
+ fnum = PQfnumber (result,
+ fname);
+ if (fnum < 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Field `%s' does not exist in result\n",
+ fname);
+ return GNUNET_SYSERR;
+ }
+ if (PQgetisnull (result,
+ row,
+ fnum))
+ return GNUNET_NO;
+ slen = PQgetlength (result,
+ row,
+ fnum);
+ res = (const char *) PQgetvalue (result,
+ row,
+ fnum);
+ *j_dst = json_loadb (res,
+ slen,
+ JSON_REJECT_DUPLICATES,
+ &json_error);
+ if (NULL == *j_dst)
+ {
+ TALER_json_warn (json_error);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to parse JSON result for field `%s'\n",
+ fname);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called to clean up memory allocated
+ * by a #GNUNET_PQ_ResultConverter.
+ *
+ * @param cls closure
+ * @param rd result data to clean up
+ */
+static void
+clean_json (void *cls,
+ void *rd)
+{
+ json_t **dst = rd;
+
+ if (NULL != *dst)
+ {
+ json_decref (*dst);
+ *dst = NULL;
+ }
+}
+
+
+/**
+ * json_t expected.
+ *
+ * @param name name of the field in the table
+ * @param[out] jp where to store the result
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_json (const char *name,
+ json_t **jp)
+{
+ struct GNUNET_PQ_ResultSpec res =
+ { &extract_json, &clean_json, NULL,
+ (void *) jp, 0,
+ name, NULL };
+ return res;
+}
+
+/* end of pq_result_helper.c */
diff --git a/src/pq/test_pq.c b/src/pq/test_pq.c
index f0413d1ff..95cfb715d 100644
--- a/src/pq/test_pq.c
+++ b/src/pq/test_pq.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2015 GNUnet e.V.
+ (C) 2015, 2016 GNUnet e.V.
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
@@ -48,47 +48,27 @@ postgres_prepare (PGconn *db_conn)
PREPARE ("test_insert",
"INSERT INTO test_pq ("
- " pub"
- ",sig"
- ",abs_time"
- ",forever"
- ",hash"
- ",hamount_val"
+ " hamount_val"
",hamount_frac"
",hamount_curr"
",namount_val"
",namount_frac"
",namount_curr"
- ",vsize"
- ",u16"
- ",u32"
- ",u64"
",json"
") VALUES "
"($1, $2, $3, $4, $5, $6,"
- "$7, $8, $9, $10, $11, $12, $13, $14, $15, $16);",
- 16, NULL);
+ "$7);",
+ 7, NULL);
PREPARE ("test_select",
"SELECT"
- " pub"
- ",sig"
- ",abs_time"
- ",forever"
- ",hash"
- ",hamount_val"
+ " hamount_val"
",hamount_frac"
",hamount_curr"
",namount_val"
",namount_frac"
",namount_curr"
- ",vsize"
- ",u16"
- ",u32"
- ",u64"
",json"
- " FROM test_pq"
- " ORDER BY abs_time DESC "
- " LIMIT 1;",
+ " FROM test_pq;",
0, NULL);
return GNUNET_OK;
#undef PREPARE
@@ -103,40 +83,15 @@ postgres_prepare (PGconn *db_conn)
static int
run_queries (PGconn *conn)
{
- struct GNUNET_CRYPTO_rsa_PublicKey *pub;
- struct GNUNET_CRYPTO_rsa_PublicKey *pub2 = NULL;
- struct GNUNET_CRYPTO_rsa_Signature *sig;
- struct GNUNET_CRYPTO_rsa_Signature *sig2 = NULL;
- struct GNUNET_TIME_Absolute abs_time = GNUNET_TIME_absolute_get ();
- struct GNUNET_TIME_Absolute abs_time2;
- struct GNUNET_TIME_Absolute forever = GNUNET_TIME_UNIT_FOREVER_ABS;
- struct GNUNET_TIME_Absolute forever2;
- struct GNUNET_HashCode hc;
- struct GNUNET_HashCode hc2;
struct TALER_Amount hamount;
struct TALER_Amount hamount2;
struct TALER_AmountNBO namount;
struct TALER_AmountNBO namount2;
PGresult *result;
int ret;
- struct GNUNET_CRYPTO_rsa_PrivateKey *priv;
- char msg[] = "Hello";
- void *msg2;
- size_t msg2_len;
- uint16_t u16;
- uint16_t u162;
- uint32_t u32;
- uint32_t u322;
- uint64_t u64;
- uint64_t u642;
json_t *json;
json_t *json2;
- priv = GNUNET_CRYPTO_rsa_private_key_create (1024);
- pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv);
- sig = GNUNET_CRYPTO_rsa_sign (priv,
- msg,
- sizeof (msg));
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount ("EUR:5.5",
&hamount));
@@ -145,87 +100,53 @@ run_queries (PGconn *conn)
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount ("EUR:4.4",
&hamount));
- u16 = 16;
- u32 = 32;
- u64 = 64;
json = json_object ();
json_object_set (json, "foo", json_integer (42));
GNUNET_assert (NULL != json);
- /* FIXME: test TALER_PQ_result_spec_variable_size */
+ /* FIXME: test GNUNET_PQ_result_spec_variable_size */
{
- struct TALER_PQ_QueryParam params_insert[] = {
- TALER_PQ_query_param_rsa_public_key (pub),
- TALER_PQ_query_param_rsa_signature (sig),
- TALER_PQ_query_param_absolute_time (&abs_time),
- TALER_PQ_query_param_absolute_time (&forever),
- TALER_PQ_query_param_auto_from_type (&hc),
+ struct GNUNET_PQ_QueryParam params_insert[] = {
TALER_PQ_query_param_amount (&hamount),
TALER_PQ_query_param_amount_nbo (&namount),
- TALER_PQ_query_param_fixed_size (msg, strlen (msg)),
- TALER_PQ_query_param_uint16 (&u16),
- TALER_PQ_query_param_uint32 (&u32),
- TALER_PQ_query_param_uint64 (&u64),
TALER_PQ_query_param_json (json),
- TALER_PQ_query_param_end
+ GNUNET_PQ_query_param_end
};
- struct TALER_PQ_QueryParam params_select[] = {
- TALER_PQ_query_param_end
+ struct GNUNET_PQ_QueryParam params_select[] = {
+ GNUNET_PQ_query_param_end
};
- struct TALER_PQ_ResultSpec results_select[] = {
- TALER_PQ_result_spec_rsa_public_key ("pub", &pub2),
- TALER_PQ_result_spec_rsa_signature ("sig", &sig2),
- TALER_PQ_result_spec_absolute_time ("abs_time", &abs_time2),
- TALER_PQ_result_spec_absolute_time ("forever", &forever2),
- TALER_PQ_result_spec_auto_from_type ("hash", &hc2),
+ struct GNUNET_PQ_ResultSpec results_select[] = {
TALER_PQ_result_spec_amount ("hamount", &hamount2),
TALER_PQ_result_spec_amount_nbo ("namount", &namount2),
- TALER_PQ_result_spec_variable_size ("vsize", &msg2, &msg2_len),
- TALER_PQ_result_spec_uint16 ("u16", &u162),
- TALER_PQ_result_spec_uint32 ("u32", &u322),
- TALER_PQ_result_spec_uint64 ("u64", &u642),
TALER_PQ_result_spec_json ("json", &json2),
- TALER_PQ_result_spec_end
+ GNUNET_PQ_result_spec_end
};
- result = TALER_PQ_exec_prepared (conn,
- "test_insert",
- params_insert);
+ result = GNUNET_PQ_exec_prepared (conn,
+ "test_insert",
+ params_insert);
if (PGRES_COMMAND_OK != PQresultStatus (result))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Database failure: %s\n",
PQresultErrorMessage (result));
PQclear (result);
- GNUNET_CRYPTO_rsa_signature_free (sig);
- GNUNET_CRYPTO_rsa_private_key_free (priv);
- GNUNET_CRYPTO_rsa_public_key_free (pub);
return 1;
}
PQclear (result);
- result = TALER_PQ_exec_prepared (conn,
- "test_select",
- params_select);
+ result = GNUNET_PQ_exec_prepared (conn,
+ "test_select",
+ params_select);
if (1 !=
PQntuples (result))
{
GNUNET_break (0);
PQclear (result);
- GNUNET_CRYPTO_rsa_signature_free (sig);
- GNUNET_CRYPTO_rsa_private_key_free (priv);
- GNUNET_CRYPTO_rsa_public_key_free (pub);
return 1;
}
- ret = TALER_PQ_extract_result (result,
- results_select,
- 0);
- GNUNET_break (GNUNET_YES == ret);
- GNUNET_break (abs_time.abs_value_us == abs_time2.abs_value_us);
- GNUNET_break (forever.abs_value_us == forever2.abs_value_us);
- GNUNET_break (0 ==
- memcmp (&hc,
- &hc2,
- sizeof (struct GNUNET_HashCode)));
+ ret = GNUNET_PQ_extract_result (result,
+ results_select,
+ 0);
GNUNET_break (0 ==
TALER_amount_cmp (&hamount,
&hamount2));
@@ -237,28 +158,11 @@ run_queries (PGconn *conn)
GNUNET_break (0 ==
TALER_amount_cmp (&hamount,
&hamount2));
- GNUNET_break (0 ==
- GNUNET_CRYPTO_rsa_signature_cmp (sig,
- sig2));
- GNUNET_break (0 ==
- GNUNET_CRYPTO_rsa_public_key_cmp (pub,
- pub2));
- GNUNET_break (strlen (msg) == msg2_len);
- GNUNET_break (0 ==
- strncmp (msg,
- msg2,
- msg2_len));
- GNUNET_break (16 == u162);
- GNUNET_break (32 == u322);
- GNUNET_break (64 == u642);
GNUNET_break (42 == json_integer_value (json_object_get (json2, "foo")));
json_decref (json2);
- TALER_PQ_cleanup_result (results_select);
+ GNUNET_PQ_cleanup_result (results_select);
PQclear (result);
}
- GNUNET_CRYPTO_rsa_signature_free (sig);
- GNUNET_CRYPTO_rsa_private_key_free (priv);
- GNUNET_CRYPTO_rsa_public_key_free (pub);
if (GNUNET_OK != ret)
return 1;
@@ -290,21 +194,12 @@ main(int argc,
result = PQexec (conn,
"CREATE TEMPORARY TABLE IF NOT EXISTS test_pq ("
- " pub BYTEA NOT NULL"
- ",sig BYTEA NOT NULL"
- ",abs_time INT8 NOT NULL"
- ",forever INT8 NOT NULL"
- ",hash BYTEA NOT NULL CHECK(LENGTH(hash)=64)"
- ",hamount_val INT8 NOT NULL"
+ " hamount_val INT8 NOT NULL"
",hamount_frac INT4 NOT NULL"
",hamount_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
",namount_val INT8 NOT NULL"
",namount_frac INT4 NOT NULL"
",namount_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
- ",vsize VARCHAR NOT NULL"
- ",u16 INT2 NOT NULL"
- ",u32 INT4 NOT NULL"
- ",u64 INT8 NOT NULL"
",json VARCHAR NOT NULL"
")");
if (PGRES_COMMAND_OK != PQresultStatus (result))