diff options
author | Christian Grothoff <christian@grothoff.org> | 2023-06-21 07:53:17 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2023-06-21 07:53:17 +0200 |
commit | 17789253e9194c66bb9ddb081425a35212ac7bf3 (patch) | |
tree | d8acb45cf9a87aecb421707017e7b5be47df1c1a /src/lib | |
parent | d6838ed841185c7850c3f52d91d1baa9a1f90a7e (diff) | |
download | exchange-17789253e9194c66bb9ddb081425a35212ac7bf3.tar.xz |
ensure forward-compatibility for auditor C API
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/auditor_api_deposit_confirmation.c | 40 | ||||
-rw-r--r-- | src/lib/auditor_api_exchanges.c | 50 | ||||
-rw-r--r-- | src/lib/auditor_api_handle.c | 49 | ||||
-rw-r--r-- | src/lib/exchange_api_handle.c | 25 | ||||
-rw-r--r-- | src/lib/exchange_api_handle.h | 7 |
5 files changed, 78 insertions, 93 deletions
diff --git a/src/lib/auditor_api_deposit_confirmation.c b/src/lib/auditor_api_deposit_confirmation.c index 55a05d962..93cdaed93 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-2021 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 General Public License as published by the Free Software @@ -87,64 +87,64 @@ handle_deposit_confirmation_finished (void *cls, { const json_t *json = djson; struct TALER_AUDITOR_DepositConfirmationHandle *dh = cls; - struct TALER_AUDITOR_HttpResponse hr = { - .reply = json, - .http_status = (unsigned int) response_code + struct TALER_AUDITOR_DepositConfirmationResponse dcr = { + .hr.reply = json, + .hr.http_status = (unsigned int) response_code }; dh->job = NULL; switch (response_code) { case 0: - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + dcr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; case MHD_HTTP_OK: - hr.ec = TALER_EC_NONE; + dcr.hr.ec = TALER_EC_NONE; break; case MHD_HTTP_BAD_REQUEST: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + dcr.hr.ec = TALER_JSON_get_error_code (json); + dcr.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: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + dcr.hr.ec = TALER_JSON_get_error_code (json); + dcr.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: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + dcr.hr.ec = TALER_JSON_get_error_code (json); + dcr.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_GONE: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + dcr.hr.ec = TALER_JSON_get_error_code (json); + dcr.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_INTERNAL_SERVER_ERROR: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + dcr.hr.ec = TALER_JSON_get_error_code (json); + dcr.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 */ - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + dcr.hr.ec = TALER_JSON_get_error_code (json); + dcr.hr.hint = TALER_JSON_get_error_hint (json); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d for auditor deposit confirmation\n", (unsigned int) response_code, - hr.ec); + dcr.hr.ec); break; } dh->cb (dh->cb_cls, - &hr); + &dcr); TALER_AUDITOR_deposit_confirmation_cancel (dh); } diff --git a/src/lib/auditor_api_exchanges.c b/src/lib/auditor_api_exchanges.c index 7327f11b2..9f35c7077 100644 --- a/src/lib/auditor_api_exchanges.c +++ b/src/lib/auditor_api_exchanges.c @@ -89,16 +89,16 @@ handle_exchanges_finished (void *cls, const json_t *ja; unsigned int ja_len; struct TALER_AUDITOR_ListExchangesHandle *leh = cls; - struct TALER_AUDITOR_HttpResponse hr = { - .reply = json, - .http_status = (unsigned int) response_code + struct TALER_AUDITOR_ListExchangesResponse ler = { + .hr.reply = json, + .hr.http_status = (unsigned int) response_code }; leh->job = NULL; switch (response_code) { case 0: - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + ler.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; case MHD_HTTP_OK: ja = json_object_get (json, @@ -107,8 +107,8 @@ handle_exchanges_finished (void *cls, (! json_is_array (ja)) ) { GNUNET_break (0); - hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; - hr.http_status = 0; + ler.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; + ler.hr.http_status = 0; break; } @@ -116,12 +116,12 @@ handle_exchanges_finished (void *cls, if (ja_len > MAX_EXCHANGES) { GNUNET_break (0); - hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; - hr.http_status = 0; + ler.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; + ler.hr.http_status = 0; break; } { - struct TALER_AUDITOR_ExchangeInfo ei[ja_len]; + struct TALER_AUDITOR_ExchangeInfo ei[GNUNET_NZL (ja_len)]; bool ok; ok = true; @@ -141,54 +141,52 @@ handle_exchanges_finished (void *cls, { GNUNET_break_op (0); ok = false; - hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; - hr.http_status = 0; + ler.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; + ler.hr.http_status = 0; break; } } if (! ok) break; + ler.details.ok.ei = ei; + ler.details.ok.num_exchanges = ja_len; leh->cb (leh->cb_cls, - &hr, - ja_len, - ei); + &ler); 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 */ - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + ler.hr.ec = TALER_JSON_get_error_code (json); + ler.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 */ - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + ler.hr.ec = TALER_JSON_get_error_code (json); + ler.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); + ler.hr.ec = TALER_JSON_get_error_code (json); + ler.hr.hint = TALER_JSON_get_error_hint (json); break; default: /* unexpected response code */ - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + ler.hr.ec = TALER_JSON_get_error_code (json); + ler.hr.hint = TALER_JSON_get_error_hint (json); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d for auditor list-exchanges request\n", (unsigned int) response_code, - (int) hr.ec); + (int) ler.hr.ec); GNUNET_break_op (0); break; } if (NULL != leh->cb) leh->cb (leh->cb_cls, - &hr, - 0, - NULL); + &ler); TALER_AUDITOR_list_exchanges_cancel (leh); } diff --git a/src/lib/auditor_api_handle.c b/src/lib/auditor_api_handle.c index 14869de43..318b63f94 100644 --- a/src/lib/auditor_api_handle.c +++ b/src/lib/auditor_api_handle.c @@ -239,10 +239,9 @@ version_completed_cb (void *cls, { struct TALER_AUDITOR_Handle *auditor = cls; const json_t *resp_obj = gresp_obj; - enum TALER_AUDITOR_VersionCompatibility vc; - struct TALER_AUDITOR_HttpResponse hr = { - .reply = resp_obj, - .http_status = (unsigned int) response_code + struct TALER_AUDITOR_VersionResponse vr = { + .hr.reply = resp_obj, + .hr.http_status = (unsigned int) response_code }; auditor->vr = NULL; @@ -250,7 +249,6 @@ version_completed_cb (void *cls, "Received version from URL `%s' with status %ld.\n", auditor->url, response_code); - vc = TALER_AUDITOR_VC_PROTOCOL_ERROR; switch (response_code) { case 0: @@ -268,28 +266,33 @@ version_completed_cb (void *cls, { GNUNET_break_op (0); TALER_LOG_WARNING ("NULL body for a 200-OK /config\n"); - hr.http_status = 0; - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + vr.hr.http_status = 0; + vr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; } - hr.ec = decode_version_json (resp_obj, - auditor, - &vc); - if (TALER_EC_NONE != hr.ec) + vr.hr.ec = decode_version_json (resp_obj, + auditor, + &vr.details.ok.compat); + if (TALER_EC_NONE != vr.hr.ec) { GNUNET_break_op (0); - hr.http_status = 0; + vr.hr.http_status = 0; break; } + auditor->state = MHS_VERSION; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Auditor %s is ready!\n", + auditor->url); + vr.details.ok.vi = auditor->vi; 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); + vr.hr.ec = TALER_JSON_get_error_code (resp_obj); + vr.hr.hint = TALER_JSON_get_error_hint (resp_obj); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d\n", (unsigned int) response_code, - (int) hr.ec); + (int) vr.hr.ec); break; } if (MHD_HTTP_OK != response_code) @@ -299,23 +302,9 @@ version_completed_cb (void *cls, auditor->url, (unsigned int) response_code); auditor->state = MHS_FAILED; - /* notify application that we failed */ - auditor->version_cb (auditor->version_cb_cls, - &hr, - NULL, - vc); - return; } - TALER_LOG_DEBUG ("Switching auditor state to 'version'\n"); - auditor->state = MHS_VERSION; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Auditor %s is ready!\n", - auditor->url); - /* notify application about the key information */ auditor->version_cb (auditor->version_cb_cls, - &hr, - &auditor->vi, - vc); + &vr); } diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c index 20bac43a0..7b815f28b 100644 --- a/src/lib/exchange_api_handle.c +++ b/src/lib/exchange_api_handle.c @@ -168,19 +168,20 @@ struct KeysRequest void -TEAH_acc_confirmation_cb (void *cls, - const struct TALER_AUDITOR_HttpResponse *hr) +TEAH_acc_confirmation_cb ( + void *cls, + const struct TALER_AUDITOR_DepositConfirmationResponse *dcr) { struct TEAH_AuditorInteractionEntry *aie = cls; struct TEAH_AuditorListEntry *ale = aie->ale; - if (MHD_HTTP_OK != hr->http_status) + if (MHD_HTTP_OK != dcr->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, - hr->http_status, - hr->ec); + dcr->hr.http_status, + dcr->hr.ec); } GNUNET_CONTAINER_DLL_remove (ale->ai_head, ale->ai_tail, @@ -579,21 +580,17 @@ parse_global_fee (struct TALER_EXCHANGE_GlobalFee *gf, * 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 + * @param vr response from the auditor */ static void auditor_version_cb ( void *cls, - const struct TALER_AUDITOR_HttpResponse *hr, - const struct TALER_AUDITOR_VersionInformation *vi, - enum TALER_AUDITOR_VersionCompatibility compat) + const struct TALER_AUDITOR_VersionResponse *vr) { struct TEAH_AuditorListEntry *ale = cls; + enum TALER_AUDITOR_VersionCompatibility compat; - (void) hr; - if (NULL == vi) + if (MHD_HTTP_OK != vr->hr.http_status) { /* In this case, we don't mark the auditor as 'up' */ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -601,7 +598,7 @@ auditor_version_cb ( ale->auditor_url); return; } - + compat = vr->details.ok.compat; if (0 != (TALER_AUDITOR_VC_INCOMPATIBLE & compat)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, diff --git a/src/lib/exchange_api_handle.h b/src/lib/exchange_api_handle.h index 3b1d875fb..47be99d4e 100644 --- a/src/lib/exchange_api_handle.h +++ b/src/lib/exchange_api_handle.h @@ -193,11 +193,12 @@ typedef struct TEAH_AuditorInteractionEntry * * auditor's /deposit-confirmation handler. * * @param cls closure of type `struct TEAH_AuditorInteractionEntry *` - * @param hr HTTP response + * @param dcr response */ void -TEAH_acc_confirmation_cb (void *cls, - const struct TALER_AUDITOR_HttpResponse *hr); +TEAH_acc_confirmation_cb ( + void *cls, + const struct TALER_AUDITOR_DepositConfirmationResponse *dcr); /** |