summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-08-16 17:15:29 +0200
committerChristian Grothoff <christian@grothoff.org>2020-08-16 17:15:29 +0200
commitd2fc32f7d466a6d2f9a7f790171fabd908c00d00 (patch)
tree73ab7b1cd19a2dfed8a7dd4a1c35656bf1249979
parent378cbac194b4c7504b05bd9f338e7adb8b4c5d50 (diff)
downloadmerchant-d2fc32f7d466a6d2f9a7f790171fabd908c00d00.tar.gz
merchant-d2fc32f7d466a6d2f9a7f790171fabd908c00d00.tar.bz2
merchant-d2fc32f7d466a6d2f9a7f790171fabd908c00d00.zip
must re-do DB operations on resume
-rw-r--r--src/backend/taler-merchant-httpd_get-orders-ID.c286
1 files changed, 143 insertions, 143 deletions
diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c b/src/backend/taler-merchant-httpd_get-orders-ID.c
index 4807c180..d6c877ca 100644
--- a/src/backend/taler-merchant-httpd_get-orders-ID.c
+++ b/src/backend/taler-merchant-httpd_get-orders-ID.c
@@ -297,7 +297,7 @@ suspend_god (struct GetOrderData *god)
TMH_long_poll_suspend (god->order_id,
god->hc->instance,
&god->sc,
- (god->sc.awaiting_refund)
+ god->sc.awaiting_refund
? &god->sc.refund_expected
: NULL);
}
@@ -1027,18 +1027,75 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh,
god->session_id = MHD_lookup_connection_value (connection,
MHD_GET_ARGUMENT_KIND,
"session_id");
+ } /* end of first-time initialization / sanity checks */
- /* Convert order_id to h_contract_terms */
- TMH_db->preflight (TMH_db->cls);
- {
- uint64_t order_serial;
+ /* Convert order_id to h_contract_terms */
+ TMH_db->preflight (TMH_db->cls);
+ {
+ uint64_t order_serial;
+
+ qs = TMH_db->lookup_contract_terms (TMH_db->cls,
+ hc->instance->settings.id,
+ order_id,
+ &god->contract_terms,
+ &order_serial);
+ }
+ if (0 > qs)
+ {
+ /* single, read-only SQL statements should never cause
+ serialization problems */
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR != qs);
+ /* Always report on hard error as well to enable diagnostics */
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GET_ORDERS_DB_LOOKUP_ERROR,
+ "database error looking up contract");
+ }
+
+ /* Check client provided the right hash code of the contract terms */
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+ {
+ struct GNUNET_HashCode h;
- qs = TMH_db->lookup_contract_terms (TMH_db->cls,
- hc->instance->settings.id,
- order_id,
- &god->contract_terms,
- &order_serial);
+ if (GNUNET_OK !=
+ TALER_JSON_contract_hash (god->contract_terms,
+ &h))
+ {
+ GNUNET_break (0);
+ GNUNET_free (god);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_INTERNAL_LOGIC_ERROR,
+ "Could not hash contract terms");
}
+ contract_match = (0 ==
+ GNUNET_memcmp (&h,
+ &god->h_contract_terms));
+ if ( (GNUNET_NO ==
+ GNUNET_is_zero (&god->h_contract_terms)) &&
+ (! contract_match) )
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_GET_ORDER_WRONG_CONTRACT,
+ "Contract hash does not match order");
+ }
+ }
+
+ if ( (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) ||
+ (! contract_match) )
+ {
+ struct TALER_ClaimTokenP db_claim_token;
+
+ qs = TMH_db->lookup_order (TMH_db->cls,
+ hc->instance->settings.id,
+ order_id,
+ &db_claim_token,
+ (NULL == god->contract_terms)
+ ? &god->contract_terms
+ : NULL);
if (0 > qs)
{
/* single, read-only SQL statements should never cause
@@ -1049,153 +1106,96 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh,
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GET_ORDERS_DB_LOOKUP_ERROR,
- "database error looking up contract");
+ "database error looking up order");
}
-
- /* Check client provided the right hash code of the contract terms */
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+ god->unclaimed = (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs);
+ if ( (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) &&
+ (NULL == god->contract_terms) )
{
- struct GNUNET_HashCode h;
-
- if (GNUNET_OK !=
- TALER_JSON_contract_hash (god->contract_terms,
- &h))
- {
- GNUNET_break (0);
- GNUNET_free (god);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_INTERNAL_LOGIC_ERROR,
- "Could not hash contract terms");
- }
- contract_match = (0 ==
- GNUNET_memcmp (&h,
- &god->h_contract_terms));
- if ( (GNUNET_NO ==
- GNUNET_is_zero (&god->h_contract_terms)) &&
- (! contract_match) )
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_FORBIDDEN,
- TALER_EC_GET_ORDER_WRONG_CONTRACT,
- "Contract hash does not match order");
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Unknown order id given: `%s'\n",
+ order_id);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_GET_ORDERS_ID_UNKNOWN,
+ "order_id not found in database");
}
- if ( (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) ||
- (! contract_match) )
- {
- struct TALER_ClaimTokenP db_claim_token;
-
- qs = TMH_db->lookup_order (TMH_db->cls,
- hc->instance->settings.id,
- order_id,
- &db_claim_token,
- (NULL == god->contract_terms)
- ? &god->contract_terms
- : NULL);
- if (0 > qs)
- {
- /* single, read-only SQL statements should never cause
- serialization problems */
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR != qs);
- /* Always report on hard error as well to enable diagnostics */
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GET_ORDERS_DB_LOOKUP_ERROR,
- "database error looking up order");
- }
- god->unclaimed = (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs);
- if ( (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) &&
- (NULL == god->contract_terms) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Unknown order id given: `%s'\n",
- order_id);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_GET_ORDERS_ID_UNKNOWN,
- "order_id not found in database");
- }
+ token_match = (0 == GNUNET_memcmp (&db_claim_token,
+ &god->claim_token));
+ } /* end unclaimed order logic */
- token_match = (0 == GNUNET_memcmp (&db_claim_token,
- &god->claim_token));
- } /* end unclaimed order logic */
+ {
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("fulfillment_url",
+ &god->fulfillment_url),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (god->contract_terms,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GET_ORDERS_DB_LOOKUP_ERROR,
+ "Merchant database error (contract terms corrupted)");
+ }
+ }
+ if ( (god->unclaimed) &&
+ (! token_match) )
+ {
+ /* Token wrong, and required because contract is unclaimed */
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_MERCHANT_GET_ORDER_INVALID_TOKEN,
+ "Claim token invalid");
+ }
+ if ( (! token_match) &&
+ (! contract_match) )
+ {
+ if (god->generate_html)
{
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("fulfillment_url",
- &god->fulfillment_url),
- GNUNET_JSON_spec_end ()
- };
+ /* Contract was claimed (maybe by another device), so this client
+ cannot get the status information. Redirect to fulfillment page,
+ where the client may be able to pickup a fresh order -- or might
+ be able authenticate via session ID */
+ struct MHD_Response *reply;
+ MHD_RESULT ret;
- if (GNUNET_OK !=
- GNUNET_JSON_parse (god->contract_terms,
- spec,
- NULL, NULL))
+ reply = MHD_create_response_from_buffer (0,
+ NULL,
+ MHD_RESPMEM_PERSISTENT);
+ if (NULL == reply)
{
GNUNET_break (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GET_ORDERS_DB_LOOKUP_ERROR,
- "Merchant database error (contract terms corrupted)");
+ return MHD_NO;
}
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (reply,
+ MHD_HTTP_HEADER_LOCATION,
+ god->fulfillment_url));
+ ret = MHD_queue_response (connection,
+ MHD_HTTP_FOUND,
+ reply);
+ MHD_destroy_response (reply);
+ return ret;
}
-
- if ( (god->unclaimed) &&
- (! token_match) )
- {
- /* Token wrong, and required because contract is unclaimed */
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_FORBIDDEN,
- TALER_EC_MERCHANT_GET_ORDER_INVALID_TOKEN,
- "Claim token invalid");
- }
- if ( (! token_match) &&
- (! contract_match) )
+ else
{
- if (god->generate_html)
- {
- /* Contract was claimed (maybe by another device), so this client
- cannot get the status information. Redirect to fulfillment page,
- where the client may be able to pickup a fresh order -- or might
- be able authenticate via session ID */
- struct MHD_Response *reply;
- MHD_RESULT ret;
-
- reply = MHD_create_response_from_buffer (0,
- NULL,
- MHD_RESPMEM_PERSISTENT);
- if (NULL == reply)
- {
- GNUNET_break (0);
- return MHD_NO;
- }
- GNUNET_break (MHD_YES ==
- MHD_add_response_header (reply,
- MHD_HTTP_HEADER_LOCATION,
- god->fulfillment_url));
- ret = MHD_queue_response (connection,
- MHD_HTTP_FOUND,
- reply);
- MHD_destroy_response (reply);
- return ret;
- }
- else
- {
- /* Need to generate JSON reply */
- return TALER_MHD_reply_json_pack (
- connection,
- MHD_HTTP_ACCEPTED,
- "{s:s}",
- "fulfillment_url",
- god->fulfillment_url);
- }
+ /* Need to generate JSON reply */
+ return TALER_MHD_reply_json_pack (
+ connection,
+ MHD_HTTP_ACCEPTED,
+ "{s:s}",
+ "fulfillment_url",
+ god->fulfillment_url);
}
- } /* end of first-time initialization / sanity checks */
+ }
if (god->unclaimed)
{