diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-14 16:40:11 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-04-14 16:40:11 +0200 |
commit | 79f1546aa9ad2eeead24324000130caeb26b0262 (patch) | |
tree | 5e32cdd17b0ca6067c0d73ece7dbc9989e370811 /src/reclaim | |
parent | 1eea290a7aaa845db727773bc7e9f2a0fdc5bebd (diff) | |
download | gnunet-79f1546aa9ad2eeead24324000130caeb26b0262.tar.gz gnunet-79f1546aa9ad2eeead24324000130caeb26b0262.zip |
RECLAIM/REST: add attribute delete REST call
Diffstat (limited to 'src/reclaim')
-rw-r--r-- | src/reclaim/gnunet-service-reclaim.c | 4 | ||||
-rw-r--r-- | src/reclaim/plugin_rest_reclaim.c | 77 |
2 files changed, 79 insertions, 2 deletions
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index 5deb482e9..a49962b4d 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c | |||
@@ -997,8 +997,8 @@ attr_delete_cont (void *cls, int32_t success, const char *emsg) | |||
997 | struct AttributeDeleteHandle *adh = cls; | 997 | struct AttributeDeleteHandle *adh = cls; |
998 | adh->ns_qe = NULL; | 998 | adh->ns_qe = NULL; |
999 | if (GNUNET_SYSERR == success) { | 999 | if (GNUNET_SYSERR == success) { |
1000 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error deleting attribute %s (%s)\n", | 1000 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error deleting attribute %s\n", |
1001 | adh->claim->name, adh->label); | 1001 | adh->label); |
1002 | send_delete_response (adh, GNUNET_SYSERR); | 1002 | send_delete_response (adh, GNUNET_SYSERR); |
1003 | cleanup_adh (adh); | 1003 | cleanup_adh (adh); |
1004 | return; | 1004 | return; |
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c index ae46211d5..74071d97b 100644 --- a/src/reclaim/plugin_rest_reclaim.c +++ b/src/reclaim/plugin_rest_reclaim.c | |||
@@ -634,6 +634,81 @@ list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
634 | 634 | ||
635 | 635 | ||
636 | static void | 636 | static void |
637 | delete_finished_cb (void *cls, int32_t success, const char *emsg) | ||
638 | { | ||
639 | struct RequestHandle *handle = cls; | ||
640 | struct MHD_Response *resp; | ||
641 | |||
642 | resp = GNUNET_REST_create_response (emsg); | ||
643 | if (GNUNET_OK != success) { | ||
644 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
645 | return; | ||
646 | } | ||
647 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | ||
648 | GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle); | ||
649 | } | ||
650 | |||
651 | |||
652 | /** | ||
653 | * List attributes for identity request | ||
654 | * | ||
655 | * @param con_handle the connection handle | ||
656 | * @param url the url | ||
657 | * @param cls the RequestHandle | ||
658 | */ | ||
659 | static void | ||
660 | delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | ||
661 | const char *url, void *cls) | ||
662 | { | ||
663 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | ||
664 | struct RequestHandle *handle = cls; | ||
665 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim attr; | ||
666 | struct EgoEntry *ego_entry; | ||
667 | char *identity_id_str; | ||
668 | char *identity; | ||
669 | char *id; | ||
670 | |||
671 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting attributes.\n"); | ||
672 | if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url)) { | ||
673 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); | ||
674 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
675 | return; | ||
676 | } | ||
677 | identity_id_str = | ||
678 | strdup (handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1); | ||
679 | identity = strtok (identity_id_str, "/"); | ||
680 | id = strtok (NULL, "/"); | ||
681 | if ((NULL == identity) || (NULL == id)) { | ||
682 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed request.\n"); | ||
683 | GNUNET_free (identity_id_str); | ||
684 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
685 | return; | ||
686 | } | ||
687 | |||
688 | for (ego_entry = handle->ego_head; NULL != ego_entry; | ||
689 | ego_entry = ego_entry->next) | ||
690 | if (0 == strcmp (identity, ego_entry->identifier)) | ||
691 | break; | ||
692 | handle->resp_object = json_array (); | ||
693 | if (NULL == ego_entry) { | ||
694 | // Done | ||
695 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity); | ||
696 | GNUNET_free (identity_id_str); | ||
697 | GNUNET_SCHEDULER_add_now (&return_response, handle); | ||
698 | return; | ||
699 | } | ||
700 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | ||
701 | handle->idp = GNUNET_RECLAIM_connect (cfg); | ||
702 | memset (&attr, 0, sizeof (struct GNUNET_RECLAIM_ATTRIBUTE_Claim)); | ||
703 | GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof (uint64_t)); | ||
704 | attr.name = ""; | ||
705 | handle->idp_op = GNUNET_RECLAIM_attribute_delete ( | ||
706 | handle->idp, priv_key, &attr, &delete_finished_cb, handle); | ||
707 | GNUNET_free (identity_id_str); | ||
708 | } | ||
709 | |||
710 | |||
711 | static void | ||
637 | revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, | 712 | revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle, |
638 | const char *url, void *cls) | 713 | const char *url, void *cls) |
639 | { | 714 | { |
@@ -815,6 +890,8 @@ init_cont (struct RequestHandle *handle) | |||
815 | &list_attribute_cont}, | 890 | &list_attribute_cont}, |
816 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, | 891 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, |
817 | &add_attribute_cont}, | 892 | &add_attribute_cont}, |
893 | {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, | ||
894 | &delete_attribute_cont}, | ||
818 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TICKETS, | 895 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TICKETS, |
819 | &list_tickets_cont}, | 896 | &list_tickets_cont}, |
820 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_REVOKE, | 897 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_REVOKE, |