more libtalermhd refactoring

This commit is contained in:
Christian Grothoff 2019-11-23 19:29:50 +01:00
parent e8a88392da
commit 7c11a822ba
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
4 changed files with 178 additions and 145 deletions

View File

@ -27,6 +27,7 @@
#include <microhttpd.h> #include <microhttpd.h>
#include <pthread.h> #include <pthread.h>
#include "taler_json_lib.h" #include "taler_json_lib.h"
#include "taler_mhd_lib.h"
#include "taler-exchange-httpd_parsing.h" #include "taler-exchange-httpd_parsing.h"
#include "taler-exchange-httpd_payback.h" #include "taler-exchange-httpd_payback.h"
#include "taler-exchange-httpd_responses.h" #include "taler-exchange-httpd_responses.h"
@ -68,24 +69,25 @@ reply_payback_refresh_success (struct MHD_Connection *connection,
&pub, &pub,
&sig)) &sig))
{ {
return TEH_RESPONSE_reply_internal_error (connection, return TALER_MHD_reply_with_error (connection,
TALER_EC_EXCHANGE_BAD_CONFIGURATION, MHD_HTTP_INTERNAL_SERVER_ERROR,
"no keys"); TALER_EC_EXCHANGE_BAD_CONFIGURATION,
"no keys");
} }
return TEH_RESPONSE_reply_json_pack (connection, return TALER_MHD_reply_json_pack (connection,
MHD_HTTP_OK, MHD_HTTP_OK,
"{s:o, s:o, s:o, s:o, s:o}", "{s:o, s:o, s:o, s:o, s:o}",
"old_coin_pub", "old_coin_pub",
GNUNET_JSON_from_data_auto ( GNUNET_JSON_from_data_auto (
old_coin_pub), old_coin_pub),
"timestamp", GNUNET_JSON_from_time_abs ( "timestamp", GNUNET_JSON_from_time_abs (
timestamp), timestamp),
"amount", TALER_JSON_from_amount ( "amount", TALER_JSON_from_amount (
amount), amount),
"exchange_sig", "exchange_sig",
GNUNET_JSON_from_data_auto (&sig), GNUNET_JSON_from_data_auto (&sig),
"exchange_pub", "exchange_pub",
GNUNET_JSON_from_data_auto (&pub)); GNUNET_JSON_from_data_auto (&pub));
} }
@ -122,23 +124,24 @@ reply_payback_success (struct MHD_Connection *connection,
&pub, &pub,
&sig)) &sig))
{ {
return TEH_RESPONSE_reply_internal_error (connection, return TALER_MHD_reply_with_error (connection,
TALER_EC_EXCHANGE_BAD_CONFIGURATION, MHD_HTTP_INTERNAL_SERVER_ERROR,
"no keys"); TALER_EC_EXCHANGE_BAD_CONFIGURATION,
"no keys");
} }
return TEH_RESPONSE_reply_json_pack (connection, return TALER_MHD_reply_json_pack (connection,
MHD_HTTP_OK, MHD_HTTP_OK,
"{s:o, s:o, s:o, s:o, s:o}", "{s:o, s:o, s:o, s:o, s:o}",
"reserve_pub", "reserve_pub",
GNUNET_JSON_from_data_auto (reserve_pub), GNUNET_JSON_from_data_auto (reserve_pub),
"timestamp", GNUNET_JSON_from_time_abs ( "timestamp", GNUNET_JSON_from_time_abs (
timestamp), timestamp),
"amount", TALER_JSON_from_amount ( "amount", TALER_JSON_from_amount (
amount), amount),
"exchange_sig", "exchange_sig",
GNUNET_JSON_from_data_auto (&sig), GNUNET_JSON_from_data_auto (&sig),
"exchange_pub", "exchange_pub",
GNUNET_JSON_from_data_auto (&pub)); GNUNET_JSON_from_data_auto (&pub));
} }

View File

@ -29,6 +29,7 @@
#include <microhttpd.h> #include <microhttpd.h>
#include <pthread.h> #include <pthread.h>
#include "taler_json_lib.h" #include "taler_json_lib.h"
#include "taler_mhd_lib.h"
#include "taler-exchange-httpd_parsing.h" #include "taler-exchange-httpd_parsing.h"
#include "taler-exchange-httpd_refund.h" #include "taler-exchange-httpd_refund.h"
#include "taler-exchange-httpd_responses.h" #include "taler-exchange-httpd_responses.h"
@ -66,17 +67,17 @@ reply_refund_success (struct MHD_Connection *connection,
&pub, &pub,
&sig)) &sig))
{ {
return TEH_RESPONSE_reply_internal_error (connection, return TALER_MHD_reply_with_error (connection,
TALER_EC_EXCHANGE_BAD_CONFIGURATION, MHD_HTTP_INTERNAL_SERVER_ERROR,
"no keys"); TALER_EC_EXCHANGE_BAD_CONFIGURATION,
"no keys");
} }
return TEH_RESPONSE_reply_json_pack (connection, return TALER_MHD_reply_json_pack (connection,
MHD_HTTP_OK, MHD_HTTP_OK,
"{s:s, s:o, s:o}", "{s:s, s:o, s:o}",
"status", "REFUND_OK", "status", "REFUND_OK",
"sig", GNUNET_JSON_from_data_auto (&sig), "sig", GNUNET_JSON_from_data_auto (&sig),
"pub", GNUNET_JSON_from_data_auto ( "pub", GNUNET_JSON_from_data_auto (&pub));
&pub));
} }
@ -94,11 +95,11 @@ reply_refund_failure (struct MHD_Connection *connection,
unsigned int response_code, unsigned int response_code,
enum TALER_ErrorCode ec) enum TALER_ErrorCode ec)
{ {
return TEH_RESPONSE_reply_json_pack (connection, return TALER_MHD_reply_json_pack (connection,
response_code, response_code,
"{s:s, s:I}", "{s:s, s:I}",
"status", "refund failure", "hint", "refund failure",
"code", (json_int_t) ec); "code", (json_int_t) ec);
} }
@ -114,15 +115,15 @@ static int
reply_refund_conflict (struct MHD_Connection *connection, reply_refund_conflict (struct MHD_Connection *connection,
const struct TALER_EXCHANGEDB_TransactionList *tl) const struct TALER_EXCHANGEDB_TransactionList *tl)
{ {
return TEH_RESPONSE_reply_json_pack (connection, return TALER_MHD_reply_json_pack (connection,
MHD_HTTP_CONFLICT, MHD_HTTP_CONFLICT,
"{s:s, s:I, s:o}", "{s:s, s:I, s:o}",
"status", "conflicting refund", "hint", "conflicting refund",
"code", "code",
(json_int_t) TALER_EC_REFUND_CONFLICT, (json_int_t) TALER_EC_REFUND_CONFLICT,
"history", "history",
TEH_RESPONSE_compile_transaction_history ( TEH_RESPONSE_compile_transaction_history (
tl)); tl));
} }
@ -259,8 +260,10 @@ refund_transaction (void *cls,
TALER_LOG_WARNING ("Deposit to /refund was not found\n"); TALER_LOG_WARNING ("Deposit to /refund was not found\n");
TEH_plugin->free_coin_transaction_list (TEH_plugin->cls, TEH_plugin->free_coin_transaction_list (TEH_plugin->cls,
tl); tl);
*mhd_ret = TEH_RESPONSE_reply_transaction_unknown (connection, *mhd_ret = TALER_MHD_reply_with_error (connection,
TALER_EC_REFUND_DEPOSIT_NOT_FOUND); MHD_HTTP_NOT_FOUND,
TALER_EC_REFUND_DEPOSIT_NOT_FOUND,
"deposit unknown");
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
/* handle if conflicting refund found */ /* handle if conflicting refund found */
@ -309,9 +312,10 @@ refund_transaction (void *cls,
GNUNET_break (0); GNUNET_break (0);
TEH_plugin->free_coin_transaction_list (TEH_plugin->cls, TEH_plugin->free_coin_transaction_list (TEH_plugin->cls,
tl); tl);
*mhd_ret = TEH_RESPONSE_reply_internal_error (connection, *mhd_ret = TALER_MHD_reply_with_error (connection,
TALER_EC_REFUND_DB_INCONSISTENT, MHD_HTTP_INTERNAL_SERVER_ERROR,
"database inconsistent"); TALER_EC_REFUND_DB_INCONSISTENT,
"database inconsistent");
return qs; return qs;
} }
if (GNUNET_DB_STATUS_SOFT_ERROR == qs) if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
@ -349,9 +353,10 @@ refund_transaction (void *cls,
TALER_LOG_ERROR ("Lacking keys to operate\n"); TALER_LOG_ERROR ("Lacking keys to operate\n");
TEH_plugin->free_coin_transaction_list (TEH_plugin->cls, TEH_plugin->free_coin_transaction_list (TEH_plugin->cls,
tl); tl);
*mhd_ret = TEH_RESPONSE_reply_internal_error (connection, *mhd_ret = TALER_MHD_reply_with_error (connection,
TALER_EC_EXCHANGE_BAD_CONFIGURATION, MHD_HTTP_INTERNAL_SERVER_ERROR,
"no keys"); TALER_EC_EXCHANGE_BAD_CONFIGURATION,
"no keys");
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
dki = TEH_KS_denomination_key_lookup_by_hash (mks, dki = TEH_KS_denomination_key_lookup_by_hash (mks,
@ -367,9 +372,10 @@ refund_transaction (void *cls,
TEH_KS_release (mks); TEH_KS_release (mks);
TEH_plugin->free_coin_transaction_list (TEH_plugin->cls, TEH_plugin->free_coin_transaction_list (TEH_plugin->cls,
tl); tl);
*mhd_ret = TEH_RESPONSE_reply_with_error (connection, *mhd_ret = TALER_MHD_reply_with_error (connection,
ec, ec,
hc); hc,
"denomination not found, but coin known");
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
TALER_amount_ntoh (&expect_fee, TALER_amount_ntoh (&expect_fee,
@ -382,9 +388,10 @@ refund_transaction (void *cls,
{ {
TEH_plugin->free_coin_transaction_list (TEH_plugin->cls, TEH_plugin->free_coin_transaction_list (TEH_plugin->cls,
tl); tl);
*mhd_ret = TEH_RESPONSE_reply_arg_invalid (connection, *mhd_ret = TALER_MHD_reply_with_error (connection,
TALER_EC_REFUND_FEE_TOO_LOW, MHD_HTTP_BAD_REQUEST,
"refund_fee"); TALER_EC_REFUND_FEE_TOO_LOW,
"refund_fee");
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
if (1 == fee_cmp) if (1 == fee_cmp)
@ -402,8 +409,10 @@ refund_transaction (void *cls,
if (GNUNET_DB_STATUS_HARD_ERROR == qs) if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{ {
TALER_LOG_WARNING ("Failed to store /refund information in database\n"); TALER_LOG_WARNING ("Failed to store /refund information in database\n");
*mhd_ret = TEH_RESPONSE_reply_internal_db_error (connection, *mhd_ret = TALER_MHD_reply_with_error (connection,
TALER_EC_REFUND_STORE_DB_ERROR); MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_REFUND_STORE_DB_ERROR,
"could not persist store information");
return qs; return qs;
} }
/* Success or soft failure */ /* Success or soft failure */
@ -443,17 +452,19 @@ verify_and_execute_refund (struct MHD_Connection *connection,
&refund->refund_fee) ) &refund->refund_fee) )
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
return TEH_RESPONSE_reply_arg_invalid (connection, return TALER_MHD_reply_with_error (connection,
TALER_EC_REFUND_FEE_CURRENCY_MISSMATCH, MHD_HTTP_BAD_REQUEST,
"refund_fee"); TALER_EC_REFUND_FEE_CURRENCY_MISSMATCH,
"refund_fee");
} }
if (-1 == TALER_amount_cmp (&refund->refund_amount, if (-1 == TALER_amount_cmp (&refund->refund_amount,
&refund->refund_fee) ) &refund->refund_fee) )
{ {
GNUNET_break_op (0); GNUNET_break_op (0);
return TEH_RESPONSE_reply_arg_invalid (connection, return TALER_MHD_reply_with_error (connection,
TALER_EC_REFUND_FEE_ABOVE_AMOUNT, MHD_HTTP_BAD_REQUEST,
"refund_amount"); TALER_EC_REFUND_FEE_ABOVE_AMOUNT,
"refund_amount");
} }
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_REFUND, GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_REFUND,
@ -462,9 +473,10 @@ verify_and_execute_refund (struct MHD_Connection *connection,
&refund->merchant_pub.eddsa_pub)) &refund->merchant_pub.eddsa_pub))
{ {
TALER_LOG_WARNING ("Invalid signature on /refund request\n"); TALER_LOG_WARNING ("Invalid signature on /refund request\n");
return TEH_RESPONSE_reply_signature_invalid (connection, return TALER_MHD_reply_with_error (connection,
TALER_EC_REFUND_MERCHANT_SIGNATURE_INVALID, MHD_HTTP_FORBIDDEN,
"merchant_sig"); TALER_EC_REFUND_MERCHANT_SIGNATURE_INVALID,
"merchant_sig");
} }
if (GNUNET_OK != if (GNUNET_OK !=
TEH_DB_run_transaction (connection, TEH_DB_run_transaction (connection,

View File

@ -23,6 +23,7 @@
#include "platform.h" #include "platform.h"
#include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_util_lib.h>
#include <jansson.h> #include <jansson.h>
#include "taler_mhd_lib.h"
#include "taler-exchange-httpd_reserve_status.h" #include "taler-exchange-httpd_reserve_status.h"
#include "taler-exchange-httpd_parsing.h" #include "taler-exchange-httpd_parsing.h"
#include "taler-exchange-httpd_responses.h" #include "taler-exchange-httpd_responses.h"
@ -47,15 +48,16 @@ reply_reserve_status_success (struct MHD_Connection *connection,
json_history = TEH_RESPONSE_compile_reserve_history (rh, json_history = TEH_RESPONSE_compile_reserve_history (rh,
&balance); &balance);
if (NULL == json_history) if (NULL == json_history)
return TEH_RESPONSE_reply_internal_error (connection, return TALER_MHD_reply_with_error (connection,
TALER_EC_RESERVE_STATUS_DB_ERROR, MHD_HTTP_INTERNAL_SERVER_ERROR,
"balance calculation failure"); TALER_EC_RESERVE_STATUS_DB_ERROR,
"balance calculation failure");
json_balance = TALER_JSON_from_amount (&balance); json_balance = TALER_JSON_from_amount (&balance);
return TEH_RESPONSE_reply_json_pack (connection, return TALER_MHD_reply_json_pack (connection,
MHD_HTTP_OK, MHD_HTTP_OK,
"{s:o, s:o}", "{s:o, s:o}",
"balance", json_balance, "balance", json_balance,
"history", json_history); "history", json_history);
} }
@ -155,14 +157,14 @@ TEH_RESERVE_handler_reserve_status (struct TEH_RequestHandler *rh,
/* generate proper response */ /* generate proper response */
if (NULL == rsc.rh) if (NULL == rsc.rh)
return TEH_RESPONSE_reply_json_pack (connection, return TALER_MHD_reply_json_pack (connection,
MHD_HTTP_NOT_FOUND, MHD_HTTP_NOT_FOUND,
"{s:s, s:s, s:I}", "{s:s, s:s, s:I}",
"error", "Reserve not found", "error", "Reserve not found",
"parameter", "withdraw_pub", "parameter", "withdraw_pub",
"code", "code",
(json_int_t) (json_int_t)
TALER_EC_RESERVE_STATUS_UNKNOWN); TALER_EC_RESERVE_STATUS_UNKNOWN);
mhd_ret = reply_reserve_status_success (connection, mhd_ret = reply_reserve_status_success (connection,
rsc.rh); rsc.rh);
TEH_plugin->free_reserve_history (TEH_plugin->cls, TEH_plugin->free_reserve_history (TEH_plugin->cls,

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER This file is part of TALER
Copyright (C) 2014-2017 GNUnet e.V. Copyright (C) 2014-2019 Taler Systems SA
TALER is free software; you can redistribute it and/or modify TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
@ -16,7 +16,6 @@
Public License along with TALER; see the file COPYING. If not, Public License along with TALER; see the file COPYING. If not,
see <http://www.gnu.org/licenses/> see <http://www.gnu.org/licenses/>
*/ */
/** /**
* @file taler-exchange-httpd_reserve_withdraw.c * @file taler-exchange-httpd_reserve_withdraw.c
* @brief Handle /reserve/withdraw requests * @brief Handle /reserve/withdraw requests
@ -27,6 +26,7 @@
#include "platform.h" #include "platform.h"
#include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_util_lib.h>
#include <jansson.h> #include <jansson.h>
#include "taler_mhd_lib.h"
#include "taler-exchange-httpd_reserve_withdraw.h" #include "taler-exchange-httpd_reserve_withdraw.h"
#include "taler-exchange-httpd_parsing.h" #include "taler-exchange-httpd_parsing.h"
#include "taler-exchange-httpd_responses.h" #include "taler-exchange-httpd_responses.h"
@ -65,20 +65,21 @@ reply_reserve_withdraw_insufficient_funds (struct MHD_Connection *connection,
/* Address the case where the ptr is not null, but /* Address the case where the ptr is not null, but
* it fails "internally" to dump as string (= corrupted). */ * it fails "internally" to dump as string (= corrupted). */
|| (0 == json_dumpb (json_history, NULL, 0, 0))) || (0 == json_dumpb (json_history, NULL, 0, 0)))
return TEH_RESPONSE_reply_internal_error (connection, return TALER_MHD_reply_with_error (connection,
TALER_EC_WITHDRAW_HISTORY_DB_ERROR_INSUFFICIENT_FUNDS, MHD_HTTP_INTERNAL_SERVER_ERROR,
"balance calculation failure"); TALER_EC_WITHDRAW_HISTORY_DB_ERROR_INSUFFICIENT_FUNDS,
"balance calculation failure");
json_balance = TALER_JSON_from_amount (&balance); json_balance = TALER_JSON_from_amount (&balance);
return TEH_RESPONSE_reply_json_pack (connection, return TALER_MHD_reply_json_pack (connection,
MHD_HTTP_FORBIDDEN, MHD_HTTP_FORBIDDEN,
"{s:s, s:I, s:o, s:o}", "{s:s, s:I, s:o, s:o}",
"error", "Insufficient funds", "error", "Insufficient funds",
"code", "code",
(json_int_t) (json_int_t)
TALER_EC_WITHDRAW_INSUFFICIENT_FUNDS, TALER_EC_WITHDRAW_INSUFFICIENT_FUNDS,
"balance", json_balance, "balance", json_balance,
"history", json_history); "history", json_history);
} }
@ -98,10 +99,10 @@ reply_reserve_withdraw_success (struct MHD_Connection *connection,
json_t *sig_json; json_t *sig_json;
sig_json = GNUNET_JSON_from_rsa_signature (collectable->sig.rsa_signature); sig_json = GNUNET_JSON_from_rsa_signature (collectable->sig.rsa_signature);
return TEH_RESPONSE_reply_json_pack (connection, return TALER_MHD_reply_json_pack (connection,
MHD_HTTP_OK, MHD_HTTP_OK,
"{s:o}", "{s:o}",
"ev_sig", sig_json); "ev_sig", sig_json);
} }
@ -209,8 +210,10 @@ withdraw_transaction (void *cls,
{ {
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
if (GNUNET_DB_STATUS_HARD_ERROR == qs) if (GNUNET_DB_STATUS_HARD_ERROR == qs)
*mhd_ret = TEH_RESPONSE_reply_internal_db_error (connection, *mhd_ret = TALER_MHD_reply_with_error (connection,
TALER_EC_WITHDRAW_DB_FETCH_ERROR); MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_WITHDRAW_DB_FETCH_ERROR,
"failed to fetch withdraw data");
wc->collectable.sig = denom_sig; wc->collectable.sig = denom_sig;
return qs; return qs;
} }
@ -252,15 +255,18 @@ withdraw_transaction (void *cls,
if (0 > qs) if (0 > qs)
{ {
if (GNUNET_DB_STATUS_HARD_ERROR == qs) if (GNUNET_DB_STATUS_HARD_ERROR == qs)
*mhd_ret = TEH_RESPONSE_reply_internal_db_error (connection, *mhd_ret = TALER_MHD_reply_with_error (connection,
TALER_EC_WITHDRAW_DB_FETCH_ERROR); MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_WITHDRAW_DB_FETCH_ERROR,
"failed to fetch reserve data");
return qs; return qs;
} }
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
{ {
*mhd_ret = TEH_RESPONSE_reply_arg_unknown (connection, *mhd_ret = TALER_MHD_reply_with_error (connection,
TALER_EC_WITHDRAW_RESERVE_UNKNOWN, MHD_HTTP_NOT_FOUND,
"reserve_pub"); TALER_EC_WITHDRAW_RESERVE_UNKNOWN,
"reserve_pub");
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
if (0 < TALER_amount_cmp (&wc->amount_required, if (0 < TALER_amount_cmp (&wc->amount_required,
@ -286,8 +292,10 @@ withdraw_transaction (void *cls,
if (NULL == rh) if (NULL == rh)
{ {
if (GNUNET_DB_STATUS_HARD_ERROR == qs) if (GNUNET_DB_STATUS_HARD_ERROR == qs)
*mhd_ret = TEH_RESPONSE_reply_internal_db_error (connection, *mhd_ret = TALER_MHD_reply_with_error (connection,
TALER_EC_WITHDRAW_DB_FETCH_ERROR); MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_WITHDRAW_DB_FETCH_ERROR,
"failed to fetch reserve history");
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
*mhd_ret = reply_reserve_withdraw_insufficient_funds (connection, *mhd_ret = reply_reserve_withdraw_insufficient_funds (connection,
@ -308,9 +316,10 @@ withdraw_transaction (void *cls,
if (NULL == wc->collectable.sig.rsa_signature) if (NULL == wc->collectable.sig.rsa_signature)
{ {
GNUNET_break (0); GNUNET_break (0);
*mhd_ret = TEH_RESPONSE_reply_internal_error (connection, *mhd_ret = TALER_MHD_reply_with_error (connection,
TALER_EC_WITHDRAW_SIGNATURE_FAILED, MHD_HTTP_INTERNAL_SERVER_ERROR,
"Internal error"); TALER_EC_WITHDRAW_SIGNATURE_FAILED,
"Failed to create signature");
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
} }
@ -330,8 +339,10 @@ withdraw_transaction (void *cls,
{ {
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
if (GNUNET_DB_STATUS_HARD_ERROR == qs) if (GNUNET_DB_STATUS_HARD_ERROR == qs)
*mhd_ret = TEH_RESPONSE_reply_internal_db_error (connection, *mhd_ret = TALER_MHD_reply_with_error (connection,
TALER_EC_WITHDRAW_DB_STORE_ERROR); MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_WITHDRAW_DB_STORE_ERROR,
"failed to persist withdraw data");
return qs; return qs;
} }
return qs; return qs;
@ -403,9 +414,10 @@ TEH_RESERVE_handler_reserve_withdraw (struct TEH_RequestHandler *rh,
{ {
TALER_LOG_ERROR ("Lacking keys to operate\n"); TALER_LOG_ERROR ("Lacking keys to operate\n");
GNUNET_JSON_parse_free (spec); GNUNET_JSON_parse_free (spec);
return TEH_RESPONSE_reply_internal_error (connection, return TALER_MHD_reply_with_error (connection,
TALER_EC_EXCHANGE_BAD_CONFIGURATION, MHD_HTTP_INTERNAL_SERVER_ERROR,
"no keys"); TALER_EC_EXCHANGE_BAD_CONFIGURATION,
"no keys");
} }
wc.dki = TEH_KS_denomination_key_lookup_by_hash (wc.key_state, wc.dki = TEH_KS_denomination_key_lookup_by_hash (wc.key_state,
&wc.denom_pub_hash, &wc.denom_pub_hash,
@ -416,9 +428,10 @@ TEH_RESERVE_handler_reserve_withdraw (struct TEH_RequestHandler *rh,
{ {
GNUNET_JSON_parse_free (spec); GNUNET_JSON_parse_free (spec);
TEH_KS_release (wc.key_state); TEH_KS_release (wc.key_state);
return TEH_RESPONSE_reply_with_error (connection, return TALER_MHD_reply_with_error (connection,
ec, ec,
hc); hc,
"could not find denomination key");
} }
GNUNET_assert (NULL != wc.dki->denom_priv.rsa_private_key); GNUNET_assert (NULL != wc.dki->denom_priv.rsa_private_key);
TALER_amount_ntoh (&amount, TALER_amount_ntoh (&amount,
@ -432,9 +445,10 @@ TEH_RESERVE_handler_reserve_withdraw (struct TEH_RequestHandler *rh,
{ {
GNUNET_JSON_parse_free (spec); GNUNET_JSON_parse_free (spec);
TEH_KS_release (wc.key_state); TEH_KS_release (wc.key_state);
return TEH_RESPONSE_reply_internal_error (connection, return TALER_MHD_reply_with_error (connection,
TALER_EC_WITHDRAW_AMOUNT_FEE_OVERFLOW, MHD_HTTP_INTERNAL_SERVER_ERROR,
"amount overflow for value plus withdraw fee"); TALER_EC_WITHDRAW_AMOUNT_FEE_OVERFLOW,
"amount overflow for value plus withdraw fee");
} }
TALER_amount_hton (&wc.wsrd.amount_with_fee, TALER_amount_hton (&wc.wsrd.amount_with_fee,
&wc.amount_required); &wc.amount_required);
@ -460,9 +474,10 @@ TEH_RESERVE_handler_reserve_withdraw (struct TEH_RequestHandler *rh,
"Client supplied invalid signature for /reserve/withdraw request\n"); "Client supplied invalid signature for /reserve/withdraw request\n");
GNUNET_JSON_parse_free (spec); GNUNET_JSON_parse_free (spec);
TEH_KS_release (wc.key_state); TEH_KS_release (wc.key_state);
return TEH_RESPONSE_reply_signature_invalid (connection, return TALER_MHD_reply_with_error (connection,
TALER_EC_WITHDRAW_RESERVE_SIGNATURE_INVALID, MHD_HTTP_FORBIDDEN,
"reserve_sig"); TALER_EC_WITHDRAW_RESERVE_SIGNATURE_INVALID,
"reserve_sig");
} }
#if OPTIMISTIC_SIGN #if OPTIMISTIC_SIGN
@ -476,9 +491,10 @@ TEH_RESERVE_handler_reserve_withdraw (struct TEH_RequestHandler *rh,
GNUNET_break (0); GNUNET_break (0);
GNUNET_JSON_parse_free (spec); GNUNET_JSON_parse_free (spec);
TEH_KS_release (wc.key_state); TEH_KS_release (wc.key_state);
return TEH_RESPONSE_reply_internal_error (connection, return TALER_MHD_reply_with_error (connection,
TALER_EC_WITHDRAW_SIGNATURE_FAILED, MHD_HTTP_INTERNAL_SERVER_ERROR,
"Internal error"); TALER_EC_WITHDRAW_SIGNATURE_FAILED,
"Failed to sign");
} }
#endif #endif