GNUnet 0.22.2
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);
104 (void *) cfg);
105 if (NULL == plugin)
106 {
107 fprintf (stderr,
108 "Failed to load %s!\n",
110 ret = 1;
113 return;
114 }
115 if (reset)
116 {
117 if (GNUNET_OK !=
118 plugin->drop_tables (plugin->cls))
119 {
120 fprintf (stderr,
121 "Failed to reset database\n");
122 ret = 1;
125 return;
126 }
127 }
128 if (init || reset)
129 {
130 if (GNUNET_OK !=
131 plugin->create_tables (plugin->cls))
132 {
133 fprintf (stderr,
134 "Failed to initialize database\n");
135 ret = 1;
138 return;
139 }
140 }
143 plugin));
145}
146
147
155int
156main (int argc, char *const *argv)
157{
159 GNUNET_GETOPT_option_flag ('i', "init",
160 gettext_noop ("initialize database"),
161 &init),
163 "reset",
165 "reset database (DANGEROUS: All existing data is lost!"),
166 &reset),
168 'p',
169 "plugin",
170 "PLUGIN",
172 "the namestore plugin to work with, e.g. 'sqlite'"),
173 &pluginname),
175 };
176 int lret;
177
178 GNUNET_log_setup ("gnunet-namestore-dbtool",
179 "WARNING",
180 NULL);
181 if (GNUNET_OK !=
183 argc,
184 argv,
185 "gnunet-namestore-dbtool",
186 _ (
187 "GNUnet namestore database manipulation tool"),
188 options,
189 &run,
190 NULL)))
191 {
192 return lret;
193 }
194 return ret;
195}
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:74
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static struct GNUNET_TESTING_PluginFunctions * plugin
Plugin to dynamically load a test case.
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.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
void * GNUNET_PLUGIN_load(const struct GNUNET_OS_ProjectData *pd, const char *library_name, void *arg)
Setup plugin (runs the "init" callback and returns whatever "init" returned).
Definition: plugin.c:221
void * GNUNET_PLUGIN_unload(const char *library_name, void *arg)
Unload plugin (runs the "done" callback and returns whatever "done" returned).
Definition: plugin.c:277
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, 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:407
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:1339
#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.
void * cls
Closure to pass to start_testcase.