GNUnet 0.21.2
gnunet-namestore-dbtool.c File Reference

command line tool to manipulate the database backends for the namestore More...

#include "platform.h"
#include <gnunet_util_lib.h>
#include <gnunet_namestore_plugin.h>
Include dependency graph for gnunet-namestore-dbtool.c:

Go to the source code of this file.

Functions

static void do_shutdown (void *cls)
 Task run on shutdown. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main function that will be run. More...
 
int main (int argc, char *const *argv)
 The main function for gnunet-namestore-dbtool. More...
 

Variables

static char * pluginname
 Name of the plugin argument. More...
 
static int reset
 Reset argument. More...
 
static int init
 Initialize argument. More...
 
static int ret = 0
 Return code. More...
 

Detailed Description

command line tool to manipulate the database backends for the namestore

Author
Martin Schanzenbach

Definition in file gnunet-namestore-dbtool.c.

Function Documentation

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Task run on shutdown.

Cleans up everything.

Parameters
clsunused

Definition at line 56 of file gnunet-namestore-dbtool.c.

57{
58 (void) cls;
59 if (NULL != pluginname)
61}
static char * pluginname
Name of the plugin argument.
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_free, and pluginname.

Referenced by run().

Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Main function that will be run.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfgconfiguration

Definition at line 73 of file gnunet-namestore-dbtool.c.

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}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static struct GNUNET_TESTING_PluginFunctions * plugin
Plugin to dynamically load a test case.
static int ret
Return code.
static void do_shutdown(void *cls)
Task run on shutdown.
static int init
Initialize argument.
static int reset
Reset argument.
static char * db_lib_name
Name of the database plugin.
#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.
@ GNUNET_ERROR_TYPE_WARNING
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
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
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
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
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.

References _, consensus-simulation::args, cfg, GNUNET_NAMESTORE_PluginFunctions::cls, GNUNET_TESTING_PluginFunctions::cls, db_lib_name, do_shutdown(), GNUNET_asprintf(), GNUNET_break, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_PLUGIN_load(), GNUNET_PLUGIN_unload(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), init, plugin, pluginname, reset, and ret.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function for gnunet-namestore-dbtool.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 154 of file gnunet-namestore-dbtool.c.

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:74
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
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.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_free_nz(ptr)
Wrapper around free.
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
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
Definition of a command line option.

References _, gettext_noop, GNUNET_free_nz, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_string(), GNUNET_log_setup(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), init, options, pluginname, reset, ret, and run().

Here is the call graph for this function:

Variable Documentation

◆ pluginname

char* pluginname
static

Name of the plugin argument.

Definition at line 33 of file gnunet-namestore-dbtool.c.

Referenced by do_shutdown(), main(), and run().

◆ reset

int reset
static

Reset argument.

Definition at line 38 of file gnunet-namestore-dbtool.c.

Referenced by handle_member_id(), join_room(), main(), notify_srv_handle_member_id(), and run().

◆ init

int init
static

Initialize argument.

Definition at line 43 of file gnunet-namestore-dbtool.c.

Referenced by main(), and run().

◆ ret

int ret = 0
static

Return code.

Definition at line 48 of file gnunet-namestore-dbtool.c.

Referenced by main(), and run().