diff options
Diffstat (limited to 'src/json')
-rw-r--r-- | src/json/json_generator.c | 27 | ||||
-rw-r--r-- | src/json/json_gnsrecord.c | 44 |
2 files changed, 53 insertions, 18 deletions
diff --git a/src/json/json_generator.c b/src/json/json_generator.c index dd875871e..594fcaf27 100644 --- a/src/json/json_generator.c +++ b/src/json/json_generator.c | |||
@@ -213,7 +213,8 @@ GNUNET_JSON_from_gnsrecord (const char*rname, | |||
213 | const struct GNUNET_GNSRECORD_Data *rd, | 213 | const struct GNUNET_GNSRECORD_Data *rd, |
214 | unsigned int rd_count) | 214 | unsigned int rd_count) |
215 | { | 215 | { |
216 | struct GNUNET_TIME_Absolute expiration_time; | 216 | struct GNUNET_TIME_Absolute abs_exp; |
217 | struct GNUNET_TIME_Relative rel_exp; | ||
217 | const char *expiration_time_str; | 218 | const char *expiration_time_str; |
218 | const char *record_type_str; | 219 | const char *record_type_str; |
219 | char *value_str; | 220 | char *value_str; |
@@ -248,22 +249,34 @@ GNUNET_JSON_from_gnsrecord (const char*rname, | |||
248 | value_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, | 249 | value_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type, |
249 | rd[i].data, | 250 | rd[i].data, |
250 | rd[i].data_size); | 251 | rd[i].data_size); |
251 | expiration_time = GNUNET_GNSRECORD_record_get_expiration_time (1, &rd[i]); | 252 | if (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION & rd[i].flags) |
252 | expiration_time_str = GNUNET_STRINGS_absolute_time_to_string ( | 253 | { |
253 | expiration_time); | 254 | rel_exp.rel_value_us = rd[i].expiration_time; |
255 | expiration_time_str = GNUNET_STRINGS_relative_time_to_string (rel_exp, | ||
256 | GNUNET_NO); | ||
257 | } else { | ||
258 | abs_exp.abs_value_us = rd[i].expiration_time; | ||
259 | expiration_time_str = GNUNET_STRINGS_absolute_time_to_string (abs_exp); | ||
260 | } | ||
254 | record_type_str = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); | 261 | record_type_str = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type); |
255 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 262 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
256 | "Packing %s %s %s %d\n", | 263 | "Packing %s %s %s %d\n", |
257 | value_str, record_type_str, expiration_time_str, rd[i].flags); | 264 | value_str, record_type_str, expiration_time_str, rd[i].flags); |
258 | record = json_pack ("{s:s,s:s,s:s,s:i}", | 265 | record = json_pack ("{s:s,s:s,s:s,s:b,s:b,s:b,s:b}", |
259 | "value", | 266 | "value", |
260 | value_str, | 267 | value_str, |
261 | "record_type", | 268 | "record_type", |
262 | record_type_str, | 269 | record_type_str, |
263 | "expiration_time", | 270 | "expiration_time", |
264 | expiration_time_str, | 271 | expiration_time_str, |
265 | "flag", | 272 | "private", |
266 | rd[i].flags); | 273 | rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE, |
274 | "relative_expiration", | ||
275 | rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION, | ||
276 | "supplemental", | ||
277 | rd[i].flags & GNUNET_GNSRECORD_RF_SUPPLEMENTAL, | ||
278 | "shadow", | ||
279 | rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD); | ||
267 | GNUNET_free (value_str); | 280 | GNUNET_free (value_str); |
268 | if (NULL == record) | 281 | if (NULL == record) |
269 | { | 282 | { |
diff --git a/src/json/json_gnsrecord.c b/src/json/json_gnsrecord.c index 37f0c03da..fe5858f06 100644 --- a/src/json/json_gnsrecord.c +++ b/src/json/json_gnsrecord.c | |||
@@ -31,7 +31,10 @@ | |||
31 | #define GNUNET_JSON_GNSRECORD_RECORD_DATA "data" | 31 | #define GNUNET_JSON_GNSRECORD_RECORD_DATA "data" |
32 | #define GNUNET_JSON_GNSRECORD_TYPE "record_type" | 32 | #define GNUNET_JSON_GNSRECORD_TYPE "record_type" |
33 | #define GNUNET_JSON_GNSRECORD_EXPIRATION_TIME "expiration_time" | 33 | #define GNUNET_JSON_GNSRECORD_EXPIRATION_TIME "expiration_time" |
34 | #define GNUNET_JSON_GNSRECORD_FLAG "flag" | 34 | #define GNUNET_JSON_GNSRECORD_FLAG_PRIVATE "private" |
35 | #define GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL "supplemental" | ||
36 | #define GNUNET_JSON_GNSRECORD_FLAG_RELATIVE "relative_expiration" | ||
37 | #define GNUNET_JSON_GNSRECORD_FLAG_SHADOW "shadow" | ||
35 | #define GNUNET_JSON_GNSRECORD_RECORD_NAME "record_name" | 38 | #define GNUNET_JSON_GNSRECORD_RECORD_NAME "record_name" |
36 | #define GNUNET_JSON_GNSRECORD_NEVER "never" | 39 | #define GNUNET_JSON_GNSRECORD_NEVER "never" |
37 | 40 | ||
@@ -48,12 +51,15 @@ struct GnsRecordInfo | |||
48 | static void | 51 | static void |
49 | cleanup_recordinfo (struct GnsRecordInfo *gnsrecord_info) | 52 | cleanup_recordinfo (struct GnsRecordInfo *gnsrecord_info) |
50 | { | 53 | { |
54 | char *tmp; | ||
55 | |||
51 | if (NULL != *(gnsrecord_info->rd)) | 56 | if (NULL != *(gnsrecord_info->rd)) |
52 | { | 57 | { |
53 | for (unsigned int i = 0; i < *(gnsrecord_info->rd_count); i++) | 58 | for (int i = 0; i < *(gnsrecord_info->rd_count); i++) |
54 | { | 59 | { |
55 | if (NULL != (*(gnsrecord_info->rd))[i].data) | 60 | tmp = (char*) (*(gnsrecord_info->rd))[i].data; |
56 | GNUNET_free_nz ((char *) (*(gnsrecord_info->rd))[i].data); | 61 | if (NULL != tmp) |
62 | GNUNET_free (tmp); | ||
57 | } | 63 | } |
58 | GNUNET_free (*(gnsrecord_info->rd)); | 64 | GNUNET_free (*(gnsrecord_info->rd)); |
59 | *(gnsrecord_info->rd) = NULL; | 65 | *(gnsrecord_info->rd) = NULL; |
@@ -80,20 +86,29 @@ parse_record (json_t *data, struct GNUNET_GNSRECORD_Data *rd) | |||
80 | const char *value; | 86 | const char *value; |
81 | const char *record_type; | 87 | const char *record_type; |
82 | const char *expiration_time; | 88 | const char *expiration_time; |
83 | int flag; | 89 | int private; |
90 | int supplemental; | ||
91 | int rel_exp; | ||
92 | int shadow; | ||
84 | int unpack_state = 0; | 93 | int unpack_state = 0; |
85 | 94 | ||
86 | // interpret single gns record | 95 | // interpret single gns record |
87 | unpack_state = json_unpack (data, | 96 | unpack_state = json_unpack (data, |
88 | "{s:s, s:s, s:s, s?:i!}", | 97 | "{s:s, s:s, s:s, s:b, s:b, s:b, s:b}", |
89 | GNUNET_JSON_GNSRECORD_VALUE, | 98 | GNUNET_JSON_GNSRECORD_VALUE, |
90 | &value, | 99 | &value, |
91 | GNUNET_JSON_GNSRECORD_TYPE, | 100 | GNUNET_JSON_GNSRECORD_TYPE, |
92 | &record_type, | 101 | &record_type, |
93 | GNUNET_JSON_GNSRECORD_EXPIRATION_TIME, | 102 | GNUNET_JSON_GNSRECORD_EXPIRATION_TIME, |
94 | &expiration_time, | 103 | &expiration_time, |
95 | GNUNET_JSON_GNSRECORD_FLAG, | 104 | GNUNET_JSON_GNSRECORD_FLAG_PRIVATE, |
96 | &flag); | 105 | &private, |
106 | GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL, | ||
107 | &supplemental, | ||
108 | GNUNET_JSON_GNSRECORD_FLAG_RELATIVE, | ||
109 | &rel_exp, | ||
110 | GNUNET_JSON_GNSRECORD_FLAG_SHADOW, | ||
111 | &shadow); | ||
97 | if (0 != unpack_state) | 112 | if (0 != unpack_state) |
98 | { | 113 | { |
99 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 114 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -119,9 +134,10 @@ parse_record (json_t *data, struct GNUNET_GNSRECORD_Data *rd) | |||
119 | { | 134 | { |
120 | rd->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | 135 | rd->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; |
121 | } | 136 | } |
122 | else if (GNUNET_OK == | 137 | else if ((1 != rel_exp) && |
138 | (GNUNET_OK == | ||
123 | GNUNET_STRINGS_fancy_time_to_absolute (expiration_time, | 139 | GNUNET_STRINGS_fancy_time_to_absolute (expiration_time, |
124 | &abs_expiration_time)) | 140 | &abs_expiration_time))) |
125 | { | 141 | { |
126 | rd->expiration_time = abs_expiration_time.abs_value_us; | 142 | rd->expiration_time = abs_expiration_time.abs_value_us; |
127 | } | 143 | } |
@@ -129,6 +145,7 @@ parse_record (json_t *data, struct GNUNET_GNSRECORD_Data *rd) | |||
129 | GNUNET_STRINGS_fancy_time_to_relative (expiration_time, | 145 | GNUNET_STRINGS_fancy_time_to_relative (expiration_time, |
130 | &rel_expiration_time)) | 146 | &rel_expiration_time)) |
131 | { | 147 | { |
148 | rd->flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | ||
132 | rd->expiration_time = rel_expiration_time.rel_value_us; | 149 | rd->expiration_time = rel_expiration_time.rel_value_us; |
133 | } | 150 | } |
134 | else | 151 | else |
@@ -136,7 +153,12 @@ parse_record (json_t *data, struct GNUNET_GNSRECORD_Data *rd) | |||
136 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expiration time invalid\n"); | 153 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expiration time invalid\n"); |
137 | return GNUNET_SYSERR; | 154 | return GNUNET_SYSERR; |
138 | } | 155 | } |
139 | rd->flags = (enum GNUNET_GNSRECORD_Flags) flag; | 156 | if (1 == private) |
157 | rd->flags |= GNUNET_GNSRECORD_RF_PRIVATE; | ||
158 | if (1 == supplemental) | ||
159 | rd->flags |= GNUNET_GNSRECORD_RF_SUPPLEMENTAL; | ||
160 | if (1 == shadow) | ||
161 | rd->flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD; | ||
140 | return GNUNET_OK; | 162 | return GNUNET_OK; |
141 | } | 163 | } |
142 | 164 | ||