exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

pg_enable_rules.c (2387B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 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 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 exchangedb/pg_enable_rules.c
     18  * @brief Implementation of the enable_rules function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "taler/platform.h"
     22 #include "taler/taler_error_codes.h"
     23 #include "taler/taler_dbevents.h"
     24 #include "taler/taler_pq_lib.h"
     25 #include "pg_enable_rules.h"
     26 #include "pg_helper.h"
     27 
     28 
     29 enum GNUNET_GenericReturnValue
     30 TEH_PG_enable_rules (
     31   void *cls,
     32   const char *schema)
     33 {
     34   struct PostgresClosure *pg = cls;
     35   struct GNUNET_PQ_Context *conn;
     36   enum GNUNET_GenericReturnValue ret;
     37   char *sp;
     38 
     39   GNUNET_asprintf (&sp,
     40                    "SET search_path TO %s,exchange;",
     41                    schema);
     42   {
     43     struct GNUNET_PQ_ExecuteStatement es[] = {
     44       GNUNET_PQ_make_try_execute (sp),
     45       GNUNET_PQ_EXECUTE_STATEMENT_END
     46     };
     47     char *schemadash;
     48 
     49     GNUNET_asprintf (&schemadash,
     50                      "%s-",
     51                      schema);
     52     conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
     53                                        "exchangedb-postgres",
     54                                        schemadash,
     55                                        es,
     56                                        NULL);
     57     GNUNET_free (schemadash);
     58   }
     59   GNUNET_free (sp);
     60   if (NULL == conn)
     61     return GNUNET_SYSERR;
     62   {
     63     char *procfile;
     64 
     65     GNUNET_asprintf (&procfile,
     66                      "%s-procedures",
     67                      schema);
     68     ret = GNUNET_PQ_exec_sql (conn,
     69                               procfile);
     70     /* $SCHEMA-procedures MAY not exist, so only check for hard error */
     71     GNUNET_break (GNUNET_SYSERR != ret);
     72     if (GNUNET_NO == ret)
     73       ret = GNUNET_OK;
     74     GNUNET_free (procfile);
     75   }
     76   GNUNET_PQ_disconnect (conn);
     77   return ret;
     78 }