rename BANK_excecute_wire_transfer to BANK_transfer, improve error handling when curl_easy_init() fails

This commit is contained in:
Christian Grothoff 2020-03-03 17:14:00 +01:00
parent 97fb6b0091
commit a9b3c564bd
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
27 changed files with 350 additions and 238 deletions

View File

@ -218,7 +218,8 @@ TALER_BANK_admin_add_incoming (struct GNUNET_CURL_Context *ctx,
"Content-Type: application/json"); "Content-Type: application/json");
eh = curl_easy_init (); eh = curl_easy_init ();
if ( (GNUNET_OK != if ( (NULL == eh) ||
(GNUNET_OK !=
TALER_BANK_setup_auth_ (eh, TALER_BANK_setup_auth_ (eh,
auth)) || auth)) ||
(CURLE_OK != (CURLE_OK !=
@ -232,6 +233,7 @@ TALER_BANK_admin_add_incoming (struct GNUNET_CURL_Context *ctx,
{ {
GNUNET_break (0); GNUNET_break (0);
TALER_BANK_admin_add_incoming_cancel (aai); TALER_BANK_admin_add_incoming_cancel (aai);
if (NULL != eh)
curl_easy_cleanup (eh); curl_easy_cleanup (eh);
json_decref (admin_obj); json_decref (admin_obj);
return NULL; return NULL;

View File

@ -276,7 +276,8 @@ TALER_BANK_credit_history (struct GNUNET_CURL_Context *ctx,
"Requesting credit history at `%s'\n", "Requesting credit history at `%s'\n",
hh->request_url); hh->request_url);
eh = curl_easy_init (); eh = curl_easy_init ();
if ( (GNUNET_OK != if ( (NULL == eh) ||
(GNUNET_OK !=
TALER_BANK_setup_auth_ (eh, TALER_BANK_setup_auth_ (eh,
auth)) || auth)) ||
(CURLE_OK != (CURLE_OK !=
@ -286,6 +287,7 @@ TALER_BANK_credit_history (struct GNUNET_CURL_Context *ctx,
{ {
GNUNET_break (0); GNUNET_break (0);
TALER_BANK_credit_history_cancel (hh); TALER_BANK_credit_history_cancel (hh);
if (NULL != eh)
curl_easy_cleanup (eh); curl_easy_cleanup (eh);
return NULL; return NULL;
} }

View File

@ -274,7 +274,8 @@ TALER_BANK_debit_history (struct GNUNET_CURL_Context *ctx,
"Requesting history at `%s'\n", "Requesting history at `%s'\n",
hh->request_url); hh->request_url);
eh = curl_easy_init (); eh = curl_easy_init ();
if ( (GNUNET_OK != if ( (NULL == eh) ||
(GNUNET_OK !=
TALER_BANK_setup_auth_ (eh, TALER_BANK_setup_auth_ (eh,
auth)) || auth)) ||
(CURLE_OK != (CURLE_OK !=
@ -284,6 +285,7 @@ TALER_BANK_debit_history (struct GNUNET_CURL_Context *ctx,
{ {
GNUNET_break (0); GNUNET_break (0);
TALER_BANK_debit_history_cancel (hh); TALER_BANK_debit_history_cancel (hh);
if (NULL != eh)
curl_easy_cleanup (eh); curl_easy_cleanup (eh);
return NULL; return NULL;
} }

View File

@ -66,7 +66,8 @@ struct WirePackP
GNUNET_NETWORK_STRUCT_END GNUNET_NETWORK_STRUCT_END
/** /**
* Prepare for exeuction of a wire transfer. * Prepare for execution of a wire transfer from the exchange to some
* merchant.
* *
* @param destination_account_payto_uri payto:// URL identifying where to send the money * @param destination_account_payto_uri payto:// URL identifying where to send the money
* @param amount amount to transfer, already rounded * @param amount amount to transfer, already rounded
@ -77,7 +78,7 @@ GNUNET_NETWORK_STRUCT_END
* @param[out] buf_size set to number of bytes in @a buf, 0 on error * @param[out] buf_size set to number of bytes in @a buf, 0 on error
*/ */
void void
TALER_BANK_prepare_wire_transfer (const char *destination_account_payto_uri, TALER_BANK_prepare_transfer (const char *destination_account_payto_uri,
const struct TALER_Amount *amount, const struct TALER_Amount *amount,
const char *exchange_base_url, const char *exchange_base_url,
const struct const struct
@ -90,6 +91,14 @@ TALER_BANK_prepare_wire_transfer (const char *destination_account_payto_uri,
size_t u_len = strlen (exchange_base_url) + 1; size_t u_len = strlen (exchange_base_url) + 1;
char *end; char *end;
if ( (d_len > (size_t) UINT32_MAX) ||
(u_len > (size_t) UINT32_MAX) )
{
GNUNET_break (0); /* that's some long URL... */
*buf = NULL;
*buf_size = 0;
return;
}
*buf_size = sizeof (*wp) + d_len + u_len; *buf_size = sizeof (*wp) + d_len + u_len;
wp = GNUNET_malloc (*buf_size); wp = GNUNET_malloc (*buf_size);
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_NONCE,
@ -111,9 +120,9 @@ TALER_BANK_prepare_wire_transfer (const char *destination_account_payto_uri,
/** /**
* @brief An transfer Handle * @brief Handle for an active wire transfer.
*/ */
struct TALER_BANK_WireExecuteHandle struct TALER_BANK_TransferHandle
{ {
/** /**
@ -134,7 +143,7 @@ struct TALER_BANK_WireExecuteHandle
/** /**
* Function to call with the result. * Function to call with the result.
*/ */
TALER_BANK_ConfirmationCallback cb; TALER_BANK_TransferCallback cb;
/** /**
* Closure for @a cb. * Closure for @a cb.
@ -148,7 +157,7 @@ struct TALER_BANK_WireExecuteHandle
* Function called when we're done processing the * Function called when we're done processing the
* HTTP /transfer request. * HTTP /transfer request.
* *
* @param cls the `struct TALER_BANK_WireExecuteHandle` * @param cls the `struct TALER_BANK_TransferHandle`
* @param response_code HTTP response code, 0 on error * @param response_code HTTP response code, 0 on error
* @param response parsed JSON result, NULL on error * @param response parsed JSON result, NULL on error
*/ */
@ -157,14 +166,13 @@ handle_transfer_finished (void *cls,
long response_code, long response_code,
const void *response) const void *response)
{ {
struct TALER_BANK_WireExecuteHandle *weh = cls; struct TALER_BANK_TransferHandle *th = cls;
uint64_t row_id = UINT64_MAX;
struct GNUNET_TIME_Absolute timestamp;
enum TALER_ErrorCode ec;
const json_t *j = response; const json_t *j = response;
uint64_t row_id = UINT64_MAX;
struct GNUNET_TIME_Absolute timestamp = GNUNET_TIME_UNIT_FOREVER_ABS;
enum TALER_ErrorCode ec;
weh->job = NULL; th->job = NULL;
timestamp = GNUNET_TIME_UNIT_FOREVER_ABS;
switch (response_code) switch (response_code)
{ {
case 0: case 0:
@ -198,19 +206,20 @@ handle_transfer_finished (void *cls,
(or API version conflict); just pass JSON reply to the application */ (or API version conflict); just pass JSON reply to the application */
ec = TALER_JSON_get_error_code (j); ec = TALER_JSON_get_error_code (j);
break; break;
case MHD_HTTP_FORBIDDEN:
/* Access denied */
ec = TALER_JSON_get_error_code (j);
break;
case MHD_HTTP_UNAUTHORIZED: case MHD_HTTP_UNAUTHORIZED:
/* Nothing really to verify, bank says one of the signatures is /* Nothing really to verify, bank says our credentials are
invalid; as we checked them, this should never happen, we invalid. We should pass the JSON reply to the application. */
should pass the JSON reply to the application */
ec = TALER_JSON_get_error_code (j); ec = TALER_JSON_get_error_code (j);
break; break;
case MHD_HTTP_NOT_FOUND: case MHD_HTTP_NOT_FOUND:
/* Nothing really to verify, this should never /* Nothing really to verify, endpoint wrong -- could be user unknown */
happen, we should pass the JSON reply to the application */ 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); ec = TALER_JSON_get_error_code (j);
break; break;
case MHD_HTTP_INTERNAL_SERVER_ERROR: case MHD_HTTP_INTERNAL_SERVER_ERROR:
@ -228,12 +237,12 @@ handle_transfer_finished (void *cls,
response_code = 0; response_code = 0;
break; break;
} }
weh->cb (weh->cb_cls, th->cb (th->cb_cls,
response_code, response_code,
ec, ec,
row_id, row_id,
timestamp); timestamp);
TALER_BANK_execute_wire_transfer_cancel (weh); TALER_BANK_transfer_cancel (th);
} }
@ -248,16 +257,16 @@ handle_transfer_finished (void *cls,
* @param cc_cls closure for @a cc * @param cc_cls closure for @a cc
* @return NULL on error * @return NULL on error
*/ */
struct TALER_BANK_WireExecuteHandle * struct TALER_BANK_TransferHandle *
TALER_BANK_execute_wire_transfer (struct GNUNET_CURL_Context *ctx, TALER_BANK_transfer (struct GNUNET_CURL_Context *ctx,
const struct const struct
TALER_BANK_AuthenticationData *auth, TALER_BANK_AuthenticationData *auth,
const void *buf, const void *buf,
size_t buf_size, size_t buf_size,
TALER_BANK_ConfirmationCallback cc, TALER_BANK_TransferCallback cc,
void *cc_cls) void *cc_cls)
{ {
struct TALER_BANK_WireExecuteHandle *weh; struct TALER_BANK_TransferHandle *th;
json_t *transfer_obj; json_t *transfer_obj;
CURL *eh; CURL *eh;
const struct WirePackP *wp = buf; const struct WirePackP *wp = buf;
@ -281,6 +290,12 @@ TALER_BANK_execute_wire_transfer (struct GNUNET_CURL_Context *ctx,
} }
destination_account_uri = (const char *) &wp[1]; destination_account_uri = (const char *) &wp[1];
exchange_base_url = destination_account_uri + d_len; exchange_base_url = destination_account_uri + d_len;
if ( ('\0' != destination_account_uri[d_len - 1]) ||
('\0' != exchange_base_url[u_len - 1]) )
{
GNUNET_break (0);
return NULL;
}
if (NULL == auth->wire_gateway_url) if (NULL == auth->wire_gateway_url)
{ {
GNUNET_break (0); GNUNET_break (0);
@ -288,15 +303,15 @@ TALER_BANK_execute_wire_transfer (struct GNUNET_CURL_Context *ctx,
} }
TALER_amount_ntoh (&amount, TALER_amount_ntoh (&amount,
&wp->amount); &wp->amount);
weh = GNUNET_new (struct TALER_BANK_WireExecuteHandle); th = GNUNET_new (struct TALER_BANK_TransferHandle);
weh->cb = cc; th->cb = cc;
weh->cb_cls = cc_cls; th->cb_cls = cc_cls;
weh->request_url = TALER_url_join (auth->wire_gateway_url, th->request_url = TALER_url_join (auth->wire_gateway_url,
"transfer", "transfer",
NULL); NULL);
if (NULL == weh->request_url) if (NULL == th->request_url)
{ {
GNUNET_free (weh); GNUNET_free (th);
GNUNET_break (0); GNUNET_break (0);
return NULL; return NULL;
} }
@ -312,58 +327,65 @@ TALER_BANK_execute_wire_transfer (struct GNUNET_CURL_Context *ctx,
GNUNET_break (0); GNUNET_break (0);
return NULL; return NULL;
} }
weh->post_ctx.headers = curl_slist_append
(weh->post_ctx.headers,
"Content-Type: application/json");
eh = curl_easy_init (); eh = curl_easy_init ();
if ( (GNUNET_OK != if ( (NULL == eh) ||
(GNUNET_OK !=
TALER_BANK_setup_auth_ (eh, TALER_BANK_setup_auth_ (eh,
auth)) || auth)) ||
(CURLE_OK != (CURLE_OK !=
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_URL, CURLOPT_URL,
weh->request_url)) || th->request_url)) ||
(GNUNET_OK != (GNUNET_OK !=
TALER_curl_easy_post (&weh->post_ctx, TALER_curl_easy_post (&th->post_ctx,
eh, eh,
transfer_obj)) ) transfer_obj)) )
{ {
GNUNET_break (0); GNUNET_break (0);
TALER_BANK_execute_wire_transfer_cancel (weh); TALER_BANK_transfer_cancel (th);
if (NULL != eh)
curl_easy_cleanup (eh); curl_easy_cleanup (eh);
json_decref (transfer_obj); json_decref (transfer_obj);
return NULL; return NULL;
} }
json_decref (transfer_obj); json_decref (transfer_obj);
weh->job = GNUNET_CURL_job_add2 (ctx, th->job = GNUNET_CURL_job_add2 (ctx,
eh, eh,
weh->post_ctx.headers, th->post_ctx.headers,
&handle_transfer_finished, &handle_transfer_finished,
weh); th);
return weh; return th;
} }
/** /**
* Cancel a wire transfer. This function cannot be used on a request handle * Abort execution of a wire transfer. For example, because we are shutting
* if a response is already served for it. * down. Note that if an execution is aborted, it may or may not still
* succeed.
* *
* @param weh the wire transfer request handle * The caller MUST run #TALER_BANK_transfer() again for the same request as
* soon as possilbe, to ensure that the request either ultimately succeeds or
* ultimately fails. Until this has been done, the transaction is in limbo
* (i.e. may or may not have been committed).
*
* This function cannot be used on a request handle if a response is already
* served for it.
*
* @param th the wire transfer request handle
*/ */
void void
TALER_BANK_execute_wire_transfer_cancel (struct TALER_BANK_transfer_cancel (struct
TALER_BANK_WireExecuteHandle *weh) TALER_BANK_TransferHandle *th)
{ {
if (NULL != weh->job) if (NULL != th->job)
{ {
GNUNET_CURL_job_cancel (weh->job); GNUNET_CURL_job_cancel (th->job);
weh->job = NULL; th->job = NULL;
} }
TALER_curl_easy_post_finished (&weh->post_ctx); TALER_curl_easy_post_finished (&th->post_ctx);
GNUNET_free (weh->request_url); GNUNET_free (th->request_url);
GNUNET_free (weh); GNUNET_free (th);
} }

View File

@ -70,7 +70,7 @@ static char *destination_account_url;
/** /**
* Handle for executing the wire transfer. * Handle for executing the wire transfer.
*/ */
static struct TALER_BANK_WireExecuteHandle *eh; static struct TALER_BANK_TransferHandle *eh;
/** /**
* Handle to ongoing history operation. * Handle to ongoing history operation.
@ -189,13 +189,13 @@ execute_wire_transfer ()
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
&wtid, &wtid,
sizeof (wtid)); sizeof (wtid));
TALER_BANK_prepare_wire_transfer (destination_account_url, TALER_BANK_prepare_transfer (destination_account_url,
&amount, &amount,
"http://exchange.example.com/", "http://exchange.example.com/",
&wtid, &wtid,
&buf, &buf,
&buf_size); &buf_size);
eh = TALER_BANK_execute_wire_transfer (ctx, eh = TALER_BANK_transfer (ctx,
&auth, &auth,
buf, buf,
buf_size, buf_size,
@ -260,7 +260,7 @@ do_shutdown (void *cls)
} }
if (NULL != eh) if (NULL != eh)
{ {
TALER_BANK_execute_wire_transfer_cancel (eh); TALER_BANK_transfer_cancel (eh);
eh = NULL; eh = NULL;
} }
TALER_BANK_auth_free (&auth); TALER_BANK_auth_free (&auth);

View File

@ -82,7 +82,7 @@ struct WirePrepareData
/** /**
* Wire execution handle. * Wire execution handle.
*/ */
struct TALER_BANK_WireExecuteHandle *eh; struct TALER_BANK_TransferHandle *eh;
/** /**
* Wire account used for this preparation. * Wire account used for this preparation.
@ -565,7 +565,7 @@ shutdown_task (void *cls)
{ {
if (NULL != wpd->eh) if (NULL != wpd->eh)
{ {
TALER_BANK_execute_wire_transfer_cancel (wpd->eh); TALER_BANK_transfer_cancel (wpd->eh);
wpd->eh = NULL; wpd->eh = NULL;
} }
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls,
@ -1211,7 +1211,7 @@ expired_reserve_cb (void *cls,
ctc->wa = wa; ctc->wa = wa;
ctc->session = session; ctc->session = session;
ctc->method = TALER_payto_get_method (account_payto_uri); ctc->method = TALER_payto_get_method (account_payto_uri);
TALER_BANK_prepare_wire_transfer (account_payto_uri, TALER_BANK_prepare_transfer (account_payto_uri,
&amount_without_fee, &amount_without_fee,
exchange_base_url, exchange_base_url,
&wtid, &wtid,
@ -1581,7 +1581,7 @@ run_aggregation (void *cls)
char *url; char *url;
url = TALER_JSON_wire_to_payto (au->wire); url = TALER_JSON_wire_to_payto (au->wire);
TALER_BANK_prepare_wire_transfer (url, TALER_BANK_prepare_transfer (url,
&au->final_amount, &au->final_amount,
exchange_base_url, exchange_base_url,
&au->wtid, &au->wtid,
@ -1804,7 +1804,7 @@ wire_prepare_cb (void *cls,
return; return;
} }
wa = wpd->wa; wa = wpd->wa;
wpd->eh = TALER_BANK_execute_wire_transfer (ctx, wpd->eh = TALER_BANK_transfer (ctx,
&wa->auth, &wa->auth,
buf, buf,
buf_size, buf_size,

View File

@ -174,7 +174,7 @@ TALER_BANK_admin_add_incoming_cancel (struct
* @param[out] buf_size set to number of bytes in @a buf, 0 on error * @param[out] buf_size set to number of bytes in @a buf, 0 on error
*/ */
void void
TALER_BANK_prepare_wire_transfer (const char *destination_account_payto_uri, TALER_BANK_prepare_transfer (const char *destination_account_payto_uri,
const struct TALER_Amount *amount, const struct TALER_Amount *amount,
const char *exchange_base_url, const char *exchange_base_url,
const struct const struct
@ -186,7 +186,7 @@ TALER_BANK_prepare_wire_transfer (const char *destination_account_payto_uri,
/** /**
* Handle for active wire transfer. * Handle for active wire transfer.
*/ */
struct TALER_BANK_WireExecuteHandle; struct TALER_BANK_TransferHandle;
/** /**
@ -199,7 +199,7 @@ struct TALER_BANK_WireExecuteHandle;
* @param timestamp when did the transaction go into effect * @param timestamp when did the transaction go into effect
*/ */
typedef void typedef void
(*TALER_BANK_ConfirmationCallback)(void *cls, (*TALER_BANK_TransferCallback)(void *cls,
unsigned int response_code, unsigned int response_code,
enum TALER_ErrorCode ec, enum TALER_ErrorCode ec,
uint64_t row_id, uint64_t row_id,
@ -217,30 +217,32 @@ typedef void
* @param cc_cls closure for @a cc * @param cc_cls closure for @a cc
* @return NULL on error * @return NULL on error
*/ */
struct TALER_BANK_WireExecuteHandle * struct TALER_BANK_TransferHandle *
TALER_BANK_execute_wire_transfer (struct GNUNET_CURL_Context *ctx, TALER_BANK_transfer (struct GNUNET_CURL_Context *ctx,
const struct const struct TALER_BANK_AuthenticationData *auth,
TALER_BANK_AuthenticationData *auth,
const void *buf, const void *buf,
size_t buf_size, size_t buf_size,
TALER_BANK_ConfirmationCallback cc, TALER_BANK_TransferCallback cc,
void *cc_cls); void *cc_cls);
/** /**
* Abort execution of a wire transfer. For example, because we are * Abort execution of a wire transfer. For example, because we are shutting
* shutting down. Note that if an execution is aborted, it may or * down. Note that if an execution is aborted, it may or may not still
* may not still succeed. The caller MUST run @e * succeed.
* execute_wire_transfer again for the same request as soon as
* possilbe, to ensure that the request either ultimately succeeds
* or ultimately fails. Until this has been done, the transaction is
* in limbo (i.e. may or may not have been committed).
* *
* @param weh execution to cancel * The caller MUST run #TALER_BANK_transfer() again for the same request as
* soon as possilbe, to ensure that the request either ultimately succeeds or
* ultimately fails. Until this has been done, the transaction is in limbo
* (i.e. may or may not have been committed).
*
* This function cannot be used on a request handle if a response is already
* served for it.
*
* @param th handle of the wire transfer request to cancel
*/ */
void void
TALER_BANK_execute_wire_transfer_cancel (struct TALER_BANK_transfer_cancel (struct TALER_BANK_TransferHandle *th);
TALER_BANK_WireExecuteHandle *weh);
/* ********************* /history/incoming *********************** */ /* ********************* /history/incoming *********************** */

View File

@ -19,7 +19,6 @@
* @brief curl easy handle defaults * @brief curl easy handle defaults
* @author Florian Dold * @author Florian Dold
*/ */
#include "auditor_api_curl_defaults.h" #include "auditor_api_curl_defaults.h"
@ -30,7 +29,7 @@
* @param url URL to query * @param url URL to query
*/ */
CURL * CURL *
TAL_curl_easy_get (const char *url) TALER_AUDITOR_curl_easy_get_ (const char *url)
{ {
CURL *eh; CURL *eh;
struct GNUNET_AsyncScopeSave scope; struct GNUNET_AsyncScopeSave scope;
@ -38,15 +37,25 @@ TAL_curl_easy_get (const char *url)
GNUNET_async_scope_get (&scope); GNUNET_async_scope_get (&scope);
eh = curl_easy_init (); eh = curl_easy_init ();
if (NULL == eh)
return NULL;
GNUNET_assert (CURLE_OK == GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_URL, CURLOPT_URL,
url)); url));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_FOLLOWLOCATION,
1L));
/* limit MAXREDIRS to 5 as a simple security measure against
a potential infinite loop caused by a malicious target */
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_MAXREDIRS,
5L));
GNUNET_assert (CURLE_OK == GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_TCP_FASTOPEN, CURLOPT_TCP_FASTOPEN,
1L)); 1L));
return eh; return eh;
} }

View File

@ -14,17 +14,14 @@
TALER; see the file COPYING. If not, see TALER; see the file COPYING. If not, see
<http://www.gnu.org/licenses/> <http://www.gnu.org/licenses/>
*/ */
/** /**
* @file lib/auditor_api_curl_defaults.h * @file lib/auditor_api_curl_defaults.h
* @brief curl easy handle defaults * @brief curl easy handle defaults
* @author Florian Dold * @author Florian Dold
*/ */
#ifndef _TALER_CURL_DEFAULTS_H #ifndef _TALER_CURL_DEFAULTS_H
#define _TALER_CURL_DEFAULTS_H #define _TALER_CURL_DEFAULTS_H
#include "platform.h" #include "platform.h"
#include <gnunet/gnunet_curl_lib.h> #include <gnunet/gnunet_curl_lib.h>
@ -36,6 +33,6 @@
* @param url URL to query * @param url URL to query
*/ */
CURL * CURL *
TAL_curl_easy_get (const char *url); TALER_AUDITOR_curl_easy_get_ (const char *url);
#endif /* _TALER_CURL_DEFAULTS_H */ #endif /* _TALER_CURL_DEFAULTS_H */

View File

@ -290,7 +290,7 @@ TALER_AUDITOR_deposit_confirmation (struct TALER_AUDITOR_Handle *auditor,
(void) GNUNET_TIME_round_abs (&ep_expire); (void) GNUNET_TIME_round_abs (&ep_expire);
(void) GNUNET_TIME_round_abs (&ep_end); (void) GNUNET_TIME_round_abs (&ep_end);
GNUNET_assert (GNUNET_YES == GNUNET_assert (GNUNET_YES ==
MAH_handle_is_ready (auditor)); TALER_AUDITOR_handle_is_ready_ (auditor));
if (GNUNET_OK != if (GNUNET_OK !=
verify_signatures (h_wire, verify_signatures (h_wire,
h_contract_terms, h_contract_terms,
@ -346,19 +346,22 @@ TALER_AUDITOR_deposit_confirmation (struct TALER_AUDITOR_Handle *auditor,
dh->auditor = auditor; dh->auditor = auditor;
dh->cb = cb; dh->cb = cb;
dh->cb_cls = cb_cls; dh->cb_cls = cb_cls;
dh->url = MAH_path_to_url (auditor, "/deposit-confirmation"); dh->url = TALER_AUDITOR_path_to_url_ (auditor,
"/deposit-confirmation");
eh = TALER_AUDITOR_curl_easy_get_ (dh->url);
eh = TAL_curl_easy_get (dh->url); if ( (NULL == eh) ||
GNUNET_assert (CURLE_OK == (CURLE_OK !=
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_CUSTOMREQUEST, CURLOPT_CUSTOMREQUEST,
"PUT")); "PUT")) ||
if (GNUNET_OK != (GNUNET_OK !=
TALER_curl_easy_post (&dh->ctx, TALER_curl_easy_post (&dh->ctx,
eh, eh,
deposit_confirmation_obj)) deposit_confirmation_obj)) )
{ {
GNUNET_break (0); GNUNET_break (0);
if (NULL != eh)
curl_easy_cleanup (eh); curl_easy_cleanup (eh);
json_decref (deposit_confirmation_obj); json_decref (deposit_confirmation_obj);
GNUNET_free (dh->url); GNUNET_free (dh->url);
@ -369,7 +372,7 @@ TALER_AUDITOR_deposit_confirmation (struct TALER_AUDITOR_Handle *auditor,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"URL for deposit-confirmation: `%s'\n", "URL for deposit-confirmation: `%s'\n",
dh->url); dh->url);
ctx = MAH_handle_to_context (auditor); ctx = TALER_AUDITOR_handle_to_context_ (auditor);
dh->job = GNUNET_CURL_job_add2 (ctx, dh->job = GNUNET_CURL_job_add2 (ctx,
eh, eh,
dh->ctx.headers, dh->ctx.headers,

View File

@ -201,19 +201,26 @@ TALER_AUDITOR_list_exchanges (struct TALER_AUDITOR_Handle *auditor,
CURL *eh; CURL *eh;
GNUNET_assert (GNUNET_YES == GNUNET_assert (GNUNET_YES ==
MAH_handle_is_ready (auditor)); TALER_AUDITOR_handle_is_ready_ (auditor));
leh = GNUNET_new (struct TALER_AUDITOR_ListExchangesHandle); leh = GNUNET_new (struct TALER_AUDITOR_ListExchangesHandle);
leh->auditor = auditor; leh->auditor = auditor;
leh->cb = cb; leh->cb = cb;
leh->cb_cls = cb_cls; leh->cb_cls = cb_cls;
leh->url = MAH_path_to_url (auditor, "/exchanges"); leh->url = TALER_AUDITOR_path_to_url_ (auditor, "/exchanges");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"URL for list-exchanges: `%s'\n", "URL for list-exchanges: `%s'\n",
leh->url); leh->url);
eh = TAL_curl_easy_get (leh->url); eh = TALER_AUDITOR_curl_easy_get_ (leh->url);
ctx = MAH_handle_to_context (auditor); if (NULL == eh)
{
GNUNET_break (0);
GNUNET_free (leh->url);
GNUNET_free (leh);
return NULL;
}
ctx = TALER_AUDITOR_handle_to_context_ (auditor);
leh->job = GNUNET_CURL_job_add (ctx, leh->job = GNUNET_CURL_job_add (ctx,
eh, eh,
GNUNET_NO, GNUNET_NO,

View File

@ -367,7 +367,7 @@ version_completed_cb (void *cls,
* @return ctx context to execute jobs in * @return ctx context to execute jobs in
*/ */
struct GNUNET_CURL_Context * struct GNUNET_CURL_Context *
MAH_handle_to_context (struct TALER_AUDITOR_Handle *h) TALER_AUDITOR_handle_to_context_ (struct TALER_AUDITOR_Handle *h)
{ {
return h->ctx; return h->ctx;
} }
@ -380,7 +380,7 @@ MAH_handle_to_context (struct TALER_AUDITOR_Handle *h)
* @return #GNUNET_YES if we are ready, #GNUNET_NO if not * @return #GNUNET_YES if we are ready, #GNUNET_NO if not
*/ */
int int
MAH_handle_is_ready (struct TALER_AUDITOR_Handle *h) TALER_AUDITOR_handle_is_ready_ (struct TALER_AUDITOR_Handle *h)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Checking if auditor %p (%s) is now ready: %s\n", "Checking if auditor %p (%s) is now ready: %s\n",
@ -399,7 +399,7 @@ MAH_handle_is_ready (struct TALER_AUDITOR_Handle *h)
* @return the full URL to use with cURL * @return the full URL to use with cURL
*/ */
char * char *
MAH_path_to_url (struct TALER_AUDITOR_Handle *h, TALER_AUDITOR_path_to_url_ (struct TALER_AUDITOR_Handle *h,
const char *path) const char *path)
{ {
char *ret; char *ret;
@ -473,13 +473,22 @@ request_version (void *cls)
GNUNET_assert (NULL == auditor->vr); GNUNET_assert (NULL == auditor->vr);
vr = GNUNET_new (struct VersionRequest); vr = GNUNET_new (struct VersionRequest);
vr->auditor = auditor; vr->auditor = auditor;
vr->url = MAH_path_to_url (auditor, vr->url = TALER_AUDITOR_path_to_url_ (auditor,
"/version"); "/version");
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Requesting auditor version with URL `%s'.\n", "Requesting auditor version with URL `%s'.\n",
vr->url); vr->url);
eh = TAL_curl_easy_get (vr->url); eh = TALER_AUDITOR_curl_easy_get_ (vr->url);
GNUNET_assert (CURLE_OK == if (NULL == eh)
{
GNUNET_break (0);
auditor->retry_delay = EXCHANGE_LIB_BACKOFF (auditor->retry_delay);
auditor->retry_task = GNUNET_SCHEDULER_add_delayed (auditor->retry_delay,
&request_version,
auditor);
return;
}
GNUNET_break (CURLE_OK ==
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_TIMEOUT, CURLOPT_TIMEOUT,
(long) 300)); (long) 300));

View File

@ -31,7 +31,7 @@
* @return ctx context to execute jobs in * @return ctx context to execute jobs in
*/ */
struct GNUNET_CURL_Context * struct GNUNET_CURL_Context *
MAH_handle_to_context (struct TALER_AUDITOR_Handle *h); TALER_AUDITOR_handle_to_context_ (struct TALER_AUDITOR_Handle *h);
/** /**
@ -41,7 +41,7 @@ MAH_handle_to_context (struct TALER_AUDITOR_Handle *h);
* @return #GNUNET_YES if we are ready, #GNUNET_NO if not * @return #GNUNET_YES if we are ready, #GNUNET_NO if not
*/ */
int int
MAH_handle_is_ready (struct TALER_AUDITOR_Handle *h); TALER_AUDITOR_handle_is_ready_ (struct TALER_AUDITOR_Handle *h);
/** /**
@ -52,7 +52,7 @@ MAH_handle_is_ready (struct TALER_AUDITOR_Handle *h);
* @return the full URL to use with cURL * @return the full URL to use with cURL
*/ */
char * char *
MAH_path_to_url (struct TALER_AUDITOR_Handle *h, TALER_AUDITOR_path_to_url_ (struct TALER_AUDITOR_Handle *h,
const char *path); const char *path);

View File

@ -24,8 +24,8 @@
/** /**
* Get a curl handle with the right defaults * Get a curl handle with the right defaults for the exchange lib. In the
* for the exchange lib. In the future, we might manage a pool of connections here. * future, we might manage a pool of connections here.
* *
* @param url URL to query * @param url URL to query
*/ */
@ -35,6 +35,8 @@ TALER_EXCHANGE_curl_easy_get_ (const char *url)
CURL *eh; CURL *eh;
eh = curl_easy_init (); eh = curl_easy_init ();
if (NULL == eh)
return NULL;
GNUNET_assert (CURLE_OK == GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_URL, CURLOPT_URL,

View File

@ -627,12 +627,14 @@ TALER_EXCHANGE_deposit (struct TALER_EXCHANGE_Handle *exchange,
not copy the pointer */ not copy the pointer */
eh = TALER_EXCHANGE_curl_easy_get_ (dh->url); eh = TALER_EXCHANGE_curl_easy_get_ (dh->url);
if (GNUNET_OK != if ( (NULL == eh) ||
(GNUNET_OK !=
TALER_curl_easy_post (&dh->ctx, TALER_curl_easy_post (&dh->ctx,
eh, eh,
deposit_obj)) deposit_obj)) )
{ {
GNUNET_break (0); GNUNET_break (0);
if (NULL != eh)
curl_easy_cleanup (eh); curl_easy_cleanup (eh);
json_decref (deposit_obj); json_decref (deposit_obj);
GNUNET_free (dh->url); GNUNET_free (dh->url);

View File

@ -367,6 +367,13 @@ TALER_EXCHANGE_deposits_get (struct TALER_EXCHANGE_Handle *exchange,
dwh->depconf.coin_pub = *coin_pub; dwh->depconf.coin_pub = *coin_pub;
eh = TALER_EXCHANGE_curl_easy_get_ (dwh->url); eh = TALER_EXCHANGE_curl_easy_get_ (dwh->url);
if (NULL == eh)
{
GNUNET_break (0);
GNUNET_free (dwh->url);
GNUNET_free (dwh);
return NULL;
}
ctx = TEAH_handle_to_context (exchange); ctx = TEAH_handle_to_context (exchange);
dwh->job = GNUNET_CURL_job_add (ctx, dwh->job = GNUNET_CURL_job_add (ctx,
eh, eh,

View File

@ -1954,11 +1954,19 @@ request_keys (void *cls)
"Requesting keys with URL `%s'.\n", "Requesting keys with URL `%s'.\n",
kr->url); kr->url);
eh = TALER_EXCHANGE_curl_easy_get_ (kr->url); eh = TALER_EXCHANGE_curl_easy_get_ (kr->url);
GNUNET_assert (CURLE_OK == if (NULL == eh)
{
exchange->retry_delay = EXCHANGE_LIB_BACKOFF (exchange->retry_delay);
exchange->retry_task = GNUNET_SCHEDULER_add_delayed (exchange->retry_delay,
&request_keys,
exchange);
return;
}
GNUNET_break (CURLE_OK ==
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_VERBOSE, CURLOPT_VERBOSE,
0)); 0));
GNUNET_assert (CURLE_OK == GNUNET_break (CURLE_OK ==
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_TIMEOUT, CURLOPT_TIMEOUT,
(long) 300)); (long) 300));

View File

@ -456,6 +456,13 @@ TALER_EXCHANGE_link (struct TALER_EXCHANGE_Handle *exchange,
lh->url = TEAH_path_to_url (exchange, lh->url = TEAH_path_to_url (exchange,
arg_str); arg_str);
eh = TALER_EXCHANGE_curl_easy_get_ (lh->url); eh = TALER_EXCHANGE_curl_easy_get_ (lh->url);
if (NULL == eh)
{
GNUNET_break (0);
GNUNET_free (lh->url);
GNUNET_free (lh);
return NULL;
}
ctx = TEAH_handle_to_context (exchange); ctx = TEAH_handle_to_context (exchange);
lh->job = GNUNET_CURL_job_add (ctx, lh->job = GNUNET_CURL_job_add (ctx,
eh, eh,

View File

@ -457,12 +457,14 @@ TALER_EXCHANGE_melt (struct TALER_EXCHANGE_Handle *exchange,
mh->url = TEAH_path_to_url (exchange, mh->url = TEAH_path_to_url (exchange,
arg_str); arg_str);
eh = TALER_EXCHANGE_curl_easy_get_ (mh->url); eh = TALER_EXCHANGE_curl_easy_get_ (mh->url);
if (GNUNET_OK != if ( (NULL == eh) ||
(GNUNET_OK !=
TALER_curl_easy_post (&mh->ctx, TALER_curl_easy_post (&mh->ctx,
eh, eh,
melt_obj)) melt_obj)) )
{ {
GNUNET_break (0); GNUNET_break (0);
if (NULL != eh)
curl_easy_cleanup (eh); curl_easy_cleanup (eh);
json_decref (melt_obj); json_decref (melt_obj);
GNUNET_free (mh->url); GNUNET_free (mh->url);

View File

@ -390,12 +390,14 @@ TALER_EXCHANGE_recoup (struct TALER_EXCHANGE_Handle *exchange,
arg_str); arg_str);
ph->was_refreshed = was_refreshed; ph->was_refreshed = was_refreshed;
eh = TALER_EXCHANGE_curl_easy_get_ (ph->url); eh = TALER_EXCHANGE_curl_easy_get_ (ph->url);
if (GNUNET_OK != if ( (NULL == eh) ||
(GNUNET_OK !=
TALER_curl_easy_post (&ph->ctx, TALER_curl_easy_post (&ph->ctx,
eh, eh,
recoup_obj)) recoup_obj)) )
{ {
GNUNET_break (0); GNUNET_break (0);
if (NULL != eh)
curl_easy_cleanup (eh); curl_easy_cleanup (eh);
json_decref (recoup_obj); json_decref (recoup_obj);
GNUNET_free (ph->url); GNUNET_free (ph->url);

View File

@ -462,12 +462,14 @@ TALER_EXCHANGE_refreshes_reveal (struct TALER_EXCHANGE_Handle *exchange,
arg_str); arg_str);
eh = TALER_EXCHANGE_curl_easy_get_ (rrh->url); eh = TALER_EXCHANGE_curl_easy_get_ (rrh->url);
if (GNUNET_OK != if ( (NULL == eh) ||
(GNUNET_OK !=
TALER_curl_easy_post (&rrh->ctx, TALER_curl_easy_post (&rrh->ctx,
eh, eh,
reveal_obj)) reveal_obj)) )
{ {
GNUNET_break (0); GNUNET_break (0);
if (NULL != eh)
curl_easy_cleanup (eh); curl_easy_cleanup (eh);
json_decref (reveal_obj); json_decref (reveal_obj);
GNUNET_free (rrh->url); GNUNET_free (rrh->url);

View File

@ -388,12 +388,14 @@ TALER_EXCHANGE_refund2 (struct TALER_EXCHANGE_Handle *exchange,
refund_fee); refund_fee);
eh = TALER_EXCHANGE_curl_easy_get_ (rh->url); eh = TALER_EXCHANGE_curl_easy_get_ (rh->url);
if (GNUNET_OK != if ( (NULL == eh) ||
(GNUNET_OK !=
TALER_curl_easy_post (&rh->ctx, TALER_curl_easy_post (&rh->ctx,
eh, eh,
refund_obj)) refund_obj)) )
{ {
GNUNET_break (0); GNUNET_break (0);
if (NULL != eh)
curl_easy_cleanup (eh); curl_easy_cleanup (eh);
json_decref (refund_obj); json_decref (refund_obj);
GNUNET_free (rh->url); GNUNET_free (rh->url);

View File

@ -275,6 +275,13 @@ TALER_EXCHANGE_reserves_get (struct TALER_EXCHANGE_Handle *exchange,
rgh->url = TEAH_path_to_url (exchange, rgh->url = TEAH_path_to_url (exchange,
arg_str); arg_str);
eh = TALER_EXCHANGE_curl_easy_get_ (rgh->url); eh = TALER_EXCHANGE_curl_easy_get_ (rgh->url);
if (NULL == eh)
{
GNUNET_break (0);
GNUNET_free (rgh->url);
GNUNET_free (rgh);
return NULL;
}
ctx = TEAH_handle_to_context (exchange); ctx = TEAH_handle_to_context (exchange);
rgh->job = GNUNET_CURL_job_add (ctx, rgh->job = GNUNET_CURL_job_add (ctx,
eh, eh,

View File

@ -367,6 +367,13 @@ TALER_EXCHANGE_transfers_get (struct TALER_EXCHANGE_Handle *exchange,
wdh->url = TEAH_path_to_url (wdh->exchange, wdh->url = TEAH_path_to_url (wdh->exchange,
arg_str); arg_str);
eh = TALER_EXCHANGE_curl_easy_get_ (wdh->url); eh = TALER_EXCHANGE_curl_easy_get_ (wdh->url);
if (NULL == eh)
{
GNUNET_break (0);
GNUNET_free (wdh->url);
GNUNET_free (wdh);
return NULL;
}
ctx = TEAH_handle_to_context (exchange); ctx = TEAH_handle_to_context (exchange);
wdh->job = GNUNET_CURL_job_add (ctx, wdh->job = GNUNET_CURL_job_add (ctx,
eh, eh,

View File

@ -405,9 +405,16 @@ TALER_EXCHANGE_wire (struct TALER_EXCHANGE_Handle *exchange,
wh->exchange = exchange; wh->exchange = exchange;
wh->cb = wire_cb; wh->cb = wire_cb;
wh->cb_cls = wire_cb_cls; wh->cb_cls = wire_cb_cls;
wh->url = TEAH_path_to_url (exchange, "/wire"); wh->url = TEAH_path_to_url (exchange,
"/wire");
eh = TALER_EXCHANGE_curl_easy_get_ (wh->url); eh = TALER_EXCHANGE_curl_easy_get_ (wh->url);
if (NULL == eh)
{
GNUNET_break (0);
GNUNET_free (wh->url);
GNUNET_free (wh);
return NULL;
}
ctx = TEAH_handle_to_context (exchange); ctx = TEAH_handle_to_context (exchange);
wh->job = GNUNET_CURL_job_add (ctx, wh->job = GNUNET_CURL_job_add (ctx,
eh, eh,

View File

@ -427,12 +427,14 @@ reserve_withdraw_internal (struct TALER_EXCHANGE_Handle *exchange,
wh->url = TEAH_path_to_url (exchange, wh->url = TEAH_path_to_url (exchange,
arg_str); arg_str);
eh = TALER_EXCHANGE_curl_easy_get_ (wh->url); eh = TALER_EXCHANGE_curl_easy_get_ (wh->url);
if (GNUNET_OK != if ( (NULL == eh) ||
(GNUNET_OK !=
TALER_curl_easy_post (&wh->ctx, TALER_curl_easy_post (&wh->ctx,
eh, eh,
withdraw_obj)) withdraw_obj)) )
{ {
GNUNET_break (0); GNUNET_break (0);
if (NULL != eh)
curl_easy_cleanup (eh); curl_easy_cleanup (eh);
json_decref (withdraw_obj); json_decref (withdraw_obj);
GNUNET_free (wh->url); GNUNET_free (wh->url);

View File

@ -76,7 +76,7 @@ struct TransferState
/** /**
* Handle to the pending request at the fakebank. * Handle to the pending request at the fakebank.
*/ */
struct TALER_BANK_WireExecuteHandle *weh; struct TALER_BANK_TransferHandle *weh;
/** /**
* Interpreter state. * Interpreter state.
@ -233,7 +233,7 @@ transfer_run (void *cls,
TALER_amount2s (&fts->amount), TALER_amount2s (&fts->amount),
fts->account_debit_url, fts->account_debit_url,
fts->payto_credit_account); fts->payto_credit_account);
TALER_BANK_prepare_wire_transfer (fts->payto_credit_account, TALER_BANK_prepare_transfer (fts->payto_credit_account,
&fts->amount, &fts->amount,
fts->exchange_base_url, fts->exchange_base_url,
&fts->wtid, &fts->wtid,
@ -241,7 +241,7 @@ transfer_run (void *cls,
&buf_size); &buf_size);
fts->is = is; fts->is = is;
fts->weh fts->weh
= TALER_BANK_execute_wire_transfer = TALER_BANK_transfer
(TALER_TESTING_interpreter_get_context (is), (TALER_TESTING_interpreter_get_context (is),
&fts->auth, &fts->auth,
buf, buf,
@ -276,7 +276,7 @@ transfer_cleanup (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Command %s did not complete\n", "Command %s did not complete\n",
cmd->label); cmd->label);
TALER_BANK_execute_wire_transfer_cancel (fts->weh); TALER_BANK_transfer_cancel (fts->weh);
fts->weh = NULL; fts->weh = NULL;
} }
if (NULL != fts->retry_task) if (NULL != fts->retry_task)