summaryrefslogtreecommitdiff
path: root/src/sync
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-11-14 23:05:49 +0100
committerChristian Grothoff <christian@grothoff.org>2019-11-14 23:05:49 +0100
commitd0e22221b9fd3627d63e484b8957337d2638a871 (patch)
tree257264263bb958d064f8f9d4ce78452d8b80f35f /src/sync
parentbbfb54908340c34d5f1b4058526f664c7a321125 (diff)
downloadsync-d0e22221b9fd3627d63e484b8957337d2638a871.tar.gz
sync-d0e22221b9fd3627d63e484b8957337d2638a871.tar.bz2
sync-d0e22221b9fd3627d63e484b8957337d2638a871.zip
update config
Diffstat (limited to 'src/sync')
-rw-r--r--src/sync/Makefile.am7
-rw-r--r--src/sync/sync-httpd.c48
-rw-r--r--src/sync/sync-httpd.h10
-rw-r--r--src/sync/sync-httpd_terms.c51
-rw-r--r--src/sync/sync-httpd_terms.h43
-rw-r--r--src/sync/sync.conf7
6 files changed, 158 insertions, 8 deletions
diff --git a/src/sync/Makefile.am b/src/sync/Makefile.am
index ad60afe..0bb6703 100644
--- a/src/sync/Makefile.am
+++ b/src/sync/Makefile.am
@@ -11,14 +11,17 @@ bin_PROGRAMS = \
sync_httpd_SOURCES = \
sync-httpd.c sync-httpd.h \
+ sync-httpd_backup.c sync-httpd_backup.h \
+ sync-httpd_mhd.c sync-httpd_mhd.h \
sync-httpd_parsing.c sync-httpd_parsing.h \
sync-httpd_responses.c sync-httpd_responses.h \
- sync-httpd_mhd.c sync-httpd_mhd.h \
- sync-httpd_backup.c sync-httpd_backup.h
+ sync-httpd_terms.c sync-httpd_terms.h
sync_httpd_LDADD = \
$(top_builddir)/src/syncdb/libsyncdb.la \
-lmicrohttpd \
-ljansson \
+ -ltalerjson \
+ -ltalerutil \
-lgnunetcurl \
-lgnunetjson \
-lgnunetutil
diff --git a/src/sync/sync-httpd.c b/src/sync/sync-httpd.c
index beb0e20..d7f6eb5 100644
--- a/src/sync/sync-httpd.c
+++ b/src/sync/sync-httpd.c
@@ -27,6 +27,7 @@
#include "sync-httpd_mhd.h"
#include "sync_database_lib.h"
#include "sync-httpd_backup.h"
+#include "sync-httpd_terms.h"
/**
* Backlog for listen operation on unix-domain sockets.
@@ -44,6 +45,16 @@ static long long unsigned port;
int SH_sync_connection_close;
/**
+ * Upload limit to the service, in megabytes.
+ */
+unsigned long long int SH_upload_limit_mb;
+
+/**
+ * Annual fee for the backup account.
+ */
+struct TALER_Amount SH_annual_fee;
+
+/**
* Task running the HTTP server.
*/
static struct GNUNET_SCHEDULER_Task *mhd_task;
@@ -76,17 +87,17 @@ struct SYNC_DatabasePlugin *db;
/**
- * Return GNUNET_YES if given a valid correlation ID and
- * GNUNET_NO otherwise.
+ * Return #GNUNET_YES if given a valid correlation ID and
+ * #GNUNET_NO otherwise.
*
- * @returns GNUNET_YES iff given a valid correlation ID
+ * @returns #GNUNET_YES iff given a valid correlation ID
*/
static int
is_valid_correlation_id (const char *correlation_id)
{
if (strlen (correlation_id) >= 64)
return GNUNET_NO;
- for (int i = 0; i < strlen (correlation_id); i++)
+ for (size_t i = 0; i < strlen (correlation_id); i++)
if (! (isalnum (correlation_id[i]) || (correlation_id[i] == '-')))
return GNUNET_NO;
return GNUNET_YES;
@@ -150,6 +161,9 @@ url_handler (void *cls,
{ "/agpl", MHD_HTTP_METHOD_GET, "text/plain",
NULL, 0,
&SH_MHD_handler_agpl_redirect, MHD_HTTP_FOUND },
+ { "/terms", MHD_HTTP_METHOD_GET, "text/plain",
+ NULL, 0,
+ &SH_handler_terms, MHD_HTTP_OK },
{NULL, NULL, NULL, NULL, 0, 0 }
};
static struct SH_RequestHandler h404 = {
@@ -439,7 +453,6 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Starting sync-httpd\n");
-
result = GNUNET_SYSERR;
GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
NULL);
@@ -447,6 +460,31 @@ run (void *cls,
GNUNET_log_setup ("sync-httpd",
"WARNING",
NULL));
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (config,
+ "sync",
+ "UPLOAD_LIMIT_MB",
+ &SH_upload_limit_mb))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "sync",
+ "UPLOAD_LIMIT_MB");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_config_get_denom (config,
+ "sync",
+ "ANNUAL_FEE",
+ &SH_annual_fee))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "sync",
+ "ANNUAL_FEE");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+
if (NULL ==
(db = SYNC_DB_plugin_load (config)))
{
diff --git a/src/sync/sync-httpd.h b/src/sync/sync-httpd.h
index 53c4f40..c2e76a3 100644
--- a/src/sync/sync-httpd.h
+++ b/src/sync/sync-httpd.h
@@ -137,6 +137,16 @@ extern int SH_sync_connection_close;
extern struct SYNC_DatabasePlugin *db;
/**
+ * Upload limit to the service, in megabytes.
+ */
+extern unsigned long long SH_upload_limit_mb;
+
+/**
+ * Annual fee for the backup account.
+ */
+extern struct TALER_Amount SH_annual_fee;
+
+/**
* Kick MHD to run now, to be called after MHD_resume_connection().
* Basically, we need to explicitly resume MHD's event loop whenever
* we made progress serving a request. This function re-schedules
diff --git a/src/sync/sync-httpd_terms.c b/src/sync/sync-httpd_terms.c
new file mode 100644
index 0000000..710f2c6
--- /dev/null
+++ b/src/sync/sync-httpd_terms.c
@@ -0,0 +1,51 @@
+/*
+ This file is part of TALER
+ (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 sync/sync-httpd_terms.c
+ * @brief headers for /terms handler
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "sync-httpd_responses.h"
+#include "sync-httpd_terms.h"
+#include <taler/taler_json_lib.h>
+
+/**
+ * Manages a /terms call.
+ *
+ * @param rh context of the handler
+ * @param connection the MHD connection to handle
+ * @param[in,out] connection_cls the connection's closure (can be updated)
+ * @param upload_data upload data
+ * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
+ * @param mi merchant backend instance, never NULL
+ * @return MHD result code
+ */
+int
+SH_handler_terms (struct SH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ void **connection_cls,
+ const char *upload_data,
+ size_t *upload_data_size)
+{
+ return SH_RESPONSE_reply_json_pack (connection,
+ MHD_HTTP_OK,
+ "{s:I, s:o}",
+ "storage_limit_in_megabytes",
+ (json_int_t) SH_upload_limit_mb,
+ "annual_fee",
+ TALER_JSON_from_amount (&SH_annual_fee));
+}
diff --git a/src/sync/sync-httpd_terms.h b/src/sync/sync-httpd_terms.h
new file mode 100644
index 0000000..d6c538e
--- /dev/null
+++ b/src/sync/sync-httpd_terms.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ (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 sync/sync-httpd_terms.h
+ * @brief headers for /terms handler
+ * @author Christian Grothoff Dold
+ */
+#ifndef SYNC_HTTPD_TERMS_H
+#define SYNC_HTTPD_TERMS_H
+#include <microhttpd.h>
+#include "sync-httpd.h"
+
+/**
+ * Manages a /terms call.
+ *
+ * @param rh context of the handler
+ * @param connection the MHD connection to handle
+ * @param[in,out] connection_cls the connection's closure (can be updated)
+ * @param upload_data upload data
+ * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
+ * @return MHD result code
+ */
+int
+SH_handler_terms (struct SH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ void **connection_cls,
+ const char *upload_data,
+ size_t *upload_data_size);
+
+#endif
diff --git a/src/sync/sync.conf b/src/sync/sync.conf
index 9425c22..601241e 100644
--- a/src/sync/sync.conf
+++ b/src/sync/sync.conf
@@ -17,7 +17,6 @@ PORT = 9966
# if left empty. Only used if "SERVE" is 'tcp'.
# BIND_TO =
-
# Which unix domain path should we bind to? Only used if "SERVE" is 'unix'.
UNIXPATH = ${sync_RUNTIME_DIR}/backend.http
# What should be the file access permissions (see chmod) for "UNIXPATH"?
@@ -26,6 +25,12 @@ UNIXPATH_MODE = 660
# Which database backend do we use?
DB = postgres
+# Annual fee for an account
+ANNUAL_FEE = TESTKUDOS:0.1
+
+# Upload limit per backup, in megabytes
+UPLOAD_LIMIT_MB = 16
+
# Configuration for postgres database.
[syncdb-postgres]
CONFIG = postgres:///sync