GNUnet 0.22.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);
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}
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 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.
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
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
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_OS_project_data_gnunet(), 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 156 of file gnunet-namestore-dbtool.c.

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 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.
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
Definition of a command line option.

References _, gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_string(), GNUNET_log_setup(), GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_PROGRAM_run(), 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().