summaryrefslogtreecommitdiff
path: root/src/backend/taler-merchant-httpd_post-orders-ID-abort.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-05-01 14:16:47 +0200
committerChristian Grothoff <christian@grothoff.org>2020-05-01 14:16:47 +0200
commit49217808de28559964ca3f2b42e50c3990436520 (patch)
tree0a331cc3cf84cc5540dc4119ef5b442f4a555ee6 /src/backend/taler-merchant-httpd_post-orders-ID-abort.c
parent577e344b018cf186e179edf8fa56101659e25307 (diff)
downloadmerchant-49217808de28559964ca3f2b42e50c3990436520.tar.gz
merchant-49217808de28559964ca3f2b42e50c3990436520.tar.bz2
merchant-49217808de28559964ca3f2b42e50c3990436520.zip
work on /abort logic
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.c133
1 files changed, 39 insertions, 94 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 604490d4..27a83812 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c
@@ -103,7 +103,7 @@ struct RefundDetails
/**
* Did we try to process this refund yet?
*/
- boolean processed;
+ bool processed;
};
@@ -242,7 +242,7 @@ abort_refunds (struct AbortContext *ac)
{
struct RefundDetails *rdi = &ac->rd[i];
- if (NULL != rdi->dh)
+ if (NULL != rdi->rh)
{
TALER_EXCHANGE_refund_cancel (rdi->rh);
rdi->rh = NULL;
@@ -262,7 +262,7 @@ TMH_force_ac_resume ()
NULL != ac;
ac = ac->next)
{
- abort_deposit (ac);
+ abort_refunds (ac);
if (NULL != ac->timeout_task)
{
GNUNET_SCHEDULER_cancel (ac->timeout_task);
@@ -358,10 +358,10 @@ generate_success_response (struct AbortContext *ac)
json_array_append_new (
refunds,
json_pack ("{s:I, s:O, s:o s:o s:o}",
- "exchange_status",
- (json_int_t) rdi->exchange_status,
- "exchange_body",
- rdi->exchange_body)))
+ "exchange_http_status",
+ (json_int_t) rdi->http_status,
+ "exchange_reply",
+ rdi->exchange_reply)))
{
json_decref (refunds);
GNUNET_break (0);
@@ -385,12 +385,12 @@ generate_success_response (struct AbortContext *ac)
/**
* Custom cleanup routine for a `struct AbortContext`.
*
- * @param hc the `struct AbortContext` to clean up.
+ * @param cls the `struct AbortContext` to clean up.
*/
static void
-abort_context_cleanup (struct TM_HandlerContext *hc)
+abort_context_cleanup (void *cls)
{
- struct AbortContext *ac = (struct AbortContext *) hc;
+ struct AbortContext *ac = cls;
if (NULL != ac->timeout_task)
{
@@ -400,14 +400,14 @@ abort_context_cleanup (struct TM_HandlerContext *hc)
abort_refunds (ac);
for (unsigned int i = 0; i<ac->coins_cnt; i++)
{
- struct RefundDetails *rd = &ac->rd[i];
+ struct RefundDetails *rdi = &ac->rd[i];
if (NULL != rdi->exchange_reply)
{
json_decref (rdi->exchange_reply);
- rdi->reply = NULL;
+ rdi->exchange_reply = NULL;
}
- GNUNET_free_non_null (rd->exchange_url);
+ GNUNET_free_non_null (rdi->exchange_url);
}
GNUNET_free_non_null (ac->rd);
if (NULL != ac->fo)
@@ -458,8 +458,8 @@ refund_cb (void *cls,
(void) sign_key;
(void) signature;
rd->rh = NULL;
- rd.http_status = hr->status;
- rd.exchange_reply = json_incref ((json_t*) hr->reply);
+ rd->http_status = hr->http_status;
+ rd->exchange_reply = json_incref ((json_t*) hr->reply);
ac->pending_at_ce--;
if (0 == ac->pending_at_ce)
find_next_exchange (ac);
@@ -485,16 +485,15 @@ process_abort_with_exchange (void *cls,
int exchange_trusted)
{
struct AbortContext *ac = cls;
- struct TMH_HandlerContext *hc = pc->hc;
- pc->fo = NULL;
- GNUNET_assert (GNUNET_YES == pc->suspended);
+ ac->fo = NULL;
+ GNUNET_assert (GNUNET_YES == ac->suspended);
if (MHD_HTTP_OK != hr->http_status)
{
/* The request failed somehow */
GNUNET_break_op (0);
- resume_pay_with_response (
- pc,
+ resume_abort_with_response (
+ ac,
MHD_HTTP_FAILED_DEPENDENCY,
TALER_MHD_make_json_pack (
(NULL != hr->reply)
@@ -534,7 +533,7 @@ process_abort_with_exchange (void *cls,
&rdi->coin_pub,
0, /* rtransaction_id */
&ac->hc->instance->merchant_priv,
- &refund_Cb,
+ &refund_cb,
rdi);
if (NULL == rdi->rh)
{
@@ -545,7 +544,7 @@ process_abort_with_exchange (void *cls,
"Failed to start refund with exchange");
return;
}
- pc->pending_at_ce++;
+ ac->pending_at_ce++;
}
}
@@ -576,9 +575,9 @@ find_next_exchange (struct AbortContext *ac)
if (! rdi->processed)
{
- ac->current_exchange = rd->exchange_url;
+ ac->current_exchange = rdi->exchange_url;
ac->fo = TMH_EXCHANGES_find_exchange (ac->current_exchange,
- ac->wm->wire_method,
+ NULL,
GNUNET_NO,
&process_abort_with_exchange,
ac);
@@ -606,30 +605,32 @@ find_next_exchange (struct AbortContext *ac)
* Function called with information about a coin that was deposited.
*
* @param cls closure
- * @param h_contract_terms hashed proposal data
+ * @param exchange_url exchange where @a coin_pub was deposited
* @param coin_pub public key of the coin
- * @param exchange_url URL of the exchange that issued @a coin_pub
* @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
- * @param exchange_proof proof from exchange that coin was accepted
*/
static void
refund_coins (void *cls,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
const char *exchange_url,
+ 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 json_t *exchange_proof)
+ const struct TALER_Amount *wire_fee)
{
struct AbortContext *ac = cls;
+ (void) amount_with_fee;
+ (void) deposit_fee;
+ (void) refund_fee;
+ (void) wire_fee;
for (unsigned int i = 0; i<ac->coins_cnt; i++)
{
struct RefundDetails *rdi = &ac->rd[i];
+ enum GNUNET_DB_QueryStatus qs;
if ( (0 !=
GNUNET_memcmp (coin_pub,
@@ -711,7 +712,6 @@ begin_transaction (struct AbortContext *ac)
if (0 < qs)
{
/* Payment is complete, refuse to abort. */
- json_decref (terms);
TMH_db->rollback (TMH_db->cls);
resume_abort_with_error (ac,
MHD_HTTP_FORBIDDEN,
@@ -875,12 +875,12 @@ parse_abort (struct MHD_Connection *connection,
/* Check request against contract on file */
{
enum GNUNET_DB_QueryStatus qs;
- json_t *contract_terms;
+ struct GNUNET_HashCode h_contract_terms;
- qs = TMH_db->lookup_contract_terms (TMH_db->cls,
- hc->instance->settings.id,
- hc->infix,
- &contract_terms);
+ qs = TMH_db->lookup_contract_terms_hash (TMH_db->cls,
+ hc->instance->settings.id,
+ hc->infix,
+ &h_contract_terms);
if (0 > qs)
{
/* single, read-only SQL statements should never cause
@@ -909,23 +909,8 @@ parse_abort (struct MHD_Connection *connection,
/* check client provided the right hash and is thus authorized to request aborting */
{
- struct GNUNET_HashCode h_contract_terms;
-
- if (GNUNET_OK !=
- TALER_JSON_hash (ac->contract_terms,
- &h_contract_terms))
- {
- GNUNET_break (0);
- return (MHD_YES ==
- TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_ABORT_FAILED_COMPUTE_PROPOSAL_HASH,
- "Failed to hash contract terms"))
- ? GNUNET_NO
- : GNUNET_SYSERR;
- }
if (0 !=
- GNUNET_memcmp (&ac->contract_terms,
+ GNUNET_memcmp (&ac->h_contract_terms,
&h_contract_terms))
{
GNUNET_break_op (0);
@@ -940,48 +925,8 @@ parse_abort (struct MHD_Connection *connection,
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Handling /abort for order `%s' with contract hash `%s'\n",
- order_id,
+ ac->hc->infix,
GNUNET_h2s (&ac->h_contract_terms));
-
- /* Check abort is still possible */
- {
- struct GNUNET_TIME_Absolute refund_deadline;
- struct GNUNET_TIME_Absolute wire_transfer_deadline;
- struct GNUNET_TIME_Absolute now;
- struct GNUNET_JSON_Specification espec[] = {
- GNUNET_JSON_spec_absolute_time ("refund_deadline",
- &refund_deadline),
- GNUNET_JSON_spec_absolute_time ("wire_transfer_deadline",
- &wire_transfer_deadline),
- GNUNET_JSON_spec_end ()
- };
-
- /* FIXME: this is a tad wrong, as IF the contract is
- malformed, the routine generates an error that blames
- it on the client (400) instead of on us! */
- res = TALER_MHD_parse_json_data (connection,
- ac->contract_terms,
- espec);
- if (GNUNET_YES != res)
- {
- GNUNET_break (0);
- return res;
- }
- now = GNUNET_TIME_absolute_get ();
- if ( (now.abs_value_us < refund_deadline.abs_value_us) &&
- ( (0 != refund_deadline.abs_value_us) ||
- (now.abs_value_us < wire_transfer_deadline.abs_value_us) ) )
- {
- /* it is most definitively too late for an abort */
- return (MHD_YES ==
- TALER_MHD_reply_with_error (connection,
- MHD_HTTP_GONE,
- TALER_EC_ABORT_TOO_LATE,
- "It is too late to abort the payment"))
- ? GNUNET_NO
- : GNUNET_SYSERR;
- }
- }
}
return GNUNET_OK;
}
@@ -1028,7 +973,7 @@ TMH_post_orders_ID_abort (const struct TMH_RequestHandler *rh,
{
struct AbortContext *ac = hc->ctx;
- if (NULL == *connection_cls)
+ if (NULL == ac)
{
ac = GNUNET_new (struct AbortContext);
GNUNET_CONTAINER_DLL_insert (ac_head,