aboutsummaryrefslogtreecommitdiff
path: root/src/gnsrecord
diff options
context:
space:
mode:
authorPhil <phil.buschmann@tum.de>2018-07-26 02:31:30 +0200
committerPhil <phil.buschmann@tum.de>2018-07-26 02:31:30 +0200
commitf7ca27a73e69a8c224d65768be3416ff1388c1d7 (patch)
tree7530a6def74a55885780285162b18b4c2b353380 /src/gnsrecord
parentcc577a227d6a5ae8ef75e0fa91ef98ced2d2b743 (diff)
downloadgnunet-f7ca27a73e69a8c224d65768be3416ff1388c1d7.tar.gz
gnunet-f7ca27a73e69a8c224d65768be3416ff1388c1d7.zip
change namestore, json handling; fix identity, gns
Diffstat (limited to 'src/gnsrecord')
-rw-r--r--src/gnsrecord/Makefile.am1
-rw-r--r--src/gnsrecord/gnsrecord.c126
2 files changed, 0 insertions, 127 deletions
diff --git a/src/gnsrecord/Makefile.am b/src/gnsrecord/Makefile.am
index 47d83169f..f840a31a4 100644
--- a/src/gnsrecord/Makefile.am
+++ b/src/gnsrecord/Makefile.am
@@ -39,7 +39,6 @@ libgnunetgnsrecord_la_SOURCES = \
39 gnsrecord_misc.c 39 gnsrecord_misc.c
40libgnunetgnsrecord_la_LIBADD = \ 40libgnunetgnsrecord_la_LIBADD = \
41 $(top_builddir)/src/util/libgnunetutil.la \ 41 $(top_builddir)/src/util/libgnunetutil.la \
42 -ljansson \
43 $(GN_LIBINTL) 42 $(GN_LIBINTL)
44libgnunetgnsrecord_la_LDFLAGS = \ 43libgnunetgnsrecord_la_LDFLAGS = \
45 $(GN_LIB_LDFLAGS) $(WINFLAGS) \ 44 $(GN_LIB_LDFLAGS) $(WINFLAGS) \
diff --git a/src/gnsrecord/gnsrecord.c b/src/gnsrecord/gnsrecord.c
index 30a0ffa83..b80d86073 100644
--- a/src/gnsrecord/gnsrecord.c
+++ b/src/gnsrecord/gnsrecord.c
@@ -247,130 +247,4 @@ GNUNET_GNSRECORD_number_to_typename (uint32_t type)
247 return NULL; 247 return NULL;
248} 248}
249 249
250/**
251 * Parse given JSON object to gns record
252 *
253 * @param cls closure, NULL
254 * @param root the json object representing data
255 * @param spec where to write the data
256 * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
257 */
258static int
259parse_gnsrecordobject (void *cls,
260 json_t *root,
261 struct GNUNET_JSON_Specification *spec)
262{
263 struct GNUNET_GNSRECORD_Data *gnsrecord_object;
264 struct GNUNET_TIME_Absolute abs_expiration_time;
265 int unpack_state=0;
266 const char *data;
267 const char *expiration_date;
268 const char *record_type;
269 const char *dummy_value;
270 int flag;
271 void *rdata;
272 size_t rdata_size;
273
274 if(!json_is_object(root))
275 {
276 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
277 "Error json is not array nor object!\n");
278 return GNUNET_SYSERR;
279 }
280 //interpret single gns record
281 unpack_state = json_unpack(root,
282 "{s:s, s:s, s:s, s?:i, s:s!}",
283 "value", &data,
284 "type", &record_type,
285 "expiration_time", &expiration_date,
286 "flag", &flag,
287 "label", &dummy_value);
288 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
289 "{value:%s, type:%s, expire:%s, flag:%i}",
290 data,
291 record_type,
292 expiration_date,
293 flag);
294 if (GNUNET_SYSERR == unpack_state)
295 {
296 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
297 "Error json object has a wrong format!\n");
298 return GNUNET_SYSERR;
299 }
300 //TODO test
301 gnsrecord_object = GNUNET_new (struct GNUNET_GNSRECORD_Data);
302 gnsrecord_object->record_type = GNUNET_GNSRECORD_typename_to_number(record_type);
303 if (GNUNET_OK
304 != GNUNET_GNSRECORD_string_to_value (gnsrecord_object->record_type,
305 data, &rdata,
306 &rdata_size))
307 {
308 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,"Value invalid for record type");
309 return GNUNET_SYSERR;
310 }
311 gnsrecord_object->data = rdata;
312 gnsrecord_object->data_size = rdata_size;
313
314 if (0 == strcmp (expiration_date, "never"))
315 {
316 gnsrecord_object->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
317 }
318 else if (GNUNET_OK
319 == GNUNET_STRINGS_fancy_time_to_absolute (expiration_date,
320 &abs_expiration_time))
321 {
322 gnsrecord_object->expiration_time = abs_expiration_time.abs_value_us;
323 }
324 else
325 {
326 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Value invalid for record type");
327 return GNUNET_SYSERR;
328 }
329 gnsrecord_object->flags = (enum GNUNET_GNSRECORD_Flags)flag;
330 *(struct GNUNET_GNSRECORD_Data **) spec->ptr = gnsrecord_object;
331 return GNUNET_OK;
332}
333
334/**
335 * Cleanup data left from parsing RSA public key.
336 *
337 * @param cls closure, NULL
338 * @param[out] spec where to free the data
339 */
340static void
341clean_gnsrecordobject (void *cls, struct GNUNET_JSON_Specification *spec)
342{
343 struct GNUNET_GNSRECORD_Data **gnsrecord_object;
344 gnsrecord_object = (struct GNUNET_GNSRECORD_Data **) spec->ptr;
345 if (NULL != *gnsrecord_object)
346 {
347 if (NULL != (*gnsrecord_object)->data)
348 GNUNET_free((char*)(*gnsrecord_object)->data);
349 GNUNET_free(*gnsrecord_object);
350 *gnsrecord_object = NULL;
351 }
352}
353
354/**
355 * JSON Specification for GNS Records.
356 *
357 * @param gnsrecord_object struct of GNUNET_GNSRECORD_Data to fill
358 * @return JSON Specification
359 */
360struct GNUNET_JSON_Specification
361GNUNET_JSON_spec_gnsrecord_data (struct GNUNET_GNSRECORD_Data **gnsrecord_object)
362{
363 struct GNUNET_JSON_Specification ret = {
364 .parser = &parse_gnsrecordobject,
365 .cleaner = &clean_gnsrecordobject,
366 .cls = NULL,
367 .field = NULL,
368 .ptr = gnsrecord_object,
369 .ptr_size = 0,
370 .size_ptr = NULL
371 };
372 *gnsrecord_object = NULL;
373 return ret;
374}
375
376/* end of gnsrecord.c */ 250/* end of gnsrecord.c */