-remove debug message
[oweals/gnunet.git] / src / gnsrecord / gnsrecord_misc.c
index aee1f9fd2323fe7cb60d5e7c8f52df82786cba67..5061f8493128b05f1d4ea88b48312242d10e3486 100644 (file)
@@ -1,22 +1,22 @@
 /*
      This file is part of GNUnet.
-     (C) 2009-2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2009-2013 GNUnet e.V.
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     or (at your option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
+     Affero General Public License for more details.
 
-     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.
-*/
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+     SPDX-License-Identifier: AGPL3.0-or-later
+ */
 
 /**
  * @file gnsrecord/gnsrecord_misc.c
@@ -35,7 +35,7 @@
 #include "gnunet_tun_lib.h"
 
 
-#define LOG(kind,...) GNUNET_log_from (kind, "gnsrecord",__VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "gnsrecord", __VA_ARGS__)
 
 /**
  * Convert a UTF-8 string to UTF-8 lowercase
 char *
 GNUNET_GNSRECORD_string_to_lowercase (const char *src)
 {
-  GNUNET_assert (NULL != src);
-  char *res = strdup (src);
-  /* normalize */
-  GNUNET_STRINGS_utf8_tolower(src, &res);
+  char *res;
+
+  res = GNUNET_strdup (src);
+  GNUNET_STRINGS_utf8_tolower (src, res);
   return res;
 }
 
@@ -64,12 +64,13 @@ GNUNET_GNSRECORD_string_to_lowercase (const char *src)
 const char *
 GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_EcdsaPublicKey *z)
 {
-  static char buf[sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) * 8];
+  static char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) * 8];
   char *end;
 
   end = GNUNET_STRINGS_data_to_string ((const unsigned char *) z,
-                                      sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
-                                      buf, sizeof (buf));
+                                       sizeof(struct
+                                              GNUNET_CRYPTO_EcdsaPublicKey),
+                                       buf, sizeof(buf));
   if (NULL == end)
   {
     GNUNET_break (0);
@@ -111,7 +112,7 @@ GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a,
     return GNUNET_NO;
   }
   if ((a->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS)
-       != (b->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS))
+      != (b->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS))
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Flags %lu (%lu) != %lu (%lu)\n", a->flags,
@@ -150,17 +151,19 @@ GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a,
  */
 struct GNUNET_TIME_Absolute
 GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count,
-                                            const struct GNUNET_GNSRECORD_Data *rd)
+                                             const struct
+                                             GNUNET_GNSRECORD_Data *rd)
 {
-  unsigned int c;
   struct GNUNET_TIME_Absolute expire;
   struct GNUNET_TIME_Absolute at;
   struct GNUNET_TIME_Relative rt;
+  struct GNUNET_TIME_Absolute at_shadow;
+  struct GNUNET_TIME_Relative rt_shadow;
 
   if (NULL == rd)
     return GNUNET_TIME_UNIT_ZERO_ABS;
   expire = GNUNET_TIME_UNIT_FOREVER_ABS;
-  for (c = 0; c < rd_count; c++)
+  for (unsigned int c = 0; c < rd_count; c++)
   {
     if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
     {
@@ -171,7 +174,29 @@ GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count,
     {
       at.abs_value_us = rd[c].expiration_time;
     }
-    expire = GNUNET_TIME_absolute_min (at, expire);
+
+    for (unsigned int c2 = 0; c2 < rd_count; c2++)
+    {
+      /* Check for shadow record */
+      if ((c == c2) ||
+          (rd[c].record_type != rd[c2].record_type) ||
+          (0 == (rd[c2].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD)))
+        continue;
+      /* We have a shadow record */
+      if (0 != (rd[c2].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
+      {
+        rt_shadow.rel_value_us = rd[c2].expiration_time;
+        at_shadow = GNUNET_TIME_relative_to_absolute (rt_shadow);
+      }
+      else
+      {
+        at_shadow.abs_value_us = rd[c2].expiration_time;
+      }
+      at = GNUNET_TIME_absolute_max (at,
+                                     at_shadow);
+    }
+    expire = GNUNET_TIME_absolute_min (at,
+                                       expire);
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Determined expiration time for block with %u records to be %s\n",
@@ -195,7 +220,8 @@ GNUNET_GNSRECORD_is_expired (const struct GNUNET_GNSRECORD_Data *rd)
   if (0 != (rd->flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION))
     return GNUNET_NO;
   at.abs_value_us = rd->expiration_time;
-  return (0 == GNUNET_TIME_absolute_get_remaining (at).rel_value_us) ? GNUNET_YES : GNUNET_NO;
+  return (0 == GNUNET_TIME_absolute_get_remaining (at).rel_value_us) ?
+         GNUNET_YES : GNUNET_NO;
 }
 
 
@@ -217,50 +243,33 @@ GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
 
   pkeys = GNUNET_CRYPTO_ecdsa_public_key_to_string (pkey);
   GNUNET_snprintf (ret,
-                  sizeof (ret),
-                  "%s.zkey",
-                  pkeys);
+                   sizeof(ret),
+                   "%s",
+                   pkeys);
   GNUNET_free (pkeys);
   return ret;
 }
 
 
 /**
- * Convert an absolute domain name in the ".zkey" pTLD to the
+ * Convert an absolute domain name to the
  * respective public key.
  *
- * @param zkey string "X.zkey" where X is the coordinates of the public
+ * @param zkey string encoding the coordinates of the public
  *         key in an encoding suitable for DNS labels.
  * @param pkey set to a public key on the eliptic curve
  * @return #GNUNET_SYSERR if @a zkey has the wrong syntax
  */
 int
 GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey,
-                              struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
+                               struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
 {
-  char *cpy;
-  char *dot;
-  const char *x;
-
-  cpy = GNUNET_strdup (zkey);
-  x = cpy;
-  if (NULL == (dot = strchr (x, (int) '.')))
-    goto error;
-  *dot = '\0';
-  if (0 != strcasecmp (dot + 1,
-                      "zkey"))
-    goto error;
-
   if (GNUNET_OK !=
-      GNUNET_CRYPTO_ecdsa_public_key_from_string (x,
-                                               strlen (x),
-                                               pkey))
-    goto error;
-  GNUNET_free (cpy);
+      GNUNET_CRYPTO_ecdsa_public_key_from_string (zkey,
+                                                  strlen (zkey),
+                                                  pkey))
+    return GNUNET_SYSERR;
   return GNUNET_OK;
- error:
-  GNUNET_free (cpy);
-  return GNUNET_SYSERR;
 }