diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-07-05 16:55:01 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-07-05 16:55:01 +0200 |
commit | 922323b4104abfaef2a11fed4e5e8292344a3bcd (patch) | |
tree | 8ed3781141741e743d120180b7e785f6a38eca3c /src/util/json.c | |
parent | f623214c1292b93fa8672361dfa978a506f4bef3 (diff) |
misc bugfixes from tests
Diffstat (limited to 'src/util/json.c')
-rw-r--r-- | src/util/json.c | 25 |
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; |