use namestore API for zone import instead of using plugin directly
[oweals/gnunet.git] / src / identity-provider / gnunet-idp.c
index 995dd577529791cc497a13a75f068dab4cdb2cd6..4f17919b9597d4406b8535de615bbf044ea942fa 100644 (file)
@@ -126,9 +126,23 @@ static struct GNUNET_IDENTITY_PROVIDER_Ticket ticket;
  */
 static struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attr_list;
 
+/**
+ * Attribute expiration interval
+ */
+static struct GNUNET_TIME_Relative exp_interval;
+
+/**
+ * Timeout task
+ */
+static struct GNUNET_SCHEDULER_Task *timeout;
+
 static void
 do_cleanup(void *cls)
 {
+  if (NULL != timeout)
+    GNUNET_SCHEDULER_cancel (timeout);
+  if (NULL != idp_op)
+    GNUNET_IDENTITY_PROVIDER_cancel (idp_op);
   if (NULL != attr_iterator)
     GNUNET_IDENTITY_PROVIDER_get_attributes_stop (attr_iterator);
   if (NULL != idp_handle)
@@ -146,6 +160,7 @@ ticket_issue_cb (void* cls,
                  const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket)
 {
   char* ticket_str;
+  idp_op = NULL;
   if (NULL != ticket) {
     ticket_str = GNUNET_STRINGS_data_to_string_alloc (ticket,
                                                       sizeof (struct GNUNET_IDENTITY_PROVIDER_Ticket));
@@ -161,6 +176,7 @@ store_attr_cont (void *cls,
                  int32_t success,
                  const char*emsg)
 {
+  idp_op = NULL;
   if (GNUNET_SYSERR == success) {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "%s\n", emsg);
@@ -176,6 +192,7 @@ process_attrs (void *cls,
   char *value_str;
   if (NULL == identity)
   {
+    idp_op = NULL;
     GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
     return;
   }
@@ -201,9 +218,20 @@ iter_error (void *cls)
   GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
 }
 
+static void
+timeout_task (void *cls)
+{
+  timeout = NULL;
+  ret = 1;
+  GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+              "Timeout\n");
+  GNUNET_SCHEDULER_add_now (&do_cleanup, NULL);
+}
+
 static void
 process_rvk (void *cls, int success, const char* msg)
 {
+  idp_op = NULL;
   if (GNUNET_OK != success)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
@@ -245,6 +273,9 @@ iter_finished (void *cls)
                                                       &ticket,
                                                       &process_attrs,
                                                       NULL);
+    timeout = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10),
+                                            &timeout_task,
+                                            NULL);
     return;
   }
   if (revoke_ticket)
@@ -272,6 +303,7 @@ iter_finished (void *cls)
   idp_op = GNUNET_IDENTITY_PROVIDER_attribute_store (idp_handle,
                                                      pkey,
                                                      claim,
+                                                     &exp_interval,
                                                      &store_attr_cont,
                                                      NULL);
 
@@ -383,6 +415,7 @@ run (void *cls,
 int
 main(int argc, char *const argv[])
 {
+  exp_interval = GNUNET_TIME_UNIT_HOURS;
   struct GNUNET_GETOPT_CommandLineOption options[] = {
 
     GNUNET_GETOPT_option_string ('a',
@@ -430,9 +463,18 @@ main(int argc, char *const argv[])
                                  NULL,
                                  gettext_noop ("Type of attribute"),
                                  &type_str),
+    GNUNET_GETOPT_option_relative_time ('E',
+                                        "expiration",
+                                        NULL,
+                                        gettext_noop ("Expiration interval of the attribute"),
+                                        &exp_interval),
+
     GNUNET_GETOPT_OPTION_END
   };
-  return (GNUNET_OK == GNUNET_PROGRAM_run (argc, argv, "ct",
+  if (GNUNET_OK != GNUNET_PROGRAM_run (argc, argv, "ct",
                       "ct", options,
-                      &run, NULL));
+                      &run, NULL))
+    return 1;
+  else
+    return ret;
 }