-consistently use struct GNUNET_HashCode
[oweals/gnunet.git] / src / namestore / gnunet-namestore.c
index bd083470eef2afd42a84d2013f977afb6fae15da..62498120149cc872f576f1613f909fa538ad29e3 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"
@@ -41,7 +40,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.
@@ -78,6 +77,16 @@ static struct GNUNET_NAMESTORE_ZoneIterator *list_it;
  */
 static int del;
 
+/**
+ * Is record public
+ */
+static int public;
+
+/**
+ * Is record authority
+ */
+static int nonauthority;
+
 /**
  * Queue entry for the 'del' operation.
  */
@@ -292,7 +301,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)
@@ -345,7 +354,11 @@ run (void *cls, char *const *args, const char *cfgfile,
   }
   if (NULL != expirationstring)
   {
-    if (GNUNET_OK !=
+    if (0 == strcmp (expirationstring, "never"))
+    {
+      etime = GNUNET_TIME_UNIT_FOREVER_REL;
+    }
+    else if (GNUNET_OK !=
        GNUNET_STRINGS_fancy_time_to_relative (expirationstring,
                                               &etime))
     {
@@ -355,11 +368,11 @@ run (void *cls, char *const *args, const char *cfgfile,
       GNUNET_SCHEDULER_shutdown ();
       return;     
     }
-  } else if (add | del)
+  } else if (add)
   {
     fprintf (stderr,
             _("Missing option `%s' for operation `%s'\n"),
-            "-e", _("add/del"));
+            "-e", _("add"));
     GNUNET_SCHEDULER_shutdown ();
     return;     
   }
@@ -377,7 +390,10 @@ run (void *cls, char *const *args, const char *cfgfile,
     rd.data_size = data_size;
     rd.record_type = type;
     rd.expiration = GNUNET_TIME_relative_to_absolute (etime);
-    rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY; // FIXME: not always...
+    if (1 != nonauthority)
+      rd.flags |= GNUNET_NAMESTORE_RF_AUTHORITY;
+    if (1 != public)
+      rd.flags |= GNUNET_NAMESTORE_RF_PRIVATE;
     add_qe = GNUNET_NAMESTORE_record_create (ns,
                                             zone_pkey,
                                             name,
@@ -398,8 +414,8 @@ 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);
-    rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY; // FIXME: not always...
+    rd.expiration.abs_value = 0;
+    rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY;
     del_qe = GNUNET_NAMESTORE_record_remove (ns,
                                             zone_pkey,
                                             name,
@@ -409,9 +425,18 @@ run (void *cls, char *const *args, const char *cfgfile,
   }
   if (list)
   {
+    uint32_t must_not_flags = 0;
+
+    if (1 == nonauthority) /* List non-authority records */
+      must_not_flags |= GNUNET_NAMESTORE_RF_AUTHORITY;
+
+    if (1 == public)
+      must_not_flags |= GNUNET_NAMESTORE_RF_PRIVATE;
+
     list_it = GNUNET_NAMESTORE_zone_iteration_start (ns,
                                                     &zone,
-                                                    0, 0,
+                                                    0,
+                                                    must_not_flags,
                                                     &display_record,
                                                     NULL);
   }
@@ -429,6 +454,9 @@ run (void *cls, char *const *args, const char *cfgfile,
 int
 main (int argc, char *const *argv)
 {
+  nonauthority = -1;
+  public = -1;
+
   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
     {'a', "add", NULL,
      gettext_noop ("add record"), 0,
@@ -440,7 +468,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,
@@ -451,6 +479,12 @@ main (int argc, char *const *argv)
     {'V', "value", "VALUE",
      gettext_noop ("value of the record to add/delete"), 1,
      &GNUNET_GETOPT_set_string, &value},   
+    {'p', "public", NULL,
+     gettext_noop ("create or list public record"), 0,
+     &GNUNET_GETOPT_set_one, &public},
+    {'N', "non-authority", NULL,
+     gettext_noop ("create or list non-authority record"), 0,
+     &GNUNET_GETOPT_set_one, &nonauthority},
     {'z', "zonekey", "FILENAME",
      gettext_noop ("filename with the zone key"), 1,
      &GNUNET_GETOPT_set_string, &keyfile},   
@@ -459,6 +493,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 ==