summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-01-31 18:39:29 +0100
committerFlorian Dold <florian.dold@gmail.com>2018-01-31 18:39:29 +0100
commit07cc75f2055ba4ae77d8272ea2cedffbb54b6842 (patch)
tree1511bfbb94b06f37b13247ce59fba80da5251368 /src/lib
parent7cc075796dd82a4d6e8e0e60433445afb589accf (diff)
downloadmerchant-07cc75f2055ba4ae77d8272ea2cedffbb54b6842.tar.gz
merchant-07cc75f2055ba4ae77d8272ea2cedffbb54b6842.tar.bz2
merchant-07cc75f2055ba4ae77d8272ea2cedffbb54b6842.zip
use url helpers from taler util
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Makefile.am1
-rw-r--r--src/lib/merchant_api_check_payment.c15
-rw-r--r--src/lib/merchant_api_common.c136
-rw-r--r--src/lib/merchant_api_common.h49
-rw-r--r--src/lib/merchant_api_history.c4
-rw-r--r--src/lib/merchant_api_pay.c4
-rw-r--r--src/lib/merchant_api_pay_abort.c3
-rw-r--r--src/lib/merchant_api_proposal.c7
-rw-r--r--src/lib/merchant_api_refund.c4
-rw-r--r--src/lib/merchant_api_tip_authorize.c4
-rw-r--r--src/lib/merchant_api_tip_pickup.c4
-rw-r--r--src/lib/merchant_api_track_transaction.c4
-rw-r--r--src/lib/merchant_api_track_transfer.c19
13 files changed, 22 insertions, 232 deletions
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index d407ee01..79f26749 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -14,7 +14,6 @@ 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_tip_authorize.c \
diff --git a/src/lib/merchant_api_check_payment.c b/src/lib/merchant_api_check_payment.c
index 0b5b3148..98e844de 100644
--- a/src/lib/merchant_api_check_payment.c
+++ b/src/lib/merchant_api_check_payment.c
@@ -30,7 +30,6 @@
#include "taler_merchant_service.h"
#include <taler/taler_json_lib.h>
#include <taler/taler_signatures.h>
-#include "merchant_api_common.h"
/**
@@ -206,13 +205,13 @@ TALER_MERCHANT_check_payment (struct GNUNET_CURL_Context *ctx,
cpo->ctx = ctx;
cpo->cb = check_payment_cb;
cpo->cb_cls = check_payment_cb_cls;
- cpo->url = MAH_make_url (backend_url, "/check-payment",
- "instance", instance,
- "order_id", order_id,
- "resource_url", resource_url,
- "session_id", session_id,
- "session_sig", session_sig,
- NULL);
+ cpo->url = TALER_url_join (backend_url, "/check-payment",
+ "instance", instance,
+ "order_id", order_id,
+ "resource_url", resource_url,
+ "session_id", session_id,
+ "session_sig", session_sig,
+ NULL);
eh = curl_easy_init ();
if (CURLE_OK != curl_easy_setopt (eh,
CURLOPT_URL,
diff --git a/src/lib/merchant_api_common.c b/src/lib/merchant_api_common.c
deleted file mode 100644
index c5b4a782..00000000
--- a/src/lib/merchant_api_common.c
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- 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 <curl/curl.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 URL 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;
-}
-
-
-/**
- * Concatenate two strings and grow the first buffer (of size n)
- * if necessary.
- */
-#define STR_CAT_GROW(s, p, n) do { \
- for (; strlen (s) + strlen (p) >= n; (n) = (n) * 2); \
- (s) = GNUNET_realloc ((s), (n)); \
- GNUNET_assert (NULL != (s)); \
- strncat (s, p, n); \
- } while (0)
-
-
-/**
- * Make an absolute URL with query parameters.
- *
- * @param base_url absolute base URL to use
- * @param path path of the url
- * @param ... NULL-terminated key-value pairs (char *) for query parameters
- * @returns the URL, must be freed with #GNUNET_free
- */
-char *
-MAH_make_url (const char *base_url,
- const char *path,
- ...)
-{
- static CURL *curl = NULL;
- if (NULL == curl)
- {
- curl = curl_easy_init();
- GNUNET_assert (NULL != curl);
- }
-
- size_t n = 256;
- char *res = GNUNET_malloc (n);
-
- GNUNET_assert (NULL != res);
-
- STR_CAT_GROW (res, base_url, n);
-
- if ( ('/' == path[0]) &&
- (0 < strlen (base_url)) &&
- ('/' == base_url[strlen (base_url) - 1]) )
- {
- /* avoid generating URL with "//" from concat */
- path++;
- }
- else if ( ('/' != path[0]) &&
- ('/' != base_url[strlen (base_url) - 1]))
- {
- /* put '/' between path and base URL if necessary */
- STR_CAT_GROW (res, "/", n);
- }
-
- STR_CAT_GROW (res, path, n);
-
- va_list args;
- va_start (args, path);
-
- unsigned int iparam = 0;
-
- while (1) {
- char *key = va_arg (args, char *);
- if (NULL == key)
- break;
- char *value = va_arg (args, char *);
- if (NULL == value)
- continue;
- if (0 == iparam)
- STR_CAT_GROW (res, "?", n);
- else
- STR_CAT_GROW (res, "&", n);
- iparam++;
- char *urlencoded_value = curl_easy_escape (curl, value, strlen (value));
- STR_CAT_GROW (res, key, n);
- STR_CAT_GROW (res, "=", n);
- STR_CAT_GROW (res, urlencoded_value, n);
- curl_free (urlencoded_value);
- }
-
- va_end (args);
-
- return res;
-}
-
-/* end of merchant_api_common.c */
diff --git a/src/lib/merchant_api_common.h b/src/lib/merchant_api_common.h
deleted file mode 100644
index c94287fb..00000000
--- a/src/lib/merchant_api_common.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- 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 URL to use with cURL
- */
-char *
-MAH_path_to_url_ (const char *base_url,
- const char *path);
-
-/**
- * Make an absolute URL with query parameters.
- *
- * @param base_url absolute base URL to use
- * @param path path of the url
- * @param ... NULL-terminated key-value pairs (char *) for query parameters
- * @returns the URL, must be freed with #GNUNET_free
- */
-char *
-MAH_make_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 8aa38dca..0a3e01a4 100644
--- a/src/lib/merchant_api_history.c
+++ b/src/lib/merchant_api_history.c
@@ -27,7 +27,6 @@
#include <gnunet/gnunet_curl_lib.h>
#include "taler_merchant_service.h"
#include <taler/taler_json_lib.h>
-#include "merchant_api_common.h"
/**
@@ -167,8 +166,7 @@ TALER_MERCHANT_history (struct GNUNET_CURL_Context *ctx,
ho->cb = history_cb;
ho->cb_cls = history_cb_cls;
seconds = date.abs_value_us / 1000LL / 1000LL;
- base = MAH_path_to_url_ (backend_url,
- "/history");
+ base = TALER_url_join (backend_url, "/history", NULL);
GNUNET_asprintf (&ho->url,
"%s?date=%llu&instance=%s&start=%d&delta=%d",
base,
diff --git a/src/lib/merchant_api_pay.c b/src/lib/merchant_api_pay.c
index 9b05467e..849b22be 100644
--- a/src/lib/merchant_api_pay.c
+++ b/src/lib/merchant_api_pay.c
@@ -29,7 +29,6 @@
#include <taler/taler_json_lib.h>
#include <taler/taler_signatures.h>
#include <taler/taler_exchange_service.h>
-#include "merchant_api_common.h"
/**
@@ -564,8 +563,7 @@ request_pay_generic (struct GNUNET_CURL_Context *ctx,
ph->abort_cb_cls = abort_cb_cls;
ph->pay_cb = pay_cb;
ph->pay_cb_cls = pay_cb_cls;
- ph->url = MAH_path_to_url_ (merchant_url,
- "/public/pay");
+ ph->url = TALER_url_join (merchant_url, "/public/pay", NULL);
ph->num_coins = num_coins;
ph->coins = GNUNET_new_array (num_coins,
struct TALER_MERCHANT_PaidCoin);
diff --git a/src/lib/merchant_api_pay_abort.c b/src/lib/merchant_api_pay_abort.c
index d9fb2e14..eb7d2194 100644
--- a/src/lib/merchant_api_pay_abort.c
+++ b/src/lib/merchant_api_pay_abort.c
@@ -440,8 +440,7 @@ TALER_MERCHANT_pay_wallet (struct GNUNET_CURL_Context *ctx,
ph->ctx = ctx;
ph->cb = pay_cb;
ph->cb_cls = pay_cb_cls;
- ph->url = MAH_path_to_url_ (merchant_url,
- "/pay");
+ ph->url = TALER_url_join (merchant_url, "/pay", NULL);
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 936e0eb1..8f4f67f5 100644
--- a/src/lib/merchant_api_proposal.c
+++ b/src/lib/merchant_api_proposal.c
@@ -29,7 +29,6 @@
#include "taler_merchant_service.h"
#include <taler/taler_json_lib.h>
#include <taler/taler_signatures.h>
-#include "merchant_api_common.h"
/**
@@ -215,8 +214,7 @@ TALER_MERCHANT_order_put (struct GNUNET_CURL_Context *ctx,
po->ctx = ctx;
po->cb = proposal_cb;
po->cb_cls = proposal_cb_cls;
- po->url = MAH_path_to_url_ (backend_url,
- "/order");
+ po->url = TALER_url_join (backend_url, "/order", NULL);
req = json_pack ("{s:O}",
"order", (json_t *) order);
eh = curl_easy_init ();
@@ -373,8 +371,7 @@ TALER_MERCHANT_proposal_lookup (struct GNUNET_CURL_Context *ctx,
plo->ctx = ctx;
plo->cb = plo_cb;
plo->cb_cls = plo_cb_cls;
- base = MAH_path_to_url_ (backend_url,
- "/public/proposal");
+ base = TALER_url_join (backend_url, "/public/proposal", NULL);
if (NULL != nonce)
{
char *nonce_str;
diff --git a/src/lib/merchant_api_refund.c b/src/lib/merchant_api_refund.c
index 0307c42f..01fa6bd3 100644
--- a/src/lib/merchant_api_refund.c
+++ b/src/lib/merchant_api_refund.c
@@ -30,7 +30,6 @@
#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
@@ -196,8 +195,7 @@ TALER_MERCHANT_refund_increase (struct GNUNET_CURL_Context *ctx,
rio->ctx = ctx;
rio->cb = cb;
rio->cb_cls = cb_cls;
- rio->url = MAH_path_to_url_ (backend_url,
- "/refund");
+ rio->url = TALER_url_join (backend_url, "/refund", NULL);
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_tip_authorize.c b/src/lib/merchant_api_tip_authorize.c
index e9b263b9..f27d06f8 100644
--- a/src/lib/merchant_api_tip_authorize.c
+++ b/src/lib/merchant_api_tip_authorize.c
@@ -29,7 +29,6 @@
#include "taler_merchant_service.h"
#include <taler/taler_json_lib.h>
#include <taler/taler_signatures.h>
-#include "merchant_api_common.h"
/**
@@ -203,8 +202,7 @@ TALER_MERCHANT_tip_authorize (struct GNUNET_CURL_Context *ctx,
tao->ctx = ctx;
tao->cb = authorize_cb;
tao->cb_cls = authorize_cb_cls;
- tao->url = MAH_path_to_url_ (backend_url,
- "/tip-authorize");
+ tao->url = TALER_url_join (backend_url, "/tip-authorize", NULL);
te_obj = json_pack ("{"
" s:o," /* amount */
" s:s," /* instance */
diff --git a/src/lib/merchant_api_tip_pickup.c b/src/lib/merchant_api_tip_pickup.c
index 4ca3b80c..3bf38e48 100644
--- a/src/lib/merchant_api_tip_pickup.c
+++ b/src/lib/merchant_api_tip_pickup.c
@@ -29,7 +29,6 @@
#include "taler_merchant_service.h"
#include <taler/taler_json_lib.h>
#include <taler/taler_signatures.h>
-#include "merchant_api_common.h"
/**
@@ -282,8 +281,7 @@ TALER_MERCHANT_tip_pickup (struct GNUNET_CURL_Context *ctx,
tpo->ctx = ctx;
tpo->cb = pickup_cb;
tpo->cb_cls = pickup_cb_cls;
- tpo->url = MAH_path_to_url_ (backend_url,
- "/public/tip-pickup");
+ tpo->url = TALER_url_join (backend_url, "/public/tip-pickup", NULL);
if (NULL == (tpo->json_enc =
json_dumps (tp_obj,
JSON_COMPACT)))
diff --git a/src/lib/merchant_api_track_transaction.c b/src/lib/merchant_api_track_transaction.c
index d48916a6..e38660c2 100644
--- a/src/lib/merchant_api_track_transaction.c
+++ b/src/lib/merchant_api_track_transaction.c
@@ -30,7 +30,6 @@
#include "taler_merchant_service.h"
#include <taler/taler_json_lib.h>
#include <taler/taler_signatures.h>
-#include "merchant_api_common.h"
/**
@@ -152,8 +151,7 @@ TALER_MERCHANT_track_transaction (struct GNUNET_CURL_Context *ctx,
tdo->ctx = ctx;
tdo->cb = track_transaction_cb;
tdo->cb_cls = track_transaction_cb_cls;
- base = MAH_path_to_url_ (backend_url,
- "/track/transaction");
+ base = TALER_url_join (backend_url, "/track/transaction", NULL);
GNUNET_asprintf (&tdo->url,
"%s?order_id=%s&instance=%s",
base,
diff --git a/src/lib/merchant_api_track_transfer.c b/src/lib/merchant_api_track_transfer.c
index c55d5440..7c78532f 100644
--- a/src/lib/merchant_api_track_transfer.c
+++ b/src/lib/merchant_api_track_transfer.c
@@ -30,7 +30,6 @@
#include "taler_merchant_service.h"
#include <taler/taler_json_lib.h>
#include <taler/taler_signatures.h>
-#include "merchant_api_common.h"
/**
@@ -236,7 +235,6 @@ 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));
@@ -244,17 +242,12 @@ TALER_MERCHANT_track_transfer (struct GNUNET_CURL_Context *ctx,
tdo->ctx = 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_url' here? */
- base = MAH_path_to_url_ (backend_url,
- "/track/transfer");
- GNUNET_asprintf (&tdo->url,
- "%s?wtid=%s&exchange=%s&instance=%s&wire_method=%s",
- base,
- wtid_str,
- exchange_url,
- instance,
- wire_method);
- GNUNET_free (base);
+ tdo->url = TALER_url_join (backend_url, "/track/transfer",
+ "wtid", wtid_str,
+ "exchange", exchange_url,
+ "instance", instance,
+ "wire_method", wire_method,
+ NULL);
GNUNET_free (wtid_str);
eh = curl_easy_init ();
GNUNET_assert (CURLE_OK ==