indentation and minor updates to reflect latest API docs
This commit is contained in:
parent
42147c2501
commit
80b29ed2ae
@ -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
|
||||
|
@ -236,8 +236,9 @@ TMH_DB_execute_withdraw_status (struct MHD_Connection *connection,
|
||||
if (NULL == rh)
|
||||
return TMH_RESPONSE_reply_json_pack (connection,
|
||||
MHD_HTTP_NOT_FOUND,
|
||||
"{s:s}",
|
||||
"error", "Reserve not found");
|
||||
"{s:s, s:s}",
|
||||
"error", "Reserve not found",
|
||||
"parameter", "withdraw_pub");
|
||||
res = TMH_RESPONSE_reply_withdraw_status_success (connection,
|
||||
rh);
|
||||
TMH_plugin->free_reserve_history (TMH_plugin->cls,
|
||||
@ -346,11 +347,8 @@ TMH_DB_execute_withdraw_sign (struct MHD_Connection *connection,
|
||||
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 */
|
||||
|
@ -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,8 +80,8 @@ 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 ();
|
||||
@ -91,7 +91,7 @@ verify_and_execute_deposit (struct MHD_Connection *connection,
|
||||
{
|
||||
TMH_KS_release (key_state);
|
||||
TALER_LOG_WARNING ("Unknown denomination key in /deposit request\n");
|
||||
return TMH_RESPONSE_reply_arg_invalid (connection,
|
||||
return TMH_RESPONSE_reply_arg_unknown (connection,
|
||||
"denom_pub");
|
||||
}
|
||||
/* check coin signature */
|
||||
@ -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);
|
||||
@ -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,
|
||||
|
@ -417,7 +417,7 @@ TMH_KS_acquire (void)
|
||||
"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,7 +436,7 @@ TMH_KS_acquire (void)
|
||||
&sig);
|
||||
keys = json_pack ("{s:o, s:o}",
|
||||
"keys", keys,
|
||||
"eddsa-signature", TALER_json_from_eddsa_sig (&ks.purpose,
|
||||
"eddsa_sig", TALER_json_from_eddsa_sig (&ks.purpose,
|
||||
&sig.eddsa_signature));
|
||||
key_state->keys_json = json_dumps (keys,
|
||||
JSON_INDENT (2));
|
||||
|
@ -408,12 +408,9 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection,
|
||||
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))
|
||||
"error", "missing field in JSON",
|
||||
"field", fname,
|
||||
"path", path))
|
||||
? GNUNET_NO : GNUNET_SYSERR;
|
||||
break;
|
||||
}
|
||||
@ -434,8 +431,7 @@ TMH_PARSE_navigate_json (struct MHD_Connection *connection,
|
||||
TMH_RESPONSE_reply_json_pack (connection,
|
||||
MHD_HTTP_BAD_REQUEST,
|
||||
"{s:s, s:o}",
|
||||
"error",
|
||||
"missing index in JSON",
|
||||
"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;
|
||||
}
|
||||
@ -473,10 +467,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;
|
||||
}
|
||||
@ -519,8 +511,7 @@ 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",
|
||||
"error", "malformed binary data in JSON",
|
||||
"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;
|
||||
}
|
||||
|
@ -113,22 +113,42 @@ 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)
|
||||
{
|
||||
/* 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");
|
||||
"{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);
|
||||
}
|
||||
|
||||
|
||||
@ -163,7 +183,7 @@ TMH_RESPONSE_reply_internal_error (struct MHD_Connection *connection,
|
||||
const char *hint)
|
||||
{
|
||||
return TMH_RESPONSE_reply_json_pack (connection,
|
||||
MHD_HTTP_BAD_REQUEST,
|
||||
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||
"{s:s, s:s}",
|
||||
"error", "internal error",
|
||||
"hint", hint);
|
||||
@ -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);
|
||||
|
@ -64,6 +64,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.
|
||||
*
|
||||
@ -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);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -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,7 +165,7 @@ 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,
|
||||
return TMH_RESPONSE_reply_signature_invalid (connection,
|
||||
"reserve_sig");
|
||||
}
|
||||
res = TMH_DB_execute_withdraw_sign (connection,
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user