aboutsummaryrefslogtreecommitdiff
path: root/src/json/json_generator.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/json/json_generator.c')
-rw-r--r--src/json/json_generator.c44
1 files changed, 24 insertions, 20 deletions
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 *
59GNUNET_JSON_from_time_abs (struct GNUNET_TIME_Absolute stamp) 59GNUNET_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 *
100GNUNET_JSON_from_time_rel (struct GNUNET_TIME_Relative stamp) 102GNUNET_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