diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-04-27 04:53:17 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-04-27 04:53:17 +0200 |
commit | 20853863335ee4cd6a43044bfa1c8b38361cbc1f (patch) | |
tree | bb9edca91007d98f93d6ef1439e6d038fa7533cd /src/backend | |
parent | 68c440b0eb385ad80dec73843e021039b91b913c (diff) |
rename fest to match new structure
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/taler-merchant-httpd_get-orders-ID-2.c (renamed from src/backend/taler-merchant-httpd_orders_order_get.c) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_get-orders-ID-2.h (renamed from src/backend/taler-merchant-httpd_orders_order_get.h) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_get-orders-ID.c (renamed from src/backend/taler-merchant-httpd_orders_order_get2.c) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_get-orders-ID.h (renamed from src/backend/taler-merchant-httpd_orders_order_get2.h) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_get-orders.c | 299 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_get-reserves.c | 462 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_orders_get.h | 49 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_post-orders-ID-abort.c (renamed from src/backend/taler-merchant-httpd_orders_order_pay.c) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_post-orders-ID-abort.h (renamed from src/backend/taler-merchant-httpd_orders_order_abort.h) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_post-orders-ID-claim.c (renamed from src/backend/taler-merchant-httpd_orders_order_get5.c) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_post-orders-ID-claim.h (renamed from src/backend/taler-merchant-httpd_orders_order_get5.h) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_post-orders-ID-pay.c (renamed from src/backend/taler-merchant-httpd_post-orders-order-abort.c) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_post-orders-ID-pay.h (renamed from src/backend/taler-merchant-httpd_orders_order_pay.h) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_post-tips-ID-pickup.c (renamed from src/backend/taler-merchant-httpd_get-tips-tip.c) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_post-tips-ID-pickup.h (renamed from src/backend/taler-merchant-httpd_tips_tip_pickup.h) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_post-transfers.c | 1089 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-get-orders-ID.c (renamed from src/backend/taler-merchant-httpd_orders_order_get4.c) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-get-orders-ID.h (renamed from src/backend/taler-merchant-httpd_check-payment.h) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-get-reserves-ID.c (renamed from src/backend/taler-merchant-httpd_get-reserves-reserve.c) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-get-reserves-ID.h (renamed from src/backend/taler-merchant-httpd_reserves_reserve_get.h) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-get-transfers.c (renamed from src/backend/taler-merchant-httpd_get-transfers.c) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-get-transfers.h (renamed from src/backend/taler-merchant-httpd_transfers-get.h) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c (renamed from src/backend/taler-merchant-httpd_orders_order_refund.c) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-orders-ID-refund.h (renamed from src/backend/taler-merchant-httpd_orders_order_refund.h) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-orders-ID-track-UNSPEC.c (renamed from src/backend/taler-merchant-httpd_orders_order_get3.c) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-orders-ID-track-UNSPEC.h (renamed from src/backend/taler-merchant-httpd_track-transaction.h) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c (renamed from src/backend/taler-merchant-httpd_post-tips.c) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.h (renamed from src/backend/taler-merchant-httpd_tips_post.h) | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_refund.h | 71 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_reserves_get.h | 153 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_transfers-post.h | 49 |
31 files changed, 0 insertions, 2172 deletions
diff --git a/src/backend/taler-merchant-httpd_orders_order_get.c b/src/backend/taler-merchant-httpd_get-orders-ID-2.c index 6ca4fcce..6ca4fcce 100644 --- a/src/backend/taler-merchant-httpd_orders_order_get.c +++ b/src/backend/taler-merchant-httpd_get-orders-ID-2.c diff --git a/src/backend/taler-merchant-httpd_orders_order_get.h b/src/backend/taler-merchant-httpd_get-orders-ID-2.h index ac13c4a3..ac13c4a3 100644 --- a/src/backend/taler-merchant-httpd_orders_order_get.h +++ b/src/backend/taler-merchant-httpd_get-orders-ID-2.h diff --git a/src/backend/taler-merchant-httpd_orders_order_get2.c b/src/backend/taler-merchant-httpd_get-orders-ID.c index e86e4e4b..e86e4e4b 100644 --- a/src/backend/taler-merchant-httpd_orders_order_get2.c +++ b/src/backend/taler-merchant-httpd_get-orders-ID.c diff --git a/src/backend/taler-merchant-httpd_orders_order_get2.h b/src/backend/taler-merchant-httpd_get-orders-ID.h index 24495daf..24495daf 100644 --- a/src/backend/taler-merchant-httpd_orders_order_get2.h +++ b/src/backend/taler-merchant-httpd_get-orders-ID.h diff --git a/src/backend/taler-merchant-httpd_get-orders.c b/src/backend/taler-merchant-httpd_get-orders.c deleted file mode 100644 index dd353208..00000000 --- a/src/backend/taler-merchant-httpd_get-orders.c +++ /dev/null @@ -1,299 +0,0 @@ -/* - This file is part of TALER - (C) 2014, 2015, 2016, 2017 INRIA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -*/ -/** - * @file backend/taler-merchant-httpd_history.c - * @brief HTTP serving layer mainly intended to communicate with the frontend - * @author Marcello Stanisci - */ -#include "platform.h" -#include <jansson.h> -#include <taler/taler_signatures.h> -#include <taler/taler_json_lib.h> -#include "taler-merchant-httpd.h" - - -/** - * Closure for #pd_cb. - */ -struct ProcessContractClosure -{ - - /** - * Updated by #pd_cb to build the response. - */ - json_t *response; - - /** - * Set to #GNUNET_SYSERR if the database returned a contract - * that was not well-formed. - */ - int failure; - -}; - - -/** - * Function called with information about a transaction. - * - * @param cls closure of type `struct ProcessContractClosure` - * @param order_id transaction's order ID. - * @param row_id serial numer of the transaction in the table, - * used as index by the frontend to skip previous results. - */ -static void -pd_cb (void *cls, - const char *order_id, - uint64_t row_id, - const json_t *contract_terms) -{ - struct ProcessContractClosure *pcc = cls; - json_t *entry; - json_t *amount; - json_t *timestamp; - json_t *instance; - json_t *summary; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "/history's row_id: %llu\n", - (unsigned long long) row_id); - summary = NULL; - if (-1 == json_unpack ((json_t *) contract_terms, - "{s:o, s:o, s:{s:o}, s?:o}", - "amount", &amount, - "timestamp", ×tamp, - "merchant", "instance", &instance, - "summary", &summary)) - { - GNUNET_break (0); - pcc->failure = GNUNET_SYSERR; - return; - } - - /* summary is optional, but we need something, so we use - the order ID if it is not given. */ - if (NULL == summary) - summary = json_string (order_id); - - if (NULL == (entry = - json_pack ("{s:I, s:s, s:O, s:O, s:O, s:O}", - "row_id", row_id, - "order_id", order_id, - "amount", amount, - "timestamp", timestamp, - "instance", instance, - "summary", summary))) - { - GNUNET_break (0); - pcc->failure = GNUNET_SYSERR; - return; - } - if (0 != - json_array_append_new (pcc->response, - entry)) - { - GNUNET_break (0); - pcc->failure = GNUNET_SYSERR; - json_decref (entry); - return; - } -} - - -/** - * Manage a /history request. Query the db and returns transactions - * younger than the date given as parameter - * - * @param rh context of the handler - * @param connection the MHD connection to handle - * @param[in,out] connection_cls the connection's closure (can be updated) - * @param upload_data upload data - * @param[in,out] upload_data_size number of bytes (left) in @a upload_data - * @param mi merchant backend instance, never NULL - * @return MHD result code - */ -MHD_RESULT -MH_handler_history (struct TMH_RequestHandler *rh, - struct MHD_Connection *connection, - void **connection_cls, - const char *upload_data, - size_t *upload_data_size, - struct MerchantInstance *mi) -{ - #define LOG_INFO(...) GNUNET_log (GNUNET_ERROR_TYPE_INFO, __VA_ARGS__) - const char *str; - struct GNUNET_TIME_Absolute date; - json_t *response; - MHD_RESULT ret; - unsigned int ascending = GNUNET_NO; - unsigned long long seconds; - unsigned long long start = INT64_MAX; - long long delta = -20; - enum GNUNET_DB_QueryStatus qs; - struct ProcessContractClosure pcc; - - LOG_INFO ("Serving /history\n"); - response = json_array (); - str = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "date"); - date = GNUNET_TIME_absolute_get (); - (void) GNUNET_TIME_round_abs (&date); - if (NULL != str) - { - if (1 != sscanf (str, - "%llu", - &seconds)) - { - json_decref (response); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_PARAMETER_MALFORMED, - "date"); - } - date.abs_value_us = seconds * 1000LL * 1000LL; - if (date.abs_value_us / 1000LL / 1000LL != seconds) - { - json_decref (response); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_HISTORY_TIMESTAMP_OVERFLOW, - "Timestamp overflowed"); - } - } - - /* Sanity check that we don't have some odd stale transaction running */ - db->preflight (db->cls); - - /* Here goes the cherry-picking logic */ - str = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "order_id"); - if (NULL != str) - { - pcc.response = response; - pcc.failure = GNUNET_NO; - qs = db->find_contract_terms_history (db->cls, - str, - &mi->pubkey, - &pd_cb, - &pcc); - /* 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); - if ( (0 > qs) || - (GNUNET_SYSERR == pcc.failure) ) - { - json_decref (response); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_HISTORY_DB_FETCH_ERROR, - "db error to get history"); - } - ret = TALER_MHD_reply_json (connection, - response, - MHD_HTTP_OK); - json_decref (response); - return ret; - } - - str = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "start"); - if (NULL != str) - { - TALER_LOG_DEBUG ("'start' argument given ('%s')\n", - str); - if (1 != sscanf (str, - "%llu", - &start)) - { - json_decref (response); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_PARAMETER_MALFORMED, - "start"); - } - } - - str = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "delta"); - - if (NULL != str) - { - if (1 != sscanf (str, - "%lld", - &delta)) - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_PARAMETER_MALFORMED, - "delta"); - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Querying history back to %s, start: %llu, delta: %lld\n", - GNUNET_STRINGS_absolute_time_to_string (date), - start, - delta); - - pcc.response = response; - pcc.failure = GNUNET_NO; - - str = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "ordering"); - if ( (NULL != str) && - (0 == strcmp ("ascending", - str)) ) - ascending = GNUNET_YES; - - qs = db->find_contract_terms_by_date_and_range (db->cls, - date, - &mi->pubkey, - start, - llabs (delta), - (delta < 0) ? GNUNET_YES : - GNUNET_NO, - ascending, - &pd_cb, - &pcc); - if ( (0 > qs) || - (GNUNET_SYSERR == pcc.failure) ) - { - /* 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); - json_decref (response); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_EC_HISTORY_DB_FETCH_ERROR, - "db error to get history"); - } - ret = TALER_MHD_reply_json_pack (connection, - MHD_HTTP_OK, - "{ s:o }", - "history", - response /* consumes 'response' */); - LOG_INFO ("/history, http code: %d\n", - MHD_HTTP_OK); - return ret; -} - - -/* end of taler-merchant-httpd_history.c */ diff --git a/src/backend/taler-merchant-httpd_get-reserves.c b/src/backend/taler-merchant-httpd_get-reserves.c deleted file mode 100644 index e104e089..00000000 --- a/src/backend/taler-merchant-httpd_get-reserves.c +++ /dev/null @@ -1,462 +0,0 @@ -/* - This file is part of TALER - (C) 2018--2020 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -*/ -/** - * @file backend/taler-merchant-httpd_tip-reserve-helper.c - * @brief helper functions to check the status of a tipping reserve - * @author Christian Grothoff - */ -#include "platform.h" -#include "taler-merchant-httpd_tip-reserve-helper.h" - - -/** - * Head of active ctr context DLL. - */ -static struct TMH_CheckTipReserve *ctr_head; - -/** - * Tail of active ctr context DLL. - */ -static struct TMH_CheckTipReserve *ctr_tail; - - -/** - * Resume connection underlying @a ctr. - * - * @param ctr what to resume - */ -static void -resume_ctr (struct TMH_CheckTipReserve *ctr) -{ - GNUNET_assert (GNUNET_YES == ctr->suspended); - GNUNET_CONTAINER_DLL_remove (ctr_head, - ctr_tail, - ctr); - MHD_resume_connection (ctr->connection); - TMH_trigger_daemon (); /* we resumed, kick MHD */ -} - - -/** - * Resume the given context and send the given response. Stores the response - * in the @a ctr and signals MHD to resume the connection. Also ensures MHD - * runs immediately. - * - * @param ctr tip reserve query helper context - * @param response_code response code to use - * @param response response data to send back - */ -static void -resume_with_response (struct TMH_CheckTipReserve *ctr, - unsigned int response_code, - struct MHD_Response *response) -{ - ctr->response_code = response_code; - ctr->response = response; - resume_ctr (ctr); - ctr->suspended = GNUNET_NO; -} - - -/** - * Function called with the result of the /reserve/status request - * for the tipping reserve. Update our database balance with the - * result. - * - * @param cls closure with a `struct TMH_CheckTipReserve *' - * @param hr HTTP response details - * @param balance current balance in the reserve, NULL on error - * @param history_length number of entries in the transaction history, 0 on error - * @param history detailed transaction history, NULL on error - */ -static void -handle_status (void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr, - const struct TALER_Amount *balance, - unsigned int history_length, - const struct TALER_EXCHANGE_ReserveHistory *history) -{ - struct TMH_CheckTipReserve *ctr = cls; - - ctr->rsh = NULL; - ctr->reserve_expiration = GNUNET_TIME_UNIT_ZERO_ABS; - if (MHD_HTTP_NOT_FOUND == hr->http_status) - { - resume_with_response ( - ctr, - MHD_HTTP_SERVICE_UNAVAILABLE, - TALER_MHD_make_json_pack ( - "{s:I, s:I, s:s, s:I, s:O}", - "code", (json_int_t) TALER_EC_TIP_QUERY_RESERVE_UNKNOWN_TO_EXCHANGE, - "exchange_http_status", hr->http_status, - "hint", "tipping reserve unknown at exchange", - "exchange_code", hr->ec, - "exchange_reply", hr->reply)); - return; - } - if (MHD_HTTP_OK != hr->http_status) - { - GNUNET_break_op (0); - resume_with_response ( - ctr, - MHD_HTTP_FAILED_DEPENDENCY, - TALER_MHD_make_json_pack ( - "{s:I, s:I, s:s, s:I, s:O}", - "code", (json_int_t) TALER_EC_TIP_QUERY_RESERVE_HISTORY_FAILED, - "exchange_http_status", hr->http_status, - "hint", "exchange failed to provide reserve history", - "exchange_code", (json_int_t) hr->ec, - "exchange_reply", hr->reply)); - return; - } - - if (0 == history_length) - { - GNUNET_break_op (0); - resume_with_response (ctr, - MHD_HTTP_FAILED_DEPENDENCY, - TALER_MHD_make_error ( - TALER_EC_TIP_QUERY_RESERVE_HISTORY_FAILED_EMPTY, - "Exchange returned empty reserve history")); - return; - } - - { - unsigned int found = UINT_MAX; - - for (unsigned int i = 0; i<history_length; i++) - if (TALER_EXCHANGE_RTT_CREDIT == history[i].type) - found = i; - if (UINT_MAX == found) - { - GNUNET_break_op (0); - resume_with_response (ctr, - MHD_HTTP_FAILED_DEPENDENCY, - TALER_MHD_make_error ( - TALER_EC_TIP_QUERY_RESERVE_HISTORY_INVALID_NO_DEPOSIT, - "Exchange returned invalid reserve history")); - return; - } - - if (0 != strcasecmp (TMH_currency, - history[found].amount.currency)) - { - GNUNET_break_op (0); - resume_with_response (ctr, - MHD_HTTP_SERVICE_UNAVAILABLE, - TALER_MHD_make_error ( - TALER_EC_TIP_QUERY_RESERVE_CURRENCY_MISMATCH, - "Exchange currency unexpected")); - return; - } - GNUNET_assert (GNUNET_OK == - TALER_amount_get_zero (history[found].amount.currency, - &ctr->amount_withdrawn)); - } - - if (GNUNET_YES == ctr->none_authorized) - ctr->amount_authorized = ctr->amount_withdrawn; /* aka zero */ - ctr->amount_deposited = ctr->amount_withdrawn; /* aka zero */ - - /* Update DB based on status! */ - for (unsigned int i = 0; i<history_length; i++) - { - const struct TALER_EXCHANGE_ReserveHistory *hi = &history[i]; - - switch (hi->type) - { - case TALER_EXCHANGE_RTT_CREDIT: - { - enum GNUNET_DB_QueryStatus qs; - struct GNUNET_HashCode uuid; - struct GNUNET_TIME_Absolute deposit_expiration; - - if (0 > - TALER_amount_add (&ctr->amount_deposited, - &ctr->amount_deposited, - &hi->amount)) - { - GNUNET_break_op (0); - resume_with_response ( - ctr, - MHD_HTTP_FAILED_DEPENDENCY, - TALER_MHD_make_error ( - TALER_EC_TIP_QUERY_RESERVE_HISTORY_ARITHMETIC_ISSUE_DEPOSIT, - "Exchange returned invalid reserve history (amount overflow)")); - return; - } - deposit_expiration = GNUNET_TIME_absolute_add ( - hi->details.in_details.timestamp, - ctr->idle_reserve_expiration_time); - /* We're interested in the latest DEPOSIT timestamp, since this determines the - * reserve's expiration date. Note that the history isn't chronologically ordered. */ - ctr->reserve_expiration = GNUNET_TIME_absolute_max ( - ctr->reserve_expiration, - deposit_expiration); - GNUNET_CRYPTO_hash (hi->details.in_details.wire_reference, - hi->details.in_details.wire_reference_size, - &uuid); - db->preflight (db->cls); - qs = db->enable_tip_reserve_TR (db->cls, - &ctr->reserve_priv, - &uuid, - &hi->amount, - deposit_expiration); - - if (0 > qs) - { - /* This is not inherently fatal for the client's request, so we merely log it */ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Database error updating tipping reserve status: %d\n", - qs); - } - } - break; - case TALER_EXCHANGE_RTT_WITHDRAWAL: - if (0 > - TALER_amount_add (&ctr->amount_withdrawn, - &ctr->amount_withdrawn, - &hi->amount)) - { - GNUNET_break_op (0); - resume_with_response ( - ctr, - MHD_HTTP_FAILED_DEPENDENCY, - TALER_MHD_make_error ( - TALER_EC_TIP_QUERY_RESERVE_HISTORY_ARITHMETIC_ISSUE_WITHDRAW, - "Exchange returned invalid reserve history (amount overflow)")); - return; - } - break; - case TALER_EXCHANGE_RTT_RECOUP: - { - enum GNUNET_DB_QueryStatus qs; - struct GNUNET_HashContext *hc; - struct GNUNET_HashCode uuid; - struct GNUNET_TIME_Absolute deposit_expiration; - struct GNUNET_TIME_AbsoluteNBO de; - - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Encountered unexpected recoup operation on tipping reserve\n"); - /* While unexpected, we can simply count these like deposits. */ - if (0 > - TALER_amount_add (&ctr->amount_deposited, - &ctr->amount_deposited, - &hi->amount)) - { - GNUNET_break_op (0); - resume_with_response ( - ctr, - MHD_HTTP_FAILED_DEPENDENCY, - TALER_MHD_make_error ( - TALER_EC_TIP_QUERY_RESERVE_HISTORY_ARITHMETIC_ISSUE_RECOUP, - "Exchange returned invalid reserve history (amount overflow)")); - return; - } - deposit_expiration = GNUNET_TIME_absolute_add ( - hi->details.recoup_details.timestamp, - ctr->idle_reserve_expiration_time); - ctr->reserve_expiration = GNUNET_TIME_absolute_max ( - ctr->reserve_expiration, - deposit_expiration); - de = GNUNET_TIME_absolute_hton (deposit_expiration); - hc = GNUNET_CRYPTO_hash_context_start (); - GNUNET_CRYPTO_hash_context_read ( - hc, - &hi->details.recoup_details.coin_pub, - sizeof (struct TALER_CoinSpendPublicKeyP)); - GNUNET_CRYPTO_hash_context_read (hc, - &de, - sizeof (de)); - GNUNET_CRYPTO_hash_context_finish (hc, - &uuid); - db->preflight (db->cls); - qs = db->enable_tip_reserve_TR (db->cls, - &ctr->reserve_priv, - &uuid, - &hi->amount, - deposit_expiration); - if (0 > qs) - { - /* This is not inherently fatal for the client's request, so we merely log it */ - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Database error updating tipping reserve status: %d\n", - qs); - } - } - break; - case TALER_EXCHANGE_RTT_CLOSE: - /* We count 'closing' amounts just like withdrawals */ - if (0 > - TALER_amount_add (&ctr->amount_withdrawn, - &ctr->amount_withdrawn, - &hi->amount)) - { - GNUNET_break_op (0); - resume_with_response ( - ctr, - MHD_HTTP_FAILED_DEPENDENCY, - TALER_MHD_make_error ( - TALER_EC_TIP_QUERY_RESERVE_HISTORY_ARITHMETIC_ISSUE_CLOSED, - "Exchange returned invalid reserve history (amount overflow)")); - return; - } - break; - } - } - - /* normal, non-error continuation */ - resume_with_response (ctr, - 0, - NULL); -} - - -/** - * Function called with the result of a #TMH_EXCHANGES_find_exchange() - * operation. Given the exchange handle, we will then interrogate - * the exchange about the status of the tipping reserve. - * - * @param cls closure with a `struct TMH_CheckTipReserve *` - * @param hr HTTP response details - * @param eh handle to the exchange context - * @param wire_fee current applicable wire fee for dealing with @a eh, NULL if not available - * @param exchange_trusted #GNUNET_YES if this exchange is trusted by config - */ -static void -exchange_cont (void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr, - struct TALER_EXCHANGE_Handle *eh, - const struct TALER_Amount *wire_fee, - int exchange_trusted) -{ - struct TMH_CheckTipReserve *ctr = cls; - struct TALER_ReservePublicKeyP reserve_pub; - const struct TALER_EXCHANGE_Keys *keys; - - ctr->fo = NULL; - if (NULL == eh) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to contact exchange configured for tipping!\n"); - resume_with_response (ctr, - MHD_HTTP_FAILED_DEPENDENCY, - TALER_MHD_make_error ( - TALER_EC_TIP_QUERY_RESERVE_STATUS_FAILED_EXCHANGE_DOWN, - "Unable to obtain /keys from exchange")); - return; - } - keys = TALER_EXCHANGE_get_keys (eh); - GNUNET_assert (NULL != keys); - ctr->idle_reserve_expiration_time - = keys->reserve_closing_delay; - GNUNET_CRYPTO_eddsa_key_get_public (&ctr->reserve_priv.eddsa_priv, - &reserve_pub.eddsa_pub); - ctr->rsh = TALER_EXCHANGE_reserves_get (eh, - &reserve_pub, - &handle_status, - ctr); -} - - -/** - * Check the status of the given reserve at the given exchange. - * Suspends the MHD connection while this is happening and resumes - * processing once we know the reserve status (or once an error - * code has been determined). - * - * @param[in,out] ctr context for checking the reserve status - * @param tip_exchange the URL of the exchange to query - */ -void -TMH_check_tip_reserve (struct TMH_CheckTipReserve *ctr, - const char *tip_exchange) -{ - MHD_suspend_connection (ctr->connection); - ctr->suspended = GNUNET_YES; - GNUNET_CONTAINER_DLL_insert (ctr_head, - ctr_tail, - ctr); - db->preflight (db->cls); - ctr->fo = TMH_EXCHANGES_find_exchange (tip_exchange, - NULL, - GNUNET_NO, - &exchange_cont, - ctr); - if (NULL == ctr->fo) - { - GNUNET_break (0); - resume_with_response (ctr, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_MHD_make_error ( - TALER_EC_INTERNAL_INVARIANT_FAILURE, - "Unable to find exchange handle")); - } -} - - -/** - * Clean up any state that might be left in @a ctr. - * - * @param[in] context to clean up - */ -void -TMH_check_tip_reserve_cleanup (struct TMH_CheckTipReserve *ctr) -{ - if (NULL != ctr->rsh) - { - TALER_EXCHANGE_reserves_get_cancel (ctr->rsh); - ctr->rsh = NULL; - } - if (NULL != ctr->fo) - { - TMH_EXCHANGES_find_exchange_cancel (ctr->fo); - ctr->fo = NULL; - } - if (NULL != ctr->response) - { - MHD_destroy_response (ctr->response); - ctr->response = NULL; - } - if (MHD_YES == ctr->suspended) - { - resume_ctr (ctr); - ctr->suspended = GNUNET_NO; - } -} - - -/** - * Force all tip reserve helper contexts to be resumed as we are about to shut - * down MHD. - */ -void -MH_force_trh_resume () -{ - struct TMH_CheckTipReserve *n; - - for (struct TMH_CheckTipReserve *ctr = ctr_head; - NULL != ctr; - ctr = n) - { - n = ctr->next; - resume_ctr (ctr); - ctr->suspended = GNUNET_SYSERR; - } -} - - -/* end of taler-merchant-httpd_tip-reserve-helper.c */ diff --git a/src/backend/taler-merchant-httpd_orders_get.h b/src/backend/taler-merchant-httpd_orders_get.h deleted file mode 100644 index eac987dd..00000000 --- a/src/backend/taler-merchant-httpd_orders_get.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - This file is part of TALER - (C) 2014, 2015, 2016 INRIA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -*/ -/** - * @file backend/taler-merchant-httpd_history.c - * @brief HTTP serving layer mainly intended to communicate with the frontend - * @author Marcello Stanisci - */ - -#ifndef TALER_MERCHANT_HTTPD_HISTORY_H -#define TALER_MERCHANT_HTTPD_HISTORY_H -#include <microhttpd.h> -#include "taler-merchant-httpd.h" - - -/** - * Manage a /history request. Query the db and returns transactions - * younger than the date given as parameter - * - * @param rh context of the handler - * @param connection the MHD connection to handle - * @param[in,out] connection_cls the connection's closure (can be updated) - * @param upload_data upload data - * @param[in,out] upload_data_size number of bytes (left) in @a upload_data - * @param mi merchant backend instance, never NULL - * @return MHD result code - */ -MHD_RESULT -MH_handler_history (struct TMH_RequestHandler *rh, - struct MHD_Connection *connection, - void **connection_cls, - const char *upload_data, - size_t *upload_data_size, - struct MerchantInstance *mi); - -/* end of taler-merchant-httpd_history.c */ -#endif diff --git a/src/backend/taler-merchant-httpd_orders_order_pay.c b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c index 7a1b7fd8..7a1b7fd8 100644 --- a/src/backend/taler-merchant-httpd_orders_order_pay.c +++ b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c diff --git a/src/backend/taler-merchant-httpd_orders_order_abort.h b/src/backend/taler-merchant-httpd_post-orders-ID-abort.h index 726a27be..726a27be 100644 --- a/src/backend/taler-merchant-httpd_orders_order_abort.h +++ b/src/backend/taler-merchant-httpd_post-orders-ID-abort.h diff --git a/src/backend/taler-merchant-httpd_orders_order_get5.c b/src/backend/taler-merchant-httpd_post-orders-ID-claim.c index 47207131..47207131 100644 --- a/src/backend/taler-merchant-httpd_orders_order_get5.c +++ b/src/backend/taler-merchant-httpd_post-orders-ID-claim.c diff --git a/src/backend/taler-merchant-httpd_orders_order_get5.h b/src/backend/taler-merchant-httpd_post-orders-ID-claim.h index 677fee0e..677fee0e 100644 --- a/src/backend/taler-merchant-httpd_orders_order_get5.h +++ b/src/backend/taler-merchant-httpd_post-orders-ID-claim.h diff --git a/src/backend/taler-merchant-httpd_post-orders-order-abort.c b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c index 7a1b7fd8..7a1b7fd8 100644 --- a/src/backend/taler-merchant-httpd_post-orders-order-abort.c +++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c diff --git a/src/backend/taler-merchant-httpd_orders_order_pay.h b/src/backend/taler-merchant-httpd_post-orders-ID-pay.h index 726a27be..726a27be 100644 --- a/src/backend/taler-merchant-httpd_orders_order_pay.h +++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.h diff --git a/src/backend/taler-merchant-httpd_get-tips-tip.c b/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c index 42066e3c..42066e3c 100644 --- a/src/backend/taler-merchant-httpd_get-tips-tip.c +++ b/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c diff --git a/src/backend/taler-merchant-httpd_tips_tip_pickup.h b/src/backend/taler-merchant-httpd_post-tips-ID-pickup.h index 6fdba31a..6fdba31a 100644 --- a/src/backend/taler-merchant-httpd_tips_tip_pickup.h +++ b/src/backend/taler-merchant-httpd_post-tips-ID-pickup.h diff --git a/src/backend/taler-merchant-httpd_post-transfers.c b/src/backend/taler-merchant-httpd_post-transfers.c deleted file mode 100644 index 7f55c917..00000000 --- a/src/backend/taler-merchant-httpd_post-transfers.c +++ /dev/null @@ -1,1089 +0,0 @@ -/* - This file is part of TALER - (C) 2014-2020 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -*/ -/** - * @file backend/taler-merchant-httpd_track-transfer.c - * @brief implement API for tracking transfers and wire transfers - * @author Marcello Stanisci - * @author Christian Grothoff - */ -#include "platform.h" -#include <jansson.h> -#include <taler/taler_signatures.h> -#include <taler/taler_json_lib.h> -#include "taler-merchant-httpd.h" -#include "taler-merchant-httpd_mhd.h" -#include "taler-merchant-httpd_auditors.h" -#include "taler-merchant-httpd_exchanges.h" -#include "taler-merchant-httpd_track-transfer.h" - - -/** - * How long to wait before giving up processing with the exchange? - */ -#define TRACK_TIMEOUT (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ - 30)) - -/** - * How often do we retry the simple INSERT database transaction? - */ -#define MAX_RETRIES 3 - -/** - * Context used for handing /track/transfer requests. - */ -struct TrackTransferContext -{ - - /** - * This MUST be first! - */ - struct TM_HandlerContext hc; - - /** - * Handle to the exchange. - */ - struct TALER_EXCHANGE_Handle *eh; - - /** - * Handle for the /wire/transfers request. - */ - struct TALER_EXCHANGE_TransfersGetHandle *wdh; - - /** - * For which merchant instance is this tracking request? - */ - struct MerchantInstance *mi; - - /** - * HTTP connection we are handling. - */ - struct MHD_Connection *connection; - - /** - * Response to return upon resume. - */ - struct MHD_Response *response; - - /** - * Handle for operation to lookup /keys (and auditors) from - * the exchange used for this transaction; NULL if no operation is - * pending. - */ - struct TMH_EXCHANGES_FindOperation *fo; - - /** - * Task run on timeout. - */ - struct GNUNET_SCHEDULER_Task *timeout_task; - - /** - * URL of the exchange. - */ - char *url; - - /** - * Wire method used for the transfer. - */ - char *wire_method; - - /** - * Pointer to the detail that we are currently - * checking in #check_transfer(). - */ - const struct TALER_TrackTransferDetails *current_detail; - - /** - * Argument for the /wire/transfers request. - */ - struct TALER_WireTransferIdentifierRawP wtid; - - /** - * Full original response we are currently processing. - */ - const json_t *original_response; - - /** - * Modified response to return to the frontend. - */ - json_t *deposits_response; - - /** - * Which transaction detail are we currently looking at? - */ - unsigned int current_offset; - - /** - * Response code to return. - */ - unsigned int response_code; - - /** - * #GNUNET_NO if we did not find a matching coin. - * #GNUNET_SYSERR if we found a matching coin, but the amounts do not match. - * #GNUNET_OK if we did find a matching coin. - */ - int check_transfer_result; -}; - - -/** - * Represents an entry in the table used to sum up - * individual deposits for each h_contract_terms. - */ -struct Entry -{ - - /** - * Sum accumulator for deposited value. - */ - struct TALER_Amount deposit_value; - - /** - * Sum accumulator for deposit fee. - */ - struct TALER_Amount deposit_fee; - -}; - - -/** - * Free the @a rctx. - * - * @param rctx data to free - */ -static void -free_transfer_track_context (struct TrackTransferContext *rctx) -{ - if (NULL != rctx->fo) - { - TMH_EXCHANGES_find_exchange_cancel (rctx->fo); - rctx->fo = NULL; - } - if (NULL != rctx->timeout_task) - { - GNUNET_SCHEDULER_cancel (rctx->timeout_task); - rctx->timeout_task = NULL; - } - if (NULL != rctx->wdh) - { - TALER_EXCHANGE_transfers_get_cancel (rctx->wdh); - rctx->wdh = NULL; - } - if (NULL != rctx->url) - { - GNUNET_free (rctx->url); - rctx->url = NULL; - } - if (NULL != rctx->wire_method) - { - GNUNET_free (rctx->wire_method); - rctx->wire_method = NULL; - } - GNUNET_free (rctx); -} - - -/** - * Callback that frees all the elements in the hashmap - * - * @param cls closure, NULL - * @param key current key - * @param value a `struct Entry` - * @return #GNUNET_YES if the iteration should continue, - * #GNUNET_NO otherwise. - */ -static int -hashmap_free (void *cls, - const struct GNUNET_HashCode *key, - void *value) -{ - struct TALER_Entry *entry = value; - - (void) cls; - (void) key; - GNUNET_free (entry); - return GNUNET_YES; -} - - -/** - * Builds JSON response containing the summed-up amounts - * from individual deposits. - * - * @param cls closure - * @param key map's current key - * @param map's current value - * @return #GNUNET_YES if iteration is to be continued, - * #GNUNET_NO otherwise. - */ -static int -build_deposits_response (void *cls, - const struct GNUNET_HashCode *key, - void *value) -{ - struct TrackTransferContext *rctx = cls; - struct Entry *entry = value; - json_t *element; - json_t *contract_terms; - json_t *order_id; - - db->preflight (db->cls); - if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != - db->find_contract_terms_from_hash (db->cls, - &contract_terms, - key, - &rctx->mi->pubkey)) - { - GNUNET_break_op (0); - return GNUNET_NO; - } - - order_id = json_object_get (contract_terms, - "order_id"); - if (NULL == order_id) - { - GNUNET_break_op (0); - json_decref (contract_terms); - return GNUNET_NO; - } - element = json_pack ("{s:O, s:o, s:o}", - "order_id", order_id, - "deposit_value", TALER_JSON_from_amount ( - &entry->deposit_value), - "deposit_fee", TALER_JSON_from_amount ( - &entry->deposit_fee)); - json_decref (contract_terms); - if (NULL == element) - { - GNUNET_break_op (0); - return GNUNET_NO; - } - GNUNET_break (0 == - json_array_append_new (rctx->deposits_response, - element)); - return GNUNET_YES; -} - - -/** - * Transform /track/transfer result as gotten from the exchange - * and transforms it in a format liked by the backoffice Web interface. - * - * @param result response from exchange's /track/transfer - * @result pointer to new JSON, or NULL upon errors. - */ -static json_t * -transform_response (const json_t *result, - struct TrackTransferContext *rctx) -{ - json_t *deposits; - json_t *value; - json_t *result_mod = NULL; - size_t index; - const char *key; - struct GNUNET_HashCode h_key; - struct GNUNET_CONTAINER_MultiHashMap *map; - struct TALER_Amount iter_value; - struct TALER_Amount iter_fee; - struct Entry *current_entry; - struct GNUNET_JSON_Specification spec[] = { - TALER_JSON_spec_amount ("deposit_value", &iter_value), - TALER_JSON_spec_amount ("deposit_fee", &iter_fee), - GNUNET_JSON_spec_string ("h_contract_terms", &key), - GNUNET_JSON_spec_end () - }; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Transforming /track/transfer response.\n"); - map = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO); - deposits = json_object_get (result, - "deposits"); - - json_array_foreach (deposits, index, value) - { - if (GNUNET_OK != - GNUNET_JSON_parse (value, - spec, - NULL, - NULL)) - { - GNUNET_break_op (0); - return NULL; - } - GNUNET_CRYPTO_hash_from_string (key, - &h_key); - - if (NULL != (current_entry = - GNUNET_CONTAINER_multihashmap_get (map, - &h_key))) - { - /* The map already knows this h_contract_terms*/ - if ( (0 > - TALER_amount_add (¤t_entry->deposit_value, - ¤t_entry->deposit_value, - &iter_value)) || - (0 > - TALER_amount_add (¤t_entry->deposit_fee, - ¤t_entry->deposit_fee, - &iter_fee)) ) - { - GNUNET_JSON_parse_free (spec); - goto cleanup; - } - } - else - { - /* First time in the map for this h_contract_terms*/ - current_entry = GNUNET_new (struct Entry); - current_entry->deposit_value = iter_value; - current_entry->deposit_fee = iter_fee; - - if (GNUNET_SYSERR == - GNUNET_CONTAINER_multihashmap_put (map, - &h_key, - current_entry, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) - { - GNUNET_JSON_parse_free (spec); - goto cleanup; - } - } - GNUNET_JSON_parse_free (spec); - } - rctx->deposits_response = json_array (); - - if (GNUNET_SYSERR == - GNUNET_CONTAINER_multihashmap_iterate (map, - &build_deposits_response, - rctx)) - goto cleanup; - - result_mod = json_copy ((struct json_t *) result); - json_object_del (result_mod, - "deposits"); - json_object_set_new (result_mod, - "deposits_sums", - rctx->deposits_response); - rctx->deposits_response = NULL; -cleanup: - GNUNET_CONTAINER_multihashmap_iterate (map, - &hashmap_free, - NULL); - GNUNET_CONTAINER_multihashmap_destroy (map); - return result_mod; -} - - -/** - * Resume the given /track/transfer operation and send the given response. - * Stores the response in the @a rctx and signals MHD to resume - * the connection. Also ensures MHD runs immediately. - * - * @param rctx transfer tracking context - * @param response_code response code to use - * @param response response data to send back - */ -static void -resume_track_transfer_with_response (struct TrackTransferContext *rctx, - unsigned int response_code, - struct MHD_Response *response) -{ - rctx->response_code = response_code; - rctx->response = response; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Resuming /track/transfer handling as exchange interaction is done (%u)\n", - response_code); - if (NULL != rctx->timeout_task) - { - GNUNET_SCHEDULER_cancel (rctx->timeout_task); - rctx->timeout_task = NULL; - } - MHD_resume_connection (rctx->connection); - TMH_trigger_daemon (); /* we resumed, kick MHD */ -} - - -/** - * Custom cleanup routine for a `struct TrackTransferContext`. - * - * @param hc the `struct TrackTransferContext` to clean up. - */ -static void -track_transfer_cleanup (struct TM_HandlerContext *hc) -{ - struct TrackTransferContext *rctx = (struct TrackTransferContext *) hc; - - free_transfer_track_context (rctx); -} - - -/** - * This function checks that the information about the coin which - * was paid back by _this_ wire transfer matches what _we_ (the merchant) - * knew about this coin. - * - * @param cls closure with our `struct TrackTransferContext *` - * @param transaction_id of the contract - * @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 transfer 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 exchange_proof proof from exchange that coin was accepted - */ -static void -check_transfer (void *cls, - const struct GNUNET_HashCode *h_contract_terms, - const struct TALER_CoinSpendPublicKeyP *coin_pub, - const char *exchange_url, - 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) -{ - struct TrackTransferContext *rctx = cls; - const struct TALER_TrackTransferDetails *ttd = rctx->current_detail; - - if (GNUNET_SYSERR == rctx->check_transfer_result) - return; /* already had a serious issue; odd that we're called more than once as well... */ - if ( (0 != TALER_amount_cmp (amount_with_fee, - &ttd->coin_value)) || - (0 != TALER_amount_cmp (deposit_fee, - &ttd->coin_fee)) ) - { - /* Disagreement between the exchange and us about how much this - coin is worth! */ - GNUNET_break_op (0); - rctx->check_transfer_result = GNUNET_SYSERR; - /* Build the `TrackTransferConflictDetails` */ - rctx->response - = TALER_MHD_make_json_pack ( - "{s:I, s:s, s:o, s:I, s:o, s:o, s:s, s:o, s:o}", - "code", (json_int_t) TALER_EC_TRACK_TRANSFER_CONFLICTING_REPORTS, - "hint", "disagreement about deposit valuation", - "exchange_deposit_proof", exchange_proof, - "conflict_offset", (json_int_t) rctx->current_offset, - "exchange_transfer_proof", rctx->original_response, - "coin_pub", GNUNET_JSON_from_data_auto (coin_pub), - "h_contract_terms", GNUNET_JSON_from_data_auto ( - &ttd->h_contract_terms), - "amount_with_fee", TALER_JSON_from_amount (amount_with_fee), - "deposit_fee", TALER_JSON_from_amount (deposit_fee)); - return; - } - rctx->check_transfer_result = GNUNET_OK; -} - - -/** - * Check that the given @a wire_fee is what the - * @a exchange_pub should charge at the @a execution_time. - * If the fee is correct (according to our database), - * return #GNUNET_OK. If we do not have the fee structure - * in our DB, we just accept it and return #GNUNET_NO; - * if we have proof that the fee is bogus, we respond with - * the proof to the client and return #GNUNET_SYSERR. - * - * @param rctx context of the transfer to respond to - * @param json response from the exchange - * @param execution_time time of the wire transfer - * @param wire_fee fee claimed by the exchange - * @return #GNUNET_SYSERR if we returned hard proof of - * missbehavior from the exchange to the client - */ -static int -check_wire_fee (struct TrackTransferContext *rctx, - const json_t *json, - struct GNUNET_TIME_Absolute execution_time, - const struct TALER_Amount *wire_fee) -{ - const struct TALER_MasterPublicKeyP *master_pub; - struct GNUNET_HashCode h_wire_method; - struct TALER_Amount expected_fee; - struct TALER_Amount closing_fee; - struct TALER_MasterSignatureP master_sig; - struct GNUNET_TIME_Absolute start_date; - struct GNUNET_TIME_Absolute end_date; - enum GNUNET_DB_QueryStatus qs; - const struct TALER_EXCHANGE_Keys *keys; - - keys = TALER_EXCHANGE_get_keys (rctx->eh); - if (NULL == keys) - { - GNUNET_break (0); - return GNUNET_NO; - } - master_pub = &keys->master_pub; - GNUNET_CRYPTO_hash (rctx->wire_method, - strlen (rctx->wire_method) + 1, - &h_wire_method); - db->preflight (db->cls); - qs = db->lookup_wire_fee (db->cls, - master_pub, - &h_wire_method, - execution_time, - &expected_fee, - &closing_fee, - &start_date, - &end_date, - &master_sig); - if (0 >= qs) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Failed to find wire fee for `%s' and method `%s' at %s in DB, accepting blindly that the fee is %s\n", - TALER_B2S (master_pub), - rctx->wire_method, - GNUNET_STRINGS_absolute_time_to_string (execution_time), - TALER_amount2s (wire_fee)); - return GNUNET_NO; - } - if (0 <= TALER_amount_cmp (&expected_fee, - wire_fee)) - return GNUNET_OK; /* expected_fee >= wire_fee */ - - /* Wire fee check failed, export proof to client */ - resume_track_transfer_with_response ( - rctx, - MHD_HTTP_FAILED_DEPENDENCY, - TALER_MHD_make_json_pack ( - "{s:I, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:O}", - "code", (json_int_t) TALER_EC_TRACK_TRANSFER_JSON_BAD_WIRE_FEE, - "wire_fee", TALER_JSON_from_amount (wire_fee), - "execution_time", GNUNET_JSON_from_time_abs (execution_time), - "expected_wire_fee", TALER_JSON_from_amount (&expected_fee), - "expected_closing_fee", TALER_JSON_from_amount (&closing_fee), - "start_date", GNUNET_JSON_from_time_abs (start_date), - "end_date", GNUNET_JSON_from_time_abs (end_date), - "master_sig", GNUNET_JSON_from_data_auto (&master_sig), - "master_pub", GNUNET_JSON_from_data_auto (master_pub), - "json", json)); - return GNUNET_SYSERR; -} - - -/** - * Function called with detailed wire transfer data, including all - * of the coin transactions that were combined into the wire transfer. - * - * @param cls closure - * @param hr HTTP response details - * @param exchange_pub public key of the exchange used to sign @a json - * @param h_wire hash of the wire transfer address the transfer went to, or NULL on error - * @param execution_time time when the exchange claims to have performed the wire transfer - * @param total_amount total amount of the wire transfer, or NULL if the exchange could - * not provide any @a wtid (set only if @a http_status is #MHD_HTTP_OK) - * @param wire_fee wire fee that was charged by the exchange - * @param details_length length of the @a details array - * @param details array with details about the combined transactions - */ -static void -wire_transfer_cb (void *cls, - const struct TALER_EXCHANGE_HttpResponse *hr, - const struct TALER_ExchangePublicKeyP *exchange_pub, - const struct GNUNET_HashCode *h_wire, - struct GNUNET_TIME_Absolute execution_time, - const struct TALER_Amount *total_amount, - const struct TALER_Amount *wire_fee, - unsigned int details_length, - const struct TALER_TrackTransferDetails *details) -{ - struct TrackTransferContext *rctx = cls; - json_t *jresponse; - enum GNUNET_DB_QueryStatus qs; - - rctx->wdh = NULL; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Got response code %u from exchange for /track/transfer\n", - hr->http_status); - if (MHD_HTTP_OK != hr->http_status) - { - resume_track_transfer_with_response ( - rctx, - MHD_HTTP_FAILED_DEPENDENCY, - TALER_MHD_make_json_pack ( - "{s:I, s:I, s:I, s:O}", - "code", (json_int_t) TALER_EC_TRACK_TRANSFER_EXCHANGE_ERROR, - "exchange_code", (json_int_t) hr->ec, - "exchange_http_status", (json_int_t) hr->http_status, - "exchange_reply", hr->reply)); - return; - } - for (unsigned int i = 0; i<MAX_RETRIES; i++) - { - db->preflight (db->cls); - qs = db->store_transfer_to_proof (db->cls, - rctx->url, - &rctx->wtid, - execution_time, - exchange_pub, - hr->reply); - if (GNUNET_DB_STATUS_SOFT_ERROR != qs) - break; - } - if (0 > qs) - { - /* Special report if retries insufficient */ - 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); - resume_track_transfer_with_response - (rctx, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_MHD_make_json_pack ("{s:I, s:s}", - "code", - (json_int_t) - TALER_EC_TRACK_TRANSFER_DB_STORE_TRANSFER_ERROR, - "details", - "failed to store response from exchange to local database")); - return; - } - rctx->original_response = hr->reply; - - if (GNUNET_SYSERR == - check_wire_fee (rctx, - hr->reply, - execution_time, - wire_fee)) - return; - - /* Now we want to double-check that any (Taler coin) deposit - * which is accounted into _this_ wire transfer, does exist - * into _our_ database. This is the rationale: if the - * exchange paid us for it, we must have received it _beforehands_! - * - * details_length is how many (Taler coin) deposits have been - * aggregated into _this_ wire transfer. - */// - for (unsigned int i = 0; i<details_length; i++) - { - rctx->current_offset = i; - rctx->current_detail = &details[i]; - /* Set the coin as "never seen" before. */ - rctx->check_transfer_result = GNUNET_NO; - db->preflight (db->cls); - qs = db->find_payments_by_hash_and_coin (db->cls, - &details[i].h_contract_terms, - &rctx->mi->pubkey, - &details[i].coin_pub, - &check_transfer, - rctx); - 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); - resume_track_transfer_with_response - (rctx, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_MHD_make_json_pack ("{s:I, s:s}", - "code", - (json_int_t) - TALER_EC_TRACK_TRANSFER_DB_FETCH_DEPOSIT_ERROR, - "details", - "failed to obtain deposit data from local database")); - return; - } - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) - { - /* The exchange says we made this deposit, but WE do not - recall making it (corrupted / unreliable database?)! - Well, let's say thanks and accept the money! */ - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Failed to find payment data in DB\n"); - rctx->check_transfer_result = GNUNET_OK; - } - if (GNUNET_NO == rctx->check_transfer_result) - { - /* Internal error: how can we have called #check_transfer() - but still have no result? */ - GNUNET_break (0); - resume_track_transfer_with_response - (rctx, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_MHD_make_json_pack ("{s:I, s:s, s:I, s:s}", - "code", - (json_int_t) - TALER_EC_TRACK_TRANSFER_DB_INTERNAL_LOGIC_ERROR, - "details", "internal logic error", - "line", (json_int_t) __LINE__, - "file", __FILE__)); - return; - } - if (GNUNET_SYSERR == rctx->check_transfer_result) - { - /* #check_transfer() failed, report conflict! */ - GNUNET_break_op (0); - GNUNET_assert (NULL != rctx->response); - resume_track_transfer_with_response - (rctx, - MHD_HTTP_FAILED_DEPENDENCY, - rctx->response); - rctx->response = NULL; - return; - } - /* Response is consistent with the /deposit we made, - remember it for future reference */ - for (unsigned int r = 0; r<MAX_RETRIES; r++) - { - db->preflight (db->cls); - qs = db->store_coin_to_transfer (db->cls, - &details[i].h_contract_terms, - &details[i].coin_pub, - &rctx->wtid); - if (GNUNET_DB_STATUS_SOFT_ERROR != qs) - break; - } - if (0 > qs) - { - /* Special report if retries insufficient */ - 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); - resume_track_transfer_with_response - (rctx, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_MHD_make_json_pack ("{s:I, s:s}", - "code", - (json_int_t) - TALER_EC_TRACK_TRANSFER_DB_STORE_COIN_ERROR, - "details", - "failed to store response from exchange to local database")); - return; - } - } - rctx->original_response = NULL; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "About to call tracks transformator.\n"); - - if (NULL == (jresponse = - transform_response (hr->reply, - rctx))) - { - resume_track_transfer_with_response - (rctx, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_MHD_make_error (TALER_EC_TRACK_TRANSFER_JSON_RESPONSE_ERROR, - "Fail to elaborate the response.")); - return; - } - - resume_track_transfer_with_response (rctx, - MHD_HTTP_OK, - TALER_MHD_make_json (jresponse)); - json_decref (jresponse); -} - - -/** - * Function called with the result of our exchange lookup. - * - * @param cls the `struct TrackTransferContext` - * @param hr HTTP response details - * @param eh NULL if exchange was not found to be acceptable - * @param wire_fee NULL (we did not specify a wire method) - * @param exchange_trusted #GNUNET_YES if this exchange is trusted by config - */ -static void -process_track_transfer_with_exchange (void *cls, - const struct - TALER_EXCHANGE_HttpResponse *hr, - struct TALER_EXCHANGE_Handle *eh, - const struct TALER_Amount *wire_fee, - int exchange_trusted) -{ - struct TrackTransferContext *rctx = cls; - - rctx->fo = NULL; - if (MHD_HTTP_OK != hr->http_status) - { - /* The request failed somehow */ - GNUNET_break_op (0); - resume_track_transfer_with_response ( - rctx, - MHD_HTTP_FAILED_DEPENDENCY, - TALER_MHD_make_json_pack ( - (NULL != hr->reply) - ? "{s:s, s:I, s:I, s:I, s:O}" - : "{s:s, s:I, s:I, s:I}", - "hint", "failed to obtain meta-data from exchange", - "code", (json_int_t) TALER_EC_TRACK_TRANSFER_EXCHANGE_KEYS_FAILURE, - "exchange_http_status", (json_int_t) hr->http_status, - "exchange_code", (json_int_t) hr->ec, - "exchange_reply", hr->reply)); - return; - } - rctx->eh = eh; - rctx->wdh = TALER_EXCHANGE_transfers_get (eh, - &rctx->wtid, - &wire_transfer_cb, - rctx); - if (NULL == rctx->wdh) - { - GNUNET_break (0); - resume_track_transfer_with_response - (rctx, - MHD_HTTP_INTERNAL_SERVER_ERROR, - TALER_MHD_make_json_pack ("{s:I, s:s}", - "code", - (json_int_t) - TALER_EC_TRACK_TRANSFER_REQUEST_ERROR, - "error", - "failed to run /transfers/ GET on exchange")); - } -} - - -/** - * Handle a timeout for the processing of the track transfer request. - * - * @param cls closure - */ -static void -handle_track_transfer_timeout (void *cls) -{ - struct TrackTransferContext *rctx = cls; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Resuming /track/transfer with error after timeout\n"); - rctx->timeout_task = NULL; - - if (NULL != rctx->fo) - { - TMH_EXCHANGES_find_exchange_cancel (rctx->fo); - rctx->fo = NULL; - } - resume_track_transfer_with_response (rctx, - MHD_HTTP_SERVICE_UNAVAILABLE, - TALER_MHD_make_error ( - TALER_EC_TRACK_TRANSFER_EXCHANGE_TIMEOUT, - "exchange not reachable")); -} - - -/** - * Function called with information about a wire transfer identifier. - * Generate a response based on the given @a proof. - * - * @param cls closure - * @param proof proof from exchange about what the wire transfer was for. - * should match the `TrackTransactionResponse` format - * of the exchange - */ -static void -proof_cb (void *cls, - const json_t *proof) -{ - struct TrackTransferContext *rctx = cls; - json_t *transformed_response; - - if (NULL == (transformed_response = - transform_response (proof, - rctx))) - { - rctx->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR; - rctx->response - = TALER_MHD_make_error (TALER_EC_TRACK_TRANSFER_JSON_RESPONSE_ERROR, - "Fail to elaborate response."); - return; - } - - rctx->response_code = MHD_HTTP_OK; - rctx->response = TALER_MHD_make_json (transformed_response); - json_decref (transformed_response); -} - - -/** - * Manages a /track/transfer call, thus it calls the /track/wtid - * offered by the exchange in order to return the set of transfers - * (of coins) associated with a given wire transfer. - * - * @param rh context of the handler - * @param connection the MHD connection to handle - * @param[in,out] connection_cls the connection's closure (can be updated) - * @param upload_data upload data - * @param[in,out] upload_data_size number of bytes (left) in @a upload_data - * @param mi merchant backend instance, never NULL - * @return MHD result code - */ -MHD_RESULT -MH_handler_track_transfer (struct TMH_RequestHandler *rh, - struct MHD_Connection *connection, - void **connection_cls, - const char *upload_data, - size_t *upload_data_size, - struct MerchantInstance *mi) -{ - struct TrackTransferContext *rctx; - const char *str; - const char *url; - const char *wire_method; - MHD_RESULT ret; - enum GNUNET_DB_QueryStatus qs; - - if (NULL == *connection_cls) - { - rctx = GNUNET_new (struct TrackTransferContext); - rctx->hc.cc = &track_transfer_cleanup; - rctx->connection = connection; - *connection_cls = rctx; - } - else - { - /* not first call, recover state */ - rctx = *connection_cls; - } - - if (0 != rctx->response_code) - { - /* We are *done* processing the request, just queue the response (!) */ - if (UINT_MAX == rctx->response_code) - { - GNUNET_break (0); - return MHD_NO; /* hard error */ - } - ret = MHD_queue_response (connection, - rctx->response_code, - rctx->response); - if (NULL != rctx->response) - { - MHD_destroy_response (rctx->response); - rctx->response = NULL; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Queueing response (%u) for /track/transfer (%s).\n", - (unsigned int) rctx->response_code, - ret ? "OK" : "FAILED"); - return ret; - } - if ( (NULL != rctx->fo) || - (NULL != rctx->eh) ) - { - /* likely old MHD version */ - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Not sure why we are here, should be suspended\n"); - return MHD_YES; /* still work in progress */ - } - - url = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "exchange"); - if (NULL == url) - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_PARAMETER_MISSING, - "exchange"); - rctx->url = GNUNET_strdup (url); - - /* FIXME: change again: we probably don't want the wire_method - but rather the _account_ (section) here! */ - wire_method = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "wire_method"); - if (NULL == wire_method) - { - if (1) - { - /* temporary work-around until demo is adjusted... */ - GNUNET_break (0); - wire_method = "x-taler-bank"; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Client needs fixing, see API change for #4943!\n"); - } - else - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_PARAMETER_MISSING, - "wire_method"); - } - rctx->wire_method = GNUNET_strdup (wire_method); - rctx->mi = mi; - str = MHD_lookup_connection_value (connection, - MHD_GET_ARGUMENT_KIND, - "wtid"); - if (NULL == str) - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_PARAMETER_MISSING, - "wtid"); - if (GNUNET_OK != - GNUNET_STRINGS_string_to_data (str, - strlen (str), - &rctx->wtid, - sizeof (rctx->wtid))) - { - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_PARAMETER_MALFORMED, - "wtid"); - } - - /* Check if reply is already in database! */ - db->preflight (db->cls); - qs = db->find_proof_by_wtid (db->cls, - rctx->url, - &rctx->wtid, - &proof_cb, - rctx); - if (0 > qs) - { - /* Simple select queries should not cause serialization issues */ - 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_TRACK_TRANSFER_DB_FETCH_DEPOSIT_ERROR, - "Fail to query database about proofs"); - } - if (0 != rctx->response_code) - { - ret = MHD_queue_response (connection, - rctx->response_code, - rctx->response); - if (NULL != rctx->response) - { - MHD_destroy_response (rctx->response); - rctx->response = NULL; - } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Queueing response (%u) for /track/transfer (%s).\n", - (unsigned int) rctx->response_code, - ret ? "OK" : "FAILED"); - return ret; - } - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Suspending /track/transfer handling while working with the exchange\n"); - MHD_suspend_connection (connection); - rctx->fo = TMH_EXCHANGES_find_exchange (url, - NULL, - GNUNET_NO, - &process_track_transfer_with_exchange, - rctx); - rctx->timeout_task - = GNUNET_SCHEDULER_add_delayed (TRACK_TIMEOUT, - &handle_track_transfer_timeout, - rctx); - return MHD_YES; -} - - -/* end of taler-merchant-httpd_track-transfer.c */ diff --git a/src/backend/taler-merchant-httpd_orders_order_get4.c b/src/backend/taler-merchant-httpd_private-get-orders-ID.c index bb5384d1..bb5384d1 100644 --- a/src/backend/taler-merchant-httpd_orders_order_get4.c +++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c diff --git a/src/backend/taler-merchant-httpd_check-payment.h b/src/backend/taler-merchant-httpd_private-get-orders-ID.h index e94645df..e94645df 100644 --- a/src/backend/taler-merchant-httpd_check-payment.h +++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.h diff --git a/src/backend/taler-merchant-httpd_get-reserves-reserve.c b/src/backend/taler-merchant-httpd_private-get-reserves-ID.c index f7aa0ab0..f7aa0ab0 100644 --- a/src/backend/taler-merchant-httpd_get-reserves-reserve.c +++ b/src/backend/taler-merchant-httpd_private-get-reserves-ID.c diff --git a/src/backend/taler-merchant-httpd_reserves_reserve_get.h b/src/backend/taler-merchant-httpd_private-get-reserves-ID.h index 3123486c..3123486c 100644 --- a/src/backend/taler-merchant-httpd_reserves_reserve_get.h +++ b/src/backend/taler-merchant-httpd_private-get-reserves-ID.h diff --git a/src/backend/taler-merchant-httpd_get-transfers.c b/src/backend/taler-merchant-httpd_private-get-transfers.c index 7f55c917..7f55c917 100644 --- a/src/backend/taler-merchant-httpd_get-transfers.c +++ b/src/backend/taler-merchant-httpd_private-get-transfers.c diff --git a/src/backend/taler-merchant-httpd_transfers-get.h b/src/backend/taler-merchant-httpd_private-get-transfers.h index 0463295e..0463295e 100644 --- a/src/backend/taler-merchant-httpd_transfers-get.h +++ b/src/backend/taler-merchant-httpd_private-get-transfers.h diff --git a/src/backend/taler-merchant-httpd_orders_order_refund.c b/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c index 5324c619..5324c619 100644 --- a/src/backend/taler-merchant-httpd_orders_order_refund.c +++ b/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c diff --git a/src/backend/taler-merchant-httpd_orders_order_refund.h b/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.h index ff178001..ff178001 100644 --- a/src/backend/taler-merchant-httpd_orders_order_refund.h +++ b/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.h diff --git a/src/backend/taler-merchant-httpd_orders_order_get3.c b/src/backend/taler-merchant-httpd_private-post-orders-ID-track-UNSPEC.c index 39f8ce9e..39f8ce9e 100644 --- a/src/backend/taler-merchant-httpd_orders_order_get3.c +++ b/src/backend/taler-merchant-httpd_private-post-orders-ID-track-UNSPEC.c diff --git a/src/backend/taler-merchant-httpd_track-transaction.h b/src/backend/taler-merchant-httpd_private-post-orders-ID-track-UNSPEC.h index d6201107..d6201107 100644 --- a/src/backend/taler-merchant-httpd_track-transaction.h +++ b/src/backend/taler-merchant-httpd_private-post-orders-ID-track-UNSPEC.h diff --git a/src/backend/taler-merchant-httpd_post-tips.c b/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c index 569cf0ab..569cf0ab 100644 --- a/src/backend/taler-merchant-httpd_post-tips.c +++ b/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c diff --git a/src/backend/taler-merchant-httpd_tips_post.h b/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.h index 1f7f44ea..1f7f44ea 100644 --- a/src/backend/taler-merchant-httpd_tips_post.h +++ b/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.h diff --git a/src/backend/taler-merchant-httpd_refund.h b/src/backend/taler-merchant-httpd_refund.h deleted file mode 100644 index f0fb44dd..00000000 --- a/src/backend/taler-merchant-httpd_refund.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - This file is part of TALER - (C) 2014, 2015, 2016, 2017 INRIA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -*/ - -/** - * @file backend/taler-merchant-httpd_refund.c - * @brief HTTP serving layer mainly intended to communicate with the frontend - * @author Marcello Stanisci - */ - -#ifndef TALER_MERCHANT_HTTPD_REFUND_H -#define TALER_MERCHANT_HTTPD_REFUND_H -#include <microhttpd.h> -#include "taler-merchant-httpd.h" - - -/** - * Return refund situation about a contract. - * - * @param rh context of the handler - * @param connection the MHD connection to handle - * @param[in,out] connection_cls the connection's closure (can be updated) - * @param upload_data upload data - * @param[in,out] upload_data_size number of bytes (left) in @a upload_data - * @param mi merchant backend instance, never NULL - * @return MHD result code - */ -MHD_RESULT -MH_handler_refund_lookup (struct TMH_RequestHandler *rh, - struct MHD_Connection *connection, - void **connection_cls, - const char *upload_data, - size_t *upload_data_size, - struct MerchantInstance *mi); - - -/** - * Force resuming all suspended refund lookups, needed during shutdown. - */ -void -MH_force_refund_resume (void); - - -/** - * Get the JSON representation of a refund. - * - * @param merchant_pub the merchant's public key - * @param mi merchant instance - * @param ret_ec where to store error code - * @param ret_errmsg where to store error message - * @return NULL on error, JSON array with refunds on success - */ -json_t * -TM_get_refund_json (const struct MerchantInstance *mi, - const struct GNUNET_HashCode *h_contract_terms, - enum TALER_ErrorCode *ret_ec, - const char **ret_errmsg); - -#endif diff --git a/src/backend/taler-merchant-httpd_reserves_get.h b/src/backend/taler-merchant-httpd_reserves_get.h deleted file mode 100644 index f180546d..00000000 --- a/src/backend/taler-merchant-httpd_reserves_get.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - This file is part of TALER - (C) 2018--2019 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -*/ -/** - * @file backend/taler-merchant-httpd_tip-reserve-helper.h - * @brief helper functions to check the status of a tipping reserve - * @author Christian Grothoff - */ -#ifndef TALER_MERCHANT_HTTPD_TIP_RESERVE_HELPER_H -#define TALER_MERCHANT_HTTPD_TIP_RESERVE_HELPER_H -#include <jansson.h> -#include <taler/taler_util.h> -#include <taler/taler_json_lib.h> -#include "taler-merchant-httpd.h" -#include "taler-merchant-httpd_mhd.h" -#include "taler-merchant-httpd_exchanges.h" -#include "taler-merchant-httpd_tip-reserve-helper.h" - - -/** - * Context with input, output and internal state for - * #TMH_check_tip_reserve() and #TMH_check_tip_reserve_cleanup(). - */ -struct TMH_CheckTipReserve -{ - /** - * Input: MHD connection we should resume when finished - */ - struct MHD_Connection *connection; - - /** - * Input: private key of the reserve. - */ - struct TALER_ReservePrivateKeyP reserve_priv; - - /** - * Output: Set to delay after which the reserve will expire if idle. - */ - struct GNUNET_TIME_Relative idle_reserve_expiration_time; - - /** - * Internal: exchange find operation. - */ - struct TMH_EXCHANGES_FindOperation *fo; - - /** - * Internal: reserve status operation. - */ - struct TALER_EXCHANGE_ReservesGetHandle *rsh; - - /** - * Internal: DLL for resumption on shutdown. - */ - struct TMH_CheckTipReserve *next; - - /** - * Internal: DLL for resumption on shutdown. - */ - struct TMH_CheckTipReserve *prev; - - /** - * Output: response object to return (on error only) - */ - struct MHD_Response *response; - - /** - * Output: Total amount deposited into the reserve. - */ - struct TALER_Amount amount_deposited; - - /** - * Output: total tip amount requested. - */ - struct TALER_Amount amount_withdrawn; - - /** - * Input: total amount authorized. - */ - struct TALER_Amount amount_authorized; - - /** - * Output: set to the time when the reserve will expire - */ - struct GNUNET_TIME_Absolute reserve_expiration; - - /** - * Output: HTTP status code to return (on error only) - */ - unsigned int response_code; - - /** - * Input: Set to #GNUNET_NO if no tips were authorized yet. - * Used to know that @e amount_authorized is not yet initialized - * and in that case the helper will set it to zero (once we know - * the currency). - */ - int none_authorized; - - /** - * Internal: Is the @e connection currently suspended? - * #GNUNET_NO if the @e connection was not suspended, - * #GNUNET_YES if the @e connection was suspended, - * #GNUNET_SYSERR if @e connection was resumed to as - * part of #MH_force_pc_resume during shutdown. - */ - int suspended; - -}; - - -/** - * Check the status of the given reserve at the given exchange. - * Suspends the MHD connection while this is happening and resumes - * processing once we know the reserve status (or once an error - * code has been determined). - * - * @param[in,out] ctr context for checking the reserve status - * @param tip_exchange the URL of the exchange to query - */ -void -TMH_check_tip_reserve (struct TMH_CheckTipReserve *ctr, - const char *tip_exchange); - - -/** - * Clean up any state that might be left in @a ctr. - * - * @param[in] context to clean up - */ -void -TMH_check_tip_reserve_cleanup (struct TMH_CheckTipReserve *ctr); - -/** - * Force all tip reserve helper contexts to be resumed as we are about to shut - * down MHD. - */ -void -MH_force_trh_resume (void); - - -#endif diff --git a/src/backend/taler-merchant-httpd_transfers-post.h b/src/backend/taler-merchant-httpd_transfers-post.h deleted file mode 100644 index 0463295e..00000000 --- a/src/backend/taler-merchant-httpd_transfers-post.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - This file is part of TALER - (C) 2014-2020 Taler Systems SA - - TALER is free software; you can redistribute it and/or modify it under the - terms of the GNU General Public License as published by the Free Software - Foundation; either version 3, or (at your option) any later version. - - TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with - TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -*/ -/** - * @file backend/taler-merchant-httpd_track-transfer.h - * @brief headers for /track/transfer handler - * @author Christian Grothoff - * @author Marcello Stanisci - */ -#ifndef TALER_MERCHANT_HTTPD_TRACK_TRANSFER_H -#define TALER_MERCHANT_HTTPD_TRACK_TRANSFER_H -#include <microhttpd.h> -#include "taler-merchant-httpd.h" - -/** - * Manages a /track/transfer call, thus it calls the /wire/transfer - * offered by the exchange in order to return the set of transfers - * (of coins) associated with a given wire transfer - * - * @param rh context of the handler - * @param connection the MHD connection to handle - * @param[in,out] connection_cls the connection's closure (can be updated) - * @param upload_data upload data - * @param[in,out] upload_data_size number of bytes (left) in @a upload_data - * @param mi merchant backend instance, never NULL - * @return MHD result code - */ -MHD_RESULT -MH_handler_track_transfer (struct TMH_RequestHandler *rh, - struct MHD_Connection *connection, - void **connection_cls, - const char *upload_data, - size_t *upload_data_size, - struct MerchantInstance *mi); - - -#endif |