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