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 (507eebd -> 2563686)


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated (507eebd -> 2563686)
Date: Sun, 25 Jun 2017 12:36:07 +0200

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

grothoff pushed a change to branch master
in repository merchant.

    from 507eebd  caring about 'summary' field
     new a63f515  do use return value of iterate_instances()
     new 633a9b6  use default log level of WARNING
     new 2563686  handle '/' at end of URLs when composing http requests in 
libtalermerchant

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 doc/version.texi                         |  4 +--
 src/backend/taler-merchant-httpd.c       | 27 +++++++++--------
 src/lib/Makefile.am                      |  1 +
 src/lib/merchant_api_common.c            | 50 ++++++++++++++++++++++++++++++++
 src/lib/merchant_api_common.h            | 36 +++++++++++++++++++++++
 src/lib/merchant_api_history.c           | 11 ++++---
 src/lib/merchant_api_pay.c               | 10 +++----
 src/lib/merchant_api_proposal.c          | 19 ++++++------
 src/lib/merchant_api_refund.c            |  7 ++---
 src/lib/merchant_api_track_transaction.c |  9 ++++--
 src/lib/merchant_api_track_transfer.c    |  9 ++++--
 11 files changed, 142 insertions(+), 41 deletions(-)
 create mode 100644 src/lib/merchant_api_common.c
 create mode 100644 src/lib/merchant_api_common.h

diff --git a/doc/version.texi b/doc/version.texi
index acbfcb4..2a18a25 100644
--- a/doc/version.texi
+++ b/doc/version.texi
@@ -1,4 +1,4 @@
address@hidden UPDATED 31 May 2017
address@hidden UPDATED-MONTH May 2017
address@hidden UPDATED 2 June 2017
address@hidden UPDATED-MONTH June 2017
 @set EDITION 0.3.0
 @set VERSION 0.3.0
diff --git a/src/backend/taler-merchant-httpd.c 
b/src/backend/taler-merchant-httpd.c
index 44831cc..9f0da2b 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -663,7 +663,7 @@ get_instance (struct json_t *json)
  * @return #GNUNET_OK if successful, #GNUNET_SYSERR upon errors
  * (for example, if no "default" instance is defined)
  */
-static unsigned int
+static int
 iterate_instances (const struct GNUNET_CONFIGURATION_Handle *config,
                    const char *allowed)
 {
@@ -716,14 +716,11 @@ iterate_instances (const struct 
GNUNET_CONFIGURATION_Handle *config,
   return GNUNET_OK;
 
  fail:
-  do {
-    GNUNET_PLUGIN_unload (lib_name,
-                          iic->plugin);
-    GNUNET_free (lib_name);
-    GNUNET_free (iic);
-    GNUNET_SCHEDULER_shutdown ();
-    return GNUNET_SYSERR;
-  } while (0);
+  GNUNET_PLUGIN_unload (lib_name,
+                       iic->plugin);
+  GNUNET_free (lib_name);
+  GNUNET_free (iic);
+  return GNUNET_SYSERR;
 }
 
 
@@ -750,7 +747,7 @@ run (void *cls,
                                  NULL);
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_log_setup ("taler-merchant-httpd",
-                                   "DEBUG",
+                                   "WARNING",
                                    NULL));
   if (GNUNET_SYSERR ==
       TMH_EXCHANGES_init (config))
@@ -853,8 +850,14 @@ run (void *cls,
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
-  iterate_instances (config,
-                     wireformat);
+  if (GNUNET_OK !=
+      iterate_instances (config,
+                        wireformat))
+  {
+    GNUNET_free (wireformat);
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
   GNUNET_free (wireformat);
 
   if (NULL ==
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 803a511..1955dd7 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -14,6 +14,7 @@ libtalermerchant_la_LDFLAGS = \
   -no-undefined
 
 libtalermerchant_la_SOURCES = \
+  merchant_api_common.c merchant_api_common.h \
   merchant_api_proposal.c \
   merchant_api_pay.c \
   merchant_api_track_transaction.c \
diff --git a/src/lib/merchant_api_common.c b/src/lib/merchant_api_common.c
new file mode 100644
index 0000000..05e2637
--- /dev/null
+++ b/src/lib/merchant_api_common.c
@@ -0,0 +1,50 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2014-2017 GNUnet e.V. and INRIA
+
+  TALER is free software; you can redistribute it and/or modify it under the
+  terms of the GNU Lesser General Public License as published by the Free 
Software
+  Foundation; either version 2.1, 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 Lesser General Public License for more 
details.
+
+  You should have received a copy of the GNU Lesser General Public License 
along with
+  TALER; see the file COPYING.LGPL.  If not, see
+  <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/merchant_api_common.c
+ * @brief Shared functionality
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+
+
+/**
+ * Obtain the URL to use for an API request.
+ *
+ * @param base_url base URL of the exchange (i.e. "http://exchange/";)
+ * @param path Taler API path (i.e. "/reserve/withdraw")
+ * @return the full URI to use with cURL
+ */
+char *
+MAH_path_to_url_ (const char *base_url,
+                 const char *path)
+{
+  char *url;
+
+  if ( ('/' == path[0]) &&
+       (0 < strlen (base_url)) &&
+       ('/' == base_url[strlen (base_url) - 1]) )
+    path++; /* avoid generating URL with "//" from concat */
+  GNUNET_asprintf (&url,
+                   "%s%s",
+                   base_url,
+                   path);
+  return url;
+}
+
+/* end of merchant_api_common.c */
diff --git a/src/lib/merchant_api_common.h b/src/lib/merchant_api_common.h
new file mode 100644
index 0000000..683f1db
--- /dev/null
+++ b/src/lib/merchant_api_common.h
@@ -0,0 +1,36 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2014-2017 GNUnet e.V. and INRIA
+
+  TALER is free software; you can redistribute it and/or modify it under the
+  terms of the GNU Lesser General Public License as published by the Free 
Software
+  Foundation; either version 2.1, 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 Lesser General Public License for more 
details.
+
+  You should have received a copy of the GNU Lesser General Public License 
along with
+  TALER; see the file COPYING.LGPL.  If not, see
+  <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/merchant_api_common.h
+ * @brief Shared functions
+ * @author Christian Grothoff
+ */
+#ifndef MERCHANT_API_COMMON_H
+#define MERCHANT_API_COMMON_H
+
+/**
+ * Obtain the URL to use for an API request.
+ *
+ * @param base_url base URL of the exchange (i.e. "http://exchange/";)
+ * @param path Taler API path (i.e. "/reserve/withdraw")
+ * @return the full URI to use with cURL
+ */
+char *
+MAH_path_to_url_ (const char *base_url,
+                 const char *path);
+
+#endif
diff --git a/src/lib/merchant_api_history.c b/src/lib/merchant_api_history.c
index c002d0a..efc20be 100644
--- a/src/lib/merchant_api_history.c
+++ b/src/lib/merchant_api_history.c
@@ -27,6 +27,7 @@
 #include <gnunet/gnunet_curl_lib.h>
 #include "taler_merchant_service.h"
 #include <taler/taler_json_lib.h>
+#include "merchant_api_common.h"
 
 
 /**
@@ -159,21 +160,23 @@ TALER_MERCHANT_history (struct GNUNET_CURL_Context *ctx,
   struct TALER_MERCHANT_HistoryOperation *ho;
   uint64_t seconds;
   CURL *eh;
+  char *base;
 
   ho = GNUNET_new (struct TALER_MERCHANT_HistoryOperation);
   ho->ctx = ctx;
   ho->cb = history_cb;
   ho->cb_cls = history_cb_cls;
   seconds = date.abs_value_us / 1000LL / 1000LL;
-
+  base = MAH_path_to_url_ (backend_uri,
+                          "/history");
   GNUNET_asprintf (&ho->url,
-                   "%s/history?date=%llu&instance=%s&start=%d&delta=%d",
-                   backend_uri,
+                   "%s?date=%llu&instance=%s&start=%d&delta=%d",
+                   base,
                    seconds,
                    instance,
                    start,
                    delta);
-
+  GNUNET_free (base);
   eh = curl_easy_init ();
   if (CURLE_OK != curl_easy_setopt (eh,
                                     CURLOPT_URL,
diff --git a/src/lib/merchant_api_pay.c b/src/lib/merchant_api_pay.c
index e5f7249..e65ecb4 100644
--- a/src/lib/merchant_api_pay.c
+++ b/src/lib/merchant_api_pay.c
@@ -29,6 +29,7 @@
 #include <taler/taler_json_lib.h>
 #include <taler/taler_signatures.h>
 #include <taler/taler_exchange_service.h>
+#include "merchant_api_common.h"
 
 
 /**
@@ -150,7 +151,6 @@ check_forbidden (struct TALER_MERCHANT_Pay *ph,
     GNUNET_JSON_spec_fixed_auto ("coin_pub", &coin_pub),
     GNUNET_JSON_spec_end()
   };
-  unsigned int i;
   int ret;
 
   if (GNUNET_OK !=
@@ -161,7 +161,7 @@ check_forbidden (struct TALER_MERCHANT_Pay *ph,
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
-  for (i=0;i<ph->num_coins;i++)
+  for (unsigned int i=0;i<ph->num_coins;i++)
   {
     if (0 == memcmp (&ph->coins[i].coin_pub,
                      &coin_pub,
@@ -479,10 +479,8 @@ TALER_MERCHANT_pay_frontend (struct GNUNET_CURL_Context 
*ctx,
   ph->ctx = ctx;
   ph->cb = pay_cb;
   ph->cb_cls = pay_cb_cls;
-  GNUNET_asprintf (&ph->url,
-                   "%s%s",
-                   merchant_uri,
-                   "/pay");
+  ph->url = MAH_path_to_url_ (merchant_uri,
+                             "/pay");
   ph->num_coins = num_coins;
   ph->coins = GNUNET_new_array (num_coins,
                                 struct TALER_MERCHANT_PaidCoin);
diff --git a/src/lib/merchant_api_proposal.c b/src/lib/merchant_api_proposal.c
index 1e340df..fa7e6b6 100644
--- a/src/lib/merchant_api_proposal.c
+++ b/src/lib/merchant_api_proposal.c
@@ -1,6 +1,6 @@
 /*
   This file is part of TALER
-  Copyright (C) 2014, 2015, 2016 GNUnet e.V. and INRIA
+  Copyright (C) 2014-2017 GNUnet e.V. and INRIA
 
   TALER is free software; you can redistribute it and/or modify it under the
   terms of the GNU Lesser General Public License as published by the Free 
Software
@@ -29,6 +29,7 @@
 #include "taler_merchant_service.h"
 #include <taler/taler_json_lib.h>
 #include <taler/taler_signatures.h>
+#include "merchant_api_common.h"
 
 
 /**
@@ -218,11 +219,8 @@ TALER_MERCHANT_order_put (struct GNUNET_CURL_Context *ctx,
   po->ctx = ctx;
   po->cb = proposal_cb;
   po->cb_cls = proposal_cb_cls;
-  GNUNET_asprintf (&po->url,
-                   "%s%s",
-                   backend_uri,
-                   "/proposal");
-
+  po->url = MAH_path_to_url_ (backend_uri,
+                             "/proposal");
   req = json_pack ("{s:O}",
                    "order", (json_t *) order);
   eh = curl_easy_init ();
@@ -303,17 +301,20 @@ TALER_MERCHANT_proposal_lookup (struct 
GNUNET_CURL_Context *ctx,
 {
   struct TALER_MERCHANT_ProposalLookupOperation *plo;
   CURL *eh;
+  char *base;
 
   plo = GNUNET_new (struct TALER_MERCHANT_ProposalLookupOperation);
   plo->ctx = ctx;
   plo->cb = plo_cb;
   plo->cb_cls = plo_cb_cls;
-
+  base = MAH_path_to_url_ (backend_uri,
+                          "/proposal");
   GNUNET_asprintf (&plo->url,
-                   "%s/proposal?order_id=%s&instance=%s",
-                   backend_uri,
+                   "%s?order_id=%s&instance=%s",
+                   base,
                    order_id,
                    instance);
+  GNUNET_free (base);
   eh = curl_easy_init ();
   if (CURLE_OK != curl_easy_setopt (eh,
                                     CURLOPT_URL,
diff --git a/src/lib/merchant_api_refund.c b/src/lib/merchant_api_refund.c
index 7c88f5b..3ed7bc1 100644
--- a/src/lib/merchant_api_refund.c
+++ b/src/lib/merchant_api_refund.c
@@ -30,6 +30,7 @@
 #include "taler_merchant_service.h"
 #include <taler/taler_json_lib.h>
 #include <taler/taler_signatures.h>
+#include "merchant_api_common.h"
 
 
 struct TALER_MERCHANT_RefundLookupOperation
@@ -195,10 +196,8 @@ TALER_MERCHANT_refund_increase (struct GNUNET_CURL_Context 
*ctx,
   rio->ctx = ctx;
   rio->cb = cb;
   rio->cb_cls = cb_cls;
-  GNUNET_asprintf (&rio->url,
-                   "%s%s",
-                   backend_uri,
-                   "/refund");
+  rio->url = MAH_path_to_url_ (backend_uri,
+                              "/refund");
   req = json_pack ("{s:o, s:s, s:s, s:s}",
                    "refund", TALER_JSON_from_amount (refund),
                    "order_id", order_id,
diff --git a/src/lib/merchant_api_track_transaction.c 
b/src/lib/merchant_api_track_transaction.c
index 560408f..25a88b7 100644
--- a/src/lib/merchant_api_track_transaction.c
+++ b/src/lib/merchant_api_track_transaction.c
@@ -30,6 +30,7 @@
 #include "taler_merchant_service.h"
 #include <taler/taler_json_lib.h>
 #include <taler/taler_signatures.h>
+#include "merchant_api_common.h"
 
 
 /**
@@ -168,16 +169,20 @@ TALER_MERCHANT_track_transaction (struct 
GNUNET_CURL_Context *ctx,
 {
   struct TALER_MERCHANT_TrackTransactionHandle *tdo;
   CURL *eh;
+  char *base;
 
   tdo = GNUNET_new (struct TALER_MERCHANT_TrackTransactionHandle);
   tdo->ctx = ctx;
   tdo->cb = track_transaction_cb;
   tdo->cb_cls = track_transaction_cb_cls;
+  base = MAH_path_to_url_ (backend_uri,
+                          "/track/transaction");
   GNUNET_asprintf (&tdo->url,
-                   "%s/track/transaction?order_id=%s&instance=%s",
-                   backend_uri,
+                   "%s?order_id=%s&instance=%s",
+                   base,
                    order_id,
                    instance);
+  GNUNET_free (base);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Requesting URI '%s'\n",
               tdo->url);
diff --git a/src/lib/merchant_api_track_transfer.c 
b/src/lib/merchant_api_track_transfer.c
index fcd208c..f0b6590 100644
--- a/src/lib/merchant_api_track_transfer.c
+++ b/src/lib/merchant_api_track_transfer.c
@@ -30,6 +30,7 @@
 #include "taler_merchant_service.h"
 #include <taler/taler_json_lib.h>
 #include <taler/taler_signatures.h>
+#include "merchant_api_common.h"
 
 
 /**
@@ -234,6 +235,7 @@ TALER_MERCHANT_track_transfer (struct GNUNET_CURL_Context 
*ctx,
   struct TALER_MERCHANT_TrackTransferHandle *tdo;
   CURL *eh;
   char *wtid_str;
+  char *base;
 
   wtid_str = GNUNET_STRINGS_data_to_string_alloc (wtid,
                                                   sizeof (struct 
TALER_WireTransferIdentifierRawP));
@@ -242,12 +244,15 @@ TALER_MERCHANT_track_transfer (struct GNUNET_CURL_Context 
*ctx,
   tdo->cb = track_transfer_cb; // very last to be called
   tdo->cb_cls = track_transfer_cb_cls;
   /* TODO: do we need to escape 'exchange_uri' here? */
+  base = MAH_path_to_url_ (backend_uri,
+                          "/track/transfer");
   GNUNET_asprintf (&tdo->url,
-                   "%s/track/transfer?wtid=%s&exchange=%s&instance=%s",
-                   backend_uri,
+                   "%s?wtid=%s&exchange=%s&instance=%s",
+                   base,
                    wtid_str,
                    exchange_uri,
                   instance);
+  GNUNET_free (base);
   GNUNET_free (wtid_str);
   eh = curl_easy_init ();
   GNUNET_assert (CURLE_OK ==

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



reply via email to

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