diff options
Diffstat (limited to 'src/lib/exchange_api_management_post_extensions.c')
-rw-r--r-- | src/lib/exchange_api_management_post_extensions.c | 64 |
1 files changed, 37 insertions, 27 deletions
diff --git a/src/lib/exchange_api_management_post_extensions.c b/src/lib/exchange_api_management_post_extensions.c index 87b0e0be8..00d1c5e3f 100644 --- a/src/lib/exchange_api_management_post_extensions.c +++ b/src/lib/exchange_api_management_post_extensions.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2015-2021 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 @@ -23,6 +23,7 @@ #include "taler_json_lib.h" #include <gnunet/gnunet_curl_lib.h> #include "taler_extensions.h" +#include "exchange_api_curl_defaults.h" #include "taler_exchange_service.h" #include "taler_signatures.h" #include "taler_curl_lib.h" @@ -82,9 +83,9 @@ handle_post_extensions_finished (void *cls, { struct TALER_EXCHANGE_ManagementPostExtensionsHandle *ph = cls; const json_t *json = response; - struct TALER_EXCHANGE_HttpResponse hr = { - .http_status = (unsigned int) response_code, - .reply = json + struct TALER_EXCHANGE_ManagementPostExtensionsResponse per = { + .hr.http_status = (unsigned int) response_code, + .hr.reply = json }; ph->job = NULL; @@ -93,31 +94,42 @@ handle_post_extensions_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); + per.hr.ec = TALER_JSON_get_error_code (json); + per.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); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Server did not find handler at `%s'. Did you configure the correct exchange base URL?\n", + ph->url); + if (NULL != json) + { + per.hr.ec = TALER_JSON_get_error_code (json); + per.hr.hint = TALER_JSON_get_error_hint (json); + } + else + { + per.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + per.hr.hint = TALER_ErrorCode_get_hint (per.hr.ec); + } 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); + per.hr.ec = TALER_JSON_get_error_code (json); + per.hr.hint = TALER_JSON_get_error_hint (json); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d for exchange management post extensions\n", (unsigned int) response_code, - (int) hr.ec); + (int) per.hr.ec); break; } if (NULL != ph->cb) { ph->cb (ph->cb_cls, - &hr); + &per); ph->cb = NULL; } - TALER_EXCHANGE_post_management_extensions_cancel (ph); + TALER_EXCHANGE_management_post_extensions_cancel (ph); } @@ -125,7 +137,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) { @@ -150,30 +162,28 @@ 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)); - eh = curl_easy_init (); - GNUNET_assert (NULL != eh); - if (GNUNET_OK != - TALER_curl_easy_post (&ph->post_ctx, - eh, - body)) + eh = TALER_EXCHANGE_curl_easy_get_ (ph->url); + if ( (NULL == eh) || + (GNUNET_OK != + TALER_curl_easy_post (&ph->post_ctx, + eh, + body)) ) { GNUNET_break (0); + if (NULL != eh) + curl_easy_cleanup (eh); json_decref (body); GNUNET_free (ph->url); - GNUNET_free (eh); return NULL; } json_decref (body); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting URL '%s'\n", ph->url); - GNUNET_assert (CURLE_OK == curl_easy_setopt (eh, - CURLOPT_URL, - ph->url)); ph->job = GNUNET_CURL_job_add2 (ctx, eh, ph->post_ctx.headers, @@ -181,7 +191,7 @@ TALER_EXCHANGE_management_post_extensions ( ph); if (NULL == ph->job) { - TALER_EXCHANGE_post_management_extensions_cancel (ph); + TALER_EXCHANGE_management_post_extensions_cancel (ph); return NULL; } return ph; @@ -189,7 +199,7 @@ TALER_EXCHANGE_management_post_extensions ( void -TALER_EXCHANGE_post_management_extensions_cancel ( +TALER_EXCHANGE_management_post_extensions_cancel ( struct TALER_EXCHANGE_ManagementPostExtensionsHandle *ph) { if (NULL != ph->job) |