GNUnet 0.21.1
gnunet-namestore-dbtool.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012, 2013, 2014, 2019, 2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
26#include "platform.h"
27#include <gnunet_util_lib.h>
29
33static char *pluginname;
34
38static int reset;
39
43static int init;
44
48static int ret = 0;
49
55static void
56do_shutdown (void *cls)
57{
58 (void) cls;
59 if (NULL != pluginname)
61}
62
63
72static void
73run (void *cls,
74 char *const *args,
75 const char *cfgfile,
76 const struct GNUNET_CONFIGURATION_Handle *cfg)
77{
78 char *db_lib_name;
80
81 (void) cls;
82 (void) args;
83 (void) cfgfile;
84 if (NULL != args[0])
87 _ ("Superfluous command line arguments (starting with `%s') ignored\n"),
88 args[0]);
89
91 (void *) cfg);
92 if (NULL == pluginname)
93 {
94 fprintf (stderr, "No plugin given!\n");
95 ret = 1;
97 return;
98 }
100 "libgnunet_plugin_namestore_%s",
101 pluginname);
103 if (NULL == plugin)
104 {
105 fprintf (stderr,
106 "Failed to load %s!\n",
108 ret = 1;
111 return;
112 }
113 if (reset)
114 {
115 if (GNUNET_OK !=
116 plugin->drop_tables (plugin->cls))
117 {
118 fprintf (stderr,
119 "Failed to reset database\n");
120 ret = 1;
123 return;
124 }
125 }
126 if (init || reset)
127 {
128 if (GNUNET_OK !=
129 plugin->create_tables (plugin->cls))
130 {
131 fprintf (stderr,
132 "Failed to initialize database\n");
133 ret = 1;
136 return;
137 }
138 }
141 plugin));
143}
144
145
153int
154main (int argc, char *const *argv)
155{
157 GNUNET_GETOPT_option_flag ('i', "init",
158 gettext_noop ("initialize database"),
159 &init),
161 "reset",
163 "reset database (DANGEROUS: All existing data is lost!"),
164 &reset),
166 'p',
167 "plugin",
168 "PLUGIN",
170 "the namestore plugin to work with, e.g. 'sqlite'"),
171 &pluginname),
173 };
174 int lret;
175
176 if (GNUNET_OK !=
178 &argc, &argv))
179 return 2;
180
181 GNUNET_log_setup ("gnunet-namestore-dbtool",
182 "WARNING",
183 NULL);
184 if (GNUNET_OK !=
185 (lret = GNUNET_PROGRAM_run (argc,
186 argv,
187 "gnunet-namestore-dbtool",
188 _ (
189 "GNUnet namestore database manipulation tool"),
190 options,
191 &run,
192 NULL)))
193 {
194 GNUNET_free_nz ((void *) argv);
195 return lret;
196 }
197 GNUNET_free_nz ((void *) argv);
198 return ret;
199}
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:70
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
struct TestcasePlugin * plugin
The process handle to the testbed service.
static char * pluginname
Name of the plugin argument.
static int ret
Return code.
static void do_shutdown(void *cls)
Task run on shutdown.
static int init
Initialize argument.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
int main(int argc, char *const *argv)
The main function for gnunet-namestore-dbtool.
static int reset
Reset argument.
static char * db_lib_name
Name of the database plugin.
Plugin API for the namestore database backend.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
#define GNUNET_log(kind,...)
@ GNUNET_OK
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
@ GNUNET_ERROR_TYPE_WARNING
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_free_nz(ptr)
Wrapper around free.
void * GNUNET_PLUGIN_load(const char *library_name, void *arg)
Setup plugin (runs the "init" callback and returns whatever "init" returned).
Definition: plugin.c:198
void * GNUNET_PLUGIN_unload(const char *library_name, void *arg)
Unload plugin (runs the "done" callback and returns whatever "done" returned).
Definition: plugin.c:242
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:400
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:567
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1340
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1230
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Definition of a command line option.
struct returned by the initialization function of the plugin
void * cls
Closure to pass to all plugin functions.