summaryrefslogtreecommitdiff
path: root/src/util/json.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/json.c')
-rw-r--r--src/util/json.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/src/util/json.c b/src/util/json.c
index 1c7cb7520..42f146463 100644
--- a/src/util/json.c
+++ b/src/util/json.c
@@ -89,11 +89,13 @@ TALER_json_from_abs (struct GNUNET_TIME_Absolute stamp)
char *mystr;
int ret;
+ GNUNET_assert (GNUNET_OK ==
+ TALER_round_abs_time (&stamp));
if (stamp.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
return json_string ("/never/");
ret = GNUNET_asprintf (&mystr,
- "/%llu/",
- (long long) (stamp.abs_value_us / (1000LL * 1000LL)));
+ "/Date(%llu)/",
+ (unsigned long long) (stamp.abs_value_us / (1000LL * 1000LL)));
GNUNET_assert (ret > 0);
j = json_string (mystr);
GNUNET_free (mystr);
@@ -320,7 +322,7 @@ TALER_json_to_amount (json_t *json,
/**
- * Parse given JSON object to Amount
+ * Parse given JSON object to absolute time.
*
* @param json the json object representing Amount
* @param[out] abs where the amount has to be written
@@ -331,9 +333,7 @@ TALER_json_to_abs (json_t *json,
struct GNUNET_TIME_Absolute *abs)
{
const char *val;
- size_t slen;
unsigned long long int tval;
- char *endp;
val = json_string_value (json);
if (NULL == val)
@@ -341,14 +341,6 @@ TALER_json_to_abs (json_t *json,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- slen = strlen (val);
- if ( (slen <= 2) ||
- ('/' != val[0]) ||
- ('/' != val[slen - 1]) )
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
if ( (0 == strcasecmp (val,
"/forever/")) ||
(0 == strcasecmp (val,
@@ -357,10 +349,9 @@ TALER_json_to_abs (json_t *json,
*abs = GNUNET_TIME_UNIT_FOREVER_ABS;
return GNUNET_OK;
}
- tval = strtoull (&val[1],
- &endp,
- 10);
- if (&val[slen - 1] != endp)
+ if (1 != sscanf (val,
+ "/Date(%llu)/",
+ &tval))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;