diff options
Diffstat (limited to 'src/stasis/anastasis-dbinit.c')
-rw-r--r-- | src/stasis/anastasis-dbinit.c | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/stasis/anastasis-dbinit.c b/src/stasis/anastasis-dbinit.c new file mode 100644 index 0000000..5c0a174 --- /dev/null +++ b/src/stasis/anastasis-dbinit.c | |||
@@ -0,0 +1,112 @@ | |||
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 util/anastasis-dbinit.c | ||
18 | * @brief Create tables for the merchant database. | ||
19 | * @author Dennis Neufeld | ||
20 | * @author Dominik Meister | ||
21 | */ | ||
22 | #include "platform.h" | ||
23 | #include "anastasis_database_lib.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 | * Main function that will be run. | ||
38 | * | ||
39 | * @param cls closure | ||
40 | * @param args remaining command-line arguments | ||
41 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
42 | * @param cfg configuration | ||
43 | */ | ||
44 | static void | ||
45 | run (void *cls, | ||
46 | char *const *args, | ||
47 | const char *cfgfile, | ||
48 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
49 | { | ||
50 | struct ANASTASIS_DatabasePlugin *plugin; | ||
51 | |||
52 | if (NULL == | ||
53 | (plugin = ANASTASIS_DB_plugin_load (cfg))) | ||
54 | { | ||
55 | fprintf (stderr, | ||
56 | "Failed to initialize database plugin.\n"); | ||
57 | global_ret = 1; | ||
58 | return; | ||
59 | } | ||
60 | if (reset_db) | ||
61 | { | ||
62 | (void) plugin->drop_tables (plugin->cls); | ||
63 | ANASTASIS_DB_plugin_unload (plugin); | ||
64 | plugin = ANASTASIS_DB_plugin_load (cfg); | ||
65 | } | ||
66 | ANASTASIS_DB_plugin_unload (plugin); | ||
67 | } | ||
68 | |||
69 | |||
70 | /** | ||
71 | * The main function of the database initialization tool. | ||
72 | * Used to initialize the Anastasis' database. | ||
73 | * | ||
74 | * @param argc number of arguments from the command line | ||
75 | * @param argv command line arguments | ||
76 | * @return 0 ok, 1 on error | ||
77 | */ | ||
78 | int | ||
79 | main (int argc, | ||
80 | char *const *argv) | ||
81 | { | ||
82 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
83 | |||
84 | GNUNET_GETOPT_option_flag ('r', | ||
85 | "reset", | ||
86 | "reset database (DANGEROUS: all existing data is lost!)", | ||
87 | &reset_db), | ||
88 | |||
89 | GNUNET_GETOPT_OPTION_END | ||
90 | }; | ||
91 | |||
92 | /* force linker to link against libtalerutil; if we do | ||
93 | not do this, the linker may "optimize" libtalerutil | ||
94 | away and skip #TALER_OS_init(), which we do need */ | ||
95 | (void) TALER_project_data_default (); | ||
96 | GNUNET_OS_init (ANASTASIS_project_data_default ()); | ||
97 | GNUNET_assert (GNUNET_OK == | ||
98 | GNUNET_log_setup ("anastasis-dbinit", | ||
99 | "INFO", | ||
100 | NULL)); | ||
101 | if (GNUNET_OK != | ||
102 | GNUNET_PROGRAM_run (argc, argv, | ||
103 | "anastasis-dbinit", | ||
104 | "Initialize anastasis database", | ||
105 | options, | ||
106 | &run, NULL)) | ||
107 | return 1; | ||
108 | return global_ret; | ||
109 | } | ||
110 | |||
111 | |||
112 | /* end of anastasis-dbinit.c */ | ||