aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorÖzgür Kesim <oec-taler@kesim.org>2023-07-30 00:44:38 +0200
committerÖzgür Kesim <oec-taler@kesim.org>2023-07-30 00:44:38 +0200
commitf0db6d55d72d7985e5a8b1e5c4a874a415a1234f (patch)
tree0968563b6753b50d0500e70ad6292f70396f0726 /src
parentdd20aa14ea8d2a4fc4893a747156b84a7bd5ae63 (diff)
[pq] use GNUNET_PQ_get_oid_by_name consistently
Diffstat (limited to 'src')
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c6
-rw-r--r--src/include/taler_pq_lib.h37
-rw-r--r--src/pq/Makefile.am1
-rw-r--r--src/pq/pq_common.h8
-rw-r--r--src/pq/pq_composite_types.c57
-rw-r--r--src/pq/pq_query_helper.c100
-rw-r--r--src/pq/pq_result_helper.c33
-rw-r--r--src/pq/test_pq.c9
8 files changed, 94 insertions, 157 deletions
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index 4f8959ff1..503a699d3 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -779,12 +779,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
plugin->batch_ensure_coin_known
= &TEH_PG_batch_ensure_coin_known;
- if (GNUNET_OK != TALER_PQ_load_oids_for_composite_types (pg->conn))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to load OIDs for composite types\n");
- }
-
return plugin;
}
diff --git a/src/include/taler_pq_lib.h b/src/include/taler_pq_lib.h
index fddfd2a29..4b2a1f5dd 100644
--- a/src/include/taler_pq_lib.h
+++ b/src/include/taler_pq_lib.h
@@ -31,31 +31,6 @@
#include "taler_util.h"
/**
- * Enumerates the composite types that Taler defines in Postgres.
- * The corresponding OIDs (which are assigned by postgres at time of
- * declaration) are stored in TALER_PQ_CompositeOIDs.
- */
-enum TALER_PQ_CompositeType
-{
- TALER_PQ_CompositeAmount,
- TALER_PQ_CompositeMAX /* MUST be last */
-};
-
-/**
- * The correspondence of the Composite types and their OID in Postgres
- */
-extern Oid TALER_PQ_CompositeOIDs[TALER_PQ_CompositeMAX];
-
-/**
- * Initialize the list of OIDs in TALER_PQ_CompositeOIDs. MUST be called
- * before any composite type is used in arrays-specs/-params.
- *
- * @return GNUNET_SYSERR on failure
- */
-enum GNUNET_GenericReturnValue
-TALER_PQ_load_oids_for_composite_types (struct GNUNET_PQ_Context *db);
-
-/**
* 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
@@ -177,7 +152,7 @@ struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_array_blinded_denom_sig (
size_t num,
const struct TALER_BlindedDenominationSignature *denom_sigs,
- const struct GNUNET_PQ_Context *db
+ struct GNUNET_PQ_Context *db
);
/**
@@ -191,7 +166,7 @@ struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_array_blinded_coin_hash (
size_t num,
const struct TALER_BlindedCoinHashP *coin_evs,
- const struct GNUNET_PQ_Context *db);
+ struct GNUNET_PQ_Context *db);
/**
* Generate query parameter for an array of mounts
@@ -332,7 +307,7 @@ TALER_PQ_result_spec_json (const char *name,
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_array_blinded_denom_sig (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
struct TALER_BlindedDenominationSignature **denom_sigs);
@@ -348,7 +323,7 @@ TALER_PQ_result_spec_array_blinded_denom_sig (
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_array_blinded_coin_hash (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
struct TALER_BlindedCoinHashP **h_coin_evs);
@@ -364,7 +339,7 @@ TALER_PQ_result_spec_array_blinded_coin_hash (
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_array_denom_hash (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
struct TALER_DenominationHashP **denom_hs);
@@ -381,7 +356,7 @@ TALER_PQ_result_spec_array_denom_hash (
*/
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_array_amount (
- struct GNUNET_PQ_Context *db, /* not const because we need to query dynamically */
+ struct GNUNET_PQ_Context *db,
const char *name,
const char *currency,
size_t *num,
diff --git a/src/pq/Makefile.am b/src/pq/Makefile.am
index 23fd34dbc..591aeae11 100644
--- a/src/pq/Makefile.am
+++ b/src/pq/Makefile.am
@@ -11,7 +11,6 @@ lib_LTLIBRARIES = \
libtalerpq_la_SOURCES = \
pq_common.h \
- pq_composite_types.c \
pq_query_helper.c \
pq_result_helper.c
libtalerpq_la_LIBADD = \
diff --git a/src/pq/pq_common.h b/src/pq/pq_common.h
index 26137f422..d479ce5bb 100644
--- a/src/pq/pq_common.h
+++ b/src/pq/pq_common.h
@@ -67,11 +67,13 @@ struct TALER_PQ_Amount_P
*
* @param db postgres-context of type `struct GNUNET_PQ_Context *`
* @param amount amount of type `struct TALER_Amount *`
+ * @param oid_v OID of the INT8 type in postgres
+ * @param oid_f OID of the INT4 type in postgres
*/
-#define MAKE_TALER_PQ_AMOUNT_P(db,amount) \
+#define MAKE_TALER_PQ_AMOUNT_P(db,amount,oid_v,oid_f) \
{ \
- .oid_v = htonl (GNUNET_PQ_get_oid ((db), GNUNET_PQ_DATATYPE_INT8)), \
- .oid_f = htonl (GNUNET_PQ_get_oid ((db), GNUNET_PQ_DATATYPE_INT4)), \
+ .oid_v = htonl (oid_v), \
+ .oid_f = htonl (oid_f), \
.sz_v = htonl (sizeof((amount)->value)), \
.sz_f = htonl (sizeof((amount)->fraction)), \
.v = GNUNET_htonll ((amount)->value), \
diff --git a/src/pq/pq_composite_types.c b/src/pq/pq_composite_types.c
deleted file mode 100644
index ed51ef428..000000000
--- a/src/pq/pq_composite_types.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2023 Taler Systems SA
-
- 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, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file pq/pq_composite_types.c
- * @brief helper functions for Taler-specific libpq (PostGres) interactions with composite types
- * @author Özgür Kesim
- */
-#include "platform.h"
-#include <gnunet/gnunet_common.h>
-#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_pq_lib.h>
-#include "taler_pq_lib.h"
-#include "pq_common.h"
-
-Oid TALER_PQ_CompositeOIDs[TALER_PQ_CompositeMAX] = {0};
-
-enum GNUNET_GenericReturnValue
-TALER_PQ_load_oids_for_composite_types (
- struct GNUNET_PQ_Context *db)
-{
- static char *names[] = {
- [TALER_PQ_CompositeAmount] = "taler_amount"
- };
- size_t num = sizeof(names) / sizeof(names[0]);
-
- GNUNET_static_assert (num == TALER_PQ_CompositeMAX);
-
- for (size_t i = 0; i < num; i++)
- {
- enum GNUNET_GenericReturnValue ret;
- enum TALER_PQ_CompositeType typ = i;
- ret = GNUNET_PQ_get_oid_by_name (db,
- names[i],
- &TALER_PQ_CompositeOIDs[typ]);
- if (GNUNET_OK != ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to load OID for type %s\n",
- names[i]);
- return GNUNET_SYSERR;
- }
- }
- return GNUNET_OK;
-}
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c
index a21b0b1d0..a1632ac68 100644
--- a/src/pq/pq_query_helper.c
+++ b/src/pq/pq_query_helper.c
@@ -175,7 +175,7 @@ qconv_amount_tuple (void *cls,
void *scratch[],
unsigned int scratch_length)
{
- const struct GNUNET_PQ_Context *db = cls;
+ struct GNUNET_PQ_Context *db = cls;
const struct TALER_Amount *amount = data;
size_t sz;
@@ -188,18 +188,29 @@ qconv_amount_tuple (void *cls,
{
char *out;
- struct TALER_PQ_Amount_P d = MAKE_TALER_PQ_AMOUNT_P (db, amount);
+ Oid oid_v, oid_f;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db, "int8", &oid_v));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db, "int4", &oid_f));
+
+ {
+ struct TALER_PQ_Amount_P d = MAKE_TALER_PQ_AMOUNT_P (db,
+ amount,
+ oid_v,
+ oid_f);
- sz = sizeof(uint32_t); /* number of elements in tuple */
- sz += sizeof(d);
+ sz = sizeof(uint32_t); /* number of elements in tuple */
+ sz += sizeof(d);
- out = GNUNET_malloc (sz);
- scratch[0] = out;
+ out = GNUNET_malloc (sz);
+ scratch[0] = out;
- *(uint32_t *) out = htonl (2);
- out += sizeof(uint32_t);
+ *(uint32_t *) out = htonl (2);
+ out += sizeof(uint32_t);
- *(struct TALER_PQ_Amount_P*) out = d;
+ *(struct TALER_PQ_Amount_P*) out = d;
+ }
}
@@ -795,7 +806,7 @@ struct qconv_array_cls
/**
* db context, needed for OID-lookup of basis-types
*/
- const struct GNUNET_PQ_Context *db;
+ struct GNUNET_PQ_Context *db;
};
/**
@@ -972,15 +983,28 @@ qconv_array (
case TALER_PQ_array_of_amount:
{
const struct TALER_Amount *amounts = data;
- struct TALER_PQ_Amount_P am = MAKE_TALER_PQ_AMOUNT_P (meta->db,
- &amounts[i]);
-
- *(uint32_t *) out = htonl (2); /* number of elements in tuple */
- out += sizeof(uint32_t);
- sz -= sizeof(uint32_t);
- GNUNET_memcpy (out,
- &am,
- sizeof(am));
+ Oid oid_v, oid_f;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (meta->db,
+ "int8",
+ &oid_v));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (meta->db,
+ "int4",
+ &oid_f));
+ {
+ struct TALER_PQ_Amount_P am = MAKE_TALER_PQ_AMOUNT_P (meta->db,
+ &amounts[i],
+ oid_v,
+ oid_f);
+
+ *(uint32_t *) out = htonl (2); /* number of elements in tuple */
+ out += sizeof(uint32_t);
+ sz -= sizeof(uint32_t);
+ GNUNET_memcpy (out,
+ &am,
+ sizeof(am));
+ }
break;
}
case TALER_PQ_array_of_blinded_denom_sig:
@@ -1086,7 +1110,7 @@ query_param_array_generic (
size_t same_size,
enum TALER_PQ_ArrayType typ,
Oid oid,
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
struct qconv_array_cls *meta = GNUNET_new (struct qconv_array_cls);
meta->typ = typ;
@@ -1113,16 +1137,18 @@ struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_array_blinded_denom_sig (
size_t num,
const struct TALER_BlindedDenominationSignature *denom_sigs,
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db, "bytea", &oid));
return query_param_array_generic (num,
true,
denom_sigs,
NULL,
0,
TALER_PQ_array_of_blinded_denom_sig,
- GNUNET_PQ_get_oid (db,
- GNUNET_PQ_DATATYPE_BYTEA),
+ oid,
NULL);
}
@@ -1131,16 +1157,18 @@ struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_array_blinded_coin_hash (
size_t num,
const struct TALER_BlindedCoinHashP *coin_hs,
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db, "bytea", &oid));
return query_param_array_generic (num,
true,
coin_hs,
NULL,
sizeof(struct TALER_BlindedCoinHashP),
TALER_PQ_array_of_blinded_coin_hash,
- GNUNET_PQ_get_oid (db,
- GNUNET_PQ_DATATYPE_BYTEA),
+ oid,
NULL);
}
@@ -1149,16 +1177,18 @@ struct GNUNET_PQ_QueryParam
TALER_PQ_query_param_array_denom_hash (
size_t num,
const struct TALER_DenominationHashP *denom_hs,
- const struct GNUNET_PQ_Context *db)
+ struct GNUNET_PQ_Context *db)
{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db, "bytea", &oid));
return query_param_array_generic (num,
true,
denom_hs,
NULL,
sizeof(struct TALER_DenominationHashP),
TALER_PQ_array_of_denom_hash,
- GNUNET_PQ_get_oid (db,
- GNUNET_PQ_DATATYPE_BYTEA),
+ oid,
NULL);
}
@@ -1169,19 +1199,17 @@ TALER_PQ_query_param_array_amount (
const struct TALER_Amount *amounts,
struct GNUNET_PQ_Context *db)
{
- if (TALER_PQ_CompositeOIDs[0] == 0)
- GNUNET_assert (GNUNET_OK ==
- TALER_PQ_load_oids_for_composite_types (db));
-
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db, "taler_amount", &oid));
return query_param_array_generic (
num,
true,
amounts,
NULL,
- sizeof(uint32_t) /* the # of elements in the tuple, here: 2 */
- + sizeof(struct TALER_PQ_Amount_P),
+ sizeof(uint32_t) + sizeof(struct TALER_PQ_Amount_P),
TALER_PQ_array_of_amount,
- TALER_PQ_CompositeOIDs[TALER_PQ_CompositeAmount],
+ oid,
db);
}
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c
index 52e42562d..ed8100a10 100644
--- a/src/pq/pq_result_helper.c
+++ b/src/pq/pq_result_helper.c
@@ -1385,7 +1385,7 @@ array_cleanup (void *cls,
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_array_blinded_denom_sig (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
struct TALER_BlindedDenominationSignature **denom_sigs)
@@ -1394,8 +1394,10 @@ TALER_PQ_result_spec_array_blinded_denom_sig (
info->num = num;
info->typ = TALER_PQ_array_of_blinded_denom_sig;
- info->oid = GNUNET_PQ_get_oid (db,
- GNUNET_PQ_DATATYPE_BYTEA);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "bytea",
+ &info->oid));
struct GNUNET_PQ_ResultSpec res = {
.conv = extract_array_generic,
@@ -1410,7 +1412,7 @@ TALER_PQ_result_spec_array_blinded_denom_sig (
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_array_blinded_coin_hash (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
struct TALER_BlindedCoinHashP **h_coin_evs)
@@ -1419,8 +1421,10 @@ TALER_PQ_result_spec_array_blinded_coin_hash (
info->num = num;
info->typ = TALER_PQ_array_of_blinded_coin_hash;
- info->oid = GNUNET_PQ_get_oid (db,
- GNUNET_PQ_DATATYPE_BYTEA);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "bytea",
+ &info->oid));
struct GNUNET_PQ_ResultSpec res = {
.conv = extract_array_generic,
@@ -1435,7 +1439,7 @@ TALER_PQ_result_spec_array_blinded_coin_hash (
struct GNUNET_PQ_ResultSpec
TALER_PQ_result_spec_array_denom_hash (
- const struct GNUNET_PQ_Context *db,
+ struct GNUNET_PQ_Context *db,
const char *name,
size_t *num,
struct TALER_DenominationHashP **denom_hs)
@@ -1444,8 +1448,10 @@ TALER_PQ_result_spec_array_denom_hash (
info->num = num;
info->typ = TALER_PQ_array_of_denom_hash;
- info->oid = GNUNET_PQ_get_oid (db,
- GNUNET_PQ_DATATYPE_BYTEA);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "bytea",
+ &info->oid));
struct GNUNET_PQ_ResultSpec res = {
.conv = extract_array_generic,
@@ -1466,16 +1472,15 @@ TALER_PQ_result_spec_array_amount (
size_t *num,
struct TALER_Amount **amounts)
{
- if (TALER_PQ_CompositeOIDs[0] == 0)
- GNUNET_assert (GNUNET_OK ==
- TALER_PQ_load_oids_for_composite_types (db));
-
struct ArrayResultCls *info = GNUNET_new (struct ArrayResultCls);
info->num = num;
info->typ = TALER_PQ_array_of_amount;
- info->oid = TALER_PQ_CompositeOIDs[TALER_PQ_CompositeAmount];
info->db = db;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "taler_amount",
+ &info->oid));
{
size_t clen = GNUNET_MIN (TALER_CURRENCY_LEN - 1,
diff --git a/src/pq/test_pq.c b/src/pq/test_pq.c
index a09e500f5..218d9ad2a 100644
--- a/src/pq/test_pq.c
+++ b/src/pq/test_pq.c
@@ -244,15 +244,6 @@ main (int argc,
return 1;
}
- ret = TALER_PQ_load_oids_for_composite_types (conn);
- if (GNUNET_OK != ret)
- {
- fprintf (stderr,
- "Failed to load oids for composites\n");
- GNUNET_PQ_disconnect (conn);
- return 1;
- }
-
ret = run_queries (conn);
{
struct GNUNET_PQ_ExecuteStatement ds[] = {