challenger

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

pg.c (2347B)


      1 /*
      2   This file is part of Challenger
      3   (C) 2023 Taler Systems SA
      4 
      5   Challenger 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   Challenger is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of ANASTASISABILITY 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   Challenger; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file challengerdb/plugin_challengerdb_postgres.c
     18  * @brief database helper functions for postgres used by challenger
     19  * @author Christian Grothoff
     20  */
     21 #include "platform.h"
     22 #include <gnunet/gnunet_util_lib.h>
     23 #include <gnunet/gnunet_db_lib.h>
     24 #include <gnunet/gnunet_pq_lib.h>
     25 #include <taler/taler_pq_lib.h>
     26 #include "challenger_database_lib.h"
     27 #include "challenger_util.h"
     28 #include "challenger-database/preflight.h"
     29 #include "pg_helper.h"
     30 
     31 
     32 struct CHALLENGERDB_PostgresContext *
     33 CHALLENGERDB_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
     34                       bool skip_preflight)
     35 {
     36   struct CHALLENGERDB_PostgresContext *pg;
     37 
     38   pg = GNUNET_new (struct CHALLENGERDB_PostgresContext);
     39   pg->cfg = cfg;
     40   if (GNUNET_OK !=
     41       GNUNET_CONFIGURATION_get_value_filename (cfg,
     42                                                "challengerdb-postgres",
     43                                                "SQL_DIR",
     44                                                &pg->sql_dir))
     45   {
     46     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
     47                                "challengerdb-postgres",
     48                                "SQL_DIR");
     49     GNUNET_free (pg);
     50     return NULL;
     51   }
     52   if (! skip_preflight)
     53   {
     54     if (GNUNET_OK !=
     55         CHALLENGERDB_preflight (pg))
     56     {
     57       GNUNET_free (pg->sql_dir);
     58       GNUNET_free (pg);
     59       return NULL;
     60     }
     61   }
     62   return pg;
     63 }
     64 
     65 
     66 void
     67 CHALLENGERDB_disconnect (struct CHALLENGERDB_PostgresContext *pg)
     68 {
     69   if (NULL == pg)
     70     return;
     71   if (NULL != pg->conn)
     72     GNUNET_PQ_disconnect (pg->conn);
     73   GNUNET_free (pg->sql_dir);
     74   GNUNET_free (pg);
     75 }
     76 
     77 
     78 /* end of plugin_challengerdb_postgres.c */