summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/taler_auditor_service.h68
-rw-r--r--src/include/taler_error_codes.h13
-rw-r--r--src/include/taler_exchange_service.h177
-rw-r--r--src/include/taler_json_lib.h11
-rw-r--r--src/include/taler_testing_lib.h10
5 files changed, 156 insertions, 123 deletions
diff --git a/src/include/taler_auditor_service.h b/src/include/taler_auditor_service.h
index 0f69da11b..fdce76cd2 100644
--- a/src/include/taler_auditor_service.h
+++ b/src/include/taler_auditor_service.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2018 Taler Systems SA
+ Copyright (C) 2014-2020 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -107,17 +107,58 @@ enum TALER_AUDITOR_VersionCompatibility
/**
+ * General information about the HTTP response we obtained
+ * from the auditor for a request.
+ */
+struct TALER_AUDITOR_HttpResponse
+{
+
+ /**
+ * The complete JSON reply. NULL if we failed to parse the
+ * reply (too big, invalid JSON).
+ */
+ const json_t *reply;
+
+ /**
+ * Set to the human-readable 'hint' that is optionally
+ * provided by the exchange together with errors. NULL
+ * if no hint was provided or if there was no error.
+ */
+ const char *hint;
+
+ /**
+ * HTTP status code for the response. 0 if the
+ * HTTP request failed and we did not get any answer, or
+ * if the answer was invalid and we set @a ec to a
+ * client-side error code.
+ */
+ unsigned int http_status;
+
+ /**
+ * Taler error code. #TALER_EC_NONE if everything was
+ * OK. Usually set to the "code" field of an error
+ * response, but may be set to values created at the
+ * client side, for example when the response was
+ * not in JSON format or was otherwise ill-formed.
+ */
+ enum TALER_ErrorCode ec;
+
+};
+
+
+/**
* Function called with information about the auditor.
*
* @param cls closure
+ * @param hr HTTP response data
* @param vi basic information about the auditor
* @param compat protocol compatibility information
*/
typedef void
(*TALER_AUDITOR_VersionCallback) (
void *cls,
- const struct
- TALER_AUDITOR_VersionInformation *vi,
+ const struct TALER_AUDITOR_HttpResponse *hr,
+ const struct TALER_AUDITOR_VersionInformation *vi,
enum TALER_AUDITOR_VersionCompatibility compat);
@@ -169,15 +210,12 @@ struct TALER_AUDITOR_DepositConfirmationHandle;
* auditor's /deposit-confirmation handler.
*
* @param cls closure
- * @param http_status HTTP status code, 200 on success
- * @param ec taler protocol error status code, 0 on success
- * @param json raw json response
+ * @param hr HTTP response data
*/
typedef void
-(*TALER_AUDITOR_DepositConfirmationResultCallback)(void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- const json_t *json);
+(*TALER_AUDITOR_DepositConfirmationResultCallback)(
+ void *cls,
+ const struct TALER_AUDITOR_HttpResponse *hr);
/**
@@ -274,20 +312,16 @@ struct TALER_AUDITOR_ExchangeInfo
* Function called with the result from /exchagnes.
*
* @param cls closure
- * @param http_status the HTTP status code, 200 on success
- * @param ec detailed Taler error status code, #TALER_EC_NONE on success
+ * @param hr HTTP response data
* @param num_exchanges length of array at @a ei
* @param ei information about exchanges returned by the auditor
- * @param raw_response raw JSON response
*/
typedef void
(*TALER_AUDITOR_ListExchangesResultCallback)(
void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
+ const struct TALER_AUDITOR_HttpResponse *hr,
unsigned int num_exchanges,
- const struct TALER_AUDITOR_ExchangeInfo *ei,
- const json_t *raw_response);
+ const struct TALER_AUDITOR_ExchangeInfo *ei);
/**
* Submit an /exchanges request to the auditor and get the
diff --git a/src/include/taler_error_codes.h b/src/include/taler_error_codes.h
index 94475f19c..cbf01b8f1 100644
--- a/src/include/taler_error_codes.h
+++ b/src/include/taler_error_codes.h
@@ -118,6 +118,13 @@ enum TALER_ErrorCode
TALER_EC_HOLE_IN_WIRE_FEE_STRUCTURE = 13,
/**
+ * The version string given does not follow the expected
+ * CURRENT:REVISION:AGE Format. Generated as an error on the client
+ * side.
+ */
+ TALER_EC_VERSION_MALFORMED = 14,
+
+ /**
* The exchange failed to even just initialize its connection to the
* database. This response is provided with HTTP status code
* #MHD_HTTP_INTERNAL_SERVER_ERROR.
@@ -1111,6 +1118,12 @@ enum TALER_ErrorCode
TALER_EC_KEYS_TIMETRAVEL_FORBIDDEN = 1902,
/**
+ * The keys response was malformed. This error is generated client-
+ * side.
+ */
+ TALER_EC_KEYS_INVALID = 1903,
+
+ /**
* The backend could not find the merchant instance specified in the
* request. This response is provided with HTTP status code
* #MHD_HTTP_NOT_FOUND.
diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h
index 5f7cf6033..68f0cea38 100644
--- a/src/include/taler_exchange_service.h
+++ b/src/include/taler_exchange_service.h
@@ -352,25 +352,61 @@ enum TALER_EXCHANGE_VersionCompatibility
/**
+ * General information about the HTTP response we obtained
+ * from the exchange for a request.
+ */
+struct TALER_EXCHANGE_HttpResponse
+{
+
+ /**
+ * The complete JSON reply. NULL if we failed to parse the
+ * reply (too big, invalid JSON).
+ */
+ const json_t *reply;
+
+ /**
+ * Set to the human-readable 'hint' that is optionally
+ * provided by the exchange together with errors. NULL
+ * if no hint was provided or if there was no error.
+ */
+ const char *hint;
+
+ /**
+ * HTTP status code for the response. 0 if the
+ * HTTP request failed and we did not get any answer, or
+ * if the answer was invalid and we set @a ec to a
+ * client-side error code.
+ */
+ unsigned int http_status;
+
+ /**
+ * Taler error code. #TALER_EC_NONE if everything was
+ * OK. Usually set to the "code" field of an error
+ * response, but may be set to values created at the
+ * client side, for example when the response was
+ * not in JSON format or was otherwise ill-formed.
+ */
+ enum TALER_ErrorCode ec;
+
+};
+
+
+/**
* Function called with information about who is auditing
* a particular exchange and what key the exchange is using.
*
* @param cls closure
+ * @param hr HTTP response data
* @param keys information about the various keys used
* by the exchange, NULL if /keys failed
* @param compat protocol compatibility information
- * @param ec error code, #TALER_EC_NONE on success
- * @param http_status status returned by /keys, #MHD_HTTP_OK on success
- * @param full_reply JSON body of /keys request, NULL if reply was not in JSON
*/
typedef void
(*TALER_EXCHANGE_CertificationCallback) (
void *cls,
+ const struct TALER_EXCHANGE_HttpResponse *hr,
const struct TALER_EXCHANGE_Keys *keys,
- enum TALER_EXCHANGE_VersionCompatibility compat,
- enum TALER_ErrorCode ec,
- unsigned int http_status,
- const json_t *full_reply);
+ enum TALER_EXCHANGE_VersionCompatibility compat);
/**
@@ -650,21 +686,16 @@ struct TALER_EXCHANGE_WireAccount
* exchange, @a http_status will also be zero.
*
* @param cls closure
- * @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 hr HTTP response data
* @param accounts_len length of the @a accounts array
* @param accounts list of wire accounts of the exchange, NULL on error
- * @param full_reply the complete reply from the exchange (if it was in JSON)
*/
typedef void
(*TALER_EXCHANGE_WireCallback) (
void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
+ const struct TALER_EXCHANGE_HttpResponse *hr,
unsigned int accounts_len,
- const struct TALER_EXCHANGE_WireAccount *accounts,
- const json_t *full_reply);
+ const struct TALER_EXCHANGE_WireAccount *accounts);
/**
@@ -722,21 +753,16 @@ struct TALER_EXCHANGE_DepositHandle;
* deposit permission request to a exchange.
*
* @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 hr HTTP response data
* @param exchange_sig signature provided by the exchange
* @param sign_key exchange key used to sign @a obj, or NULL
- * @param obj the received JSON reply, should be kept as proof (and, in case of errors,
- * be forwarded to the customer)
*/
typedef void
(*TALER_EXCHANGE_DepositResultCallback) (
void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
+ const struct TALER_EXCHANGE_HttpResponse *hr,
const struct TALER_ExchangeSignatureP *exchange_sig,
- const struct TALER_ExchangePublicKeyP *sign_key,
- const json_t *obj);
+ const struct TALER_ExchangePublicKeyP *sign_key);
/**
@@ -822,20 +848,14 @@ struct TALER_EXCHANGE_RefundHandle;
* refund request to an exchange.
*
* @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 hr HTTP response data
* @param sign_key exchange key used to sign @a obj, or NULL
- * @param obj the received JSON reply, should be kept as proof (and, in particular,
- * be forwarded to the customer)
*/
typedef void
(*TALER_EXCHANGE_RefundCallback) (
void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- const struct TALER_ExchangePublicKeyP *sign_key,
- const json_t *obj);
+ const struct TALER_EXCHANGE_HttpResponse *hr,
+ const struct TALER_ExchangePublicKeyP *sign_key);
/**
@@ -1120,10 +1140,7 @@ struct TALER_EXCHANGE_ReserveHistory
* reserve status request to a exchange.
*
* @param cls closure
- * @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 json original response in JSON format (useful only for diagnostics)
+ * @param hr HTTP response data
* @param balance current balance in the reserve, NULL on error
* @param history_length number of entries in the transaction history, 0 on error
* @param history detailed transaction history, NULL on error
@@ -1131,11 +1148,8 @@ struct TALER_EXCHANGE_ReserveHistory
typedef void
(*TALER_EXCHANGE_ReservesGetCallback) (
void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- const json_t *json,
- const struct
- TALER_Amount *balance,
+ const struct TALER_EXCHANGE_HttpResponse *hr,
+ const struct TALER_Amount *balance,
unsigned int history_length,
const struct TALER_EXCHANGE_ReserveHistory *history);
@@ -1189,19 +1203,14 @@ struct TALER_EXCHANGE_WithdrawHandle;
* withdraw request to a exchange.
*
* @param cls closure
- * @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 hr HTTP response data
* @param sig signature over the coin, NULL on error
- * @param full_response full response from the exchange (for logging, in case of errors)
*/
typedef void
(*TALER_EXCHANGE_WithdrawCallback) (
void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- const struct TALER_DenominationSignature *sig,
- const json_t *full_response);
+ const struct TALER_EXCHANGE_HttpResponse *hr,
+ const struct TALER_DenominationSignature *sig);
/**
@@ -1345,21 +1354,17 @@ struct TALER_EXCHANGE_MeltHandle;
* #TALER_EXCHANGE_refreshes_reveal().
*
* @param cls closure
- * @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 hr HTTP response data
* @param noreveal_index choice by the exchange in the cut-and-choose protocol,
* UINT32_MAX on error
* @param sign_key exchange key used to sign @a full_response, or NULL
- * @param full_response full response from the exchange (for logging, in case of errors)
*/
typedef void
-(*TALER_EXCHANGE_MeltCallback) (void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- uint32_t noreveal_index,
- const struct TALER_ExchangePublicKeyP *sign_key,
- const json_t *full_response);
+(*TALER_EXCHANGE_MeltCallback) (
+ void *cls,
+ const struct TALER_EXCHANGE_HttpResponse *hr,
+ uint32_t noreveal_index,
+ const struct TALER_ExchangePublicKeyP *sign_key);
/**
@@ -1412,23 +1417,18 @@ TALER_EXCHANGE_melt_cancel (struct TALER_EXCHANGE_MeltHandle *mh);
* the original request specified the respective denomination keys.
*
* @param cls closure
- * @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 hr HTTP response data
* @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
- * @param full_response full response from the exchange (for logging, in case of errors)
*/
typedef void
(*TALER_EXCHANGE_RefreshesRevealCallback)(
void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
+ const struct TALER_EXCHANGE_HttpResponse *hr,
unsigned int num_coins,
const struct TALER_PlanchetSecretsP *coin_privs,
- const struct TALER_DenominationSignature *sigs,
- const json_t *full_response);
+ const struct TALER_DenominationSignature *sigs);
/**
@@ -1496,25 +1496,20 @@ struct TALER_EXCHANGE_LinkHandle;
* created when the original coin was melted.
*
* @param cls closure
- * @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 hr HTTP response data
* @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
* @param pubs array of public keys for the @a sigs, NULL on error
- * @param full_response full response from the exchange (for logging, in case of errors)
*/
typedef void
(*TALER_EXCHANGE_LinkCallback) (
void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
+ const struct TALER_EXCHANGE_HttpResponse *hr,
unsigned int num_coins,
const struct TALER_CoinSpendPrivateKeyP *coin_privs,
const struct TALER_DenominationSignature *sigs,
- const struct TALER_DenominationPublicKey *pubs,
- const json_t *full_response);
+ const struct TALER_DenominationPublicKey *pubs);
/**
@@ -1560,11 +1555,8 @@ struct TALER_EXCHANGE_TransfersGetHandle;
* of the coin transactions that were combined into the wire transfer.
*
* @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 hr HTTP response data
* @param sign_key exchange key used to sign @a json, or NULL
- * @param json original json reply (may include signatures, those have then been
- * validated already)
* @param h_wire hash of the wire transfer address the transfer went to, or NULL on error
* @param execution_time time when the exchange claims to have performed the wire transfer
* @param total_amount total amount of the wire transfer, or NULL if the exchange could
@@ -1576,10 +1568,8 @@ struct TALER_EXCHANGE_TransfersGetHandle;
typedef void
(*TALER_EXCHANGE_TransfersGetCallback)(
void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
+ const struct TALER_EXCHANGE_HttpResponse *hr,
const struct TALER_ExchangePublicKeyP *sign_key,
- const json_t *json,
const struct GNUNET_HashCode *h_wire,
struct GNUNET_TIME_Absolute execution_time,
const struct TALER_Amount *total_amount,
@@ -1630,11 +1620,8 @@ struct TALER_EXCHANGE_DepositGetHandle;
* Function called with detailed wire transfer data.
*
* @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 hr HTTP response data
* @param sign_key exchange key used to sign @a json, or NULL
- * @param json original json reply (may include signatures, those have then been
- * validated already)
* @param wtid wire transfer identifier used by the exchange, NULL if exchange did not
* yet execute the transaction
* @param execution_time actual or planned execution time for the wire transfer
@@ -1643,13 +1630,10 @@ struct TALER_EXCHANGE_DepositGetHandle;
typedef void
(*TALER_EXCHANGE_DepositGetCallback)(
void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
+ const struct TALER_EXCHANGE_HttpResponse *hr,
const struct TALER_ExchangePublicKeyP *sign_key,
- const json_t *json,
const struct TALER_WireTransferIdentifierRawP *wtid,
- struct GNUNET_TIME_Absolute
- execution_time,
+ struct GNUNET_TIME_Absolute execution_time,
const struct TALER_Amount *coin_contribution);
@@ -1766,24 +1750,19 @@ struct TALER_EXCHANGE_RecoupHandle;
* the original request specified the respective denomination keys.
*
* @param cls closure
- * @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 hr HTTP response data
* @param amount amount the exchange will wire back for this coin,
* on error the total balance remaining, or NULL
* @param timestamp what time did the exchange receive the /recoup request
* @param reserve_pub public key of the reserve receiving the recoup, NULL if refreshed or on error
* @param old_coin_pub public key of the dirty coin, NULL if not refreshed or on error
- * @param full_response full response from the exchange (for logging, in case of errors)
*/
typedef void
(*TALER_EXCHANGE_RecoupResultCallback) (
void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
+ const struct TALER_EXCHANGE_HttpResponse *hr,
const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_CoinSpendPublicKeyP *old_coin_pub,
- const json_t *full_response);
+ const struct TALER_CoinSpendPublicKeyP *old_coin_pub);
/**
diff --git a/src/include/taler_json_lib.h b/src/include/taler_json_lib.h
index fa14dc0bc..094cbe2eb 100644
--- a/src/include/taler_json_lib.h
+++ b/src/include/taler_json_lib.h
@@ -133,6 +133,17 @@ TALER_JSON_get_error_code (const json_t *json);
/**
+ * Extract the Taler error hint from the given @a json object.
+ * Note that NULL is returned if no "hint" is present.
+ *
+ * @param json response to extract the error hint from
+ * @return the "hint" value from @a json; only valid as long as @a json is valid
+ */
+const char *
+TALER_JSON_get_error_hint (const json_t *json);
+
+
+/**
* Extract the Taler error code from the given @a data object, which is expected to be in JSON.
* Note that #TALER_EC_INVALID is returned if no "code" is present or if @a data is not in JSON.
*
diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h
index be20e0cd7..dcdbb3c19 100644
--- a/src/include/taler_testing_lib.h
+++ b/src/include/taler_testing_lib.h
@@ -135,19 +135,15 @@ TALER_TESTING_prepare_exchange (const char *config_filename,
*
* @param cls closure, typically, the "run" method containing
* all the commands to be run, and a closure for it.
+ * @param hr http response details
* @param keys the exchange's keys.
* @param compat protocol compatibility information.
- * @param ec error code, #TALER_EC_NONE on success
- * @param http_status status returned by /keys, #MHD_HTTP_OK on success
- * @param full_reply JSON body of /keys request, NULL if reply was not in JSON
*/
void
TALER_TESTING_cert_cb (void *cls,
+ const struct TALER_EXCHANGE_HttpResponse *hr,
const struct TALER_EXCHANGE_Keys *keys,
- enum TALER_EXCHANGE_VersionCompatibility compat,
- enum TALER_ErrorCode ec,
- unsigned int http_status,
- const json_t *full_reply);
+ enum TALER_EXCHANGE_VersionCompatibility compat);
/**