diff options
Diffstat (limited to 'src/exchange-lib')
-rw-r--r-- | src/exchange-lib/Makefile.am | 2 | ||||
-rw-r--r-- | src/exchange-lib/exchange_api_admin.c | 3 | ||||
-rw-r--r-- | src/exchange-lib/exchange_api_common.c | 5 | ||||
-rw-r--r-- | src/exchange-lib/exchange_api_common.h | 41 | ||||
-rw-r--r-- | src/exchange-lib/exchange_api_deposit.c | 2 | ||||
-rw-r--r-- | src/exchange-lib/exchange_api_refresh.c | 9 | ||||
-rw-r--r-- | src/exchange-lib/exchange_api_refresh_link.c | 7 | ||||
-rw-r--r-- | src/exchange-lib/exchange_api_refund.c | 2 | ||||
-rw-r--r-- | src/exchange-lib/exchange_api_reserve.c | 11 | ||||
-rw-r--r-- | src/exchange-lib/exchange_api_track_transaction.c | 2 | ||||
-rw-r--r-- | src/exchange-lib/exchange_api_track_transfer.c | 3 | ||||
-rw-r--r-- | src/exchange-lib/exchange_api_wire.c | 2 | ||||
-rw-r--r-- | src/exchange-lib/test_exchange_api.c | 41 |
13 files changed, 65 insertions, 65 deletions
diff --git a/src/exchange-lib/Makefile.am b/src/exchange-lib/Makefile.am index 83fcf1475..19c36744d 100644 --- a/src/exchange-lib/Makefile.am +++ b/src/exchange-lib/Makefile.am @@ -14,7 +14,7 @@ libtalerexchange_la_LDFLAGS = \ -no-undefined libtalerexchange_la_SOURCES = \ - exchange_api_common.c exchange_api_common.h \ + exchange_api_common.c \ exchange_api_handle.c exchange_api_handle.h \ exchange_api_admin.c \ exchange_api_deposit.c \ diff --git a/src/exchange-lib/exchange_api_admin.c b/src/exchange-lib/exchange_api_admin.c index 524916e68..e6cb8101c 100644 --- a/src/exchange-lib/exchange_api_admin.c +++ b/src/exchange-lib/exchange_api_admin.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014, 2015 GNUnet e.V. + Copyright (C) 2014, 2015, 2016 GNUnet e.V. TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -129,6 +129,7 @@ handle_admin_add_incoming_finished (void *cls, } aai->cb (aai->cb_cls, response_code, + TALER_JSON_get_error_code (json), json); TALER_EXCHANGE_admin_add_incoming_cancel (aai); } diff --git a/src/exchange-lib/exchange_api_common.c b/src/exchange-lib/exchange_api_common.c index acf90fce6..a531b1c39 100644 --- a/src/exchange-lib/exchange_api_common.c +++ b/src/exchange-lib/exchange_api_common.c @@ -20,7 +20,6 @@ * @author Christian Grothoff */ #include "platform.h" -#include "exchange_api_common.h" #include "taler_json_lib.h" #include <gnunet/gnunet_curl_lib.h> #include "exchange_api_handle.h" @@ -38,8 +37,8 @@ */ int TALER_EXCHANGE_verify_coin_history (const char *currency, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - json_t *history, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + json_t *history, struct TALER_Amount *total) { size_t len; diff --git a/src/exchange-lib/exchange_api_common.h b/src/exchange-lib/exchange_api_common.h deleted file mode 100644 index 5655f5d3b..000000000 --- a/src/exchange-lib/exchange_api_common.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2015 GNUnet e.V. - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, 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 General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see - <http://www.gnu.org/licenses/> -*/ -/** - * @file exchange-lib/exchange_api_common.h - * @brief common functions for the exchange API - * @author Christian Grothoff - */ -#include <jansson.h> -#include <gnunet/gnunet_util_lib.h> -#include "taler_exchange_service.h" - -/** - * Verify a coins transaction history as returned by the exchange. - * - * @param currency expected currency for the coin - * @param coin_pub public key of the coin - * @param history history of the coin in json encoding - * @param[out] total how much of the coin has been spent according to @a history - * @return #GNUNET_OK if @a history is valid, #GNUNET_SYSERR if not - */ -int -TALER_EXCHANGE_verify_coin_history (const char *currency, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - json_t *history, - struct TALER_Amount *total); - -/* end of exchange_api_common.h */ diff --git a/src/exchange-lib/exchange_api_deposit.c b/src/exchange-lib/exchange_api_deposit.c index aa7e07ed8..9282bbfd1 100644 --- a/src/exchange-lib/exchange_api_deposit.c +++ b/src/exchange-lib/exchange_api_deposit.c @@ -29,7 +29,6 @@ #include <gnunet/gnunet_curl_lib.h> #include "taler_json_lib.h" #include "taler_exchange_service.h" -#include "exchange_api_common.h" #include "exchange_api_handle.h" #include "taler_signatures.h" @@ -262,6 +261,7 @@ handle_deposit_finished (void *cls, } dh->cb (dh->cb_cls, response_code, + TALER_JSON_get_error_code (json), ep, json); TALER_EXCHANGE_deposit_cancel (dh); diff --git a/src/exchange-lib/exchange_api_refresh.c b/src/exchange-lib/exchange_api_refresh.c index 6d12a718c..c3216a6e6 100644 --- a/src/exchange-lib/exchange_api_refresh.c +++ b/src/exchange-lib/exchange_api_refresh.c @@ -28,7 +28,6 @@ #include <gnunet/gnunet_curl_lib.h> #include "taler_json_lib.h" #include "taler_exchange_service.h" -#include "exchange_api_common.h" #include "exchange_api_handle.h" #include "taler_signatures.h" @@ -1115,6 +1114,7 @@ handle_refresh_melt_finished (void *cls, { rmh->melt_cb (rmh->melt_cb_cls, response_code, + TALER_JSON_get_error_code (json), noreveal_index, (0 == response_code) ? NULL : &exchange_pub, json); @@ -1160,6 +1160,7 @@ handle_refresh_melt_finished (void *cls, if (NULL != rmh->melt_cb) rmh->melt_cb (rmh->melt_cb_cls, response_code, + TALER_JSON_get_error_code (json), UINT16_MAX, NULL, json); @@ -1598,6 +1599,7 @@ handle_refresh_reveal_finished (void *cls, { rrh->reveal_cb (rrh->reveal_cb_cls, MHD_HTTP_OK, + TALER_EC_NONE, rrh->md->num_fresh_coins, coin_privs, sigs, @@ -1634,7 +1636,10 @@ handle_refresh_reveal_finished (void *cls, if (NULL != rrh->reveal_cb) rrh->reveal_cb (rrh->reveal_cb_cls, response_code, - 0, NULL, NULL, + TALER_JSON_get_error_code (json), + 0, + NULL, + NULL, json); TALER_EXCHANGE_refresh_reveal_cancel (rrh); } diff --git a/src/exchange-lib/exchange_api_refresh_link.c b/src/exchange-lib/exchange_api_refresh_link.c index a1dba9938..9b825138e 100644 --- a/src/exchange-lib/exchange_api_refresh_link.c +++ b/src/exchange-lib/exchange_api_refresh_link.c @@ -265,6 +265,7 @@ parse_refresh_link_ok (struct TALER_EXCHANGE_RefreshLinkHandle *rlh, { rlh->link_cb (rlh->link_cb_cls, MHD_HTTP_OK, + TALER_EC_NONE, num_coins, coin_privs, sigs, @@ -345,7 +346,11 @@ handle_refresh_link_finished (void *cls, if (NULL != rlh->link_cb) rlh->link_cb (rlh->link_cb_cls, response_code, - 0, NULL, NULL, NULL, + TALER_JSON_get_error_code (json), + 0, + NULL, + NULL, + NULL, json); TALER_EXCHANGE_refresh_link_cancel (rlh); } diff --git a/src/exchange-lib/exchange_api_refund.c b/src/exchange-lib/exchange_api_refund.c index f712f126a..be080c57b 100644 --- a/src/exchange-lib/exchange_api_refund.c +++ b/src/exchange-lib/exchange_api_refund.c @@ -28,7 +28,6 @@ #include <gnunet/gnunet_curl_lib.h> #include "taler_json_lib.h" #include "taler_exchange_service.h" -#include "exchange_api_common.h" #include "exchange_api_handle.h" #include "taler_signatures.h" @@ -196,6 +195,7 @@ handle_refund_finished (void *cls, } rh->cb (rh->cb_cls, response_code, + TALER_JSON_get_error_code (json), ep, json); TALER_EXCHANGE_refund_cancel (rh); diff --git a/src/exchange-lib/exchange_api_reserve.c b/src/exchange-lib/exchange_api_reserve.c index 0bff767e6..28f329c42 100644 --- a/src/exchange-lib/exchange_api_reserve.c +++ b/src/exchange-lib/exchange_api_reserve.c @@ -314,7 +314,8 @@ handle_reserve_status_finished (void *cls, if (GNUNET_OK != GNUNET_JSON_parse (json, spec, - NULL, NULL)) + NULL, + NULL)) { GNUNET_break_op (0); response_code = 0; @@ -355,6 +356,7 @@ handle_reserve_status_finished (void *cls, } wsh->cb (wsh->cb_cls, response_code, + TALER_EC_NONE, json, &balance, len, @@ -387,6 +389,7 @@ handle_reserve_status_finished (void *cls, if (NULL != wsh->cb) wsh->cb (wsh->cb_cls, response_code, + TALER_JSON_get_error_code (json), json, NULL, 0, NULL); @@ -589,6 +592,7 @@ reserve_withdraw_ok (struct TALER_EXCHANGE_ReserveWithdrawHandle *wsh, dsig.rsa_signature = sig; wsh->cb (wsh->cb_cls, MHD_HTTP_OK, + TALER_EC_NONE, &dsig, json); /* make sure callback isn't called again after return */ @@ -599,7 +603,7 @@ reserve_withdraw_ok (struct TALER_EXCHANGE_ReserveWithdrawHandle *wsh, /** - * We got a 402 PAYMENT REQUIRED response for the /reserve/withdraw operation. + * We got a 403 FORBIDDEN response for the /reserve/withdraw operation. * Check the signatures on the withdraw transactions in the provided * history and that the balances add up. We don't do anything directly * with the information, as the JSON will be returned to the application. @@ -723,7 +727,7 @@ handle_reserve_withdraw_finished (void *cls, /* This should never happen, either us or the exchange is buggy (or API version conflict); just pass JSON reply to the application */ break; - case MHD_HTTP_PAYMENT_REQUIRED: + case MHD_HTTP_FORBIDDEN: /* The exchange says that the reserve has insufficient funds; check the signatures in the history... */ if (GNUNET_OK != @@ -762,6 +766,7 @@ handle_reserve_withdraw_finished (void *cls, if (NULL != wsh->cb) wsh->cb (wsh->cb_cls, response_code, + TALER_JSON_get_error_code (json), NULL, json); TALER_EXCHANGE_reserve_withdraw_cancel (wsh); diff --git a/src/exchange-lib/exchange_api_track_transaction.c b/src/exchange-lib/exchange_api_track_transaction.c index c05115d57..7fd2efb21 100644 --- a/src/exchange-lib/exchange_api_track_transaction.c +++ b/src/exchange-lib/exchange_api_track_transaction.c @@ -28,7 +28,6 @@ #include <gnunet/gnunet_curl_lib.h> #include "taler_json_lib.h" #include "taler_exchange_service.h" -#include "exchange_api_common.h" #include "exchange_api_handle.h" #include "taler_signatures.h" @@ -239,6 +238,7 @@ handle_deposit_wtid_finished (void *cls, } dwh->cb (dwh->cb_cls, response_code, + TALER_JSON_get_error_code (json), ep, json, wtid, diff --git a/src/exchange-lib/exchange_api_track_transfer.c b/src/exchange-lib/exchange_api_track_transfer.c index ffcb19b59..8ed5865d7 100644 --- a/src/exchange-lib/exchange_api_track_transfer.c +++ b/src/exchange-lib/exchange_api_track_transfer.c @@ -26,7 +26,6 @@ #include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_curl_lib.h> #include "taler_exchange_service.h" -#include "exchange_api_common.h" #include "taler_json_lib.h" #include "exchange_api_handle.h" #include "taler_signatures.h" @@ -183,6 +182,7 @@ check_track_transfer_response_ok (struct TALER_EXCHANGE_TrackTransferHandle *wdh } wdh->cb (wdh->cb_cls, MHD_HTTP_OK, + TALER_EC_NONE, &exchange_pub, json, &h_wire, @@ -253,6 +253,7 @@ handle_track_transfer_finished (void *cls, } wdh->cb (wdh->cb_cls, response_code, + TALER_JSON_get_error_code (json), NULL, json, NULL, diff --git a/src/exchange-lib/exchange_api_wire.c b/src/exchange-lib/exchange_api_wire.c index cb8df4944..7401e66d4 100644 --- a/src/exchange-lib/exchange_api_wire.c +++ b/src/exchange-lib/exchange_api_wire.c @@ -28,7 +28,6 @@ #include "taler_exchange_service.h" #include "taler_json_lib.h" #include "taler_wire_plugin.h" -#include "exchange_api_common.h" #include "exchange_api_handle.h" @@ -210,6 +209,7 @@ handle_wire_finished (void *cls, } wh->cb (wh->cb_cls, response_code, + TALER_JSON_get_error_code (json), (NULL != keep) ? keep : json); if (NULL != keep) json_decref (keep); diff --git a/src/exchange-lib/test_exchange_api.c b/src/exchange-lib/test_exchange_api.c index 541a621d2..e25fa66cd 100644 --- a/src/exchange-lib/test_exchange_api.c +++ b/src/exchange-lib/test_exchange_api.c @@ -761,11 +761,13 @@ next_command (struct InterpreterState *is) * @param cls closure with the interpreter state * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request * 0 if the exchange's reply is bogus (fails to follow the protocol) + * @param ec taler-specific error code, #TALER_EC_NONE on success * @param full_response full response from the exchange (for logging, in case of errors) */ static void add_incoming_cb (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, const json_t *full_response) { struct InterpreterState *is = cls; @@ -857,6 +859,7 @@ compare_reserve_withdraw_history (const struct TALER_EXCHANGE_ReserveHistory *h, * @param cls closure with the interpreter state * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request * 0 if the exchange's reply is bogus (fails to follow the protocol) + * @param ec taler-specific error code, #TALER_EC_NONE on success * @param[in] json original response in JSON format (useful only for diagnostics) * @param balance current balance in the reserve, NULL on error * @param history_length number of entries in the transaction history, 0 on error @@ -865,6 +868,7 @@ compare_reserve_withdraw_history (const struct TALER_EXCHANGE_ReserveHistory *h, static void reserve_status_cb (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, const json_t *json, const struct TALER_Amount *balance, unsigned int history_length, @@ -924,7 +928,7 @@ reserve_status_cb (void *cls, { if (GNUNET_OK != compare_reserve_withdraw_history (&history[j], - rel)) + rel)) { GNUNET_break (0); fail (is); @@ -973,12 +977,14 @@ reserve_status_cb (void *cls, * @param cls closure with the interpreter state * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request * 0 if the exchange's reply is bogus (fails to follow the protocol) + * @param ec taler-specific error code, #TALER_EC_NONE on success * @param sig signature over the coin, NULL on error * @param full_response full response from the exchange (for logging, in case of errors) */ static void reserve_withdraw_cb (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, const struct TALER_DenominationSignature *sig, const json_t *full_response) { @@ -1009,7 +1015,7 @@ reserve_withdraw_cb (void *cls, cmd->details.reserve_withdraw.sig.rsa_signature = GNUNET_CRYPTO_rsa_signature_dup (sig->rsa_signature); break; - case MHD_HTTP_PAYMENT_REQUIRED: + case MHD_HTTP_FORBIDDEN: /* nothing to check */ break; default: @@ -1027,6 +1033,7 @@ reserve_withdraw_cb (void *cls, * @param cls closure with the interpreter state * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful deposit; * 0 if the exchange's reply is bogus (fails to follow the protocol) + * @param ec taler-specific error code, #TALER_EC_NONE on success * @param exchange_pub public key the exchange used for signing * @param obj the received JSON reply, should be kept as proof (and, in case of errors, * be forwarded to the customer) @@ -1034,6 +1041,7 @@ reserve_withdraw_cb (void *cls, static void deposit_cb (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, const struct TALER_ExchangePublicKeyP *exchange_pub, const json_t *obj) { @@ -1061,6 +1069,7 @@ deposit_cb (void *cls, * @param cls closure with the interpreter state * @param http_status HTTP response code, never #MHD_HTTP_OK (200) as for successful intermediate response this callback is skipped. * 0 if the exchange's reply is bogus (fails to follow the protocol) + * @param ec taler-specific error code, #TALER_EC_NONE on success * @param noreveal_index choice by the exchange in the cut-and-choose protocol, * UINT16_MAX on error * @param exchange_pub public key the exchange used for signing @@ -1069,6 +1078,7 @@ deposit_cb (void *cls, static void melt_cb (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, uint16_t noreveal_index, const struct TALER_ExchangePublicKeyP *exchange_pub, const json_t *full_response) @@ -1098,6 +1108,7 @@ melt_cb (void *cls, * @param cls closure with the interpreter state * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request * 0 if the exchange's reply is bogus (fails to follow the protocol) + * @param ec taler-specific error code, #TALER_EC_NONE on success * @param num_coins number of fresh coins created, length of the @a sigs and @a coin_privs arrays, 0 if the operation failed * @param coin_privs array of @a num_coins private keys for the coins that were created, NULL on error * @param sigs array of signature over @a num_coins coins, NULL on error @@ -1106,6 +1117,7 @@ melt_cb (void *cls, static void reveal_cb (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, unsigned int num_coins, const struct TALER_CoinSpendPrivateKeyP *coin_privs, const struct TALER_DenominationSignature *sigs, @@ -1160,6 +1172,7 @@ reveal_cb (void *cls, * @param cls closure with the interpreter state * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request * 0 if the exchange's reply is bogus (fails to follow the protocol) + * @param ec taler-specific error code, #TALER_EC_NONE on success * @param num_coins number of fresh coins created, length of the @a sigs and @a coin_privs arrays, 0 if the operation failed * @param coin_privs array of @a num_coins private keys for the coins that were created, NULL on error * @param sigs array of signature over @a num_coins coins, NULL on error @@ -1169,6 +1182,7 @@ reveal_cb (void *cls, static void link_cb (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, unsigned int num_coins, const struct TALER_CoinSpendPrivateKeyP *coin_privs, const struct TALER_DenominationSignature *sigs, @@ -1336,12 +1350,14 @@ find_pk (const struct TALER_EXCHANGE_Keys *keys, * @param cls closure with the interpreter state * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful request; * 0 if the exchange's reply is bogus (fails to follow the protocol) + * @param ec taler-specific error code, #TALER_EC_NONE on success * @param obj the received JSON reply, if successful this should be the wire * format details as provided by /wire. */ static void wire_cb (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, const json_t *obj) { struct InterpreterState *is = cls; @@ -1391,6 +1407,7 @@ wire_cb (void *cls, * * @param cls closure * @param http_status HTTP status code we got, 0 on exchange protocol violation + * @param ec taler-specific error code, #TALER_EC_NONE on success * @param exchange_pub public key the exchange used for signing * @param json original json reply (may include signatures, those have then been * validated already) @@ -1404,6 +1421,7 @@ wire_cb (void *cls, static void wire_deposits_cb (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, const struct TALER_ExchangePublicKeyP *exchange_pub, const json_t *json, const struct GNUNET_HashCode *h_wire, @@ -1521,6 +1539,7 @@ wire_deposits_cb (void *cls, * * @param cls closure * @param http_status HTTP status code we got, 0 on exchange protocol violation + * @param ec taler-specific error code, #TALER_EC_NONE on success * @param exchange_pub public key the exchange used for signing * @param json original json reply (may include signatures, those have then been * validated already) @@ -1534,6 +1553,7 @@ wire_deposits_cb (void *cls, static void deposit_wtid_cb (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, const struct TALER_ExchangePublicKeyP *exchange_pub, const json_t *json, const struct TALER_WireTransferIdentifierRawP *wtid, @@ -1588,6 +1608,7 @@ deposit_wtid_cb (void *cls, * @param cls closure * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful deposit; * 0 if the exchange's reply is bogus (fails to follow the protocol) + * @param ec taler-specific error code, #TALER_EC_NONE on success * @param exchange_pub public key the exchange used for signing @a obj * @param obj the received JSON reply, should be kept as proof (and, in particular, * be forwarded to the customer) @@ -1595,6 +1616,7 @@ deposit_wtid_cb (void *cls, static void refund_cb (void *cls, unsigned int http_status, + enum TALER_ErrorCode ec, const struct TALER_ExchangePublicKeyP *exchange_pub, const json_t *obj) { @@ -1782,9 +1804,9 @@ interpreter_run (void *cls) &reserve_pub.eddsa_pub); cmd->details.reserve_status.wsh = TALER_EXCHANGE_reserve_status (exchange, - &reserve_pub, - &reserve_status_cb, - is); + &reserve_pub, + &reserve_status_cb, + is); return; case OC_WITHDRAW_SIGN: GNUNET_assert (NULL != @@ -2737,7 +2759,7 @@ run (void *cls) /* Try to overdraw funds ... */ { .oc = OC_WITHDRAW_SIGN, .label = "withdraw-coin-2", - .expected_response_code = MHD_HTTP_PAYMENT_REQUIRED, + .expected_response_code = MHD_HTTP_FORBIDDEN, .details.reserve_withdraw.reserve_reference = "create-reserve-1", .details.reserve_withdraw.amount = "EUR:5" }, @@ -3051,8 +3073,11 @@ main (int argc, unsigned long code; GNUNET_log_setup ("test-exchange-api", - "WARNING", - NULL); + "DEBUG", + "/tmp/logs"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test log\n"); + return 0; + /* These might get in the way... */ unsetenv ("XDG_DATA_HOME"); unsetenv ("XDG_CONFIG_HOME"); |