challenger

OAuth 2.0-based authentication service that validates user can receive messages at a certain address
Log | Files | Refs | Submodules | README | LICENSE

commit 33018904026e10ea0458d3559228c6a7eacb2837
parent bd67e05e43c40512bd88172e65560231dc124187
Author: Christian Grothoff <grothoff@gnunet.org>
Date:   Wed,  1 Jul 2026 16:57:11 +0200

fix #11593

Diffstat:
Msrc/challengerdb/pg.c | 10++++++++--
Msrc/challengerdb/pg_helper.h | 47++++++++++++++++++++++++-----------------------
2 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/src/challengerdb/pg.c b/src/challengerdb/pg.c @@ -30,6 +30,12 @@ struct CHALLENGERDB_PostgresContext; #include "pg_helper.h" /** + * Counts how often we have established a fresh @e conn + * to the database. Used to re-prepare statements. + */ +unsigned long long CH_PG_prep_gen_; + +/** * Function called each time we connect or reconnect to the * database. Gives the application a chance to run some * per-connection initialization logic. @@ -70,7 +76,7 @@ reconnect_cb (struct CHALLENGERDB_PostgresContext *pg, GNUNET_break (0); return; } - pg->prep_gen++; + CH_PG_prep_gen_++; } @@ -93,7 +99,7 @@ internal_setup (struct CHALLENGERDB_PostgresContext *pg) pg); if (NULL == db_conn) return GNUNET_SYSERR; - if (0 == pg->prep_gen) + if (0 == CH_PG_prep_gen_) { GNUNET_PQ_disconnect (db_conn); return GNUNET_SYSERR; diff --git a/src/challengerdb/pg_helper.h b/src/challengerdb/pg_helper.h @@ -49,15 +49,16 @@ struct CHALLENGERDB_PostgresContext */ const char *transaction_name; - /** - * How often did we (re)establish @a conn so far? - */ - uint64_t prep_gen; - }; /** + * Counts how often we have established a fresh @e conn + * to the database. Used to re-prepare statements. + */ +extern unsigned long long CH_PG_prep_gen_; + +/** * Check that the database connection is still up. * * @param cls a `struct CHALLENGERDB_PostgresContext` with connection to check @@ -75,25 +76,25 @@ CH_PG_check_connection (void *cls); * @param sql actual SQL text */ #define PREPARE(pg,name,sql) \ - do { \ - static unsigned long long gen; \ + do { \ + static unsigned long long gen; \ \ - if (gen < pg->prep_gen) \ - { \ - struct GNUNET_PQ_PreparedStatement ps[] = { \ - GNUNET_PQ_make_prepare (name, sql), \ - GNUNET_PQ_PREPARED_STATEMENT_END \ - }; \ + if (gen < CH_PG_prep_gen_) \ + { \ + struct GNUNET_PQ_PreparedStatement ps[] = { \ + GNUNET_PQ_make_prepare (name, sql), \ + GNUNET_PQ_PREPARED_STATEMENT_END \ + }; \ \ - if (GNUNET_OK != \ - GNUNET_PQ_prepare_statements (pg->conn, \ - ps)) \ - { \ - GNUNET_break (0); \ - return GNUNET_DB_STATUS_HARD_ERROR; \ - } \ - gen = pg->prep_gen; \ - } \ - } while (0) + if (GNUNET_OK != \ + GNUNET_PQ_prepare_statements (pg->conn, \ + ps)) \ + { \ + GNUNET_break (0); \ + return GNUNET_DB_STATUS_HARD_ERROR; \ + } \ + gen = CH_PG_prep_gen_; \ + } \ + } while (0) #endif