change label processing in namestore REST api for gns records
authorSchanzenbach, Martin <mschanzenbach@posteo.de>
Sat, 9 May 2020 17:11:40 +0000 (19:11 +0200)
committerSchanzenbach, Martin <mschanzenbach@posteo.de>
Sat, 9 May 2020 17:11:40 +0000 (19:11 +0200)
src/json/json_generator.c
src/json/json_gnsrecord.c

index 9b2fb7fbb866173ff412400a8b23765c81dbcd5f..6a7ffa941af58e53dbd28b082def71a0297c69f3 100644 (file)
@@ -171,7 +171,7 @@ GNUNET_JSON_from_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *pk)
   json_t *ret;
 
   buf_len = GNUNET_CRYPTO_rsa_public_key_encode (pk,
-                                                 &buf);
+                                                 (void**) &buf);
   ret = GNUNET_JSON_from_data (buf,
                                buf_len);
   GNUNET_free (buf);
@@ -193,7 +193,7 @@ GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig)
   json_t *ret;
 
   buf_len = GNUNET_CRYPTO_rsa_signature_encode (sig,
-                                                &buf);
+                                                (void**) &buf);
   ret = GNUNET_JSON_from_data (buf,
                                buf_len);
   GNUNET_free (buf);
@@ -213,7 +213,8 @@ GNUNET_JSON_from_gnsrecord (const char*rname,
                             const struct GNUNET_GNSRECORD_Data *rd,
                             unsigned int rd_count)
 {
-  struct GNUNET_TIME_Absolute expiration_time;
+  struct GNUNET_TIME_Absolute abs_exp;
+  struct GNUNET_TIME_Relative rel_exp;
   const char *expiration_time_str;
   const char *record_type_str;
   char *value_str;
@@ -248,22 +249,34 @@ GNUNET_JSON_from_gnsrecord (const char*rname,
     value_str = GNUNET_GNSRECORD_value_to_string (rd[i].record_type,
                                                   rd[i].data,
                                                   rd[i].data_size);
-    expiration_time = GNUNET_GNSRECORD_record_get_expiration_time (1, &rd[i]);
-    expiration_time_str = GNUNET_STRINGS_absolute_time_to_string (
-      expiration_time);
+    if (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION & rd[i].flags)
+    {
+      rel_exp.rel_value_us = rd[i].expiration_time;
+      expiration_time_str = GNUNET_STRINGS_relative_time_to_string (rel_exp,
+                                                                    GNUNET_NO);
+    } else {
+      abs_exp.abs_value_us = rd[i].expiration_time;
+      expiration_time_str = GNUNET_STRINGS_absolute_time_to_string (abs_exp);
+    }
     record_type_str = GNUNET_GNSRECORD_number_to_typename (rd[i].record_type);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Packing %s %s %s %d\n",
                 value_str, record_type_str, expiration_time_str, rd[i].flags);
-    record = json_pack ("{s:s,s:s,s:s,s:i}",
+    record = json_pack ("{s:s,s:s,s:s,s:b,s:b,s:b,s:b}",
                         "value",
                         value_str,
                         "record_type",
                         record_type_str,
                         "expiration_time",
                         expiration_time_str,
-                        "flag",
-                        rd[i].flags);
+                        "private",
+                        rd[i].flags & GNUNET_GNSRECORD_RF_PRIVATE,
+                        "relative_expiration",
+                        rd[i].flags & GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION,
+                        "supplemental",
+                        rd[i].flags & GNUNET_GNSRECORD_RF_SUPPLEMENTAL,
+                        "shadow",
+                        rd[i].flags & GNUNET_GNSRECORD_RF_SHADOW_RECORD);
     GNUNET_free (value_str);
     if (NULL == record)
     {
index bfbdd96ee91291143af271563e2e5237409d2850..eecf45810b871a1243a1f8ce737afa1670e8751a 100644 (file)
 #define GNUNET_JSON_GNSRECORD_RECORD_DATA "data"
 #define GNUNET_JSON_GNSRECORD_TYPE "record_type"
 #define GNUNET_JSON_GNSRECORD_EXPIRATION_TIME "expiration_time"
-#define GNUNET_JSON_GNSRECORD_FLAG "flag"
+#define GNUNET_JSON_GNSRECORD_FLAG_PRIVATE "private"
+#define GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL "supplemental"
+#define GNUNET_JSON_GNSRECORD_FLAG_RELATIVE "relative_expiration"
+#define GNUNET_JSON_GNSRECORD_FLAG_SHADOW "shadow"
 #define GNUNET_JSON_GNSRECORD_RECORD_NAME "record_name"
 #define GNUNET_JSON_GNSRECORD_NEVER "never"
 
@@ -80,20 +83,29 @@ parse_record (json_t *data, struct GNUNET_GNSRECORD_Data *rd)
   const char *value;
   const char *record_type;
   const char *expiration_time;
-  int flag;
+  int private;
+  int supplemental;
+  int rel_exp;
+  int shadow;
   int unpack_state = 0;
 
   // interpret single gns record
   unpack_state = json_unpack (data,
-                              "{s:s, s:s, s:s, s?:i!}",
+                              "{s:s, s:s, s:s, s:b, s:b, s:b, s:b}",
                               GNUNET_JSON_GNSRECORD_VALUE,
                               &value,
                               GNUNET_JSON_GNSRECORD_TYPE,
                               &record_type,
                               GNUNET_JSON_GNSRECORD_EXPIRATION_TIME,
                               &expiration_time,
-                              GNUNET_JSON_GNSRECORD_FLAG,
-                              &flag);
+                              GNUNET_JSON_GNSRECORD_FLAG_PRIVATE,
+                              &private,
+                              GNUNET_JSON_GNSRECORD_FLAG_SUPPLEMENTAL,
+                              &supplemental,
+                              GNUNET_JSON_GNSRECORD_FLAG_RELATIVE,
+                              &rel_exp,
+                              GNUNET_JSON_GNSRECORD_FLAG_SHADOW,
+                              &shadow);
   if (0 != unpack_state)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -119,9 +131,10 @@ parse_record (json_t *data, struct GNUNET_GNSRECORD_Data *rd)
   {
     rd->expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
   }
-  else if (GNUNET_OK ==
+  else if ((1 != rel_exp) &&
+           (GNUNET_OK ==
            GNUNET_STRINGS_fancy_time_to_absolute (expiration_time,
-                                                  &abs_expiration_time))
+                                                  &abs_expiration_time)))
   {
     rd->expiration_time = abs_expiration_time.abs_value_us;
   }
@@ -129,6 +142,7 @@ parse_record (json_t *data, struct GNUNET_GNSRECORD_Data *rd)
            GNUNET_STRINGS_fancy_time_to_relative (expiration_time,
                                                   &rel_expiration_time))
   {
+    rd->flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
     rd->expiration_time = rel_expiration_time.rel_value_us;
   }
   else
@@ -136,7 +150,12 @@ parse_record (json_t *data, struct GNUNET_GNSRECORD_Data *rd)
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expiration time invalid\n");
     return GNUNET_SYSERR;
   }
-  rd->flags = (enum GNUNET_GNSRECORD_Flags) flag;
+  if (1 == private)
+    rd->flags |= GNUNET_GNSRECORD_RF_PRIVATE;
+  if (1 == supplemental)
+    rd->flags |= GNUNET_GNSRECORD_RF_SUPPLEMENTAL;
+  if (1 == shadow)
+    rd->flags |= GNUNET_GNSRECORD_RF_SHADOW_RECORD;
   return GNUNET_OK;
 }