[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-merchant] 02/03: fix time parser, why was this ever written
From: |
gnunet |
Subject: |
[taler-merchant] 02/03: fix time parser, why was this ever written |
Date: |
Tue, 24 Dec 2019 23:36:05 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository merchant.
commit 21cad09ca7ff4ba2aa8a80dff805e5e8c182ff41
Author: Christian Grothoff <address@hidden>
AuthorDate: Tue Dec 24 23:33:08 2019 +0100
fix time parser, why was this ever written
---
src/lib/testing_api_cmd_history.c | 65 ++++++---------------------------------
1 file changed, 10 insertions(+), 55 deletions(-)
diff --git a/src/lib/testing_api_cmd_history.c
b/src/lib/testing_api_cmd_history.c
index 5a776fc..2f4702a 100644
--- a/src/lib/testing_api_cmd_history.c
+++ b/src/lib/testing_api_cmd_history.c
@@ -86,56 +86,6 @@ struct HistoryState
unsigned int nresult;
};
-/**
- * Parse given JSON object to absolute time.
- *
- * @param root the json object representing data
- * @param[out] ret where to write the data
- * @return #GNUNET_OK upon successful parsing;
- * #GNUNET_SYSERR upon error
- */
-static int
-parse_abs_time (json_t *root,
- struct GNUNET_TIME_Absolute *ret)
-{
- const char *val;
- unsigned long long int tval;
-
- val = json_string_value (root);
- if (NULL == val)
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if ( (0 == strcasecmp (val,
- "/forever/")) ||
- (0 == strcasecmp (val,
- "/end of time/")) ||
- (0 == strcasecmp (val,
- "/never/")) )
- {
- *ret = GNUNET_TIME_UNIT_FOREVER_ABS;
- return GNUNET_OK;
- }
- if (1 != sscanf (val,
- "/Date(%llu)/",
- &tval))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- /* Time is in seconds in JSON, but in microseconds in
- * GNUNET_TIME_Absolute */
- ret->abs_value_us = tval * 1000LL * 1000LL;
- if ( (ret->abs_value_us) / 1000LL / 1000LL != tval)
- {
- /* Integer overflow */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
/**
* Callback for a /history request; checks that (1) HTTP status
@@ -193,12 +143,17 @@ history_cb (void *cls,
size_t index;
json_array_foreach (arr, index, entry)
{
- json_t *timestamp;
-
- timestamp = json_object_get (entry, "timestamp");
- if (GNUNET_OK != parse_abs_time (timestamp, &entry_timestamp))
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_absolute_time ("timestamp",
+ &entry_timestamp),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (entry,
+ spec,
+ NULL, NULL))
TALER_TESTING_FAIL (hs->is);
-
if (last_timestamp.abs_value_us < entry_timestamp.abs_value_us)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
--
To stop receiving notification emails like this one, please contact
address@hidden.