fix #3636, and add amount parsing functionality to spec-parser

This commit is contained in:
Christian Grothoff 2015-03-22 17:10:45 +01:00
parent 884fff1297
commit 1d7bb2d091
3 changed files with 43 additions and 16 deletions

View File

@ -680,6 +680,16 @@ GNUNET_MINT_parse_navigate_json (struct MHD_Connection *connection,
break;
}
case JNAV_RET_AMOUNT:
{
struct TALER_Amount *where = va_arg (argp, void *);
ret = TALER_MINT_parse_amount_json (connection,
(json_t *) root,
where);
break;
}
default:
GNUNET_break (0);
ret = (MHD_YES ==
@ -721,6 +731,8 @@ TALER_MINT_parse_json_data (struct MHD_Connection *connection,
ret = GNUNET_YES;
for (i=0; NULL != spec[i].field_name; i++)
{
if (GNUNET_YES != ret)
break;
switch (spec[i].command)
{
case JNAV_FIELD:
@ -730,8 +742,6 @@ TALER_MINT_parse_json_data (struct MHD_Connection *connection,
GNUNET_break (0);
return GNUNET_SYSERR;
case JNAV_RET_DATA:
if (GNUNET_YES != ret)
break;
ret = GNUNET_MINT_parse_navigate_json (connection,
root,
JNAV_FIELD,
@ -741,8 +751,6 @@ TALER_MINT_parse_json_data (struct MHD_Connection *connection,
spec[i].destination_size_in);
break;
case JNAV_RET_DATA_VAR:
if (GNUNET_YES != ret)
break;
ptr = NULL;
ret = GNUNET_MINT_parse_navigate_json (connection,
root,
@ -754,8 +762,6 @@ TALER_MINT_parse_json_data (struct MHD_Connection *connection,
spec[i].destination = ptr;
break;
case JNAV_RET_TYPED_JSON:
if (GNUNET_YES != ret)
break;
ptr = NULL;
ret = GNUNET_MINT_parse_navigate_json (connection,
root,
@ -767,8 +773,6 @@ TALER_MINT_parse_json_data (struct MHD_Connection *connection,
*((void**)spec[i].destination) = ptr;
break;
case JNAV_RET_RSA_PUBLIC_KEY:
if (GNUNET_YES != ret)
break;
ptr = NULL;
ret = GNUNET_MINT_parse_navigate_json (connection,
root,
@ -779,8 +783,6 @@ TALER_MINT_parse_json_data (struct MHD_Connection *connection,
spec[i].destination = ptr;
break;
case JNAV_RET_RSA_SIGNATURE:
if (GNUNET_YES != ret)
break;
ptr = NULL;
ret = GNUNET_MINT_parse_navigate_json (connection,
root,
@ -790,6 +792,16 @@ TALER_MINT_parse_json_data (struct MHD_Connection *connection,
&ptr);
spec[i].destination = ptr;
break;
case JNAV_RET_AMOUNT:
GNUNET_assert (sizeof (struct TALER_Amount) ==
spec[i].destination_size_in);
ret = GNUNET_MINT_parse_navigate_json (connection,
root,
JNAV_FIELD,
spec[i].field_name,
JNAV_RET_AMOUNT,
&spec[i].destination);
break;
}
}
if (GNUNET_YES != ret)
@ -854,6 +866,11 @@ TALER_MINT_release_parsed_data (struct GNUNET_MINT_ParseFieldSpec *spec)
*(void**) spec[i].destination = NULL;
}
break;
case JNAV_RET_AMOUNT:
memset (spec[i].destination,
0,
sizeof (struct TALER_Amount));
break;
}
}
}

View File

@ -120,7 +120,13 @@ enum TALER_MINT_JsonNavigationCommand
* Return a `struct GNUNET_CRYPTO_rsa_Signature` which was
* encoded as variable-size base32crockford encoded data.
*/
JNAV_RET_RSA_SIGNATURE
JNAV_RET_RSA_SIGNATURE,
/**
* Return a `struct TALER_Amount` which was
* encoded within its own json object.
*/
JNAV_RET_AMOUNT
};
@ -270,6 +276,14 @@ TALER_MINT_release_parsed_data (struct GNUNET_MINT_ParseFieldSpec *spec);
*/
#define TALER_MINT_PARSE_RSA_SIGNATURE(field,ptrsig) { field, ptrsig, 0, 0, JNAV_RET_RSA_SIGNATURE, 0 }
/**
* Generate line in parser specification for an amount.
*
* @param field name of the field
* @param amount a `struct TALER_Amount *` to initialize
*/
#define TALER_MINT_PARSE_AMOUNT(field,amount) { field, amount, sizeof(*amount), 0, JNAV_RET_AMOUNT, 0 }
/**
* Generate line in parser specification indicating the end of the spec.
*/

View File

@ -237,19 +237,15 @@ get_coin_public_info (struct MHD_Connection *connection,
TALER_MINT_PARSE_RSA_SIGNATURE ("denom_sig", &sig),
TALER_MINT_PARSE_RSA_PUBLIC_KEY ("denom_pub", &pk),
TALER_MINT_PARSE_FIXED ("confirm_sig", &melt_sig),
/* FIXME: #3636! */
TALER_MINT_PARSE_AMOUNT ("value_with_fee", &amount),
TALER_MINT_PARSE_END
};
memset (&amount, 0, sizeof (amount)); // FIXME: #3636!
ret = TALER_MINT_parse_json_data (connection,
coin_info,
spec);
if (GNUNET_OK != ret)
return ret;
/* FIXME: include amount of coin value to be melted here (#3636!) and
in what we return!? */
/* check mint signature on the coin */
r_public_info->denom_sig = sig;
r_public_info->denom_pub = pk;