From e0d46f96859b33b3f04791028e30bce4f0173567 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 18 Jan 2024 12:08:53 +0100 Subject: auditordb tabularasa --- src/pq/pq_common.h | 15 +++++++++++++++ src/pq/pq_result_helper.c | 41 +++++++++++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 10 deletions(-) (limited to 'src/pq') diff --git a/src/pq/pq_common.h b/src/pq/pq_common.h index 1562646ff..3248778a0 100644 --- a/src/pq/pq_common.h +++ b/src/pq/pq_common.h @@ -76,6 +76,21 @@ struct TALER_PQ_AmountP } __attribute__((packed)); +/** + * Memory representation of an taler amount record for Postgres. + * + * All values need to be in network-byte-order. + */ +struct TALER_PQ_AmountNullP +{ + uint32_t cnt; /* # elements in the tuple (== 2) */ + uint32_t oid_v; /* oid of .v */ + uint32_t sz_v; /* size of .v */ + uint32_t oid_f; /* oid of .f */ + uint32_t sz_f; /* size of .f */ +} __attribute__((packed)); + + /** * Memory representation of an taler amount record with currency for Postgres. * diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c index 915aad144..e81c78302 100644 --- a/src/pq/pq_result_helper.c +++ b/src/pq/pq_result_helper.c @@ -229,6 +229,30 @@ extract_amount_tuple (void *cls, size = PQgetlength (result, row, col); + in = PQgetvalue (result, + row, + col); + if (sizeof(struct TALER_PQ_AmountNullP) == size) + { + struct TALER_PQ_AmountNullP apn; + + memcpy (&apn, + in, + size); + if ( (2 == ntohl (apn.cnt)) && + (-1 == (int32_t) ntohl (apn.sz_v)) && + (-1 == (int32_t) ntohl (apn.sz_f)) ) + { + /* is NULL! */ + return GNUNET_NO; + } + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Incorrect size of binary field `%s' and not NULL (got %zu, expected %zu)\n", + fname, + size, + sizeof(ap)); + return GNUNET_SYSERR; + } if (sizeof(ap) != size) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -239,9 +263,6 @@ extract_amount_tuple (void *cls, return GNUNET_SYSERR; } - in = PQgetvalue (result, - row, - col); memcpy (&ap, in, size); @@ -1141,13 +1162,13 @@ extract_array_generic ( *((void **) dst) = NULL; #define FAIL_IF(cond) \ - do { \ - if ((cond)) \ - { \ - GNUNET_break (! (cond)); \ - goto FAIL; \ - } \ - } while (0) + do { \ + if ((cond)) \ + { \ + GNUNET_break (! (cond)); \ + goto FAIL; \ + } \ + } while (0) col_num = PQfnumber (result, fname); FAIL_IF (0 > col_num); -- cgit v1.2.3