summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2018-12-18 11:47:50 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2018-12-18 11:47:50 +0100
commit6bce2eb4247f1fe2922c58cf08bd08a936a244af (patch)
tree450f7fe980d15dc9a8af2cbf9726d4b22fcfddd8
parenta5d0452b2a46f875a1879b2e836d0d5e3ede6167 (diff)
downloadmerchant-6bce2eb4247f1fe2922c58cf08bd08a936a244af.tar.gz
merchant-6bce2eb4247f1fe2922c58cf08bd08a936a244af.tar.bz2
merchant-6bce2eb4247f1fe2922c58cf08bd08a936a244af.zip
/history API.
Provide the (client) API with a mean of omitting the 'start' argument, therefore letting the server use the default.
-rw-r--r--src/include/taler_merchant_service.h22
-rw-r--r--src/lib/merchant_api_history.c120
2 files changed, 124 insertions, 18 deletions
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h
index 9c7ca12c..30059639 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -781,6 +781,28 @@ TALER_MERCHANT_history (struct GNUNET_CURL_Context *ctx,
TALER_MERCHANT_HistoryOperationCallback history_cb,
void *history_cb_cls);
+/**
+ * Issue a /history request to the backend.
+ *
+ * @param ctx execution context
+ * @param backend_url base URL of the merchant backend
+ * @param instance which merchant instance is performing this call
+ * @param start return `delta` records starting from position `start`.
+ * If given as zero, then no initial skip of `start` records is done.
+ * @param delta return `delta` records starting from position `start`
+ * @param date only transactions younger than/equals to date will be returned
+ * @param history_cb callback which will work the response gotten from the backend
+ * @param history_cb_cls closure to pass to @a history_cb
+ * @return handle for this operation, NULL upon errors
+ */
+struct TALER_MERCHANT_HistoryOperation *
+TALER_MERCHANT_history_default_start (struct GNUNET_CURL_Context *ctx,
+ const char *backend_url,
+ const char *instance,
+ long long delta,
+ struct GNUNET_TIME_Absolute date,
+ TALER_MERCHANT_HistoryOperationCallback history_cb,
+ void *history_cb_cls);
/**
diff --git a/src/lib/merchant_api_history.c b/src/lib/merchant_api_history.c
index eecccd10..d98df671 100644
--- a/src/lib/merchant_api_history.c
+++ b/src/lib/merchant_api_history.c
@@ -144,7 +144,6 @@ history_raw_cb (void *cls,
TALER_MERCHANT_history_cancel (ho);
}
-
/**
* Issue a /history request to the backend.
*
@@ -152,22 +151,24 @@ history_raw_cb (void *cls,
* @param backend_url base URL of the merchant backend
* @param instance which merchant instance is performing this call
* @param start return `delta` records starting from position `start`.
- * If given as zero, then no initial skip of `start` records is done.
+ * If given as zero, then no initial skip of `start` records is done.
+ * @param use_default_start do NOT include the 'start' argument in URL.
* @param delta return `delta` records starting from position `start`
* @param date only transactions younger than/equals to date will be returned
* @param history_cb callback which will work the response gotten from the backend
* @param history_cb_cls closure to pass to @a history_cb
* @return handle for this operation, NULL upon errors
*/
-struct TALER_MERCHANT_HistoryOperation *
-TALER_MERCHANT_history (struct GNUNET_CURL_Context *ctx,
- const char *backend_url,
- const char *instance,
- unsigned long long start,
- long long delta,
- struct GNUNET_TIME_Absolute date,
- TALER_MERCHANT_HistoryOperationCallback history_cb,
- void *history_cb_cls)
+static struct TALER_MERCHANT_HistoryOperation *
+TALER_MERCHANT_history2 (struct GNUNET_CURL_Context *ctx,
+ const char *backend_url,
+ const char *instance,
+ unsigned long long start,
+ int use_default_start,
+ long long delta,
+ struct GNUNET_TIME_Absolute date,
+ TALER_MERCHANT_HistoryOperationCallback history_cb,
+ void *history_cb_cls)
{
struct TALER_MERCHANT_HistoryOperation *ho;
uint64_t seconds;
@@ -180,13 +181,25 @@ TALER_MERCHANT_history (struct GNUNET_CURL_Context *ctx,
ho->cb_cls = history_cb_cls;
seconds = date.abs_value_us / 1000LL / 1000LL;
base = TALER_url_join (backend_url, "/history", NULL);
- GNUNET_asprintf (&ho->url,
- "%s?date=%llu&instance=%s&start=%llu&delta=%lld",
- base,
- seconds,
- instance,
- start,
- delta);
+
+ if (GNUNET_YES == use_default_start)
+ GNUNET_asprintf (&ho->url,
+ "%s?date=%llu&instance=%s&delta=%lld",
+ base,
+ seconds,
+ instance,
+ delta);
+ else
+ GNUNET_asprintf (&ho->url,
+ "%s?date=%llu&instance=%s&delta=%lld&start=%llu",
+ base,
+ seconds,
+ instance,
+ delta,
+ start);
+
+
+
GNUNET_free (base);
eh = curl_easy_init ();
if (CURLE_OK != curl_easy_setopt (eh,
@@ -210,4 +223,75 @@ TALER_MERCHANT_history (struct GNUNET_CURL_Context *ctx,
}
+/**
+ * Issue a /history request to the backend.
+ *
+ * @param ctx execution context
+ * @param backend_url base URL of the merchant backend
+ * @param instance which merchant instance is performing this call
+ * @param start return `delta` records starting from position `start`.
+ * If given as zero, then no initial skip of `start` records is done.
+ * @param delta return `delta` records starting from position `start`
+ * @param date only transactions younger than/equals to date will be returned
+ * @param history_cb callback which will work the response gotten from the backend
+ * @param history_cb_cls closure to pass to @a history_cb
+ * @return handle for this operation, NULL upon errors
+ */
+struct TALER_MERCHANT_HistoryOperation *
+TALER_MERCHANT_history_default_start (struct GNUNET_CURL_Context *ctx,
+ const char *backend_url,
+ const char *instance,
+ long long delta,
+ struct GNUNET_TIME_Absolute date,
+ TALER_MERCHANT_HistoryOperationCallback history_cb,
+ void *history_cb_cls)
+{
+ return TALER_MERCHANT_history2 (ctx,
+ backend_url,
+ instance,
+ -1, /* fake 'start' argument: will NOT be used */
+ GNUNET_YES, /* Specifies "no start argument" in final URL */
+ delta,
+ date,
+ history_cb,
+ history_cb_cls);
+}
+
+
+/**
+ * Issue a /history request to the backend.
+ *
+ * @param ctx execution context
+ * @param backend_url base URL of the merchant backend
+ * @param instance which merchant instance is performing this call
+ * @param start return `delta` records starting from position `start`.
+ * If given as zero, then no initial skip of `start` records is done.
+ * @param delta return `delta` records starting from position `start`
+ * @param date only transactions younger than/equals to date will be returned
+ * @param history_cb callback which will work the response gotten from the backend
+ * @param history_cb_cls closure to pass to @a history_cb
+ * @return handle for this operation, NULL upon errors
+ */
+struct TALER_MERCHANT_HistoryOperation *
+TALER_MERCHANT_history (struct GNUNET_CURL_Context *ctx,
+ const char *backend_url,
+ const char *instance,
+ unsigned long long start,
+ long long delta,
+ struct GNUNET_TIME_Absolute date,
+ TALER_MERCHANT_HistoryOperationCallback history_cb,
+ void *history_cb_cls)
+{
+ return TALER_MERCHANT_history2 (ctx,
+ backend_url,
+ instance,
+ start,
+ GNUNET_NO,
+ delta,
+ date,
+ history_cb,
+ history_cb_cls);
+}
+
+
/* end of merchant_api_contract.c */