diff options
author | Marcello Stanisci <stanisci.m@gmail.com> | 2019-06-14 23:19:12 +0200 |
---|---|---|
committer | Marcello Stanisci <stanisci.m@gmail.com> | 2019-06-14 23:19:12 +0200 |
commit | 2363d21cc073208b45a22b010a3da090cb1b77b0 (patch) | |
tree | d06261169e42570df593516ebe61927f057e48c4 /src/twister/taler-twister-service.c | |
parent | b5399d0bafb8e4bd058d4278d506ebada632bb2d (diff) | |
download | twister-2363d21cc073208b45a22b010a3da090cb1b77b0.tar.gz twister-2363d21cc073208b45a22b010a3da090cb1b77b0.tar.bz2 twister-2363d21cc073208b45a22b010a3da090cb1b77b0.zip |
porting 'delete-path'
Diffstat (limited to 'src/twister/taler-twister-service.c')
-rw-r--r-- | src/twister/taler-twister-service.c | 75 |
1 files changed, 55 insertions, 20 deletions
diff --git a/src/twister/taler-twister-service.c b/src/twister/taler-twister-service.c index 034fa5a..f6a3b04 100644 --- a/src/twister/taler-twister-service.c +++ b/src/twister/taler-twister-service.c @@ -315,7 +315,7 @@ static unsigned int hack_response_code; * Will point to a JSON object to delete. Only cares about * _download_ objects. */ -static char delete_path[TWISTER_PATH_LENGTH] = {'\0'}; +static char *delete_path = NULL; /** * Will point to a JSON _string_ object @@ -1250,10 +1250,9 @@ flip_object (struct MHD_Connection *con, * * @param con FIXME deprecated. * @param hr contains the object whose field will be deleted. - * @return MHD_YES / MHD_NO depending on successful / failing - * response queueing. + * @return GNUNET_OK when the path was found, and deleted. */ -static void +static int delete_object (struct MHD_Connection *con, struct HttpRequest *hr) { @@ -1264,7 +1263,11 @@ delete_object (struct MHD_Connection *con, &parent, &target, hr->json)) - return; + { + TALER_LOG_INFO ("Path (%s) was not found on this object\n", + delete_path); + return GNUNET_NO; + } /* here, element is the parent of the element to be deleted. */ int ret_deletion = -1; @@ -1279,12 +1282,15 @@ delete_object (struct MHD_Connection *con, NULL, 10)); } - if (-1 == ret_deletion) - TALER_LOG_WARNING ("Could not delete '%s'\n", target); - - delete_path[0] = '\0'; GNUNET_free (target); - return; + + if (-1 == ret_deletion) + { + TALER_LOG_WARNING ("Could not delete '%s'\n", + target); + return GNUNET_SYSERR; + } + return GNUNET_OK; } /** @@ -1823,12 +1829,16 @@ create_response (void *cls, } } - if ('\0' != delete_path[0]) + if (NULL != delete_path) { TALER_LOG_DEBUG ("Will delete path: %s\n", delete_path); - delete_object (con, - hr); + if (GNUNET_OK == delete_object (con, + hr)) + { + GNUNET_free (delete_path); + delete_path = NULL; + } } if ('\0' != modify_path_dl[0]) @@ -2678,6 +2688,19 @@ handle_flip_path_ul (void *cls, send_acknowledgement (c); } +/** + * Control handler for deleting JSON fields from response objects + * + * @param cls message queue for sending replies + * @param src received message + */ +static int +check_delete_path (void *cls, + const struct TWISTER_DeletePath *src) +{ + return GNUNET_OK; +} + /** * Control handler for deleting JSON fields from response objects @@ -2690,8 +2713,19 @@ handle_delete_path (void *cls, const struct TWISTER_DeletePath *src) { struct GNUNET_SERVICE_Client *c = cls; + uint16_t tailsize; + char *payload; + + tailsize = ntohs (src->header.size) - sizeof (*src); + + GNUNET_assert + (tailsize == GNUNET_STRINGS_buffer_tokenize + ((const char *) &src[1], + tailsize, + 1, + &payload)); + delete_path = GNUNET_strdup (payload); - strcpy (delete_path, src->path); send_acknowledgement (c); } @@ -2703,8 +2737,9 @@ handle_delete_path (void *cls, * @param src received message */ static void -handle_set_response_code (void *cls, - const struct TWISTER_SetResponseCode *src) +handle_set_response_code + (void *cls, + const struct TWISTER_SetResponseCode *src) { struct GNUNET_SERVICE_Client *c = cls; @@ -2748,10 +2783,10 @@ GNUNET_SERVICE_MAIN struct TWISTER_Malform, NULL), - GNUNET_MQ_hd_fixed_size (delete_path, - TWISTER_MESSAGE_TYPE_DELETE_PATH, - struct TWISTER_DeletePath, - NULL), + GNUNET_MQ_hd_var_size (delete_path, + TWISTER_MESSAGE_TYPE_DELETE_PATH, + struct TWISTER_DeletePath, + NULL), GNUNET_MQ_hd_var_size (flip_path_ul, TWISTER_MESSAGE_TYPE_FLIP_PATH_UL, |