aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-11-14 22:33:33 +0100
committerChristian Grothoff <christian@grothoff.org>2024-11-14 22:33:33 +0100
commit0869773b5cc3aca0edf675e29294d560631e86ac (patch)
treea3534862e1855aaed3f337fe84064165f76d8ecf
parent15980ee476270bc0af4dc1327be0744ce1e6194e (diff)
new util/ dir with PD
-rw-r--r--src/include/taler_merchant_util.h32
-rw-r--r--src/util/.gitignore1
-rw-r--r--src/util/Makefile.am39
-rw-r--r--src/util/merchant-paths.conf34
-rw-r--r--src/util/os_installation.c62
-rw-r--r--src/util/taler-merchant-config.c73
6 files changed, 241 insertions, 0 deletions
diff --git a/src/include/taler_merchant_util.h b/src/include/taler_merchant_util.h
new file mode 100644
index 00000000..8ca6e9af
--- /dev/null
+++ b/src/include/taler_merchant_util.h
@@ -0,0 +1,32 @@
+/*
+ This file is part of GNU Taler
+ Copyright (C) 2024 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 include/taler_merchant_util.h
+ * @brief Interface for common utility functions
+ * @author Christian Grothoff
+ */
+#ifndef TALER_MERCHANT__UTIL_H
+#define TALER_MERCHANT_UTIL_H
+
+#include <gnunet/gnunet_util_lib.h>
+
+/**
+ * Return default project data used by Taler merchant.
+ */
+const struct GNUNET_OS_ProjectData *
+TALER_MERCHANT_project_data (void);
+
+#endif
diff --git a/src/util/.gitignore b/src/util/.gitignore
new file mode 100644
index 00000000..dc7568d4
--- /dev/null
+++ b/src/util/.gitignore
@@ -0,0 +1 @@
+taler-merchant-config
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
new file mode 100644
index 00000000..c06de792
--- /dev/null
+++ b/src/util/Makefile.am
@@ -0,0 +1,39 @@
+# This Makefile.am is in the public domain
+AM_CPPFLAGS = -I$(top_srcdir)/src/include $(LIBGCRYPT_CFLAGS)
+
+if USE_COVERAGE
+ AM_CFLAGS = --coverage -O0
+ XLIB = -lgcov
+endif
+
+
+pkgcfgdir = $(prefix)/share/sync/config.d/
+
+pkgcfg_DATA = \
+ merchant-paths.conf
+
+bin_PROGRAMS = \
+ taler-merchant-config
+
+taler_merchant_config_SOURCES = \
+ taler-merchant-config.c
+taler_merchant_config_LDADD = \
+ libtalermerchantutil.la \
+ -lgnunetutil \
+ $(XLIB)
+
+EXTRA_DIST = \
+ $(bin_SCRIPTS) \
+ $(pkgcfg_DATA)
+
+lib_LTLIBRARIES = \
+ libtalermerchantutil.la
+
+libtalermerchantutil_la_SOURCES = \
+ os_installation.c
+libtalermerchantutil_la_LIBADD = \
+ -lgnunetutil \
+ $(XLIB)
+libtalermerchantutil_la_LDFLAGS = \
+ -version-info 0:0:0 \
+ -export-dynamic -no-undefined
diff --git a/src/util/merchant-paths.conf b/src/util/merchant-paths.conf
new file mode 100644
index 00000000..b328a49f
--- /dev/null
+++ b/src/util/merchant-paths.conf
@@ -0,0 +1,34 @@
+[PATHS]
+# The PATHS section is special, as filenames including $-expression are
+# expanded using the values from PATHS or the system environment (PATHS
+# is checked first). libgnunetutil supports expanding $-expressions using
+# defaults with the syntax "${VAR:-default}". Here, "default" can again
+# be a $-expression.
+#
+# We usually want $HOME for $TALER_HOME
+#
+TALER_HOME = ${HOME:-${USERPROFILE}}
+
+# see XDG Base Directory Specification at
+# http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
+# for how these should be used.
+
+# Persistent data storage
+TALER_DATA_HOME = ${XDG_DATA_HOME:-$TALER_HOME/.local/share}/sync/
+
+# Configuration files
+TALER_CONFIG_HOME = ${XDG_CONFIG_HOME:-$TALER_HOME/.config}/sync/
+
+# Cached data, no big deal if lost
+TALER_CACHE_HOME = ${XDG_CACHE_HOME:-$TALER_HOME/.cache}/sync/
+
+# Runtime data (i.e UNIX domain sockets, locks, always lost on system boot)
+TALER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/sync-runtime/
+
+# Directory to use for temporary files.
+TALER_TMP = ${TMPDIR:-${TMP:-/tmp}}/sync/
+
+# DEFAULTCONFIG = /etc/sync.conf
+# If 'DEFAULTCONFIG' is not defined, the current
+# configuration file is assumed to be the default,
+# which is what we want by default...
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
new file mode 100644
index 00000000..322710f1
--- /dev/null
+++ b/src/util/os_installation.c
@@ -0,0 +1,62 @@
+/*
+ This file is part of GNU Taler.
+ Copyright (C) 2019 Taler Systems SA
+
+ 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, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+/**
+ * @file os_installation.c
+ * @brief initialize libgnunet OS subsystem for taler-merchant.
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include "taler_merchant_util.h"
+
+
+/**
+ * Default project data used for installation path detection
+ * for GNU Taler merchant.
+ */
+static const struct GNUNET_OS_ProjectData merchant_pd = {
+ .libname = "libtalermerchantutil",
+ .project_dirname = "taler",
+ .binary_name = "taler-merchant-httpd",
+ .env_varname = "TALER_PREFIX",
+ .base_config_varname = "TALER_BASE_CONFIG",
+ .bug_email = "taler@lists.gnu.org",
+ .homepage = "http://www.gnu.org/s/taler/",
+ .config_file = "taler.conf",
+ .user_config_file = "~/.config/taler.conf",
+ .version = PACKAGE_VERSION,
+ .is_gnu = 1,
+ .gettext_domain = "taler",
+ .gettext_path = NULL,
+};
+
+
+/**
+ * Return default project data used by Taler merchant.
+ */
+const struct GNUNET_OS_ProjectData *
+TALER_MERCHANT_project_data (void)
+{
+ return &merchant_pd;
+}
+
+
+/* end of os_installation.c */
diff --git a/src/util/taler-merchant-config.c b/src/util/taler-merchant-config.c
new file mode 100644
index 00000000..150c9f06
--- /dev/null
+++ b/src/util/taler-merchant-config.c
@@ -0,0 +1,73 @@
+/*
+ This file is part of Taler.
+ Copyright (C) 2012-2024 Taler Systems SA
+
+ Taler is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ 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
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
+ */
+
+/**
+ * @file util/taler-merchant-config.c
+ * @brief tool to access and manipulate Taler merchant configuration files
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_merchant_util.h"
+
+
+/**
+ * Program to manipulate configuration files.
+ *
+ * @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_CONFIGURATION_ConfigSettings cs = {
+ .api_version = GNUNET_UTIL_VERSION,
+ .global_ret = EXIT_SUCCESS
+ };
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_help (TALER_MERCHANT_project_data (),
+ "taler-merchant-config [OPTIONS]"),
+ GNUNET_GETOPT_option_version (TALER_MERCHANT_project_data ()->version),
+ GNUNET_CONFIGURATION_CONFIG_OPTIONS (&cs),
+ GNUNET_GETOPT_OPTION_END
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ ret = GNUNET_PROGRAM_run (
+ TALER_MERCHANT_project_data (),
+ argc,
+ argv,
+ "taler-merchant-config [OPTIONS]",
+ gettext_noop (
+ "Manipulate taler-merchant configuration files"),
+ options,
+ &GNUNET_CONFIGURATION_config_tool_run,
+ &cs);
+ GNUNET_CONFIGURATION_config_settings_free (&cs);
+ if (GNUNET_NO == ret)
+ return 0;
+ if (GNUNET_SYSERR == ret)
+ return EXIT_INVALIDARGUMENT;
+ return cs.global_ret;
+}
+
+
+/* end of sync-config.c */