diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-04-08 22:28:52 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-04-08 22:28:52 +0200 |
commit | 80b29ed2aef0c50a9755809816d781afc08ef71e (patch) | |
tree | d1dbc750be7e3017c6ee3521c19ba8073203b9ed | |
parent | 42147c2501d06c44c8bfbc052d72fb2e97eaa2c6 (diff) |
indentation and minor updates to reflect latest API docs
-rw-r--r-- | src/include/taler_amount_lib.h | 10 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_db.c | 72 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_deposit.c | 31 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_keystate.c | 14 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_parsing.c | 101 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_refresh.c | 6 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_responses.c | 150 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_responses.h | 24 | ||||
-rw-r--r-- | src/mint/taler-mint-httpd_withdraw.c | 8 | ||||
-rw-r--r-- | src/util/json.c | 11 |
10 files changed, 221 insertions, 206 deletions
diff --git a/src/include/taler_amount_lib.h b/src/include/taler_amount_lib.h index 60405a2e4..82952f0b2 100644 --- a/src/include/taler_amount_lib.h +++ b/src/include/taler_amount_lib.h @@ -24,11 +24,13 @@ /** * @brief Number of characters (plus 1 for 0-termination) we use to - * represent currency names (i.e. EUR, USD, etc.). We use - * 4 for alignment as 3 characters are typical and we need a - * 0-terminator. So do not change this. + * represent currency names (i.e. EUR, USD, etc.). We use 8+4 for + * alignment in the `struct TALER_Amount`. The amount is typically an + * ISO 4217 currency code when an alpha-numeric 3-digit code is used. + * For regional currencies, the first character should be a "*" followed + * by a region-specific name (i.e. "*BRETAGNEFR"). */ -#define TALER_CURRENCY_LEN 4 +#define TALER_CURRENCY_LEN 12 /** * @brief The "fraction" value in a `struct TALER_Amount` represents which diff --git a/src/mint/taler-mint-httpd_db.c b/src/mint/taler-mint-httpd_db.c index 3f009e735..d8ce9e1c4 100644 --- a/src/mint/taler-mint-httpd_db.c +++ b/src/mint/taler-mint-httpd_db.c @@ -186,7 +186,7 @@ TMH_DB_execute_deposit (struct MHD_Connection *connection, { TALER_LOG_WARNING ("Failed to store /deposit information in database\n"); TMH_plugin->rollback (TMH_plugin->cls, - session); + session); return TMH_RESPONSE_reply_internal_db_error (connection); } @@ -218,30 +218,31 @@ TMH_DB_execute_deposit (struct MHD_Connection *connection, */ int TMH_DB_execute_withdraw_status (struct MHD_Connection *connection, - const struct TALER_ReservePublicKeyP *reserve_pub) + const struct TALER_ReservePublicKeyP *reserve_pub) { struct TALER_MINTDB_Session *session; struct TALER_MINTDB_ReserveHistory *rh; int res; 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); } rh = TMH_plugin->get_reserve_history (TMH_plugin->cls, - session, - reserve_pub); + session, + reserve_pub); if (NULL == rh) return TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_NOT_FOUND, - "{s:s}", - "error", "Reserve not found"); + MHD_HTTP_NOT_FOUND, + "{s:s, s:s}", + "error", "Reserve not found", + "parameter", "withdraw_pub"); res = TMH_RESPONSE_reply_withdraw_status_success (connection, - rh); + rh); TMH_plugin->free_reserve_history (TMH_plugin->cls, - rh); + rh); return res; } @@ -262,11 +263,11 @@ TMH_DB_execute_withdraw_status (struct MHD_Connection *connection, */ int TMH_DB_execute_withdraw_sign (struct MHD_Connection *connection, - const struct TALER_ReservePublicKeyP *reserve, - const struct TALER_DenominationPublicKey *denomination_pub, - const char *blinded_msg, - size_t blinded_msg_len, - const struct TALER_ReserveSignatureP *signature) + const struct TALER_ReservePublicKeyP *reserve, + const struct TALER_DenominationPublicKey *denomination_pub, + const char *blinded_msg, + size_t blinded_msg_len, + const struct TALER_ReserveSignatureP *signature) { struct TALER_MINTDB_Session *session; struct TALER_MINTDB_ReserveHistory *rh; @@ -290,15 +291,15 @@ TMH_DB_execute_withdraw_sign (struct MHD_Connection *connection, &h_blind); 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_collectable_blindcoin (TMH_plugin->cls, - session, - &h_blind, - &collectable); + session, + &h_blind, + &collectable); if (GNUNET_SYSERR == res) { GNUNET_break (0); @@ -319,15 +320,15 @@ TMH_DB_execute_withdraw_sign (struct MHD_Connection *connection, /* Check if balance is sufficient */ key_state = TMH_KS_acquire (); dki = TMH_KS_denomination_key_lookup (key_state, - denomination_pub); + denomination_pub); if (NULL == dki) { TMH_KS_release (key_state); return TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_NOT_FOUND, - "{s:s}", - "error", - "Denomination not found"); + MHD_HTTP_NOT_FOUND, + "{s:s}", + "error", + "Denomination not found"); } if (GNUNET_OK != TMH_plugin->start (TMH_plugin->cls, @@ -339,18 +340,15 @@ TMH_DB_execute_withdraw_sign (struct MHD_Connection *connection, } rh = TMH_plugin->get_reserve_history (TMH_plugin->cls, - session, - reserve); + session, + reserve); if (NULL == rh) { TMH_plugin->rollback (TMH_plugin->cls, session); TMH_KS_release (key_state); - return TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_NOT_FOUND, - "{s:s}", - "error", - "Reserve not found"); + return TMH_RESPONSE_reply_arg_unknown (connection, + "reserve_pub"); } /* calculate amount required including fees */ @@ -386,7 +384,7 @@ TMH_DB_execute_withdraw_sign (struct MHD_Connection *connection, &pos->details.bank->amount)) { TMH_plugin->rollback (TMH_plugin->cls, - session); + session); TMH_KS_release (key_state); return TMH_RESPONSE_reply_internal_db_error (connection); } @@ -394,7 +392,7 @@ TMH_DB_execute_withdraw_sign (struct MHD_Connection *connection, break; case TALER_MINTDB_RO_WITHDRAW_COIN: tdki = TMH_KS_denomination_key_lookup (key_state, - &pos->details.withdraw->denom_pub); + &pos->details.withdraw->denom_pub); TALER_amount_ntoh (&value, &tdki->issue.value); if (0 == (res & 2)) @@ -406,7 +404,7 @@ TMH_DB_execute_withdraw_sign (struct MHD_Connection *connection, &value)) { TMH_plugin->rollback (TMH_plugin->cls, - session); + session); TMH_KS_release (key_state); return TMH_RESPONSE_reply_internal_db_error (connection); } @@ -426,13 +424,13 @@ TMH_DB_execute_withdraw_sign (struct MHD_Connection *connection, TMH_plugin->rollback (TMH_plugin->cls, session); res = TMH_RESPONSE_reply_withdraw_sign_insufficient_funds (connection, - rh); + rh); TMH_plugin->free_reserve_history (TMH_plugin->cls, - rh); + rh); return res; } TMH_plugin->free_reserve_history (TMH_plugin->cls, - rh); + rh); /* Balance is good, sign the coin! */ sig = GNUNET_CRYPTO_rsa_sign (dki->denom_priv.rsa_private_key, diff --git a/src/mint/taler-mint-httpd_deposit.c b/src/mint/taler-mint-httpd_deposit.c index 18cc18f7b..e85eac78a 100644 --- a/src/mint/taler-mint-httpd_deposit.c +++ b/src/mint/taler-mint-httpd_deposit.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014 GNUnet e.V. + Copyright (C) 2014, 2015 GNUnet e.V. 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 @@ -23,8 +23,8 @@ * @author Christian Grothoff * * TODO: - * - missing 'wire' format check (well-formed SEPA-details) - * - ugliy if-construction for deposit type + * - missing 'wire' format check (well-formed SEPA-details) (#3624) + * - ugly if-construction for deposit type */ #include "platform.h" #include <gnunet/gnunet_util_lib.h> @@ -80,19 +80,19 @@ verify_and_execute_deposit (struct MHD_Connection *connection, &deposit->coin.coin_pub.ecdsa_pub)) { TALER_LOG_WARNING ("Invalid signature on /deposit request\n"); - return TMH_RESPONSE_reply_arg_invalid (connection, - "csig"); + return TMH_RESPONSE_reply_signature_invalid (connection, + "coin_sig"); } /* check denomination exists and is valid */ key_state = TMH_KS_acquire (); dki = TMH_KS_denomination_key_lookup (key_state, - &deposit->coin.denom_pub); + &deposit->coin.denom_pub); if (NULL == dki) { TMH_KS_release (key_state); TALER_LOG_WARNING ("Unknown denomination key in /deposit request\n"); - return TMH_RESPONSE_reply_arg_invalid (connection, - "denom_pub"); + return TMH_RESPONSE_reply_arg_unknown (connection, + "denom_pub"); } /* check coin signature */ if (GNUNET_YES != @@ -100,7 +100,8 @@ verify_and_execute_deposit (struct MHD_Connection *connection, { TALER_LOG_WARNING ("Invalid coin passed for /deposit\n"); TMH_KS_release (key_state); - return TMH_RESPONSE_reply_coin_invalid (connection); + return TMH_RESPONSE_reply_signature_invalid (connection, + "ub_sig"); } TALER_amount_ntoh (&fee_deposit, &dki->issue.fee_deposit); @@ -110,7 +111,7 @@ verify_and_execute_deposit (struct MHD_Connection *connection, TMH_KS_release (key_state); return (MHD_YES == TMH_RESPONSE_reply_external_error (connection, - "deposited amount smaller than depositing fee")) + "deposited amount smaller than depositing fee")) ? GNUNET_NO : GNUNET_SYSERR; } TMH_KS_release (key_state); @@ -145,12 +146,12 @@ parse_and_handle_deposit_request (struct MHD_Connection *connection, struct TMH_KS_StateHandle *ks; struct TMH_PARSE_FieldSpecification spec[] = { TMH_PARSE_MEMBER_DENOMINATION_PUBLIC_KEY ("denom_pub", &deposit.coin.denom_pub), - TMH_PARSE_MEMBER_DENOMINATION_SIGNATURE ("ubsig", &deposit.coin.denom_sig), + TMH_PARSE_MEMBER_DENOMINATION_SIGNATURE ("ub_sig", &deposit.coin.denom_sig), TMH_PARSE_MEMBER_FIXED ("coin_pub", &deposit.coin.coin_pub), TMH_PARSE_MEMBER_FIXED ("merchant_pub", &deposit.merchant_pub), - TMH_PARSE_MEMBER_FIXED ("H_a", &deposit.h_contract), + TMH_PARSE_MEMBER_FIXED ("H_contract", &deposit.h_contract), TMH_PARSE_MEMBER_FIXED ("H_wire", &deposit.h_wire), - TMH_PARSE_MEMBER_FIXED ("csig", &deposit.csig), + TMH_PARSE_MEMBER_FIXED ("coin_sig", &deposit.csig), TMH_PARSE_MEMBER_FIXED ("transaction_id", &deposit.transaction_id), TMH_PARSE_MEMBER_TIME_ABS ("timestamp", &deposit.timestamp), TMH_PARSE_MEMBER_TIME_ABS ("refund_deadline", &deposit.refund_deadline), @@ -170,7 +171,7 @@ parse_and_handle_deposit_request (struct MHD_Connection *connection, wire)) { TMH_PARSE_release_data (spec); - return TMH_RESPONSE_reply_arg_invalid (connection, + return TMH_RESPONSE_reply_arg_unknown (connection, "wire"); } if (NULL == (wire_enc = json_dumps (wire, JSON_COMPACT | JSON_SORT_KEYS))) @@ -192,7 +193,7 @@ parse_and_handle_deposit_request (struct MHD_Connection *connection, { TMH_KS_release (ks); TMH_PARSE_release_data (spec); - return TMH_RESPONSE_reply_arg_invalid (connection, + return TMH_RESPONSE_reply_arg_unknown (connection, "denom_pub"); } TALER_amount_ntoh (&deposit.deposit_fee, diff --git a/src/mint/taler-mint-httpd_keystate.c b/src/mint/taler-mint-httpd_keystate.c index 8caeb2d01..bb4b74eec 100644 --- a/src/mint/taler-mint-httpd_keystate.c +++ b/src/mint/taler-mint-httpd_keystate.c @@ -406,18 +406,18 @@ TMH_KS_acquire (void) GNUNET_NO); key_state->reload_time = GNUNET_TIME_absolute_get (); TALER_MINTDB_denomination_keys_iterate (TMH_mint_directory, - &reload_keys_denom_iter, - key_state); + &reload_keys_denom_iter, + key_state); TALER_MINTDB_signing_keys_iterate (TMH_mint_directory, - &reload_keys_sign_iter, - key_state); + &reload_keys_sign_iter, + key_state); key_state->next_reload = GNUNET_TIME_absolute_ntoh (key_state->current_sign_key_issue.issue.expire); if (0 == key_state->next_reload.abs_value_us) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No valid signing key found!\n"); keys = json_pack ("{s:o, s:o, s:o, s:o}", - "TMH_master_public_key", + "master_public_key", TALER_json_from_data (&TMH_master_public_key, sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)), "signkeys", key_state->sign_keys_array, @@ -436,8 +436,8 @@ TMH_KS_acquire (void) &sig); keys = json_pack ("{s:o, s:o}", "keys", keys, - "eddsa-signature", TALER_json_from_eddsa_sig (&ks.purpose, - &sig.eddsa_signature)); + "eddsa_sig", TALER_json_from_eddsa_sig (&ks.purpose, + &sig.eddsa_signature)); key_state->keys_json = json_dumps (keys, JSON_INDENT (2)); json_decref (keys); diff --git a/src/mint/taler-mint-httpd_parsing.c b/src/mint/taler-mint-httpd_parsing.c index f8df1855c..7f08d76e0 100644 --- a/src/mint/taler-mint-httpd_parsing.c +++ b/src/mint/taler-mint-httpd_parsing.c @@ -276,9 +276,9 @@ TMH_PARSE_post_cleanup_callback (void *con_cls) */ int TMH_PARSE_mhd_request_arg_data (struct MHD_Connection *connection, - const char *param_name, - void *out_data, - size_t out_size) + const char *param_name, + void *out_data, + size_t out_size) { const char *str; @@ -406,14 +406,11 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, { ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s, s:s, s:o}", - "error", - "missing field in JSON", - "field", - fname, - "path", - path)) + MHD_HTTP_BAD_REQUEST, + "{s:s, s:s, s:o}", + "error", "missing field in JSON", + "field", fname, + "path", path)) ? GNUNET_NO : GNUNET_SYSERR; break; } @@ -432,11 +429,10 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, { ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s, s:o}", - "error", - "missing index in JSON", - "path", path)) + MHD_HTTP_BAD_REQUEST, + "{s:s, s:o}", + "error", "missing index in JSON", + "path", path)) ? GNUNET_NO : GNUNET_SYSERR; break; } @@ -458,10 +454,8 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, "{s:s, s:o}", - "error", - "string expected", - "path", - path)) + "error", "string expected", + "path", path)) ? GNUNET_NO : GNUNET_SYSERR; break; } @@ -471,12 +465,10 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, { ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s, s:o}", - "error", - "malformed binary data in JSON", - "path", - path)) + MHD_HTTP_BAD_REQUEST, + "{s:s, s:o}", + "error", "malformed binary data in JSON", + "path", path)) ? GNUNET_NO : GNUNET_SYSERR; break; } @@ -517,11 +509,10 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, *len = 0; ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s, s:o}", - "error", - "malformed binary data in JSON", - "path", path)) + MHD_HTTP_BAD_REQUEST, + "{s:s, s:o}", + "error", "malformed binary data in JSON", + "path", path)) ? GNUNET_NO : GNUNET_SYSERR; break; } @@ -539,12 +530,12 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, { ret = (MHD_YES == TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s, s:i, s:i, s:o}", - "error", "wrong JSON field type", - "type_expected", typ, - "type_actual", json_typeof (root), - "path", path)) + MHD_HTTP_BAD_REQUEST, + "{s:s, s:i, s:i, s:o}", + "error", "wrong JSON field type", + "type_expected", typ, + "type_actual", json_typeof (root), + "path", path)) ? GNUNET_NO : GNUNET_SYSERR; break; } @@ -570,10 +561,8 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, "{s:s, s:o}", - "error", - "string expected", - "path", - path)) + "error", "string expected", + "path", path)) ? GNUNET_NO : GNUNET_SYSERR; break; } @@ -590,10 +579,8 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, "{s:s, s:o}", - "error", - "malformed binary data in JSON", - "path", - path)) + "error", "malformed binary data in JSON", + "path", path)) ? GNUNET_NO : GNUNET_SYSERR; break; } @@ -606,10 +593,8 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, "{s:s, s:o}", - "error", - "malformed RSA public key in JSON", - "path", - path)) + "error", "malformed RSA public key in JSON", + "path", path)) ? GNUNET_NO : GNUNET_SYSERR; break; } @@ -634,10 +619,8 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, "{s:s, s:o}", - "error", - "string expected", - "path", - path)) + "error", "string expected", + "path", path)) ? GNUNET_NO : GNUNET_SYSERR; break; } @@ -654,10 +637,8 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, "{s:s, s:o}", - "error", - "malformed binary data in JSON", - "path", - path)) + "error", "malformed binary data in JSON", + "path", path)) ? GNUNET_NO : GNUNET_SYSERR; break; } @@ -670,10 +651,8 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection, TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_BAD_REQUEST, "{s:s, s:o}", - "error", - "malformed RSA signature in JSON", - "path", - path)) + "error", "malformed RSA signature in JSON", + "path", path)) ? GNUNET_NO : GNUNET_SYSERR; break; } diff --git a/src/mint/taler-mint-httpd_refresh.c b/src/mint/taler-mint-httpd_refresh.c index 151035c04..4e23e636e 100644 --- a/src/mint/taler-mint-httpd_refresh.c +++ b/src/mint/taler-mint-httpd_refresh.c @@ -139,9 +139,9 @@ handle_refresh_melt_binary (struct MHD_Connection *connection, /* We require total value of coins being melted and total value of coins being generated to match! */ return TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s}", - "error", "value mismatch"); + MHD_HTTP_BAD_REQUEST, + "{s:s}", + "error", "value mismatch"); } return TMH_DB_execute_refresh_melt (connection, session_hash, diff --git a/src/mint/taler-mint-httpd_responses.c b/src/mint/taler-mint-httpd_responses.c index 6367c6bd8..2060d3f84 100644 --- a/src/mint/taler-mint-httpd_responses.c +++ b/src/mint/taler-mint-httpd_responses.c @@ -39,8 +39,8 @@ */ int TMH_RESPONSE_reply_json (struct MHD_Connection *connection, - const json_t *json, - unsigned int response_code) + const json_t *json, + unsigned int response_code) { struct MHD_Response *resp; char *json_str; @@ -72,9 +72,9 @@ TMH_RESPONSE_reply_json (struct MHD_Connection *connection, */ int TMH_RESPONSE_reply_json_pack (struct MHD_Connection *connection, - unsigned int response_code, - const char *fmt, - ...) + unsigned int response_code, + const char *fmt, + ...) { json_t *json; va_list argp; @@ -86,8 +86,8 @@ TMH_RESPONSE_reply_json_pack (struct MHD_Connection *connection, if (NULL == json) return MHD_NO; ret = TMH_RESPONSE_reply_json (connection, - json, - response_code); + json, + response_code); json_decref (json); return ret; } @@ -102,33 +102,53 @@ TMH_RESPONSE_reply_json_pack (struct MHD_Connection *connection, */ int TMH_RESPONSE_reply_arg_invalid (struct MHD_Connection *connection, - const char *param_name) + const char *param_name) { return TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s, s:s}", - "error", "invalid parameter", - "parameter", param_name); + MHD_HTTP_BAD_REQUEST, + "{s:s, s:s}", + "error", "invalid parameter", + "parameter", param_name); } /** - * Send a response indicating an invalid coin. (I.e. the signature - * over the public key of the coin does not match a valid signing key - * of this mint). + * Send a response indicating an argument refering to a + * resource unknown to the mint (i.e. unknown reserve or + * denomination key). * * @param connection the MHD connection to use - * @return MHD result code + * @param param_name the parameter that is invalid + * @return a MHD result code */ int -TMH_RESPONSE_reply_coin_invalid (struct MHD_Connection *connection) +TMH_RESPONSE_reply_arg_unknown (struct MHD_Connection *connection, + const char *param_name) { - /* TODO: may want to be more precise in the future and - distinguish bogus signatures from bogus public keys. */ return TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_NOT_FOUND, - "{s:s}", - "error", "Coin is not valid"); + MHD_HTTP_NOT_FOUND, + "{s:s, s:s}", + "error", "unknown entity referenced", + "parameter", param_name); +} + + +/** + * Send a response indicating an invalid signature. + * + * @param connection the MHD connection to use + * @param param_name the parameter that is invalid + * @return a MHD result code + */ +int +TMH_RESPONSE_reply_signature_invalid (struct MHD_Connection *connection, + const char *param_name) +{ + return TMH_RESPONSE_reply_json_pack (connection, + MHD_HTTP_UNAUTHORIZED, + "{s:s, s:s}", + "error", "invalid signature", + "parameter", param_name); } @@ -141,13 +161,13 @@ TMH_RESPONSE_reply_coin_invalid (struct MHD_Connection *connection) */ int TMH_RESPONSE_reply_arg_missing (struct MHD_Connection *connection, - const char *param_name) + const char *param_name) { return TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{ s:s, s:s}", - "error", "missing parameter", - "parameter", param_name); + MHD_HTTP_BAD_REQUEST, + "{ s:s, s:s}", + "error", "missing parameter", + "parameter", param_name); } @@ -160,13 +180,13 @@ TMH_RESPONSE_reply_arg_missing (struct MHD_Connection *connection, */ int TMH_RESPONSE_reply_internal_error (struct MHD_Connection *connection, - const char *hint) + const char *hint) { return TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s, s:s}", - "error", "internal error", - "hint", hint); + MHD_HTTP_INTERNAL_SERVER_ERROR, + "{s:s, s:s}", + "error", "internal error", + "hint", hint); } @@ -256,10 +276,10 @@ int TMH_RESPONSE_reply_invalid_json (struct MHD_Connection *connection) { return TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s}", - "error", - "invalid json"); + MHD_HTTP_BAD_REQUEST, + "{s:s}", + "error", + "invalid json"); } @@ -312,10 +332,10 @@ TMH_RESPONSE_reply_deposit_success (struct MHD_Connection *connection, sig_json = TALER_json_from_eddsa_sig (&dc.purpose, &sig.eddsa_signature); ret = TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_OK, - "{s:s, s:o}", - "status", "DEPOSIT_OK", - "signature", sig_json); + MHD_HTTP_OK, + "{s:s, s:o}", + "status", "DEPOSIT_OK", + "signature", sig_json); json_decref (sig_json); return ret; } @@ -369,7 +389,7 @@ compile_transaction_history (const struct TALER_MINTDB_TransactionList *tl) { struct TALER_RefreshMeltCoinAffirmationPS ms; const struct TALER_MINTDB_RefreshMelt *melt = pos->details.melt; - +t type = "melt"; value = melt->amount_with_fee; ms.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_MELT); @@ -493,7 +513,7 @@ compile_reserve_history (const struct TALER_MINTDB_ReserveHistory *rh, case TALER_MINTDB_RO_WITHDRAW_COIN: dki = TMH_KS_denomination_key_lookup (key_state, - &pos->details.withdraw->denom_pub); + &pos->details.withdraw->denom_pub); TALER_amount_ntoh (&value, &dki->issue.value); if (0 == ret) @@ -556,7 +576,7 @@ compile_reserve_history (const struct TALER_MINTDB_ReserveHistory *rh, */ int TMH_RESPONSE_reply_withdraw_status_success (struct MHD_Connection *connection, - const struct TALER_MINTDB_ReserveHistory *rh) + const struct TALER_MINTDB_ReserveHistory *rh) { json_t *json_balance; json_t *json_history; @@ -567,13 +587,13 @@ TMH_RESPONSE_reply_withdraw_status_success (struct MHD_Connection *connection, &balance); if (NULL == json_history) return TMH_RESPONSE_reply_internal_error (connection, - "balance calculation failure"); + "balance calculation failure"); json_balance = TALER_json_from_amount (&balance); ret = TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_OK, - "{s:o, s:o}", - "balance", json_balance, - "history", json_history); + MHD_HTTP_OK, + "{s:o, s:o}", + "balance", json_balance, + "history", json_history); json_decref (json_history); json_decref (json_balance); return ret; @@ -591,7 +611,7 @@ TMH_RESPONSE_reply_withdraw_status_success (struct MHD_Connection *connection, */ int TMH_RESPONSE_reply_withdraw_sign_insufficient_funds (struct MHD_Connection *connection, - const struct TALER_MINTDB_ReserveHistory *rh) + const struct TALER_MINTDB_ReserveHistory *rh) { json_t *json_balance; json_t *json_history; @@ -602,14 +622,14 @@ TMH_RESPONSE_reply_withdraw_sign_insufficient_funds (struct MHD_Connection *conn &balance); if (NULL == json_history) return TMH_RESPONSE_reply_internal_error (connection, - "balance calculation failure"); + "balance calculation failure"); json_balance = TALER_json_from_amount (&balance); ret = TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_PAYMENT_REQUIRED, - "{s:s, s:o, s:o}", - "error", "Insufficient funds" - "balance", json_balance, - "history", json_history); + MHD_HTTP_PAYMENT_REQUIRED, + "{s:s, s:o, s:o}", + "error", "Insufficient funds" + "balance", json_balance, + "history", json_history); json_decref (json_history); json_decref (json_balance); return ret; @@ -625,16 +645,16 @@ TMH_RESPONSE_reply_withdraw_sign_insufficient_funds (struct MHD_Connection *conn */ int TMH_RESPONSE_reply_withdraw_sign_success (struct MHD_Connection *connection, - const struct TALER_MINTDB_CollectableBlindcoin *collectable) + const struct TALER_MINTDB_CollectableBlindcoin *collectable) { json_t *sig_json; int ret; sig_json = TALER_json_from_rsa_signature (collectable->sig.rsa_signature); ret = TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_OK, - "{s:o}", - "ev_sig", sig_json); + MHD_HTTP_OK, + "{s:o}", + "ev_sig", sig_json); json_decref (sig_json); return ret; } @@ -774,12 +794,12 @@ TMH_RESPONSE_reply_refresh_reveal_missmatch (struct MHD_Connection *connection, const char *missmatch_object) { return TMH_RESPONSE_reply_json_pack (connection, - MHD_HTTP_BAD_REQUEST, - "{s:s, s:i, s:i, s:s}", - "error", "commitment violation", - "offset", (int) off, - "index", (int) j, - "object", missmatch_object); + MHD_HTTP_BAD_REQUEST, + "{s:s, s:i, s:i, s:s}", + "error", "commitment violation", + "offset", (int) off, + "index", (int) j, + "object", missmatch_object); } diff --git a/src/mint/taler-mint-httpd_responses.h b/src/mint/taler-mint-httpd_responses.h index 616ce6ae7..cedb90d36 100644 --- a/src/mint/taler-mint-httpd_responses.h +++ b/src/mint/taler-mint-httpd_responses.h @@ -65,6 +65,18 @@ TMH_RESPONSE_reply_json_pack (struct MHD_Connection *connection, /** + * Send a response indicating an invalid signature. + * + * @param connection the MHD connection to use + * @param param_name the parameter that is invalid + * @return a MHD result code + */ +int +TMH_RESPONSE_reply_signature_invalid (struct MHD_Connection *connection, + const char *param_name); + + +/** * Send a response indicating an invalid argument. * * @param connection the MHD connection to use @@ -77,15 +89,17 @@ TMH_RESPONSE_reply_arg_invalid (struct MHD_Connection *connection, /** - * Send a response indicating an invalid coin. (I.e. the signature - * over the public key of the coin does not match a valid signing key - * of this mint). + * Send a response indicating an argument refering to a + * resource unknown to the mint (i.e. unknown reserve or + * denomination key). * * @param connection the MHD connection to use - * @return MHD result code + * @param param_name the parameter that is invalid + * @return a MHD result code */ int -TMH_RESPONSE_reply_coin_invalid (struct MHD_Connection *connection); +TMH_RESPONSE_reply_arg_unknown (struct MHD_Connection *connection, + const char *param_name); /** diff --git a/src/mint/taler-mint-httpd_withdraw.c b/src/mint/taler-mint-httpd_withdraw.c index 98228217e..cd79532b2 100644 --- a/src/mint/taler-mint-httpd_withdraw.c +++ b/src/mint/taler-mint-httpd_withdraw.c @@ -61,7 +61,7 @@ TMH_WITHDRAW_handler_withdraw_status (struct TMH_RequestHandler *rh, if (GNUNET_NO == res) return MHD_YES; /* parse error */ return TMH_DB_execute_withdraw_status (connection, - &reserve_pub); + &reserve_pub); } @@ -132,7 +132,7 @@ TMH_WITHDRAW_handler_withdraw_sign (struct TMH_RequestHandler *rh, if (NULL == dki) { TMH_PARSE_release_data (spec); - return TMH_RESPONSE_reply_arg_invalid (connection, + return TMH_RESPONSE_reply_arg_unknown (connection, "denom_pub"); } TALER_amount_ntoh (&amount, @@ -165,8 +165,8 @@ TMH_WITHDRAW_handler_withdraw_sign (struct TMH_RequestHandler *rh, { TALER_LOG_WARNING ("Client supplied invalid signature for /withdraw/sign request\n"); TMH_PARSE_release_data (spec); - return TMH_RESPONSE_reply_arg_invalid (connection, - "reserve_sig"); + return TMH_RESPONSE_reply_signature_invalid (connection, + "reserve_sig"); } res = TMH_DB_execute_withdraw_sign (connection, &wsrd.reserve_pub, diff --git a/src/util/json.c b/src/util/json.c index c462597a1..74236ed1b 100644 --- a/src/util/json.c +++ b/src/util/json.c @@ -84,7 +84,8 @@ TALER_json_from_abs (struct GNUNET_TIME_Absolute stamp) json_t *j; char *mystr; int ret; - ret = GNUNET_asprintf (&mystr, "%llu", + ret = GNUNET_asprintf (&mystr, + "%llu", (long long) (stamp.abs_value_us / (1000 * 1000))); GNUNET_assert (ret > 0); j = json_string (mystr); @@ -117,11 +118,11 @@ TALER_json_from_eddsa_sig (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpo el = TALER_json_from_data (purpose, ntohl (purpose->size)); - json_object_set_new (root, "eddsa-val", el); + json_object_set_new (root, "eddsa_val", el); el = TALER_json_from_data (signature, sizeof (struct GNUNET_CRYPTO_EddsaSignature)); - json_object_set_new (root, "eddsa-sig", el); + json_object_set_new (root, "eddsa_sig", el); return root; } @@ -151,11 +152,11 @@ TALER_json_from_ecdsa_sig (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpo el = TALER_json_from_data (purpose, ntohl (purpose->size)); - json_object_set_new (root, "ecdsa-val", el); + json_object_set_new (root, "ecdsa_val", el); el = TALER_json_from_data (signature, sizeof (struct GNUNET_CRYPTO_EddsaSignature)); - json_object_set_new (root, "ecdsa-sig", el); + json_object_set_new (root, "ecdsa_sig", el); return root; } |