sync

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

syncdb_pg.c (2588B)


      1 /*
      2   This file is part of TALER
      3   (C) 2014--2022 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Lesser 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 syncdb/syncdb_pg.c
     18  * @brief shared database state and helpers for sync postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "syncdb_pg.h"
     22 #include "sync/sync_util.h"
     23 
     24 
     25 /**
     26  * Global database closure.
     27  */
     28 struct PostgresClosure *pg;
     29 
     30 
     31 enum GNUNET_GenericReturnValue
     32 SYNCDB_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
     33              bool skip_preflight)
     34 {
     35   pg = GNUNET_new (struct PostgresClosure);
     36   pg->cfg = cfg;
     37   if (GNUNET_OK !=
     38       GNUNET_CONFIGURATION_get_value_filename (cfg,
     39                                                "syncdb-postgres",
     40                                                "SQL_DIR",
     41                                                &pg->sql_dir))
     42   {
     43     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
     44                                "syncdb-postgres",
     45                                "SQL_DIR");
     46     GNUNET_free (pg);
     47     pg = NULL;
     48     return GNUNET_SYSERR;
     49   }
     50   if (GNUNET_OK !=
     51       GNUNET_CONFIGURATION_get_value_string (cfg,
     52                                              "sync",
     53                                              "CURRENCY",
     54                                              &pg->currency))
     55   {
     56     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
     57                                "sync",
     58                                "CURRENCY");
     59     GNUNET_free (pg->sql_dir);
     60     GNUNET_free (pg);
     61     pg = NULL;
     62     return GNUNET_SYSERR;
     63   }
     64   if ( (! skip_preflight) &&
     65        (GNUNET_OK !=
     66         SYNCDB_preflight ()) )
     67   {
     68     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     69                 "Database not ready. Try running sync-dbinit!\n");
     70     SYNCDB_fini ();
     71     return GNUNET_SYSERR;
     72   }
     73   return GNUNET_OK;
     74 }
     75 
     76 
     77 void
     78 SYNCDB_fini (void)
     79 {
     80   if (NULL == pg)
     81     return;
     82   if (NULL != pg->conn)
     83     GNUNET_PQ_disconnect (pg->conn);
     84   GNUNET_free (pg->currency);
     85   GNUNET_free (pg->sql_dir);
     86   GNUNET_free (pg);
     87   pg = NULL;
     88 }
     89 
     90 
     91 /* end of syncdb_pg.c */