diff options
author | Markus Voggenreiter <Markus.Voggenreiter@tum.de> | 2019-10-23 21:50:46 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-01-13 13:31:03 +0100 |
commit | bb286cb253251e8210ed686dbde3dc8ecee16420 (patch) | |
tree | 4e7f625480adb0397df002f6e26bb6a3755ff3cc /src/reclaim/json_reclaim.c | |
parent | c136a16600cd4f72d7def1af7b4aa7592310c898 (diff) | |
download | gnunet-bb286cb253251e8210ed686dbde3dc8ecee16420.tar.gz gnunet-bb286cb253251e8210ed686dbde3dc8ecee16420.zip |
Preparation for Reference Type
Diffstat (limited to 'src/reclaim/json_reclaim.c')
-rw-r--r-- | src/reclaim/json_reclaim.c | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/reclaim/json_reclaim.c b/src/reclaim/json_reclaim.c index a0016bac8..552ca0e69 100644 --- a/src/reclaim/json_reclaim.c +++ b/src/reclaim/json_reclaim.c | |||
@@ -374,3 +374,107 @@ GNUNET_RECLAIM_JSON_spec_claim_attest (struct | |||
374 | *attr = NULL; | 374 | *attr = NULL; |
375 | return ret; | 375 | return ret; |
376 | } | 376 | } |
377 | |||
378 | /** | ||
379 | * Parse given JSON object to an attestation claim | ||
380 | * | ||
381 | * @param cls closure, NULL | ||
382 | * @param root the json object representing data | ||
383 | * @param spec where to write the data | ||
384 | * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error | ||
385 | */ | ||
386 | static int | ||
387 | parse_attest_ref (void *cls, json_t *root, struct | ||
388 | GNUNET_JSON_Specification *spec) | ||
389 | { | ||
390 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr; | ||
391 | const char *name_str = NULL; | ||
392 | const char *ref_val_str = NULL; | ||
393 | const char *ref_id_str = NULL; | ||
394 | const char *id_str = NULL; | ||
395 | int unpack_state; | ||
396 | |||
397 | GNUNET_assert (NULL != root); | ||
398 | |||
399 | if (! json_is_object (root)) | ||
400 | { | ||
401 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
402 | "Error json is not array nor object!\n"); | ||
403 | return GNUNET_SYSERR; | ||
404 | } | ||
405 | // interpret single reference | ||
406 | unpack_state = json_unpack (root, | ||
407 | "{s:s, s?s, s:s, s:s!}", | ||
408 | "name", | ||
409 | &name_str, | ||
410 | "id", | ||
411 | &id_str, | ||
412 | "ref_id", | ||
413 | &ref_id_str, | ||
414 | "ref_value", | ||
415 | &ref_val_str); | ||
416 | if ((0 != unpack_state) || (NULL == name_str) || (NULL == ref_val_str) || | ||
417 | (NULL == ref_id_str)) | ||
418 | { | ||
419 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
420 | "Error json object has a wrong format!\n"); | ||
421 | return GNUNET_SYSERR; | ||
422 | } | ||
423 | |||
424 | attr = GNUNET_RECLAIM_ATTESTATION_reference_new (name_str, ref_val_str); | ||
425 | |||
426 | attr->id = 0; | ||
427 | |||
428 | if ((NULL == ref_id_str) || (0 == strlen (ref_id_str))) | ||
429 | attr->id_attest = 0; | ||
430 | else | ||
431 | GNUNET_STRINGS_string_to_data (ref_id_str, | ||
432 | strlen (ref_id_str), | ||
433 | &attr->id_attest, | ||
434 | sizeof(uint64_t)); | ||
435 | |||
436 | *(struct GNUNET_RECLAIM_ATTESTATION_REFERENCE **) spec->ptr = attr; | ||
437 | return GNUNET_OK; | ||
438 | } | ||
439 | |||
440 | /** | ||
441 | * Cleanup data left from parsing RSA public key. | ||
442 | * | ||
443 | * @param cls closure, NULL | ||
444 | * @param[out] spec where to free the data | ||
445 | */ | ||
446 | static void | ||
447 | clean_attest_ref (void *cls, struct GNUNET_JSON_Specification *spec) | ||
448 | { | ||
449 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE **attr; | ||
450 | |||
451 | attr = (struct GNUNET_RECLAIM_ATTESTATION_REFERENCE **) spec->ptr; | ||
452 | if (NULL != *attr) | ||
453 | { | ||
454 | GNUNET_free (*attr); | ||
455 | *attr = NULL; | ||
456 | } | ||
457 | } | ||
458 | |||
459 | /** | ||
460 | * JSON Specification for Reclaim attestation references. | ||
461 | * | ||
462 | * @param ticket struct of GNUNET_RECLAIM_ATTESTATION_REFERENCE to fill | ||
463 | * @return JSON Specification | ||
464 | */ | ||
465 | struct GNUNET_JSON_Specification | ||
466 | GNUNET_RECLAIM_JSON_spec_claim_attest_ref (struct | ||
467 | GNUNET_RECLAIM_ATTESTATION_REFERENCE | ||
468 | **attr) | ||
469 | { | ||
470 | struct GNUNET_JSON_Specification ret = { .parser = &parse_attest_ref, | ||
471 | .cleaner = &clean_attest_ref, | ||
472 | .cls = NULL, | ||
473 | .field = NULL, | ||
474 | .ptr = attr, | ||
475 | .ptr_size = 0, | ||
476 | .size_ptr = NULL }; | ||
477 | |||
478 | *attr = NULL; | ||
479 | return ret; | ||
480 | } \ No newline at end of file | ||