finshing json parsing support for /refresh/melt handling
This commit is contained in:
parent
6ea5858d32
commit
189adf52eb
@ -253,6 +253,37 @@ parse_json (json_t *root,
|
||||
}
|
||||
break;
|
||||
|
||||
case MAJ_CMD_UINT16:
|
||||
{
|
||||
json_int_t val;
|
||||
|
||||
if (! json_is_integer (pos))
|
||||
{
|
||||
GNUNET_break_op (0);
|
||||
return i;
|
||||
}
|
||||
val = json_integer_value (pos);
|
||||
if ( (0 > val) || (val > UINT16_MAX) )
|
||||
{
|
||||
GNUNET_break_op (0);
|
||||
return i;
|
||||
}
|
||||
*spec[i].details.u16 = (uint16_t) val;
|
||||
}
|
||||
break;
|
||||
|
||||
case MAJ_CMD_JSON_OBJECT:
|
||||
{
|
||||
if (! (json_is_object (pos) || json_is_array (pos)) )
|
||||
{
|
||||
GNUNET_break_op (0);
|
||||
return i;
|
||||
}
|
||||
json_incref (pos);
|
||||
*spec[i].details.obj = pos;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
GNUNET_break (0);
|
||||
return i;
|
||||
@ -307,6 +338,10 @@ parse_free (struct MAJ_Specification *spec,
|
||||
GNUNET_free (*spec[i].details.eddsa_signature.purpose_p);
|
||||
*spec[i].details.eddsa_signature.purpose_p = NULL;
|
||||
break;
|
||||
case MAJ_CMD_JSON_OBJECT:
|
||||
json_decref (*spec[i].details.obj);
|
||||
*spec[i].details.obj = NULL;
|
||||
break;
|
||||
default:
|
||||
GNUNET_break (0);
|
||||
break;
|
||||
@ -417,6 +452,46 @@ MAJ_spec_amount (const char *name,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 16-bit integer.
|
||||
*
|
||||
* @param name name of the JSON field
|
||||
* @param[out] u16 where to store the integer found under @a name
|
||||
*/
|
||||
struct MAJ_Specification
|
||||
MAJ_spec_uint16 (const char *name,
|
||||
uint16_t *u16)
|
||||
{
|
||||
struct MAJ_Specification ret =
|
||||
{
|
||||
.cmd = MAJ_CMD_UINT16,
|
||||
.field = name,
|
||||
.details.u16 = u16
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* JSON object.
|
||||
*
|
||||
* @param name name of the JSON field
|
||||
* @param[out] jsonp where to store the JSON found under @a name
|
||||
*/
|
||||
struct MAJ_Specification
|
||||
MAJ_spec_json (const char *name,
|
||||
json_t **jsonp)
|
||||
{
|
||||
struct MAJ_Specification ret =
|
||||
{
|
||||
.cmd = MAJ_CMD_JSON_OBJECT,
|
||||
.field = name,
|
||||
.details.obj = jsonp
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Specification for parsing an RSA public key.
|
||||
*
|
||||
|
@ -79,7 +79,17 @@ enum MAJ_Command
|
||||
MAJ_CMD_STRING,
|
||||
|
||||
/**
|
||||
* Parse at current position.
|
||||
* Parse `uint16_t` integer at the current position.
|
||||
*/
|
||||
MAJ_CMD_UINT16,
|
||||
|
||||
/**
|
||||
* Parse JSON object at the current position.
|
||||
*/
|
||||
MAJ_CMD_JSON_OBJECT,
|
||||
|
||||
/**
|
||||
* Parse ??? at current position.
|
||||
*/
|
||||
MAJ_CMD_C
|
||||
|
||||
@ -181,6 +191,16 @@ struct MAJ_Specification
|
||||
*/
|
||||
const char **strptr;
|
||||
|
||||
/**
|
||||
* Where to store 16-bit integer.
|
||||
*/
|
||||
uint16_t *u16;
|
||||
|
||||
/**
|
||||
* Where to store a JSON object.
|
||||
*/
|
||||
json_t **obj;
|
||||
|
||||
} details;
|
||||
|
||||
};
|
||||
@ -249,13 +269,35 @@ MAJ_spec_string (const char *name,
|
||||
* Absolute time.
|
||||
*
|
||||
* @param name name of the JSON field
|
||||
* @param at where to store the absolute time found under @a name
|
||||
* @param[out] at where to store the absolute time found under @a name
|
||||
*/
|
||||
struct MAJ_Specification
|
||||
MAJ_spec_absolute_time (const char *name,
|
||||
struct GNUNET_TIME_Absolute *at);
|
||||
|
||||
|
||||
/**
|
||||
* 16-bit integer.
|
||||
*
|
||||
* @param name name of the JSON field
|
||||
* @param[out] u16 where to store the integer found under @a name
|
||||
*/
|
||||
struct MAJ_Specification
|
||||
MAJ_spec_uint16 (const char *name,
|
||||
uint16_t *u16);
|
||||
|
||||
|
||||
/**
|
||||
* JSON object.
|
||||
*
|
||||
* @param name name of the JSON field
|
||||
* @param[out] jsonp where to store the JSON found under @a name
|
||||
*/
|
||||
struct MAJ_Specification
|
||||
MAJ_spec_json (const char *name,
|
||||
json_t **jsonp);
|
||||
|
||||
|
||||
/**
|
||||
* Specification for parsing an amount value.
|
||||
*
|
||||
|
@ -1063,7 +1063,7 @@ verify_refresh_melt_signature_ok (struct TALER_MINT_RefreshMeltHandle *rmh,
|
||||
struct MAJ_Specification spec[] = {
|
||||
MAJ_spec_fixed_auto ("mint_sig", &mint_sig),
|
||||
MAJ_spec_fixed_auto ("mint_pub", &mint_sig),
|
||||
// MAJ_spec_uint16 ("noreveal_index", noreveal_index), // FIXME!
|
||||
MAJ_spec_uint16 ("noreveal_index", noreveal_index),
|
||||
MAJ_spec_end
|
||||
};
|
||||
struct TALER_RefreshMeltConfirmationPS confirm;
|
||||
@ -1124,7 +1124,7 @@ verify_refresh_melt_signature_forbidden (struct TALER_MINT_RefreshMeltHandle *rm
|
||||
struct TALER_CoinSpendPublicKeyP coin_pub;
|
||||
unsigned int i;
|
||||
struct MAJ_Specification spec[] = {
|
||||
// MAJ_spec_json ("history", &history), // FIXME!
|
||||
MAJ_spec_json ("history", &history),
|
||||
MAJ_spec_fixed_auto ("coin_pub", &coin_pub),
|
||||
MAJ_spec_amount ("original_value", &original_value),
|
||||
MAJ_spec_amount ("requested_value", &melt_value_with_fee),
|
||||
@ -1165,6 +1165,7 @@ verify_refresh_melt_signature_forbidden (struct TALER_MINT_RefreshMeltHandle *rm
|
||||
{
|
||||
/* coin not found in our original request */
|
||||
GNUNET_break_op (0);
|
||||
json_decref (history);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
|
||||
@ -1174,6 +1175,7 @@ verify_refresh_melt_signature_forbidden (struct TALER_MINT_RefreshMeltHandle *rm
|
||||
{
|
||||
/* We disagree on the value of the coin */
|
||||
GNUNET_break_op (0);
|
||||
json_decref (history);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (0 != TALER_amount_cmp (&melt_value_with_fee,
|
||||
@ -1181,6 +1183,7 @@ verify_refresh_melt_signature_forbidden (struct TALER_MINT_RefreshMeltHandle *rm
|
||||
{
|
||||
/* We disagree on the value of the coin */
|
||||
GNUNET_break_op (0);
|
||||
json_decref (history);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
|
||||
@ -1194,8 +1197,10 @@ verify_refresh_melt_signature_forbidden (struct TALER_MINT_RefreshMeltHandle *rm
|
||||
&total))
|
||||
{
|
||||
GNUNET_break_op (0);
|
||||
json_decref (history);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
json_decref (history);
|
||||
|
||||
/* check if melt operation was really too expensive given history */
|
||||
if (GNUNET_OK !=
|
||||
|
Loading…
Reference in New Issue
Block a user