aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/gnunet-namestore-dbtool.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/gnunet-namestore-dbtool.c')
-rw-r--r--src/namestore/gnunet-namestore-dbtool.c55
1 files changed, 33 insertions, 22 deletions
diff --git a/src/namestore/gnunet-namestore-dbtool.c b/src/namestore/gnunet-namestore-dbtool.c
index a1ecf5e71..835d7a228 100644
--- a/src/namestore/gnunet-namestore-dbtool.c
+++ b/src/namestore/gnunet-namestore-dbtool.c
@@ -59,6 +59,8 @@ do_shutdown (void *cls)
59 if (NULL != pluginname) 59 if (NULL != pluginname)
60 GNUNET_free (pluginname); 60 GNUNET_free (pluginname);
61} 61}
62
63
62/** 64/**
63 * Main function that will be run. 65 * Main function that will be run.
64 * 66 *
@@ -74,7 +76,6 @@ run (void *cls,
74 const struct GNUNET_CONFIGURATION_Handle *cfg) 76 const struct GNUNET_CONFIGURATION_Handle *cfg)
75{ 77{
76 char *db_lib_name; 78 char *db_lib_name;
77 char *emsg;
78 struct GNUNET_NAMESTORE_PluginFunctions *plugin; 79 struct GNUNET_NAMESTORE_PluginFunctions *plugin;
79 80
80 (void) cls; 81 (void) cls;
@@ -86,7 +87,8 @@ run (void *cls,
86 _ ("Superfluous command line arguments (starting with `%s') ignored\n"), 87 _ ("Superfluous command line arguments (starting with `%s') ignored\n"),
87 args[0]); 88 args[0]);
88 89
89 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, (void *) cfg); 90 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
91 (void *) cfg);
90 if (NULL == pluginname) 92 if (NULL == pluginname)
91 { 93 {
92 fprintf (stderr, "No plugin given!\n"); 94 fprintf (stderr, "No plugin given!\n");
@@ -94,11 +96,15 @@ run (void *cls,
94 GNUNET_SCHEDULER_shutdown (); 96 GNUNET_SCHEDULER_shutdown ();
95 return; 97 return;
96 } 98 }
97 GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", pluginname); 99 GNUNET_asprintf (&db_lib_name,
100 "libgnunet_plugin_namestore_%s",
101 pluginname);
98 plugin = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg); 102 plugin = GNUNET_PLUGIN_load (db_lib_name, (void *) cfg);
99 if (NULL == plugin) 103 if (NULL == plugin)
100 { 104 {
101 fprintf (stderr, "Failed to load %s!\n", db_lib_name); 105 fprintf (stderr,
106 "Failed to load %s!\n",
107 db_lib_name);
102 ret = 1; 108 ret = 1;
103 GNUNET_SCHEDULER_shutdown (); 109 GNUNET_SCHEDULER_shutdown ();
104 GNUNET_free (db_lib_name); 110 GNUNET_free (db_lib_name);
@@ -106,34 +112,33 @@ run (void *cls,
106 } 112 }
107 if (reset) 113 if (reset)
108 { 114 {
109 if (GNUNET_OK != plugin->reset_database (plugin->cls, &emsg)) 115 if (GNUNET_OK !=
116 plugin->drop_tables (plugin->cls))
110 { 117 {
111 // FIXME do we want to return a reason? 118 fprintf (stderr,
112 fprintf (stderr, "Failed to reset database: %s\n", 119 "Failed to reset database\n");
113 emsg);
114 ret = 1; 120 ret = 1;
115 GNUNET_free (emsg);
116 GNUNET_free (db_lib_name); 121 GNUNET_free (db_lib_name);
117 GNUNET_SCHEDULER_shutdown (); 122 GNUNET_SCHEDULER_shutdown ();
118 return; 123 return;
119 } 124 }
120 } 125 }
121 else if (init) 126 if (init || reset)
122 { 127 {
123 if (GNUNET_OK != plugin->initialize_database (plugin->cls, &emsg)) 128 if (GNUNET_OK !=
129 plugin->create_tables (plugin->cls))
124 { 130 {
125 // FIXME do we want to return a reason? 131 fprintf (stderr,
126 fprintf (stderr, "Failed to initialize database: %s\n", 132 "Failed to initialize database\n");
127 emsg);
128 ret = 1; 133 ret = 1;
129 GNUNET_free (emsg);
130 GNUNET_free (db_lib_name); 134 GNUNET_free (db_lib_name);
131 GNUNET_SCHEDULER_shutdown (); 135 GNUNET_SCHEDULER_shutdown ();
132 return; 136 return;
133 } 137 }
134 } 138 }
135 GNUNET_SCHEDULER_shutdown (); 139 GNUNET_SCHEDULER_shutdown ();
136 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, plugin)); 140 GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name,
141 plugin));
137 GNUNET_free (db_lib_name); 142 GNUNET_free (db_lib_name);
138} 143}
139 144
@@ -148,9 +153,10 @@ run (void *cls,
148int 153int
149main (int argc, char *const *argv) 154main (int argc, char *const *argv)
150{ 155{
151 struct GNUNET_GETOPT_CommandLineOption options[] = 156 struct GNUNET_GETOPT_CommandLineOption options[] = {
152 { GNUNET_GETOPT_option_flag ('i', "init", gettext_noop ( 157 GNUNET_GETOPT_option_flag ('i', "init",
153 "initialize database"), &init), 158 gettext_noop ("initialize database"),
159 &init),
154 GNUNET_GETOPT_option_flag ('r', 160 GNUNET_GETOPT_option_flag ('r',
155 "reset", 161 "reset",
156 gettext_noop ( 162 gettext_noop (
@@ -163,13 +169,18 @@ main (int argc, char *const *argv)
163 gettext_noop ( 169 gettext_noop (
164 "the namestore plugin to work with, e.g. 'sqlite'"), 170 "the namestore plugin to work with, e.g. 'sqlite'"),
165 &pluginname), 171 &pluginname),
166 GNUNET_GETOPT_OPTION_END }; 172 GNUNET_GETOPT_OPTION_END
173 };
167 int lret; 174 int lret;
168 175
169 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 176 if (GNUNET_OK !=
177 GNUNET_STRINGS_get_utf8_args (argc, argv,
178 &argc, &argv))
170 return 2; 179 return 2;
171 180
172 GNUNET_log_setup ("gnunet-namestore-dbtool", "WARNING", NULL); 181 GNUNET_log_setup ("gnunet-namestore-dbtool",
182 "WARNING",
183 NULL);
173 if (GNUNET_OK != 184 if (GNUNET_OK !=
174 (lret = GNUNET_PROGRAM_run (argc, 185 (lret = GNUNET_PROGRAM_run (argc,
175 argv, 186 argv,