LCOV - code coverage report
Current view: top level - auditordb - preflight.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 61.5 % 26 16
Test Date: 2026-04-14 15:39:31 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /*
       2              :    This file is part of TALER
       3              :    Copyright (C) 2026 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 src/auditordb/preflight.c
      18              :  * @brief Implementation of the preflight function for Postgres
      19              :  * @author Christian Grothoff
      20              :  */
      21              : #include "taler/taler_pq_lib.h"
      22              : #include "auditor-database/preflight.h"
      23              : #include "pg_helper.h"
      24              : 
      25              : 
      26              : /**
      27              :  * Connect to the db if the connection does not exist yet.
      28              :  *
      29              :  * @param[in,out] pg the plugin-specific state
      30              :  * @return #GNUNET_OK on success
      31              :  */
      32              : static enum GNUNET_GenericReturnValue
      33           24 : setup_connection (struct TALER_AUDITORDB_PostgresContext *pg)
      34              : {
      35           24 :   struct GNUNET_PQ_ExecuteStatement es[] = {
      36           24 :     GNUNET_PQ_make_try_execute ("SET search_path TO auditor;"),
      37              :     GNUNET_PQ_EXECUTE_STATEMENT_END
      38              :   };
      39              :   struct GNUNET_PQ_Context *db_conn;
      40              : 
      41           24 :   if (NULL != pg->conn)
      42              :   {
      43            0 :     GNUNET_PQ_reconnect_if_down (pg->conn);
      44            0 :     return GNUNET_OK;
      45              :   }
      46           24 :   db_conn = GNUNET_PQ_connect_with_cfg2 (pg->cfg,
      47              :                                          "auditordb-postgres",
      48              :                                          "auditor-",
      49              :                                          es,
      50              :                                          NULL, /* prepared statements */
      51              :                                          GNUNET_PQ_FLAG_CHECK_CURRENT);
      52           24 :   if (NULL == db_conn)
      53            0 :     return GNUNET_SYSERR;
      54           24 :   pg->conn = db_conn;
      55           24 :   pg->prep_gen++;
      56           24 :   return GNUNET_OK;
      57              : }
      58              : 
      59              : 
      60              : enum GNUNET_GenericReturnValue
      61           66 : TALER_AUDITORDB_preflight (struct TALER_AUDITORDB_PostgresContext *pg)
      62              : {
      63           66 :   struct GNUNET_PQ_ExecuteStatement es[] = {
      64           66 :     GNUNET_PQ_make_execute ("ROLLBACK"),
      65              :     GNUNET_PQ_EXECUTE_STATEMENT_END
      66              :   };
      67              : 
      68           90 :   if ( (NULL == pg->conn) &&
      69              :        (GNUNET_OK !=
      70           24 :         setup_connection (pg)) )
      71            0 :     return GNUNET_SYSERR;
      72           66 :   if (NULL == pg->transaction_name)
      73           66 :     return GNUNET_OK; /* all good */
      74            0 :   if (GNUNET_OK ==
      75            0 :       GNUNET_PQ_exec_statements (pg->conn,
      76              :                                  es))
      77              :   {
      78            0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
      79              :                 "BUG: Preflight check rolled back transaction `%s'!\n",
      80              :                 pg->transaction_name);
      81              :   }
      82              :   else
      83              :   {
      84            0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
      85              :                 "BUG: Preflight check failed to rollback transaction `%s'!\n",
      86              :                 pg->transaction_name);
      87              :   }
      88            0 :   pg->transaction_name = NULL;
      89            0 :   return GNUNET_NO;
      90              : }
        

Generated by: LCOV version 2.0-1