LCOV - code coverage report
Current view: top level - exchange-tools - taler-exchange-dbinit.c (source / functions) Hit Total Coverage
Test: rcoverage.info Lines: 15 25 60.0 %
Date: 2017-11-25 11:31:41 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2014, 2015 GNUnet e.V.
       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 exchange-tools/taler-exchange-dbinit.c
      18             :  * @brief Create tables for the exchange database.
      19             :  * @author Florian Dold
      20             :  */
      21             : #include "platform.h"
      22             : #include <gnunet/gnunet_util_lib.h>
      23             : #include "taler_exchangedb_plugin.h"
      24             : 
      25             : 
      26             : /**
      27             :  * Return value from main().
      28             :  */
      29             : static int global_ret;
      30             : 
      31             : /**
      32             :  * -r option: do full DB reset
      33             :  */
      34             : static int reset_db;
      35             : 
      36             : /**
      37             :  * -g option: garbage collect DB reset
      38             :  */
      39             : static int gc_db;
      40             : 
      41             : /**
      42             :  * Main function that will be run.
      43             :  *
      44             :  * @param cls closure
      45             :  * @param args remaining command-line arguments
      46             :  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
      47             :  * @param cfg configuration
      48             :  */
      49             : static void
      50           3 : run (void *cls,
      51             :      char *const *args,
      52             :      const char *cfgfile,
      53             :      const struct GNUNET_CONFIGURATION_Handle *cfg)
      54             : {
      55             :   struct TALER_EXCHANGEDB_Plugin *plugin;
      56             : 
      57           3 :   if (NULL ==
      58             :       (plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
      59             :   {
      60           0 :     fprintf (stderr,
      61             :              "Failed to initialize database plugin.\n");
      62           0 :     global_ret = 1;
      63           0 :     return;
      64             :   }
      65           3 :   if (reset_db)
      66           3 :     (void) plugin->drop_tables (plugin->cls);
      67           3 :   if (GNUNET_OK !=
      68           3 :       plugin->create_tables (plugin->cls))
      69             :   {
      70           0 :     fprintf (stderr,
      71             :              "Failed to initialize database.\n");
      72           0 :     TALER_EXCHANGEDB_plugin_unload (plugin);
      73           0 :     global_ret = 1;
      74           0 :     return;
      75             :   }
      76           3 :   if (gc_db)
      77             :     {
      78           0 :       if (GNUNET_SYSERR == plugin->gc (plugin->cls))
      79           0 :         fprintf (stderr,
      80             :                  "Garbage collection failed!\n");
      81             :     }
      82           3 :   TALER_EXCHANGEDB_plugin_unload (plugin);
      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           3 : main (int argc,
      96             :       char *const *argv)
      97             : {
      98           3 :   const struct GNUNET_GETOPT_CommandLineOption options[] = {
      99             :     GNUNET_GETOPT_option_flag ('r',
     100             :                                   "reset",
     101             :                                   "reset database (DANGEROUS: all existing data is lost!)",
     102             :                                   &reset_db),
     103             :     GNUNET_GETOPT_option_flag ('g',
     104             :                                   "gc",
     105             :                                   "garbage collect database",
     106             :                                   &gc_db),
     107             :     GNUNET_GETOPT_OPTION_END
     108             :   };
     109             : 
     110             :   /* force linker to link against libtalerutil; if we do
     111             :      not do this, the linker may "optimize" libtalerutil
     112             :      away and skip #TALER_OS_init(), which we do need */
     113           3 :   (void) TALER_project_data_default ();
     114           3 :   GNUNET_assert (GNUNET_OK ==
     115             :                  GNUNET_log_setup ("taler-exchange-dbinit",
     116             :                                    "INFO",
     117             :                                    NULL));
     118           3 :   if (GNUNET_OK !=
     119           3 :       GNUNET_PROGRAM_run (argc, argv,
     120             :                           "taler-exchange-dbinit",
     121             :                           "Initialize Taler exchange database",
     122             :                           options,
     123             :                           &run, NULL))
     124           0 :     return 1;
     125           3 :   return global_ret;
     126             : }
     127             : 
     128             : 
     129             : /* end of taler-exchange-dbinit.c */

Generated by: LCOV version 1.13