diff options
author | Marcello Stanisci <stanisci.m@gmail.com> | 2018-03-10 13:12:25 +0100 |
---|---|---|
committer | Marcello Stanisci <stanisci.m@gmail.com> | 2018-03-10 13:12:25 +0100 |
commit | 8b914fd9ccff92a7db4009a58c2fccfefaba11d9 (patch) | |
tree | 9189982a0b90aada0716d621d90e602f6ac6aa6e | |
parent | 07b6e87b6366a7b1893a0edf75a493b2e38af6ff (diff) | |
download | twister-8b914fd9ccff92a7db4009a58c2fccfefaba11d9.tar.gz twister-8b914fd9ccff92a7db4009a58c2fccfefaba11d9.tar.bz2 twister-8b914fd9ccff92a7db4009a58c2fccfefaba11d9.zip |
remove number conversion, for now.
This feature is not very relevant to modify Taler JSON objects.
-rwxr-xr-x | src/test/test_twister.sh | 4 | ||||
-rw-r--r-- | src/twister/taler-twister-service.c | 101 | ||||
-rw-r--r-- | src/twister/taler-twister.c | 36 | ||||
-rw-r--r-- | src/twister/testing_api_cmd_exec_client.c | 2 |
4 files changed, 70 insertions, 73 deletions
diff --git a/src/test/test_twister.sh b/src/test/test_twister.sh index 7609edf..6703ce1 100755 --- a/src/test/test_twister.sh +++ b/src/test/test_twister.sh @@ -54,11 +54,11 @@ fi # check if cumulative mods work. taler-twister -c ./test_twister.conf \ - --modobject "hello" -V "7" \ + --modobject "hello" -V "world" \ --deleteobject "when" cum_mods=$(curl -s ${TWISTER_URL}) -if ! test '{"hello":7}' = $cum_mods; then +if ! test '{"hello":"world"}' = $cum_mods; then printf "Response body (%s) has not been" \ " cumulative-modified as expected\n" \ "$cum_mods" diff --git a/src/twister/taler-twister-service.c b/src/twister/taler-twister-service.c index b0207c5..7d37198 100644 --- a/src/twister/taler-twister-service.c +++ b/src/twister/taler-twister-service.c @@ -1,23 +1,24 @@ /* - This file is part of GNUnet. - Copyright (C) 2012-2014 GNUnet e.V. - Copyright (C) 2018 Taler Systems SA - - GNUnet is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version - 3, or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public - License along with GNUnet; see the file COPYING. If not, - write to the Free Software Foundation, Inc., 51 Franklin - Street, Fifth Floor, Boston, MA 02110-1301, USA. + This file is part of GNUnet. + Copyright (C) 2012-2014 GNUnet e.V. + Copyright (C) 2018 Taler Systems SA + + GNUnet is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 3, or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with GNUnet; see the file COPYING. If not, + write to the Free Software Foundation, Inc., 51 Franklin + Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + /** * @author Martin Schanzenbach * @author Christian Grothoff @@ -244,12 +245,12 @@ static unsigned int hack_response_code; /** * Will point to a JSON object to delete */ -static char delete_path[TWISTER_PATH_LENGTH] = { '\0' }; +static char delete_path[TWISTER_PATH_LENGTH] = {'\0'}; /** * Will point to a JSON object to modify */ -static char modify_path[TWISTER_PATH_LENGTH] = { '\0' }; +static char modify_path[TWISTER_PATH_LENGTH] = {'\0'}; /** * New value. @@ -261,7 +262,7 @@ static char modify_value[TWISTER_VALUE_LENGTH]; * Will point to the path if it has to be deleted */ -/* ************************* Global helpers ********************* */ +/* ********************* Global helpers ****************** */ /** @@ -821,7 +822,7 @@ con_val_iter (void *cls, * @param[out] response parsed original response, to be decref'd * by the caller. * @param[out] target last token of the path. E.g. given a x.y.z, - * will point to 'z'. + * will point to 'z'. To be freed by the caller. * @param hr contains original response. * * @return GNUNET_OK if @a path was valid. @@ -879,8 +880,9 @@ walk_response_object (const char *path, return GNUNET_NO; } - *target = last_token; + *target = GNUNET_strdup (last_token); *parent = element; + GNUNET_free (path_dup); return GNUNET_OK; } @@ -894,45 +896,40 @@ modify_object (struct MHD_Connection *con, { char *target; - unsigned long long n; unsigned int ret_modify; json_t *parent; json_t *new_value; json_error_t error; - walk_response_object (modify_path, - &parent, - &target, - hr); + if (GNUNET_OK != walk_response_object (modify_path, + &parent, + &target, + hr)) + return; /* At this point, the parent and the target are pointed to. */ - if (NULL != (new_value = json_loadb (modify_value, - strlen (modify_value), - JSON_DECODE_ANY, + if (NULL != (new_value = json_loads (modify_value, + JSON_REJECT_DUPLICATES + | JSON_DISABLE_EOF_CHECK, &error))) - goto perform_modbody; - - if (ULONG_MAX > (n = strtoull (modify_value, - NULL, - 10))) { - if (NULL != (new_value = json_integer ((json_int_t) n))) - goto perform_modbody; + TALER_LOG_DEBUG ("New value parsed as object/array\n"); + goto perform_modbody; } if (NULL != (new_value = json_string (modify_value))) + { + TALER_LOG_DEBUG ("New value parsed as string\n"); goto perform_modbody; + } - TALER_LOG_ERROR ("Unvalid new value given: %s\n", - modify_value); - /* Resetting operation too. */ + TALER_LOG_ERROR ("Unvalid new value given: %s\n", modify_value); modify_path[0] = '\0'; - + GNUNET_free (target); return; perform_modbody: - ret_modify = -1; if (json_is_object (parent)) ret_modify = json_object_set_new (parent, @@ -941,15 +938,13 @@ modify_object (struct MHD_Connection *con, if (json_is_array (parent)) ret_modify = json_array_set_new (parent, - (unsigned int) strtoul (target, - NULL, - 10), + (unsigned int) strtoul (target, NULL, 10), new_value); if (-1 == ret_modify) - TALER_LOG_WARNING ("Could not replace '%s'\n", - target); + TALER_LOG_WARNING ("Could not replace '%s'\n", target); modify_path[0] = '\0'; + GNUNET_free (target); return; } @@ -970,10 +965,11 @@ delete_object (struct MHD_Connection *con, char *target; json_t *parent; - walk_response_object (delete_path, - &parent, - &target, - hr); + if (GNUNET_OK != walk_response_object (delete_path, + &parent, + &target, + hr)) + return; /* here, element is the parent of the element to be deleted. */ int ret_deletion = -1; @@ -992,6 +988,7 @@ delete_object (struct MHD_Connection *con, TALER_LOG_WARNING ("Could not delete '%s'\n", target); delete_path[0] = '\0'; + GNUNET_free (target); return; } diff --git a/src/twister/taler-twister.c b/src/twister/taler-twister.c index ce34c21..e7fe2ea 100644 --- a/src/twister/taler-twister.c +++ b/src/twister/taler-twister.c @@ -1,22 +1,22 @@ /* - This file is part of Taler - Copyright (C) 2008--2014, 2016 GNUnet e.V. - Copyright (C) 2018 Taler Systems SA - - Taler is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version - 3, or (at your option) any later version. - - Taler is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public - License along with Taler; see the file COPYING. If not, - write to the Free Software Foundation, Inc., 51 Franklin - Street, Fifth Floor, Boston, MA 02110-1301, USA. + This file is part of Taler + Copyright (C) 2008--2014, 2016 GNUnet e.V. + Copyright (C) 2018 Taler Systems SA + + Taler is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 3, or (at your option) any later version. + + Taler is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with Taler; see the file COPYING. If not, + write to the Free Software Foundation, Inc., 51 Franklin + Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /** diff --git a/src/twister/testing_api_cmd_exec_client.c b/src/twister/testing_api_cmd_exec_client.c index 2e18afc..352d05a 100644 --- a/src/twister/testing_api_cmd_exec_client.c +++ b/src/twister/testing_api_cmd_exec_client.c @@ -358,7 +358,7 @@ modify_object_run (void *cls, "taler-twister", "taler-twister", "-c", mos->config_filename, - "--deleteobject", mos->path, + "--modobject", mos->path, "--value", mos->value, NULL); if (NULL == mos->proc) |