diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-09-10 17:00:26 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-09-10 17:00:26 +0200 |
commit | 801a505c178d456b29f5f4553dd30e9c1a038bb5 (patch) | |
tree | 92905d0e2f4096249021df5c802079dd1b6b3930 /src/backend/taler-merchant-httpd_private-get-orders-ID.c | |
parent | 26ff9653ab5a67847cecf0b225a18a48e2f76b7a (diff) | |
download | merchant-801a505c178d456b29f5f4553dd30e9c1a038bb5.tar.gz merchant-801a505c178d456b29f5f4553dd30e9c1a038bb5.tar.bz2 merchant-801a505c178d456b29f5f4553dd30e9c1a038bb5.zip |
fix long polling: need to re-fetch contract terms
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-get-orders-ID.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_private-get-orders-ID.c | 165 |
1 files changed, 85 insertions, 80 deletions
diff --git a/src/backend/taler-merchant-httpd_private-get-orders-ID.c b/src/backend/taler-merchant-httpd_private-get-orders-ID.c index 392954ce..1f47a475 100644 --- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c @@ -818,93 +818,98 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, hc->infix, GNUNET_STRINGS_absolute_time_to_string ( gorc->sc.long_poll_timeout)); - if (NULL == gorc->contract_terms) + if (NULL != gorc->contract_terms) + { + /* Clear old contract terms, might be from an earlier unclaimed contract + and thus could have changed during claiming. */ + json_decref (gorc->contract_terms); + gorc->contract_terms = NULL; + gorc->fulfillment_url = NULL; + } + TMH_db->preflight (TMH_db->cls); + qs = TMH_db->lookup_contract_terms (TMH_db->cls, + hc->instance->settings.id, + hc->infix, + &gorc->contract_terms, + &gorc->order_serial); + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) + { + struct GNUNET_HashCode unused; + + /* We don't have contract terms, but the order may still exist. */ + qs = TMH_db->lookup_order (TMH_db->cls, + hc->instance->settings.id, + hc->infix, + &claim_token, + &unused, + &gorc->contract_terms); + order_only = true; + } + if (0 > qs) { - TMH_db->preflight (TMH_db->cls); - qs = TMH_db->lookup_contract_terms (TMH_db->cls, - hc->instance->settings.id, - hc->infix, - &gorc->contract_terms, - &gorc->order_serial); - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == 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_FETCH_CONTRACT_TERMS_ERROR, + NULL); + } + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) + { + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_NOT_FOUND, + TALER_EC_GET_ORDERS_ORDER_NOT_FOUND, + hc->infix); + } + /* extract the fulfillment URL and total amount from the contract terms! */ + { + struct GNUNET_JSON_Specification spec[] = { + TALER_JSON_spec_amount ("amount", + &gorc->contract_amount), + GNUNET_JSON_spec_end () + }; + + if (GNUNET_OK != + GNUNET_JSON_parse (gorc->contract_terms, + spec, + NULL, NULL)) { - struct GNUNET_HashCode unused; - - /* We don't have contract terms, but the order may still exist. */ - qs = TMH_db->lookup_order (TMH_db->cls, - hc->instance->settings.id, - hc->infix, - &claim_token, - &unused, - &gorc->contract_terms); - order_only = true; + GNUNET_break (0); + return TALER_MHD_reply_with_error ( + connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GET_ORDERS_DB_FETCH_CONTRACT_TERMS_ERROR, + hc->infix); } - if (0 > qs) + if (0 != + strcasecmp (TMH_currency, + gorc->contract_amount.currency)) { - /* 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_FETCH_CONTRACT_TERMS_ERROR, - NULL); + GNUNET_break (0); + return TALER_MHD_reply_with_error ( + connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GET_ORDERS_DB_FETCH_CONTRACT_TERMS_ERROR, + gorc->contract_amount.currency); } - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) + } + gorc->fulfillment_url + = json_string_value (json_object_get (gorc->contract_terms, + "fulfillment_url")); + if (! order_only) + { + if (GNUNET_OK != + TALER_JSON_contract_hash (gorc->contract_terms, + &gorc->h_contract_terms)) { + GNUNET_break (0); return TALER_MHD_reply_with_error (connection, - MHD_HTTP_NOT_FOUND, - TALER_EC_GET_ORDERS_ORDER_NOT_FOUND, - hc->infix); - } - /* extract the fulfillment URL and total amount from the contract terms! */ - { - struct GNUNET_JSON_Specification spec[] = { - TALER_JSON_spec_amount ("amount", - &gorc->contract_amount), - GNUNET_JSON_spec_end () - }; - - if (GNUNET_OK != - GNUNET_JSON_parse (gorc->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_FETCH_CONTRACT_TERMS_ERROR, - hc->infix); - } - if (0 != - strcasecmp (TMH_currency, - gorc->contract_amount.currency)) - { - GNUNET_break (0); - return TALER_MHD_reply_with_error ( - connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GET_ORDERS_DB_FETCH_CONTRACT_TERMS_ERROR, - gorc->contract_amount.currency); - } - } - gorc->fulfillment_url - = json_string_value (json_object_get (gorc->contract_terms, - "fulfillment_url")); - if (! order_only) - { - if (GNUNET_OK != - TALER_JSON_contract_hash (gorc->contract_terms, - &gorc->h_contract_terms)) - { - GNUNET_break (0); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_GET_ORDERS_FAILED_COMPUTE_PROPOSAL_HASH, - NULL); - } + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GET_ORDERS_FAILED_COMPUTE_PROPOSAL_HASH, + NULL); } } if (TALER_EC_NONE != gorc->wire_ec) |