commit bcb47c0abb9a40e290a0f7ea5ea6e699ec71f770
parent 324eff476dae560dda4ac99b71c776671da1a031
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Wed, 7 Mar 2018 12:35:22 +0100
lazy check object/array path element.
Diffstat:
1 file changed, 23 insertions(+), 26 deletions(-)
diff --git 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);