aboutsummaryrefslogtreecommitdiff
path: root/src/json/json_helper.c
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-12-19 12:55:00 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-12-19 12:55:00 +0100
commitf0f45c5113bdc7a6ac0e009b491fdb63d6d6a79a (patch)
tree1e5d9d93c542d4864c218d1d9507789cd0c89208 /src/json/json_helper.c
parentc80982c74a02eab0a457fb9a3c3671956b2909ee (diff)
downloadgnunet-f0f45c5113bdc7a6ac0e009b491fdb63d6d6a79a.tar.gz
gnunet-f0f45c5113bdc7a6ac0e009b491fdb63d6d6a79a.zip
switch to new date format (#5862)
Diffstat (limited to 'src/json/json_helper.c')
-rw-r--r--src/json/json_helper.c90
1 files changed, 48 insertions, 42 deletions
diff --git a/src/json/json_helper.c b/src/json/json_helper.c
index a9b933762..e7711a03e 100644
--- a/src/json/json_helper.c
+++ b/src/json/json_helper.c
@@ -561,41 +561,42 @@ parse_abs_time (void *cls,
561 struct GNUNET_JSON_Specification *spec) 561 struct GNUNET_JSON_Specification *spec)
562{ 562{
563 struct GNUNET_TIME_Absolute *abs = spec->ptr; 563 struct GNUNET_TIME_Absolute *abs = spec->ptr;
564 const char *val; 564 json_t *json_t_ms;
565 unsigned long long int tval; 565 unsigned long long int tval;
566 566
567 val = json_string_value (root); 567 if (!json_is_object (root))
568 if (NULL == val)
569 { 568 {
570 GNUNET_break_op (0); 569 GNUNET_break_op (0);
571 return GNUNET_SYSERR; 570 return GNUNET_SYSERR;
572 } 571 }
573 if ((0 == strcasecmp (val, 572 json_t_ms = json_object_get (root, "t_ms");
574 "/forever/")) || 573 if (json_is_integer (json_t_ms))
575 (0 == strcasecmp (val, 574 {
576 "/end of time/")) || 575 tval = json_integer_value (json_t_ms);
577 (0 == strcasecmp (val, 576 /* Time is in milliseconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
578 "/never/"))) 577 abs->abs_value_us = tval * 1000LL;
579 { 578 if ((abs->abs_value_us) / 1000LL != tval)
580 *abs = GNUNET_TIME_UNIT_FOREVER_ABS; 579 {
580 /* Integer overflow */
581 GNUNET_break_op (0);
582 return GNUNET_SYSERR;
583 }
581 return GNUNET_OK; 584 return GNUNET_OK;
582 } 585 }
583 if (1 != sscanf (val, 586 if (json_is_string (json_t_ms))
584 "/Date(%llu)/",
585 &tval))
586 { 587 {
588 const char *val;
589 val = json_string_value (json_t_ms);
590 if ((0 == strcasecmp (val, "never")))
591 {
592 *abs = GNUNET_TIME_UNIT_FOREVER_ABS;
593 return GNUNET_OK;
594 }
587 GNUNET_break_op (0); 595 GNUNET_break_op (0);
588 return GNUNET_SYSERR; 596 return GNUNET_SYSERR;
589 } 597 }
590 /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */ 598 GNUNET_break_op (0);
591 abs->abs_value_us = tval * 1000LL * 1000LL; 599 return GNUNET_SYSERR;
592 if ((abs->abs_value_us) / 1000LL / 1000LL != tval)
593 {
594 /* Integer overflow */
595 GNUNET_break_op (0);
596 return GNUNET_SYSERR;
597 }
598 return GNUNET_OK;
599} 600}
600 601
601 602
@@ -715,37 +716,42 @@ parse_rel_time (void *cls,
715 struct GNUNET_JSON_Specification *spec) 716 struct GNUNET_JSON_Specification *spec)
716{ 717{
717 struct GNUNET_TIME_Relative *rel = spec->ptr; 718 struct GNUNET_TIME_Relative *rel = spec->ptr;
718 const char *val; 719 json_t *json_d_ms;
719 unsigned long long int tval; 720 unsigned long long int tval;
720 721
721 val = json_string_value (root); 722 if (!json_is_object (root))
722 if (NULL == val)
723 { 723 {
724 GNUNET_break_op (0); 724 GNUNET_break_op (0);
725 return GNUNET_SYSERR; 725 return GNUNET_SYSERR;
726 } 726 }
727 if ((0 == strcasecmp (val, 727 json_d_ms = json_object_get (root, "d_ms");
728 "/forever/"))) 728 if (json_is_integer (json_d_ms))
729 { 729 {
730 *rel = GNUNET_TIME_UNIT_FOREVER_REL; 730 tval = json_integer_value (json_d_ms);
731 /* Time is in milliseconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
732 rel->rel_value_us = tval * 1000LL;
733 if ((rel->rel_value_us) / 1000LL != tval)
734 {
735 /* Integer overflow */
736 GNUNET_break_op (0);
737 return GNUNET_SYSERR;
738 }
731 return GNUNET_OK; 739 return GNUNET_OK;
732 } 740 }
733 if (1 != sscanf (val, 741 if (json_is_string (json_d_ms))
734 "/Delay(%llu)/",
735 &tval))
736 {
737 GNUNET_break_op (0);
738 return GNUNET_SYSERR;
739 }
740 /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Relative */
741 rel->rel_value_us = tval * 1000LL * 1000LL;
742 if ((rel->rel_value_us) / 1000LL / 1000LL != tval)
743 { 742 {
744 /* Integer overflow */ 743 const char *val;
744 val = json_string_value (json_d_ms);
745 if ((0 == strcasecmp (val, "forever")))
746 {
747 *rel = GNUNET_TIME_UNIT_FOREVER_REL;
748 return GNUNET_OK;
749 }
745 GNUNET_break_op (0); 750 GNUNET_break_op (0);
746 return GNUNET_SYSERR; 751 return GNUNET_SYSERR;
747 } 752 }
748 return GNUNET_OK; 753 GNUNET_break_op (0);
754 return GNUNET_SYSERR;
749} 755}
750 756
751 757