fixing RC counting and a comma

This commit is contained in:
Christian Grothoff 2015-07-05 13:05:58 +02:00
parent ff6d4c081c
commit 9084ac4821
9 changed files with 138 additions and 94 deletions

View File

@ -36,7 +36,7 @@
*/ */
#define JSON_WARN(error) \ #define JSON_WARN(error) \
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \
"JSON parsing failed at %s:%u: %s (%s)", \ "JSON parsing failed at %s:%u: %s (%s)\n", \
__FILE__, __LINE__, error.text, error.source) __FILE__, __LINE__, error.text, error.source)
@ -800,7 +800,20 @@ handle_withdraw_sign_finished (void *cls,
wsh->job = NULL; wsh->job = NULL;
json = NULL; json = NULL;
if (0 == wsh->eno) if (CURLE_OK !=
curl_easy_getinfo (eh,
CURLINFO_RESPONSE_CODE,
&response_code))
{
/* unexpected error... */
GNUNET_break (0);
response_code = 0;
}
fprintf (stderr,
"Response code: %u\n",
(unsigned int) response_code);
if ( (0 == wsh->eno) &&
(0 != response_code) )
{ {
json = json_loadb (wsh->buf, json = json_loadb (wsh->buf,
wsh->buf_size, wsh->buf_size,
@ -812,18 +825,6 @@ handle_withdraw_sign_finished (void *cls,
response_code = 0; response_code = 0;
} }
} }
if (NULL != json)
{
if (CURLE_OK !=
curl_easy_getinfo (eh,
CURLINFO_RESPONSE_CODE,
&response_code))
{
/* unexpected error... */
GNUNET_break (0);
response_code = 0;
}
}
switch (response_code) switch (response_code)
{ {
case 0: case 0:
@ -1032,6 +1033,10 @@ TALER_MINT_withdraw_sign (struct TALER_MINT_Handle *mint,
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_URL, CURLOPT_URL,
wsh->url)); wsh->url));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_VERBOSE,
1LL));
GNUNET_assert (CURLE_OK == GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh, curl_easy_setopt (eh,
CURLOPT_POSTFIELDS, CURLOPT_POSTFIELDS,

View File

@ -358,6 +358,7 @@ add_incoming_cb (void *cls,
cmd->details.admin_add_incoming.aih = NULL; cmd->details.admin_add_incoming.aih = NULL;
if (MHD_HTTP_OK != http_status) if (MHD_HTTP_OK != http_status)
{ {
GNUNET_break (0);
fail (is); fail (is);
return; return;
} }
@ -385,12 +386,10 @@ withdraw_sign_cb (void *cls,
struct InterpreterState *is = cls; struct InterpreterState *is = cls;
struct Command *cmd = &is->commands[is->ip]; struct Command *cmd = &is->commands[is->ip];
fprintf (stderr,
"Withdraw completed: %u\n",
http_status);
cmd->details.withdraw_sign.wsh = NULL; cmd->details.withdraw_sign.wsh = NULL;
if (NULL == sig) if (NULL == sig)
{ {
GNUNET_break (0);
fail (is); fail (is);
return; return;
} }

View File

@ -411,11 +411,23 @@ TMH_DB_execute_withdraw_sign (struct MHD_Connection *connection,
break; break;
} }
} }
if (0 == (res & 1))
{
/* did not encounter any deposit operations, how can we have a reserve? */
GNUNET_break (0);
return TMH_RESPONSE_reply_internal_db_error (connection);
}
if (0 == (res & 2))
{
/* did not encounter any withdraw operations, set to zero */
TALER_amount_get_zero (deposit_total.currency,
&withdraw_total);
}
/* All reserve balances should be non-negative */ /* All reserve balances should be non-negative */
GNUNET_break (GNUNET_SYSERR != GNUNET_assert (GNUNET_SYSERR !=
TALER_amount_subtract (&balance, TALER_amount_subtract (&balance,
&deposit_total, &deposit_total,
&withdraw_total)); &withdraw_total));
if (0 < TALER_amount_cmp (&amount_required, if (0 < TALER_amount_cmp (&amount_required,
&balance)) &balance))
{ {

View File

@ -139,8 +139,8 @@ parse_and_handle_deposit_request (struct MHD_Connection *connection,
struct TALER_MINTDB_DenominationKeyIssueInformation *dki; struct TALER_MINTDB_DenominationKeyIssueInformation *dki;
struct TMH_KS_StateHandle *ks; struct TMH_KS_StateHandle *ks;
struct TMH_PARSE_FieldSpecification spec[] = { struct TMH_PARSE_FieldSpecification spec[] = {
TMH_PARSE_MEMBER_DENOMINATION_PUBLIC_KEY ("denom_pub", &deposit.coin.denom_pub), TMH_PARSE_member_denomination_public_key ("denom_pub", &deposit.coin.denom_pub),
TMH_PARSE_MEMBER_DENOMINATION_SIGNATURE ("ub_sig", &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 ("coin_pub", &deposit.coin.coin_pub),
TMH_PARSE_MEMBER_FIXED ("merchant_pub", &deposit.merchant_pub), TMH_PARSE_MEMBER_FIXED ("merchant_pub", &deposit.merchant_pub),
TMH_PARSE_MEMBER_FIXED ("H_contract", &deposit.h_contract), TMH_PARSE_MEMBER_FIXED ("H_contract", &deposit.h_contract),

View File

@ -768,24 +768,20 @@ TMH_PARSE_json_data (struct MHD_Connection *connection,
*((void**)spec[i].destination) = ptr; *((void**)spec[i].destination) = ptr;
break; break;
case TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY: case TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY:
ptr = NULL;
ret = TMH_PARSE_navigate_json (connection, ret = TMH_PARSE_navigate_json (connection,
root, root,
TMH_PARSE_JNC_FIELD, TMH_PARSE_JNC_FIELD,
spec[i].field_name, spec[i].field_name,
TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY, TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY,
&ptr); spec[i].destination);
spec[i].destination = ptr;
break; break;
case TMH_PARSE_JNC_RET_RSA_SIGNATURE: case TMH_PARSE_JNC_RET_RSA_SIGNATURE:
ptr = NULL;
ret = TMH_PARSE_navigate_json (connection, ret = TMH_PARSE_navigate_json (connection,
root, root,
TMH_PARSE_JNC_FIELD, TMH_PARSE_JNC_FIELD,
spec[i].field_name, spec[i].field_name,
TMH_PARSE_JNC_RET_RSA_SIGNATURE, TMH_PARSE_JNC_RET_RSA_SIGNATURE,
&ptr); spec[i].destination);
spec[i].destination = ptr;
break; break;
case TMH_PARSE_JNC_RET_AMOUNT: case TMH_PARSE_JNC_RET_AMOUNT:
GNUNET_assert (sizeof (struct TALER_Amount) == GNUNET_assert (sizeof (struct TALER_Amount) ==
@ -857,25 +853,25 @@ TMH_PARSE_release_data (struct TMH_PARSE_FieldSpecification *spec)
break; break;
case TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY: case TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY:
{ {
struct TALER_DenominationPublicKey pk; struct TALER_DenominationPublicKey *pk;
pk = *(struct TALER_DenominationPublicKey *) spec[i].destination; pk = spec[i].destination;
if (NULL != pk.rsa_public_key) if (NULL != pk->rsa_public_key)
{ {
GNUNET_CRYPTO_rsa_public_key_free (pk.rsa_public_key); GNUNET_CRYPTO_rsa_public_key_free (pk->rsa_public_key);
pk.rsa_public_key = NULL; pk->rsa_public_key = NULL;
} }
} }
break; break;
case TMH_PARSE_JNC_RET_RSA_SIGNATURE: case TMH_PARSE_JNC_RET_RSA_SIGNATURE:
{ {
struct TALER_DenominationSignature sig; struct TALER_DenominationSignature *sig;
sig = *(struct TALER_DenominationSignature *) spec[i].destination; sig = spec[i].destination;
if (NULL != sig.rsa_signature) if (NULL != sig->rsa_signature)
{ {
GNUNET_CRYPTO_rsa_signature_free (sig.rsa_signature); GNUNET_CRYPTO_rsa_signature_free (sig->rsa_signature);
sig.rsa_signature = NULL; sig->rsa_signature = NULL;
} }
} }
break; break;
@ -1084,6 +1080,40 @@ TMH_PARSE_member_time_abs (const char *field,
} }
/**
* Generate line in parser specification for RSA public key.
*
* @param field name of the field
* @param[out] pk key to initialize
* @return corresponding field spec
*/
struct TMH_PARSE_FieldSpecification
TMH_PARSE_member_denomination_public_key (const char *field,
struct TALER_DenominationPublicKey *pk)
{
struct TMH_PARSE_FieldSpecification ret =
{ field, pk, 0, 0, TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY, 0 };
return ret;
}
/**
* Generate line in parser specification for RSA public key.
*
* @param field name of the field
* @param sig the signature to initialize
* @return corresponding field spec
*/
struct TMH_PARSE_FieldSpecification
TMH_PARSE_member_denomination_signature (const char *field,
struct TALER_DenominationSignature *sig)
{
struct TMH_PARSE_FieldSpecification ret =
{ field, sig, 0, 0, TMH_PARSE_JNC_RET_RSA_SIGNATURE, 0 };
return ret;
}
/** /**
* Generate line in parser specification for an amount. * Generate line in parser specification for an amount.
* *

View File

@ -277,17 +277,24 @@ TMH_PARSE_member_object (const char *field,
* Generate line in parser specification for RSA public key. * Generate line in parser specification for RSA public key.
* *
* @param field name of the field * @param field name of the field
* @param ptrpk address of `struct TALER_DenominationPublicKey` initialize * @param[out] pk key to initialize
* @return corresponding field spec
*/ */
#define TMH_PARSE_MEMBER_DENOMINATION_PUBLIC_KEY(field,ptrpk) { field, ptrpk, 0, 0, TMH_PARSE_JNC_RET_RSA_PUBLIC_KEY, 0 } struct TMH_PARSE_FieldSpecification
TMH_PARSE_member_denomination_public_key (const char *field,
struct TALER_DenominationPublicKey *pk);
/** /**
* Generate line in parser specification for RSA public key. * Generate line in parser specification for RSA public key.
* *
* @param field name of the field * @param field name of the field
* @param ptrsig address of `struct TALER_DenominationSignature *` initialize * @param sig the signature to initialize
* @return corresponding field spec
*/ */
#define TMH_PARSE_MEMBER_DENOMINATION_SIGNATURE(field,ptrsig) { field, ptrsig, 0, 0, TMH_PARSE_JNC_RET_RSA_SIGNATURE, 0 } struct TMH_PARSE_FieldSpecification
TMH_PARSE_member_denomination_signature (const char *field,
struct TALER_DenominationSignature *sig);
/** /**

View File

@ -174,8 +174,8 @@ get_coin_public_info (struct MHD_Connection *connection,
struct TALER_Amount amount; struct TALER_Amount amount;
struct TMH_PARSE_FieldSpecification spec[] = { struct TMH_PARSE_FieldSpecification spec[] = {
TMH_PARSE_MEMBER_FIXED ("coin_pub", &r_melt_detail->coin_info.coin_pub), TMH_PARSE_MEMBER_FIXED ("coin_pub", &r_melt_detail->coin_info.coin_pub),
TMH_PARSE_MEMBER_DENOMINATION_SIGNATURE ("denom_sig", &sig.rsa_signature), TMH_PARSE_member_denomination_signature ("denom_sig", &sig),
TMH_PARSE_MEMBER_DENOMINATION_PUBLIC_KEY ("denom_pub", &pk.rsa_public_key), TMH_PARSE_member_denomination_public_key ("denom_pub", &pk),
TMH_PARSE_MEMBER_FIXED ("confirm_sig", &melt_sig), TMH_PARSE_MEMBER_FIXED ("confirm_sig", &melt_sig),
TMH_PARSE_member_amount ("value_with_fee", &amount), TMH_PARSE_member_amount ("value_with_fee", &amount),
TMH_PARSE_MEMBER_END TMH_PARSE_MEMBER_END

View File

@ -47,10 +47,12 @@ TMH_RESPONSE_reply_json (struct MHD_Connection *connection,
int ret; int ret;
json_str = json_dumps (json, JSON_INDENT(2)); json_str = json_dumps (json, JSON_INDENT(2));
GNUNET_assert (NULL != json_str);
resp = MHD_create_response_from_buffer (strlen (json_str), json_str, resp = MHD_create_response_from_buffer (strlen (json_str), json_str,
MHD_RESPMEM_MUST_FREE); MHD_RESPMEM_MUST_FREE);
if (NULL == resp) if (NULL == resp)
{ {
free (json_str);
GNUNET_break (0); GNUNET_break (0);
return MHD_NO; return MHD_NO;
} }
@ -84,12 +86,17 @@ TMH_RESPONSE_reply_json_pack (struct MHD_Connection *connection,
json_t *json; json_t *json;
va_list argp; va_list argp;
int ret; int ret;
json_error_t jerror;
va_start (argp, fmt); va_start (argp, fmt);
json = json_vpack_ex (NULL, 0, fmt, argp); json = json_vpack_ex (&jerror, 0, fmt, argp);
va_end (argp); va_end (argp);
if (NULL == json) if (NULL == json)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to pack JSON with format `%s': %s\n",
fmt,
jerror.text);
GNUNET_break (0); GNUNET_break (0);
return MHD_NO; return MHD_NO;
} }
@ -229,10 +236,10 @@ TMH_RESPONSE_reply_external_error (struct MHD_Connection *connection,
const char *hint) const char *hint)
{ {
return TMH_RESPONSE_reply_json_pack (connection, return TMH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_BAD_REQUEST, MHD_HTTP_BAD_REQUEST,
"{s:s, s:s}", "{s:s, s:s}",
"error", "client error", "error", "client error",
"hint", hint); "hint", hint);
} }
@ -247,9 +254,9 @@ int
TMH_RESPONSE_reply_commit_error (struct MHD_Connection *connection) TMH_RESPONSE_reply_commit_error (struct MHD_Connection *connection)
{ {
return TMH_RESPONSE_reply_json_pack (connection, return TMH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_BAD_REQUEST, MHD_HTTP_BAD_REQUEST,
"{s:s}", "{s:s}",
"error", "commit failure"); "error", "commit failure");
} }
@ -571,16 +578,14 @@ compile_reserve_history (const struct TALER_MINTDB_ReserveHistory *rh,
"type", "WITHDRAW", "type", "WITHDRAW",
"signature", transaction, "signature", transaction,
"amount", TALER_json_from_amount (&value))); "amount", TALER_json_from_amount (&value)));
break; break;
} }
} }
if (0 == ret) if (0 == ret)
{ {
/* history is empty!? */ /* did not encounter any withdraw operations, set to zero */
GNUNET_break (0); TALER_amount_get_zero (deposit_total.currency,
json_decref (json_history); &withdraw_total);
return NULL;
} }
if (GNUNET_SYSERR == if (GNUNET_SYSERR ==
TALER_amount_subtract (balance, TALER_amount_subtract (balance,
@ -591,6 +596,7 @@ compile_reserve_history (const struct TALER_MINTDB_ReserveHistory *rh,
json_decref (json_history); json_decref (json_history);
return NULL; return NULL;
} }
return json_history; return json_history;
} }
@ -609,7 +615,6 @@ TMH_RESPONSE_reply_withdraw_status_success (struct MHD_Connection *connection,
json_t *json_balance; json_t *json_balance;
json_t *json_history; json_t *json_history;
struct TALER_Amount balance; struct TALER_Amount balance;
int ret;
json_history = compile_reserve_history (rh, json_history = compile_reserve_history (rh,
&balance); &balance);
@ -617,14 +622,11 @@ TMH_RESPONSE_reply_withdraw_status_success (struct MHD_Connection *connection,
return TMH_RESPONSE_reply_internal_error (connection, return TMH_RESPONSE_reply_internal_error (connection,
"balance calculation failure"); "balance calculation failure");
json_balance = TALER_json_from_amount (&balance); json_balance = TALER_json_from_amount (&balance);
ret = TMH_RESPONSE_reply_json_pack (connection, return TMH_RESPONSE_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);
json_decref (json_history);
json_decref (json_balance);
return ret;
} }
@ -644,7 +646,6 @@ TMH_RESPONSE_reply_withdraw_sign_insufficient_funds (struct MHD_Connection *conn
json_t *json_balance; json_t *json_balance;
json_t *json_history; json_t *json_history;
struct TALER_Amount balance; struct TALER_Amount balance;
int ret;
json_history = compile_reserve_history (rh, json_history = compile_reserve_history (rh,
&balance); &balance);
@ -652,15 +653,12 @@ TMH_RESPONSE_reply_withdraw_sign_insufficient_funds (struct MHD_Connection *conn
return TMH_RESPONSE_reply_internal_error (connection, return TMH_RESPONSE_reply_internal_error (connection,
"balance calculation failure"); "balance calculation failure");
json_balance = TALER_json_from_amount (&balance); json_balance = TALER_json_from_amount (&balance);
ret = TMH_RESPONSE_reply_json_pack (connection, return TMH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_FORBIDDEN, MHD_HTTP_FORBIDDEN,
"{s:s, s:o, s:o}", "{s:s, s:o, s:o}",
"error", "Insufficient funds" "error", "Insufficient funds",
"balance", json_balance, "balance", json_balance,
"history", json_history); "history", json_history);
json_decref (json_history);
json_decref (json_balance);
return ret;
} }
@ -676,15 +674,12 @@ 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; json_t *sig_json;
int ret;
sig_json = TALER_json_from_rsa_signature (collectable->sig.rsa_signature); sig_json = TALER_json_from_rsa_signature (collectable->sig.rsa_signature);
ret = TMH_RESPONSE_reply_json_pack (connection, return TMH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_OK, MHD_HTTP_OK,
"{s:o}", "{s:o}",
"ev_sig", sig_json); "ev_sig", sig_json);
json_decref (sig_json);
return ret;
} }
@ -743,7 +738,6 @@ TMH_RESPONSE_reply_refresh_melt_success (struct MHD_Connection *connection,
struct TALER_RefreshMeltConfirmationPS body; struct TALER_RefreshMeltConfirmationPS body;
struct TALER_MintSignatureP sig; struct TALER_MintSignatureP sig;
json_t *sig_json; json_t *sig_json;
int ret;
body.purpose.size = htonl (sizeof (struct TALER_RefreshMeltConfirmationPS)); body.purpose.size = htonl (sizeof (struct TALER_RefreshMeltConfirmationPS));
body.purpose.purpose = htonl (TALER_SIGNATURE_MINT_CONFIRM_MELT); body.purpose.purpose = htonl (TALER_SIGNATURE_MINT_CONFIRM_MELT);
@ -754,13 +748,11 @@ TMH_RESPONSE_reply_refresh_melt_success (struct MHD_Connection *connection,
sig_json = TALER_json_from_eddsa_sig (&body.purpose, sig_json = TALER_json_from_eddsa_sig (&body.purpose,
&sig.eddsa_signature); &sig.eddsa_signature);
GNUNET_assert (NULL != sig_json); GNUNET_assert (NULL != sig_json);
ret = TMH_RESPONSE_reply_json_pack (connection, return TMH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_OK, MHD_HTTP_OK,
"{s:i, s:o}", "{s:i, s:o}",
"noreveal_index", (int) noreveal_index, "noreveal_index", (int) noreveal_index,
"signature", sig_json); "signature", sig_json);
json_decref (sig_json);
return ret;
} }
@ -916,7 +908,6 @@ TMH_RESPONSE_reply_refresh_reveal_missmatch (struct MHD_Connection *connection,
json_array_append_new (info_links, json_array_append_new (info_links,
info_link_k); info_link_k);
} }
return TMH_RESPONSE_reply_json_pack (connection, return TMH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_CONFLICT, MHD_HTTP_CONFLICT,
"{s:s, s:i, s:i, s:o, s:o, s:o, s:o, s:s}", "{s:s, s:i, s:i, s:o, s:o, s:o, s:o, s:s}",

View File

@ -105,7 +105,7 @@ TMH_WITHDRAW_handler_withdraw_sign (struct TMH_RequestHandler *rh,
TMH_PARSE_MEMBER_VARIABLE ("coin_ev"), TMH_PARSE_MEMBER_VARIABLE ("coin_ev"),
TMH_PARSE_MEMBER_FIXED ("reserve_pub", &wsrd.reserve_pub), TMH_PARSE_MEMBER_FIXED ("reserve_pub", &wsrd.reserve_pub),
TMH_PARSE_MEMBER_FIXED ("reserve_sig", &signature), TMH_PARSE_MEMBER_FIXED ("reserve_sig", &signature),
TMH_PARSE_MEMBER_DENOMINATION_PUBLIC_KEY ("denom_pub", &denomination_pub), TMH_PARSE_member_denomination_public_key ("denom_pub", &denomination_pub),
TMH_PARSE_MEMBER_END TMH_PARSE_MEMBER_END
}; };