diff options
author | Markus Voggenreiter <Markus.Voggenreiter@tum.de> | 2019-11-01 17:24:32 +0100 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-01-13 13:31:04 +0100 |
commit | 0688b167e707e1c60d1aa3c220bc6b99d60fd662 (patch) | |
tree | 42d91bdfff756c3d8404afa70ae2d3a624f0c672 | |
parent | 6fad96b4971e3067168932088dcaf6c3cbdcb124 (diff) | |
download | gnunet-0688b167e707e1c60d1aa3c220bc6b99d60fd662.tar.gz gnunet-0688b167e707e1c60d1aa3c220bc6b99d60fd662.zip |
Pure Listing of References
-rw-r--r-- | src/reclaim/plugin_rest_reclaim.c | 123 |
1 files changed, 119 insertions, 4 deletions
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index f7713c284..6a14132c4 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c | |||
@@ -629,6 +629,106 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
629 | GNUNET_JSON_parse_free (attrspec); | 629 | GNUNET_JSON_parse_free (attrspec); |
630 | } | 630 | } |
631 | 631 | ||
632 | /** | ||
633 | * Collect all references for an ego | ||
634 | * | ||
635 | */ | ||
636 | static void | ||
637 | ref_collect (void *cls, | ||
638 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | ||
639 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, | ||
640 | const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest, | ||
641 | const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *reference) | ||
642 | { | ||
643 | struct RequestHandle *handle = cls; | ||
644 | json_t *attr_obj; | ||
645 | char *id_str; | ||
646 | char *id_attest_str; | ||
647 | |||
648 | if (NULL == reference) | ||
649 | { | ||
650 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); | ||
651 | return; | ||
652 | } | ||
653 | |||
654 | if ((NULL == reference->name) || (NULL == reference->reference_value)) | ||
655 | { | ||
656 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); | ||
657 | return; | ||
658 | } | ||
659 | |||
660 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding reference: %s\n", | ||
661 | reference->name); | ||
662 | attr_obj = json_object (); | ||
663 | json_object_set_new (attr_obj, "name", json_string (reference->name)); | ||
664 | json_object_set_new (attr_obj, "ref_value", json_string ( | ||
665 | reference->reference_value)); | ||
666 | id_str = GNUNET_STRINGS_data_to_string_alloc (&reference->id, | ||
667 | sizeof(uint64_t)); | ||
668 | id_attest_str = GNUNET_STRINGS_data_to_string_alloc (&reference->id_attest, | ||
669 | sizeof(uint64_t)); | ||
670 | json_object_set_new (attr_obj, "id", json_string (id_str)); | ||
671 | json_object_set_new (attr_obj, "ref_id", json_string (id_attest_str)); | ||
672 | json_array_append (handle->resp_object, attr_obj); | ||
673 | json_decref (attr_obj); | ||
674 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); | ||
675 | } | ||
676 | |||
677 | /** | ||
678 | * Lists references for identity request | ||
679 | * | ||
680 | * @param con_handle the connection handle | ||
681 | * @param url the url | ||
682 | * @param cls the RequestHandle | ||
683 | */ | ||
684 | static void | ||
685 | list_reference_cont (struct GNUNET_REST_RequestHandle *con_handle, | ||
686 | const char *url, | ||
687 | void *cls) | ||
688 | { | ||
689 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | ||
690 | struct RequestHandle *handle = cls; | ||
691 | struct EgoEntry *ego_entry; | ||
692 | char *identity; | ||
693 | |||
694 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
695 | "Getting references for %s.\n", | ||
696 | handle->url); | ||
697 | if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + strlen ( | ||
698 | "reference/") + 1 >= strlen ( | ||
699 | handle->url)) | ||
700 | { | ||
701 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); | ||
702 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
703 | return; | ||
704 | } | ||
705 | identity = handle->url + strlen ( | ||
706 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + strlen ("reference/") | ||
707 | + 1; | ||
708 | for (ego_entry = handle->ego_head; NULL != ego_entry; | ||
709 | ego_entry = ego_entry->next) | ||
710 | if (0 == strcmp (identity, ego_entry->identifier)) | ||
711 | break; | ||
712 | handle->resp_object = json_array (); | ||
713 | |||
714 | if (NULL == ego_entry) | ||
715 | { | ||
716 | // Done | ||
717 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity); | ||
718 | GNUNET_SCHEDULER_add_now (&return_response, handle); | ||
719 | return; | ||
720 | } | ||
721 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | ||
722 | handle->idp = GNUNET_RECLAIM_connect (cfg); | ||
723 | handle->attr_it = GNUNET_RECLAIM_get_attributes_start (handle->idp, | ||
724 | priv_key, | ||
725 | &collect_error_cb, | ||
726 | handle, | ||
727 | &ref_collect, | ||
728 | handle, | ||
729 | &collect_finished_cb, | ||
730 | handle); | ||
731 | } | ||
632 | 732 | ||
633 | /** | 733 | /** |
634 | * Collect all attestations for an ego | 734 | * Collect all attestations for an ego |
@@ -691,8 +791,21 @@ list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
691 | const char *url, | 791 | const char *url, |
692 | void *cls) | 792 | void *cls) |
693 | { | 793 | { |
694 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | ||
695 | struct RequestHandle *handle = cls; | 794 | struct RequestHandle *handle = cls; |
795 | /* Check for substring "reference" */ | ||
796 | if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) < strlen ( | ||
797 | handle->url)) | ||
798 | { | ||
799 | if ( strncmp ("reference/", (handle->url + strlen ( | ||
800 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) | ||
801 | + 1), strlen ( | ||
802 | "reference/")) == 0) | ||
803 | { | ||
804 | list_reference_cont (con_handle,url,cls); | ||
805 | return; | ||
806 | } | ||
807 | } | ||
808 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | ||
696 | struct EgoEntry *ego_entry; | 809 | struct EgoEntry *ego_entry; |
697 | char *identity; | 810 | char *identity; |
698 | 811 | ||
@@ -1063,6 +1176,7 @@ attr_collect (void *cls, | |||
1063 | 1176 | ||
1064 | if ((NULL == attr)&& (NULL == reference)) | 1177 | if ((NULL == attr)&& (NULL == reference)) |
1065 | { | 1178 | { |
1179 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute Collection with empty Attribute/Reference\n"); | ||
1066 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); | 1180 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); |
1067 | return; | 1181 | return; |
1068 | } | 1182 | } |
@@ -1072,19 +1186,19 @@ attr_collect (void *cls, | |||
1072 | 1186 | ||
1073 | if ((NULL == reference->name) || (NULL == reference->reference_value)) | 1187 | if ((NULL == reference->name) || (NULL == reference->reference_value)) |
1074 | { | 1188 | { |
1189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute Collection with empty Reference Name/Value\n"); | ||
1075 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); | 1190 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); |
1076 | return; | 1191 | return; |
1077 | } | 1192 | } |
1078 | 1193 | ||
1079 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding reference as attribute: %s\n", | 1194 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding reference as attribute: %s\n", |
1080 | reference->name); | 1195 | reference->name); |
1081 | |||
1082 | |||
1083 | attr_obj = json_object (); | 1196 | attr_obj = json_object (); |
1084 | json_object_set_new (attr_obj, "name", json_string (reference->name)); | 1197 | json_object_set_new (attr_obj, "name", json_string (reference->name)); |
1085 | json_object_set_new (attr_obj, "value", json_string ( | 1198 | json_object_set_new (attr_obj, "value", json_string ( |
1086 | reference->reference_value)); | 1199 | reference->reference_value)); |
1087 | id_str = GNUNET_STRINGS_data_to_string_alloc (&reference->id, sizeof(uint64_t)); | 1200 | id_str = GNUNET_STRINGS_data_to_string_alloc (&reference->id, |
1201 | sizeof(uint64_t)); | ||
1088 | json_object_set_new (attr_obj, "id", json_string (id_str)); | 1202 | json_object_set_new (attr_obj, "id", json_string (id_str)); |
1089 | char *flag; | 1203 | char *flag; |
1090 | flag = "1"; | 1204 | flag = "1"; |
@@ -1100,6 +1214,7 @@ attr_collect (void *cls, | |||
1100 | { | 1214 | { |
1101 | if ((NULL == attr->name) || (NULL == attr->data)) | 1215 | if ((NULL == attr->name) || (NULL == attr->data)) |
1102 | { | 1216 | { |
1217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute Collection with empty Attribute Name/Value\n"); | ||
1103 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); | 1218 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); |
1104 | return; | 1219 | return; |
1105 | } | 1220 | } |