[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] 01/02: tolerate old style values (for now)
From: |
gnunet |
Subject: |
[gnunet] 01/02: tolerate old style values (for now) |
Date: |
Thu, 16 Dec 2021 12:53:43 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
commit a062e12419bdce16c9f4255871de7ecb024f2428
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Thu Dec 16 12:51:02 2021 +0100
tolerate old style values (for now)
---
src/json/json_helper.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/src/json/json_helper.c b/src/json/json_helper.c
index 73f5fc00c..7735503f6 100644
--- a/src/json/json_helper.c
+++ b/src/json/json_helper.c
@@ -593,6 +593,7 @@ parse_timestamp (void *cls,
{
struct GNUNET_TIME_Timestamp *ts = spec->ptr;
json_t *json_t_s;
+ json_t *json_t_ms;
unsigned long long int tval;
if (! json_is_object (root))
@@ -632,6 +633,40 @@ parse_timestamp (void *cls,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
+ json_t_ms = json_object_get (root,
+ "t_ms");
+ if (json_is_integer (json_t_ms))
+ {
+ tval = json_integer_value (json_t_ms);
+ GNUNET_break_op (0 == tval % 1000);
+ tval -= tval % 1000;
+ /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute
*/
+ ts->abs_time.abs_value_us
+ = tval * GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us;
+ if (ts->abs_time.abs_value_us
+ / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us
+ != tval)
+ {
+ /* Integer overflow */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+ }
+ if (json_is_string (json_t_ms))
+ {
+ const char *val;
+
+ val = json_string_value (json_t_ms);
+ if ((0 == strcasecmp (val,
+ "never")))
+ {
+ ts->abs_time = GNUNET_TIME_UNIT_FOREVER_ABS;
+ return GNUNET_OK;
+ }
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
@@ -712,6 +747,7 @@ parse_rel_time (void *cls,
{
struct GNUNET_TIME_Relative *rel = spec->ptr;
json_t *json_d_us;
+ json_t *json_d_ms;
unsigned long long int tval;
if (! json_is_object (root))
@@ -747,6 +783,31 @@ parse_rel_time (void *cls,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
+
+ json_d_ms = json_object_get (root,
+ "d_ms");
+ if (json_is_integer (json_d_ms))
+ {
+ tval = json_integer_value (json_d_ms);
+ rel->rel_value_us = GNUNET_TIME_relative_multiply (
+ GNUNET_TIME_UNIT_MILLISECONDS,
+ tval);
+ return GNUNET_OK;
+ }
+ if (json_is_string (json_d_ms))
+ {
+ const char *val;
+
+ val = json_string_value (json_d_ms);
+ if ((0 == strcasecmp (val,
+ "forever")))
+ {
+ *rel = GNUNET_TIME_UNIT_FOREVER_REL;
+ return GNUNET_OK;
+ }
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.