diff options
author | Markus Voggenreiter <Markus.Voggenreiter@tum.de> | 2019-10-19 11:30:24 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-01-13 13:31:02 +0100 |
commit | 4eda8d33675ba1e004792635b33342c04c5cbe32 (patch) | |
tree | 93eab84b3b93dace71ec4f31988991abcd692a2d /src/reclaim/plugin_rest_reclaim.c | |
parent | 483bc7e3095dff908fe8c032ea96995d44304868 (diff) | |
download | gnunet-4eda8d33675ba1e004792635b33342c04c5cbe32.tar.gz gnunet-4eda8d33675ba1e004792635b33342c04c5cbe32.zip |
Listing Attestations through service
Diffstat (limited to 'src/reclaim/plugin_rest_reclaim.c')
-rw-r--r-- | src/reclaim/plugin_rest_reclaim.c | 111 |
1 files changed, 106 insertions, 5 deletions
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index 5e586152c..5908a38dd 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c | |||
@@ -535,15 +535,110 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
535 | handle); | 535 | handle); |
536 | GNUNET_JSON_parse_free (attrspec); | 536 | GNUNET_JSON_parse_free (attrspec); |
537 | } | 537 | } |
538 | /*Placeholder*/ | 538 | |
539 | |||
540 | /** | ||
541 | * Collect all attestations for an ego | ||
542 | * | ||
543 | */ | ||
544 | static void | ||
545 | attest_collect (void *cls, | ||
546 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | ||
547 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, | ||
548 | const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest) | ||
549 | { | ||
550 | struct RequestHandle *handle = cls; | ||
551 | json_t *attr_obj; | ||
552 | const char *type; | ||
553 | char *tmp_value; | ||
554 | char *id_str; | ||
555 | |||
556 | if (NULL == attest) | ||
557 | { | ||
558 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); | ||
559 | return; | ||
560 | } | ||
561 | |||
562 | if ((NULL == attest->name) || (NULL == attest->data)) | ||
563 | { | ||
564 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); | ||
565 | return; | ||
566 | } | ||
567 | |||
568 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attestation: %s\n", | ||
569 | attest->name); | ||
570 | |||
571 | tmp_value = GNUNET_RECLAIM_ATTESTATION_value_to_string (attest->type, | ||
572 | attest->data, | ||
573 | attest->data_size); | ||
574 | attr_obj = json_object (); | ||
575 | json_object_set_new (attr_obj, "value", json_string (tmp_value)); | ||
576 | json_object_set_new (attr_obj, "name", json_string (attest->name)); | ||
577 | type = GNUNET_RECLAIM_ATTESTATION_number_to_typename (attest->type); | ||
578 | json_object_set_new (attr_obj, "type", json_string (type)); | ||
579 | id_str = GNUNET_STRINGS_data_to_string_alloc (&attest->id, sizeof(uint64_t)); | ||
580 | json_object_set_new (attr_obj, "id", json_string (id_str)); | ||
581 | json_array_append (handle->resp_object, attr_obj); | ||
582 | json_decref (attr_obj); | ||
583 | GNUNET_free (tmp_value); | ||
584 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); | ||
585 | } | ||
586 | |||
587 | |||
588 | /** | ||
589 | * Lists attestation for identity request | ||
590 | * | ||
591 | * @param con_handle the connection handle | ||
592 | * @param url the url | ||
593 | * @param cls the RequestHandle | ||
594 | */ | ||
539 | static void | 595 | static void |
540 | list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, | 596 | list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle, |
541 | const char *url, | 597 | const char *url, |
542 | void *cls) | 598 | void *cls) |
543 | { | 599 | { |
544 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Listing Attestations not supported\n"); | 600 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; |
545 | GNUNET_SCHEDULER_add_now (&do_error, cls); | 601 | struct RequestHandle *handle = cls; |
546 | return; | 602 | struct EgoEntry *ego_entry; |
603 | char *identity; | ||
604 | |||
605 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
606 | "Getting attestations for %s.\n", | ||
607 | handle->url); | ||
608 | if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) >= strlen ( | ||
609 | handle->url)) | ||
610 | { | ||
611 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); | ||
612 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
613 | return; | ||
614 | } | ||
615 | identity = handle->url + strlen ( | ||
616 | GNUNET_REST_API_NS_RECLAIM_ATTESTATION_REFERENCE) + 1; | ||
617 | |||
618 | for (ego_entry = handle->ego_head; NULL != ego_entry; | ||
619 | ego_entry = ego_entry->next) | ||
620 | if (0 == strcmp (identity, ego_entry->identifier)) | ||
621 | break; | ||
622 | handle->resp_object = json_array (); | ||
623 | |||
624 | |||
625 | if (NULL == ego_entry) | ||
626 | { | ||
627 | // Done | ||
628 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity); | ||
629 | GNUNET_SCHEDULER_add_now (&return_response, handle); | ||
630 | return; | ||
631 | } | ||
632 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | ||
633 | handle->idp = GNUNET_RECLAIM_connect (cfg); | ||
634 | handle->attr_it = GNUNET_RECLAIM_get_attributes_start (handle->idp, | ||
635 | priv_key, | ||
636 | &collect_error_cb, | ||
637 | handle, | ||
638 | &attest_collect, | ||
639 | handle, | ||
640 | &collect_finished_cb, | ||
641 | handle); | ||
547 | } | 642 | } |
548 | 643 | ||
549 | /** | 644 | /** |
@@ -764,6 +859,12 @@ attr_collect (void *cls, | |||
764 | char *tmp_value; | 859 | char *tmp_value; |
765 | char *id_str; | 860 | char *id_str; |
766 | 861 | ||
862 | if (NULL == attr) | ||
863 | { | ||
864 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); | ||
865 | return; | ||
866 | } | ||
867 | |||
767 | if ((NULL == attr->name) || (NULL == attr->data)) | 868 | if ((NULL == attr->name) || (NULL == attr->data)) |
768 | { | 869 | { |
769 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); | 870 | GNUNET_RECLAIM_get_attributes_next (handle->attr_it); |
@@ -988,7 +1089,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
988 | static void | 1089 | static void |
989 | consume_cont (void *cls, | 1090 | consume_cont (void *cls, |
990 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | 1091 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, |
991 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, | 1092 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, |
992 | const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest) | 1093 | const struct GNUNET_RECLAIM_ATTESTATION_Claim *attest) |
993 | { | 1094 | { |
994 | struct RequestHandle *handle = cls; | 1095 | struct RequestHandle *handle = cls; |