rename BANK_excecute_wire_transfer to BANK_transfer, improve error handling when curl_easy_init() fails
This commit is contained in:
parent
97fb6b0091
commit
a9b3c564bd
@ -218,7 +218,8 @@ TALER_BANK_admin_add_incoming (struct GNUNET_CURL_Context *ctx,
|
||||
"Content-Type: application/json");
|
||||
|
||||
eh = curl_easy_init ();
|
||||
if ( (GNUNET_OK !=
|
||||
if ( (NULL == eh) ||
|
||||
(GNUNET_OK !=
|
||||
TALER_BANK_setup_auth_ (eh,
|
||||
auth)) ||
|
||||
(CURLE_OK !=
|
||||
@ -232,6 +233,7 @@ TALER_BANK_admin_add_incoming (struct GNUNET_CURL_Context *ctx,
|
||||
{
|
||||
GNUNET_break (0);
|
||||
TALER_BANK_admin_add_incoming_cancel (aai);
|
||||
if (NULL != eh)
|
||||
curl_easy_cleanup (eh);
|
||||
json_decref (admin_obj);
|
||||
return NULL;
|
||||
|
@ -276,7 +276,8 @@ TALER_BANK_credit_history (struct GNUNET_CURL_Context *ctx,
|
||||
"Requesting credit history at `%s'\n",
|
||||
hh->request_url);
|
||||
eh = curl_easy_init ();
|
||||
if ( (GNUNET_OK !=
|
||||
if ( (NULL == eh) ||
|
||||
(GNUNET_OK !=
|
||||
TALER_BANK_setup_auth_ (eh,
|
||||
auth)) ||
|
||||
(CURLE_OK !=
|
||||
@ -286,6 +287,7 @@ TALER_BANK_credit_history (struct GNUNET_CURL_Context *ctx,
|
||||
{
|
||||
GNUNET_break (0);
|
||||
TALER_BANK_credit_history_cancel (hh);
|
||||
if (NULL != eh)
|
||||
curl_easy_cleanup (eh);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -274,7 +274,8 @@ TALER_BANK_debit_history (struct GNUNET_CURL_Context *ctx,
|
||||
"Requesting history at `%s'\n",
|
||||
hh->request_url);
|
||||
eh = curl_easy_init ();
|
||||
if ( (GNUNET_OK !=
|
||||
if ( (NULL == eh) ||
|
||||
(GNUNET_OK !=
|
||||
TALER_BANK_setup_auth_ (eh,
|
||||
auth)) ||
|
||||
(CURLE_OK !=
|
||||
@ -284,6 +285,7 @@ TALER_BANK_debit_history (struct GNUNET_CURL_Context *ctx,
|
||||
{
|
||||
GNUNET_break (0);
|
||||
TALER_BANK_debit_history_cancel (hh);
|
||||
if (NULL != eh)
|
||||
curl_easy_cleanup (eh);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -66,7 +66,8 @@ struct WirePackP
|
||||
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 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
|
||||
*/
|
||||
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 char *exchange_base_url,
|
||||
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;
|
||||
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;
|
||||
wp = GNUNET_malloc (*buf_size);
|
||||
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.
|
||||
*/
|
||||
TALER_BANK_ConfirmationCallback cb;
|
||||
TALER_BANK_TransferCallback cb;
|
||||
|
||||
/**
|
||||
* Closure for @a cb.
|
||||
@ -148,7 +157,7 @@ struct TALER_BANK_WireExecuteHandle
|
||||
* Function called when we're done processing the
|
||||
* 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 parsed JSON result, NULL on error
|
||||
*/
|
||||
@ -157,14 +166,13 @@ handle_transfer_finished (void *cls,
|
||||
long response_code,
|
||||
const void *response)
|
||||
{
|
||||
struct TALER_BANK_WireExecuteHandle *weh = cls;
|
||||
uint64_t row_id = UINT64_MAX;
|
||||
struct GNUNET_TIME_Absolute timestamp;
|
||||
enum TALER_ErrorCode ec;
|
||||
struct TALER_BANK_TransferHandle *th = cls;
|
||||
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;
|
||||
timestamp = GNUNET_TIME_UNIT_FOREVER_ABS;
|
||||
th->job = NULL;
|
||||
switch (response_code)
|
||||
{
|
||||
case 0:
|
||||
@ -198,19 +206,20 @@ handle_transfer_finished (void *cls,
|
||||
(or API version conflict); just pass JSON reply to the application */
|
||||
ec = TALER_JSON_get_error_code (j);
|
||||
break;
|
||||
case MHD_HTTP_FORBIDDEN:
|
||||
/* Access denied */
|
||||
ec = TALER_JSON_get_error_code (j);
|
||||
break;
|
||||
case MHD_HTTP_UNAUTHORIZED:
|
||||
/* Nothing really to verify, bank says one of the signatures is
|
||||
invalid; as we checked them, this should never happen, we
|
||||
should pass the JSON reply to the application */
|
||||
/* 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);
|
||||
break;
|
||||
case MHD_HTTP_NOT_FOUND:
|
||||
/* Nothing really to verify, this should never
|
||||
happen, we should pass the JSON reply to the application */
|
||||
/* Nothing really to verify, endpoint wrong -- could be user unknown */
|
||||
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);
|
||||
break;
|
||||
case MHD_HTTP_INTERNAL_SERVER_ERROR:
|
||||
@ -228,12 +237,12 @@ handle_transfer_finished (void *cls,
|
||||
response_code = 0;
|
||||
break;
|
||||
}
|
||||
weh->cb (weh->cb_cls,
|
||||
th->cb (th->cb_cls,
|
||||
response_code,
|
||||
ec,
|
||||
row_id,
|
||||
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
|
||||
* @return NULL on error
|
||||
*/
|
||||
struct TALER_BANK_WireExecuteHandle *
|
||||
TALER_BANK_execute_wire_transfer (struct GNUNET_CURL_Context *ctx,
|
||||
struct TALER_BANK_TransferHandle *
|
||||
TALER_BANK_transfer (struct GNUNET_CURL_Context *ctx,
|
||||
const struct
|
||||
TALER_BANK_AuthenticationData *auth,
|
||||
const void *buf,
|
||||
size_t buf_size,
|
||||
TALER_BANK_ConfirmationCallback cc,
|
||||
TALER_BANK_TransferCallback cc,
|
||||
void *cc_cls)
|
||||
{
|
||||
struct TALER_BANK_WireExecuteHandle *weh;
|
||||
struct TALER_BANK_TransferHandle *th;
|
||||
json_t *transfer_obj;
|
||||
CURL *eh;
|
||||
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];
|
||||
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)
|
||||
{
|
||||
GNUNET_break (0);
|
||||
@ -288,15 +303,15 @@ TALER_BANK_execute_wire_transfer (struct GNUNET_CURL_Context *ctx,
|
||||
}
|
||||
TALER_amount_ntoh (&amount,
|
||||
&wp->amount);
|
||||
weh = GNUNET_new (struct TALER_BANK_WireExecuteHandle);
|
||||
weh->cb = cc;
|
||||
weh->cb_cls = cc_cls;
|
||||
weh->request_url = TALER_url_join (auth->wire_gateway_url,
|
||||
th = GNUNET_new (struct TALER_BANK_TransferHandle);
|
||||
th->cb = cc;
|
||||
th->cb_cls = cc_cls;
|
||||
th->request_url = TALER_url_join (auth->wire_gateway_url,
|
||||
"transfer",
|
||||
NULL);
|
||||
if (NULL == weh->request_url)
|
||||
if (NULL == th->request_url)
|
||||
{
|
||||
GNUNET_free (weh);
|
||||
GNUNET_free (th);
|
||||
GNUNET_break (0);
|
||||
return NULL;
|
||||
}
|
||||
@ -312,58 +327,65 @@ TALER_BANK_execute_wire_transfer (struct GNUNET_CURL_Context *ctx,
|
||||
GNUNET_break (0);
|
||||
return NULL;
|
||||
}
|
||||
weh->post_ctx.headers = curl_slist_append
|
||||
(weh->post_ctx.headers,
|
||||
"Content-Type: application/json");
|
||||
|
||||
eh = curl_easy_init ();
|
||||
if ( (GNUNET_OK !=
|
||||
if ( (NULL == eh) ||
|
||||
(GNUNET_OK !=
|
||||
TALER_BANK_setup_auth_ (eh,
|
||||
auth)) ||
|
||||
(CURLE_OK !=
|
||||
curl_easy_setopt (eh,
|
||||
CURLOPT_URL,
|
||||
weh->request_url)) ||
|
||||
th->request_url)) ||
|
||||
(GNUNET_OK !=
|
||||
TALER_curl_easy_post (&weh->post_ctx,
|
||||
TALER_curl_easy_post (&th->post_ctx,
|
||||
eh,
|
||||
transfer_obj)) )
|
||||
{
|
||||
GNUNET_break (0);
|
||||
TALER_BANK_execute_wire_transfer_cancel (weh);
|
||||
TALER_BANK_transfer_cancel (th);
|
||||
if (NULL != eh)
|
||||
curl_easy_cleanup (eh);
|
||||
json_decref (transfer_obj);
|
||||
return NULL;
|
||||
}
|
||||
json_decref (transfer_obj);
|
||||
|
||||
weh->job = GNUNET_CURL_job_add2 (ctx,
|
||||
th->job = GNUNET_CURL_job_add2 (ctx,
|
||||
eh,
|
||||
weh->post_ctx.headers,
|
||||
th->post_ctx.headers,
|
||||
&handle_transfer_finished,
|
||||
weh);
|
||||
return weh;
|
||||
th);
|
||||
return th;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cancel a wire transfer. This function cannot be used on a request handle
|
||||
* if a response is already served for it.
|
||||
* Abort execution of a wire transfer. For example, because we are shutting
|
||||
* 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
|
||||
TALER_BANK_execute_wire_transfer_cancel (struct
|
||||
TALER_BANK_WireExecuteHandle *weh)
|
||||
TALER_BANK_transfer_cancel (struct
|
||||
TALER_BANK_TransferHandle *th)
|
||||
{
|
||||
if (NULL != weh->job)
|
||||
if (NULL != th->job)
|
||||
{
|
||||
GNUNET_CURL_job_cancel (weh->job);
|
||||
weh->job = NULL;
|
||||
GNUNET_CURL_job_cancel (th->job);
|
||||
th->job = NULL;
|
||||
}
|
||||
TALER_curl_easy_post_finished (&weh->post_ctx);
|
||||
GNUNET_free (weh->request_url);
|
||||
GNUNET_free (weh);
|
||||
TALER_curl_easy_post_finished (&th->post_ctx);
|
||||
GNUNET_free (th->request_url);
|
||||
GNUNET_free (th);
|
||||
}
|
||||
|
||||
|
||||
|
@ -70,7 +70,7 @@ static char *destination_account_url;
|
||||
/**
|
||||
* Handle for executing the wire transfer.
|
||||
*/
|
||||
static struct TALER_BANK_WireExecuteHandle *eh;
|
||||
static struct TALER_BANK_TransferHandle *eh;
|
||||
|
||||
/**
|
||||
* Handle to ongoing history operation.
|
||||
@ -189,13 +189,13 @@ execute_wire_transfer ()
|
||||
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
|
||||
&wtid,
|
||||
sizeof (wtid));
|
||||
TALER_BANK_prepare_wire_transfer (destination_account_url,
|
||||
TALER_BANK_prepare_transfer (destination_account_url,
|
||||
&amount,
|
||||
"http://exchange.example.com/",
|
||||
&wtid,
|
||||
&buf,
|
||||
&buf_size);
|
||||
eh = TALER_BANK_execute_wire_transfer (ctx,
|
||||
eh = TALER_BANK_transfer (ctx,
|
||||
&auth,
|
||||
buf,
|
||||
buf_size,
|
||||
@ -260,7 +260,7 @@ do_shutdown (void *cls)
|
||||
}
|
||||
if (NULL != eh)
|
||||
{
|
||||
TALER_BANK_execute_wire_transfer_cancel (eh);
|
||||
TALER_BANK_transfer_cancel (eh);
|
||||
eh = NULL;
|
||||
}
|
||||
TALER_BANK_auth_free (&auth);
|
||||
|
@ -82,7 +82,7 @@ struct WirePrepareData
|
||||
/**
|
||||
* Wire execution handle.
|
||||
*/
|
||||
struct TALER_BANK_WireExecuteHandle *eh;
|
||||
struct TALER_BANK_TransferHandle *eh;
|
||||
|
||||
/**
|
||||
* Wire account used for this preparation.
|
||||
@ -565,7 +565,7 @@ shutdown_task (void *cls)
|
||||
{
|
||||
if (NULL != wpd->eh)
|
||||
{
|
||||
TALER_BANK_execute_wire_transfer_cancel (wpd->eh);
|
||||
TALER_BANK_transfer_cancel (wpd->eh);
|
||||
wpd->eh = NULL;
|
||||
}
|
||||
db_plugin->rollback (db_plugin->cls,
|
||||
@ -1211,7 +1211,7 @@ expired_reserve_cb (void *cls,
|
||||
ctc->wa = wa;
|
||||
ctc->session = session;
|
||||
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,
|
||||
exchange_base_url,
|
||||
&wtid,
|
||||
@ -1581,7 +1581,7 @@ run_aggregation (void *cls)
|
||||
char *url;
|
||||
|
||||
url = TALER_JSON_wire_to_payto (au->wire);
|
||||
TALER_BANK_prepare_wire_transfer (url,
|
||||
TALER_BANK_prepare_transfer (url,
|
||||
&au->final_amount,
|
||||
exchange_base_url,
|
||||
&au->wtid,
|
||||
@ -1804,7 +1804,7 @@ wire_prepare_cb (void *cls,
|
||||
return;
|
||||
}
|
||||
wa = wpd->wa;
|
||||
wpd->eh = TALER_BANK_execute_wire_transfer (ctx,
|
||||
wpd->eh = TALER_BANK_transfer (ctx,
|
||||
&wa->auth,
|
||||
buf,
|
||||
buf_size,
|
||||
|
@ -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
|
||||
*/
|
||||
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 char *exchange_base_url,
|
||||
const struct
|
||||
@ -186,7 +186,7 @@ TALER_BANK_prepare_wire_transfer (const char *destination_account_payto_uri,
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
typedef void
|
||||
(*TALER_BANK_ConfirmationCallback)(void *cls,
|
||||
(*TALER_BANK_TransferCallback)(void *cls,
|
||||
unsigned int response_code,
|
||||
enum TALER_ErrorCode ec,
|
||||
uint64_t row_id,
|
||||
@ -217,30 +217,32 @@ typedef void
|
||||
* @param cc_cls closure for @a cc
|
||||
* @return NULL on error
|
||||
*/
|
||||
struct TALER_BANK_WireExecuteHandle *
|
||||
TALER_BANK_execute_wire_transfer (struct GNUNET_CURL_Context *ctx,
|
||||
const struct
|
||||
TALER_BANK_AuthenticationData *auth,
|
||||
struct TALER_BANK_TransferHandle *
|
||||
TALER_BANK_transfer (struct GNUNET_CURL_Context *ctx,
|
||||
const struct TALER_BANK_AuthenticationData *auth,
|
||||
const void *buf,
|
||||
size_t buf_size,
|
||||
TALER_BANK_ConfirmationCallback cc,
|
||||
TALER_BANK_TransferCallback cc,
|
||||
void *cc_cls);
|
||||
|
||||
|
||||
/**
|
||||
* Abort execution of a wire transfer. For example, because we are
|
||||
* shutting down. Note that if an execution is aborted, it may or
|
||||
* may not still succeed. The caller MUST run @e
|
||||
* 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).
|
||||
* Abort execution of a wire transfer. For example, because we are shutting
|
||||
* down. Note that if an execution is aborted, it may or may not still
|
||||
* succeed.
|
||||
*
|
||||
* @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
|
||||
TALER_BANK_execute_wire_transfer_cancel (struct
|
||||
TALER_BANK_WireExecuteHandle *weh);
|
||||
TALER_BANK_transfer_cancel (struct TALER_BANK_TransferHandle *th);
|
||||
|
||||
|
||||
/* ********************* /history/incoming *********************** */
|
||||
|
@ -19,7 +19,6 @@
|
||||
* @brief curl easy handle defaults
|
||||
* @author Florian Dold
|
||||
*/
|
||||
|
||||
#include "auditor_api_curl_defaults.h"
|
||||
|
||||
|
||||
@ -30,7 +29,7 @@
|
||||
* @param url URL to query
|
||||
*/
|
||||
CURL *
|
||||
TAL_curl_easy_get (const char *url)
|
||||
TALER_AUDITOR_curl_easy_get_ (const char *url)
|
||||
{
|
||||
CURL *eh;
|
||||
struct GNUNET_AsyncScopeSave scope;
|
||||
@ -38,15 +37,25 @@ TAL_curl_easy_get (const char *url)
|
||||
GNUNET_async_scope_get (&scope);
|
||||
|
||||
eh = curl_easy_init ();
|
||||
|
||||
if (NULL == eh)
|
||||
return NULL;
|
||||
GNUNET_assert (CURLE_OK ==
|
||||
curl_easy_setopt (eh,
|
||||
CURLOPT_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 ==
|
||||
curl_easy_setopt (eh,
|
||||
CURLOPT_TCP_FASTOPEN,
|
||||
1L));
|
||||
|
||||
return eh;
|
||||
}
|
||||
|
@ -14,17 +14,14 @@
|
||||
TALER; see the file COPYING. If not, see
|
||||
<http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file lib/auditor_api_curl_defaults.h
|
||||
* @brief curl easy handle defaults
|
||||
* @author Florian Dold
|
||||
*/
|
||||
|
||||
#ifndef _TALER_CURL_DEFAULTS_H
|
||||
#define _TALER_CURL_DEFAULTS_H
|
||||
|
||||
|
||||
#include "platform.h"
|
||||
#include <gnunet/gnunet_curl_lib.h>
|
||||
|
||||
@ -36,6 +33,6 @@
|
||||
* @param url URL to query
|
||||
*/
|
||||
CURL *
|
||||
TAL_curl_easy_get (const char *url);
|
||||
TALER_AUDITOR_curl_easy_get_ (const char *url);
|
||||
|
||||
#endif /* _TALER_CURL_DEFAULTS_H */
|
||||
|
@ -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_end);
|
||||
GNUNET_assert (GNUNET_YES ==
|
||||
MAH_handle_is_ready (auditor));
|
||||
TALER_AUDITOR_handle_is_ready_ (auditor));
|
||||
if (GNUNET_OK !=
|
||||
verify_signatures (h_wire,
|
||||
h_contract_terms,
|
||||
@ -346,19 +346,22 @@ TALER_AUDITOR_deposit_confirmation (struct TALER_AUDITOR_Handle *auditor,
|
||||
dh->auditor = auditor;
|
||||
dh->cb = cb;
|
||||
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);
|
||||
GNUNET_assert (CURLE_OK ==
|
||||
if ( (NULL == eh) ||
|
||||
(CURLE_OK !=
|
||||
curl_easy_setopt (eh,
|
||||
CURLOPT_CUSTOMREQUEST,
|
||||
"PUT"));
|
||||
if (GNUNET_OK !=
|
||||
"PUT")) ||
|
||||
(GNUNET_OK !=
|
||||
TALER_curl_easy_post (&dh->ctx,
|
||||
eh,
|
||||
deposit_confirmation_obj))
|
||||
deposit_confirmation_obj)) )
|
||||
{
|
||||
GNUNET_break (0);
|
||||
if (NULL != eh)
|
||||
curl_easy_cleanup (eh);
|
||||
json_decref (deposit_confirmation_obj);
|
||||
GNUNET_free (dh->url);
|
||||
@ -369,7 +372,7 @@ TALER_AUDITOR_deposit_confirmation (struct TALER_AUDITOR_Handle *auditor,
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
||||
"URL for deposit-confirmation: `%s'\n",
|
||||
dh->url);
|
||||
ctx = MAH_handle_to_context (auditor);
|
||||
ctx = TALER_AUDITOR_handle_to_context_ (auditor);
|
||||
dh->job = GNUNET_CURL_job_add2 (ctx,
|
||||
eh,
|
||||
dh->ctx.headers,
|
||||
|
@ -201,19 +201,26 @@ TALER_AUDITOR_list_exchanges (struct TALER_AUDITOR_Handle *auditor,
|
||||
CURL *eh;
|
||||
|
||||
GNUNET_assert (GNUNET_YES ==
|
||||
MAH_handle_is_ready (auditor));
|
||||
TALER_AUDITOR_handle_is_ready_ (auditor));
|
||||
|
||||
leh = GNUNET_new (struct TALER_AUDITOR_ListExchangesHandle);
|
||||
leh->auditor = auditor;
|
||||
leh->cb = cb;
|
||||
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,
|
||||
"URL for list-exchanges: `%s'\n",
|
||||
leh->url);
|
||||
eh = TAL_curl_easy_get (leh->url);
|
||||
ctx = MAH_handle_to_context (auditor);
|
||||
eh = TALER_AUDITOR_curl_easy_get_ (leh->url);
|
||||
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,
|
||||
eh,
|
||||
GNUNET_NO,
|
||||
|
@ -367,7 +367,7 @@ version_completed_cb (void *cls,
|
||||
* @return ctx context to execute jobs in
|
||||
*/
|
||||
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;
|
||||
}
|
||||
@ -380,7 +380,7 @@ MAH_handle_to_context (struct TALER_AUDITOR_Handle *h)
|
||||
* @return #GNUNET_YES if we are ready, #GNUNET_NO if not
|
||||
*/
|
||||
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,
|
||||
"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
|
||||
*/
|
||||
char *
|
||||
MAH_path_to_url (struct TALER_AUDITOR_Handle *h,
|
||||
TALER_AUDITOR_path_to_url_ (struct TALER_AUDITOR_Handle *h,
|
||||
const char *path)
|
||||
{
|
||||
char *ret;
|
||||
@ -473,13 +473,22 @@ request_version (void *cls)
|
||||
GNUNET_assert (NULL == auditor->vr);
|
||||
vr = GNUNET_new (struct VersionRequest);
|
||||
vr->auditor = auditor;
|
||||
vr->url = MAH_path_to_url (auditor,
|
||||
vr->url = TALER_AUDITOR_path_to_url_ (auditor,
|
||||
"/version");
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||
"Requesting auditor version with URL `%s'.\n",
|
||||
vr->url);
|
||||
eh = TAL_curl_easy_get (vr->url);
|
||||
GNUNET_assert (CURLE_OK ==
|
||||
eh = TALER_AUDITOR_curl_easy_get_ (vr->url);
|
||||
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,
|
||||
CURLOPT_TIMEOUT,
|
||||
(long) 300));
|
||||
|
@ -31,7 +31,7 @@
|
||||
* @return ctx context to execute jobs in
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
char *
|
||||
MAH_path_to_url (struct TALER_AUDITOR_Handle *h,
|
||||
TALER_AUDITOR_path_to_url_ (struct TALER_AUDITOR_Handle *h,
|
||||
const char *path);
|
||||
|
||||
|
||||
|
@ -24,8 +24,8 @@
|
||||
|
||||
|
||||
/**
|
||||
* Get a curl handle with the right defaults
|
||||
* for the exchange lib. In the future, we might manage a pool of connections here.
|
||||
* Get a curl handle with the right defaults for the exchange lib. In the
|
||||
* future, we might manage a pool of connections here.
|
||||
*
|
||||
* @param url URL to query
|
||||
*/
|
||||
@ -35,6 +35,8 @@ TALER_EXCHANGE_curl_easy_get_ (const char *url)
|
||||
CURL *eh;
|
||||
|
||||
eh = curl_easy_init ();
|
||||
if (NULL == eh)
|
||||
return NULL;
|
||||
GNUNET_assert (CURLE_OK ==
|
||||
curl_easy_setopt (eh,
|
||||
CURLOPT_URL,
|
||||
|
@ -627,12 +627,14 @@ TALER_EXCHANGE_deposit (struct TALER_EXCHANGE_Handle *exchange,
|
||||
not copy the pointer */
|
||||
|
||||
eh = TALER_EXCHANGE_curl_easy_get_ (dh->url);
|
||||
if (GNUNET_OK !=
|
||||
if ( (NULL == eh) ||
|
||||
(GNUNET_OK !=
|
||||
TALER_curl_easy_post (&dh->ctx,
|
||||
eh,
|
||||
deposit_obj))
|
||||
deposit_obj)) )
|
||||
{
|
||||
GNUNET_break (0);
|
||||
if (NULL != eh)
|
||||
curl_easy_cleanup (eh);
|
||||
json_decref (deposit_obj);
|
||||
GNUNET_free (dh->url);
|
||||
|
@ -367,6 +367,13 @@ TALER_EXCHANGE_deposits_get (struct TALER_EXCHANGE_Handle *exchange,
|
||||
dwh->depconf.coin_pub = *coin_pub;
|
||||
|
||||
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);
|
||||
dwh->job = GNUNET_CURL_job_add (ctx,
|
||||
eh,
|
||||
|
@ -1954,11 +1954,19 @@ request_keys (void *cls)
|
||||
"Requesting keys with URL `%s'.\n",
|
||||
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,
|
||||
CURLOPT_VERBOSE,
|
||||
0));
|
||||
GNUNET_assert (CURLE_OK ==
|
||||
GNUNET_break (CURLE_OK ==
|
||||
curl_easy_setopt (eh,
|
||||
CURLOPT_TIMEOUT,
|
||||
(long) 300));
|
||||
|
@ -456,6 +456,13 @@ TALER_EXCHANGE_link (struct TALER_EXCHANGE_Handle *exchange,
|
||||
lh->url = TEAH_path_to_url (exchange,
|
||||
arg_str);
|
||||
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);
|
||||
lh->job = GNUNET_CURL_job_add (ctx,
|
||||
eh,
|
||||
|
@ -457,12 +457,14 @@ TALER_EXCHANGE_melt (struct TALER_EXCHANGE_Handle *exchange,
|
||||
mh->url = TEAH_path_to_url (exchange,
|
||||
arg_str);
|
||||
eh = TALER_EXCHANGE_curl_easy_get_ (mh->url);
|
||||
if (GNUNET_OK !=
|
||||
if ( (NULL == eh) ||
|
||||
(GNUNET_OK !=
|
||||
TALER_curl_easy_post (&mh->ctx,
|
||||
eh,
|
||||
melt_obj))
|
||||
melt_obj)) )
|
||||
{
|
||||
GNUNET_break (0);
|
||||
if (NULL != eh)
|
||||
curl_easy_cleanup (eh);
|
||||
json_decref (melt_obj);
|
||||
GNUNET_free (mh->url);
|
||||
|
@ -390,12 +390,14 @@ TALER_EXCHANGE_recoup (struct TALER_EXCHANGE_Handle *exchange,
|
||||
arg_str);
|
||||
ph->was_refreshed = was_refreshed;
|
||||
eh = TALER_EXCHANGE_curl_easy_get_ (ph->url);
|
||||
if (GNUNET_OK !=
|
||||
if ( (NULL == eh) ||
|
||||
(GNUNET_OK !=
|
||||
TALER_curl_easy_post (&ph->ctx,
|
||||
eh,
|
||||
recoup_obj))
|
||||
recoup_obj)) )
|
||||
{
|
||||
GNUNET_break (0);
|
||||
if (NULL != eh)
|
||||
curl_easy_cleanup (eh);
|
||||
json_decref (recoup_obj);
|
||||
GNUNET_free (ph->url);
|
||||
|
@ -462,12 +462,14 @@ TALER_EXCHANGE_refreshes_reveal (struct TALER_EXCHANGE_Handle *exchange,
|
||||
arg_str);
|
||||
|
||||
eh = TALER_EXCHANGE_curl_easy_get_ (rrh->url);
|
||||
if (GNUNET_OK !=
|
||||
if ( (NULL == eh) ||
|
||||
(GNUNET_OK !=
|
||||
TALER_curl_easy_post (&rrh->ctx,
|
||||
eh,
|
||||
reveal_obj))
|
||||
reveal_obj)) )
|
||||
{
|
||||
GNUNET_break (0);
|
||||
if (NULL != eh)
|
||||
curl_easy_cleanup (eh);
|
||||
json_decref (reveal_obj);
|
||||
GNUNET_free (rrh->url);
|
||||
|
@ -388,12 +388,14 @@ TALER_EXCHANGE_refund2 (struct TALER_EXCHANGE_Handle *exchange,
|
||||
refund_fee);
|
||||
|
||||
eh = TALER_EXCHANGE_curl_easy_get_ (rh->url);
|
||||
if (GNUNET_OK !=
|
||||
if ( (NULL == eh) ||
|
||||
(GNUNET_OK !=
|
||||
TALER_curl_easy_post (&rh->ctx,
|
||||
eh,
|
||||
refund_obj))
|
||||
refund_obj)) )
|
||||
{
|
||||
GNUNET_break (0);
|
||||
if (NULL != eh)
|
||||
curl_easy_cleanup (eh);
|
||||
json_decref (refund_obj);
|
||||
GNUNET_free (rh->url);
|
||||
|
@ -275,6 +275,13 @@ TALER_EXCHANGE_reserves_get (struct TALER_EXCHANGE_Handle *exchange,
|
||||
rgh->url = TEAH_path_to_url (exchange,
|
||||
arg_str);
|
||||
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);
|
||||
rgh->job = GNUNET_CURL_job_add (ctx,
|
||||
eh,
|
||||
|
@ -367,6 +367,13 @@ TALER_EXCHANGE_transfers_get (struct TALER_EXCHANGE_Handle *exchange,
|
||||
wdh->url = TEAH_path_to_url (wdh->exchange,
|
||||
arg_str);
|
||||
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);
|
||||
wdh->job = GNUNET_CURL_job_add (ctx,
|
||||
eh,
|
||||
|
@ -405,9 +405,16 @@ TALER_EXCHANGE_wire (struct TALER_EXCHANGE_Handle *exchange,
|
||||
wh->exchange = exchange;
|
||||
wh->cb = wire_cb;
|
||||
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);
|
||||
if (NULL == eh)
|
||||
{
|
||||
GNUNET_break (0);
|
||||
GNUNET_free (wh->url);
|
||||
GNUNET_free (wh);
|
||||
return NULL;
|
||||
}
|
||||
ctx = TEAH_handle_to_context (exchange);
|
||||
wh->job = GNUNET_CURL_job_add (ctx,
|
||||
eh,
|
||||
|
@ -427,12 +427,14 @@ reserve_withdraw_internal (struct TALER_EXCHANGE_Handle *exchange,
|
||||
wh->url = TEAH_path_to_url (exchange,
|
||||
arg_str);
|
||||
eh = TALER_EXCHANGE_curl_easy_get_ (wh->url);
|
||||
if (GNUNET_OK !=
|
||||
if ( (NULL == eh) ||
|
||||
(GNUNET_OK !=
|
||||
TALER_curl_easy_post (&wh->ctx,
|
||||
eh,
|
||||
withdraw_obj))
|
||||
withdraw_obj)) )
|
||||
{
|
||||
GNUNET_break (0);
|
||||
if (NULL != eh)
|
||||
curl_easy_cleanup (eh);
|
||||
json_decref (withdraw_obj);
|
||||
GNUNET_free (wh->url);
|
||||
|
@ -76,7 +76,7 @@ struct TransferState
|
||||
/**
|
||||
* Handle to the pending request at the fakebank.
|
||||
*/
|
||||
struct TALER_BANK_WireExecuteHandle *weh;
|
||||
struct TALER_BANK_TransferHandle *weh;
|
||||
|
||||
/**
|
||||
* Interpreter state.
|
||||
@ -233,7 +233,7 @@ transfer_run (void *cls,
|
||||
TALER_amount2s (&fts->amount),
|
||||
fts->account_debit_url,
|
||||
fts->payto_credit_account);
|
||||
TALER_BANK_prepare_wire_transfer (fts->payto_credit_account,
|
||||
TALER_BANK_prepare_transfer (fts->payto_credit_account,
|
||||
&fts->amount,
|
||||
fts->exchange_base_url,
|
||||
&fts->wtid,
|
||||
@ -241,7 +241,7 @@ transfer_run (void *cls,
|
||||
&buf_size);
|
||||
fts->is = is;
|
||||
fts->weh
|
||||
= TALER_BANK_execute_wire_transfer
|
||||
= TALER_BANK_transfer
|
||||
(TALER_TESTING_interpreter_get_context (is),
|
||||
&fts->auth,
|
||||
buf,
|
||||
@ -276,7 +276,7 @@ transfer_cleanup (void *cls,
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
|
||||
"Command %s did not complete\n",
|
||||
cmd->label);
|
||||
TALER_BANK_execute_wire_transfer_cancel (fts->weh);
|
||||
TALER_BANK_transfer_cancel (fts->weh);
|
||||
fts->weh = NULL;
|
||||
}
|
||||
if (NULL != fts->retry_task)
|
||||
|
Loading…
Reference in New Issue
Block a user