sync

Backup service to store encrypted wallet databases (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit 666ef72f72439c9e608a67aa45ee13df749ac12d
parent a07cc5b2fd16149b1d023ba479fabe39ae60834e
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 22 Mar 2026 13:51:12 +0100

add missing file

Diffstat:
Asrc/syncdb/syncdb_pg.h | 133+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 133 insertions(+), 0 deletions(-)

diff --git a/src/syncdb/syncdb_pg.h b/src/syncdb/syncdb_pg.h @@ -0,0 +1,133 @@ +/* + This file is part of TALER + (C) 2014--2022 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU Lesser 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 syncdb/syncdb_pg.h + * @brief internal shared state for sync postgres database + * @author Christian Grothoff + */ +#ifndef SYNCDB_PG_H +#define SYNCDB_PG_H + +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_db_lib.h> +#include <gnunet/gnunet_pq_lib.h> +#include <taler/taler_pq_lib.h> +#include "sync/sync_database_lib.h" + +/** + * Type of the shared database closure. + */ +struct PostgresClosure +{ + + /** + * Postgres connection handle. + */ + struct GNUNET_PQ_Context *conn; + + /** + * Directory with SQL statements to run to create tables. + */ + char *sql_dir; + + /** + * Underlying configuration. + */ + const struct GNUNET_CONFIGURATION_Handle *cfg; + + /** + * Name of the currently active transaction, NULL if none is active. + */ + const char *transaction_name; + + /** + * Currency we accept payments in. + */ + char *currency; + + /** + * How often did we (re)establish @a conn so far? + */ + uint64_t prep_gen; + +}; + + +/** + * Global database closure, initialized by SYNCDB_init(). + */ +extern struct PostgresClosure *pg; + + +/** + * Start a transaction. + * + * @param name unique name identifying the transaction (for debugging), + * must point to a constant + * @return #GNUNET_OK on success + */ +enum GNUNET_GenericReturnValue +begin_transaction (const char *name); + + +/** + * Roll back the current transaction of a database connection. + */ +void +rollback (void); + + +/** + * Commit the current transaction of a database connection. + * + * @return transaction status code + */ +enum GNUNET_DB_QueryStatus +commit_transaction (void); + + +/** + * Prepares SQL statement @a sql under @a name for + * connection @a pg once. + * Returns with #GNUNET_DB_STATUS_HARD_ERROR on failure. + * + * @param name name to prepare the statement under + * @param sql actual SQL text + */ +#define PREPARE(name,sql) \ + 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 (GNUNET_OK != \ + GNUNET_PQ_prepare_statements (pg->conn, \ + ps)) \ + { \ + GNUNET_break (0); \ + return GNUNET_DB_STATUS_HARD_ERROR; \ + } \ + gen = pg->prep_gen; \ + } \ + } while (0) + +#endif