- move rest plugins into rest directory where they belong
[oweals/gnunet.git] / src / namestore / gnunet-namestore.c
index 07c79f0330c93af0c5ccb8544b1b89176f1b78be..fccf92ce7d9936b8deb345ed746fc1268bbfeb81 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2012, 2013, 2014 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2012, 2013, 2014 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 /**
  * @file gnunet-namestore.c
@@ -109,11 +109,6 @@ static int is_public;
  */
 static int is_shadow;
 
-/**
- * Is record pending approval (#GNUNET_GNSRECORD_RF_PENDING)
- */
-static int is_pending;
-
 /**
  * Queue entry for the 'del' operation.
  */
@@ -414,13 +409,12 @@ display_record (void *cls,
       ets = GNUNET_STRINGS_absolute_time_to_string (at);
     }
     FPRINTF (stdout,
-            "\t%s: %s (%s)\t%s\t%s\t%s\n",
+            "\t%s: %s (%s)\t%s\t%s\n",
             typestring,
             s,
              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" : "");
+             (0 != (rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)) ? "SHADOW" : "");
     GNUNET_free (s);
   }
   FPRINTF (stdout, "%s", "\n");
@@ -459,23 +453,92 @@ get_existing_record (void *cls,
 {
   struct GNUNET_GNSRECORD_Data rdn[rd_count + 1];
   struct GNUNET_GNSRECORD_Data *rde;
+  unsigned int i;
 
   add_qe = NULL;
   if ( (NULL != zone_key) &&
        (0 != strcmp (rec_name, name)) )
   {
     GNUNET_break (0);
+    ret = 1;
+    test_finished ();
     return;
   }
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %u records for name `%s'\n",
-      rd_count, rec_name);
-
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Received %u records for name `%s'\n",
+              rd_count, rec_name);
+  for (i=0;i<rd_count;i++)
+  {
+    switch (rd[i].record_type)
+    {
+    case GNUNET_DNSPARSER_TYPE_CNAME:
+      fprintf (stderr,
+               _("A %s record exists already under `%s', no other records can be added.\n"),
+               "CNAME",
+               rec_name);
+      ret = 1;
+      test_finished ();
+      return;
+    case GNUNET_GNSRECORD_TYPE_PKEY:
+      fprintf (stderr,
+               _("A %s record exists already under `%s', no other records can be added.\n"),
+               "PKEY",
+               rec_name);
+      ret = 1;
+      test_finished ();
+      return;
+    case GNUNET_GNSRECORD_TYPE_GNS2DNS:
+      fprintf (stderr,
+               _("A %s record exists already under `%s', no other records can be added.\n"),
+               "GNS2DNS",
+               rec_name);
+      ret = 1;
+      test_finished ();
+      return;
+    }
+  }
+  switch (type)
+  {
+  case GNUNET_DNSPARSER_TYPE_CNAME:
+    if (0 != rd_count)
+    {
+      fprintf (stderr,
+               _("Records already exist under `%s', cannot add `%s' record.\n"),
+               rec_name,
+               "CNAME");
+      ret = 1;
+      test_finished ();
+      return;
+    }
+    break;
+  case GNUNET_GNSRECORD_TYPE_PKEY:
+    if (0 != rd_count)
+    {
+      fprintf (stderr,
+               _("Records already exist under `%s', cannot add `%s' record.\n"),
+               rec_name,
+               "PKEY");
+      ret = 1;
+      test_finished ();
+      return;
+    }
+    break;
+  case GNUNET_GNSRECORD_TYPE_GNS2DNS:
+    if (0 != rd_count)
+    {
+      fprintf (stderr,
+               _("Records already exist under `%s', cannot add `%s' record.\n"),
+               rec_name,
+               "GNS2DNS");
+      ret = 1;
+      test_finished ();
+      return;
+    }
+    break;
+  }
   memset (rdn, 0, sizeof (struct GNUNET_GNSRECORD_Data));
   memcpy (&rdn[1], rd, rd_count * sizeof (struct GNUNET_GNSRECORD_Data));
-  /* FIXME: should add some logic to overwrite records if there
-     can only be one record of a particular type, and to check
-     if the combination of records is valid to begin with... */
   rde = &rdn[0];
   rde->data = data;
   rde->data_size = data_size;
@@ -484,8 +547,6 @@ get_existing_record (void *cls,
     rde->flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD;
   if (1 != is_public)
     rde->flags |= GNUNET_GNSRECORD_RF_PRIVATE;
-  if (1 == is_pending)
-    rde->flags |= GNUNET_GNSRECORD_RF_PENDING;
   if (GNUNET_YES == etime_is_rel)
   {
     rde->expiration_time = etime_rel.rel_value_us;
@@ -796,7 +857,11 @@ testservice_task (void *cls,
     char sname[64];
     struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
 
-    if ( (2 != (sscanf (uri, "gnunet://gns/%52s/%63s", sh, sname)) ) ||
+    GNUNET_STRINGS_utf8_tolower (uri, uri);
+    if ( (2 != (sscanf (uri,
+                        "gnunet://gns/%52s/%63s",
+                        sh,
+                        sname)) ) ||
          (GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (sh, strlen (sh), &pkey)) )
     {
       fprintf (stderr,
@@ -994,7 +1059,6 @@ int
 main (int argc, char *const *argv)
 {
   is_public = -1;
-  is_pending = -1;
   is_shadow = -1;
 
   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
@@ -1034,9 +1098,6 @@ main (int argc, char *const *argv)
     {'p', "public", NULL,
      gettext_noop ("create or list public record"), 0,
      &GNUNET_GETOPT_set_one, &is_public},
-    {'P', "pending", NULL,
-     gettext_noop ("create record that is pending approval (and thus for now inactive)"), 0,
-     &GNUNET_GETOPT_set_one, &is_pending},
     {'s', "shadow", NULL,
      gettext_noop ("create shadow record (only valid if all other records of the same type have expired"), 0,
      &GNUNET_GETOPT_set_one, &is_shadow},