summaryrefslogtreecommitdiff
path: root/src/reclaim
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2019-04-14 16:40:11 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-04-14 16:40:11 +0200
commit79f1546aa9ad2eeead24324000130caeb26b0262 (patch)
tree5e32cdd17b0ca6067c0d73ece7dbc9989e370811 /src/reclaim
parent1eea290a7aaa845db727773bc7e9f2a0fdc5bebd (diff)
RECLAIM/REST: add attribute delete REST call
Diffstat (limited to 'src/reclaim')
-rw-r--r--src/reclaim/gnunet-service-reclaim.c4
-rw-r--r--src/reclaim/plugin_rest_reclaim.c77
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)
struct AttributeDeleteHandle *adh = cls;
adh->ns_qe = NULL;
if (GNUNET_SYSERR == success) {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error deleting attribute %s (%s)\n",
- adh->claim->name, adh->label);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error deleting attribute %s\n",
+ adh->label);
send_delete_response (adh, GNUNET_SYSERR);
cleanup_adh (adh);
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,
static void
+delete_finished_cb (void *cls, int32_t success, const char *emsg)
+{
+ struct RequestHandle *handle = cls;
+ struct MHD_Response *resp;
+
+ resp = GNUNET_REST_create_response (emsg);
+ if (GNUNET_OK != success) {
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+ return;
+ }
+ handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
+ GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
+}
+
+
+/**
+ * List attributes for identity request
+ *
+ * @param con_handle the connection handle
+ * @param url the url
+ * @param cls the RequestHandle
+ */
+static void
+delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
+ const char *url, void *cls)
+{
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
+ struct RequestHandle *handle = cls;
+ struct GNUNET_RECLAIM_ATTRIBUTE_Claim attr;
+ struct EgoEntry *ego_entry;
+ char *identity_id_str;
+ char *identity;
+ char *id;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting attributes.\n");
+ if (strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) >= strlen (handle->url)) {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n");
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+ return;
+ }
+ identity_id_str =
+ strdup (handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1);
+ identity = strtok (identity_id_str, "/");
+ id = strtok (NULL, "/");
+ if ((NULL == identity) || (NULL == id)) {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed request.\n");
+ GNUNET_free (identity_id_str);
+ GNUNET_SCHEDULER_add_now (&do_error, handle);
+ return;
+ }
+
+ for (ego_entry = handle->ego_head; NULL != ego_entry;
+ ego_entry = ego_entry->next)
+ if (0 == strcmp (identity, ego_entry->identifier))
+ break;
+ handle->resp_object = json_array ();
+ if (NULL == ego_entry) {
+ // Done
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", identity);
+ GNUNET_free (identity_id_str);
+ GNUNET_SCHEDULER_add_now (&return_response, handle);
+ return;
+ }
+ priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
+ handle->idp = GNUNET_RECLAIM_connect (cfg);
+ memset (&attr, 0, sizeof (struct GNUNET_RECLAIM_ATTRIBUTE_Claim));
+ GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof (uint64_t));
+ attr.name = "";
+ handle->idp_op = GNUNET_RECLAIM_attribute_delete (
+ handle->idp, priv_key, &attr, &delete_finished_cb, handle);
+ GNUNET_free (identity_id_str);
+}
+
+
+static void
revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
const char *url, void *cls)
{
@@ -815,6 +890,8 @@ init_cont (struct RequestHandle *handle)
&list_attribute_cont},
{MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
&add_attribute_cont},
+ {MHD_HTTP_METHOD_DELETE, GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
+ &delete_attribute_cont},
{MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TICKETS,
&list_tickets_cont},
{MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_REVOKE,