summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-11-25 16:00:37 +0100
committerChristian Grothoff <christian@grothoff.org>2019-11-25 16:00:37 +0100
commite982d9fe320cb8fe3726af061fec178ba03e5252 (patch)
tree388fb658a0eca5c1a2a3e66564aac12cce2cefb6
parentcbd5fbd796b18916ea032021661397369fbcbd22 (diff)
downloadsync-e982d9fe320cb8fe3726af061fec178ba03e5252.tar.gz
sync-e982d9fe320cb8fe3726af061fec178ba03e5252.tar.bz2
sync-e982d9fe320cb8fe3726af061fec178ba03e5252.zip
add sync-dbinit tool
-rw-r--r--src/include/Makefile.am4
-rw-r--r--src/include/sync_util.h33
-rw-r--r--src/syncdb/.gitignore1
-rw-r--r--src/syncdb/Makefile.am16
-rw-r--r--src/syncdb/sync-dbinit.c111
5 files changed, 162 insertions, 3 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index abcbfe9..21c4d5d 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -5,6 +5,8 @@ EXTRA_DIST = \
talerincludedir = $(includedir)/taler
talerinclude_HEADERS = \
+ sync_database_lib.h \
sync_database_plugin.h \
sync_service.h \
- sync_database_lib.h
+ sync_util.h
+
diff --git a/src/include/sync_util.h b/src/include/sync_util.h
new file mode 100644
index 0000000..86e4fe4
--- /dev/null
+++ b/src/include/sync_util.h
@@ -0,0 +1,33 @@
+/*
+ This file is part of SYNC
+ Copyright (C) 2014, 2015 GNUnet e.V.
+
+ SYNC is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ SYNC is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ SYNC; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file include/sync_util.h
+ * @brief Interface for common utility functions
+ * @author Christian Grothoff
+ */
+#ifndef SYNC_UTIL_H
+#define SYNC_UTIL_H
+
+#include <gnunet/gnunet_util_lib.h>
+
+/**
+ * Return default project data used by Sync.
+ */
+const struct GNUNET_OS_ProjectData *
+SYNC_project_data_default (void);
+
+
+#endif
diff --git a/src/syncdb/.gitignore b/src/syncdb/.gitignore
index e8e02d8..afedfcc 100644
--- a/src/syncdb/.gitignore
+++ b/src/syncdb/.gitignore
@@ -2,3 +2,4 @@ test_sync_db-postgres
.deps
.libs
test-suite.log
+sync-dbinit
diff --git a/src/syncdb/Makefile.am b/src/syncdb/Makefile.am
index e181df9..d5c92fa 100644
--- a/src/syncdb/Makefile.am
+++ b/src/syncdb/Makefile.am
@@ -15,12 +15,24 @@ if USE_COVERAGE
XLIB = -lgcov
endif
+bin_PROGRAMS = \
+ sync-dbinit
+
+sync_dbinit_SOURCES = \
+ sync-dbinit.c
+sync_dbinit_LDADD = \
+ $(LIBGCRYPT_LIBS) \
+ $(top_builddir)/src/util/libsyncutil.la \
+ -lsyncdb \
+ -lgnunetutil \
+ -ltalerutil \
+ -ltalerpq
+
+
lib_LTLIBRARIES = \
libsyncdb.la
-
libsyncdb_la_SOURCES = \
sync_db_plugin.c
-
libsyncdb_la_LIBADD = \
$(top_builddir)/src/util/libsyncutil.la \
-lgnunetpq \
diff --git a/src/syncdb/sync-dbinit.c b/src/syncdb/sync-dbinit.c
new file mode 100644
index 0000000..055060e
--- /dev/null
+++ b/src/syncdb/sync-dbinit.c
@@ -0,0 +1,111 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2019 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file util/sync-dbinit.c
+ * @brief Create tables for the sync database.
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <taler/taler_util.h>
+#include <gnunet/gnunet_util_lib.h>
+#include "sync_util.h"
+#include "sync_database_lib.h"
+
+
+/**
+ * Return value from main().
+ */
+static int global_ret;
+
+/**
+ * -r option: do full DB reset
+ */
+static int reset_db;
+
+/**
+ * Main function that will be run.
+ *
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be NULL!)
+ * @param cfg configuration
+ */
+static void
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ struct SYNC_DatabasePlugin *plugin;
+
+ if (NULL ==
+ (plugin = SYNC_DB_plugin_load (cfg)))
+ {
+ fprintf (stderr,
+ "Failed to initialize database plugin.\n");
+ global_ret = 1;
+ return;
+ }
+ if (reset_db)
+ {
+ (void) plugin->drop_tables (plugin->cls);
+ SYNC_DB_plugin_unload (plugin);
+ plugin = SYNC_DB_plugin_load (cfg);
+ }
+ SYNC_DB_plugin_unload (plugin);
+}
+
+
+/**
+ * The main function of the database initialization tool.
+ * Used to initialize the Sync' database.
+ *
+ * @param argc number of arguments from the command line
+ * @param argv command line arguments
+ * @return 0 ok, 1 on error
+ */
+int
+main (int argc,
+ char *const *argv)
+{
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_flag ('r',
+ "reset",
+ "reset database (DANGEROUS: all existing data is lost!)",
+ &reset_db),
+ GNUNET_GETOPT_OPTION_END
+ };
+
+ /* force linker to link against libtalerutil; if we do
+ not do this, the linker may "optimize" libtalerutil
+ away and skip #TALER_OS_init(), which we do need */
+ (void) SYNC_project_data_default ();
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_log_setup ("sync-dbinit",
+ "INFO",
+ NULL));
+ if (GNUNET_OK !=
+ GNUNET_PROGRAM_run (argc, argv,
+ "sync-dbinit",
+ "Initialize sync database",
+ options,
+ &run, NULL))
+ return 1;
+ return global_ret;
+}
+
+
+/* end of sync-dbinit.c */