From bf8c5982a2e79f0b5198a0033dd41e9702d093f9 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 5 Apr 2020 22:05:38 +0200 Subject: make exchange API more uniform in how information is returned --- src/lib/exchange_api_withdraw.c | 56 +++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 24 deletions(-) (limited to 'src/lib/exchange_api_withdraw.c') diff --git a/src/lib/exchange_api_withdraw.c b/src/lib/exchange_api_withdraw.c index a9fe477eb..6f7928c65 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); -- cgit v1.2.3