merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

pg.c (2966B)


      1 /*
      2   This file is part of TALER
      3   (C) 2014--2025 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 src/backenddb/pg.c
     18  * @brief database helper functions for postgres used by the merchant
     19  * @author Sree Harsha Totakura <sreeharsha@totakura.in>
     20  * @author Christian Grothoff
     21  * @author Marcello Stanisci
     22  * @author Priscilla Huang
     23  * @author Iván Ávalos
     24  */
     25 #include "platform.h"
     26 #include <gnunet/gnunet_util_lib.h>
     27 #include <gnunet/gnunet_pq_lib.h>
     28 #include <taler/taler_util.h>
     29 #include <taler/taler_pq_lib.h>
     30 #include <taler/taler_json_lib.h>
     31 #include <taler/taler_mhd_lib.h>
     32 #include "merchantdb_lib.h"
     33 #include "helper.h"
     34 
     35 
     36 // FIXME: prefix?
     37 void
     38 check_connection (
     39   struct TALER_MERCHANTDB_PostgresContext *pg)
     40 {
     41   if (NULL != pg->transaction_name)
     42     return;
     43   GNUNET_PQ_reconnect_if_down (pg->conn);
     44 }
     45 
     46 
     47 struct TALER_MERCHANTDB_PostgresContext *
     48 TALER_MERCHANTDB_connect (
     49   const struct GNUNET_CONFIGURATION_Handle *cfg)
     50 {
     51   struct TALER_MERCHANTDB_PostgresContext *pg;
     52   struct GNUNET_PQ_ExecuteStatement es[] = {
     53     GNUNET_PQ_make_try_execute ("SET search_path TO merchant;"),
     54     GNUNET_PQ_EXECUTE_STATEMENT_END
     55   };
     56 
     57   pg = GNUNET_new (struct TALER_MERCHANTDB_PostgresContext);
     58   pg->cfg = cfg;
     59   if (GNUNET_OK !=
     60       GNUNET_CONFIGURATION_get_value_filename (cfg,
     61                                                "merchantdb-postgres",
     62                                                "SQL_DIR",
     63                                                &pg->sql_dir))
     64   {
     65     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
     66                                "merchantdb-postgres",
     67                                "SQL_DIR");
     68     GNUNET_free (pg);
     69     return NULL;
     70   }
     71   pg->conn = GNUNET_PQ_connect_with_cfg2 (pg->cfg,
     72                                           "merchantdb-postgres",
     73                                           "merchant-",
     74                                           es,
     75                                           NULL, /* prepared statemetns */
     76                                           GNUNET_PQ_FLAG_CHECK_CURRENT);
     77   pg->prep_gen++;
     78   if (NULL == pg->conn)
     79   {
     80     TALER_MERCHANTDB_disconnect (pg);
     81     return NULL;
     82   }
     83   return pg;
     84 }
     85 
     86 
     87 void
     88 TALER_MERCHANTDB_disconnect (
     89   struct TALER_MERCHANTDB_PostgresContext *pg)
     90 {
     91   GNUNET_PQ_disconnect (pg->conn);
     92   GNUNET_free (pg->current_merchant_id);
     93   GNUNET_free (pg);
     94 }
     95 
     96 
     97 /* end of pg.c */