diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-09 19:36:24 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-09 19:36:24 +0200 |
commit | 7afcc8275c0e8e19ceeb178bca21c7988966cba5 (patch) | |
tree | b8fb349ae21cd455b82a4bf354cc1cefa5d68e26 /src/lib | |
parent | cb930318e14b314288d762d690b69ff86e7ee466 (diff) |
skeleton for /track/transfer and /track/transaction, renaming to match latest exchange API
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Makefile.am | 3 | ||||
-rw-r--r-- | src/lib/merchant_api_track_transaction.c | 193 | ||||
-rw-r--r-- | src/lib/merchant_api_track_transfer.c (renamed from src/lib/merchant_api_track.c) | 69 | ||||
-rw-r--r-- | src/lib/test_merchant_api.c | 16 |
4 files changed, 238 insertions, 43 deletions
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 5baf0296..a7ded655 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -16,7 +16,8 @@ libtalermerchant_la_LDFLAGS = \ libtalermerchant_la_SOURCES = \ merchant_api_contract.c \ merchant_api_pay.c \ - merchant_api_track.c + merchant_api_track_transaction.c \ + merchant_api_track_transfer.c libtalermerchant_la_LIBADD = \ -ltalerexchange \ diff --git a/src/lib/merchant_api_track_transaction.c b/src/lib/merchant_api_track_transaction.c new file mode 100644 index 00000000..356c0852 --- /dev/null +++ b/src/lib/merchant_api_track_transaction.c @@ -0,0 +1,193 @@ +/* + This file is part of TALER + Copyright (C) 2014, 2015, 2016 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, If not, see + <http://www.gnu.org/licenses/> +*/ +/** + * @file lib/merchant_api_track_transaction.c + * @brief Implementation of the /track/transaction request of the + * merchant's HTTP API + * @author Marcello Stanisci + * @author Christian Grothoff + */ +#include "platform.h" +#include <curl/curl.h> +#include <jansson.h> +#include <microhttpd.h> /* just for HTTP status codes */ +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_curl_lib.h> +#include "taler_merchant_service.h" +#include <taler/taler_json_lib.h> +#include <taler/taler_signatures.h> + + +/** + * @brief A handle for tracking transactions. + */ +struct TALER_MERCHANT_TrackTransactionHandle +{ + + /** + * The url for this request. + */ + char *url; + + /** + * base32 identifier being the 'witd' parameter required by the + * exchange + */ + char *wtid; + + /** + * Handle for the request. + */ + struct GNUNET_CURL_Job *job; + + /** + * Function to call with the result. + */ + TALER_MERCHANT_TrackTransactionCallback cb; + + /** + * Closure for @a cb. + */ + void *cb_cls; + + /** + * Reference to the execution context. + */ + struct GNUNET_CURL_Context *ctx; +}; + + +/** + * Function called when we're done processing the + * HTTP /track/transaction request. + * + * @param cls the `struct TALER_MERCHANT_TrackTransactionHandle` + * @param response_code HTTP response code, 0 on error + * @param json response body, NULL if not in JSON + */ +static void +handle_tracktransaction_finished (void *cls, + long response_code, + const json_t *json) +{ + struct TALER_MERCHANT_TrackTransactionHandle *tdo = cls; + + tdo->job = NULL; + switch (response_code) + { + case 0: + break; + case MHD_HTTP_OK: + { + /* Work out argument for external callback from the body .. */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "200 returned from /track/transaction\n"); + /* FIXME: actually verify signature */ + } + break; + case MHD_HTTP_NOT_FOUND: + /* Nothing really to verify, this should never + happen, we should pass the JSON reply to the application */ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "track transaction URI not found\n"); + break; + case MHD_HTTP_INTERNAL_SERVER_ERROR: + /* Server had an internal issue; we should retry, but this API + leaves this to the application */ + break; + default: + /* unexpected response code */ + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unexpected response code %u\n", + (unsigned int) response_code); + GNUNET_break (0); + response_code = 0; + break; + } + /* FIXME: figure out which parameters ought to be passed back */ + tdo->cb (tdo->cb_cls, + response_code, + json); +} + + +/** + * Request backend to return transactions associated with a given wtid. + * + * @param ctx execution context + * @param backend_uri URI of the backend (having "/track/transaction" appended) + * @param wtid base32 string indicating a wtid + * @param exchange base URL of the exchange in charge of returning the wanted information + * @param track_transaction_cb the callback to call when a reply for this request is available + * @param track_transaction_cb_cls closure for @a contract_cb + * @return a handle for this request + */ +struct TALER_MERCHANT_TrackTransactionHandle * +TALER_MERCHANT_track_transaction (struct GNUNET_CURL_Context *ctx, + const char *backend_uri, + uint64_t transaction_id, + const char *exchange_uri, + TALER_MERCHANT_TrackTransactionCallback track_transaction_cb, + void *track_transaction_cb_cls) +{ + struct TALER_MERCHANT_TrackTransactionHandle *tdo; + CURL *eh; + + tdo = GNUNET_new (struct TALER_MERCHANT_TrackTransactionHandle); + tdo->ctx = ctx; + tdo->cb = track_transaction_cb; + tdo->cb_cls = track_transaction_cb_cls; + /* URI gotten with /track/transaction already appended... */ + GNUNET_asprintf (&tdo->url, + "%s?transaction=%llu&exchange=%s", + backend_uri, + (unsigned long long) transaction_id, + exchange_uri); + eh = curl_easy_init (); + GNUNET_assert (CURLE_OK == + curl_easy_setopt (eh, + CURLOPT_URL, + tdo->url)); + tdo->job = GNUNET_CURL_job_add (ctx, + eh, + GNUNET_YES, + &handle_tracktransaction_finished, + tdo); + return tdo; +} + + +/** + * Cancel a /track/transaction request. This function cannot be used + * on a request handle if a response is already served for it. + * + * @param co the transaction's tracking handle + */ +void +TALER_MERCHANT_track_transaction_cancel (struct TALER_MERCHANT_TrackTransactionHandle *tdo) +{ + if (NULL != tdo->job) + { + GNUNET_CURL_job_cancel (tdo->job); + tdo->job = NULL; + } + GNUNET_free (tdo->url); + GNUNET_free (tdo->wtid); + GNUNET_free (tdo); +} + +/* end of merchant_api_track_transaction.c */ diff --git a/src/lib/merchant_api_track.c b/src/lib/merchant_api_track_transfer.c index e3f926ac..9b87f9ce 100644 --- a/src/lib/merchant_api_track.c +++ b/src/lib/merchant_api_track_transfer.c @@ -15,10 +15,11 @@ <http://www.gnu.org/licenses/> */ /** - * @file lib/merchant_api_contract.c - * @brief Implementation of the /track/deposit and /track/wtid request of the + * @file lib/merchant_api_track_transfer.c + * @brief Implementation of the /track/transfer request of the * merchant's HTTP API * @author Marcello Stanisci + * @author Christian Grothoff */ #include "platform.h" #include <curl/curl.h> @@ -32,9 +33,9 @@ /** - * @brief A Contract Operation Handle + * @brief A Handle for tracking wire transfers. */ -struct TALER_MERCHANT_TrackDepositOperation +struct TALER_MERCHANT_TrackTransferHandle { /** @@ -56,7 +57,7 @@ struct TALER_MERCHANT_TrackDepositOperation /** * Function to call with the result. */ - TALER_MERCHANT_TrackDepositCallback cb; + TALER_MERCHANT_TrackTransferCallback cb; /** * Closure for @a cb. @@ -72,18 +73,18 @@ struct TALER_MERCHANT_TrackDepositOperation /** * Function called when we're done processing the - * HTTP /track/deposit request. + * HTTP /track/transfer request. * - * @param cls the `struct TALER_MERCHANT_TrackDepositOperation` + * @param cls the `struct TALER_MERCHANT_TrackTransferHandle` * @param response_code HTTP response code, 0 on error * @param json response body, NULL if not in JSON */ static void -handle_trackdeposit_finished (void *cls, - long response_code, - const json_t *json) +handle_track_transfer_finished (void *cls, + long response_code, + const json_t *json) { - struct TALER_MERCHANT_TrackDepositOperation *tdo = cls; + struct TALER_MERCHANT_TrackTransferHandle *tdo = cls; tdo->job = NULL; switch (response_code) @@ -94,7 +95,7 @@ handle_trackdeposit_finished (void *cls, { /* Work out argument for external callback from the body .. */ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "200 returned from /track/deposit\n"); + "200 returned from /track/transfer\n"); /* FIXME: actually verify signature */ } break; @@ -102,7 +103,7 @@ handle_trackdeposit_finished (void *cls, /* Nothing really to verify, this should never happen, we should pass the JSON reply to the application */ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "track deposit URI not found\n"); + "track transfer URI not found\n"); break; case MHD_HTTP_INTERNAL_SERVER_ERROR: /* Server had an internal issue; we should retry, but this API @@ -125,35 +126,35 @@ handle_trackdeposit_finished (void *cls, /** - * Request backend to return deposits associated with a given wtid. + * Request backend to return transfers associated with a given wtid. * * @param ctx execution context - * @param backend_uri URI of the backend (having "/track/deposit" appended) + * @param backend_uri URI of the backend (having "/track/transfer" appended) * @param wtid base32 string indicating a wtid * @param exchange base URL of the exchange in charge of returning the wanted information - * @param trackdeposit_cb the callback to call when a reply for this request is available - * @param trackdeposit_cb_cls closure for @a contract_cb + * @param tracktransfer_cb the callback to call when a reply for this request is available + * @param tracktransfer_cb_cls closure for @a contract_cb * @return a handle for this request */ -struct TALER_MERCHANT_TrackDepositOperation * -TALER_MERCHANT_track_deposit (struct GNUNET_CURL_Context *ctx, - const char *backend_uri, - const struct TALER_WireTransferIdentifierRawP *wtid, - const char *exchange_uri, - TALER_MERCHANT_TrackDepositCallback trackdeposit_cb, - void *trackdeposit_cb_cls) +struct TALER_MERCHANT_TrackTransferHandle * +TALER_MERCHANT_track_transfer (struct GNUNET_CURL_Context *ctx, + const char *backend_uri, + const struct TALER_WireTransferIdentifierRawP *wtid, + const char *exchange_uri, + TALER_MERCHANT_TrackTransferCallback tracktransfer_cb, + void *tracktransfer_cb_cls) { - struct TALER_MERCHANT_TrackDepositOperation *tdo; + struct TALER_MERCHANT_TrackTransferHandle *tdo; CURL *eh; char *wtid_str; wtid_str = GNUNET_STRINGS_data_to_string_alloc (wtid, sizeof (struct TALER_WireTransferIdentifierRawP)); - tdo = GNUNET_new (struct TALER_MERCHANT_TrackDepositOperation); + tdo = GNUNET_new (struct TALER_MERCHANT_TrackTransferHandle); tdo->ctx = ctx; - tdo->cb = trackdeposit_cb; - tdo->cb_cls = trackdeposit_cb_cls; - /* URI gotten with /track/deposit already appended... */ + tdo->cb = tracktransfer_cb; + tdo->cb_cls = tracktransfer_cb_cls; + /* URI gotten with /track/transfer already appended... */ GNUNET_asprintf (&tdo->url, "%s?wtid=%s&exchange=%s", backend_uri, @@ -168,20 +169,20 @@ TALER_MERCHANT_track_deposit (struct GNUNET_CURL_Context *ctx, tdo->job = GNUNET_CURL_job_add (ctx, eh, GNUNET_YES, - &handle_trackdeposit_finished, + &handle_track_transfer_finished, tdo); return tdo; } /** - * Cancel a /track/deposit request. This function cannot be used + * Cancel a /track/transfer request. This function cannot be used * on a request handle if a response is already served for it. * - * @param co the deposit's tracking operation + * @param co the transfer's tracking handle */ void -TALER_MERCHANT_track_deposit_cancel (struct TALER_MERCHANT_TrackDepositOperation *tdo) +TALER_MERCHANT_track_transfer_cancel (struct TALER_MERCHANT_TrackTransferHandle *tdo) { if (NULL != tdo->job) { @@ -193,4 +194,4 @@ TALER_MERCHANT_track_deposit_cancel (struct TALER_MERCHANT_TrackDepositOperation GNUNET_free (tdo); } -/* end of merchant_api_track.c */ +/* end of merchant_api_track_transfer.c */ diff --git a/src/lib/test_merchant_api.c b/src/lib/test_merchant_api.c index 3a44552e..df423519 100644 --- a/src/lib/test_merchant_api.c +++ b/src/lib/test_merchant_api.c @@ -459,9 +459,9 @@ struct Command char *check_bank_ref; /** - * Handle to a /track/deposit operation + * Handle to a /track/transfer operation */ - struct TALER_MERCHANT_TrackDepositOperation *tdo; + struct TALER_MERCHANT_TrackTransferHandle *tdo; } track_deposit; @@ -944,7 +944,7 @@ maint_child_death (void *cls) /** - * Callback for a /track/deposit operation + * Callback for a /track/transfer operation * * @param cls closure for this function * @param http_status HTTP response code returned by the server @@ -963,13 +963,13 @@ track_deposit_cb (void *cls, if (MHD_HTTP_OK == http_status) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Ok from /track/deposit handler\n"); + "Ok from /track/transfer handler\n"); result = GNUNET_OK; } else { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Not Ok from /track/deposit handler\n"); + "Not Ok from /track/transfer handler\n"); result = GNUNET_SYSERR; } next_command (is); @@ -1448,7 +1448,7 @@ interpreter_run (void *cls) cmd->details.track_deposit.check_bank_ref); GNUNET_assert (NULL != ref); cmd->details.track_deposit.tdo = - TALER_MERCHANT_track_deposit (ctx, + TALER_MERCHANT_track_transfer (ctx, MERCHANT_URI "track/deposit", &ref->details.check_bank_transfer.wtid, EXCHANGE_URI, @@ -1594,10 +1594,10 @@ do_shutdown (void *cls) break; case OC_TRACK_DEPOSIT: GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "shutting down /track/deposit\n"); + "shutting down /track/transfer\n"); if (NULL != cmd->details.track_deposit.tdo) { - TALER_MERCHANT_track_deposit_cancel (cmd->details.track_deposit.tdo); + TALER_MERCHANT_track_transfer_cancel (cmd->details.track_deposit.tdo); cmd->details.track_deposit.tdo = NULL; } break; |