summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-04-05 22:05:38 +0200
committerChristian Grothoff <christian@grothoff.org>2020-04-05 22:05:38 +0200
commitbf8c5982a2e79f0b5198a0033dd41e9702d093f9 (patch)
tree93b62feb9b7e24ae3d4f73b1a5f883a8fc368bfe /src/lib
parent5059da7108fb2d65fc3844ffe695574c532f8dff (diff)
downloadexchange-bf8c5982a2e79f0b5198a0033dd41e9702d093f9.tar.gz
exchange-bf8c5982a2e79f0b5198a0033dd41e9702d093f9.tar.bz2
exchange-bf8c5982a2e79f0b5198a0033dd41e9702d093f9.zip
make exchange API more uniform in how information is returned
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/auditor_api_deposit_confirmation.c35
-rw-r--r--src/lib/auditor_api_exchanges.c47
-rw-r--r--src/lib/auditor_api_handle.c42
-rw-r--r--src/lib/exchange_api_deposit.c87
-rw-r--r--src/lib/exchange_api_deposits_get.c48
-rw-r--r--src/lib/exchange_api_handle.c54
-rw-r--r--src/lib/exchange_api_handle.h8
-rw-r--r--src/lib/exchange_api_link.c47
-rw-r--r--src/lib/exchange_api_melt.c54
-rw-r--r--src/lib/exchange_api_recoup.c69
-rw-r--r--src/lib/exchange_api_refreshes_reveal.c44
-rw-r--r--src/lib/exchange_api_refund.c47
-rw-r--r--src/lib/exchange_api_reserves_get.c44
-rw-r--r--src/lib/exchange_api_transfers_get.c59
-rw-r--r--src/lib/exchange_api_wire.c67
-rw-r--r--src/lib/exchange_api_withdraw.c56
16 files changed, 444 insertions, 364 deletions
diff --git a/src/lib/auditor_api_deposit_confirmation.c b/src/lib/auditor_api_deposit_confirmation.c
index e0135bb4..04510208 100644
--- a/src/lib/auditor_api_deposit_confirmation.c
+++ b/src/lib/auditor_api_deposit_confirmation.c
@@ -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 General Public License as published by the Free Software
@@ -87,53 +87,58 @@ handle_deposit_confirmation_finished (void *cls,
{
const json_t *json = djson;
struct TALER_AUDITOR_DepositConfirmationHandle *dh = cls;
- enum TALER_ErrorCode ec;
+ struct TALER_AUDITOR_HttpResponse hr = {
+ .reply = json,
+ .http_status = (unsigned int) response_code
+ };
dh->job = NULL;
switch (response_code)
{
case 0:
- ec = TALER_EC_INVALID_RESPONSE;
+ hr.ec = TALER_EC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
- ec = TALER_EC_NONE;
+ hr.ec = TALER_EC_NONE;
break;
case MHD_HTTP_BAD_REQUEST:
- ec = TALER_JSON_get_error_code (json);
+ hr.ec = TALER_JSON_get_error_code (json);
+ hr.hint = TALER_JSON_get_error_hint (json);
/* This should never happen, either us or the auditor is buggy
(or API version conflict); just pass JSON reply to the application */
break;
case MHD_HTTP_FORBIDDEN:
- ec = TALER_JSON_get_error_code (json);
+ hr.ec = TALER_JSON_get_error_code (json);
+ hr.hint = TALER_JSON_get_error_hint (json);
/* Nothing really to verify, auditor says one of the signatures is
invalid; as we checked them, this should never happen, we
should pass the JSON reply to the application */
break;
case MHD_HTTP_NOT_FOUND:
- ec = TALER_JSON_get_error_code (json);
+ hr.ec = TALER_JSON_get_error_code (json);
+ hr.hint = TALER_JSON_get_error_hint (json);
/* Nothing really to verify, this should never
happen, we should pass the JSON reply to the application */
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
- ec = TALER_JSON_get_error_code (json);
+ hr.ec = TALER_JSON_get_error_code (json);
+ hr.hint = TALER_JSON_get_error_hint (json);
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
break;
default:
/* unexpected response code */
- ec = TALER_JSON_get_error_code (json);
+ hr.ec = TALER_JSON_get_error_code (json);
+ hr.hint = TALER_JSON_get_error_hint (json);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d\n",
(unsigned int) response_code,
- ec);
- GNUNET_break (0);
- response_code = 0;
+ hr.ec);
+ GNUNET_break_op (0);
break;
}
dh->cb (dh->cb_cls,
- response_code,
- ec,
- json);
+ &hr);
TALER_AUDITOR_deposit_confirmation_cancel (dh);
}
diff --git a/src/lib/auditor_api_exchanges.c b/src/lib/auditor_api_exchanges.c
index 4e23267f..83cbc4bb 100644
--- a/src/lib/auditor_api_exchanges.c
+++ b/src/lib/auditor_api_exchanges.c
@@ -89,13 +89,16 @@ handle_exchanges_finished (void *cls,
const json_t *ja;
unsigned int ja_len;
struct TALER_AUDITOR_ListExchangesHandle *leh = cls;
- enum TALER_ErrorCode ec;
+ struct TALER_AUDITOR_HttpResponse hr = {
+ .reply = json,
+ .http_status = (unsigned int) response_code
+ };
leh->job = NULL;
switch (response_code)
{
case 0:
- ec = TALER_EC_INVALID_RESPONSE;
+ hr.ec = TALER_EC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
ja = json_object_get (json,
@@ -104,8 +107,8 @@ handle_exchanges_finished (void *cls,
(! json_is_array (ja)) )
{
GNUNET_break (0);
- ec = TALER_EC_AUDITOR_EXCHANGES_REPLY_MALFORMED;
- response_code = 0;
+ hr.ec = TALER_EC_AUDITOR_EXCHANGES_REPLY_MALFORMED;
+ hr.http_status = 0;
break;
}
@@ -113,8 +116,8 @@ handle_exchanges_finished (void *cls,
if (ja_len > MAX_EXCHANGES)
{
GNUNET_break (0);
- ec = TALER_EC_AUDITOR_EXCHANGES_REPLY_MALFORMED;
- response_code = 0;
+ hr.ec = TALER_EC_AUDITOR_EXCHANGES_REPLY_MALFORMED;
+ hr.http_status = 0;
break;
}
{
@@ -138,54 +141,54 @@ handle_exchanges_finished (void *cls,
{
GNUNET_break_op (0);
ok = GNUNET_NO;
- ec = TALER_EC_AUDITOR_EXCHANGES_REPLY_MALFORMED;
+ hr.ec = TALER_EC_AUDITOR_EXCHANGES_REPLY_MALFORMED;
+ hr.http_status = 0;
break;
}
}
if (GNUNET_YES != ok)
break;
leh->cb (leh->cb_cls,
- response_code,
- TALER_EC_NONE,
+ &hr,
ja_len,
- ei,
- json);
+ ei);
TALER_AUDITOR_list_exchanges_cancel (leh);
return;
}
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the auditor is buggy
(or API version conflict); just pass JSON reply to the application */
- ec = TALER_JSON_get_error_code (json);
+ hr.ec = TALER_JSON_get_error_code (json);
+ hr.hint = TALER_JSON_get_error_hint (json);
break;
case MHD_HTTP_NOT_FOUND:
/* Nothing really to verify, this should never
happen, we should pass the JSON reply to the application */
- ec = TALER_JSON_get_error_code (json);
+ hr.ec = TALER_JSON_get_error_code (json);
+ hr.hint = TALER_JSON_get_error_hint (json);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- ec = TALER_JSON_get_error_code (json);
+ hr.ec = TALER_JSON_get_error_code (json);
+ hr.hint = TALER_JSON_get_error_hint (json);
break;
default:
/* unexpected response code */
- ec = TALER_JSON_get_error_code (json);
+ hr.ec = TALER_JSON_get_error_code (json);
+ hr.hint = TALER_JSON_get_error_hint (json);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d\n",
(unsigned int) response_code,
- (int) ec);
- GNUNET_break (0);
- response_code = 0;
+ (int) hr.ec);
+ GNUNET_break_op (0);
break;
}
if (NULL != leh->cb)
leh->cb (leh->cb_cls,
- response_code,
- TALER_JSON_get_error_code (json),
+ &hr,
0,
- NULL,
- json);
+ NULL);
TALER_AUDITOR_list_exchanges_cancel (leh);
}
diff --git a/src/lib/auditor_api_handle.c b/src/lib/auditor_api_handle.c
index 85f42c3f..99d0a4f9 100644
--- a/src/lib/auditor_api_handle.c
+++ b/src/lib/auditor_api_handle.c
@@ -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 General Public License as published by the Free Software
@@ -197,9 +197,9 @@ free_version_info (struct TALER_AUDITOR_VersionInformation *vi)
* @param[in] resp_obj JSON object to parse
* @param[out] vi where to store the results we decoded
* @param[out] vc where to store version compatibility data
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (malformed JSON)
+ * @return #TALER_EC_NONE on success
*/
-static int
+static enum TALER_ErrorCode
decode_version_json (const json_t *resp_obj,
struct TALER_AUDITOR_VersionInformation *vi,
enum TALER_AUDITOR_VersionCompatibility *vc)
@@ -219,7 +219,7 @@ decode_version_json (const json_t *resp_obj,
if (JSON_OBJECT != json_typeof (resp_obj))
{
GNUNET_break_op (0);
- return GNUNET_SYSERR;
+ return TALER_EC_JSON_INVALID;
}
/* check the version */
if (GNUNET_OK !=
@@ -228,7 +228,7 @@ decode_version_json (const json_t *resp_obj,
NULL, NULL))
{
GNUNET_break_op (0);
- return GNUNET_SYSERR;
+ return TALER_EC_JSON_INVALID;
}
if (3 != sscanf (ver,
"%u:%u:%u",
@@ -237,7 +237,7 @@ decode_version_json (const json_t *resp_obj,
&age))
{
GNUNET_break_op (0);
- return GNUNET_SYSERR;
+ return TALER_EC_VERSION_MALFORMED;
}
vi->version = GNUNET_strdup (ver);
*vc = TALER_AUDITOR_VC_MATCH;
@@ -253,7 +253,7 @@ decode_version_json (const json_t *resp_obj,
if (TALER_PROTOCOL_CURRENT - TALER_PROTOCOL_AGE > current)
*vc |= TALER_AUDITOR_VC_INCOMPATIBLE;
}
- return GNUNET_OK;
+ return TALER_EC_NONE;
}
@@ -283,6 +283,10 @@ version_completed_cb (void *cls,
struct VersionRequest *vr = cls;
struct TALER_AUDITOR_Handle *auditor = vr->auditor;
enum TALER_AUDITOR_VersionCompatibility vc;
+ struct TALER_AUDITOR_HttpResponse hr = {
+ .reply = resp_obj,
+ .http_status = (unsigned int) response_code
+ };
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received version from URL `%s' with status %ld.\n",
@@ -293,6 +297,8 @@ version_completed_cb (void *cls,
{
case 0:
case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ /* NOTE: this design is debatable. We MAY want to throw this error at the
+ client. We may then still additionally internally re-try. */
free_version_request (vr);
auditor->vr = NULL;
GNUNET_assert (NULL == auditor->retry_task);
@@ -306,24 +312,28 @@ version_completed_cb (void *cls,
{
GNUNET_break_op (0);
TALER_LOG_WARNING ("NULL body for a 200-OK /version\n");
- response_code = 0;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_INVALID_RESPONSE;
break;
}
- if (GNUNET_OK !=
- decode_version_json (resp_obj,
- &auditor->vi,
- &vc))
+ hr.ec = decode_version_json (resp_obj,
+ &auditor->vi,
+ &vc);
+ if (TALER_EC_NONE != hr.ec)
{
GNUNET_break_op (0);
- response_code = 0;
+ hr.http_status = 0;
break;
}
auditor->retry_delay = GNUNET_TIME_UNIT_ZERO; /* restart quickly */
break;
default:
+ hr.ec = TALER_JSON_get_error_code (resp_obj);
+ hr.hint = TALER_JSON_get_error_hint (resp_obj);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u\n",
- (unsigned int) response_code);
+ "Unexpected response code %u/%d\n",
+ (unsigned int) response_code,
+ (int) hr.ec);
break;
}
if (MHD_HTTP_OK != response_code)
@@ -338,6 +348,7 @@ version_completed_cb (void *cls,
free_version_info (&auditor->vi);
/* notify application that we failed */
auditor->version_cb (auditor->version_cb_cls,
+ &hr,
NULL,
vc);
return;
@@ -352,6 +363,7 @@ version_completed_cb (void *cls,
auditor);
/* notify application about the key information */
auditor->version_cb (auditor->version_cb_cls,
+ &hr,
&auditor->vi,
vc);
}
diff --git a/src/lib/exchange_api_deposit.c b/src/lib/exchange_api_deposit.c
index 54dad747..e01a3c58 100644
--- a/src/lib/exchange_api_deposit.c
+++ b/src/lib/exchange_api_deposit.c
@@ -156,25 +156,24 @@ auditor_cb (void *cls,
TALER_amount_ntoh (&amount_without_fee,
&dh->depconf.amount_without_fee);
aie = GNUNET_new (struct TEAH_AuditorInteractionEntry);
- aie->dch = TALER_AUDITOR_deposit_confirmation (ah,
- &dh->depconf.h_wire,
- &dh->depconf.h_contract_terms,
- GNUNET_TIME_absolute_ntoh (
- dh->depconf.timestamp),
- GNUNET_TIME_absolute_ntoh (
- dh->depconf.refund_deadline),
- &amount_without_fee,
- &dh->depconf.coin_pub,
- &dh->depconf.merchant,
- &dh->exchange_pub,
- &dh->exchange_sig,
- &key_state->master_pub,
- spk->valid_from,
- spk->valid_until,
- spk->valid_legal,
- &spk->master_sig,
- &TEAH_acc_confirmation_cb,
- aie);
+ aie->dch = TALER_AUDITOR_deposit_confirmation (
+ ah,
+ &dh->depconf.h_wire,
+ &dh->depconf.h_contract_terms,
+ GNUNET_TIME_absolute_ntoh (dh->depconf.timestamp),
+ GNUNET_TIME_absolute_ntoh (dh->depconf.refund_deadline),
+ &amount_without_fee,
+ &dh->depconf.coin_pub,
+ &dh->depconf.merchant,
+ &dh->exchange_pub,
+ &dh->exchange_sig,
+ &key_state->master_pub,
+ spk->valid_from,
+ spk->valid_until,
+ spk->valid_legal,
+ &spk->master_sig,
+ &TEAH_acc_confirmation_cb,
+ aie);
return aie;
}
@@ -305,13 +304,16 @@ handle_deposit_finished (void *cls,
struct TALER_ExchangeSignatureP *es = NULL;
struct TALER_ExchangePublicKeyP *ep = NULL;
const json_t *j = response;
- enum TALER_ErrorCode ec;
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = j,
+ .http_status = (unsigned int) response_code
+ };
dh->job = NULL;
switch (response_code)
{
case 0:
- ec = TALER_EC_INVALID_RESPONSE;
+ hr.ec = TALER_EC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
if (GNUNET_OK !=
@@ -321,66 +323,71 @@ handle_deposit_finished (void *cls,
&exchange_pub))
{
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE;
}
else
{
es = &exchange_sig;
ep = &exchange_pub;
- ec = TALER_EC_NONE;
}
break;
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the exchange is buggy
(or API version conflict); just pass JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_CONFLICT:
/* Double spending; check signatures on transaction history */
- ec = TALER_JSON_get_error_code (j);
if (GNUNET_OK !=
verify_deposit_signature_forbidden (dh,
j))
{
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE;
+ }
+ else
+ {
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
}
break;
case MHD_HTTP_FORBIDDEN:
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
/* Nothing really to verify, exchange says one of the signatures is
invalid; as we checked them, this should never happen, we
should pass the JSON reply to the application */
break;
case MHD_HTTP_NOT_FOUND:
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
/* Nothing really to verify, this should never
- happen, we should pass the JSON reply to the application */
+ happen, we should pass the JSON reply to the application */
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
break;
default:
/* unexpected response code */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d\n",
(unsigned int) response_code,
- ec);
- GNUNET_break (0);
- response_code = 0;
+ hr.ec);
+ GNUNET_break_op (0);
break;
}
dh->cb (dh->cb_cls,
- response_code,
- ec,
+ &hr,
es,
- ep,
- j);
+ ep);
TALER_EXCHANGE_deposit_cancel (dh);
}
diff --git a/src/lib/exchange_api_deposits_get.c b/src/lib/exchange_api_deposits_get.c
index 0ab926ea..053f3ac8 100644
--- a/src/lib/exchange_api_deposits_get.c
+++ b/src/lib/exchange_api_deposits_get.c
@@ -151,13 +151,16 @@ handle_deposit_wtid_finished (void *cls,
struct TALER_ExchangePublicKeyP exchange_pub;
struct TALER_ExchangePublicKeyP *ep = NULL;
const json_t *j = response;
- enum TALER_ErrorCode ec;
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = j,
+ .http_status = (unsigned int) response_code
+ };
dwh->job = NULL;
switch (response_code)
{
case 0:
- ec = TALER_EC_INVALID_RESPONSE;
+ hr.ec = TALER_EC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
{
@@ -174,8 +177,8 @@ handle_deposit_wtid_finished (void *cls,
NULL, NULL))
{
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_DEPOSITS_INVALID_BODY_BY_EXCHANGE;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_DEPOSITS_INVALID_BODY_BY_EXCHANGE;
break;
}
wtid = &dwh->depconf.wtid;
@@ -189,13 +192,12 @@ handle_deposit_wtid_finished (void *cls,
&exchange_pub))
{
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_DEPOSITS_INVALID_SIGNATURE_BY_EXCHANGE;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_DEPOSITS_INVALID_SIGNATURE_BY_EXCHANGE;
}
else
{
ep = &exchange_pub;
- ec = TALER_EC_NONE;
}
}
break;
@@ -213,49 +215,51 @@ handle_deposit_wtid_finished (void *cls,
NULL, NULL))
{
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_DEPOSITS_INVALID_BODY_BY_EXCHANGE;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_DEPOSITS_INVALID_BODY_BY_EXCHANGE;
break;
}
- ec = TALER_EC_NONE;
}
break;
case MHD_HTTP_BAD_REQUEST:
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
/* 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_FORBIDDEN:
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
/* Nothing really to verify, exchange says one of the signatures is
invalid; as we checked them, this should never happen, we
should pass the JSON reply to the application */
break;
case MHD_HTTP_NOT_FOUND:
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
/* Exchange does not know about transaction;
we should pass the reply to the application */
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
break;
default:
/* unexpected response code */
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u\n",
- (unsigned int) response_code);
- GNUNET_break (0);
- ec = TALER_JSON_get_error_code (j);
- response_code = 0;
+ "Unexpected response code %u/%d\n",
+ (unsigned int) response_code,
+ (int) hr.ec);
+ GNUNET_break_op (0);
break;
}
dwh->cb (dwh->cb_cls,
- response_code,
- ec,
+ &hr,
ep,
- j,
wtid,
execution_time,
coin_contribution);
diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c
index 8ae5b06d..5c69ee97 100644
--- a/src/lib/exchange_api_handle.c
+++ b/src/lib/exchange_api_handle.c
@@ -265,27 +265,22 @@ struct KeysRequest
* auditor's /deposit-confirmation handler.
*
* @param cls closure of type `struct TEAH_AuditorInteractionEntry *`
- * @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
*/
void
TEAH_acc_confirmation_cb (void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- const json_t *json)
+ const struct TALER_AUDITOR_HttpResponse *hr)
{
struct TEAH_AuditorInteractionEntry *aie = cls;
struct TEAH_AuditorListEntry *ale = aie->ale;
- (void) json;
- if (MHD_HTTP_OK != http_status)
+ if (MHD_HTTP_OK != hr->http_status)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to submit deposit confirmation to auditor `%s' with HTTP status %d (EC: %d). This is acceptable if it does not happen often.\n",
ale->auditor_url,
- http_status,
- (int) ec);
+ hr->http_status,
+ hr->ec);
}
GNUNET_CONTAINER_DLL_remove (ale->ai_head,
ale->ai_tail,
@@ -664,12 +659,14 @@ parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor,
* auditor as 'up'.
*
* @param cls closure, a `struct TEAH_AuditorListEntry *`
+ * @param hr http response from the auditor
* @param vi basic information about the auditor
* @param compat protocol compatibility information
*/
static void
auditor_version_cb (
void *cls,
+ const struct TALER_AUDITOR_HttpResponse *hr,
const struct TALER_AUDITOR_VersionInformation *vi,
enum TALER_AUDITOR_VersionCompatibility compat)
{
@@ -1252,6 +1249,10 @@ keys_completed_cb (void *cls,
struct TALER_EXCHANGE_Keys kd_old;
enum TALER_EXCHANGE_VersionCompatibility vc;
const json_t *j = resp_obj;
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = j,
+ .http_status = (unsigned int) response_code
+ };
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received keys from URL `%s' with status %ld.\n",
@@ -1328,7 +1329,8 @@ keys_completed_cb (void *cls,
&vc))
{
TALER_LOG_ERROR ("Could not decode /keys response\n");
- response_code = 0;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_KEYS_INVALID;
for (unsigned int i = 0; i<kd.num_auditors; i++)
{
struct TALER_EXCHANGE_AuditorInformation *anew = &kd.auditors[i];
@@ -1354,9 +1356,12 @@ keys_completed_cb (void *cls,
exchange->retry_delay = GNUNET_TIME_UNIT_ZERO;
break;
default:
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u\n",
- (unsigned int) response_code);
+ "Unexpected response code %u/%d\n",
+ (unsigned int) response_code,
+ (int) hr.ec);
break;
}
exchange->key_data = kd;
@@ -1380,11 +1385,9 @@ keys_completed_cb (void *cls,
free_key_data (&kd_old);
/* notify application that we failed */
exchange->cert_cb (exchange->cert_cb_cls,
+ &hr,
NULL,
- vc,
- TALER_JSON_get_error_code (j),
- response_code,
- j);
+ vc);
return;
}
@@ -1397,11 +1400,9 @@ keys_completed_cb (void *cls,
update_auditors (exchange);
/* notify application about the key information */
exchange->cert_cb (exchange->cert_cb_cls,
+ &hr,
&exchange->key_data,
- vc,
- TALER_EC_NONE,
- MHD_HTTP_OK,
- j);
+ vc);
free_key_data (&kd_old);
}
@@ -1575,6 +1576,11 @@ deserialize_data (struct TALER_EXCHANGE_Handle *exchange,
GNUNET_JSON_spec_end ()
};
struct TALER_EXCHANGE_Keys key_data;
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .ec = TALER_EC_NONE,
+ .http_status = MHD_HTTP_OK,
+ .reply = data
+ };
if (NULL == data)
return;
@@ -1622,11 +1628,9 @@ deserialize_data (struct TALER_EXCHANGE_Handle *exchange,
update_auditors (exchange);
/* notify application about the key information */
exchange->cert_cb (exchange->cert_cb_cls,
+ &hr,
&exchange->key_data,
- vc,
- TALER_EC_NONE,
- MHD_HTTP_OK,
- data);
+ vc);
GNUNET_JSON_parse_free (spec);
}
diff --git a/src/lib/exchange_api_handle.h b/src/lib/exchange_api_handle.h
index 63f789c8..b4b8ccf5 100644
--- a/src/lib/exchange_api_handle.h
+++ b/src/lib/exchange_api_handle.h
@@ -79,15 +79,11 @@ typedef struct TEAH_AuditorInteractionEntry *
* auditor's /deposit-confirmation handler.
*
* @param cls closure of type `struct TEAH_AuditorInteractionEntry *`
- * @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
*/
void
TEAH_acc_confirmation_cb (void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- const json_t *json);
+ const struct TALER_AUDITOR_HttpResponse *hr);
/**
diff --git a/src/lib/exchange_api_link.c b/src/lib/exchange_api_link.c
index 088e4aa3..c05b2e56 100644
--- a/src/lib/exchange_api_link.c
+++ b/src/lib/exchange_api_link.c
@@ -186,6 +186,10 @@ parse_link_ok (struct TALER_EXCHANGE_LinkHandle *lh,
unsigned int session;
unsigned int num_coins;
int ret;
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = json,
+ .http_status = MHD_HTTP_OK
+ };
if (! json_is_array (json))
{
@@ -305,13 +309,11 @@ parse_link_ok (struct TALER_EXCHANGE_LinkHandle *lh,
if (off_coin == num_coins)
{
lh->link_cb (lh->link_cb_cls,
- MHD_HTTP_OK,
- TALER_EC_NONE,
+ &hr,
num_coins,
coin_privs,
sigs,
- pubs,
- json);
+ pubs);
lh->link_cb = NULL;
ret = GNUNET_OK;
}
@@ -350,13 +352,16 @@ handle_link_finished (void *cls,
{
struct TALER_EXCHANGE_LinkHandle *lh = cls;
const json_t *j = response;
- enum TALER_ErrorCode ec;
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = j,
+ .http_status = (unsigned int) response_code
+ };
lh->job = NULL;
switch (response_code)
{
case 0:
- ec = TALER_EC_INVALID_RESPONSE;
+ hr.ec = TALER_EC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
if (GNUNET_OK !=
@@ -364,47 +369,49 @@ handle_link_finished (void *cls,
j))
{
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_LINK_REPLY_MALFORMED;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_LINK_REPLY_MALFORMED;
break;
}
GNUNET_assert (NULL == lh->link_cb);
TALER_EXCHANGE_link_cancel (lh);
return;
case MHD_HTTP_BAD_REQUEST:
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
/* 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_NOT_FOUND:
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
/* Nothing really to verify, exchange says this coin was not melted; we
should pass the JSON reply to the application */
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
break;
default:
/* unexpected response code */
+ GNUNET_break_op (0);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u\n",
- (unsigned int) response_code);
- GNUNET_break (0);
- response_code = 0;
- ec = TALER_JSON_get_error_code (j);
+ "Unexpected response code %u/%d\n",
+ (unsigned int) response_code,
+ (int) hr.ec);
break;
}
if (NULL != lh->link_cb)
lh->link_cb (lh->link_cb_cls,
- response_code,
- ec,
+ &hr,
0,
NULL,
NULL,
- NULL,
- j);
+ NULL);
TALER_EXCHANGE_link_cancel (lh);
}
diff --git a/src/lib/exchange_api_melt.c b/src/lib/exchange_api_melt.c
index d6acf92c..4d0d21b3 100644
--- a/src/lib/exchange_api_melt.c
+++ b/src/lib/exchange_api_melt.c
@@ -267,13 +267,16 @@ handle_melt_finished (void *cls,
uint32_t noreveal_index = TALER_CNC_KAPPA; /* invalid value */
struct TALER_ExchangePublicKeyP exchange_pub;
const json_t *j = response;
- enum TALER_ErrorCode ec;
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = j,
+ .http_status = (unsigned int) response_code
+ };
mh->job = NULL;
switch (response_code)
{
case 0:
- ec = TALER_EC_INVALID_RESPONSE;
+ hr.ec = TALER_EC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
if (GNUNET_OK !=
@@ -283,30 +286,25 @@ handle_melt_finished (void *cls,
&noreveal_index))
{
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_MELT_INVALID_SIGNATURE_BY_EXCHANGE;
- }
- else
- {
- ec = TALER_EC_NONE;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_MELT_INVALID_SIGNATURE_BY_EXCHANGE;
}
if (NULL != mh->melt_cb)
{
mh->melt_cb (mh->melt_cb_cls,
- response_code,
- ec,
+ &hr,
noreveal_index,
(0 == response_code)
? NULL
- : &exchange_pub,
- j);
+ : &exchange_pub);
mh->melt_cb = NULL;
}
break;
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the exchange is buggy
(or API version conflict); just pass JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_CONFLICT:
/* Double spending; check signatures on transaction history */
@@ -315,46 +313,46 @@ handle_melt_finished (void *cls,
j))
{
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_MELT_INVALID_SIGNATURE_BY_EXCHANGE;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_MELT_INVALID_SIGNATURE_BY_EXCHANGE;
+ hr.hint = TALER_JSON_get_error_hint (j);
}
- else
- ec = TALER_EC_NONE;
break;
case MHD_HTTP_FORBIDDEN:
/* Nothing really to verify, exchange says one of the signatures is
invalid; assuming we checked them, this should never happen, we
should pass the JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_NOT_FOUND:
/* Nothing really to verify, this should never
happen, we should pass the JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
default:
/* unexpected response code */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d\n",
(unsigned int) response_code,
- ec);
- GNUNET_break (0);
- response_code = 0;
+ hr.ec);
+ GNUNET_break_op (0);
break;
}
if (NULL != mh->melt_cb)
mh->melt_cb (mh->melt_cb_cls,
- response_code,
- ec,
+ &hr,
UINT32_MAX,
- NULL,
- j);
+ NULL);
TALER_EXCHANGE_melt_cancel (mh);
}
diff --git a/src/lib/exchange_api_recoup.c b/src/lib/exchange_api_recoup.c
index a3416b5b..484d2753 100644
--- a/src/lib/exchange_api_recoup.c
+++ b/src/lib/exchange_api_recoup.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2017 Taler Systems SA
+ Copyright (C) 2017-2020 Taler Systems SA
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
@@ -112,6 +112,10 @@ process_recoup_response (const struct TALER_EXCHANGE_RecoupHandle *ph,
GNUNET_JSON_spec_fixed_auto ("old_coin_pub", &old_coin_pub),
GNUNET_JSON_spec_end ()
};
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = json,
+ .http_status = MHD_HTTP_OK
+ };
if (GNUNET_OK !=
GNUNET_JSON_parse (json,
@@ -127,11 +131,9 @@ process_recoup_response (const struct TALER_EXCHANGE_RecoupHandle *ph,
return GNUNET_SYSERR;
}
ph->cb (ph->cb_cls,
- MHD_HTTP_OK,
- TALER_EC_NONE,
+ &hr,
ph->was_refreshed ? NULL : &reserve_pub,
- ph->was_refreshed ? &old_coin_pub : NULL,
- json);
+ ph->was_refreshed ? &old_coin_pub : NULL);
return GNUNET_OK;
}
@@ -151,23 +153,25 @@ handle_recoup_finished (void *cls,
{
struct TALER_EXCHANGE_RecoupHandle *ph = cls;
const json_t *j = response;
- enum TALER_ErrorCode ec;
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = j,
+ .http_status = (unsigned int) response_code
+ };
ph->job = NULL;
switch (response_code)
{
case 0:
- ec = TALER_EC_INVALID_RESPONSE;
+ hr.ec = TALER_EC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
- ec = TALER_EC_NONE;
if (GNUNET_OK !=
process_recoup_response (ph,
j))
{
GNUNET_break_op (0);
- ec = TALER_EC_RECOUP_REPLY_MALFORMED;
- response_code = 0;
+ hr.ec = TALER_EC_RECOUP_REPLY_MALFORMED;
+ hr.http_status = 0;
break;
}
TALER_EXCHANGE_recoup_cancel (ph);
@@ -175,7 +179,8 @@ handle_recoup_finished (void *cls,
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the exchange is buggy
(or API version conflict); just pass JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_CONFLICT:
{
@@ -195,15 +200,18 @@ handle_recoup_finished (void *cls,
&total))
{
GNUNET_break_op (0);
- response_code = 0;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_RECOUP_REPLY_MALFORMED;
+ }
+ else
+ {
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
}
- ec = TALER_JSON_get_error_code (j);
ph->cb (ph->cb_cls,
- response_code,
- ec,
- NULL,
+ &hr,
NULL,
- j);
+ NULL);
TALER_EXCHANGE_recoup_cancel (ph);
return;
}
@@ -211,39 +219,42 @@ handle_recoup_finished (void *cls,
/* Nothing really to verify, exchange says one of the signatures is
invalid; as we checked them, this should never happen, we
should pass the JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_NOT_FOUND:
/* Nothing really to verify, this should never
happen, we should pass the JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_GONE:
/* Kind of normal: the money was already sent to the merchant
(it was too late for the refund). */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
default:
/* unexpected response code */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u\n",
- (unsigned int) response_code);
+ "Unexpected response code %u/%d\n",
+ (unsigned int) response_code,
+ (int) hr.ec);
GNUNET_break (0);
- response_code = 0;
break;
}
ph->cb (ph->cb_cls,
- response_code,
- ec,
- NULL,
+ &hr,
NULL,
- j);
+ NULL);
TALER_EXCHANGE_recoup_cancel (ph);
}
diff --git a/src/lib/exchange_api_refreshes_reveal.c b/src/lib/exchange_api_refreshes_reveal.c
index f07dc904..f8071f5c 100644
--- a/src/lib/exchange_api_refreshes_reveal.c
+++ b/src/lib/exchange_api_refreshes_reveal.c
@@ -202,13 +202,16 @@ handle_refresh_reveal_finished (void *cls,
{
struct TALER_EXCHANGE_RefreshesRevealHandle *rrh = cls;
const json_t *j = response;
- enum TALER_ErrorCode ec;
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = j,
+ .http_status = MHD_HTTP_OK
+ };
rrh->job = NULL;
switch (response_code)
{
case 0:
- ec = TALER_EC_INVALID_RESPONSE;
+ hr.ec = TALER_EC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
{
@@ -221,19 +224,16 @@ handle_refresh_reveal_finished (void *cls,
sigs);
if (GNUNET_OK != ret)
{
- response_code = 0;
- ec = TALER_EC_REVEAL_REPLY_MALFORMED;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_REVEAL_REPLY_MALFORMED;
}
else
{
- ec = TALER_EC_NONE;
rrh->reveal_cb (rrh->reveal_cb_cls,
- MHD_HTTP_OK,
- ec,
+ &hr,
rrh->md->num_fresh_coins,
rrh->md->fresh_coins[rrh->noreveal_index],
- sigs,
- j);
+ sigs);
rrh->reveal_cb = NULL;
}
for (unsigned int i = 0; i<rrh->md->num_fresh_coins; i++)
@@ -245,37 +245,39 @@ handle_refresh_reveal_finished (void *cls,
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the exchange is buggy
(or API version conflict); just pass JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_CONFLICT:
/* Nothing really to verify, exchange says our reveal is inconsistent
with our commitment, so either side is buggy; we
should pass the JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
default:
/* unexpected response code */
+ GNUNET_break_op (0);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u\n",
- (unsigned int) response_code);
- GNUNET_break (0);
- response_code = 0;
- ec = TALER_JSON_get_error_code (j);
+ "Unexpected response code %u/%d\n",
+ (unsigned int) response_code,
+ (int) hr.ec);
break;
}
if (NULL != rrh->reveal_cb)
rrh->reveal_cb (rrh->reveal_cb_cls,
- response_code,
- ec,
+ &hr,
0,
NULL,
- NULL,
- j);
+ NULL);
TALER_EXCHANGE_refreshes_reveal_cancel (rrh);
}
diff --git a/src/lib/exchange_api_refund.c b/src/lib/exchange_api_refund.c
index 826c39b1..81127c5a 100644
--- a/src/lib/exchange_api_refund.c
+++ b/src/lib/exchange_api_refund.c
@@ -145,13 +145,16 @@ handle_refund_finished (void *cls,
struct TALER_ExchangePublicKeyP exchange_pub;
struct TALER_ExchangePublicKeyP *ep = NULL;
const json_t *j = response;
- enum TALER_ErrorCode ec;
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = j,
+ .http_status = (unsigned int) response_code
+ };
rh->job = NULL;
switch (response_code)
{
case 0:
- ec = TALER_EC_INVALID_RESPONSE;
+ hr.ec = TALER_EC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
if (GNUNET_OK !=
@@ -160,67 +163,71 @@ handle_refund_finished (void *cls,
&exchange_pub))
{
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_REFUND_INVALID_SIGNATURE_BY_EXCHANGE;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_REFUND_INVALID_SIGNATURE_BY_EXCHANGE;
}
else
{
ep = &exchange_pub;
- ec = TALER_EC_NONE;
}
break;
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the exchange is buggy
(or API version conflict); just pass JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_FORBIDDEN:
/* Nothing really to verify, exchange says one of the signatures is
invalid; as we checked them, this should never happen, we
should pass the JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_NOT_FOUND:
/* Nothing really to verify, this should never
happen, we should pass the JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_GONE:
/* Kind of normal: the money was already sent to the merchant
(it was too late for the refund). */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_PRECONDITION_FAILED:
/* Client request was inconsistent; might be a currency mismatch
problem. */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_CONFLICT:
/* Two refund requests were made about the same deposit, but
carrying different refund transaction ids. */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
default:
/* unexpected response code */
- ec = TALER_JSON_get_error_code (j);
+ GNUNET_break_op (0);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d\n",
(unsigned int) response_code,
- ec);
- GNUNET_break (0);
- response_code = 0;
+ hr.ec);
break;
}
rh->cb (rh->cb_cls,
- response_code,
- ec,
- ep,
- j);
+ &hr,
+ ep);
TALER_EXCHANGE_refund_cancel (rh);
}
diff --git a/src/lib/exchange_api_reserves_get.c b/src/lib/exchange_api_reserves_get.c
index e44eefad..0624f0d0 100644
--- a/src/lib/exchange_api_reserves_get.c
+++ b/src/lib/exchange_api_reserves_get.c
@@ -91,6 +91,10 @@ handle_reserves_get_ok (struct TALER_EXCHANGE_ReservesGetHandle *rgh,
TALER_JSON_spec_amount ("balance", &balance),
GNUNET_JSON_spec_end ()
};
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = j,
+ .http_status = MHD_HTTP_OK
+ };
if (GNUNET_OK !=
GNUNET_JSON_parse (j,
@@ -141,9 +145,7 @@ handle_reserves_get_ok (struct TALER_EXCHANGE_ReservesGetHandle *rgh,
if (NULL != rgh->cb)
{
rgh->cb (rgh->cb_cls,
- MHD_HTTP_OK,
- TALER_EC_NONE,
- j,
+ &hr,
&balance,
len,
rhistory);
@@ -171,55 +173,59 @@ handle_reserves_get_finished (void *cls,
{
struct TALER_EXCHANGE_ReservesGetHandle *rgh = cls;
const json_t *j = response;
- enum TALER_ErrorCode ec;
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = j,
+ .http_status = (unsigned int) response_code
+ };
rgh->job = NULL;
switch (response_code)
{
case 0:
- ec = TALER_EC_INVALID_RESPONSE;
+ hr.ec = TALER_EC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
- ec = TALER_EC_NONE;
if (GNUNET_OK !=
handle_reserves_get_ok (rgh,
j))
{
- response_code = 0;
- ec = TALER_EC_RESERVE_STATUS_REPLY_MALFORMED;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_RESERVE_STATUS_REPLY_MALFORMED;
}
break;
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the exchange is buggy
(or API version conflict); just pass JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_NOT_FOUND:
/* Nothing really to verify, this should never
happen, we should pass the JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
default:
/* unexpected response code */
- ec = TALER_JSON_get_error_code (j);
+ GNUNET_break_op (0);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u\n",
- (unsigned int) response_code);
- GNUNET_break (0);
- response_code = 0;
+ "Unexpected response code %u/%d\n",
+ (unsigned int) response_code,
+ (int) hr.ec);
break;
}
if (NULL != rgh->cb)
{
rgh->cb (rgh->cb_cls,
- response_code,
- ec,
- j,
+ &hr,
NULL,
0, NULL);
rgh->cb = NULL;
diff --git a/src/lib/exchange_api_transfers_get.c b/src/lib/exchange_api_transfers_get.c
index d3513fb8..2f1e3289 100644
--- a/src/lib/exchange_api_transfers_get.c
+++ b/src/lib/exchange_api_transfers_get.c
@@ -105,6 +105,10 @@ check_transfers_get_response_ok (
GNUNET_JSON_spec_fixed_auto ("exchange_pub", &exchange_pub),
GNUNET_JSON_spec_end ()
};
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = json,
+ .http_status = MHD_HTTP_OK
+ };
if (GNUNET_OK !=
GNUNET_JSON_parse (json,
@@ -175,10 +179,10 @@ check_transfers_get_response_ok (
GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
- GNUNET_CRYPTO_hash_context_read (hash_context,
- &dd,
- sizeof (struct
- TALER_WireDepositDetailP));
+ GNUNET_CRYPTO_hash_context_read (
+ hash_context,
+ &dd,
+ sizeof (struct TALER_WireDepositDetailP));
}
/* Check signature */
wdp.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE_DEPOSIT);
@@ -200,8 +204,9 @@ check_transfers_get_response_ok (
GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
- if (GNUNET_OK != GNUNET_CRYPTO_eddsa_verify
- (TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE_DEPOSIT,
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_eddsa_verify (
+ TALER_SIGNATURE_EXCHANGE_CONFIRM_WIRE_DEPOSIT,
&wdp.purpose,
&exchange_sig.eddsa_signature,
&exchange_pub.eddsa_pub))
@@ -229,10 +234,8 @@ check_transfers_get_response_ok (
return GNUNET_SYSERR;
}
wdh->cb (wdh->cb_cls,
- MHD_HTTP_OK,
- TALER_EC_NONE,
+ &hr,
&exchange_pub,
- json,
&h_wire,
exec_time,
&total_amount,
@@ -261,13 +264,16 @@ handle_transfers_get_finished (void *cls,
{
struct TALER_EXCHANGE_TransfersGetHandle *wdh = cls;
const json_t *j = response;
- enum TALER_ErrorCode ec;
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = j,
+ .http_status = (unsigned int) response_code
+ };
wdh->job = NULL;
switch (response_code)
{
case 0:
- ec = TALER_EC_INVALID_RESPONSE;
+ hr.ec = TALER_EC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
if (GNUNET_OK ==
@@ -275,45 +281,48 @@ handle_transfers_get_finished (void *cls,
j))
return;
GNUNET_break_op (0);
- ec = TALER_EC_TRANSFERS_GET_REPLY_MALFORMED;
- response_code = 0;
+ hr.ec = TALER_EC_TRANSFERS_GET_REPLY_MALFORMED;
+ hr.http_status = 0;
break;
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the exchange is buggy
(or API version conflict); just pass JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_FORBIDDEN:
/* Nothing really to verify, exchange says one of the signatures is
invalid; as we checked them, this should never happen, we
should pass the JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_NOT_FOUND:
/* Exchange does not know about transaction;
we should pass the reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
default:
/* unexpected response code */
- ec = TALER_JSON_get_error_code (j);
+ GNUNET_break_op (0);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u\n",
- (unsigned int) response_code);
- GNUNET_break (0);
- response_code = 0;
+ "Unexpected response code %u/%d\n",
+ (unsigned int) response_code,
+ (int) hr.ec);
break;
}
wdh->cb (wdh->cb_cls,
- response_code,
- ec,
+ &hr,
NULL,
- j,
NULL,
GNUNET_TIME_UNIT_ZERO_ABS,
NULL,
diff --git a/src/lib/exchange_api_wire.c b/src/lib/exchange_api_wire.c
index 3f3998f5..2602038b 100644
--- a/src/lib/exchange_api_wire.c
+++ b/src/lib/exchange_api_wire.c
@@ -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 General Public License as published by the Free Software
@@ -208,15 +208,18 @@ handle_wire_finished (void *cls,
const void *response)
{
struct TALER_EXCHANGE_WireHandle *wh = cls;
- enum TALER_ErrorCode ec;
const json_t *j = response;
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = j,
+ .http_status = (unsigned int) response_code
+ };
TALER_LOG_DEBUG ("Checking raw /wire response\n");
wh->job = NULL;
switch (response_code)
{
case 0:
- ec = TALER_EC_INVALID_RESPONSE;
+ hr.ec = TALER_EC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
{
@@ -238,8 +241,8 @@ handle_wire_finished (void *cls,
{
/* bogus reply */
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_SERVER_JSON_INVALID;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_SERVER_JSON_INVALID;
break;
}
if (0 == (num_accounts = json_array_size (accounts)))
@@ -247,8 +250,8 @@ handle_wire_finished (void *cls,
/* bogus reply */
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
- response_code = 0;
- ec = TALER_EC_SERVER_JSON_INVALID;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_SERVER_JSON_INVALID;
break;
}
if (NULL == (fm = parse_fees (fees)))
@@ -256,12 +259,11 @@ handle_wire_finished (void *cls,
/* bogus reply */
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
- response_code = 0;
- ec = TALER_EC_SERVER_JSON_INVALID;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_SERVER_JSON_INVALID;
break;
}
- ec = TALER_EC_NONE;
key_state = TALER_EXCHANGE_get_keys (wh->exchange);
/* parse accounts */
{
@@ -286,8 +288,8 @@ handle_wire_finished (void *cls,
{
/* bogus reply */
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_SERVER_SIGNATURE_INVALID;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_SERVER_SIGNATURE_INVALID;
break;
}
if (GNUNET_OK !=
@@ -297,16 +299,16 @@ handle_wire_finished (void *cls,
{
/* bogus reply */
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_SERVER_JSON_INVALID;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_SERVER_JSON_INVALID;
break;
}
if (NULL == (method = TALER_payto_get_method (wa->payto_uri)))
{
/* bogus reply */
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_SERVER_JSON_INVALID;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_SERVER_JSON_INVALID;
break;
}
if (NULL == (wa->fees = lookup_fee (fm,
@@ -314,8 +316,8 @@ handle_wire_finished (void *cls,
{
/* bogus reply */
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_SERVER_JSON_INVALID;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_SERVER_JSON_INVALID;
GNUNET_free (method);
break;
}
@@ -325,11 +327,9 @@ handle_wire_finished (void *cls,
(NULL != wh->cb) )
{
wh->cb (wh->cb_cls,
- response_code,
- ec,
+ &hr,
num_accounts,
- was,
- j);
+ was);
wh->cb = NULL;
}
} /* end of 'parse accounts */
@@ -340,36 +340,37 @@ handle_wire_finished (void *cls,
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the exchange is buggy
(or API version conflict); just pass JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_NOT_FOUND:
/* Nothing really to verify, this should never
happen, we should pass the JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
default:
/* unexpected response code */
- ec = TALER_JSON_get_error_code (j);
+ GNUNET_break_op (0);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d\n",
(unsigned int) response_code,
- (int) ec);
- GNUNET_break (0);
- response_code = 0;
+ (int) hr.ec);
break;
}
if (NULL != wh->cb)
wh->cb (wh->cb_cls,
- response_code,
- ec,
+ &hr,
0,
- NULL,
- j);
+ NULL);
TALER_EXCHANGE_wire_cancel (wh);
}
diff --git a/src/lib/exchange_api_withdraw.c b/src/lib/exchange_api_withdraw.c
index a9fe477e..6f7928c6 100644
--- a/src/lib/exchange_api_withdraw.c
+++ b/src/lib/exchange_api_withdraw.c
@@ -116,6 +116,10 @@ reserve_withdraw_ok (struct TALER_EXCHANGE_WithdrawHandle *wh,
&blind_sig),
GNUNET_JSON_spec_end ()
};
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = json,
+ .http_status = MHD_HTTP_OK
+ };
if (GNUNET_OK !=
GNUNET_JSON_parse (json,
@@ -140,10 +144,8 @@ reserve_withdraw_ok (struct TALER_EXCHANGE_WithdrawHandle *wh,
/* signature is valid, return it to the application */
wh->cb (wh->cb_cls,
- MHD_HTTP_OK,
- TALER_EC_NONE,
- &fc.sig,
- json);
+ &hr,
+ &fc.sig);
/* make sure callback isn't called again after return */
wh->cb = NULL;
GNUNET_CRYPTO_rsa_signature_free (fc.sig.rsa_signature);
@@ -277,13 +279,16 @@ handle_reserve_withdraw_finished (void *cls,
{
struct TALER_EXCHANGE_WithdrawHandle *wh = cls;
const json_t *j = response;
- enum TALER_ErrorCode ec;
+ struct TALER_EXCHANGE_HttpResponse hr = {
+ .reply = j,
+ .http_status = (unsigned int) response_code
+ };
wh->job = NULL;
switch (response_code)
{
case 0:
- ec = TALER_EC_INVALID_RESPONSE;
+ hr.ec = TALER_EC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
if (GNUNET_OK !=
@@ -291,8 +296,8 @@ handle_reserve_withdraw_finished (void *cls,
j))
{
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_WITHDRAW_REPLY_MALFORMED;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_WITHDRAW_REPLY_MALFORMED;
break;
}
GNUNET_assert (NULL == wh->cb);
@@ -301,7 +306,8 @@ handle_reserve_withdraw_finished (void *cls,
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the exchange is buggy
(or API version conflict); just pass JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_CONFLICT:
/* The exchange says that the reserve has insufficient funds;
@@ -311,51 +317,53 @@ handle_reserve_withdraw_finished (void *cls,
j))
{
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_WITHDRAW_REPLY_MALFORMED;
+ hr.http_status = 0;
+ hr.ec = TALER_EC_WITHDRAW_REPLY_MALFORMED;
}
else
{
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
}
break;
case MHD_HTTP_FORBIDDEN:
- GNUNET_break (0);
+ GNUNET_break_op (0);
/* Nothing really to verify, exchange says one of the signatures is
invalid; as we checked them, this should never happen, we
should pass the JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_NOT_FOUND:
/* Nothing really to verify, the exchange basically just says
that it doesn't know this reserve. Can happen if we
query before the wire transfer went through.
We should simply pass the JSON reply to the application. */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- ec = TALER_JSON_get_error_code (j);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
break;
default:
/* unexpected response code */
- ec = TALER_JSON_get_error_code (j);
+ GNUNET_break_op (0);
+ hr.ec = TALER_JSON_get_error_code (j);
+ hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d\n",
(unsigned int) response_code,
- (int) ec);
- GNUNET_break (0);
- response_code = 0;
+ (int) hr.ec);
break;
}
if (NULL != wh->cb)
{
wh->cb (wh->cb_cls,
- response_code,
- ec,
- NULL,
- j);
+ &hr,
+ NULL);
wh->cb = NULL;
}
TALER_EXCHANGE_withdraw_cancel (wh);