gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] 01/02: Revert "Revert "change label processing in namestore RES


From: gnunet
Subject: [gnunet] 01/02: Revert "Revert "change label processing in namestore REST api for gns records""
Date: Sat, 09 May 2020 19:21:00 +0200

This is an automated email from the git hooks/post-receive script.

martin-schanzenbach pushed a commit to branch master
in repository gnunet.

commit 69ea05d2b141226721494d518feabd547ca39e6a
Author: Schanzenbach, Martin <address@hidden>
AuthorDate: Sat May 9 19:15:30 2020 +0200

    Revert "Revert "change label processing in namestore REST api for gns 
records""
    
    This reverts commit 116b96d2d3410cb7ad3fad969b68981fb3eede3d.
---
 src/json/json_generator.c | 35 ++++++++++++++++++++++++-----------
 src/json/json_gnsrecord.c | 39 +++++++++++++++++++++++++++++----------
 2 files changed, 53 insertions(+), 21 deletions(-)

diff --git a/src/json/json_generator.c b/src/json/json_generator.c
index dd875871e..6a7ffa941 100644
--- a/src/json/json_generator.c
+++ b/src/json/json_generator.c
@@ -166,12 +166,12 @@ GNUNET_JSON_from_time_rel (struct GNUNET_TIME_Relative 
stamp)
 json_t *
 GNUNET_JSON_from_rsa_public_key (const struct GNUNET_CRYPTO_RsaPublicKey *pk)
 {
-  void *buf;
+  char *buf;
   size_t buf_len;
   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);
@@ -188,12 +188,12 @@ GNUNET_JSON_from_rsa_public_key (const struct 
GNUNET_CRYPTO_RsaPublicKey *pk)
 json_t *
 GNUNET_JSON_from_rsa_signature (const struct GNUNET_CRYPTO_RsaSignature *sig)
 {
-  void *buf;
+  char *buf;
   size_t buf_len;
   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)
     {
diff --git a/src/json/json_gnsrecord.c b/src/json/json_gnsrecord.c
index 37f0c03da..eecf45810 100644
--- a/src/json/json_gnsrecord.c
+++ b/src/json/json_gnsrecord.c
@@ -31,7 +31,10 @@
 #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"
 
@@ -50,10 +53,10 @@ cleanup_recordinfo (struct GnsRecordInfo *gnsrecord_info)
 {
   if (NULL != *(gnsrecord_info->rd))
   {
-    for (unsigned int i = 0; i < *(gnsrecord_info->rd_count); i++)
+    for (int i = 0; i < *(gnsrecord_info->rd_count); i++)
     {
       if (NULL != (*(gnsrecord_info->rd))[i].data)
-        GNUNET_free_nz ((char *) (*(gnsrecord_info->rd))[i].data);
+        GNUNET_free ((char *) (*(gnsrecord_info->rd))[i].data);
     }
     GNUNET_free (*(gnsrecord_info->rd));
     *(gnsrecord_info->rd) = NULL;
@@ -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;
 }
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]