replace GNUNET_asserts() with more proper error handling, fix indentation
This commit is contained in:
parent
1a537490eb
commit
c0c80d4a67
@ -29,6 +29,14 @@
|
|||||||
#include "taler_json_lib.h"
|
#include "taler_json_lib.h"
|
||||||
#include "taler-exchange-httpd_keystate.h"
|
#include "taler-exchange-httpd_keystate.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable checking signatures before we hand them out
|
||||||
|
* (even though we should have checked them before).
|
||||||
|
* So technically these checks are redundant, but good
|
||||||
|
* during testing.
|
||||||
|
*/
|
||||||
|
#define SANITY_CHECKS_ON 1
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add headers we want to return in every response.
|
* Add headers we want to return in every response.
|
||||||
@ -473,7 +481,9 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
|||||||
GNUNET_break (0); /* out of memory!? */
|
GNUNET_break (0); /* out of memory!? */
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
for (const struct TALER_EXCHANGEDB_TransactionList *pos = tl; NULL != pos; pos = pos->next)
|
for (const struct TALER_EXCHANGEDB_TransactionList *pos = tl;
|
||||||
|
NULL != pos;
|
||||||
|
pos = pos->next)
|
||||||
{
|
{
|
||||||
switch (pos->type)
|
switch (pos->type)
|
||||||
{
|
{
|
||||||
@ -494,6 +504,7 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
|||||||
&deposit->deposit_fee);
|
&deposit->deposit_fee);
|
||||||
dr.merchant = deposit->merchant_pub;
|
dr.merchant = deposit->merchant_pub;
|
||||||
dr.coin_pub = deposit->coin.coin_pub;
|
dr.coin_pub = deposit->coin.coin_pub;
|
||||||
|
#if SANITY_CHECKS_ON
|
||||||
/* internal sanity check before we hand out a bogus sig... */
|
/* internal sanity check before we hand out a bogus sig... */
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_DEPOSIT,
|
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_DEPOSIT,
|
||||||
@ -505,8 +516,8 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
|||||||
json_decref (history);
|
json_decref (history);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
GNUNET_assert (0 ==
|
if (0 !=
|
||||||
json_array_append_new (history,
|
json_array_append_new (history,
|
||||||
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o}",
|
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o}",
|
||||||
"type", "DEPOSIT",
|
"type", "DEPOSIT",
|
||||||
@ -517,7 +528,12 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
|||||||
"merchant_pub", GNUNET_JSON_from_data_auto (&deposit->merchant_pub),
|
"merchant_pub", GNUNET_JSON_from_data_auto (&deposit->merchant_pub),
|
||||||
"h_contract_terms", GNUNET_JSON_from_data_auto (&deposit->h_contract_terms),
|
"h_contract_terms", GNUNET_JSON_from_data_auto (&deposit->h_contract_terms),
|
||||||
"h_wire", GNUNET_JSON_from_data_auto (&deposit->h_wire),
|
"h_wire", GNUNET_JSON_from_data_auto (&deposit->h_wire),
|
||||||
"coin_sig", GNUNET_JSON_from_data_auto (&deposit->csig))));
|
"coin_sig", GNUNET_JSON_from_data_auto (&deposit->csig))))
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
json_decref (history);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TALER_EXCHANGEDB_TT_REFRESH_MELT:
|
case TALER_EXCHANGEDB_TT_REFRESH_MELT:
|
||||||
@ -533,6 +549,7 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
|||||||
TALER_amount_hton (&ms.melt_fee,
|
TALER_amount_hton (&ms.melt_fee,
|
||||||
&melt->melt_fee);
|
&melt->melt_fee);
|
||||||
ms.coin_pub = melt->session.coin.coin_pub;
|
ms.coin_pub = melt->session.coin.coin_pub;
|
||||||
|
#if SANITY_CHECKS_ON
|
||||||
/* internal sanity check before we hand out a bogus sig... */
|
/* internal sanity check before we hand out a bogus sig... */
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_MELT,
|
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_WALLET_COIN_MELT,
|
||||||
@ -544,15 +561,20 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
|||||||
json_decref (history);
|
json_decref (history);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
GNUNET_assert (0 ==
|
if (0 !=
|
||||||
json_array_append_new (history,
|
json_array_append_new (history,
|
||||||
json_pack ("{s:s, s:o, s:o, s:o, s:o}",
|
json_pack ("{s:s, s:o, s:o, s:o, s:o}",
|
||||||
"type", "MELT",
|
"type", "MELT",
|
||||||
"amount", TALER_JSON_from_amount (&melt->session.amount_with_fee),
|
"amount", TALER_JSON_from_amount (&melt->session.amount_with_fee),
|
||||||
"melt_fee", TALER_JSON_from_amount (&melt->melt_fee),
|
"melt_fee", TALER_JSON_from_amount (&melt->melt_fee),
|
||||||
"rc", GNUNET_JSON_from_data_auto (&melt->session.rc),
|
"rc", GNUNET_JSON_from_data_auto (&melt->session.rc),
|
||||||
"coin_sig", GNUNET_JSON_from_data_auto (&melt->session.coin_sig))));
|
"coin_sig", GNUNET_JSON_from_data_auto (&melt->session.coin_sig))))
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
json_decref (history);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TALER_EXCHANGEDB_TT_REFUND:
|
case TALER_EXCHANGEDB_TT_REFUND:
|
||||||
@ -580,6 +602,7 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
|||||||
&refund->refund_amount);
|
&refund->refund_amount);
|
||||||
TALER_amount_hton (&rr.refund_fee,
|
TALER_amount_hton (&rr.refund_fee,
|
||||||
&refund->refund_fee);
|
&refund->refund_fee);
|
||||||
|
#if SANITY_CHECKS_ON
|
||||||
/* internal sanity check before we hand out a bogus sig... */
|
/* internal sanity check before we hand out a bogus sig... */
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_REFUND,
|
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MERCHANT_REFUND,
|
||||||
@ -591,8 +614,8 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
|||||||
json_decref (history);
|
json_decref (history);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
GNUNET_assert (0 ==
|
if (0 !=
|
||||||
json_array_append_new (history,
|
json_array_append_new (history,
|
||||||
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:I, s:o}",
|
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:I, s:o}",
|
||||||
"type", "REFUND",
|
"type", "REFUND",
|
||||||
@ -601,7 +624,12 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
|||||||
"h_contract_terms", GNUNET_JSON_from_data_auto (&refund->h_contract_terms),
|
"h_contract_terms", GNUNET_JSON_from_data_auto (&refund->h_contract_terms),
|
||||||
"merchant_pub", GNUNET_JSON_from_data_auto (&refund->merchant_pub),
|
"merchant_pub", GNUNET_JSON_from_data_auto (&refund->merchant_pub),
|
||||||
"rtransaction_id", (json_int_t) refund->rtransaction_id,
|
"rtransaction_id", (json_int_t) refund->rtransaction_id,
|
||||||
"merchant_sig", GNUNET_JSON_from_data_auto (&refund->merchant_sig))));
|
"merchant_sig", GNUNET_JSON_from_data_auto (&refund->merchant_sig))))
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
json_decref (history);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TALER_EXCHANGEDB_TT_PAYBACK:
|
case TALER_EXCHANGEDB_TT_PAYBACK:
|
||||||
@ -627,7 +655,7 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
|||||||
json_decref (history);
|
json_decref (history);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
GNUNET_assert (0 ==
|
if (0 !=
|
||||||
json_array_append_new (history,
|
json_array_append_new (history,
|
||||||
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
|
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
|
||||||
"type", "PAYBACK",
|
"type", "PAYBACK",
|
||||||
@ -635,7 +663,12 @@ TEH_RESPONSE_compile_transaction_history (const struct TALER_EXCHANGEDB_Transact
|
|||||||
"exchange_sig", GNUNET_JSON_from_data_auto (&esig),
|
"exchange_sig", GNUNET_JSON_from_data_auto (&esig),
|
||||||
"exchange_pub", GNUNET_JSON_from_data_auto (&epub),
|
"exchange_pub", GNUNET_JSON_from_data_auto (&epub),
|
||||||
"reserve_pub", GNUNET_JSON_from_data_auto (&payback->reserve_pub),
|
"reserve_pub", GNUNET_JSON_from_data_auto (&payback->reserve_pub),
|
||||||
"timestamp", GNUNET_JSON_from_time_abs (payback->timestamp))));
|
"timestamp", GNUNET_JSON_from_time_abs (payback->timestamp))))
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
json_decref (history);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -717,7 +750,7 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ret |= 1;
|
ret |= 1;
|
||||||
GNUNET_assert (0 ==
|
if (0 !=
|
||||||
json_array_append_new (json_history,
|
json_array_append_new (json_history,
|
||||||
json_pack ("{s:s, s:o, s:s, s:o, s:o}",
|
json_pack ("{s:s, s:o, s:s, s:o, s:o}",
|
||||||
"type", "DEPOSIT",
|
"type", "DEPOSIT",
|
||||||
@ -725,7 +758,12 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
|
|||||||
"sender_account_url", pos->details.bank->sender_account_details,
|
"sender_account_url", pos->details.bank->sender_account_details,
|
||||||
"wire_reference", GNUNET_JSON_from_data (pos->details.bank->wire_reference,
|
"wire_reference", GNUNET_JSON_from_data (pos->details.bank->wire_reference,
|
||||||
pos->details.bank->wire_reference_size),
|
pos->details.bank->wire_reference_size),
|
||||||
"amount", TALER_JSON_from_amount (&pos->details.bank->amount))));
|
"amount", TALER_JSON_from_amount (&pos->details.bank->amount))))
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
json_decref (json_history);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case TALER_EXCHANGEDB_RO_WITHDRAW_COIN:
|
case TALER_EXCHANGEDB_RO_WITHDRAW_COIN:
|
||||||
{
|
{
|
||||||
@ -749,7 +787,7 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret |= 2;
|
ret |= 2;
|
||||||
GNUNET_assert (0 ==
|
if (0 !=
|
||||||
json_array_append_new (json_history,
|
json_array_append_new (json_history,
|
||||||
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
|
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
|
||||||
"type", "WITHDRAW",
|
"type", "WITHDRAW",
|
||||||
@ -757,7 +795,12 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
|
|||||||
"h_coin_envelope", GNUNET_JSON_from_data_auto (&pos->details.withdraw->h_coin_envelope),
|
"h_coin_envelope", GNUNET_JSON_from_data_auto (&pos->details.withdraw->h_coin_envelope),
|
||||||
"h_denom_pub", GNUNET_JSON_from_data_auto (&pos->details.withdraw->denom_pub_hash),
|
"h_denom_pub", GNUNET_JSON_from_data_auto (&pos->details.withdraw->denom_pub_hash),
|
||||||
"withdraw_fee", TALER_JSON_from_amount (&pos->details.withdraw->withdraw_fee),
|
"withdraw_fee", TALER_JSON_from_amount (&pos->details.withdraw->withdraw_fee),
|
||||||
"amount", TALER_JSON_from_amount (&value))));
|
"amount", TALER_JSON_from_amount (&value))))
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
json_decref (json_history);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TALER_EXCHANGEDB_RO_PAYBACK_COIN:
|
case TALER_EXCHANGEDB_RO_PAYBACK_COIN:
|
||||||
@ -798,7 +841,7 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
GNUNET_assert (0 ==
|
if (0 !=
|
||||||
json_array_append_new (json_history,
|
json_array_append_new (json_history,
|
||||||
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
|
json_pack ("{s:s, s:o, s:o, s:o, s:o, s:o}",
|
||||||
"type", "PAYBACK",
|
"type", "PAYBACK",
|
||||||
@ -806,12 +849,16 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
|
|||||||
"exchange_sig", GNUNET_JSON_from_data_auto (&sig),
|
"exchange_sig", GNUNET_JSON_from_data_auto (&sig),
|
||||||
"timestamp", GNUNET_JSON_from_time_abs (payback->timestamp),
|
"timestamp", GNUNET_JSON_from_time_abs (payback->timestamp),
|
||||||
"amount", TALER_JSON_from_amount (&payback->value),
|
"amount", TALER_JSON_from_amount (&payback->value),
|
||||||
"coin_pub", GNUNET_JSON_from_data_auto (&payback->coin.coin_pub))));
|
"coin_pub", GNUNET_JSON_from_data_auto (&payback->coin.coin_pub))))
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
json_decref (json_history);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK:
|
case TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK:
|
||||||
{
|
{
|
||||||
|
|
||||||
struct TALER_ReserveCloseConfirmationPS rcc;
|
struct TALER_ReserveCloseConfirmationPS rcc;
|
||||||
struct TALER_ExchangePublicKeyP pub;
|
struct TALER_ExchangePublicKeyP pub;
|
||||||
struct TALER_ExchangeSignatureP sig;
|
struct TALER_ExchangeSignatureP sig;
|
||||||
@ -829,6 +876,7 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
|
|||||||
&withdraw_total,
|
&withdraw_total,
|
||||||
&value))
|
&value))
|
||||||
{
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
json_decref (json_history);
|
json_decref (json_history);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -855,7 +903,7 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
|
|||||||
json_decref (json_history);
|
json_decref (json_history);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
GNUNET_assert (0 ==
|
if (0 !=
|
||||||
json_array_append_new (json_history,
|
json_array_append_new (json_history,
|
||||||
json_pack ("{s:s, s:s, s:o, s:o, s:o, s:o, s:o, s:o}",
|
json_pack ("{s:s, s:s, s:o, s:o, s:o, s:o, s:o, s:o}",
|
||||||
"type", "CLOSING",
|
"type", "CLOSING",
|
||||||
@ -865,7 +913,12 @@ TEH_RESPONSE_compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHisto
|
|||||||
"exchange_sig", GNUNET_JSON_from_data_auto (&sig),
|
"exchange_sig", GNUNET_JSON_from_data_auto (&sig),
|
||||||
"timestamp", GNUNET_JSON_from_time_abs (pos->details.closing->execution_date),
|
"timestamp", GNUNET_JSON_from_time_abs (pos->details.closing->execution_date),
|
||||||
"amount", TALER_JSON_from_amount (&value),
|
"amount", TALER_JSON_from_amount (&value),
|
||||||
"closing_fee", TALER_JSON_from_amount (&pos->details.closing->closing_fee))));
|
"closing_fee", TALER_JSON_from_amount (&pos->details.closing->closing_fee))))
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
json_decref (json_history);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -918,5 +971,4 @@ TEH_RESPONSE_reply_transaction_unknown (struct MHD_Connection *connection,
|
|||||||
"code", (json_int_t) ec);
|
"code", (json_int_t) ec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* end of taler-exchange-httpd_responses.c */
|
/* end of taler-exchange-httpd_responses.c */
|
||||||
|
Loading…
Reference in New Issue
Block a user