From 6bce2eb4247f1fe2922c58cf08bd08a936a244af Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Tue, 18 Dec 2018 11:47:50 +0100 Subject: /history API. Provide the (client) API with a mean of omitting the 'start' argument, therefore letting the server use the default. --- src/include/taler_merchant_service.h | 22 +++++++ src/lib/merchant_api_history.c | 120 +++++++++++++++++++++++++++++------ 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 */ -- cgit v1.2.3