summaryrefslogtreecommitdiff
path: root/src/lib/exchange_api_wire.c
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/exchange_api_wire.c
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/exchange_api_wire.c')
-rw-r--r--src/lib/exchange_api_wire.c67
1 files changed, 34 insertions, 33 deletions
diff --git a/src/lib/exchange_api_wire.c b/src/lib/exchange_api_wire.c
index 3f3998f5b..2602038b7 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);
}