-more debug messages
[oweals/gnunet.git] / src / namestore / gnunet-namestore.c
index 1eec9cfdcf165feda71e2eedd3cf69dc52cb1cac..a79178abab261bc137645b6a130ae9b90c1f614d 100644 (file)
@@ -25,7 +25,6 @@
  * TODO:
  * - allow users to set record options (not just 'RF_AUTHORITY')
  * - test
- * - parsing SOA, PTR and MX value specifications (and define format!)
  * - add options to list/lookup individual records
  */
 #include "platform.h"
@@ -33,6 +32,7 @@
 #include <gnunet_dnsparser_lib.h>
 #include <gnunet_namestore_service.h>
 
+
 /**
  * Handle to the namestore.
  */
@@ -126,7 +126,7 @@ do_shutdown (void *cls,
 {
   if (NULL != ns)
   {
-    GNUNET_NAMESTORE_disconnect (ns, GNUNET_NO);
+    GNUNET_NAMESTORE_disconnect (ns);
     ns = NULL;
   }
   if (NULL != zone_pkey)
@@ -265,7 +265,9 @@ run (void *cls, char *const *args, const char *cfgfile,
   uint32_t type;
   void *data = NULL;
   size_t data_size = 0;
-  struct GNUNET_TIME_Relative etime;
+  struct GNUNET_TIME_Relative etime_rel;
+  struct GNUNET_TIME_Absolute etime_abs;
+  int etime_is_rel = GNUNET_SYSERR;
   struct GNUNET_NAMESTORE_RecordData rd;
 
   if (NULL == keyfile)
@@ -355,9 +357,24 @@ run (void *cls, char *const *args, const char *cfgfile,
   }
   if (NULL != expirationstring)
   {
-    if (GNUNET_OK !=
-       GNUNET_STRINGS_fancy_time_to_relative (expirationstring,
-                                              &etime))
+    if (0 == strcmp (expirationstring, "never"))
+    {
+      etime_abs = GNUNET_TIME_UNIT_FOREVER_ABS;
+      etime_is_rel = GNUNET_NO;
+    }
+    else if (GNUNET_OK ==
+            GNUNET_STRINGS_fancy_time_to_relative (expirationstring,
+                                                   &etime_rel))
+    {
+      etime_is_rel = GNUNET_YES;
+    }
+    else if (GNUNET_OK == 
+            GNUNET_STRINGS_fancy_time_to_absolute (expirationstring,
+                                                   &etime_abs))
+    {
+      etime_is_rel = GNUNET_NO;
+    }
+    else
     {
       fprintf (stderr,
               _("Invalid time format `%s'\n"),
@@ -365,7 +382,8 @@ run (void *cls, char *const *args, const char *cfgfile,
       GNUNET_SCHEDULER_shutdown ();
       return;     
     }
-  } else if (add)
+  } 
+  else if (add)
   {
     fprintf (stderr,
             _("Missing option `%s' for operation `%s'\n"),
@@ -386,7 +404,21 @@ run (void *cls, char *const *args, const char *cfgfile,
     rd.data = data;
     rd.data_size = data_size;
     rd.record_type = type;
-    rd.expiration = GNUNET_TIME_relative_to_absolute (etime);
+    if (GNUNET_YES == etime_is_rel)
+    {
+      rd.expiration_time = etime_rel.rel_value;
+      rd.flags |= GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION;
+    }
+    else if (GNUNET_NO == etime_is_rel)
+      rd.expiration_time = etime_abs.abs_value;
+    else
+    {
+      fprintf (stderr,
+              _("No valid expiration time for operation `%s'\n"),
+              _("add"));
+      GNUNET_SCHEDULER_shutdown ();
+      return;
+    }
     if (1 != nonauthority)
       rd.flags |= GNUNET_NAMESTORE_RF_AUTHORITY;
     if (1 != public)
@@ -411,7 +443,7 @@ run (void *cls, char *const *args, const char *cfgfile,
     rd.data = data;
     rd.data_size = data_size;
     rd.record_type = type;
-    rd.expiration.abs_value = 0;
+    rd.expiration_time = 0;
     rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
     del_qe = GNUNET_NAMESTORE_record_remove (ns,
                                             zone_pkey,
@@ -465,7 +497,7 @@ main (int argc, char *const *argv)
      gettext_noop ("display records"), 0,
      &GNUNET_GETOPT_set_one, &list},   
     {'e', "expiration", "TIME",
-     gettext_noop ("expiration time for record to use (for adding only)"), 1,
+     gettext_noop ("expiration time for record to use (for adding only), \"never\" is possible"), 1,
      &GNUNET_GETOPT_set_string, &expirationstring},   
     {'n', "name", "NAME",
      gettext_noop ("name of the record to add/delete/display"), 1,
@@ -490,6 +522,9 @@ main (int argc, char *const *argv)
 
   int ret;
 
+  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+    return 2;
+
   GNUNET_log_setup ("gnunet-namestore", "WARNING", NULL);
   ret =
       (GNUNET_OK ==