gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-twister] 08/34: lazy check object/array path element


From: gnunet
Subject: [GNUnet-SVN] [taler-twister] 08/34: lazy check object/array path element.
Date: Sat, 17 Mar 2018 01:57:59 +0100

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

marcello pushed a commit to branch master
in repository twister.

commit bcb47c0abb9a40e290a0f7ea5ea6e699ec71f770
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed Mar 7 12:35:22 2018 +0100

    lazy check object/array path element.
---
 src/twister/taler-twister-service.c | 49 +++++++++++++++++--------------------
 1 file changed, 23 insertions(+), 26 deletions(-)

diff --git a/src/twister/taler-twister-service.c 
b/src/twister/taler-twister-service.c
index 7d1b435..3137457 100644
--- a/src/twister/taler-twister-service.c
+++ b/src/twister/taler-twister-service.c
@@ -1140,33 +1140,28 @@ create_response (void *cls,
       if (NULL == token_path)
         break;
 
-      /* Check if path part is a number; if so, then
-         element is expected to be a array. */
-      if (-1 != GNUNET_asprintf
-          (&token_path, "%u", &index))
-      {
-        if (NULL == (element = json_array_get (element,
-                                               index)))
-        {
-          TALER_LOG_ERROR ("Array index not found\n");
-          delete_path[0] = '\0';
-          return create_and_queue_response
-            (con,
-             "{\"error\": \"Array index not found\"}",
-             MHD_HTTP_GONE);
-        }
-        continue;
-      }
-      if (NULL == (element = json_object_get (element,
+
+      /* For simplicity, we don't check if the token is
+         a number or not, and react accordingly.  We lazily
+         try to get the element until something is found or
+         not. */
+      if (NULL != (element = json_object_get (element,
                                               token_path)))
-      {
-        TALER_LOG_ERROR ("Path element not found\n");
-        delete_path[0] = '\0';
-        return create_and_queue_response
-          (con,
-           "{\"error\": \"Path element not found\"}",
-           MHD_HTTP_GONE);
-      }
+        continue;
+
+      GNUNET_assert (-1 != GNUNET_asprintf (&token_path,
+                                            "%u",
+                                            &index));
+      if (NULL != (element = json_array_get (element,
+                                             index)))
+        continue;
+
+      TALER_LOG_ERROR ("Path token '%s' not found",
+                       token_path);
+      return create_and_queue_response
+        (con,
+         "{\"error\": \"path token not found\"}",
+         MHD_HTTP_GONE);
     }
     while (NULL != (token_path = strtok (NULL, ".")));
     
@@ -1175,6 +1170,7 @@ create_response (void *cls,
     {
       TALER_LOG_ERROR ("Could not empty the object\n");
       delete_path[0] = '\0';
+      json_decref (parsed_response); 
       return create_and_queue_response
         (con,
          "{\"error\": \"Could not empty the object\"}",
@@ -1194,6 +1190,7 @@ create_response (void *cls,
 
     /* reset for next request*/
     delete_path[0] = '\0';
+    json_decref (parsed_response); 
     return create_and_queue_response (con,
                                       mod_response,
                                       hr->response_code);

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



reply via email to

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