summaryrefslogtreecommitdiff
path: root/src/mint
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-04-09 20:37:21 +0200
committerChristian Grothoff <christian@grothoff.org>2015-04-09 20:37:21 +0200
commit8ecb69399070d5afd6086076015d2fade9274cc8 (patch)
treeaee8258384a0fd1479af6581c4b5c473020d6ba9 /src/mint
parentd04360879ef1719ecdffd7fa202c53463550b691 (diff)
downloadexchange-8ecb69399070d5afd6086076015d2fade9274cc8.tar.gz
exchange-8ecb69399070d5afd6086076015d2fade9274cc8.tar.bz2
exchange-8ecb69399070d5afd6086076015d2fade9274cc8.zip
indenting and minor improvements to refresh operations to make them match API spec
Diffstat (limited to 'src/mint')
-rw-r--r--src/mint/taler-mint-httpd_db.c38
-rw-r--r--src/mint/taler-mint-httpd_refresh.c76
-rw-r--r--src/mint/taler-mint-httpd_responses.c71
3 files changed, 88 insertions, 97 deletions
diff --git a/src/mint/taler-mint-httpd_db.c b/src/mint/taler-mint-httpd_db.c
index d8ce9e1c4..93251d750 100644
--- a/src/mint/taler-mint-httpd_db.c
+++ b/src/mint/taler-mint-httpd_db.c
@@ -514,11 +514,8 @@ refresh_accept_melts (struct MHD_Connection *connection,
if (NULL == dki)
return (MHD_YES ==
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_NOT_FOUND,
- "{s:s}",
- "error",
- "denom not found"))
+ TMH_RESPONSE_reply_arg_unknown (connection,
+ "denom_pub"))
? GNUNET_NO : GNUNET_SYSERR;
TALER_amount_ntoh (&coin_value,
@@ -681,7 +678,7 @@ TMH_DB_execute_refresh_melt (struct MHD_Connection *connection,
denom_pubs))
{
TMH_plugin->rollback (TMH_plugin->cls,
- session);
+ session);
return TMH_RESPONSE_reply_internal_db_error (connection);
}
@@ -917,7 +914,7 @@ check_commitment (struct MHD_Connection *connection,
GNUNET_break (0);
GNUNET_free (commit_coins);
return (MHD_YES == TMH_RESPONSE_reply_internal_error (connection,
- "Decryption error"))
+ "Decryption error"))
? GNUNET_NO : GNUNET_SYSERR;
}
@@ -1227,7 +1224,7 @@ TMH_DB_execute_refresh_reveal (struct MHD_Connection *connection,
*/
int
TMH_DB_execute_refresh_link (struct MHD_Connection *connection,
- const union TALER_CoinSpendPublicKeyP *coin_pub)
+ const union TALER_CoinSpendPublicKeyP *coin_pub)
{
int res;
struct TALER_MINTDB_Session *session;
@@ -1236,16 +1233,16 @@ TMH_DB_execute_refresh_link (struct MHD_Connection *connection,
struct TALER_MINTDB_LinkDataList *ldl;
if (NULL == (session = TMH_plugin->get_session (TMH_plugin->cls,
- GNUNET_NO)))
+ GNUNET_NO)))
{
GNUNET_break (0);
return TMH_RESPONSE_reply_internal_db_error (connection);
}
res = TMH_plugin->get_transfer (TMH_plugin->cls,
- session,
- coin_pub,
- &transfer_pub,
- &shared_secret_enc);
+ session,
+ coin_pub,
+ &transfer_pub,
+ &shared_secret_enc);
if (GNUNET_SYSERR == res)
{
GNUNET_break (0);
@@ -1253,11 +1250,8 @@ TMH_DB_execute_refresh_link (struct MHD_Connection *connection,
}
if (GNUNET_NO == res)
{
- return TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_NOT_FOUND,
- "{s:s}",
- "error",
- "link data not found (transfer)");
+ return TMH_RESPONSE_reply_arg_unknown (connection,
+ "coin_pub");
}
GNUNET_assert (GNUNET_OK == res);
@@ -1273,11 +1267,11 @@ TMH_DB_execute_refresh_link (struct MHD_Connection *connection,
"link data not found (link)");
}
res = TMH_RESPONSE_reply_refresh_link_success (connection,
- &transfer_pub,
- &shared_secret_enc,
- ldl);
+ &transfer_pub,
+ &shared_secret_enc,
+ ldl);
TMH_plugin->free_link_data_list (TMH_plugin->cls,
- ldl);
+ ldl);
return res;
}
diff --git a/src/mint/taler-mint-httpd_refresh.c b/src/mint/taler-mint-httpd_refresh.c
index 287faefa8..ffe65911f 100644
--- a/src/mint/taler-mint-httpd_refresh.c
+++ b/src/mint/taler-mint-httpd_refresh.c
@@ -81,7 +81,7 @@ handle_refresh_melt_binary (struct MHD_Connection *connection,
for (i=0;i<num_new_denoms;i++)
{
dki = &TMH_KS_denomination_key_lookup (key_state,
- &denom_pubs[i])->issue;
+ &denom_pubs[i])->issue;
TALER_amount_ntoh (&value,
&dki->value);
TALER_amount_ntoh (&fee_withdraw,
@@ -97,7 +97,7 @@ handle_refresh_melt_binary (struct MHD_Connection *connection,
{
TMH_KS_release (key_state);
return TMH_RESPONSE_reply_internal_error (connection,
- "cost calculation failure");
+ "cost calculation failure");
}
}
@@ -119,7 +119,7 @@ handle_refresh_melt_binary (struct MHD_Connection *connection,
{
TMH_KS_release (key_state);
return TMH_RESPONSE_reply_external_error (connection,
- "Melt contribution below melting fee");
+ "Melt contribution below melting fee");
}
if (GNUNET_OK !=
TALER_amount_add (&total_melt,
@@ -128,7 +128,7 @@ handle_refresh_melt_binary (struct MHD_Connection *connection,
{
TMH_KS_release (key_state);
return TMH_RESPONSE_reply_internal_error (connection,
- "balance calculation failure");
+ "balance calculation failure");
}
}
TMH_KS_release (key_state);
@@ -198,10 +198,8 @@ get_coin_public_info (struct MHD_Connection *connection,
r_melt_detail->coin_info.denom_sig.rsa_signature = NULL;
r_melt_detail->coin_info.denom_pub.rsa_public_key = NULL;
return (MHD_YES ==
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_NOT_FOUND,
- "{s:s}",
- "error", "coin invalid"))
+ TMH_RESPONSE_reply_signature_invalid (connection,
+ "denom_sig"))
? GNUNET_NO : GNUNET_SYSERR;
}
r_melt_detail->melt_sig = melt_sig;
@@ -242,7 +240,7 @@ verify_coin_public_info (struct MHD_Connection *connection,
{
TMH_KS_release (key_state);
TALER_LOG_WARNING ("Unknown denomination key in /refresh/melt request\n");
- return TMH_RESPONSE_reply_arg_invalid (connection,
+ return TMH_RESPONSE_reply_arg_unknown (connection,
"denom_pub");
}
/* FIXME: need to check if denomination key is still
@@ -275,10 +273,8 @@ verify_coin_public_info (struct MHD_Connection *connection,
&melt_detail->coin_info.coin_pub.ecdsa_pub))
{
if (MHD_YES !=
- TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_UNAUTHORIZED,
- "{s:s}",
- "error", "signature invalid"))
+ TMH_RESPONSE_reply_signature_invalid (connection,
+ "confirm_sig"))
return GNUNET_SYSERR;
return GNUNET_NO;
}
@@ -453,7 +449,7 @@ handle_refresh_melt_json (struct MHD_Connection *connection,
GNUNET_free (coin_melt_details);
GNUNET_free (denom_pubs);
return TMH_RESPONSE_reply_external_error (connection,
- "melting same coin twice in same session is not allowed");
+ "melting same coin twice in same session is not allowed");
}
}
TALER_amount_hton (&melt_amount,
@@ -558,7 +554,7 @@ handle_refresh_melt_json (struct MHD_Connection *connection,
TMH_PARSE_JNC_INDEX, (int) j,
TMH_PARSE_JNC_RET_DATA,
&rcl->shared_secret_enc,
- sizeof (struct GNUNET_HashCode));
+ sizeof (struct TALER_EncryptedLinkSecretP));
if (GNUNET_OK != res)
{
@@ -676,8 +672,8 @@ TMH_REFRESH_handler_refresh_melt (struct TMH_RequestHandler *rh,
return MHD_YES;
res = TMH_PARSE_json_data (connection,
- root,
- spec);
+ root,
+ spec);
json_decref (root);
if (GNUNET_OK != res)
return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES;
@@ -688,19 +684,19 @@ TMH_REFRESH_handler_refresh_melt (struct TMH_RequestHandler *rh,
GNUNET_break_op (0);
TMH_PARSE_release_data (spec);
return TMH_RESPONSE_reply_arg_invalid (connection,
- "coin_evs");
+ "coin_evs");
}
if (TALER_CNC_KAPPA != json_array_size (transfer_pubs))
{
GNUNET_break_op (0);
TMH_PARSE_release_data (spec);
return TMH_RESPONSE_reply_arg_invalid (connection,
- "transfer_pubs");
+ "transfer_pubs");
}
res = TMH_PARSE_navigate_json (connection, coin_evs,
- TMH_PARSE_JNC_INDEX, (int) 0,
- TMH_PARSE_JNC_RET_DATA,
- JSON_ARRAY, &coin_detail);
+ TMH_PARSE_JNC_INDEX, (int) 0,
+ TMH_PARSE_JNC_RET_DATA,
+ JSON_ARRAY, &coin_detail);
if (GNUNET_OK != res)
{
TMH_PARSE_release_data (spec);
@@ -708,10 +704,10 @@ TMH_REFRESH_handler_refresh_melt (struct TMH_RequestHandler *rh,
}
num_newcoins = json_array_size (coin_detail);
res = TMH_PARSE_navigate_json (connection,
- transfer_pubs,
- TMH_PARSE_JNC_INDEX, (int) 0,
- TMH_PARSE_JNC_RET_DATA,
- JSON_ARRAY, &coin_detail);
+ transfer_pubs,
+ TMH_PARSE_JNC_INDEX, (int) 0,
+ TMH_PARSE_JNC_RET_DATA,
+ JSON_ARRAY, &coin_detail);
if (GNUNET_OK != res)
{
TMH_PARSE_release_data (spec);
@@ -771,12 +767,12 @@ handle_refresh_reveal_json (struct MHD_Connection *connection,
if (GNUNET_OK != res)
break;
res = TMH_PARSE_navigate_json (connection,
- tp_json,
- TMH_PARSE_JNC_INDEX, (int) i,
- TMH_PARSE_JNC_INDEX, (int) j,
- TMH_PARSE_JNC_RET_DATA,
- &transfer_privs[i][j],
- sizeof (struct TALER_TransferPrivateKeyP));
+ tp_json,
+ TMH_PARSE_JNC_INDEX, (int) i,
+ TMH_PARSE_JNC_INDEX, (int) j,
+ TMH_PARSE_JNC_RET_DATA,
+ &transfer_privs[i][j],
+ sizeof (struct TALER_TransferPrivateKeyP));
}
}
if (GNUNET_OK != res)
@@ -838,8 +834,8 @@ TMH_REFRESH_handler_refresh_reveal (struct TMH_RequestHandler *rh,
return MHD_YES;
res = TMH_PARSE_json_data (connection,
- root,
- spec);
+ root,
+ spec);
json_decref (root);
if (GNUNET_OK != res)
return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES;
@@ -849,15 +845,15 @@ TMH_REFRESH_handler_refresh_reveal (struct TMH_RequestHandler *rh,
{
TMH_PARSE_release_data (spec);
return TMH_RESPONSE_reply_arg_invalid (connection,
- "transfer_privs");
+ "transfer_privs");
}
/* Note we do +1 as 1 row (cut-and-choose!) is missing! */
res = TMH_PARSE_navigate_json (connection,
- transfer_privs,
- TMH_PARSE_JNC_INDEX, 0,
- TMH_PARSE_JNC_RET_TYPED_JSON,
- JSON_ARRAY,
- &reveal_detail);
+ transfer_privs,
+ TMH_PARSE_JNC_INDEX, 0,
+ TMH_PARSE_JNC_RET_TYPED_JSON,
+ JSON_ARRAY,
+ &reveal_detail);
if (GNUNET_OK != res)
{
TMH_PARSE_release_data (spec);
diff --git a/src/mint/taler-mint-httpd_responses.c b/src/mint/taler-mint-httpd_responses.c
index bec632520..c567103f0 100644
--- a/src/mint/taler-mint-httpd_responses.c
+++ b/src/mint/taler-mint-httpd_responses.c
@@ -199,7 +199,7 @@ TMH_RESPONSE_reply_internal_error (struct MHD_Connection *connection,
*/
int
TMH_RESPONSE_reply_external_error (struct MHD_Connection *connection,
- const char *hint)
+ const char *hint)
{
return TMH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_BAD_REQUEST,
@@ -442,7 +442,7 @@ TMH_RESPONSE_reply_deposit_insufficient_funds (struct MHD_Connection *connection
history = compile_transaction_history (tl);
return TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_FORBIDDEN,
+ MHD_HTTP_PRECONDITION_FAILED,
"{s:s, s:o}",
"error", "insufficient funds",
"history", history);
@@ -625,7 +625,7 @@ TMH_RESPONSE_reply_withdraw_sign_insufficient_funds (struct MHD_Connection *conn
"balance calculation failure");
json_balance = TALER_json_from_amount (&balance);
ret = TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_PAYMENT_REQUIRED,
+ MHD_HTTP_FORBIDDEN,
"{s:s, s:o, s:o}",
"error", "Insufficient funds"
"balance", json_balance,
@@ -677,25 +677,25 @@ TMH_RESPONSE_reply_withdraw_sign_success (struct MHD_Connection *connection,
*/
int
TMH_RESPONSE_reply_refresh_melt_insufficient_funds (struct MHD_Connection *connection,
- const union TALER_CoinSpendPublicKeyP *coin_pub,
- struct TALER_Amount coin_value,
- struct TALER_MINTDB_TransactionList *tl,
- struct TALER_Amount requested,
- struct TALER_Amount residual)
+ const union TALER_CoinSpendPublicKeyP *coin_pub,
+ struct TALER_Amount coin_value,
+ struct TALER_MINTDB_TransactionList *tl,
+ struct TALER_Amount requested,
+ struct TALER_Amount residual)
{
json_t *history;
history = compile_transaction_history (tl);
return TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_NOT_FOUND,
- "{s:s, s:o, s:o, s:o, s:o, s:o}",
- "error", "insufficient funds",
- "coin-pub", TALER_json_from_data (coin_pub,
- sizeof (union TALER_CoinSpendPublicKeyP)),
- "original-value", TALER_json_from_amount (&coin_value),
- "residual-value", TALER_json_from_amount (&residual),
- "requested-value", TALER_json_from_amount (&requested),
- "history", history);
+ MHD_HTTP_NOT_FOUND,
+ "{s:s, s:o, s:o, s:o, s:o, s:o}",
+ "error", "insufficient funds",
+ "coin-pub", TALER_json_from_data (coin_pub,
+ sizeof (union TALER_CoinSpendPublicKeyP)),
+ "original-value", TALER_json_from_amount (&coin_value),
+ "residual-value", TALER_json_from_amount (&residual),
+ "requested-value", TALER_json_from_amount (&requested),
+ "history", history);
}
@@ -709,8 +709,8 @@ TMH_RESPONSE_reply_refresh_melt_insufficient_funds (struct MHD_Connection *conne
*/
int
TMH_RESPONSE_reply_refresh_melt_success (struct MHD_Connection *connection,
- const struct GNUNET_HashCode *session_hash,
- uint16_t noreveal_index)
+ const struct GNUNET_HashCode *session_hash,
+ uint16_t noreveal_index)
{
struct TALER_RefreshMeltConfirmationPS body;
struct TALER_MintSignatureP sig;
@@ -727,10 +727,10 @@ TMH_RESPONSE_reply_refresh_melt_success (struct MHD_Connection *connection,
&sig.eddsa_signature);
GNUNET_assert (NULL != sig_json);
ret = TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_OK,
- "{s:i, s:o}",
- "noreveal_index", (int) noreveal_index,
- "signature", sig_json);
+ MHD_HTTP_OK,
+ "{s:i, s:o}",
+ "noreveal_index", (int) noreveal_index,
+ "signature", sig_json);
json_decref (sig_json);
return ret;
}
@@ -746,8 +746,8 @@ TMH_RESPONSE_reply_refresh_melt_success (struct MHD_Connection *connection,
*/
int
TMH_RESPONSE_reply_refresh_reveal_success (struct MHD_Connection *connection,
- unsigned int num_newcoins,
- const struct TALER_DenominationSignature *sigs)
+ unsigned int num_newcoins,
+ const struct TALER_DenominationSignature *sigs)
{
int newcoin_index;
json_t *root;
@@ -763,8 +763,8 @@ TMH_RESPONSE_reply_refresh_reveal_success (struct MHD_Connection *connection,
json_array_append_new (list,
TALER_json_from_rsa_signature (sigs[newcoin_index].rsa_signature));
ret = TMH_RESPONSE_reply_json (connection,
- root,
- MHD_HTTP_OK);
+ root,
+ MHD_HTTP_OK);
json_decref (root);
return ret;
}
@@ -789,12 +789,12 @@ TMH_RESPONSE_reply_refresh_reveal_success (struct MHD_Connection *connection,
*/
int
TMH_RESPONSE_reply_refresh_reveal_missmatch (struct MHD_Connection *connection,
- unsigned int off,
- unsigned int j,
- const char *missmatch_object)
+ unsigned int off,
+ unsigned int j,
+ const char *missmatch_object)
{
return TMH_RESPONSE_reply_json_pack (connection,
- MHD_HTTP_BAD_REQUEST,
+ MHD_HTTP_CONFLICT,
"{s:s, s:i, s:i, s:s}",
"error", "commitment violation",
"offset", (int) off,
@@ -814,9 +814,9 @@ TMH_RESPONSE_reply_refresh_reveal_missmatch (struct MHD_Connection *connection,
*/
int
TMH_RESPONSE_reply_refresh_link_success (struct MHD_Connection *connection,
- const struct TALER_TransferPublicKeyP *transfer_pub,
- const struct TALER_EncryptedLinkSecretP *shared_secret_enc,
- const struct TALER_MINTDB_LinkDataList *ldl)
+ const struct TALER_TransferPublicKeyP *transfer_pub,
+ const struct TALER_EncryptedLinkSecretP *shared_secret_enc,
+ const struct TALER_MINTDB_LinkDataList *ldl)
{
const struct TALER_MINTDB_LinkDataList *pos;
json_t *root;
@@ -829,7 +829,8 @@ TMH_RESPONSE_reply_refresh_link_success (struct MHD_Connection *connection,
json_t *obj;
obj = json_object ();
- json_object_set_new (obj, "link_enc",
+ json_object_set_new (obj,
+ "link_enc",
TALER_json_from_data (ldl->link_data_enc->coin_priv_enc,
sizeof (union TALER_CoinSpendPrivateKeyP) +
ldl->link_data_enc->blinding_key_enc_size));