donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit 447f6f550603b9c8d517e8af52f3a1e3836c566e
parent 11aea1a7977dceda58a1b8906f812e202dcbb055
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
Date:   Sat, 13 Apr 2024 01:02:02 +0200

[donaudb] some changes

Diffstat:
Msrc/donaudb/0002-donau_receipts_issued.sql | 4++--
Msrc/donaudb/pg_insert_issued_receipt.c | 28+++++++++++-----------------
Msrc/donaudb/pg_insert_issued_receipt.h | 3++-
Msrc/pq/pq_query_helper.c | 293++++++++++++++++++++++++++++++++++++++++---------------------------------------
4 files changed, 164 insertions(+), 164 deletions(-)

diff --git a/src/donaudb/0002-donau_receipts_issued.sql b/src/donaudb/0002-donau_receipts_issued.sql @@ -31,7 +31,7 @@ COMMENT ON COLUMN receipts_issued.receipt_hash CREATE FUNCTION transaction_save_issue_receipts_request( IN charity_id BIGINT -- charity id which made the issue receitps request - ,IN blinded_sig BYTEA[] -- blinded signatures + --,IN blinded_sig BYTEA[] -- blinded signatures ,IN receipt_hash BYTEA -- hash over all budi key pairs (primary key) ,IN amount taler_amount -- total amount of the requested receipts ,IN new_total_amount taler_amount -- new total amount of a charity @@ -43,7 +43,7 @@ BEGIN -- Update table charity UPDATE charity SET receipts_to_date = new_total_amount; -- Insert into the table receipts_issued -INSERT INTO receipts_issued (blinded_sig, charity_id, receipt_hash, amount) VALUES ('blinded_sig', 'charity_id', 'receipts_hash', 'amount'); +INSERT INTO receipts_issued (/*blinded_sig,*/ charity_id, receipt_hash, amount) VALUES (/*'blinded_sig',*/ 'charity_id', 'receipts_hash', 'amount'); -- Commit the transaction if everything is successful END $$; COMMIT; diff --git a/src/donaudb/pg_insert_issued_receipt.c b/src/donaudb/pg_insert_issued_receipt.c @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file donaudb/pg_insert_issed_receipt.c + * @file donaudb/pg_insert_issued_receipt.c * @brief Implementation of the insert_issued_receipt function for Postgres * @author Johannes Casaburi * @author Lukas Matyja @@ -33,22 +33,19 @@ enum GNUNET_DB_QueryStatus DH_PG_insert_issued_receipt (void *cls, const size_t num_blinded_sig, const struct - DONAU_BlindedDonationUnitSignature signatures[num_blinded_sig], + DONAU_BlindedDonationUnitSignature signatures[ + num_blinded_sig], const uint64_t charity_id, const struct DONAU_DonationReceiptHashP *h_receipt, const struct TALER_Amount *amount_receipts_request, const struct TALER_Amount *charity_new_amount) { struct PostgresClosure *pc = cls; - - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_end - }; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&charity_id), - DONAU_PQ_query_param_array_blinded_donation_unit_sig (num_blinded_sig, - signatures, pc->conn), + // DONAU_PQ_query_param_array_blinded_donation_unit_sig (num_blinded_sig, + // signatures, pc->conn), GNUNET_PQ_query_param_fixed_size (&h_receipt->hash, sizeof(struct DONAU_DonationReceiptHashP)), TALER_PQ_query_param_amount_with_currency (pc->conn, @@ -61,17 +58,14 @@ DH_PG_insert_issued_receipt (void *cls, PREPARE (pc, "insert_issued_receipts_request", - "SELECT" + "SELECT" " transaction_save_issue_receipts_request" - " ($1,$2,$3,$4,$5);"); - - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "pg: insert issued receipt. Number of paramameters: %ld\n", (sizeof(params) / sizeof(params[0]))); + " ($1,$2,$3,$4);"); - qs = GNUNET_PQ_eval_prepared_singleton_select (pc->conn, - "insert_issued_receipts_request", - params, - rs); + qs = GNUNET_PQ_eval_prepared_multi_select (pc->conn, + "insert_issued_receipts_request", + params, + NULL, NULL); GNUNET_PQ_cleanup_query_params_closures (params); return qs; } diff --git a/src/donaudb/pg_insert_issued_receipt.h b/src/donaudb/pg_insert_issued_receipt.h @@ -41,7 +41,8 @@ enum GNUNET_DB_QueryStatus DH_PG_insert_issued_receipt (void *cls, const size_t num_blinded_sig, const struct - DONAU_BlindedDonationUnitSignature signatures[num_blinded_sig], + DONAU_BlindedDonationUnitSignature signatures[ + num_blinded_sig], const uint64_t charity_id, const struct DONAU_DonationReceiptHashP *h_receipt, const struct TALER_Amount *amount_receipts_request, diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c @@ -121,6 +121,7 @@ DONAU_PQ_query_param_donation_unit_pub ( return res; } + /** * Closure for the array result specifications. Contains type information * for the generic parser extract_array_generic and out-pointers for the results. @@ -135,7 +136,7 @@ struct ArrayResultCls /** * Target type */ - //enum TALER_PQ_ArrayType typ; + // enum TALER_PQ_ArrayType typ; /** * If not 0, defines the expected size of each entry @@ -196,7 +197,7 @@ struct qconv_array_cls /** * Type of the array elements */ - //enum TALER_PQ_ArrayType typ; + // enum TALER_PQ_ArrayType typ; /** * Oid of the array elements @@ -337,44 +338,44 @@ qconv_array ( // } // case TALER_PQ_array_of_blinded_denom_sig: // { - const struct DONAU_BlindedDonationUnitSignature *du_sigs = data; - size_t len; - - buffers = GNUNET_new_array (num, void *); - buffer_lengths = GNUNET_new_array (num, size_t); - - for (size_t i = 0; i<num; i++) - { - const struct GNUNET_CRYPTO_BlindedSignature *bs = - du_sigs[i].blinded_sig; - - switch (bs->cipher) - { - case GNUNET_CRYPTO_BSA_RSA: - len = GNUNET_CRYPTO_rsa_signature_encode ( - bs->details.blinded_rsa_signature, - &buffers[i]); - RETURN_UNLESS (len != 0); - break; - case GNUNET_CRYPTO_BSA_CS: - len = sizeof (bs->details.blinded_cs_answer); - break; - default: - //FIXME (set to zero) - GNUNET_assert (1); - len = 0; - break; - } - - /* for the cipher and marker */ - len += 2 * sizeof(uint32_t); - buffer_lengths[i] = len; - - y = total_size; - total_size += len; - RETURN_UNLESS (total_size >= y); - } - sizes = buffer_lengths; + const struct DONAU_BlindedDonationUnitSignature *du_sigs = data; + size_t len; + + buffers = GNUNET_new_array (num, void *); + buffer_lengths = GNUNET_new_array (num, size_t); + + for (size_t i = 0; i<num; i++) + { + const struct GNUNET_CRYPTO_BlindedSignature *bs = + du_sigs[i].blinded_sig; + + switch (bs->cipher) + { + case GNUNET_CRYPTO_BSA_RSA: + len = GNUNET_CRYPTO_rsa_signature_encode ( + bs->details.blinded_rsa_signature, + &buffers[i]); + RETURN_UNLESS (len != 0); + break; + case GNUNET_CRYPTO_BSA_CS: + len = sizeof (bs->details.blinded_cs_answer); + break; + default: + // FIXME (set to zero) + GNUNET_assert (1); + len = 0; + break; + } + + /* for the cipher and marker */ + len += 2 * sizeof(uint32_t); + buffer_lengths[i] = len; + + y = total_size; + total_size += len; + RETURN_UNLESS (total_size >= y); + } + sizes = buffer_lengths; // break; // } // default: @@ -387,7 +388,7 @@ qconv_array ( elements = GNUNET_malloc (total_size); } - + /* Write data */ { char *out = elements; @@ -480,37 +481,37 @@ qconv_array ( // } // case TALER_PQ_array_of_blinded_denom_sig: // { - const struct DONAU_BlindedDonationUnitSignature *denom_sigs = data; - const struct GNUNET_CRYPTO_BlindedSignature *bs = - denom_sigs[i].blinded_sig; - uint32_t be[2]; - - be[0] = htonl ((uint32_t) bs->cipher); - be[1] = htonl (0x01); /* magic margker: blinded */ - GNUNET_memcpy (out, - &be, - sizeof(be)); - out += sizeof(be); - sz -= sizeof(be); - - switch (bs->cipher) - { - case GNUNET_CRYPTO_BSA_RSA: - /* For RSA, 'same_sized' must have been false */ - GNUNET_assert (NULL != buffers); - GNUNET_memcpy (out, - buffers[i], - sz); - break; - case GNUNET_CRYPTO_BSA_CS: - GNUNET_memcpy (out, - &bs->details.blinded_cs_answer, - sz); - break; - default: - //FIXME (set to zero) - GNUNET_assert (1); - } + const struct DONAU_BlindedDonationUnitSignature *denom_sigs = data; + const struct GNUNET_CRYPTO_BlindedSignature *bs = + denom_sigs[i].blinded_sig; + uint32_t be[2]; + + be[0] = htonl ((uint32_t) bs->cipher); + be[1] = htonl (0x01); /* magic margker: blinded */ + GNUNET_memcpy (out, + &be, + sizeof(be)); + out += sizeof(be); + sz -= sizeof(be); + + switch (bs->cipher) + { + case GNUNET_CRYPTO_BSA_RSA: + /* For RSA, 'same_sized' must have been false */ + GNUNET_assert (NULL != buffers); + GNUNET_memcpy (out, + buffers[i], + sz); + break; + case GNUNET_CRYPTO_BSA_CS: + GNUNET_memcpy (out, + &bs->details.blinded_cs_answer, + sz); + break; + default: + // FIXME (set to zero) + GNUNET_assert (1); + } // break; // } // case TALER_PQ_array_of_blinded_coin_hash: @@ -579,6 +580,7 @@ qconv_array_cls_cleanup (void *cls) GNUNET_free (cls); } + /** * Function to generate a typ specific query parameter and corresponding closure * @@ -599,13 +601,13 @@ query_param_array_generic ( const void *elements, const size_t *sizes, size_t same_size, - //enum TALER_PQ_ArrayType typ, + // enum TALER_PQ_ArrayType typ, Oid oid, struct GNUNET_PQ_Context *db) { struct qconv_array_cls *meta = GNUNET_new (struct qconv_array_cls); - //meta->typ = typ; + // meta->typ = typ; meta->oid = oid; meta->sizes = sizes; meta->same_size = same_size; @@ -626,6 +628,7 @@ query_param_array_generic ( } } + struct GNUNET_PQ_QueryParam DONAU_PQ_query_param_array_blinded_donation_unit_sig ( size_t num, @@ -643,11 +646,12 @@ DONAU_PQ_query_param_array_blinded_donation_unit_sig ( du_sigs, NULL, 0, - //TALER_PQ_array_of_blinded_du_sig, + // TALER_PQ_array_of_blinded_du_sig, oid, NULL); } + /** * Extract data from a Postgres database @a result as array of a specific type * from row @a row. The type information and optionally additional @@ -675,7 +679,7 @@ extract_array_generic ( const struct ArrayResultCls *info = cls; int data_sz; char *data; - //void *out = NULL; + // void *out = NULL; struct GNUNET_PQ_ArrayHeader_P header; int col_num; @@ -841,74 +845,74 @@ extract_array_generic ( // case TALER_PQ_array_of_blinded_denom_sig: // { - struct DONAU_BlindedDonationUnitSignature *du_sigs; - if (0 == header.dim) - { - if (NULL != dst_size) - *dst_size = 0; - goto FAIL; - } + struct DONAU_BlindedDonationUnitSignature *du_sigs; + if (0 == header.dim) + { + if (NULL != dst_size) + *dst_size = 0; + goto FAIL; + } - du_sigs = GNUNET_new_array (header.dim, - struct DONAU_BlindedDonationUnitSignature); - *((void **) dst) = du_sigs; + du_sigs = GNUNET_new_array (header.dim, + struct DONAU_BlindedDonationUnitSignature); + *((void **) dst) = du_sigs; - /* copy data */ - for (uint32_t i = 0; i < header.dim; i++) + /* copy data */ + for (uint32_t i = 0; i < header.dim; i++) + { + struct DONAU_BlindedDonationUnitSignature *du_sig = &du_sigs[i]; + struct GNUNET_CRYPTO_BlindedSignature *bs; + uint32_t be[2]; + uint32_t val; + size_t sz; + + GNUNET_memcpy (&val, + in, + sizeof(val)); + sz = ntohl (val); + FAIL_IF (sizeof(be) > sz); + + in += sizeof(val); + GNUNET_memcpy (&be, + in, + sizeof(be)); + FAIL_IF (0x01 != ntohl (be[1])); /* magic marker: blinded */ + + in += sizeof(be); + sz -= sizeof(be); + bs = GNUNET_new (struct GNUNET_CRYPTO_BlindedSignature); + bs->cipher = ntohl (be[0]); + bs->rc = 1; + switch (bs->cipher) + { + case GNUNET_CRYPTO_BSA_RSA: + bs->details.blinded_rsa_signature + = GNUNET_CRYPTO_rsa_signature_decode (in, + sz); + if (NULL == bs->details.blinded_rsa_signature) + { + GNUNET_free (bs); + FAIL_IF (true); + } + break; + case GNUNET_CRYPTO_BSA_CS: + if (sizeof(bs->details.blinded_cs_answer) != sz) { - struct DONAU_BlindedDonationUnitSignature *du_sig = &du_sigs[i]; - struct GNUNET_CRYPTO_BlindedSignature *bs; - uint32_t be[2]; - uint32_t val; - size_t sz; - - GNUNET_memcpy (&val, - in, - sizeof(val)); - sz = ntohl (val); - FAIL_IF (sizeof(be) > sz); - - in += sizeof(val); - GNUNET_memcpy (&be, - in, - sizeof(be)); - FAIL_IF (0x01 != ntohl (be[1])); /* magic marker: blinded */ - - in += sizeof(be); - sz -= sizeof(be); - bs = GNUNET_new (struct GNUNET_CRYPTO_BlindedSignature); - bs->cipher = ntohl (be[0]); - bs->rc = 1; - switch (bs->cipher) - { - case GNUNET_CRYPTO_BSA_RSA: - bs->details.blinded_rsa_signature - = GNUNET_CRYPTO_rsa_signature_decode (in, - sz); - if (NULL == bs->details.blinded_rsa_signature) - { - GNUNET_free (bs); - FAIL_IF (true); - } - break; - case GNUNET_CRYPTO_BSA_CS: - if (sizeof(bs->details.blinded_cs_answer) != sz) - { - GNUNET_free (bs); - FAIL_IF (true); - } - GNUNET_memcpy (&bs->details.blinded_cs_answer, - in, - sz); - break; - default: - GNUNET_free (bs); - FAIL_IF (true); - } - du_sig->blinded_sig = bs; - in += sz; + GNUNET_free (bs); + FAIL_IF (true); } - return GNUNET_OK; + GNUNET_memcpy (&bs->details.blinded_cs_answer, + in, + sz); + break; + default: + GNUNET_free (bs); + FAIL_IF (true); + } + du_sig->blinded_sig = bs; + in += sz; + } + return GNUNET_OK; // } // default: // FAIL_IF (true); @@ -938,10 +942,10 @@ array_cleanup (void *cls, /* Clean up signatures, if applicable */ // if (TALER_PQ_array_of_blinded_denom_sig == info->typ) // { - struct DONAU_BlindedDonationUnitSignature *du_sigs = *dst; - GNUNET_assert (NULL != info->num); - for (size_t i = 0; i < *info->num; i++) - GNUNET_free (du_sigs[i].blinded_sig); + struct DONAU_BlindedDonationUnitSignature *du_sigs = *dst; + GNUNET_assert (NULL != info->num); + for (size_t i = 0; i < *info->num; i++) + GNUNET_free (du_sigs[i].blinded_sig); // } GNUNET_free (cls); @@ -977,4 +981,5 @@ DONAU_PQ_result_spec_array_blinded_donation_unit_sig ( } + /* end of pq/pq_query_helper.c */