diff options
author | Markus Voggenreiter <Markus.Voggenreiter@tum.de> | 2019-11-27 12:30:49 +0100 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-01-13 13:31:05 +0100 |
commit | cb08bbcbefc98afe6b8c7600bb0dfb1241343cff (patch) | |
tree | ec801cb4e772bd245ca8d22f19bc751ca67d2737 /src/reclaim-attribute/reclaim_attribute.c | |
parent | c0fce9ca75973a646f80372fcc08c059818ba548 (diff) | |
download | gnunet-cb08bbcbefc98afe6b8c7600bb0dfb1241343cff.tar.gz gnunet-cb08bbcbefc98afe6b8c7600bb0dfb1241343cff.zip |
Basic Functionality Implemented
Diffstat (limited to 'src/reclaim-attribute/reclaim_attribute.c')
-rw-r--r-- | src/reclaim-attribute/reclaim_attribute.c | 214 |
1 files changed, 188 insertions, 26 deletions
diff --git a/src/reclaim-attribute/reclaim_attribute.c b/src/reclaim-attribute/reclaim_attribute.c index 207bfb617..43199c108 100644 --- a/src/reclaim-attribute/reclaim_attribute.c +++ b/src/reclaim-attribute/reclaim_attribute.c | |||
@@ -476,7 +476,30 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size ( | |||
476 | size_t len = 0; | 476 | size_t len = 0; |
477 | 477 | ||
478 | for (le = attrs->list_head; NULL != le; le = le->next) | 478 | for (le = attrs->list_head; NULL != le; le = le->next) |
479 | len += GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (le->claim); | 479 | { |
480 | if (NULL != le->claim) | ||
481 | { | ||
482 | len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
483 | len += GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (le->claim); | ||
484 | } | ||
485 | else if (NULL != le->attest ) | ||
486 | { | ||
487 | len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
488 | len += GNUNET_RECLAIM_ATTESTATION_serialize_get_size (le->attest); | ||
489 | } | ||
490 | else if (NULL != le->reference) | ||
491 | { | ||
492 | len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
493 | len += GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size (le->reference); | ||
494 | } | ||
495 | else | ||
496 | { | ||
497 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
498 | "Unserialized Claim List Entry Type for size not known.\n"); | ||
499 | break; | ||
500 | } | ||
501 | len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | ||
502 | } | ||
480 | return len; | 503 | return len; |
481 | } | 504 | } |
482 | 505 | ||
@@ -497,14 +520,50 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize ( | |||
497 | size_t len; | 520 | size_t len; |
498 | size_t total_len; | 521 | size_t total_len; |
499 | char *write_ptr; | 522 | char *write_ptr; |
500 | |||
501 | write_ptr = result; | 523 | write_ptr = result; |
502 | total_len = 0; | 524 | total_len = 0; |
503 | for (le = attrs->list_head; NULL != le; le = le->next) | 525 | for (le = attrs->list_head; NULL != le; le = le->next) |
504 | { | 526 | { |
505 | len = GNUNET_RECLAIM_ATTRIBUTE_serialize (le->claim, write_ptr); | 527 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType *list_type; |
506 | total_len += len; | 528 | if (NULL != le->claim) |
507 | write_ptr += len; | 529 | { |
530 | list_type = (struct | ||
531 | GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType *) write_ptr; | ||
532 | list_type->type = htons (1); | ||
533 | total_len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
534 | write_ptr += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
535 | len = GNUNET_RECLAIM_ATTRIBUTE_serialize (le->claim, write_ptr); | ||
536 | total_len += len; | ||
537 | write_ptr += len; | ||
538 | } | ||
539 | else if (NULL != le->attest ) | ||
540 | { | ||
541 | list_type = (struct | ||
542 | GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType *) write_ptr; | ||
543 | list_type->type = htons (2); | ||
544 | total_len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
545 | write_ptr += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
546 | len = GNUNET_RECLAIM_ATTESTATION_serialize (le->attest, write_ptr); | ||
547 | total_len += len; | ||
548 | write_ptr += len; | ||
549 | } | ||
550 | else if (NULL != le->reference) | ||
551 | { | ||
552 | list_type = (struct | ||
553 | GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType *) write_ptr; | ||
554 | list_type->type = htons (3); | ||
555 | total_len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
556 | write_ptr += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
557 | len = GNUNET_RECLAIM_ATTESTATION_REF_serialize (le->reference, write_ptr); | ||
558 | total_len += len; | ||
559 | write_ptr += len; | ||
560 | } | ||
561 | else | ||
562 | { | ||
563 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
564 | "Unserialized Claim List Entry Type not known.\n"); | ||
565 | continue; | ||
566 | } | ||
508 | } | 567 | } |
509 | return total_len; | 568 | return total_len; |
510 | } | 569 | } |
@@ -525,23 +584,75 @@ GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char *data, size_t data_size) | |||
525 | size_t attr_len; | 584 | size_t attr_len; |
526 | const char *read_ptr; | 585 | const char *read_ptr; |
527 | 586 | ||
528 | if (data_size < sizeof(struct Attribute)) | 587 | if ((data_size < sizeof(struct Attribute) + sizeof(struct |
588 | GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry)) | ||
589 | && (data_size < sizeof(struct | ||
590 | Attestation) | ||
591 | + sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry)) && | ||
592 | (data_size < sizeof(struct Attestation_Reference) + sizeof(struct | ||
593 | GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry)) ) | ||
529 | return NULL; | 594 | return NULL; |
530 | 595 | ||
531 | attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); | 596 | attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); |
532 | read_ptr = data; | 597 | read_ptr = data; |
533 | while (((data + data_size) - read_ptr) >= sizeof(struct Attribute)) | 598 | while (((data + data_size) - read_ptr) >= sizeof(struct Attribute)) |
534 | { | 599 | { |
535 | le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | 600 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType *list_type; |
536 | le->claim = | 601 | list_type = (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType *) read_ptr; |
537 | GNUNET_RECLAIM_ATTRIBUTE_deserialize (read_ptr, | 602 | if (1 == ntohs (list_type->type)) |
538 | data_size - (read_ptr - data)); | 603 | { |
539 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 604 | le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); |
540 | "Deserialized attribute %s\n", | 605 | read_ptr += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); |
541 | le->claim->name); | 606 | if (((data + data_size) - read_ptr) < sizeof(struct Attribute)) |
542 | GNUNET_CONTAINER_DLL_insert (attrs->list_head, attrs->list_tail, le); | 607 | break; |
543 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (le->claim); | 608 | le->attest = NULL; |
544 | read_ptr += attr_len; | 609 | le->reference = NULL; |
610 | le->claim = | ||
611 | GNUNET_RECLAIM_ATTRIBUTE_deserialize (read_ptr, | ||
612 | data_size - (read_ptr - data)); | ||
613 | GNUNET_CONTAINER_DLL_insert (attrs->list_head, attrs->list_tail, le); | ||
614 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (le->claim); | ||
615 | read_ptr += attr_len; | ||
616 | } | ||
617 | else if (2 == ntohs (list_type->type)) | ||
618 | { | ||
619 | le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | ||
620 | read_ptr += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
621 | if (((data + data_size) - read_ptr) < sizeof(struct Attestation)) | ||
622 | break; | ||
623 | le->claim = NULL; | ||
624 | le->reference = NULL; | ||
625 | le->attest = | ||
626 | GNUNET_RECLAIM_ATTESTATION_deserialize (read_ptr, | ||
627 | data_size - (read_ptr - data)); | ||
628 | GNUNET_CONTAINER_DLL_insert (attrs->list_head, attrs->list_tail, le); | ||
629 | attr_len = GNUNET_RECLAIM_ATTESTATION_serialize_get_size (le->attest); | ||
630 | read_ptr += attr_len; | ||
631 | } | ||
632 | else if (3 == ntohs (list_type->type)) | ||
633 | { | ||
634 | le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | ||
635 | read_ptr += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
636 | if (((data + data_size) - read_ptr) < sizeof(struct | ||
637 | Attestation_Reference)) | ||
638 | break; | ||
639 | le->claim = NULL; | ||
640 | le->attest = NULL; | ||
641 | le->reference = | ||
642 | GNUNET_RECLAIM_ATTESTATION_REF_deserialize (read_ptr, | ||
643 | data_size - (read_ptr | ||
644 | - data)); | ||
645 | GNUNET_CONTAINER_DLL_insert (attrs->list_head, attrs->list_tail, le); | ||
646 | attr_len = GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size ( | ||
647 | le->reference); | ||
648 | read_ptr += attr_len; | ||
649 | } | ||
650 | else | ||
651 | { | ||
652 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
653 | "Serialized Claim List Entry Type not known.\n"); | ||
654 | break; | ||
655 | } | ||
545 | } | 656 | } |
546 | return attrs; | 657 | return attrs; |
547 | } | 658 | } |
@@ -561,16 +672,45 @@ GNUNET_RECLAIM_ATTRIBUTE_list_dup ( | |||
561 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *result; | 672 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *result; |
562 | 673 | ||
563 | result = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); | 674 | result = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); |
675 | if (NULL == attrs->list_head) | ||
676 | { | ||
677 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Duplicating empty List\n"); | ||
678 | } | ||
564 | for (le = attrs->list_head; NULL != le; le = le->next) | 679 | for (le = attrs->list_head; NULL != le; le = le->next) |
565 | { | 680 | { |
566 | result_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | 681 | result_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); |
567 | result_le->claim = | 682 | result_le->claim = NULL; |
568 | GNUNET_RECLAIM_ATTRIBUTE_claim_new (le->claim->name, | 683 | result_le->attest = NULL; |
569 | le->claim->type, | 684 | result_le->reference = NULL; |
570 | le->claim->data, | 685 | if (NULL != le->claim) |
571 | le->claim->data_size); | 686 | { |
572 | result_le->claim->id = le->claim->id; | 687 | result_le->claim = |
573 | result_le->claim->flag = le->claim->flag; | 688 | GNUNET_RECLAIM_ATTRIBUTE_claim_new (le->claim->name, |
689 | le->claim->type, | ||
690 | le->claim->data, | ||
691 | le->claim->data_size); | ||
692 | |||
693 | result_le->claim->id = le->claim->id; | ||
694 | result_le->claim->flag = le->claim->flag; | ||
695 | } | ||
696 | if ( NULL != le->attest) | ||
697 | { | ||
698 | result_le->attest = GNUNET_RECLAIM_ATTESTATION_claim_new ( | ||
699 | le->attest->name, | ||
700 | le->attest->type, | ||
701 | le->attest->data, | ||
702 | le->attest-> | ||
703 | data_size); | ||
704 | result_le->attest->id = le->attest->id; | ||
705 | } | ||
706 | if (NULL !=le->reference) | ||
707 | { | ||
708 | result_le->reference = GNUNET_RECLAIM_ATTESTATION_reference_new ( | ||
709 | le->reference->name, | ||
710 | le->reference->reference_value); | ||
711 | result_le->reference->id = le->reference->id; | ||
712 | result_le->reference->id_attest = le->reference->id_attest; | ||
713 | } | ||
574 | GNUNET_CONTAINER_DLL_insert (result->list_head, | 714 | GNUNET_CONTAINER_DLL_insert (result->list_head, |
575 | result->list_tail, | 715 | result->list_tail, |
576 | result_le); | 716 | result_le); |
@@ -591,9 +731,14 @@ GNUNET_RECLAIM_ATTRIBUTE_list_destroy ( | |||
591 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 731 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; |
592 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *tmp_le; | 732 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *tmp_le; |
593 | 733 | ||
594 | for (le = attrs->list_head; NULL != le;) | 734 | for (le = attrs->list_head; NULL != le; le = le->next) |
595 | { | 735 | { |
596 | GNUNET_free (le->claim); | 736 | if (NULL != le->claim) |
737 | GNUNET_free (le->claim); | ||
738 | if (NULL != le->attest) | ||
739 | GNUNET_free (le->attest); | ||
740 | if (NULL != le->reference) | ||
741 | GNUNET_free (le->reference); | ||
597 | tmp_le = le; | 742 | tmp_le = le; |
598 | le = le->next; | 743 | le = le->next; |
599 | GNUNET_free (tmp_le); | 744 | GNUNET_free (tmp_le); |
@@ -601,7 +746,24 @@ GNUNET_RECLAIM_ATTRIBUTE_list_destroy ( | |||
601 | GNUNET_free (attrs); | 746 | GNUNET_free (attrs); |
602 | } | 747 | } |
603 | 748 | ||
604 | 749 | /** | |
750 | * Count attestations in claim list | ||
751 | * | ||
752 | * @param attrs list | ||
753 | */ | ||
754 | int | ||
755 | GNUNET_RECLAIM_ATTRIBUTE_list_count_attest ( | ||
756 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) | ||
757 | { | ||
758 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | ||
759 | int i = 0; | ||
760 | for (le = attrs->list_head; NULL != le; le = le->next) | ||
761 | { | ||
762 | if (NULL != le->attest) | ||
763 | i++; | ||
764 | } | ||
765 | return i; | ||
766 | } | ||
605 | /** | 767 | /** |
606 | * Get required size for serialization buffer | 768 | * Get required size for serialization buffer |
607 | * | 769 | * |