pq_common.h (4501B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2023 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 TALER is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 /** 17 * @file pq/pq_common.h 18 * @brief common defines for the pq functions 19 * @author Özgür Kesim 20 */ 21 #ifndef TALER_PQ_COMMON_H_ 22 #define TALER_PQ_COMMON_H_ 23 24 #include "taler/taler_util.h" 25 26 /** 27 * Internal types that are supported as TALER-exchange-specific array types. 28 * 29 * To support a new type, 30 * 1. add a new entry into this list, 31 * 2. for query-support, implement the size calculation and memory copying in 32 * qconv_array() accordingly, in pq_query_helper.c 33 * 3. provide a query-API for arrays of the type, by calling 34 * query_param_array_generic with the appropriate parameters, 35 * in pq_query_helper.c 36 * 4. for result-support, implement memory copying by adding another case 37 * to extract_array_generic, in pq_result_helper.c 38 * 5. provide a result-spec-API for arrays of the type, 39 * in pq_result_helper.c 40 * 6. expose the API's in taler_pq_lib.h 41 */ 42 enum TALER_PQ_ArrayType 43 { 44 TALER_PQ_array_of_blinded_denom_sig, 45 /** 46 * Unblinded denomination signatures (`struct TALER_DenominationSignature`). 47 */ 48 TALER_PQ_array_of_denom_sig, 49 TALER_PQ_array_of_blinded_coin_hash, 50 TALER_PQ_array_of_denom_hash, 51 TALER_PQ_array_of_hash_code, 52 TALER_PQ_array_of_cs_r_pub, 53 /** 54 * Amounts *without* currency. 55 */ 56 TALER_PQ_array_of_amount, 57 /** 58 * Amounts *with* currency. 59 */ 60 TALER_PQ_array_of_amount_currency, 61 TALER_PQ_array_of_MAX, /* must be last */ 62 }; 63 64 65 /** 66 * Memory representation of an taler amount record for Postgres. 67 * 68 * All values need to be in network-byte-order. 69 */ 70 struct TALER_PQ_AmountP 71 { 72 uint32_t cnt; /* # elements in the tuple (== 2) */ 73 uint32_t oid_v; /* oid of .v */ 74 uint32_t sz_v; /* size of .v */ 75 uint64_t v; /* value */ 76 uint32_t oid_f; /* oid of .f */ 77 uint32_t sz_f; /* size of .f */ 78 uint32_t f; /* fraction */ 79 } __attribute__((packed)); 80 81 82 /** 83 * Memory representation of an taler amount record for Postgres. 84 * 85 * All values need to be in network-byte-order. 86 */ 87 struct TALER_PQ_AmountNullP 88 { 89 uint32_t cnt; /* # elements in the tuple (== 2) */ 90 uint32_t oid_v; /* oid of .v */ 91 uint32_t sz_v; /* size of .v */ 92 uint32_t oid_f; /* oid of .f */ 93 uint32_t sz_f; /* size of .f */ 94 } __attribute__((packed)); 95 96 97 /** 98 * Memory representation of an taler amount record with currency for Postgres. 99 * 100 * All values need to be in network-byte-order. 101 */ 102 struct TALER_PQ_AmountCurrencyP 103 { 104 uint32_t cnt; /* # elements in the tuple (== 3) */ 105 uint32_t oid_v; /* oid of .v */ 106 uint32_t sz_v; /* size of .v */ 107 uint64_t v; /* value */ 108 uint32_t oid_f; /* oid of .f */ 109 uint32_t sz_f; /* size of .f */ 110 uint32_t f; /* fraction */ 111 uint32_t oid_c; /* oid of .c */ 112 uint32_t sz_c; /* size of .c */ 113 uint8_t c[TALER_CURRENCY_LEN]; /* currency */ 114 } __attribute__((packed)); 115 116 117 /** 118 * Create a `struct TALER_PQ_AmountP` for initialization 119 * 120 * @param amount amount of type `struct TALER_Amount *` 121 * @param oid_v OID of the INT8 type in postgres 122 * @param oid_f OID of the INT4 type in postgres 123 */ 124 struct TALER_PQ_AmountP 125 TALER_PQ_make_taler_pq_amount_ ( 126 const struct TALER_Amount *amount, 127 uint32_t oid_v, 128 uint32_t oid_f); 129 130 131 /** 132 * Create a `struct TALER_PQ_AmountCurrencyP` for initialization 133 * 134 * @param amount amount of type `struct TALER_Amount *` 135 * @param oid_v OID of the INT8 type in postgres 136 * @param oid_f OID of the INT4 type in postgres 137 * @param oid_c OID of the TEXT type in postgres 138 * @param[out] rval set to encoded @a amount 139 * @return actual (useful) size of @a rval for Postgres 140 */ 141 size_t 142 TALER_PQ_make_taler_pq_amount_currency_ ( 143 const struct TALER_Amount *amount, 144 uint32_t oid_v, 145 uint32_t oid_f, 146 uint32_t oid_c, 147 struct TALER_PQ_AmountCurrencyP *rval); 148 149 150 #endif /* TALER_PQ_COMMON_H_ */ 151 /* end of pg/pq_common.h */