refactor track_transfer 200 handling, fix minor leak

This commit is contained in:
Christian Grothoff 2016-06-09 21:51:49 +02:00
parent 4a412841ba
commit 3f4d668463

View File

@ -67,26 +67,18 @@ struct TALER_EXCHANGE_TrackTransferHandle
/**
* Function called when we're done processing the
* HTTP /track/transfer request.
* We got a #MHD_HTTP_OK response for the /track/transfer request.
* Check that the response is well-formed and if it is, call the
* callback. If not, return an error code.
*
* @param cls the `struct TALER_EXCHANGE_TrackTransferHandle`
* @param response_code HTTP response code, 0 on error
* @param json parsed JSON result, NULL on error
* @param wdh handle to the operation
* @param json response we got
* @return #GNUNET_OK if we are done and all is well,
* #GNUNET_SYSERR if the response was bogus
*/
static void
handle_wire_deposits_finished (void *cls,
long response_code,
static int
check_track_transfer_response_ok (struct TALER_EXCHANGE_TrackTransferHandle *wdh,
const json_t *json)
{
struct TALER_EXCHANGE_TrackTransferHandle *wdh = cls;
wdh->job = NULL;
switch (response_code)
{
case 0:
break;
case MHD_HTTP_OK:
{
json_t *details_j;
struct GNUNET_HashCode h_wire;
@ -111,8 +103,7 @@ handle_wire_deposits_finished (void *cls,
NULL, NULL))
{
GNUNET_break_op (0);
response_code = 0;
break;
return GNUNET_SYSERR;
}
num_details = json_array_size (details_j);
{
@ -142,8 +133,8 @@ handle_wire_deposits_finished (void *cls,
NULL, NULL))
{
GNUNET_break_op (0);
response_code = 0;
break;
GNUNET_CRYPTO_hash_context_abort (hash_context);
return GNUNET_SYSERR;
}
/* build up big hash for signature checking later */
dd.h_contract = detail->h_contract;
@ -166,36 +157,61 @@ handle_wire_deposits_finished (void *cls,
wdp.h_wire = h_wire;
GNUNET_CRYPTO_hash_context_finish (hash_context,
&wdp.h_details);
if ( (0 == response_code /* avoid crypto if things are already wrong */) &&
(GNUNET_OK !=
if (GNUNET_OK !=
TALER_EXCHANGE_test_signing_key (TALER_EXCHANGE_get_keys (wdh->exchange),
&exchange_pub)) )
&exchange_pub))
{
GNUNET_break_op (0);
response_code = 0;
return GNUNET_SYSERR;
}
if ( (0 == response_code /* avoid crypto if things are already wrong */) &&
(GNUNET_OK !=
if (GNUNET_OK !=
TALER_EXCHANGE_test_signing_key (TALER_EXCHANGE_get_keys (wdh->exchange),
&exchange_pub)) )
&exchange_pub))
{
GNUNET_break_op (0);
response_code = 0;
return GNUNET_SYSERR;
}
if (0 == response_code)
break;
wdh->cb (wdh->cb_cls,
response_code,
MHD_HTTP_OK,
&exchange_pub,
json,
&h_wire,
&total_amount,
num_details,
details);
}
TALER_EXCHANGE_track_transfer_cancel (wdh);
return GNUNET_OK;
}
/**
* Function called when we're done processing the
* HTTP /track/transfer request.
*
* @param cls the `struct TALER_EXCHANGE_TrackTransferHandle`
* @param response_code HTTP response code, 0 on error
* @param json parsed JSON result, NULL on error
*/
static void
handle_track_transfer_finished (void *cls,
long response_code,
const json_t *json)
{
struct TALER_EXCHANGE_TrackTransferHandle *wdh = cls;
wdh->job = NULL;
switch (response_code)
{
case 0:
break;
case MHD_HTTP_OK:
if (GNUNET_OK ==
check_track_transfer_response_ok (wdh,
json))
return;
}
}
GNUNET_break_op (0);
response_code = 0;
break;
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the exchange is buggy
@ -285,7 +301,7 @@ TALER_EXCHANGE_track_transfer (struct TALER_EXCHANGE_Handle *exchange,
wdh->job = GNUNET_CURL_job_add (ctx,
eh,
GNUNET_YES,
&handle_wire_deposits_finished,
&handle_track_transfer_finished,
wdh);
return wdh;
}