LCOV - code coverage report
Current view: top level - merchant-tools - taler-merchant-dbinit.c (source / functions) Hit Total Coverage
Test: GNU Taler merchant coverage report Lines: 26 33 78.8 %
Date: 2022-08-25 06:17:04 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2014, 2015, 2020 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 merchant-tools/taler-merchant-dbinit.c
      18             :  * @brief Create tables for the merchant database.
      19             :  * @author Florian Dold
      20             :  * @author Marcello Stanisci
      21             :  */
      22             : #include "platform.h"
      23             : #include <taler/taler_util.h>
      24             : #include <gnunet/gnunet_util_lib.h>
      25             : #include "taler_merchantdb_lib.h"
      26             : 
      27             : 
      28             : /**
      29             :  * Return value from main().
      30             :  */
      31             : static int global_ret;
      32             : 
      33             : /**
      34             :  * -r option: do full DB reset
      35             :  */
      36             : static int reset_db;
      37             : 
      38             : /**
      39             :  * Main function that will be run.
      40             :  *
      41             :  * @param cls closure
      42             :  * @param args remaining command-line arguments
      43             :  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
      44             :  * @param config configuration
      45             :  */
      46             : static void
      47           5 : run (void *cls,
      48             :      char *const *args,
      49             :      const char *cfgfile,
      50             :      const struct GNUNET_CONFIGURATION_Handle *config)
      51             : {
      52             :   struct TALER_MERCHANTDB_Plugin *plugin;
      53             :   struct GNUNET_CONFIGURATION_Handle *cfg;
      54             : 
      55           5 :   cfg = GNUNET_CONFIGURATION_dup (config);
      56           5 :   if (NULL ==
      57           5 :       (plugin = TALER_MERCHANTDB_plugin_load (cfg)))
      58             :   {
      59           0 :     fprintf (stderr,
      60             :              "Failed to initialize database plugin.\n");
      61           0 :     global_ret = 1;
      62           0 :     GNUNET_CONFIGURATION_destroy (cfg);
      63           0 :     return;
      64             :   }
      65           5 :   if (reset_db)
      66             :   {
      67           5 :     if (GNUNET_OK !=
      68           5 :         plugin->drop_tables (plugin->cls))
      69             :     {
      70           5 :       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
      71             :                   "Failed to reset the database\n");
      72             :     }
      73             :   }
      74           5 :   if (GNUNET_OK !=
      75           5 :       plugin->create_tables (plugin->cls))
      76             :   {
      77           5 :     global_ret = 1;
      78           5 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
      79             :                 "Failed to initialize tables\n");
      80             :   }
      81           5 :   TALER_MERCHANTDB_plugin_unload (plugin);
      82           5 :   GNUNET_CONFIGURATION_destroy (cfg);
      83             : }
      84             : 
      85             : 
      86             : /**
      87             :  * The main function of the database initialization tool.
      88             :  * Used to initialize the Taler Exchange's database.
      89             :  *
      90             :  * @param argc number of arguments from the command line
      91             :  * @param argv command line arguments
      92             :  * @return 0 ok, 1 on error
      93             :  */
      94             : int
      95           5 : main (int argc,
      96             :       char *const *argv)
      97             : {
      98           5 :   struct GNUNET_GETOPT_CommandLineOption options[] = {
      99           5 :     GNUNET_GETOPT_option_flag ('r',
     100             :                                "reset",
     101             :                                "reset database (DANGEROUS: all existing data is lost!)",
     102             :                                &reset_db),
     103             : 
     104           5 :     GNUNET_GETOPT_option_version (PACKAGE_VERSION "-" VCS_VERSION),
     105             :     GNUNET_GETOPT_OPTION_END
     106             :   };
     107             :   enum GNUNET_GenericReturnValue ret;
     108             : 
     109             :   /* force linker to link against libtalerutil; if we do
     110             :      not do this, the linker may "optimize" libtalerutil
     111             :      away and skip #TALER_OS_init(), which we do need */
     112           5 :   (void) TALER_project_data_default ();
     113           5 :   if (GNUNET_OK !=
     114           5 :       GNUNET_STRINGS_get_utf8_args (argc, argv,
     115             :                                     &argc, &argv))
     116           0 :     return 4;
     117           5 :   ret = GNUNET_PROGRAM_run (
     118             :     argc, argv,
     119             :     "taler-merchant-dbinit",
     120             :     gettext_noop ("Initialize Taler merchant database"),
     121             :     options,
     122             :     &run, NULL);
     123           5 :   GNUNET_free_nz ((void *) argv);
     124           5 :   if (GNUNET_SYSERR == ret)
     125           0 :     return 3;
     126           5 :   if (GNUNET_NO == ret)
     127           0 :     return 0;
     128           5 :   return global_ret;
     129             : }
     130             : 
     131             : 
     132             : /* end of taler-merchant-dbinit.c */

Generated by: LCOV version 1.14