-fix
[oweals/gnunet.git] / src / namestore / gnunet-namestore.c
index 9829eaaa41d3c13bd934887a9e3da6fb8eeced83..eb77913cc50a1f4c953427b4282f88ace6bad637 100644 (file)
@@ -23,7 +23,6 @@
  * @author Christian Grothoff
  *
  * TODO:
- * - printing records
  * - allow users to set record options (not just 'RF_AUTHORITY')
  * - test
  * - parsing SOA, PTR and MX value specifications (and define format!)
@@ -42,7 +41,7 @@ static struct GNUNET_NAMESTORE_Handle *ns;
 /**
  * Hash of the public key of our zone.
  */
-static GNUNET_HashCode zone;
+static struct GNUNET_CRYPTO_ShortHashCode zone;
 
 /**
  * Private key for the our zone.
@@ -104,10 +103,6 @@ static char *typestring;
  */
 static char *expirationstring;
 
-/**
- * Desired block expiration time.
- */
-static char *blockexpirationstring;
 
 /**
  * Task run on shutdown.  Cleans up everything.
@@ -261,15 +256,21 @@ run (void *cls, char *const *args, const char *cfgfile,
   void *data = NULL;
   size_t data_size = 0;
   struct GNUNET_TIME_Relative etime;
-  struct GNUNET_TIME_Relative btime;
   struct GNUNET_NAMESTORE_RecordData rd;
 
   if (NULL == keyfile)
   {
-    fprintf (stderr,
-            _("Option `%s' not given, but I need a zone key file!\n"),
-            "z");
-    return;
+      if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
+                                                 "ZONEKEY", &keyfile))
+      {
+        fprintf (stderr,
+                 _("Option `%s' not given, but I need a zone key file!\n"),
+                 "z");
+        return;
+      }
+      fprintf (stderr,
+               _("Using default zone file `%s'\n"),
+               keyfile);
   }
   zone_pkey = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
   GNUNET_free (keyfile);
@@ -277,6 +278,8 @@ run (void *cls, char *const *args, const char *cfgfile,
   if (! (add|del|list))
   {
     /* nothing more to be done */  
+    fprintf (stderr,
+             _("No options given\n"));
     GNUNET_CRYPTO_rsa_key_free (zone_pkey);
     zone_pkey = NULL;
     return; 
@@ -289,7 +292,7 @@ run (void *cls, char *const *args, const char *cfgfile,
   }
   GNUNET_CRYPTO_rsa_key_get_public (zone_pkey,
                                    &pub);
-  GNUNET_CRYPTO_hash (&pub, sizeof (pub), &zone);
+  GNUNET_CRYPTO_short_hash (&pub, sizeof (pub), &zone);
 
   ns = GNUNET_NAMESTORE_connect (cfg);
   if (NULL == ns)
@@ -309,7 +312,8 @@ run (void *cls, char *const *args, const char *cfgfile,
     fprintf (stderr, _("Unsupported type `%s'\n"), typestring);
     GNUNET_SCHEDULER_shutdown ();
     return;
-  } else if (add | del)
+  }
+  if ((NULL == typestring) && (add | del))
   {
     fprintf (stderr,
             _("Missing option `%s' for operation `%s'\n"),
@@ -359,27 +363,6 @@ run (void *cls, char *const *args, const char *cfgfile,
     GNUNET_SCHEDULER_shutdown ();
     return;     
   }
-  if (NULL != blockexpirationstring)
-  {
-    if (GNUNET_OK !=
-        GNUNET_STRINGS_fancy_time_to_relative (blockexpirationstring,
-                                               &btime))
-    {
-      fprintf (stderr,
-               _("Invalid time format `%s'\n"),
-               blockexpirationstring);
-      GNUNET_SCHEDULER_shutdown ();
-      return;
-    }
-  } else if (add | del)
-  {
-    fprintf (stderr,
-             _("Missing option `%s' for operation `%s'\n"),
-             "-b", _("add/del"));
-    GNUNET_SCHEDULER_shutdown ();
-    return;
-  }
-
   if (add)
   {
     if (NULL == name)
@@ -397,7 +380,6 @@ run (void *cls, char *const *args, const char *cfgfile,
     rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY; // FIXME: not always...
     add_qe = GNUNET_NAMESTORE_record_create (ns,
                                             zone_pkey,
-                                             GNUNET_TIME_relative_to_absolute (btime),
                                             name,
                                             &rd,
                                             &add_continuation,
@@ -451,9 +433,6 @@ main (int argc, char *const *argv)
     {'a', "add", NULL,
      gettext_noop ("add record"), 0,
      &GNUNET_GETOPT_set_one, &add},
-    {'b', "name-expiration", "TIME",
-     gettext_noop ("expiration time for name to use (for adding only)"), 1,
-     &GNUNET_GETOPT_set_string, &blockexpirationstring},
     {'d', "delete", NULL,
      gettext_noop ("delete record"), 0,
      &GNUNET_GETOPT_set_one, &del},