tolerate additional IPv4 address now available for gnunet.org
[oweals/gnunet.git] / src / reclaim / gnunet-reclaim.c
index 0e5591d69fb37151783ec97444ed6fbdec44dec5..a9d6f67d2ba40694eb94f31a5efaffacaa1a1834 100644 (file)
@@ -157,7 +157,18 @@ static struct GNUNET_SCHEDULER_Task *cleanup_task;
  */
 struct GNUNET_RECLAIM_ATTRIBUTE_Claim *claim;
 
-static void do_cleanup (void *cls)
+/**
+ * Claim to delete
+ */
+static char *attr_delete;
+
+/**
+ * Claim object to delete
+ */
+static struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr_to_delete;
+
+static void
+do_cleanup (void *cls)
 {
   cleanup_task = NULL;
   if (NULL != timeout)
@@ -176,10 +187,12 @@ static void do_cleanup (void *cls)
     GNUNET_free (abe_key);
   if (NULL != attr_list)
     GNUNET_free (attr_list);
+  if (NULL != attr_to_delete)
+    GNUNET_free (attr_to_delete);
 }
 
-static void ticket_issue_cb (void *cls,
-                             const struct GNUNET_RECLAIM_Ticket *ticket)
+static void
+ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
 {
   char *ticket_str;
   reclaim_op = NULL;
@@ -192,7 +205,8 @@ static void ticket_issue_cb (void *cls,
   cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
 }
 
-static void store_attr_cont (void *cls, int32_t success, const char *emsg)
+static void
+store_attr_cont (void *cls, int32_t success, const char *emsg)
 {
   reclaim_op = NULL;
   if (GNUNET_SYSERR == success) {
@@ -201,11 +215,12 @@ static void store_attr_cont (void *cls, int32_t success, const char *emsg)
   cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
 }
 
-static void process_attrs (void *cls,
-                           const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
-                           const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
+static void
+process_attrs (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
+               const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
 {
   char *value_str;
+  char *id;
   const char *attr_type;
 
   if (NULL == identity) {
@@ -220,37 +235,51 @@ static void process_attrs (void *cls,
   value_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, attr->data,
                                                         attr->data_size);
   attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type);
-  fprintf (stdout, "%s: %s [%s,v%u,id=%" PRIu64 "]\n", attr->name, value_str,
-           attr_type, attr->version, attr->id);
+  id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof (uint64_t));
+  fprintf (stdout, "Name: %s; Value: %s (%s); Version %u; ID: %s\n", attr->name,
+           value_str, attr_type, attr->version, id);
+  GNUNET_free (id);
 }
 
-static void ticket_iter_err (void *cls)
+static void
+ticket_iter_err (void *cls)
 {
   ticket_iterator = NULL;
   fprintf (stderr, "Failed to iterate over tickets\n");
   cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
 }
 
-static void ticket_iter_fin (void *cls)
+static void
+ticket_iter_fin (void *cls)
 {
   ticket_iterator = NULL;
   cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
 }
 
-static void ticket_iter (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
+static void
+ticket_iter (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
 {
-  fprintf (stdout, "Found ticket\n");
+  char *aud;
+  char *ref;
+
+  aud = GNUNET_STRINGS_data_to_string_alloc (
+      &ticket->audience, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
+  ref = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t));
+
+  fprintf (stdout, "Ticket ID: %s | Audience: %s\n", ref, aud);
   GNUNET_RECLAIM_ticket_iteration_next (ticket_iterator);
 }
 
-static void iter_error (void *cls)
+static void
+iter_error (void *cls)
 {
   attr_iterator = NULL;
   fprintf (stderr, "Failed to iterate over attributes\n");
   cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
 }
 
-static void timeout_task (void *cls)
+static void
+timeout_task (void *cls)
 {
   timeout = NULL;
   ret = 1;
@@ -259,7 +288,8 @@ static void timeout_task (void *cls)
     cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
 }
 
-static void process_rvk (void *cls, int success, const char *msg)
+static void
+process_rvk (void *cls, int success, const char *msg)
 {
   reclaim_op = NULL;
   if (GNUNET_OK != success) {
@@ -269,7 +299,21 @@ static void process_rvk (void *cls, int success, const char *msg)
   cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
 }
 
-static void iter_finished (void *cls)
+
+static void
+process_delete (void *cls, int success, const char *msg)
+{
+  reclaim_op = NULL;
+  if (GNUNET_OK != success) {
+    fprintf (stderr, "Deletion failed.\n");
+    ret = 1;
+  }
+  cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
+}
+
+
+static void
+iter_finished (void *cls)
 {
   char *data;
   size_t data_size;
@@ -299,6 +343,15 @@ static void iter_finished (void *cls)
                                                &process_rvk, NULL);
     return;
   }
+  if (attr_delete) {
+    if (NULL == attr_to_delete) {
+      fprintf (stdout, "No such attribute ``%s''\n", attr_delete);
+      return;
+    }
+    reclaim_op = GNUNET_RECLAIM_attribute_delete (
+        reclaim_handle, pkey, attr_to_delete, &process_delete, NULL);
+    return;
+  }
   if (attr_name) {
     if (NULL == type_str)
       type = GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING;
@@ -325,13 +378,15 @@ static void iter_finished (void *cls)
   cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
 }
 
-static void iter_cb (void *cls,
-                     const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
-                     const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
+static void
+iter_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
+         const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr)
 {
   struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le;
   char *attrs_tmp;
   char *attr_str;
+  char *label;
+  char *id;
   const char *attr_type;
 
   if ((NULL != attr_name) && (NULL != claim)) {
@@ -357,17 +412,28 @@ static void iter_cb (void *cls,
       break;
     }
     GNUNET_free (attrs_tmp);
+  } else if (attr_delete && (NULL == attr_to_delete)) {
+    label = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof (uint64_t));
+    if (0 == strcasecmp (attr_delete, label)) {
+      attr_to_delete = GNUNET_RECLAIM_ATTRIBUTE_claim_new (
+          attr->name, attr->type, attr->data, attr->data_size);
+      attr_to_delete->id = attr->id;
+    }
+    GNUNET_free (label);
   } else if (list) {
     attr_str = GNUNET_RECLAIM_ATTRIBUTE_value_to_string (attr->type, attr->data,
                                                          attr->data_size);
     attr_type = GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (attr->type);
-    fprintf (stdout, "%s: %s [%s,v%u,id=%" PRIu64 "]\n", attr->name, attr_str,
-             attr_type, attr->version, attr->id);
+    id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof (uint64_t));
+    fprintf (stdout, "Name: %s; Value: %s (%s); Version %u; ID: %s\n",
+             attr->name, attr_str, attr_type, attr->version, id);
+    GNUNET_free (id);
   }
   GNUNET_RECLAIM_get_attributes_next (attr_iterator);
 }
 
-static void start_process ()
+static void
+start_process ()
 {
   if (NULL == pkey) {
     fprintf (stderr, "Ego %s not found\n", ego_name);
@@ -402,8 +468,9 @@ static void start_process ()
 
 static int init = GNUNET_YES;
 
-static void ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx,
-                    const char *name)
+static void
+ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx,
+        const char *name)
 {
   if (NULL == name) {
     if (GNUNET_YES == init) {
@@ -418,8 +485,9 @@ static void ego_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx,
 }
 
 
-static void run (void *cls, char *const *args, const char *cfgfile,
-                 const struct GNUNET_CONFIGURATION_Handle *c)
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *c)
 {
   ret = 0;
   if (NULL == ego_name) {
@@ -446,7 +514,8 @@ static void run (void *cls, char *const *args, const char *cfgfile,
 }
 
 
-int main (int argc, char *const argv[])
+int
+main (int argc, char *const argv[])
 {
   exp_interval = GNUNET_TIME_UNIT_HOURS;
   struct GNUNET_GETOPT_CommandLineOption options[] = {
@@ -454,7 +523,9 @@ int main (int argc, char *const argv[])
       GNUNET_GETOPT_option_string ('a', "add", "NAME",
                                    gettext_noop ("Add an attribute NAME"),
                                    &attr_name),
-
+      GNUNET_GETOPT_option_string ('d', "delete", "ID",
+                                   gettext_noop ("Add an attribute with ID"),
+                                   &attr_delete),
       GNUNET_GETOPT_option_string ('V', "value", "VALUE",
                                    gettext_noop ("The attribute VALUE"),
                                    &attr_value),