gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-merchant] branch master updated: add taler-merchant-


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated: add taler-merchant-tip-enable, including docs
Date: Sat, 04 Nov 2017 11:51:35 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 65d6a48  add taler-merchant-tip-enable, including docs
65d6a48 is described below

commit 65d6a4851e9544fded2b776fb955900598744f96
Author: Christian Grothoff <address@hidden>
AuthorDate: Sat Nov 4 11:51:30 2017 +0100

    add taler-merchant-tip-enable, including docs
---
 .gitignore                                     |   2 +
 doc/Makefile.am                                |  21 +-
 doc/taler-merchant-httpd.1                     |  37 ++++
 doc/taler-merchant-tip-enable.1                |  47 +++++
 src/merchant-tools/Makefile.am                 |  14 +-
 src/merchant-tools/taler-merchant-tip-enable.c | 277 +++++++++++++++++++++++++
 6 files changed, 392 insertions(+), 6 deletions(-)

diff --git a/.gitignore b/.gitignore
index 5c692c1..1f27591 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,6 +36,7 @@ taler_merchant_config.h.in
 doc/*
 !doc/*.texi
 !doc/*.css
+!doc/*.1
 doc/version.texi
 !doc/*.am
 !doc/*.sh
@@ -46,3 +47,4 @@ src/merchant-tools/mitm/taler-merchant-mitm
 src/merchant-tools/mitm/merchant-mitm.wsgi
 doxygen-doc/
 contrib/taler-merchant.tag
+src/merchant-tools/taler-merchant-tip-enable
diff --git a/doc/Makefile.am b/doc/Makefile.am
index fdfea96..e20e333 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -11,13 +11,26 @@ arch.jpg: arch.dot
 
 AM_MAKEINFOHTMLFLAGS = --no-split --css-ref=docstyle.css 
--css-ref=brown-paper.css
 
+man_MANS = \
+  taler-merchant-tip-enable.1 \
+  taler-merchant-httpd.1
+
 info_TEXINFOS = manual.texi
+
 manual_TEXINFOS = version.texi
 
+extra_TEXINFOS = \
+  fdl-1.3.texi \
+  agpl.texi \
+  syntax.texi
+
 EXTRA_DIST = \
   arch.dot \
-  lgpl.texi \
-  agpl.texi \
-  fdl-1.3.texi \
+  $(extra_TEXINFOS) \
   docstyle.css \
-  brown-paper.css
+  brown-paper.css \
+  $(man_MANS)
+
+DISTCLEANFILES = \
+  manual.cps \
+  manual.dvi
diff --git a/doc/taler-merchant-httpd.1 b/doc/taler-merchant-httpd.1
new file mode 100644
index 0000000..7e34587
--- /dev/null
+++ b/doc/taler-merchant-httpd.1
@@ -0,0 +1,37 @@
+.TH TALER\-MERCHANT\-HTTPD 1 "Nov 4, 2017" "GNU Taler"
+
+.SH NAME
+taler\-merchant\-httpd \- Run Taler merchant backend (with RESTful API)
+
+.SH SYNOPSIS
+.B taler\-merchant\-httpd
+.RI [ options ]
+.br
+
+.SH DESCRIPTION
+\fBtaler\-merchant\-httpd\fP is a command line tool to run the Taler merchant 
(HTTP backend).  The required configuration and database must exist before 
running this command.
+
+.SH OPTIONS
+.B
+.IP "\-C,  \-\-connection-close"
+Force each HTTP connection to be closed after each request (useful in 
combination with \-f to avoid having to wait for nc to time out).
+.B
+.IP "\-c FILENAME,  \-\-config=FILENAME"
+Use the configuration and other resources for the merchant to operate from 
FILENAME.
+.B
+.IP "\-h, \-\-help"
+Print short help on options.
+.B
+.IP "\-v, \-\-version"
+Print version information.
+
+.SH SIGNALS
+.B
+.IP SIGTERM
+Sending a SIGTERM to the process will cause it to shutdown cleanly.
+
+.SH BUGS
+Report bugs by using Mantis <https://gnunet.org/bugs/> or by sending 
electronic mail to <address@hidden>
+
+.SH "SEE ALSO"
+\fBtaler\-merchant\-dbinit\fP(1), \fBtaler\-merchant\-tip\-enable\fP(1), 
\fBtaler.conf\fP(5)
diff --git a/doc/taler-merchant-tip-enable.1 b/doc/taler-merchant-tip-enable.1
new file mode 100644
index 0000000..b61504b
--- /dev/null
+++ b/doc/taler-merchant-tip-enable.1
@@ -0,0 +1,47 @@
+.TH TALER\-MERCHANT\-TIP\-ENABLE 1 "Nov 4, 2017" "GNU Taler"
+
+.SH NAME
+taler\-merchant\-tip\-enable \- Tell Taler merchant backend about reserve 
funding for tipping
+
+.SH SYNOPSIS
+.B taler\-merchant\-tip\-enable
+.RI [ options ]
+.br
+
+.SH DESCRIPTION
+\fBtaler\-merchant\-tip\-enable\fP is a command line tool to inform the Taler 
merchant backend that a wire transfer was made to enable tipping from the 
backend.  Note that the command cannot check that the wire transfer was made 
correctly (with the correct wire subject and the specified amount), and will 
thus just trust the operator.  Enabling tipping at an instance without a wire 
transfer may cause visitors to receive unfunded tips and experience error 
messages.  You should read the man [...]
+
+.SH OPTIONS
+.B
+.IP "\-a VALUE,  \-\-amount=VALUE"
+Which amount was transferred into the reserve at the exchange.  Must be of the 
format CUR:VALUE.FRACTION.
+.B
+.IP "\-b URI,  \-\-backend=URI"
+At which URI does the backend run that we are to inform about the availability 
of funding for tipping?
+.B
+.IP "\-C UUID,  \-\-credit-uuid=UUID"
+What is the UUID of the wire transfer.  The backend will automatically detect 
if the same UUID is used repeatedly, and ignore multiple invocations.  Pass a 
UUID generated by the wire transfer of the bank.
+.B
+.IP "\-e TIMESTAMP,  \-\-expiration=TIMESTAMP"
+When does the reserve expire.  Determining this value may today require 
information from the exchange operator.
+.B
+.IP "\-h, \-\-help"
+Print short help on options.
+.B
+.IP "\-i NAME, \-\-instance=NAME"
+Name of the instance where tipping is to be enabled.  The instance must have 
the reserve (private) key and exchange URI already configured. Note that this 
command-line tool must also have access to the same configuration with the 
instance's private key in it.
+.B
+.IP "\-v, \-\-version"
+Print version information.
+.B
+
+.SH SIGNALS
+.B
+.IP SIGTERM
+Sending a SIGTERM to the process will cause it to shutdown cleanly.
+
+.SH BUGS
+Report bugs by using Mantis <https://gnunet.org/bugs/> or by sending 
electronic mail to <address@hidden>
+
+.SH "SEE ALSO"
+\fBtaler\-merchant\-httpd\fP(1), \fBtaler.conf\fP(5)
diff --git a/src/merchant-tools/Makefile.am b/src/merchant-tools/Makefile.am
index fb950e1..df271a2 100644
--- a/src/merchant-tools/Makefile.am
+++ b/src/merchant-tools/Makefile.am
@@ -3,7 +3,8 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/include
 
 bin_PROGRAMS = \
   taler-merchant-dbinit \
-  taler-merchant-generate-payments
+  taler-merchant-generate-payments \
+  taler-merchant-tip-enable
 
 taler_merchant_dbinit_SOURCES = \
   taler-merchant-dbinit.c
@@ -15,6 +16,16 @@ taler_merchant_dbinit_LDADD = \
   -ltalerutil \
   -ltalerpq
 
+taler_merchant_tip_enable_SOURCES = \
+  taler-merchant-tip-enable.c
+
+taler_merchant_tip_enable_LDADD = \
+  $(LIBGCRYPT_LIBS) \
+  $(top_builddir)/src/lib/libtalermerchant.la \
+  -lgnunetcurl \
+  -lgnunetutil \
+  -ltalerutil
+
 taler_merchant_generate_payments_SOURCES = \
   taler-merchant-generate-payments.c
 
@@ -30,4 +41,3 @@ taler_merchant_generate_payments_LDADD = \
   -lgnunetcurl \
   -lgnunetutil \
   -ljansson
-
diff --git a/src/merchant-tools/taler-merchant-tip-enable.c 
b/src/merchant-tools/taler-merchant-tip-enable.c
new file mode 100644
index 0000000..776d10a
--- /dev/null
+++ b/src/merchant-tools/taler-merchant-tip-enable.c
@@ -0,0 +1,277 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2017 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 merchant-tools/taler-merchant-tip-enable.c
+ * @brief enable tips by telling the backend that a reserve was charged
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <taler/taler_util.h>
+#include <gnunet/gnunet_util_lib.h>
+#include "taler_merchant_service.h"
+#include <microhttpd.h> /* just for HTTP status code, no need to link against 
*/
+
+/**
+ * Return value from main().
+ */
+static int global_ret;
+
+/**
+ * -a option: how much money was deposited into the reserve
+ */
+static struct TALER_Amount amount;
+
+/**
+ * For which instance did we charge the reserve?
+ */
+static char *instance;
+
+/**
+ * Under which URI does the backend run?
+ */
+static char *backend_uri;
+
+/**
+ * UUID of the wire transfer.
+ */
+static char *credit_uuid;
+
+/**
+ * Expiration time for the reserve.
+ */
+static struct GNUNET_TIME_Absolute expiration;
+
+/**
+ * Main execution context for the main loop of the exchange.
+ */
+static struct GNUNET_CURL_Context *ctx;
+
+/**
+ * Context for running the #ctx's event loop.
+ */
+static struct GNUNET_CURL_RescheduleContext *rc;
+
+/**
+ * Handle for the /tip-enable operation.
+ */
+static struct TALER_MERCHANT_TipEnableOperation *teo;
+
+
+/**
+ * Function run when the test terminates (good or bad).
+ * Cleans up our state.
+ *
+ * @param cls the interpreter state.
+ */
+static void
+do_shutdown (void *cls)
+{
+  if (NULL != teo)
+  {
+    TALER_MERCHANT_tip_enable_cancel (teo);
+    teo = NULL;
+  }
+  if (NULL != ctx)
+  {
+    GNUNET_CURL_fini (ctx);
+    ctx = NULL;
+  }
+  if (NULL != rc)
+  {
+    GNUNET_CURL_gnunet_rc_destroy (rc);
+    rc = NULL;
+  }
+}
+
+
+/**
+ * Callback for a /tip-enable request.  Returns the result of
+ * the operation.
+ *
+ * @param cls closure
+ * @param http_status HTTP status returned by the merchant backend
+ * @param ec taler-specific error code
+ */
+static void
+enable_cb (void *cls,
+           unsigned int http_status,
+           enum TALER_ErrorCode ec)
+{
+  teo = NULL;
+  GNUNET_SCHEDULER_shutdown ();
+  if ( (MHD_HTTP_OK == http_status) &&
+       (TALER_EC_NONE == ec) )
+  {
+    global_ret = 0;
+    return;
+  }
+  fprintf (stderr,
+           "Failed with HTTP status %u and error code %u\n",
+           http_status,
+           ec);
+  global_ret = 3;
+}
+
+
+/**
+ * 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 TALER_ReservePrivateKeyP reserve_priv;
+  char *section;
+  char *res_str;
+  struct GNUNET_HashCode hcredit_uuid;
+  struct GNUNET_CURL_Context *ctx;
+
+  GNUNET_asprintf (&section,
+                   "merchant-instance-%s",
+                   instance);
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_filename (cfg,
+                                               section,
+                                               "TIP_RESERVE_PRIV",
+                                               &res_str))
+  {
+    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+                               section,
+                               "TIP_RESERVE_PRIV");
+    GNUNET_free (section);
+    global_ret = 1;
+    return;
+  }
+  if (GNUNET_OK !=
+      GNUNET_STRINGS_string_to_data (res_str,
+                                     strlen (res_str),
+                                     &reserve_priv,
+                                     sizeof (struct TALER_ReservePrivateKeyP)))
+  {
+    GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+                               section,
+                               "TIP_RESERVE_PRIV",
+                               "Must decode to private EdDSA key");
+    GNUNET_free (section);
+    GNUNET_free (res_str);
+    global_ret = 1;
+    return;
+  }
+  GNUNET_free (res_str);
+  GNUNET_free (section);
+
+  GNUNET_CRYPTO_hash (credit_uuid,
+                      strlen (credit_uuid),
+                      &hcredit_uuid);
+
+  ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
+                          &rc);
+  if (NULL == ctx)
+  {
+    GNUNET_break (0);
+    global_ret = 1;
+    return;
+  }
+  rc = GNUNET_CURL_gnunet_rc_create (ctx);
+  teo = TALER_MERCHANT_tip_enable (ctx,
+                                   backend_uri,
+                                   &amount,
+                                   expiration,
+                                   &reserve_priv,
+                                   &hcredit_uuid,
+                                   &enable_cb,
+                                   NULL);
+  GNUNET_assert (NULL != teo);
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+                                 NULL);
+}
+
+
+/**
+ * The main function of the database initialization tool.
+ * Used to initialize the Taler Exchange's 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_mandatory
+    (TALER_getopt_get_amount ('a',
+                              "amount",
+                              "VALUE",
+                              "value that was added to the reserve",
+                              &amount)),
+    GNUNET_GETOPT_option_mandatory
+    (GNUNET_GETOPT_option_string ('b',
+                                  "backend",
+                                  "URI",
+                                  "URI of the backend to use",
+                                  &backend_uri)),
+    GNUNET_GETOPT_option_mandatory
+    (GNUNET_GETOPT_option_string ('C',
+                                  "credit-uuid",
+                                  "UUID",
+                                  "unique identifier of the wire transfer (to 
detect duplicate invocations)",
+                                  &credit_uuid)),
+    GNUNET_GETOPT_option_mandatory
+    (GNUNET_GETOPT_option_absolute_time ('e',
+                                         "expiration",
+                                         "TIMESTAMP",
+                                         "when does the reserve expire",
+                                         &expiration)),
+    GNUNET_GETOPT_option_mandatory
+    (GNUNET_GETOPT_option_string ('i',
+                                  "instance",
+                                  "NAME",
+                                  "name of the instance of which the reserve 
was charged",
+                                  &instance)),
+    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) TALER_project_data_default ();
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_log_setup ("taler-merchant-tip-enable",
+                                   "INFO",
+                                   NULL));
+  global_ret = 2;
+  if (GNUNET_OK !=
+      GNUNET_PROGRAM_run (argc, argv,
+                          "taler-merchant-tip-enable",
+                         "Enable tipping by telling the backend that a reserve 
was charged",
+                         options,
+                         &run,
+                          NULL))
+    return 1;
+  return global_ret;
+}
+
+
+/* end of taler-exchange-tip-enable.c */

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]