diff options
Diffstat (limited to 'src/backend/taler-merchant-httpd_post-orders-ID-abort.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_post-orders-ID-abort.c | 116 |
1 files changed, 42 insertions, 74 deletions
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c index d0fcfbc0..50a793a3 100644 --- a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c +++ b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c @@ -176,7 +176,7 @@ struct AbortContext * the exchange used for this transaction; NULL if no operation is * pending. */ - struct TMH_EXCHANGES_FindOperation *fo; + struct TMH_EXCHANGES_KeysOperation *fo; /** * URL of the exchange used for the last @e fo. @@ -186,7 +186,7 @@ struct AbortContext /** * Number of coins this abort is for. Length of the @e rd array. */ - unsigned int coins_cnt; + size_t coins_cnt; /** * How often have we retried the 'main' transaction? @@ -198,7 +198,7 @@ struct AbortContext * @e coins_cnt, decremented on each transaction that * successfully finished. */ - unsigned int pending; + size_t pending; /** * Number of transactions still pending for the currently selected @@ -206,7 +206,7 @@ struct AbortContext * exchange, decremented on each transaction that successfully * finished. Once it hits zero, we pick the next exchange. */ - unsigned int pending_at_ce; + size_t pending_at_ce; /** * HTTP status code to use for the reply, i.e 200 for "OK". @@ -247,7 +247,7 @@ abort_refunds (struct AbortContext *ac) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Aborting pending /deposit operations\n"); - for (unsigned int i = 0; i<ac->coins_cnt; i++) + for (size_t i = 0; i<ac->coins_cnt; i++) { struct RefundDetails *rdi = &ac->rd[i]; @@ -356,7 +356,7 @@ generate_success_response (struct AbortContext *ac) "could not create JSON array"); return; } - for (unsigned int i = 0; i<ac->coins_cnt; i++) + for (size_t i = 0; i<ac->coins_cnt; i++) { struct RefundDetails *rdi = &ac->rd[i]; json_t *detail; @@ -424,7 +424,7 @@ abort_context_cleanup (void *cls) ac->timeout_task = NULL; } abort_refunds (ac); - for (unsigned int i = 0; i<ac->coins_cnt; i++) + for (size_t i = 0; i<ac->coins_cnt; i++) { struct RefundDetails *rdi = &ac->rd[i]; @@ -438,7 +438,7 @@ abort_context_cleanup (void *cls) GNUNET_free (ac->rd); if (NULL != ac->fo) { - TMH_EXCHANGES_find_exchange_cancel (ac->fo); + TMH_EXCHANGES_keys4exchange_cancel (ac->fo); ac->fo = NULL; } if (NULL != ac->response) @@ -468,30 +468,23 @@ find_next_exchange (struct AbortContext *ac); * passed back to the wallet). * * @param cls closure - * @param hr HTTP response data - * @param sign_key exchange key used to sign @a obj, or NULL - * @param signature the actual signature, or NULL on error + * @param rr response data */ static void refund_cb (void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr, - const struct TALER_ExchangePublicKeyP *sign_key, - const struct TALER_ExchangeSignatureP *signature) + const struct TALER_EXCHANGE_RefundResponse *rr) { struct RefundDetails *rd = cls; + const struct TALER_EXCHANGE_HttpResponse *hr = &rr->hr; struct AbortContext *ac = rd->ac; - (void) sign_key; - (void) signature; rd->rh = NULL; rd->http_status = hr->http_status; rd->exchange_reply = json_incref ((json_t*) hr->reply); if (MHD_HTTP_OK == hr->http_status) { - GNUNET_assert (NULL != sign_key); - GNUNET_assert (NULL != signature); - rd->exchange_pub = *sign_key; - rd->exchange_sig = *signature; + rd->exchange_pub = rr->details.ok.exchange_pub; + rd->exchange_sig = rr->details.ok.exchange_sig; } ac->pending_at_ce--; if (0 == ac->pending_at_ce) @@ -503,29 +496,20 @@ refund_cb (void *cls, * Function called with the result of our exchange lookup. * * @param cls the `struct AbortContext` - * @param hr HTTP response details - * @param payto_uri payto://-URI of the exchange - * @param exchange_handle NULL if exchange was not found to be acceptable - * @param wire_fee current applicable fee for dealing with @a exchange_handle, - * NULL if not available - * @param exchange_trusted true if this exchange is - * trusted by config + * @param keys keys of the exchange + * @param exchange representation of the exchange */ static void process_abort_with_exchange (void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr, - struct TALER_EXCHANGE_Handle *exchange_handle, - const char *payto_uri, - const struct TALER_Amount *wire_fee, - bool exchange_trusted) + struct TALER_EXCHANGE_Keys *keys, + struct TMH_Exchange *exchange) { struct AbortContext *ac = cls; - (void) payto_uri; - (void) exchange_trusted; + (void) exchange; ac->fo = NULL; GNUNET_assert (GNUNET_YES == ac->suspended); - if (NULL == hr) + if (NULL == keys) { resume_abort_with_response ( ac, @@ -535,23 +519,10 @@ process_abort_with_exchange (void *cls, NULL)); return; } - if (NULL == exchange_handle) - { - /* The request failed somehow */ - GNUNET_break_op (0); - resume_abort_with_response ( - ac, - MHD_HTTP_BAD_GATEWAY, - TALER_MHD_MAKE_JSON_PACK ( - TALER_JSON_pack_ec ( - TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE), - TMH_pack_exchange_reply (hr))); - return; - } /* Initiate refund operation for all coins of the current exchange (!) */ GNUNET_assert (0 == ac->pending_at_ce); - for (unsigned int i = 0; i<ac->coins_cnt; i++) + for (size_t i = 0; i<ac->coins_cnt; i++) { struct RefundDetails *rdi = &ac->rd[i]; @@ -563,14 +534,17 @@ process_abort_with_exchange (void *cls, continue; rdi->processed = true; ac->pending--; - rdi->rh = TALER_EXCHANGE_refund (exchange_handle, - &rdi->amount_with_fee, - &ac->h_contract_terms, - &rdi->coin_pub, - 0, /* rtransaction_id */ - &ac->hc->instance->merchant_priv, - &refund_cb, - rdi); + rdi->rh = TALER_EXCHANGE_refund ( + TMH_curl_ctx, + ac->current_exchange, + keys, + &rdi->amount_with_fee, + &ac->h_contract_terms, + &rdi->coin_pub, + 0, /* rtransaction_id */ + &ac->hc->instance->merchant_priv, + &refund_cb, + rdi); if (NULL == rdi->rh) { GNUNET_break_op (0); @@ -605,16 +579,15 @@ begin_transaction (struct AbortContext *ac); static void find_next_exchange (struct AbortContext *ac) { - for (unsigned int i = 0; i<ac->coins_cnt; i++) + for (size_t i = 0; i<ac->coins_cnt; i++) { struct RefundDetails *rdi = &ac->rd[i]; if (! rdi->processed) { ac->current_exchange = rdi->exchange_url; - ac->fo = TMH_EXCHANGES_find_exchange (ac->current_exchange, - NULL, - GNUNET_NO, + ac->fo = TMH_EXCHANGES_keys4exchange (ac->current_exchange, + false, &process_abort_with_exchange, ac); if (NULL == ac->fo) @@ -646,7 +619,6 @@ find_next_exchange (struct AbortContext *ac) * @param amount_with_fee amount the exchange will deposit for this coin * @param deposit_fee fee the exchange will charge for this coin * @param refund_fee fee the exchange will charge for refunding this coin - * @param wire_fee wire fee the exchange of this coin charges */ static void refund_coins (void *cls, @@ -654,8 +626,7 @@ refund_coins (void *cls, const struct TALER_CoinSpendPublicKeyP *coin_pub, const struct TALER_Amount *amount_with_fee, const struct TALER_Amount *deposit_fee, - const struct TALER_Amount *refund_fee, - const struct TALER_Amount *wire_fee) + const struct TALER_Amount *refund_fee) { struct AbortContext *ac = cls; struct GNUNET_TIME_Timestamp now; @@ -663,9 +634,8 @@ refund_coins (void *cls, (void) amount_with_fee; (void) deposit_fee; (void) refund_fee; - (void) wire_fee; now = GNUNET_TIME_timestamp_get (); - for (unsigned int i = 0; i<ac->coins_cnt; i++) + for (size_t i = 0; i<ac->coins_cnt; i++) { struct RefundDetails *rdi = &ac->rd[i]; enum GNUNET_DB_QueryStatus qs; @@ -871,10 +841,10 @@ parse_abort (struct MHD_Connection *connection, struct TMH_HandlerContext *hc, struct AbortContext *ac) { - json_t *coins; + const json_t *coins; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("coins", - &coins), + GNUNET_JSON_spec_array_const ("coins", + &coins), GNUNET_JSON_spec_fixed_auto ("h_contract", &ac->h_contract_terms), @@ -893,7 +863,7 @@ parse_abort (struct MHD_Connection *connection, ac->coins_cnt = json_array_size (coins); if (0 == ac->coins_cnt) { - GNUNET_JSON_parse_free (spec); + GNUNET_break_op (0); return TALER_MHD_reply_with_error (connection, MHD_HTTP_BAD_REQUEST, TALER_EC_MERCHANT_POST_ORDERS_ID_ABORT_COINS_ARRAY_EMPTY, @@ -915,7 +885,7 @@ parse_abort (struct MHD_Connection *connection, TALER_JSON_spec_amount ("contribution", TMH_currency, &rd->amount_with_fee), - GNUNET_JSON_spec_string ("exchange_url", + TALER_JSON_spec_web_url ("exchange_url", &exchange_url), GNUNET_JSON_spec_fixed_auto ("coin_pub", &rd->coin_pub), @@ -927,7 +897,6 @@ parse_abort (struct MHD_Connection *connection, ispec); if (GNUNET_YES != res) { - GNUNET_JSON_parse_free (spec); GNUNET_break_op (0); return res; } @@ -936,7 +905,6 @@ parse_abort (struct MHD_Connection *connection, rd->ac = ac; } } - GNUNET_JSON_parse_free (spec); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Handling /abort for order `%s' with contract hash `%s'\n", ac->hc->infix, @@ -961,7 +929,7 @@ handle_abort_timeout (void *cls) "Resuming abort with error after timeout\n"); if (NULL != ac->fo) { - TMH_EXCHANGES_find_exchange_cancel (ac->fo); + TMH_EXCHANGES_keys4exchange_cancel (ac->fo); ac->fo = NULL; } resume_abort_with_error (ac, |