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.c108
1 files changed, 0 insertions, 108 deletions
diff --git a/src/json/json_generator.c b/src/json/json_generator.c
index 3f82a5f17..5806eb174 100644
--- a/src/json/json_generator.c
+++ b/src/json/json_generator.c
@@ -201,113 +201,5 @@ GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig)
201} 201}
202 202
203 203
204/**
205 * Convert GNS record to JSON.
206 *
207 * @param rname name of record
208 * @param rd record data
209 * @return corresponding JSON encoding
210 */
211json_t *
212GNUNET_JSON_from_gnsrecord (const char*rname,
213 const struct GNUNET_GNSRECORD_Data *rd,
214 unsigned int rd_count)
215{
216 struct GNUNET_TIME_Absolute abs_exp;
217 struct GNUNET_TIME_Relative rel_exp;
218 const char *expiration_time_str;
219 const char *record_type_str;
220 char *value_str;
221 json_t *data;
222 json_t *record;
223 json_t *records;
224
225 data = json_object ();
226 if (NULL == data)
227 {
228 GNUNET_break (0);
229 return NULL;
230 }
231 if (0 !=
232 json_object_set_new (data,
233 "record_name",
234 json_string (rname)))
235 {
236 GNUNET_break (0);
237 json_decref (data);
238 return NULL;
239 }
240 records = json_array ();
241 if (NULL == records)
242 {
243 GNUNET_break (0);
244 json_decref (data);
245 return NULL;
246 }
247 for (int i = 0; i < rd_count; i++)
248 {
249 value_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
250 rd[i].data,
251 rd[i].data_size);
252 if (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION & rd[i].flags)
253 {
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 }
258 else
259 {
260 abs_exp.abs_value_us = rd[i].expiration_time;
261 expiration_time_str = GNUNET_STRINGS_absolute_time_to_string (abs_exp);
262 }
263 record_type_str = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
265 "Packing %s %s %s %d\n",
266 value_str, record_type_str, expiration_time_str, rd[i].flags);
267 record = json_pack ("{s:s,s:s,s:s,s:b,s:b,s:b,s:b}",
268 "value",
269 value_str,
270 "record_type",
271 record_type_str,
272 "expiration_time",
273 expiration_time_str,
274 "private",
275 rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE,
276 "relative_expiration",
277 rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION,
278 "supplemental",
279 rd[i].flags & GNUNET_GNSRECORD_RF_SUPPLEMENTAL,
280 "shadow",
281 rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD);
282 GNUNET_free (value_str);
283 if (NULL == record)
284 {
285 GNUNET_break (0);
286 json_decref (records);
287 json_decref (data);
288 return NULL;
289 }
290 if (0 !=
291 json_array_append_new (records,
292 record))
293 {
294 GNUNET_break (0);
295 json_decref (records);
296 json_decref (data);
297 return NULL;
298 }
299 }
300 if (0 !=
301 json_object_set_new (data,
302 "data",
303 records))
304 {
305 GNUNET_break (0);
306 json_decref (data);
307 return NULL;
308 }
309 return data;
310}
311
312 204
313/* End of json/json_generator.c */ 205/* End of json/json_generator.c */