summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2019-06-14 22:38:42 +0200
committerMarcello Stanisci <stanisci.m@gmail.com>2019-06-14 22:38:42 +0200
commitb5399d0bafb8e4bd058d4278d506ebada632bb2d (patch)
treed42d9c0158b1c04efd05d8b0ad953be3bc8b5ec9
parentdc19a8ed0e5e7c771b8bb05e3f89a1305a5ddb2b (diff)
downloadtwister-b5399d0bafb8e4bd058d4278d506ebada632bb2d.tar.gz
twister-b5399d0bafb8e4bd058d4278d506ebada632bb2d.tar.bz2
twister-b5399d0bafb8e4bd058d4278d506ebada632bb2d.zip
change path freeing policy
-rw-r--r--src/twister/taler-twister-service.c87
1 files changed, 51 insertions, 36 deletions
diff --git a/src/twister/taler-twister-service.c b/src/twister/taler-twister-service.c
index c06f9c6..034fa5a 100644
--- a/src/twister/taler-twister-service.c
+++ b/src/twister/taler-twister-service.c
@@ -981,10 +981,10 @@ con_val_iter (void *cls,
* @return #GNUNET_OK if @a path was valid.
*/
static unsigned int
-walk_response_object (const char *path,
- json_t **parent,
- char **target,
- json_t *json)
+walk_object (const char *path,
+ json_t **parent,
+ char **target,
+ json_t *json)
{
json_t *element;
@@ -1084,10 +1084,10 @@ modify_object (struct MHD_Connection *con,
json_t *new_value;
json_error_t error;
- if (GNUNET_OK != walk_response_object (path,
- &parent,
- &target,
- json))
+ if (GNUNET_OK != walk_object (path,
+ &parent,
+ &target,
+ json))
return;
/* At this point, the parent and the target are pointed to. */
@@ -1148,8 +1148,9 @@ modify_object (struct MHD_Connection *con,
* @param con FIXME deprecated.
* @param json the object whose field will be flipped.
* @param flip_path the path to the string-field to flip.
+ * @return GNUNET_OK when the path was found, and flipped.
*/
-static void
+static int
flip_object (struct MHD_Connection *con,
json_t *json,
char *flip_path)
@@ -1164,17 +1165,21 @@ flip_object (struct MHD_Connection *con,
'R', 'S', 'T', 'V', 'W', 'X',
'Y', 'Z'}; // index: 0-31
- if (GNUNET_OK != walk_response_object (flip_path,
- &parent,
- &target,
- json))
- {
- TALER_LOG_ERROR ("Could not walk the object in the quest for flip\n");
- return;
+ if (GNUNET_OK != walk_object (flip_path,
+ &parent,
+ &target,
+ json))
+ {
+ /**
+ * Not an error, as the user can "batch"
+ * requests until the right object gets in the way.
+ */
+ TALER_LOG_INFO ("Path (%s) was not found on this object\n",
+ flip_path);
+ return GNUNET_NO;
}
/* here, element is the parent of the element to be deleted. */
- int ret_flip = -1;
json_t *child = NULL;
const char *current_value;
char *current_value_flip;
@@ -1219,17 +1224,19 @@ flip_object (struct MHD_Connection *con,
TALER_LOG_INFO ("Flipping %s to %s\n",
current_value,
current_value_flip);
- if (0 == json_string_set
+ if (0 != json_string_set
(child,
(const char *) current_value_flip))
- ret_flip = GNUNET_YES;
- GNUNET_free (current_value_flip);
- if (-1 == ret_flip)
+ {
TALER_LOG_WARNING ("Could not flip '%s'\n", target);
+ GNUNET_free (current_value_flip);
+ GNUNET_free (target);
+ return GNUNET_SYSERR;
+ }
- flip_path[0] = '\0';
+ GNUNET_free (current_value_flip);
GNUNET_free (target);
- return;
+ return GNUNET_OK;
}
@@ -1253,10 +1260,10 @@ delete_object (struct MHD_Connection *con,
char *target;
json_t *parent;
- if (GNUNET_OK != walk_response_object (delete_path,
- &parent,
- &target,
- hr->json))
+ if (GNUNET_OK != walk_object (delete_path,
+ &parent,
+ &target,
+ hr->json))
return;
/* here, element is the parent of the element to be deleted. */
@@ -1570,10 +1577,13 @@ create_response (void *cls,
"Will flip path in request: %s\n",
flip_path_ul);
- flip_object (con,
- hr->json,
- flip_path_ul);
- GNUNET_free (flip_path_ul);
+ if (GNUNET_OK == flip_object (con,
+ hr->json,
+ flip_path_ul))
+ {
+ GNUNET_free (flip_path_ul);
+ flip_path_ul = NULL;
+ }
}
if ('\0' != modify_path_ul[0])
@@ -1800,12 +1810,17 @@ create_response (void *cls,
if (NULL != flip_path_dl)
{
- TALER_LOG_DEBUG ("Will flip path in response: %s\n",
+ TALER_LOG_DEBUG ("Will flip path"
+ " in response: %s\n",
flip_path_dl);
- flip_object (con,
- hr->json,
- flip_path_dl);
- GNUNET_free (flip_path_dl);
+
+ if (GNUNET_OK == flip_object (con,
+ hr->json,
+ flip_path_dl))
+ {
+ GNUNET_free (flip_path_dl);
+ flip_path_dl = NULL;
+ }
}
if ('\0' != delete_path[0])