gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [gnunet] branch master updated: NAMESTORE/JSON: fix parsing


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated: NAMESTORE/JSON: fix parsing exp and flags
Date: Thu, 25 Apr 2019 22:54:15 +0200

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

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

The following commit(s) were added to refs/heads/master by this push:
     new 07d451f79 NAMESTORE/JSON: fix parsing exp and flags
07d451f79 is described below

commit 07d451f79110dd98bb2ff8c1cf107745edbe92ce
Author: Schanzenbach, Martin <address@hidden>
AuthorDate: Thu Apr 25 22:54:02 2019 +0200

    NAMESTORE/JSON: fix parsing exp and flags
---
 src/json/json_gnsrecord.c | 48 ++++++++++++++++++++++-------------------------
 1 file changed, 22 insertions(+), 26 deletions(-)

diff --git a/src/json/json_gnsrecord.c b/src/json/json_gnsrecord.c
index 83ea367d5..2adf3c777 100644
--- a/src/json/json_gnsrecord.c
+++ b/src/json/json_gnsrecord.c
@@ -45,11 +45,12 @@
  */
 static int
 parse_gnsrecordobject (void *cls,
-                      json_t *root,
-                      struct GNUNET_JSON_Specification *spec)
+                       json_t *root,
+                       struct GNUNET_JSON_Specification *spec)
 {
   struct GNUNET_GNSRECORD_Data *gnsrecord_object;
   struct GNUNET_TIME_Absolute abs_expiration_time;
+  struct GNUNET_TIME_Absolute rel_expiration_time;
   int unpack_state=0;
   const char *value;
   const char *expiration_time;
@@ -63,21 +64,21 @@ parse_gnsrecordobject (void *cls,
   if(!json_is_object(root))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-               "Error json is not array nor object!\n");
+                "Error json is not array nor object!\n");
     return GNUNET_SYSERR;
   }
   //interpret single gns record
   unpack_state = json_unpack(root,
-                            "{s:s, s:s, s:s, s?:i, s:s!}",
-                            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_RECORD_NAME, &name);
+                             "{s:s, s:s, s:s, s?:i, s:s!}",
+                             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_RECORD_NAME, &name);
   if (0 != unpack_state)
   {
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-              "Error json object has a wrong format!\n");
+               "Error json object has a wrong format!\n");
     return GNUNET_SYSERR;
   }
   gnsrecord_object = GNUNET_new (struct GNUNET_GNSRECORD_Data);
@@ -90,9 +91,9 @@ parse_gnsrecordobject (void *cls,
   }
   if (GNUNET_OK
       != GNUNET_GNSRECORD_string_to_value (gnsrecord_object->record_type,
-                                          value,
-                                          &rdata,
-                                          &rdata_size))
+                                           value,
+                                           &rdata,
+                                           &rdata_size))
   {
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,"Value invalid for record type\n");
     GNUNET_free(gnsrecord_object);
@@ -107,25 +108,20 @@ parse_gnsrecordobject (void *cls,
     gnsrecord_object->expiration_time = 
GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
   }
   else if (GNUNET_OK
-      == GNUNET_STRINGS_fancy_time_to_absolute (expiration_time,
-                                               &abs_expiration_time))
+           == GNUNET_STRINGS_fancy_time_to_absolute (expiration_time,
+                                                     &abs_expiration_time))
   {
     gnsrecord_object->expiration_time = abs_expiration_time.abs_value_us;
   }
-  else
+  else if (GNUNET_OK
+           == GNUNET_STRINGS_fancy_time_to_relative (expiration_time,
+                                                     &rel_expiration_time))
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Expiration time invalid\n");
-    GNUNET_free_non_null(rdata);
-    GNUNET_free(gnsrecord_object);
-    return GNUNET_SYSERR;
+    gnsrecord_object->expiration_time = rel_expiration_time.rel_value_us;
   }
-  // check if flag is a valid enum value
-  if ((GNUNET_GNSRECORD_RF_NONE != flag)
-      && (GNUNET_GNSRECORD_RF_PRIVATE != flag)
-      && (GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION != flag)
-      && (GNUNET_GNSRECORD_RF_SHADOW_RECORD) != flag)
+  else
   {
-    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Flag invalid\n");
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Expiration time invalid\n");
     GNUNET_free_non_null(rdata);
     GNUNET_free(gnsrecord_object);
     return GNUNET_SYSERR;

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



reply via email to

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