diff options
m--------- | contrib/build-common | 0 | ||||
-rw-r--r-- | src/json/json_generator.c | 44 | ||||
-rw-r--r-- | src/json/json_helper.c | 90 |
3 files changed, 72 insertions, 62 deletions
diff --git a/contrib/build-common b/contrib/build-common | |||
Subproject 6ac60bd0b1f96324b4175fa03aaf9780ed8efb4 | Subproject 1915a74bbb4cd2ae9bc541a382dfebc37064a2f | ||
diff --git a/src/json/json_generator.c b/src/json/json_generator.c index 6373d65d8..89fd53265 100644 --- a/src/json/json_generator.c +++ b/src/json/json_generator.c | |||
@@ -59,20 +59,22 @@ json_t * | |||
59 | GNUNET_JSON_from_time_abs (struct GNUNET_TIME_Absolute stamp) | 59 | GNUNET_JSON_from_time_abs (struct GNUNET_TIME_Absolute stamp) |
60 | { | 60 | { |
61 | json_t *j; | 61 | json_t *j; |
62 | char *mystr; | ||
63 | int ret; | ||
64 | 62 | ||
65 | GNUNET_assert (GNUNET_OK == | 63 | GNUNET_assert (GNUNET_OK == |
66 | GNUNET_TIME_round_abs (&stamp)); | 64 | GNUNET_TIME_round_abs (&stamp)); |
65 | |||
66 | j = json_object (); | ||
67 | |||
67 | if (stamp.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) | 68 | if (stamp.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) |
68 | return json_string ("/never/"); | 69 | { |
69 | ret = GNUNET_asprintf (&mystr, | 70 | json_object_set_new (j, |
70 | "/Date(%llu)/", | 71 | "t_ms", |
71 | (unsigned long long) (stamp.abs_value_us / (1000LL | 72 | json_string ("never")); |
72 | * 1000LL))); | 73 | return j; |
73 | GNUNET_assert (ret > 0); | 74 | } |
74 | j = json_string (mystr); | 75 | json_object_set_new (j, |
75 | GNUNET_free (mystr); | 76 | "t_ms", |
77 | json_integer ((json_int_t) (stamp.abs_value_us / 1000LL))); | ||
76 | return j; | 78 | return j; |
77 | } | 79 | } |
78 | 80 | ||
@@ -100,20 +102,22 @@ json_t * | |||
100 | GNUNET_JSON_from_time_rel (struct GNUNET_TIME_Relative stamp) | 102 | GNUNET_JSON_from_time_rel (struct GNUNET_TIME_Relative stamp) |
101 | { | 103 | { |
102 | json_t *j; | 104 | json_t *j; |
103 | char *mystr; | ||
104 | int ret; | ||
105 | 105 | ||
106 | GNUNET_assert (GNUNET_OK == | 106 | GNUNET_assert (GNUNET_OK == |
107 | GNUNET_TIME_round_rel (&stamp)); | 107 | GNUNET_TIME_round_rel (&stamp)); |
108 | |||
109 | j = json_object (); | ||
110 | |||
108 | if (stamp.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) | 111 | if (stamp.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) |
109 | return json_string ("/forever/"); | 112 | { |
110 | ret = GNUNET_asprintf (&mystr, | 113 | json_object_set_new (j, |
111 | "/Delay(%llu)/", | 114 | "d_ms", |
112 | (unsigned long long) (stamp.rel_value_us / (1000LL | 115 | json_string ("forever")); |
113 | * 1000LL))); | 116 | return j; |
114 | GNUNET_assert (ret > 0); | 117 | } |
115 | j = json_string (mystr); | 118 | json_object_set_new (j, |
116 | GNUNET_free (mystr); | 119 | "d_ms", |
120 | json_integer ((json_int_t) (stamp.rel_value_us / 1000LL))); | ||
117 | return j; | 121 | return j; |
118 | } | 122 | } |
119 | 123 | ||
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 | ||