aboutsummaryrefslogtreecommitdiff
path: root/src/json/json_helper.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-12-16 12:51:02 +0100
committerChristian Grothoff <christian@grothoff.org>2021-12-16 12:51:02 +0100
commita062e12419bdce16c9f4255871de7ecb024f2428 (patch)
treeabfe7ec0f18a4a5de4e3a2d2d26eb07b79cd1709 /src/json/json_helper.c
parent1e762cdf707a263be49cfed845c7bb4a76ef8913 (diff)
downloadgnunet-a062e12419bdce16c9f4255871de7ecb024f2428.tar.gz
gnunet-a062e12419bdce16c9f4255871de7ecb024f2428.zip
tolerate old style values (for now)
Diffstat (limited to 'src/json/json_helper.c')
-rw-r--r--src/json/json_helper.c61
1 files changed, 61 insertions, 0 deletions
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,
593{ 593{
594 struct GNUNET_TIME_Timestamp *ts = spec->ptr; 594 struct GNUNET_TIME_Timestamp *ts = spec->ptr;
595 json_t *json_t_s; 595 json_t *json_t_s;
596 json_t *json_t_ms;
596 unsigned long long int tval; 597 unsigned long long int tval;
597 598
598 if (! json_is_object (root)) 599 if (! json_is_object (root))
@@ -632,6 +633,40 @@ parse_timestamp (void *cls,
632 GNUNET_break_op (0); 633 GNUNET_break_op (0);
633 return GNUNET_SYSERR; 634 return GNUNET_SYSERR;
634 } 635 }
636 json_t_ms = json_object_get (root,
637 "t_ms");
638 if (json_is_integer (json_t_ms))
639 {
640 tval = json_integer_value (json_t_ms);
641 GNUNET_break_op (0 == tval % 1000);
642 tval -= tval % 1000;
643 /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
644 ts->abs_time.abs_value_us
645 = tval * GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us;
646 if (ts->abs_time.abs_value_us
647 / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us
648 != tval)
649 {
650 /* Integer overflow */
651 GNUNET_break_op (0);
652 return GNUNET_SYSERR;
653 }
654 return GNUNET_OK;
655 }
656 if (json_is_string (json_t_ms))
657 {
658 const char *val;
659
660 val = json_string_value (json_t_ms);
661 if ((0 == strcasecmp (val,
662 "never")))
663 {
664 ts->abs_time = GNUNET_TIME_UNIT_FOREVER_ABS;
665 return GNUNET_OK;
666 }
667 GNUNET_break_op (0);
668 return GNUNET_SYSERR;
669 }
635 GNUNET_break_op (0); 670 GNUNET_break_op (0);
636 return GNUNET_SYSERR; 671 return GNUNET_SYSERR;
637} 672}
@@ -712,6 +747,7 @@ parse_rel_time (void *cls,
712{ 747{
713 struct GNUNET_TIME_Relative *rel = spec->ptr; 748 struct GNUNET_TIME_Relative *rel = spec->ptr;
714 json_t *json_d_us; 749 json_t *json_d_us;
750 json_t *json_d_ms;
715 unsigned long long int tval; 751 unsigned long long int tval;
716 752
717 if (! json_is_object (root)) 753 if (! json_is_object (root))
@@ -747,6 +783,31 @@ parse_rel_time (void *cls,
747 GNUNET_break_op (0); 783 GNUNET_break_op (0);
748 return GNUNET_SYSERR; 784 return GNUNET_SYSERR;
749 } 785 }
786
787 json_d_ms = json_object_get (root,
788 "d_ms");
789 if (json_is_integer (json_d_ms))
790 {
791 tval = json_integer_value (json_d_ms);
792 rel->rel_value_us = GNUNET_TIME_relative_multiply (
793 GNUNET_TIME_UNIT_MILLISECONDS,
794 tval);
795 return GNUNET_OK;
796 }
797 if (json_is_string (json_d_ms))
798 {
799 const char *val;
800
801 val = json_string_value (json_d_ms);
802 if ((0 == strcasecmp (val,
803 "forever")))
804 {
805 *rel = GNUNET_TIME_UNIT_FOREVER_REL;
806 return GNUNET_OK;
807 }
808 GNUNET_break_op (0);
809 return GNUNET_SYSERR;
810 }
750 GNUNET_break_op (0); 811 GNUNET_break_op (0);
751 return GNUNET_SYSERR; 812 return GNUNET_SYSERR;
752} 813}