From 809300158caaa0215c36ef89c7e38f0edfa93593 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 4 Jun 2023 13:26:00 +0200 Subject: code cleanup, fixing misc. memory leaks in the process --- src/include/taler_exchange_service.h | 4 ++-- src/include/taler_exchangedb_plugin.h | 8 ++++---- src/include/taler_extensions.h | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/include') diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h index 6d4ca109..5fcfa403 100644 --- a/src/include/taler_exchange_service.h +++ b/src/include/taler_exchange_service.h @@ -3592,7 +3592,7 @@ enum GNUNET_GenericReturnValue TALER_EXCHANGE_verify_coin_history ( const struct TALER_EXCHANGE_DenomPublicKey *dk, const struct TALER_CoinSpendPublicKeyP *coin_pub, - json_t *history, + const json_t *history, struct TALER_Amount *total); @@ -4498,7 +4498,7 @@ TALER_EXCHANGE_post_management_keys_cancel ( */ struct TALER_EXCHANGE_ManagementPostExtensionsData { - json_t *extensions; + const json_t *extensions; struct TALER_MasterSignatureP extensions_sig; }; diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index 92fb36fb..5404f0b1 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -5577,8 +5577,8 @@ struct TALER_EXCHANGEDB_Plugin (*insert_wire)(void *cls, const char *payto_uri, const char *conversion_url, - json_t *debit_restrictions, - json_t *credit_restrictions, + const json_t *debit_restrictions, + const json_t *credit_restrictions, struct GNUNET_TIME_Timestamp start_date, const struct TALER_MasterSignatureP *master_sig); @@ -5600,8 +5600,8 @@ struct TALER_EXCHANGEDB_Plugin (*update_wire)(void *cls, const char *payto_uri, const char *conversion_url, - json_t *debit_restrictions, - json_t *credit_restrictions, + const json_t *debit_restrictions, + const json_t *credit_restrictions, struct GNUNET_TIME_Timestamp change_date, bool enabled); diff --git a/src/include/taler_extensions.h b/src/include/taler_extensions.h index 75f22534..cd9d7ddd 100644 --- a/src/include/taler_extensions.h +++ b/src/include/taler_extensions.h @@ -259,13 +259,13 @@ TALER_extensions_parse_manifest ( */ enum GNUNET_GenericReturnValue TALER_extensions_load_manifests ( - json_t *manifests); + const json_t *manifests); /* * @brief Returns the head of the linked list of extensions. */ const struct TALER_Extensions * -TALER_extensions_get_head (); +TALER_extensions_get_head (void); /** * @brief Finds and returns a supported extension by a given type. @@ -323,7 +323,7 @@ TALER_extensions_is_enabled ( */ enum GNUNET_GenericReturnValue TALER_extensions_verify_manifests_signature ( - json_t *manifests, + const json_t *manifests, struct TALER_MasterSignatureP *extensions_sig, struct TALER_MasterPublicKeyP *master_pub); @@ -363,7 +363,7 @@ struct TALER_AgeRestrictionConfig * @return age restriction configuration if present, otherwise NULL. */ const struct TALER_AgeRestrictionConfig * -TALER_extensions_get_age_restriction_config (); +TALER_extensions_get_age_restriction_config (void); /** * @brief Check if age restriction is enabled @@ -371,7 +371,7 @@ TALER_extensions_get_age_restriction_config (); * @return true, if age restriction is loaded, configured and enabled; otherwise false. */ bool -TALER_extensions_is_age_restriction_enabled (); +TALER_extensions_is_age_restriction_enabled (void); /** * @brief Return the age mask for age restriction @@ -379,6 +379,6 @@ TALER_extensions_is_age_restriction_enabled (); * @return configured age mask, if age restriction is loaded, configured and enabled; otherwise zero mask. */ struct TALER_AgeMask -TALER_extensions_get_age_restriction_mask (); +TALER_extensions_get_age_restriction_mask (void); #endif -- cgit v1.2.3 From 0ad3de938e37cd4f34dd791283350ccfc09df2db Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 4 Jun 2023 14:10:54 +0200 Subject: address API stability FIXMEs in taler_exchange_service --- src/exchange-tools/taler-auditor-offline.c | 5 +- src/exchange-tools/taler-exchange-offline.c | 29 +++-- src/include/taler_exchange_service.h | 119 +++++++++++++++++---- src/lib/exchange_api_add_aml_decision.c | 26 ++--- src/lib/exchange_api_auditor_add_denomination.c | 34 +++--- src/lib/exchange_api_management_add_partner.c | 26 ++--- src/lib/exchange_api_management_auditor_disable.c | 26 ++--- src/lib/exchange_api_management_auditor_enable.c | 22 ++-- src/lib/exchange_api_management_post_extensions.c | 4 +- src/lib/exchange_api_management_set_global_fee.c | 26 ++--- src/lib/exchange_api_management_set_wire_fee.c | 26 ++--- src/testing/testing_api_cmd_auditor_add.c | 8 +- .../testing_api_cmd_auditor_add_denom_sig.c | 8 +- src/testing/testing_api_cmd_auditor_del.c | 9 +- src/testing/testing_api_cmd_set_wire_fee.c | 5 +- src/testing/testing_api_cmd_take_aml_decision.c | 10 +- 16 files changed, 237 insertions(+), 146 deletions(-) (limited to 'src/include') diff --git a/src/exchange-tools/taler-auditor-offline.c b/src/exchange-tools/taler-auditor-offline.c index cd439d23..39495311 100644 --- a/src/exchange-tools/taler-auditor-offline.c +++ b/src/exchange-tools/taler-auditor-offline.c @@ -388,14 +388,15 @@ load_offline_key (int do_create) * add operation result. * * @param cls closure with a `struct DenominationAddRequest` - * @param hr HTTP response data + * @param adr response data */ static void denomination_add_cb ( void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr) + const struct TALER_EXCHANGE_AuditorAddDenominationResponse *adr) { struct DenominationAddRequest *dar = cls; + const struct TALER_EXCHANGE_HttpResponse *hr = &adr->hr; if (MHD_HTTP_NO_CONTENT != hr->http_status) { diff --git a/src/exchange-tools/taler-exchange-offline.c b/src/exchange-tools/taler-exchange-offline.c index 77c163c3..fed29437 100644 --- a/src/exchange-tools/taler-exchange-offline.c +++ b/src/exchange-tools/taler-exchange-offline.c @@ -1301,13 +1301,15 @@ upload_signkey_revocation (const char *exchange_url, * Function called with information about the post auditor add operation result. * * @param cls closure with a `struct AuditorAddRequest` - * @param hr HTTP response data + * @param mer response data */ static void -auditor_add_cb (void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr) +auditor_add_cb ( + void *cls, + const struct TALER_EXCHANGE_ManagementAuditorEnableResponse *mer) { struct AuditorAddRequest *aar = cls; + const struct TALER_EXCHANGE_HttpResponse *hr = &mer->hr; if (MHD_HTTP_NO_CONTENT != hr->http_status) { @@ -1401,13 +1403,15 @@ upload_auditor_add (const char *exchange_url, * Function called with information about the post auditor del operation result. * * @param cls closure with a `struct AuditorDelRequest` - * @param hr HTTP response data + * @param mdr response data */ static void auditor_del_cb (void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr) + const struct + TALER_EXCHANGE_ManagementAuditorDisableResponse *mdr) { struct AuditorDelRequest *adr = cls; + const struct TALER_EXCHANGE_HttpResponse *hr = &mdr->hr; if (MHD_HTTP_NO_CONTENT != hr->http_status) { @@ -1726,14 +1730,15 @@ upload_wire_del (const char *exchange_url, * Function called with information about the post wire fee operation result. * * @param cls closure with a `struct WireFeeRequest` - * @param hr HTTP response data + * @param swr response data */ static void wire_fee_cb ( void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr) + const struct TALER_EXCHANGE_ManagementSetWireFeeResponse *swr) { struct WireFeeRequest *wfr = cls; + const struct TALER_EXCHANGE_HttpResponse *hr = &swr->hr; if (MHD_HTTP_NO_CONTENT != hr->http_status) { @@ -1831,14 +1836,15 @@ upload_wire_fee (const char *exchange_url, * Function called with information about the post global fee operation result. * * @param cls closure with a `struct WireFeeRequest` - * @param hr HTTP response data + * @param gr response data */ static void global_fee_cb ( void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr) + const struct TALER_EXCHANGE_ManagementSetGlobalFeeResponse *gr) { struct GlobalFeeRequest *gfr = cls; + const struct TALER_EXCHANGE_HttpResponse *hr = &gr->hr; if (MHD_HTTP_NO_CONTENT != hr->http_status) { @@ -2358,14 +2364,15 @@ upload_extensions (const char *exchange_url, * Function called with information about the add partner operation. * * @param cls closure with a `struct PartnerAddRequest` - * @param hr HTTP response data + * @param apr response data */ static void add_partner_cb ( void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr) + const struct TALER_EXCHANGE_ManagementAddPartnerResponse *apr) { struct PartnerAddRequest *par = cls; + const struct TALER_EXCHANGE_HttpResponse *hr = &apr->hr; if (MHD_HTTP_NO_CONTENT != hr->http_status) { diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h index 5fcfa403..c6c1d3a1 100644 --- a/src/include/taler_exchange_service.h +++ b/src/include/taler_exchange_service.h @@ -4548,7 +4548,7 @@ struct TALER_EXCHANGE_ManagementPostExtensionsHandle * TALER_EXCHANGE_management_post_extensions ( struct GNUNET_CURL_Context *ctx, const char *url, - struct TALER_EXCHANGE_ManagementPostExtensionsData *ped, + const struct TALER_EXCHANGE_ManagementPostExtensionsData *ped, TALER_EXCHANGE_ManagementPostExtensionsCallback cb, void *cb_cls); @@ -5091,7 +5091,7 @@ TALER_EXCHANGE_lookup_aml_decision ( /** - * Cancel #TALER_EXCHANGE_add_aml_decision() operation. + * Cancel #TALER_EXCHANGE_lookup_aml_decision() operation. * * @param rh handle of the operation to cancel */ @@ -5105,18 +5105,30 @@ TALER_EXCHANGE_lookup_aml_decision_cancel ( */ struct TALER_EXCHANGE_AddAmlDecision; + +/** + * Response when making an AML decision. + */ +struct TALER_EXCHANGE_AddAmlDecisionResponse +{ + /** + * HTTP response data. + */ + struct TALER_EXCHANGE_HttpResponse hr; +}; + + /** * Function called with information about storing an * an AML decision. * * @param cls closure - * @param hr HTTP response data + * @param adr response data */ -// FIXME: bad API typedef void (*TALER_EXCHANGE_AddAmlDecisionCallback) ( void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr); + const struct TALER_EXCHANGE_AddAmlDecisionResponse *adr); /** * Inform the exchange that an AML decision has been taken. @@ -5161,18 +5173,28 @@ TALER_EXCHANGE_add_aml_decision_cancel ( struct TALER_EXCHANGE_AddAmlDecision *rh); +/** + * Response when adding a partner exchange. + */ +struct TALER_EXCHANGE_ManagementAddPartnerResponse +{ + /** + * HTTP response data. + */ + struct TALER_EXCHANGE_HttpResponse hr; +}; + /** * Function called with information about the change to * an AML officer status. * * @param cls closure - * @param hr HTTP response data + * @param apr response data */ -// FIXME: bad API typedef void (*TALER_EXCHANGE_ManagementAddPartnerCallback) ( void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr); + const struct TALER_EXCHANGE_ManagementAddPartnerResponse *apr); /** @@ -5223,17 +5245,27 @@ TALER_EXCHANGE_management_add_partner_cancel ( struct TALER_EXCHANGE_ManagementAddPartner *rh); +/** + * Response when enabling an auditor. + */ +struct TALER_EXCHANGE_ManagementAuditorEnableResponse +{ + /** + * HTTP response data. + */ + struct TALER_EXCHANGE_HttpResponse hr; +}; + /** * Function called with information about the auditor setup operation result. * * @param cls closure - * @param hr HTTP response data + * @param aer response data */ -// FIXME: bad API typedef void (*TALER_EXCHANGE_ManagementAuditorEnableCallback) ( void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr); + const struct TALER_EXCHANGE_ManagementAuditorEnableResponse *aer); /** @@ -5278,18 +5310,27 @@ void TALER_EXCHANGE_management_enable_auditor_cancel ( struct TALER_EXCHANGE_ManagementAuditorEnableHandle *ah); +/** + * Response when disabling an auditor. + */ +struct TALER_EXCHANGE_ManagementAuditorDisableResponse +{ + /** + * HTTP response data. + */ + struct TALER_EXCHANGE_HttpResponse hr; +}; /** * Function called with information about the auditor disable operation result. * * @param cls closure - * @param hr HTTP response data + * @param adr HTTP response data */ -// FIXME: bad API typedef void (*TALER_EXCHANGE_ManagementAuditorDisableCallback) ( void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr); + const struct TALER_EXCHANGE_ManagementAuditorDisableResponse *adr); /** @@ -5467,17 +5508,27 @@ TALER_EXCHANGE_management_disable_wire_cancel ( struct TALER_EXCHANGE_ManagementWireDisableHandle *wh); +/** + * Response when setting wire fees. + */ +struct TALER_EXCHANGE_ManagementSetWireFeeResponse +{ + /** + * HTTP response data. + */ + struct TALER_EXCHANGE_HttpResponse hr; +}; + /** * Function called with information about the wire enable operation result. * * @param cls closure - * @param hr HTTP response data + * @param wfr response data */ -// FIXME: bad API typedef void (*TALER_EXCHANGE_ManagementSetWireFeeCallback) ( void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr); + const struct TALER_EXCHANGE_ManagementSetWireFeeResponse *wfr); /** @@ -5524,17 +5575,28 @@ TALER_EXCHANGE_management_set_wire_fees_cancel ( struct TALER_EXCHANGE_ManagementSetWireFeeHandle *swfh); +/** + * Response when setting global fees. + */ +struct TALER_EXCHANGE_ManagementSetGlobalFeeResponse +{ + /** + * HTTP response data. + */ + struct TALER_EXCHANGE_HttpResponse hr; +}; + + /** * Function called with information about the global fee setting operation result. * * @param cls closure - * @param hr HTTP response data + * @param gfr HTTP response data */ -// FIXME: bad API typedef void (*TALER_EXCHANGE_ManagementSetGlobalFeeCallback) ( void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr); + const struct TALER_EXCHANGE_ManagementSetGlobalFeeResponse *gfr); /** @@ -5585,18 +5647,29 @@ TALER_EXCHANGE_management_set_global_fees_cancel ( struct TALER_EXCHANGE_ManagementSetGlobalFeeHandle *sgfh); +/** + * Response when adding denomination signature by auditor. + */ +struct TALER_EXCHANGE_AuditorAddDenominationResponse +{ + /** + * HTTP response data. + */ + struct TALER_EXCHANGE_HttpResponse hr; +}; + + /** * Function called with information about the POST * /auditor/$AUDITOR_PUB/$H_DENOM_PUB operation result. * * @param cls closure - * @param hr HTTP response data + * @param adr HTTP response data */ -// FIXME: bad API typedef void (*TALER_EXCHANGE_AuditorAddDenominationCallback) ( void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr); + const struct TALER_EXCHANGE_AuditorAddDenominationResponse *adr); /** diff --git a/src/lib/exchange_api_add_aml_decision.c b/src/lib/exchange_api_add_aml_decision.c index 7245db3b..342e1e3d 100644 --- a/src/lib/exchange_api_add_aml_decision.c +++ b/src/lib/exchange_api_add_aml_decision.c @@ -79,9 +79,9 @@ handle_add_aml_decision_finished (void *cls, { struct TALER_EXCHANGE_AddAmlDecision *wh = cls; const json_t *json = response; - struct TALER_EXCHANGE_HttpResponse hr = { - .http_status = (unsigned int) response_code, - .reply = json + struct TALER_EXCHANGE_AddAmlDecisionResponse adr = { + .hr.http_status = (unsigned int) response_code, + .hr.reply = json }; wh->job = NULL; @@ -89,34 +89,34 @@ handle_add_aml_decision_finished (void *cls, { case 0: /* no reply */ - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; - hr.hint = "server offline?"; + adr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + adr.hr.hint = "server offline?"; break; case MHD_HTTP_NO_CONTENT: break; case MHD_HTTP_FORBIDDEN: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + adr.hr.ec = TALER_JSON_get_error_code (json); + adr.hr.hint = TALER_JSON_get_error_hint (json); break; case MHD_HTTP_CONFLICT: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + adr.hr.ec = TALER_JSON_get_error_code (json); + adr.hr.hint = TALER_JSON_get_error_hint (json); break; default: /* unexpected response code */ GNUNET_break_op (0); - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + adr.hr.ec = TALER_JSON_get_error_code (json); + adr.hr.hint = TALER_JSON_get_error_hint (json); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d for exchange AML decision\n", (unsigned int) response_code, - (int) hr.ec); + (int) adr.hr.ec); break; } if (NULL != wh->cb) { wh->cb (wh->cb_cls, - &hr); + &adr); wh->cb = NULL; } TALER_EXCHANGE_add_aml_decision_cancel (wh); diff --git a/src/lib/exchange_api_auditor_add_denomination.c b/src/lib/exchange_api_auditor_add_denomination.c index 71f421d4..89de0d7f 100644 --- a/src/lib/exchange_api_auditor_add_denomination.c +++ b/src/lib/exchange_api_auditor_add_denomination.c @@ -79,9 +79,9 @@ handle_auditor_add_denomination_finished (void *cls, { struct TALER_EXCHANGE_AuditorAddDenominationHandle *ah = cls; const json_t *json = response; - struct TALER_EXCHANGE_HttpResponse hr = { - .http_status = (unsigned int) response_code, - .reply = json + struct TALER_EXCHANGE_AuditorAddDenominationResponse adr = { + .hr.http_status = (unsigned int) response_code, + .hr.reply = json }; ah->job = NULL; @@ -90,37 +90,37 @@ handle_auditor_add_denomination_finished (void *cls, case MHD_HTTP_NO_CONTENT: break; case MHD_HTTP_FORBIDDEN: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + adr.hr.ec = TALER_JSON_get_error_code (json); + adr.hr.hint = TALER_JSON_get_error_hint (json); break; case MHD_HTTP_NOT_FOUND: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + adr.hr.ec = TALER_JSON_get_error_code (json); + adr.hr.hint = TALER_JSON_get_error_hint (json); break; case MHD_HTTP_GONE: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + adr.hr.ec = TALER_JSON_get_error_code (json); + adr.hr.hint = TALER_JSON_get_error_hint (json); break; case MHD_HTTP_PRECONDITION_FAILED: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + adr.hr.ec = TALER_JSON_get_error_code (json); + adr.hr.hint = TALER_JSON_get_error_hint (json); break; default: /* unexpected response code */ if (NULL != json) { - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + adr.hr.ec = TALER_JSON_get_error_code (json); + adr.hr.hint = TALER_JSON_get_error_hint (json); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d for exchange auditor-add-denomination at URL `%s'\n", (unsigned int) response_code, - (int) hr.ec, + (int) adr.hr.ec, ah->url); } else { - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; - hr.hint = NULL; + adr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + adr.hr.hint = NULL; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected HTTP response code %u (no JSON returned) at URL `%s'\n", (unsigned int) response_code, @@ -131,7 +131,7 @@ handle_auditor_add_denomination_finished (void *cls, if (NULL != ah->cb) { ah->cb (ah->cb_cls, - &hr); + &adr); ah->cb = NULL; } TALER_EXCHANGE_add_auditor_denomination_cancel (ah); diff --git a/src/lib/exchange_api_management_add_partner.c b/src/lib/exchange_api_management_add_partner.c index 75fb8aa6..fec66c56 100644 --- a/src/lib/exchange_api_management_add_partner.c +++ b/src/lib/exchange_api_management_add_partner.c @@ -79,9 +79,9 @@ handle_add_partner_finished (void *cls, { struct TALER_EXCHANGE_ManagementAddPartner *wh = cls; const json_t *json = response; - struct TALER_EXCHANGE_HttpResponse hr = { - .http_status = (unsigned int) response_code, - .reply = json + struct TALER_EXCHANGE_ManagementAddPartnerResponse apr = { + .hr.http_status = (unsigned int) response_code, + .hr.reply = json }; wh->job = NULL; @@ -89,34 +89,34 @@ handle_add_partner_finished (void *cls, { case 0: /* no reply */ - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; - hr.hint = "server offline?"; + apr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + apr.hr.hint = "server offline?"; break; case MHD_HTTP_NO_CONTENT: break; case MHD_HTTP_FORBIDDEN: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + apr.hr.ec = TALER_JSON_get_error_code (json); + apr.hr.hint = TALER_JSON_get_error_hint (json); break; case MHD_HTTP_CONFLICT: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + apr.hr.ec = TALER_JSON_get_error_code (json); + apr.hr.hint = TALER_JSON_get_error_hint (json); break; default: /* unexpected response code */ GNUNET_break_op (0); - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + apr.hr.ec = TALER_JSON_get_error_code (json); + apr.hr.hint = TALER_JSON_get_error_hint (json); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d for adding exchange partner\n", (unsigned int) response_code, - (int) hr.ec); + (int) apr.hr.ec); break; } if (NULL != wh->cb) { wh->cb (wh->cb_cls, - &hr); + &apr); wh->cb = NULL; } TALER_EXCHANGE_management_add_partner_cancel (wh); diff --git a/src/lib/exchange_api_management_auditor_disable.c b/src/lib/exchange_api_management_auditor_disable.c index b1de80f0..8bce7f74 100644 --- a/src/lib/exchange_api_management_auditor_disable.c +++ b/src/lib/exchange_api_management_auditor_disable.c @@ -81,9 +81,9 @@ handle_auditor_disable_finished (void *cls, { struct TALER_EXCHANGE_ManagementAuditorDisableHandle *ah = cls; const json_t *json = response; - struct TALER_EXCHANGE_HttpResponse hr = { - .http_status = (unsigned int) response_code, - .reply = json + struct TALER_EXCHANGE_ManagementAuditorDisableResponse adr = { + .hr.http_status = (unsigned int) response_code, + .hr.reply = json }; ah->job = NULL; @@ -92,32 +92,32 @@ handle_auditor_disable_finished (void *cls, case MHD_HTTP_NO_CONTENT: break; case MHD_HTTP_FORBIDDEN: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + adr.hr.ec = TALER_JSON_get_error_code (json); + adr.hr.hint = TALER_JSON_get_error_hint (json); break; case MHD_HTTP_NOT_FOUND: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + adr.hr.ec = TALER_JSON_get_error_code (json); + adr.hr.hint = TALER_JSON_get_error_hint (json); break; case MHD_HTTP_CONFLICT: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + adr.hr.ec = TALER_JSON_get_error_code (json); + adr.hr.hint = TALER_JSON_get_error_hint (json); break; default: /* unexpected response code */ GNUNET_break_op (0); - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + adr.hr.ec = TALER_JSON_get_error_code (json); + adr.hr.hint = TALER_JSON_get_error_hint (json); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d for exchange management auditor disable\n", (unsigned int) response_code, - (int) hr.ec); + (int) adr.hr.ec); break; } if (NULL != ah->cb) { ah->cb (ah->cb_cls, - &hr); + &adr); ah->cb = NULL; } TALER_EXCHANGE_management_disable_auditor_cancel (ah); diff --git a/src/lib/exchange_api_management_auditor_enable.c b/src/lib/exchange_api_management_auditor_enable.c index af75215e..65018577 100644 --- a/src/lib/exchange_api_management_auditor_enable.c +++ b/src/lib/exchange_api_management_auditor_enable.c @@ -82,9 +82,9 @@ handle_auditor_enable_finished (void *cls, { struct TALER_EXCHANGE_ManagementAuditorEnableHandle *ah = cls; const json_t *json = response; - struct TALER_EXCHANGE_HttpResponse hr = { - .http_status = (unsigned int) response_code, - .reply = json + struct TALER_EXCHANGE_ManagementAuditorEnableResponse aer = { + .hr.http_status = (unsigned int) response_code, + .hr.reply = json }; ah->job = NULL; @@ -93,28 +93,28 @@ handle_auditor_enable_finished (void *cls, case MHD_HTTP_NO_CONTENT: break; case MHD_HTTP_FORBIDDEN: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + aer.hr.ec = TALER_JSON_get_error_code (json); + aer.hr.hint = TALER_JSON_get_error_hint (json); break; case MHD_HTTP_CONFLICT: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + aer.hr.ec = TALER_JSON_get_error_code (json); + aer.hr.hint = TALER_JSON_get_error_hint (json); break; default: /* unexpected response code */ GNUNET_break_op (0); - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + aer.hr.ec = TALER_JSON_get_error_code (json); + aer.hr.hint = TALER_JSON_get_error_hint (json); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d for exchange management auditor enable\n", (unsigned int) response_code, - (int) hr.ec); + (int) aer.hr.ec); break; } if (NULL != ah->cb) { ah->cb (ah->cb_cls, - &hr); + &aer); ah->cb = NULL; } TALER_EXCHANGE_management_enable_auditor_cancel (ah); diff --git a/src/lib/exchange_api_management_post_extensions.c b/src/lib/exchange_api_management_post_extensions.c index b9721a98..99d1653d 100644 --- a/src/lib/exchange_api_management_post_extensions.c +++ b/src/lib/exchange_api_management_post_extensions.c @@ -126,7 +126,7 @@ struct TALER_EXCHANGE_ManagementPostExtensionsHandle * TALER_EXCHANGE_management_post_extensions ( struct GNUNET_CURL_Context *ctx, const char *url, - struct TALER_EXCHANGE_ManagementPostExtensionsData *ped, + const struct TALER_EXCHANGE_ManagementPostExtensionsData *ped, TALER_EXCHANGE_ManagementPostExtensionsCallback cb, void *cb_cls) { @@ -151,7 +151,7 @@ TALER_EXCHANGE_management_post_extensions ( body = GNUNET_JSON_PACK ( GNUNET_JSON_pack_object_steal ("extensions", - ped->extensions), + (json_t *) ped->extensions), GNUNET_JSON_pack_data_auto ("extensions_sig", &ped->extensions_sig)); diff --git a/src/lib/exchange_api_management_set_global_fee.c b/src/lib/exchange_api_management_set_global_fee.c index c8fae5c1..518e710c 100644 --- a/src/lib/exchange_api_management_set_global_fee.c +++ b/src/lib/exchange_api_management_set_global_fee.c @@ -79,9 +79,9 @@ handle_set_global_fee_finished (void *cls, { struct TALER_EXCHANGE_ManagementSetGlobalFeeHandle *sgfh = cls; const json_t *json = response; - struct TALER_EXCHANGE_HttpResponse hr = { - .http_status = (unsigned int) response_code, - .reply = json + struct TALER_EXCHANGE_ManagementSetGlobalFeeResponse sfr = { + .hr.http_status = (unsigned int) response_code, + .hr.reply = json }; sgfh->job = NULL; @@ -90,32 +90,32 @@ handle_set_global_fee_finished (void *cls, case MHD_HTTP_NO_CONTENT: break; case MHD_HTTP_FORBIDDEN: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + sfr.hr.ec = TALER_JSON_get_error_code (json); + sfr.hr.hint = TALER_JSON_get_error_hint (json); break; case MHD_HTTP_CONFLICT: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + sfr.hr.ec = TALER_JSON_get_error_code (json); + sfr.hr.hint = TALER_JSON_get_error_hint (json); break; case MHD_HTTP_PRECONDITION_FAILED: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + sfr.hr.ec = TALER_JSON_get_error_code (json); + sfr.hr.hint = TALER_JSON_get_error_hint (json); break; default: /* unexpected response code */ GNUNET_break_op (0); - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + sfr.hr.ec = TALER_JSON_get_error_code (json); + sfr.hr.hint = TALER_JSON_get_error_hint (json); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d for exchange management set global fee\n", (unsigned int) response_code, - (int) hr.ec); + (int) sfr.hr.ec); break; } if (NULL != sgfh->cb) { sgfh->cb (sgfh->cb_cls, - &hr); + &sfr); sgfh->cb = NULL; } TALER_EXCHANGE_management_set_global_fees_cancel (sgfh); diff --git a/src/lib/exchange_api_management_set_wire_fee.c b/src/lib/exchange_api_management_set_wire_fee.c index 72526116..01ed7742 100644 --- a/src/lib/exchange_api_management_set_wire_fee.c +++ b/src/lib/exchange_api_management_set_wire_fee.c @@ -79,9 +79,9 @@ handle_set_wire_fee_finished (void *cls, { struct TALER_EXCHANGE_ManagementSetWireFeeHandle *swfh = cls; const json_t *json = response; - struct TALER_EXCHANGE_HttpResponse hr = { - .http_status = (unsigned int) response_code, - .reply = json + struct TALER_EXCHANGE_ManagementSetWireFeeResponse swr = { + .hr.http_status = (unsigned int) response_code, + .hr.reply = json }; swfh->job = NULL; @@ -90,32 +90,32 @@ handle_set_wire_fee_finished (void *cls, case MHD_HTTP_NO_CONTENT: break; case MHD_HTTP_FORBIDDEN: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + swr.hr.ec = TALER_JSON_get_error_code (json); + swr.hr.hint = TALER_JSON_get_error_hint (json); break; case MHD_HTTP_CONFLICT: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + swr.hr.ec = TALER_JSON_get_error_code (json); + swr.hr.hint = TALER_JSON_get_error_hint (json); break; case MHD_HTTP_PRECONDITION_FAILED: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + swr.hr.ec = TALER_JSON_get_error_code (json); + swr.hr.hint = TALER_JSON_get_error_hint (json); break; default: /* unexpected response code */ GNUNET_break_op (0); - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + swr.hr.ec = TALER_JSON_get_error_code (json); + swr.hr.hint = TALER_JSON_get_error_hint (json); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d for exchange management set wire fee\n", (unsigned int) response_code, - (int) hr.ec); + (int) swr.hr.ec); break; } if (NULL != swfh->cb) { swfh->cb (swfh->cb_cls, - &hr); + &swr); swfh->cb = NULL; } TALER_EXCHANGE_management_set_wire_fees_cancel (swfh); diff --git a/src/testing/testing_api_cmd_auditor_add.c b/src/testing/testing_api_cmd_auditor_add.c index 8362b66c..41182b7c 100644 --- a/src/testing/testing_api_cmd_auditor_add.c +++ b/src/testing/testing_api_cmd_auditor_add.c @@ -62,13 +62,15 @@ struct AuditorAddState * if the response code is acceptable. * * @param cls closure. - * @param hr HTTP response details + * @param aer response details */ static void -auditor_add_cb (void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr) +auditor_add_cb ( + void *cls, + const struct TALER_EXCHANGE_ManagementAuditorEnableResponse *aer) { struct AuditorAddState *ds = cls; + const struct TALER_EXCHANGE_HttpResponse *hr = &aer->hr; ds->dh = NULL; if (ds->expected_response_code != hr->http_status) diff --git a/src/testing/testing_api_cmd_auditor_add_denom_sig.c b/src/testing/testing_api_cmd_auditor_add_denom_sig.c index 3d7ea82f..55b9f77a 100644 --- a/src/testing/testing_api_cmd_auditor_add_denom_sig.c +++ b/src/testing/testing_api_cmd_auditor_add_denom_sig.c @@ -67,13 +67,15 @@ struct AuditorAddDenomSigState * if the response code is acceptable. * * @param cls closure. - * @param hr HTTP response details + * @param adr response details */ static void -denom_sig_add_cb (void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr) +denom_sig_add_cb ( + void *cls, + const struct TALER_EXCHANGE_AuditorAddDenominationResponse *adr) { struct AuditorAddDenomSigState *ds = cls; + const struct TALER_EXCHANGE_HttpResponse *hr = &adr->hr; ds->dh = NULL; if (ds->expected_response_code != hr->http_status) diff --git a/src/testing/testing_api_cmd_auditor_del.c b/src/testing/testing_api_cmd_auditor_del.c index de03d163..5bf77bb5 100644 --- a/src/testing/testing_api_cmd_auditor_del.c +++ b/src/testing/testing_api_cmd_auditor_del.c @@ -62,13 +62,16 @@ struct AuditorDelState * if the response code is acceptable. * * @param cls closure. - * @param hr HTTP response details + * @param adr response details */ static void -auditor_del_cb (void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr) +auditor_del_cb ( + void *cls, + const struct TALER_EXCHANGE_ManagementAuditorDisableResponse *adr) + { struct AuditorDelState *ds = cls; + const struct TALER_EXCHANGE_HttpResponse *hr = &adr->hr; ds->dh = NULL; if (ds->expected_response_code != hr->http_status) diff --git a/src/testing/testing_api_cmd_set_wire_fee.c b/src/testing/testing_api_cmd_set_wire_fee.c index ed3448ac..f0f76a87 100644 --- a/src/testing/testing_api_cmd_set_wire_fee.c +++ b/src/testing/testing_api_cmd_set_wire_fee.c @@ -77,13 +77,14 @@ struct WireFeeState * if the response code is acceptable. * * @param cls closure. - * @param hr HTTP response details + * @param sfr response details */ static void wire_add_cb (void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr) + const struct TALER_EXCHANGE_ManagementSetWireFeeResponse *sfr) { struct WireFeeState *ds = cls; + const struct TALER_EXCHANGE_HttpResponse *hr = &sfr->hr; ds->dh = NULL; if (ds->expected_response_code != hr->http_status) diff --git a/src/testing/testing_api_cmd_take_aml_decision.c b/src/testing/testing_api_cmd_take_aml_decision.c index 21ba9af6..c355c686 100644 --- a/src/testing/testing_api_cmd_take_aml_decision.c +++ b/src/testing/testing_api_cmd_take_aml_decision.c @@ -90,17 +90,19 @@ struct AmlDecisionState /** - * Callback to analyze the /management/XXX response, just used to check + * Callback to analyze the /aml-decision/$OFFICER_PUB response, just used to check * if the response code is acceptable. * * @param cls closure. - * @param hr HTTP response details + * @param adr response details */ static void -take_aml_decision_cb (void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr) +take_aml_decision_cb ( + void *cls, + const struct TALER_EXCHANGE_AddAmlDecisionResponse *adr) { struct AmlDecisionState *ds = cls; + const struct TALER_EXCHANGE_HttpResponse *hr = &adr->hr; ds->dh = NULL; if (ds->expected_response != hr->http_status) -- cgit v1.2.3 From 9e7d3f90657dc2ac9905c8800bff79cd1c97ebd9 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 4 Jun 2023 14:29:15 +0200 Subject: address FIXMEs in bank service API --- src/bank-lib/bank_api_admin.c | 39 +++---- src/bank-lib/bank_api_transfer.c | 37 +++---- src/bank-lib/taler-exchange-wire-gateway-client.c | 48 +++----- src/exchange/taler-exchange-transfer.c | 28 ++--- src/include/taler_bank_service.h | 122 +++++++++++++++++---- .../testing_api_cmd_bank_admin_add_incoming.c | 47 ++++---- src/testing/testing_api_cmd_bank_transfer.c | 34 +++--- 7 files changed, 194 insertions(+), 161 deletions(-) (limited to 'src/include') diff --git a/src/bank-lib/bank_api_admin.c b/src/bank-lib/bank_api_admin.c index f0d97bda..0b8e80e9 100644 --- a/src/bank-lib/bank_api_admin.c +++ b/src/bank-lib/bank_api_admin.c @@ -74,25 +74,25 @@ handle_admin_add_incoming_finished (void *cls, const void *response) { struct TALER_BANK_AdminAddIncomingHandle *aai = cls; - uint64_t row_id = UINT64_MAX; - struct GNUNET_TIME_Timestamp timestamp; - enum TALER_ErrorCode ec; const json_t *j = response; + struct TALER_BANK_AdminAddIncomingResponse ir = { + .http_status = response_code, + .response = response + }; aai->job = NULL; - timestamp = GNUNET_TIME_UNIT_FOREVER_TS; switch (response_code) { case 0: - ec = TALER_EC_GENERIC_INVALID_RESPONSE; + ir.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; case MHD_HTTP_OK: { struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_uint64 ("row_id", - &row_id), + &ir.details.ok.serial_id), GNUNET_JSON_spec_timestamp ("timestamp", - ×tamp), + &ir.details.ok.timestamp), GNUNET_JSON_spec_end () }; @@ -102,42 +102,41 @@ handle_admin_add_incoming_finished (void *cls, NULL, NULL)) { GNUNET_break_op (0); - response_code = 0; - ec = TALER_EC_GENERIC_INVALID_RESPONSE; + ir.http_status = 0; + ir.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; } - ec = TALER_EC_NONE; } break; case MHD_HTTP_BAD_REQUEST: /* This should never happen, either us or the bank is buggy (or API version conflict); just pass JSON reply to the application */ GNUNET_break_op (0); - ec = TALER_JSON_get_error_code (j); + ir.ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_FORBIDDEN: /* Access denied */ - ec = TALER_JSON_get_error_code (j); + ir.ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_UNAUTHORIZED: /* Nothing really to verify, bank says the password is invalid; we should pass the JSON reply to the application */ - ec = TALER_JSON_get_error_code (j); + ir.ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_NOT_FOUND: /* Nothing really to verify, maybe account really does not exist. We should pass the JSON reply to the application */ - ec = TALER_JSON_get_error_code (j); + ir.ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_CONFLICT: /* Nothing to verify, we used the same wire subject twice? */ - ec = TALER_JSON_get_error_code (j); + ir.ec = TALER_JSON_get_error_code (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); + ir.ec = TALER_JSON_get_error_code (j); break; default: /* unexpected response code */ @@ -145,15 +144,11 @@ handle_admin_add_incoming_finished (void *cls, "Unexpected response code %u\n", (unsigned int) response_code); GNUNET_break (0); - ec = TALER_JSON_get_error_code (j); + ir.ec = TALER_JSON_get_error_code (j); break; } aai->cb (aai->cb_cls, - response_code, - ec, - row_id, - timestamp, - j); + &ir); TALER_BANK_admin_add_incoming_cancel (aai); } diff --git a/src/bank-lib/bank_api_transfer.c b/src/bank-lib/bank_api_transfer.c index 94d8c6b6..0748a0d7 100644 --- a/src/bank-lib/bank_api_transfer.c +++ b/src/bank-lib/bank_api_transfer.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2015--2020 Taler Systems SA + Copyright (C) 2015--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 @@ -158,23 +158,24 @@ handle_transfer_finished (void *cls, { struct TALER_BANK_TransferHandle *th = cls; const json_t *j = response; - uint64_t row_id = UINT64_MAX; - struct GNUNET_TIME_Timestamp timestamp = GNUNET_TIME_UNIT_FOREVER_TS; - enum TALER_ErrorCode ec; + struct TALER_BANK_TransferResponse tr = { + .http_status = response_code, + .response = j + }; th->job = NULL; switch (response_code) { case 0: - ec = TALER_EC_GENERIC_INVALID_RESPONSE; + tr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; case MHD_HTTP_OK: { struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_uint64 ("row_id", - &row_id), + &tr.details.ok.row_id), GNUNET_JSON_spec_timestamp ("timestamp", - ×tamp), + &tr.details.ok.timestamp), GNUNET_JSON_spec_end () }; @@ -184,39 +185,38 @@ handle_transfer_finished (void *cls, NULL, NULL)) { GNUNET_break_op (0); - response_code = 0; - ec = TALER_EC_GENERIC_INVALID_RESPONSE; + tr.http_status = 0; + tr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; } - ec = TALER_EC_NONE; } break; case MHD_HTTP_BAD_REQUEST: /* This should never happen, either us or the bank is buggy (or API version conflict); just pass JSON reply to the application */ GNUNET_break_op (0); - ec = TALER_JSON_get_error_code (j); + tr.ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_UNAUTHORIZED: /* Nothing really to verify, bank says our credentials are invalid. We should pass the JSON reply to the application. */ - ec = TALER_JSON_get_error_code (j); + tr.ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_NOT_FOUND: /* Nothing really to verify, endpoint wrong -- could be user unknown */ - ec = TALER_JSON_get_error_code (j); + tr.ec = TALER_JSON_get_error_code (j); break; case MHD_HTTP_CONFLICT: /* Nothing really to verify. Server says we used the same transfer request UID before, but with different details. Should not happen if the user properly used #TALER_BANK_prepare_transfer() and our PRNG is not broken... */ - ec = TALER_JSON_get_error_code (j); + tr.ec = TALER_JSON_get_error_code (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); + tr.ec = TALER_JSON_get_error_code (j); break; default: /* unexpected response code */ @@ -224,14 +224,11 @@ handle_transfer_finished (void *cls, "Unexpected response code %u\n", (unsigned int) response_code); GNUNET_break (0); - ec = TALER_JSON_get_error_code (j); + tr.ec = TALER_JSON_get_error_code (j); break; } th->cb (th->cb_cls, - response_code, - ec, - row_id, - timestamp); + &tr); TALER_BANK_transfer_cancel (th); } diff --git a/src/bank-lib/taler-exchange-wire-gateway-client.c b/src/bank-lib/taler-exchange-wire-gateway-client.c index a972bcfd..0d4bba00 100644 --- a/src/bank-lib/taler-exchange-wire-gateway-client.c +++ b/src/bank-lib/taler-exchange-wire-gateway-client.c @@ -357,34 +357,28 @@ execute_debit_history (void) * execution. * * @param cls closure - * @param response_code HTTP status code - * @param ec taler error code - * @param row_id unique ID of the wire transfer in the bank's records - * @param timestamp when did the transaction go into effect + * @param tr response details */ static void confirmation_cb (void *cls, - unsigned int response_code, - enum TALER_ErrorCode ec, - uint64_t row_id, - struct GNUNET_TIME_Timestamp timestamp) + const struct TALER_BANK_TransferResponse *tr) { (void) cls; eh = NULL; - if (MHD_HTTP_OK != response_code) + if (MHD_HTTP_OK != tr->http_status) { fprintf (stderr, "The wire transfer didn't execute correctly (%u/%d).\n", - response_code, - ec); + tr->http_status, + tr->ec); GNUNET_SCHEDULER_shutdown (); return; } fprintf (stdout, "Wire transfer #%llu executed successfully at %s.\n", - (unsigned long long) row_id, - GNUNET_TIME_timestamp2s (timestamp)); + (unsigned long long) tr->details.ok.row_id, + GNUNET_TIME_timestamp2s (tr->details.ok.timestamp)); global_ret = 0; GNUNET_SCHEDULER_shutdown (); } @@ -464,39 +458,29 @@ execute_wire_transfer (void) * Function called with the result of the operation. * * @param cls closure - * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request - * 0 if the bank's reply is bogus (fails to follow the protocol) - * @param ec detailed error code - * @param serial_id unique ID of the wire transfer in the bank's records; UINT64_MAX on error - * @param timestamp timestamp when the transaction got settled at the bank. - * @param json detailed response from the HTTPD, or NULL if reply was not in JSON + * @param air response details */ static void res_cb (void *cls, - unsigned int http_status, - enum TALER_ErrorCode ec, - uint64_t serial_id, - struct GNUNET_TIME_Timestamp timestamp, - const json_t *json) + const struct TALER_BANK_AdminAddIncomingResponse *air) { (void) cls; - (void) timestamp; op = NULL; - switch (ec) + switch (air->http_status) { - case TALER_EC_NONE: + case MHD_HTTP_OK: global_ret = 0; fprintf (stdout, "%llu\n", - (unsigned long long) serial_id); + (unsigned long long) air->details.ok.serial_id); break; default: fprintf (stderr, "Operation failed with status code %u/%u\n", - (unsigned int) ec, - http_status); - if (NULL != json) - json_dumpf (json, + (unsigned int) air->ec, + air->http_status); + if (NULL != air->response) + json_dumpf (air->response, stderr, JSON_INDENT (2)); break; diff --git a/src/exchange/taler-exchange-transfer.c b/src/exchange/taler-exchange-transfer.c index 255fe76a..ae2b4fe7 100644 --- a/src/exchange/taler-exchange-transfer.c +++ b/src/exchange/taler-exchange-transfer.c @@ -406,25 +406,17 @@ batch_done (void) * except for irrecoverable errors. * * @param cls `struct WirePrepareData` we are working on - * @param http_status_code #MHD_HTTP_OK on success - * @param ec taler error code - * @param row_id unique ID of the wire transfer in the bank's records - * @param wire_timestamp when did the transfer happen + * @param tr transfer response */ static void wire_confirm_cb (void *cls, - unsigned int http_status_code, - enum TALER_ErrorCode ec, - uint64_t row_id, - struct GNUNET_TIME_Timestamp wire_timestamp) + const struct TALER_BANK_TransferResponse *tr) { struct WirePrepareData *wpd = cls; enum GNUNET_DB_QueryStatus qs; - (void) row_id; - (void) wire_timestamp; wpd->eh = NULL; - switch (http_status_code) + switch (tr->http_status) { case MHD_HTTP_OK: GNUNET_log (GNUNET_ERROR_TYPE_INFO, @@ -438,8 +430,8 @@ wire_confirm_cb (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Wire transaction %llu failed: %u/%d\n", (unsigned long long) wpd->row_id, - http_status_code, - ec); + tr->http_status, + tr->ec); qs = db_plugin->wire_prepare_data_mark_failed (db_plugin->cls, wpd->row_id); /* continued below */ @@ -456,7 +448,7 @@ wire_confirm_cb (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Wire transfer %llu failed (%u), trying again\n", (unsigned long long) wpd->row_id, - http_status_code); + tr->http_status); wpd->eh = TALER_BANK_transfer (ctx, wpd->wa->auth, &wpd[1], @@ -468,8 +460,8 @@ wire_confirm_cb (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Wire transaction %llu failed: %u/%d\n", (unsigned long long) wpd->row_id, - http_status_code, - ec); + tr->http_status, + tr->ec); cleanup_wpd (); db_plugin->rollback (db_plugin->cls); global_ret = EXIT_FAILURE; @@ -479,8 +471,8 @@ wire_confirm_cb (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Wire transfer %llu failed: %u/%d\n", (unsigned long long) wpd->row_id, - http_status_code, - ec); + tr->http_status, + tr->ec); db_plugin->rollback (db_plugin->cls); cleanup_wpd (); global_ret = EXIT_FAILURE; diff --git a/src/include/taler_bank_service.h b/src/include/taler_bank_service.h index 5ce5e254..e0970cb1 100644 --- a/src/include/taler_bank_service.h +++ b/src/include/taler_bank_service.h @@ -99,27 +99,65 @@ struct TALER_BANK_AuthenticationData struct TALER_BANK_AdminAddIncomingHandle; +/** + * Response details for a history request. + */ +struct TALER_BANK_AdminAddIncomingResponse +{ + + /** + * HTTP status. + */ + unsigned int http_status; + + /** + * Taler error code, #TALER_EC_NONE on success. + */ + enum TALER_ErrorCode ec; + + /** + * Full response, NULL if body was not in JSON format. + */ + const json_t *response; + + /** + * Details returned depending on the @e http_status. + */ + union + { + + /** + * Details if status was #MHD_HTTP_OK + */ + struct + { + /** + * unique ID of the wire transfer in the bank's records + */ + uint64_t serial_id; + + /** + * time when the transaction was made. + */ + struct GNUNET_TIME_Timestamp timestamp; + + } ok; + + } details; + +}; + /** * Callbacks of this type are used to return the result of submitting * a request to transfer funds to the exchange. * * @param cls closure - * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request - * 0 if the bank's reply is bogus (fails to follow the protocol) - * @param ec detailed error code - * @param serial_id unique ID of the wire transfer in the bank's records; UINT64_MAX on error - * @param timestamp time when the transaction was made. - * @param json detailed response from the HTTPD, or NULL if reply was not in JSON + * @param air response details */ -// FIXME: bad API typedef void (*TALER_BANK_AdminAddIncomingCallback) ( void *cls, - unsigned int http_status, - enum TALER_ErrorCode ec, - uint64_t serial_id, - struct GNUNET_TIME_Timestamp timestamp, - const json_t *json); + const struct TALER_BANK_AdminAddIncomingResponse *air); /** @@ -191,23 +229,65 @@ TALER_BANK_prepare_transfer ( struct TALER_BANK_TransferHandle; +/** + * Response details for a history request. + */ +struct TALER_BANK_TransferResponse +{ + + /** + * HTTP status. + */ + unsigned int http_status; + + /** + * Taler error code, #TALER_EC_NONE on success. + */ + enum TALER_ErrorCode ec; + + /** + * Full response, NULL if body was not in JSON format. + */ + const json_t *response; + + /** + * Details returned depending on the @e http_status. + */ + union + { + + /** + * Details if status was #MHD_HTTP_OK + */ + struct + { + + + /** + * unique ID of the wire transfer in the bank's records + */ + uint64_t row_id; + + /** + * when did the transaction go into effect + */ + struct GNUNET_TIME_Timestamp timestamp; + + } ok; + } details; +}; + + /** * Function called with the result from the execute step. * * @param cls closure - * @param response_code HTTP status code - * @param ec taler error code - * @param row_id unique ID of the wire transfer in the bank's records - * @param timestamp when did the transaction go into effect + * @param tr response details */ -// FIXME: bad API typedef void (*TALER_BANK_TransferCallback)( void *cls, - unsigned int response_code, - enum TALER_ErrorCode ec, - uint64_t row_id, - struct GNUNET_TIME_Timestamp timestamp); + const struct TALER_BANK_TransferResponse *tr); /** diff --git a/src/testing/testing_api_cmd_bank_admin_add_incoming.c b/src/testing/testing_api_cmd_bank_admin_add_incoming.c index 973209f2..a7c5dd45 100644 --- a/src/testing/testing_api_cmd_bank_admin_add_incoming.c +++ b/src/testing/testing_api_cmd_bank_admin_add_incoming.c @@ -194,28 +194,15 @@ do_retry (void *cls) * acceptable. * * @param cls closure with the interpreter state - * @param http_status HTTP response code, #MHD_HTTP_OK (200) for - * successful status request; 0 if the exchange's reply is - * bogus (fails to follow the protocol) - * @param ec taler-specific error code, #TALER_EC_NONE on success - * @param serial_id unique ID of the wire transfer - * @param timestamp time stamp of the transaction made. - * @param json raw response + * @param air response details */ static void confirmation_cb (void *cls, - unsigned int http_status, - enum TALER_ErrorCode ec, - uint64_t serial_id, - struct GNUNET_TIME_Timestamp timestamp, - const json_t *json) + const struct TALER_BANK_AdminAddIncomingResponse *air) { struct AdminAddIncomingState *fts = cls; struct TALER_TESTING_Interpreter *is = fts->is; - (void) json; - fts->reserve_history.details.in_details.timestamp = timestamp; - fts->reserve_history.details.in_details.wire_reference = serial_id; fts->aih = NULL; /** * Test case not caring about the HTTP status code. @@ -237,17 +224,23 @@ confirmation_cb (void *cls, TALER_TESTING_interpreter_next (is); return; } - if (http_status != fts->expected_http_status) + if (air->http_status != fts->expected_http_status) { GNUNET_break (0); TALER_TESTING_interpreter_fail (is); return; } - switch (http_status) + switch (air->http_status) { case MHD_HTTP_OK: - fts->serial_id = serial_id; - fts->timestamp = timestamp; + fts->reserve_history.details.in_details.timestamp + = air->details.ok.timestamp; + fts->reserve_history.details.in_details.wire_reference + = air->details.ok.serial_id; + fts->serial_id + = air->details.ok.serial_id; + fts->timestamp + = air->details.ok.timestamp; TALER_TESTING_interpreter_next (is); return; case MHD_HTTP_UNAUTHORIZED: @@ -271,17 +264,17 @@ confirmation_cb (void *cls, if (0 != fts->do_retry) { fts->do_retry--; - if ( (0 == http_status) || - (TALER_EC_GENERIC_DB_SOFT_FAILURE == ec) || - (MHD_HTTP_INTERNAL_SERVER_ERROR == http_status) ) + if ( (0 == air->http_status) || + (TALER_EC_GENERIC_DB_SOFT_FAILURE == air->ec) || + (MHD_HTTP_INTERNAL_SERVER_ERROR == air->http_status) ) { GNUNET_log ( GNUNET_ERROR_TYPE_INFO, "Retrying fakebank transfer failed with %u/%d\n", - http_status, - (int) ec); + air->http_status, + (int) air->ec); /* on DB conflicts, do not use backoff */ - if (TALER_EC_GENERIC_DB_SOFT_FAILURE == ec) + if (TALER_EC_GENERIC_DB_SOFT_FAILURE == air->ec) fts->backoff = GNUNET_TIME_UNIT_ZERO; else fts->backoff = GNUNET_TIME_randomized_backoff (fts->backoff, @@ -299,8 +292,8 @@ confirmation_cb (void *cls, GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fakebank returned HTTP status %u/%d\n", - http_status, - (int) ec); + air->http_status, + (int) air->ec); TALER_TESTING_interpreter_fail (is); } diff --git a/src/testing/testing_api_cmd_bank_transfer.c b/src/testing/testing_api_cmd_bank_transfer.c index 8c14aac1..d4477645 100644 --- a/src/testing/testing_api_cmd_bank_transfer.c +++ b/src/testing/testing_api_cmd_bank_transfer.c @@ -163,39 +163,31 @@ do_retry (void *cls) * acceptable. * * @param cls closure with the interpreter state - * @param http_status HTTP response code, #MHD_HTTP_OK (200) for - * successful status request; 0 if the exchange's reply is - * bogus (fails to follow the protocol) - * @param ec taler-specific error code, #TALER_EC_NONE on success - * @param serial_id unique ID of the wire transfer - * @param timestamp time stamp of the transaction made. + * @param tr response details */ static void confirmation_cb (void *cls, - unsigned int http_status, - enum TALER_ErrorCode ec, - uint64_t serial_id, - struct GNUNET_TIME_Timestamp timestamp) + const struct TALER_BANK_TransferResponse *tr) { struct TransferState *fts = cls; struct TALER_TESTING_Interpreter *is = fts->is; fts->weh = NULL; - if (MHD_HTTP_OK != http_status) + if (MHD_HTTP_OK != tr->http_status) { if (0 != fts->do_retry) { fts->do_retry--; - if ( (0 == http_status) || - (TALER_EC_GENERIC_DB_SOFT_FAILURE == ec) || - (MHD_HTTP_INTERNAL_SERVER_ERROR == http_status) ) + if ( (0 == tr->http_status) || + (TALER_EC_GENERIC_DB_SOFT_FAILURE == tr->ec) || + (MHD_HTTP_INTERNAL_SERVER_ERROR == tr->http_status) ) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Retrying transfer failed with %u/%d\n", - http_status, - (int) ec); + tr->http_status, + (int) tr->ec); /* on DB conflicts, do not use backoff */ - if (TALER_EC_GENERIC_DB_SOFT_FAILURE == ec) + if (TALER_EC_GENERIC_DB_SOFT_FAILURE == tr->ec) fts->backoff = GNUNET_TIME_UNIT_ZERO; else fts->backoff = EXCHANGE_LIB_BACKOFF (fts->backoff); @@ -210,14 +202,14 @@ confirmation_cb (void *cls, GNUNET_break (0); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Bank returned HTTP status %u/%d\n", - http_status, - (int) ec); + tr->http_status, + (int) tr->ec); TALER_TESTING_interpreter_fail (is); return; } - fts->serial_id = serial_id; - fts->timestamp = timestamp; + fts->serial_id = tr->details.ok.row_id; + fts->timestamp = tr->details.ok.timestamp; TALER_TESTING_interpreter_next (is); } -- cgit v1.2.3