summaryrefslogtreecommitdiff
path: root/src/lib/merchant_api_get_transfers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/merchant_api_get_transfers.c')
-rw-r--r--src/lib/merchant_api_get_transfers.c72
1 files changed, 30 insertions, 42 deletions
diff --git a/src/lib/merchant_api_get_transfers.c b/src/lib/merchant_api_get_transfers.c
index f2f1186d..6116a54f 100644
--- a/src/lib/merchant_api_get_transfers.c
+++ b/src/lib/merchant_api_get_transfers.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2017, 2020 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free Software
@@ -81,23 +81,23 @@ handle_transfers_get_finished (void *cls,
{
struct TALER_MERCHANT_GetTransfersHandle *gth = cls;
const json_t *json = response;
- struct TALER_MERCHANT_HttpResponse hr = {
- .http_status = (unsigned int) response_code,
- .reply = json
+ struct TALER_MERCHANT_GetTransfersResponse gtr = {
+ .hr.http_status = (unsigned int) response_code,
+ .hr.reply = json
};
gth->job = NULL;
switch (response_code)
{
case 0:
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ gtr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
{
- json_t *transfers;
+ const json_t *transfers;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("transfers",
- &transfers),
+ GNUNET_JSON_spec_array_const ("transfers",
+ &transfers),
GNUNET_JSON_spec_end ()
};
@@ -107,26 +107,18 @@ handle_transfers_get_finished (void *cls,
NULL, NULL))
{
GNUNET_break_op (0);
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ gtr.hr.http_status = 0;
+ gtr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
}
- else
+
{
size_t tds_length;
struct TALER_MERCHANT_TransferData *tds;
json_t *transfer;
- unsigned int i;
+ size_t i;
bool ok;
- if (! json_is_array (transfers))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- }
tds_length = json_array_size (transfers);
tds = GNUNET_new_array (tds_length,
struct TALER_MERCHANT_TransferData);
@@ -138,9 +130,9 @@ handle_transfers_get_finished (void *cls,
&td->credit_amount),
GNUNET_JSON_spec_fixed_auto ("wtid",
&td->wtid),
- GNUNET_JSON_spec_string ("payto_uri",
- &td->payto_uri),
- GNUNET_JSON_spec_string ("exchange_url",
+ TALER_JSON_spec_payto_uri ("payto_uri",
+ &td->payto_uri),
+ TALER_JSON_spec_web_url ("exchange_url",
&td->exchange_url),
GNUNET_JSON_spec_uint64 ("transfer_serial_id",
&td->credit_serial),
@@ -174,55 +166,51 @@ handle_transfers_get_finished (void *cls,
{
GNUNET_break_op (0);
GNUNET_free (tds);
- GNUNET_JSON_parse_free (spec);
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ gtr.hr.http_status = 0;
+ gtr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
}
+ gtr.details.ok.transfers = tds;
+ gtr.details.ok.transfers_length = tds_length;
gth->cb (gth->cb_cls,
- &hr,
- tds_length,
- tds);
+ &gtr);
GNUNET_free (tds);
- GNUNET_JSON_parse_free (spec);
TALER_MERCHANT_transfers_get_cancel (gth);
return;
}
}
case MHD_HTTP_UNAUTHORIZED:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ gtr.hr.ec = TALER_JSON_get_error_code (json);
+ gtr.hr.hint = TALER_JSON_get_error_hint (json);
/* Nothing really to verify, merchant says we need to authenticate. */
break;
case MHD_HTTP_NOT_FOUND:
/* Nothing really to verify, this should never
happen, we should pass the JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ gtr.hr.ec = TALER_JSON_get_error_code (json);
+ gtr.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 */
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ gtr.hr.ec = TALER_JSON_get_error_code (json);
+ gtr.hr.hint = TALER_JSON_get_error_hint (json);
break;
default:
/* unexpected response code */
GNUNET_break_op (0);
TALER_MERCHANT_parse_error_details_ (json,
response_code,
- &hr);
+ &gtr.hr);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d\n",
(unsigned int) response_code,
- (int) hr.ec);
- response_code = 0;
+ (int) gtr.hr.ec);
+ gtr.hr.http_status = 0;
break;
}
gth->cb (gth->cb_cls,
- &hr,
- 0,
- NULL);
+ &gtr);
TALER_MERCHANT_transfers_get_cancel (gth);
}