X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fgnsrecord%2Fgnsrecord_misc.c;h=4c3bf6fa8f89a3ad02390073e70e686b469f6ab6;hb=79fb947eb8fba243ea65e19b40b65e04f8806865;hp=7d73af37668c902d49b573b0c876c5258ed01dc8;hpb=3d670727232e79b7e49a1df7ba9260db4e5798a0;p=oweals%2Fgnunet.git diff --git a/src/gnsrecord/gnsrecord_misc.c b/src/gnsrecord/gnsrecord_misc.c index 7d73af376..4c3bf6fa8 100644 --- a/src/gnsrecord/gnsrecord_misc.c +++ b/src/gnsrecord/gnsrecord_misc.c @@ -1,6 +1,6 @@ /* 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 @@ -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. */ /** @@ -43,12 +43,12 @@ * @return converted result */ char * -GNUNET_NAMESTORE_normalize_string (const char *src) +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; } @@ -59,10 +59,10 @@ GNUNET_NAMESTORE_normalize_string (const char *src) * NOT reentrant! * * @param z the zone key - * @return string form; will be overwritten by next call to #GNUNET_NAMESTORE_z2s + * @return string form; will be overwritten by next call to #GNUNET_GNSRECORD_z2s */ const char * -GNUNET_NAMESTORE_z2s (const struct GNUNET_CRYPTO_EcdsaPublicKey *z) +GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_EcdsaPublicKey *z) { static char buf[sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) * 8]; char *end; @@ -90,8 +90,8 @@ GNUNET_NAMESTORE_z2s (const struct GNUNET_CRYPTO_EcdsaPublicKey *z) * @return #GNUNET_YES if the records are equal or #GNUNET_NO if they are not */ int -GNUNET_NAMESTORE_records_cmp (const struct GNUNET_NAMESTORE_RecordData *a, - const struct GNUNET_NAMESTORE_RecordData *b) +GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, + const struct GNUNET_GNSRECORD_Data *b) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Comparing records\n"); @@ -110,13 +110,13 @@ GNUNET_NAMESTORE_records_cmp (const struct GNUNET_NAMESTORE_RecordData *a, b->expiration_time); return GNUNET_NO; } - if ((a->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS) - != (b->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS)) + if ((a->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, - a->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS, b->flags, - b->flags & GNUNET_NAMESTORE_RF_RCMP_FLAGS); + a->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS, b->flags, + b->flags & GNUNET_GNSRECORD_RF_RCMP_FLAGS); return GNUNET_NO; } if (a->data_size != b->data_size) @@ -149,20 +149,23 @@ GNUNET_NAMESTORE_records_cmp (const struct GNUNET_NAMESTORE_RecordData *a, * @return absolute expiration time */ struct GNUNET_TIME_Absolute -GNUNET_NAMESTORE_record_get_expiration_time (unsigned int rd_count, - const struct GNUNET_NAMESTORE_RecordData *rd) +GNUNET_GNSRECORD_record_get_expiration_time (unsigned int rd_count, + const struct GNUNET_GNSRECORD_Data *rd) { unsigned int c; + unsigned int c2; 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++) { - if (0 != (rd[c].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)) + if (0 != (rd[c].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION)) { rt.rel_value_us = rd[c].expiration_time; at = GNUNET_TIME_relative_to_absolute (rt); @@ -171,6 +174,26 @@ GNUNET_NAMESTORE_record_get_expiration_time (unsigned int rd_count, { at.abs_value_us = rd[c].expiration_time; } + + for (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, @@ -188,11 +211,11 @@ GNUNET_NAMESTORE_record_get_expiration_time (unsigned int rd_count, * #GNUNET_NO if not */ int -GNUNET_NAMESTORE_is_expired (const struct GNUNET_NAMESTORE_RecordData *rd) +GNUNET_GNSRECORD_is_expired (const struct GNUNET_GNSRECORD_Data *rd) { struct GNUNET_TIME_Absolute at; - if (0 != (rd->flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION)) + 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; @@ -210,7 +233,7 @@ GNUNET_NAMESTORE_is_expired (const struct GNUNET_NAMESTORE_RecordData *rd) * key in an encoding suitable for DNS labels. */ const char * -GNUNET_NAMESTORE_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) +GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) { static char ret[128]; char *pkeys; @@ -235,7 +258,7 @@ GNUNET_NAMESTORE_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) * @return #GNUNET_SYSERR if @a zkey has the wrong syntax */ int -GNUNET_NAMESTORE_zkey_to_pkey (const char *zkey, +GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) { char *cpy;