summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
m---------doc/prebuilt0
-rw-r--r--src/json/json_helper.c107
2 files changed, 9 insertions, 98 deletions
diff --git a/doc/prebuilt b/doc/prebuilt
-Subproject 934a6a18301e81c4fd1b3a8cda2dc13dca4741c
+Subproject ca53235ccfa0458ebf11c204888ca370e20ec3f
diff --git a/src/json/json_helper.c b/src/json/json_helper.c
index 0f67e9d80..536eece90 100644
--- a/src/json/json_helper.c
+++ b/src/json/json_helper.c
@@ -78,65 +78,20 @@ parse_amount (void *cls,
struct GNUNET_JSON_Specification *spec)
{
struct TALER_Amount *r_amount = spec->ptr;
- json_int_t value;
- json_int_t fraction;
- const char *currency;
(void) cls;
- if (json_is_string (root))
- {
- if (GNUNET_OK !=
- TALER_string_to_amount (json_string_value (root), r_amount))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
- }
-
- /* Also allow the legacy { value, fraction, currency} format.
- This might be removed in the future. */
-
- memset (r_amount,
- 0,
- sizeof (struct TALER_Amount));
- if (0 != json_unpack (root,
- "{s:I, s:I, s:s}",
- "value", &value,
- "fraction", &fraction,
- "currency", &currency))
- {
- char *json_enc;
-
- if (NULL == (json_enc = json_dumps (root,
- JSON_COMPACT | JSON_ENCODE_ANY)))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Malformed JSON amount: %s\n",
- json_enc);
- free (json_enc);
- return GNUNET_SYSERR;
- }
- if ( (value < 0) ||
- (fraction < 0) ||
- (((uint64_t) value) > UINT64_MAX) ||
- (fraction > UINT32_MAX) )
+ if (! json_is_string (root))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- if (strlen (currency) >= TALER_CURRENCY_LEN)
+ if (GNUNET_OK !=
+ TALER_string_to_amount (json_string_value (root),
+ r_amount))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- r_amount->value = (uint64_t) value;
- r_amount->fraction = (uint32_t) fraction;
- strcpy (r_amount->currency, currency);
- (void) TALER_amount_normalize (r_amount);
return GNUNET_OK;
}
@@ -178,64 +133,20 @@ parse_amount_nbo (void *cls,
struct GNUNET_JSON_Specification *spec)
{
struct TALER_AmountNBO *r_amount = spec->ptr;
- struct TALER_Amount amount;
- json_int_t value;
- json_int_t fraction;
- const char *currency;
(void) cls;
- if (json_is_string (root))
+ if (! json_is_string (root))
{
- if (GNUNET_OK !=
- TALER_string_to_amount_nbo (json_string_value (root), r_amount))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
- }
-
- memset (&amount,
- 0,
- sizeof (struct TALER_Amount));
- if (0 != json_unpack (root,
- "{s:I, s:I, s:s}",
- "value", &value,
- "fraction", &fraction,
- "currency", &currency))
- {
- char *json_enc;
-
- if (NULL == (json_enc = json_dumps (root,
- JSON_COMPACT | JSON_ENCODE_ANY)))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Malformed JSON amount: %s\n",
- json_enc);
- free (json_enc);
- return GNUNET_SYSERR;
- }
- if ( (value < 0) ||
- (fraction < 0) ||
- (fraction > (json_int_t) UINT32_MAX) )
- {
- GNUNET_break_op (0);
+ GNUNET_break (0);
return GNUNET_SYSERR;
}
- if (strlen (currency) >= TALER_CURRENCY_LEN)
+ if (GNUNET_OK !=
+ TALER_string_to_amount_nbo (json_string_value (root),
+ r_amount))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- amount.value = (uint64_t) value;
- amount.fraction = (uint32_t) fraction;
- strcpy (amount.currency, currency);
- (void) TALER_amount_normalize (&amount);
- TALER_amount_hton (r_amount,
- &amount);
return GNUNET_OK;
}