aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/taler_pq_lib.h57
-rw-r--r--src/mintdb/plugin_mintdb_postgres.c60
-rw-r--r--src/pq/db_pq.c4
3 files changed, 70 insertions, 51 deletions
diff --git a/src/include/taler_pq_lib.h b/src/include/taler_pq_lib.h
index d90b5f7aa..148385c8b 100644
--- a/src/include/taler_pq_lib.h
+++ b/src/include/taler_pq_lib.h
@@ -262,7 +262,7 @@ struct TALER_PQ_ResultSpec
/**
* Field name of the desired result.
*/
- char *fname;
+ const char *fname;
/**
* Where to store actual size of the result.
@@ -274,6 +274,8 @@ struct TALER_PQ_ResultSpec
/**
* 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 }
@@ -283,6 +285,7 @@ struct TALER_PQ_ResultSpec
* @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_SIZED(name, dst, s) { TALER_PQ_RF_FIXED_BLOB, (void *) (dst), (s), (name), NULL }
@@ -292,6 +295,7 @@ struct TALER_PQ_ResultSpec
*
* @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(name, dst) { TALER_PQ_RF_VARSIZE_BLOB, (void *) dst, sizeof (*(dst)), name, NULL }
@@ -300,53 +304,74 @@ struct TALER_PQ_ResultSpec
* Variable-size result expected.
*
* @param name name of the field in the table
- * @param dst where to store the result (of type void **), to be allocated
- * @param sptr pointer to a `size_t` for where to store the size of @a dst
+ * @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
*/
-#define TALER_PQ_RESULT_SPEC_VAR(name, dst, sptr) {TALER_PQ_RF_VARSIZE_BLOB, (void *) (dst), 0, (name), sptr }
+struct TALER_PQ_ResultSpec
+TALER_PQ_RESULT_SPEC_VAR (const char *name,
+ void **dst,
+ size_t *sptr);
/**
* Currency amount expected.
*
* @param name name of the field in the table
- * @param amount a `struct TALER_AmountNBO` where to store the result
+ * @param[out] amount where to store the result
+ * @return array entry for the result specification to use
*/
-#define TALER_PQ_RESULT_SPEC_AMOUNT_NBO(name, amount) {TALER_PQ_RF_AMOUNT_NBO, (void *) (&amount), sizeof (amount), (name), NULL }
+struct TALER_PQ_ResultSpec
+TALER_PQ_RESULT_SPEC_AMOUNT_NBO (const char *name,
+ struct TALER_AmountNBO *amount);
+
/**
* Currency amount expected.
*
* @param name name of the field in the table
- * @param amount a `struct TALER_Amount` where to store the result
+ * @param[out] amount where to store the result
+ * @return array entry for the result specification to use
*/
-#define TALER_PQ_RESULT_SPEC_AMOUNT(name, amount) {TALER_PQ_RF_AMOUNT, (void *) (&amount), sizeof (amount), (name), NULL }
+struct TALER_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 rsa a `struct GNUNET_CRYPTO_rsa_PublicKey *` where to store the result;
- * the R-value must be NULL at the time of the call
+ * @param[out] rsa where to store the result
+ * @return array entry for the result specification to use
*/
-#define TALER_PQ_RESULT_SPEC_RSA_PUBLIC_KEY(name, rsa) {TALER_PQ_RF_RSA_PUBLIC_KEY, (void *) &(rsa), 0, (name), NULL }
+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 sig a `struct GNUNET_CRYPTO_rsa_Signature *` where to store the result;
- * the R-value must be NULL at the time of the call
+ * @param[out] sig where to store the result;
+ * @return array entry for the result specification to use
*/
-#define TALER_PQ_RESULT_SPEC_RSA_SIGNATURE(name, sig) {TALER_PQ_RF_RSA_SIGNATURE, (void *) &(sig), 0, (name), NULL }
+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 at a `struct GNUNET_TIME_Absolute` where to store the result
+ * @param[out] at where to store the result
+ * @return array entry for the result specification to use
*/
-#define TALER_PQ_RESULT_SPEC_ABSOLUTE_TIME(name,at) {TALER_PQ_RF_TIME_ABSOLUTE, (void *) (&at), sizeof (at), (name), NULL }
+struct TALER_PQ_ResultSpec
+TALER_PQ_RESULT_SPEC_ABSOLUTE_TIME (const char *name,
+ struct GNUNET_TIME_Absolute *at);
/**
diff --git a/src/mintdb/plugin_mintdb_postgres.c b/src/mintdb/plugin_mintdb_postgres.c
index b49995155..8ed374f03 100644
--- a/src/mintdb/plugin_mintdb_postgres.c
+++ b/src/mintdb/plugin_mintdb_postgres.c
@@ -894,8 +894,8 @@ postgres_reserve_get (void *cls,
TALER_PQ_QUERY_PARAM_END
};
struct TALER_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_AMOUNT("current_balance", &reserve->balance),
+ TALER_PQ_RESULT_SPEC_ABSOLUTE_TIME("expiration_date", &reserve->expiry),
TALER_PQ_RESULT_SPEC_END
};
@@ -1116,8 +1116,8 @@ postgres_get_collectable_blindcoin (void *cls,
TALER_PQ_QUERY_PARAM_PTR (h_blind),
TALER_PQ_QUERY_PARAM_END
};
- struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub = NULL;
- struct GNUNET_CRYPTO_rsa_Signature *denom_sig = NULL;
+ struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub;
+ struct GNUNET_CRYPTO_rsa_Signature *denom_sig;
int ret;
ret = GNUNET_SYSERR;
@@ -1136,8 +1136,8 @@ postgres_get_collectable_blindcoin (void *cls,
goto cleanup;
}
struct TALER_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_RSA_PUBLIC_KEY("denom_pub", denom_pub),
- TALER_PQ_RESULT_SPEC_RSA_SIGNATURE("denom_sig", denom_sig),
+ TALER_PQ_RESULT_SPEC_RSA_PUBLIC_KEY("denom_pub", &denom_pub),
+ TALER_PQ_RESULT_SPEC_RSA_SIGNATURE("denom_sig", &denom_sig),
TALER_PQ_RESULT_SPEC("reserve_sig", &collectable->reserve_sig),
TALER_PQ_RESULT_SPEC("reserve_pub", &collectable->reserve_pub),
TALER_PQ_RESULT_SPEC_END
@@ -1155,12 +1155,7 @@ postgres_get_collectable_blindcoin (void *cls,
cleanup:
PQclear (result);
if (GNUNET_YES != ret)
- {
- if (NULL != denom_pub)
- GNUNET_CRYPTO_rsa_public_key_free (denom_pub);
- if (NULL != denom_sig)
- GNUNET_CRYPTO_rsa_signature_free (denom_sig);
- }
+ TALER_PQ_cleanup_result (rs);
return ret;
}
@@ -1344,8 +1339,8 @@ postgres_get_reserve_history (void *cls,
}
struct TALER_PQ_ResultSpec rs[] = {
TALER_PQ_RESULT_SPEC ("blind_ev", &blind_ev),
- TALER_PQ_RESULT_SPEC_RSA_PUBLIC_KEY ("denom_pub", denom_pub),
- TALER_PQ_RESULT_SPEC_RSA_SIGNATURE ("denom_sig", denom_sig),
+ TALER_PQ_RESULT_SPEC_RSA_PUBLIC_KEY ("denom_pub", &denom_pub),
+ TALER_PQ_RESULT_SPEC_RSA_SIGNATURE ("denom_sig", &denom_sig),
TALER_PQ_RESULT_SPEC ("reserve_sig", &reserve_sig),
TALER_PQ_RESULT_SPEC_END
};
@@ -1354,9 +1349,8 @@ postgres_get_reserve_history (void *cls,
GNUNET_assert (NULL == rh_head->next);
while (0 < rows)
{
- denom_sig = NULL;
- denom_pub = NULL;
- if (GNUNET_YES != TALER_PQ_extract_result (result, rs, --rows))
+ if (GNUNET_YES !=
+ TALER_PQ_extract_result (result, rs, --rows))
{
GNUNET_break (0);
goto cleanup;
@@ -1799,7 +1793,7 @@ 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", denom_pubs->rsa_public_key),
+ TALER_PQ_RESULT_SPEC_RSA_PUBLIC_KEY ("denom_pub", &denom_pubs->rsa_public_key),
TALER_PQ_RESULT_SPEC_END
};
if (GNUNET_OK != TALER_PQ_extract_result (result, rs, 0))
@@ -1902,9 +1896,9 @@ postgres_get_refresh_commit_coins (void *cls,
TALER_PQ_QUERY_PARAM_PTR(&newcoin_index_nbo),
TALER_PQ_QUERY_PARAM_END
};
- char *c_buf;
+ void *c_buf;
size_t c_buf_size;
- char *rl_buf;
+ void *rl_buf;
size_t rl_buf_size;
struct TALER_RefreshLinkEncrypted *rl;
@@ -2204,14 +2198,14 @@ postgres_get_link_data_list (void *cls,
for (i = 0; i < PQntuples (result); i++)
{
struct TALER_RefreshLinkEncrypted *link_enc;
- struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub = NULL;
- struct GNUNET_CRYPTO_rsa_Signature *sig = NULL;
- char *ld_buf;
+ struct GNUNET_CRYPTO_rsa_PublicKey *denom_pub;
+ struct GNUNET_CRYPTO_rsa_Signature *sig;
+ void *ld_buf;
size_t ld_buf_size;
struct TALER_PQ_ResultSpec rs[] = {
TALER_PQ_RESULT_SPEC_VAR("link_vector_enc", &ld_buf, &ld_buf_size),
- TALER_PQ_RESULT_SPEC_RSA_PUBLIC_KEY("denom_pub", denom_pub),
- TALER_PQ_RESULT_SPEC_RSA_SIGNATURE("ev_sig", sig),
+ TALER_PQ_RESULT_SPEC_RSA_PUBLIC_KEY("denom_pub", &denom_pub),
+ TALER_PQ_RESULT_SPEC_RSA_SIGNATURE("ev_sig", &sig),
TALER_PQ_RESULT_SPEC_END
};
@@ -2355,7 +2349,7 @@ postgres_get_coin_transactions (void *cls,
TALER_PQ_QUERY_PARAM_END
};
json_error_t json_error;
- char *json_wire_enc;
+ void *json_wire_enc;
size_t json_wire_enc_size;
int i;
result = TALER_PQ_exec_prepared (session->conn,
@@ -2385,13 +2379,13 @@ postgres_get_coin_transactions (void *cls,
*/
TALER_PQ_RESULT_SPEC_END
};
- if ((GNUNET_OK != TALER_PQ_extract_result (result, rs, i))
- || (GNUNET_OK != TALER_PQ_extract_amount (result,
- i,
- "amount_val",
- "amount_frac",
- "amount_curr",
- &deposit->amount_with_fee)))
+ if ((GNUNET_OK != TALER_PQ_extract_result (result, rs, i)) ||
+ (GNUNET_OK != TALER_PQ_extract_amount (result,
+ i,
+ "amount_val",
+ "amount_frac",
+ "amount_curr",
+ &deposit->amount_with_fee)))
{
GNUNET_break (0);
goto cleanup_deposit;
diff --git a/src/pq/db_pq.c b/src/pq/db_pq.c
index 74126750b..72a9370ed 100644
--- a/src/pq/db_pq.c
+++ b/src/pq/db_pq.c
@@ -415,7 +415,7 @@ TALER_PQ_extract_result (PGresult *result,
const char *res;
int fnum;
- GNUNET_break (NULL == *pk);
+ *pk = NULL;
fnum = PQfnumber (result,
spec->fname);
if (fnum < 0)
@@ -459,7 +459,7 @@ TALER_PQ_extract_result (PGresult *result,
const char *res;
int fnum;
- GNUNET_break (NULL == *sig);
+ *sig = NULL;
fnum = PQfnumber (result,
spec->fname);
if (fnum < 0)