- Tests did not clean up: TEST_HOME with namestore db was not removed after test
[oweals/gnunet.git] / src / namestore / gnunet-namestore.c
index 205e65f8231b005b8ae675107127de4c657f6f56..5de86182f69365074ba845bdebe60dabcd4fff79 100644 (file)
@@ -31,6 +31,7 @@
 #include <gnunet_dnsparser_lib.h>
 #include <gnunet_identity_service.h>
 #include <gnunet_gnsrecord_lib.h>
+#include <gnunet_gns_service.h>
 #include <gnunet_namestore_service.h>
 
 
@@ -134,6 +135,11 @@ static char *typestring;
  */
 static char *expirationstring;
 
+/**
+ * Desired nick name.
+ */
+static char *nickstring;
+
 /**
  * Global return value
  */
@@ -300,10 +306,20 @@ del_continuation (void *cls,
                  const char *emsg)
 {
   del_qe = NULL;
-  if (success != GNUNET_YES)
+  if (GNUNET_NO == success)
+  {
     fprintf (stderr,
-            _("Deleting record failed: %s\n"),
-            emsg);
+            _("Deleting record failed, record does not exist%s%s\n"),
+            (NULL != emsg) ? ": " : "",
+            (NULL != emsg) ? emsg : "");
+  }
+  if (GNUNET_SYSERR == success)
+  {
+    fprintf (stderr,
+             _("Deleting record failed%s%s\n"),
+             (NULL != emsg) ? ": " : "",
+             (NULL != emsg) ? emsg : "");
+  }
   test_finished ();
 }
 
@@ -369,10 +385,13 @@ display_record (void *cls,
       ets = GNUNET_STRINGS_absolute_time_to_string (at);
     }
     FPRINTF (stdout,
-            "\t%s: %s (%s)\n",
+            "\t%s: %s (%s)\t%s\t%s\t%s\n",
             typestring,
             s,
-             ets);
+             ets,
+             (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE)) ? "PRIVATE" : "PUBLIC",
+             (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) ? "SHADOW" : "",
+             (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_PENDING)) ? "PENDING" : "");
     GNUNET_free (s);
   }
   FPRINTF (stdout, "%s", "\n");
@@ -432,7 +451,7 @@ get_existing_record (void *cls,
   rde->data = data;
   rde->data_size = data_size;
   rde->record_type = type;
-  if (1 != shadow)
+  if (1 == shadow)
     rde->flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD;
   if (1 != public)
     rde->flags |= GNUNET_GNSRECORD_RF_PRIVATE;
@@ -508,7 +527,7 @@ testservice_task (void *cls,
             "namestore");
     return;
   }
-  if (! (add|del|list|(NULL != uri)|(NULL != reverse_pkey)) )
+  if (! (add|del|list|(NULL != nickstring)|(NULL != uri)|(NULL != reverse_pkey)) )
   {
     /* nothing more to be done */
     fprintf (stderr,
@@ -692,6 +711,7 @@ testservice_task (void *cls,
       rd.expiration_time = etime_abs.abs_value_us;
     else
       rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
+
     if (1 != shadow)
       rd.flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD;
     add_qe_uri = GNUNET_NAMESTORE_records_store (ns,
@@ -702,6 +722,20 @@ testservice_task (void *cls,
                                                 &add_continuation,
                                                 &add_qe_uri);
   }
+  if (NULL != nickstring)
+  {
+    if (0 == strlen(nickstring))
+    {
+      fprintf (stderr,
+               _("Invalid nick `%s'\n"),
+               nickstring);
+      GNUNET_SCHEDULER_shutdown ();
+      ret = 1;
+      return;
+    }
+    add_qe_uri = GNUNET_NAMESTORE_set_nick(ns, &zone_pkey, nickstring,
+        &add_continuation, &add_qe_uri);
+  }
   if (monitor)
   {
     zm = GNUNET_NAMESTORE_zone_monitor_start (cfg,
@@ -764,6 +798,7 @@ run (void *cls, char *const *args, const char *cfgfile,
             _("You must specify which zone should be accessed\n"));
     return;
   }
+
   if ( (NULL != args[0]) && (NULL == uri) )
     uri = GNUNET_strdup (args[0]);
   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
@@ -786,6 +821,7 @@ int
 main (int argc, char *const *argv)
 {
   public = -1;
+  shadow = -1;
 
   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
     {'a', "add", NULL,
@@ -800,6 +836,9 @@ main (int argc, char *const *argv)
     {'e', "expiration", "TIME",
      gettext_noop ("expiration time for record to use (for adding only), \"never\" is possible"), 1,
      &GNUNET_GETOPT_set_string, &expirationstring},
+    {'i', "nick", "NICKNAME",
+     gettext_noop ("set the desired nick name for the zone"), 1,
+     &GNUNET_GETOPT_set_string, &nickstring},
     {'m', "monitor", NULL,
      gettext_noop ("monitor changes in the namestore"), 0,
      &GNUNET_GETOPT_set_one, &monitor},