summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/Makefile.am1
-rw-r--r--src/lib/merchant_api_common.c50
-rw-r--r--src/lib/merchant_api_common.h36
-rw-r--r--src/lib/merchant_api_history.c11
-rw-r--r--src/lib/merchant_api_pay.c10
-rw-r--r--src/lib/merchant_api_proposal.c19
-rw-r--r--src/lib/merchant_api_refund.c7
-rw-r--r--src/lib/merchant_api_track_transaction.c9
-rw-r--r--src/lib/merchant_api_track_transfer.c9
9 files changed, 125 insertions, 27 deletions
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 803a5117..1955dd70 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 00000000..05e2637a
--- /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 00000000..683f1dbd
--- /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 c002d0a2..efc20be1 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 e5f7249c..e65ecb4c 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 1e340dff..fa7e6b68 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 7c88f5b5..3ed7bc1a 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 560408f2..25a88b77 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 fcd208ce..f0b65903 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 ==