use wire validation routine
This commit is contained in:
parent
968e4aa68f
commit
6404213457
@ -139,11 +139,11 @@ TALER_JSON_to_data (json_t *json,
|
||||
*
|
||||
* @param type the type of the wire format
|
||||
* @param wire the JSON wire format object
|
||||
* @return 1 if correctly formatted; 0 if not
|
||||
* @return #GNUNET_YES if correctly formatted; #GNUNET_NO if not
|
||||
*/
|
||||
int
|
||||
TALER_JSON_validate_wireformat (const char *type,
|
||||
json_t *wire);
|
||||
const json_t *wire);
|
||||
|
||||
|
||||
#endif /* TALER_JSON_LIB_H_ */
|
||||
|
@ -55,6 +55,11 @@ struct GNUNET_CONFIGURATION_Handle *cfg;
|
||||
*/
|
||||
struct GNUNET_CRYPTO_EddsaPublicKey master_pub;
|
||||
|
||||
/**
|
||||
* In which format does this MINT expect wiring instructions?
|
||||
*/
|
||||
char *expected_wire_format = "sepa";
|
||||
|
||||
/**
|
||||
* The HTTP Daemon.
|
||||
*/
|
||||
|
@ -48,6 +48,11 @@ extern struct GNUNET_CONFIGURATION_Handle *cfg;
|
||||
*/
|
||||
extern char *mintdir;
|
||||
|
||||
/**
|
||||
* In which format does this MINT expect wiring instructions?
|
||||
*/
|
||||
extern char *expected_wire_format;
|
||||
|
||||
/**
|
||||
* Master public key (according to the
|
||||
* configuration in the mint directory).
|
||||
|
@ -145,7 +145,14 @@ parse_and_handle_deposit_request (struct MHD_Connection *connection,
|
||||
return MHD_NO; /* hard failure */
|
||||
if (GNUNET_NO == res)
|
||||
return MHD_YES; /* failure */
|
||||
/* FIXME: check that "wire" is formatted correctly */
|
||||
if (GNUNET_YES !=
|
||||
TALER_JSON_validate_wireformat (expected_wire_format,
|
||||
wire))
|
||||
{
|
||||
TALER_MINT_release_parsed_data (spec);
|
||||
return TALER_MINT_reply_arg_invalid (connection,
|
||||
"wire");
|
||||
}
|
||||
if (NULL == (wire_enc = json_dumps (wire, JSON_COMPACT | JSON_SORT_KEYS)))
|
||||
{
|
||||
LOG_WARNING ("Failed to parse JSON wire format specification for /deposit request\n");
|
||||
|
@ -505,13 +505,15 @@ validate_iban (const char *iban)
|
||||
*
|
||||
* @param type the type of the wire format
|
||||
* @param wire the JSON wire format object
|
||||
* @return 1 if correctly formatted; 0 if not
|
||||
* @return #GNUNET_YES if correctly formatted; #GNUNET_NO if not
|
||||
*/
|
||||
int
|
||||
TALER_JSON_validate_wireformat (const char *type, json_t *wire)
|
||||
TALER_JSON_validate_wireformat (const char *type,
|
||||
const json_t *wire)
|
||||
{
|
||||
json_error_t error;
|
||||
if (0 == strcmp ("SEPA", type))
|
||||
|
||||
if (0 == strcasecmp ("SEPA", type))
|
||||
{
|
||||
const char *type;
|
||||
const char *iban;
|
||||
@ -521,7 +523,8 @@ TALER_JSON_validate_wireformat (const char *type, json_t *wire)
|
||||
uint64_t r;
|
||||
const char *address;
|
||||
UNPACK_EXITIF (0 != json_unpack_ex
|
||||
(wire, &error, JSON_STRICT,
|
||||
((json_t *) wire,
|
||||
&error, JSON_STRICT,
|
||||
"{"
|
||||
"s:s " /* type: "SEPA" */
|
||||
"s:s " /* IBAN: iban */
|
||||
@ -540,11 +543,11 @@ TALER_JSON_validate_wireformat (const char *type, json_t *wire)
|
||||
"address", &address));
|
||||
EXITIF (0 != strcmp (type, "SEPA"));
|
||||
EXITIF (1 != validate_iban (iban));
|
||||
return 1;
|
||||
return GNUNET_YES;
|
||||
}
|
||||
|
||||
EXITIF_exit:
|
||||
return 0;
|
||||
return GNUNET_NO;
|
||||
}
|
||||
|
||||
/* End of util/json.c */
|
||||
|
Loading…
Reference in New Issue
Block a user