From c04151f2e12f3e6c0a726f293214da635897b535 Mon Sep 17 00:00:00 2001 From: josch Date: Fri, 5 Dec 2014 14:27:31 +0100 Subject: [PATCH] remove json_object_by_path --- CMakeLists.txt | 1 - mfapi/apicalls.c | 3 +- mfapi/apicalls/device_get_changes.c | 12 +-- mfapi/apicalls/device_get_patch.c | 3 +- mfapi/apicalls/device_get_status.c | 3 +- mfapi/apicalls/device_get_updates.c | 3 +- mfapi/apicalls/file_get_info.c | 5 +- mfapi/apicalls/file_get_links.c | 3 +- mfapi/apicalls/folder_get_content.c | 12 +-- mfapi/apicalls/folder_get_info.c | 5 +- mfapi/apicalls/upload_poll_upload.c | 5 +- mfapi/apicalls/upload_simple.c | 5 +- mfapi/apicalls/user_get_info.c | 5 +- mfapi/apicalls/user_get_session_token.c | 3 +- utils/json.c | 104 ------------------------ utils/json.h | 26 ------ 16 files changed, 26 insertions(+), 172 deletions(-) delete mode 100644 utils/json.c delete mode 100644 utils/json.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ea0597f..997fad2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,6 @@ add_library(mfapi SHARED add_library(mfutils SHARED utils/http.c - utils/json.c utils/strings.c utils/stringv.c utils/xdelta3.c diff --git a/mfapi/apicalls.c b/mfapi/apicalls.c index 631a9e3..1196988 100644 --- a/mfapi/apicalls.c +++ b/mfapi/apicalls.c @@ -22,7 +22,6 @@ #include #include "../utils/http.h" -#include "../utils/json.h" int mfapi_check_response(json_t * response, const char *apicall) { @@ -90,7 +89,7 @@ int mfapi_decode_common(mfhttp * conn, void *user_ptr) return -1; } - node = json_object_by_path(root, "response"); + node = json_object_get(root, "response"); retval = mfapi_check_response(node, apicall); if (retval != 0) { diff --git a/mfapi/apicalls/device_get_changes.c b/mfapi/apicalls/device_get_changes.c index bf02417..06784f6 100644 --- a/mfapi/apicalls/device_get_changes.c +++ b/mfapi/apicalls/device_get_changes.c @@ -26,7 +26,6 @@ #include #include "../../utils/http.h" -#include "../../utils/json.h" #include "../mfconn.h" #include "../apicalls.h" // IWYU pragma: keep @@ -97,6 +96,7 @@ static int _decode_device_get_changes(mfhttp * conn, void *user_ptr) json_error_t error; json_t *root; json_t *node; + json_t *response; json_t *data; json_t *obj_array; @@ -124,16 +124,16 @@ static int _decode_device_get_changes(mfhttp * conn, void *user_ptr) return -1; } - node = json_object_by_path(root, "response"); + response = json_object_get(root, "response"); - retval = mfapi_check_response(node, "device/get_changes"); + retval = mfapi_check_response(response, "device/get_changes"); if (retval != 0) { fprintf(stderr, "invalid response\n"); json_decref(root); return retval; } - device_revision = json_object_get(node, "device_revision"); + device_revision = json_object_get(response, "device_revision"); if (device_revision == NULL) { fprintf(stderr, "response/device_revision is not part of the result\n"); @@ -143,7 +143,7 @@ static int _decode_device_get_changes(mfhttp * conn, void *user_ptr) len_changes = 0; - node = json_object_by_path(root, "response/updated"); + node = json_object_get(response, "updated"); obj_array = json_object_get(node, "files"); if (json_is_array(obj_array)) { @@ -175,7 +175,7 @@ static int _decode_device_get_changes(mfhttp * conn, void *user_ptr) } } - node = json_object_by_path(root, "response/deleted"); + node = json_object_get(response, "deleted"); obj_array = json_object_get(node, "files"); if (json_is_array(obj_array)) { diff --git a/mfapi/apicalls/device_get_patch.c b/mfapi/apicalls/device_get_patch.c index 3438c94..ffe4e95 100644 --- a/mfapi/apicalls/device_get_patch.c +++ b/mfapi/apicalls/device_get_patch.c @@ -24,7 +24,6 @@ #include #include "../../utils/http.h" -#include "../../utils/json.h" #include "../mfconn.h" #include "../patch.h" #include "../apicalls.h" // IWYU pragma: keep @@ -94,7 +93,7 @@ static int _decode_device_get_patch(mfhttp * conn, void *data) return -1; } - node = json_object_by_path(root, "response"); + node = json_object_get(root, "response"); retval = mfapi_check_response(node, "device/get_patch"); if (retval != 0) { diff --git a/mfapi/apicalls/device_get_status.c b/mfapi/apicalls/device_get_status.c index d999430..0719cb5 100644 --- a/mfapi/apicalls/device_get_status.c +++ b/mfapi/apicalls/device_get_status.c @@ -23,7 +23,6 @@ #include #include "../../utils/http.h" -#include "../../utils/json.h" #include "../mfconn.h" #include "../apicalls.h" // IWYU pragma: keep @@ -76,7 +75,7 @@ static int _decode_device_get_status(mfhttp * conn, void *data) return -1; } - node = json_object_by_path(root, "response"); + node = json_object_get(root, "response"); retval = mfapi_check_response(node, "device/get_status"); if (retval != 0) { diff --git a/mfapi/apicalls/device_get_updates.c b/mfapi/apicalls/device_get_updates.c index 5610879..fbb9998 100644 --- a/mfapi/apicalls/device_get_updates.c +++ b/mfapi/apicalls/device_get_updates.c @@ -25,7 +25,6 @@ #include #include "../../utils/http.h" -#include "../../utils/json.h" #include "../patch.h" #include "../mfconn.h" #include "../apicalls.h" // IWYU pragma: keep @@ -115,7 +114,7 @@ static int _decode_device_get_updates(mfhttp * conn, void *user_ptr) return -1; } - node = json_object_by_path(root, "response"); + node = json_object_get(root, "response"); retval = mfapi_check_response(node, "device/get_updates"); if (retval != 0) { diff --git a/mfapi/apicalls/file_get_info.c b/mfapi/apicalls/file_get_info.c index a6fe213..264edee 100644 --- a/mfapi/apicalls/file_get_info.c +++ b/mfapi/apicalls/file_get_info.c @@ -25,7 +25,6 @@ #include #include "../../utils/http.h" -#include "../../utils/json.h" #include "../mfconn.h" #include "../file.h" #include "../apicalls.h" // IWYU pragma: keep @@ -93,7 +92,7 @@ static int _decode_file_get_info(mfhttp * conn, void *data) return -1; } - node = json_object_by_path(root, "response"); + node = json_object_get(root, "response"); retval = mfapi_check_response(node, "file/get_info"); if (retval != 0) { @@ -102,7 +101,7 @@ static int _decode_file_get_info(mfhttp * conn, void *data) return retval; } - node = json_object_by_path(root, "response/file_info"); + node = json_object_get(node, "file_info"); quickkey = json_object_get(node, "quickkey"); if (quickkey != NULL) diff --git a/mfapi/apicalls/file_get_links.c b/mfapi/apicalls/file_get_links.c index 9cc41fe..79e58d1 100644 --- a/mfapi/apicalls/file_get_links.c +++ b/mfapi/apicalls/file_get_links.c @@ -23,7 +23,6 @@ #include #include "../../utils/http.h" -#include "../../utils/json.h" #include "../mfconn.h" #include "../file.h" #include "../apicalls.h" // IWYU pragma: keep @@ -92,7 +91,7 @@ static int _decode_file_get_links(mfhttp * conn, void *data) return -1; } - node = json_object_by_path(root, "response"); + node = json_object_get(root, "response"); retval = mfapi_check_response(node, "file/get_links"); if (retval != 0) { diff --git a/mfapi/apicalls/folder_get_content.c b/mfapi/apicalls/folder_get_content.c index 4bb7f8c..4fb4a6b 100644 --- a/mfapi/apicalls/folder_get_content.c +++ b/mfapi/apicalls/folder_get_content.c @@ -26,7 +26,6 @@ #include #include "../../utils/http.h" -#include "../../utils/json.h" #include "../folder.h" #include "../file.h" #include "../mfconn.h" @@ -131,7 +130,7 @@ static int _decode_folder_get_content_folders(mfhttp * conn, void *user_ptr) return -1; } - node = json_object_by_path(root, "response"); + node = json_object_get(root, "response"); retval = mfapi_check_response(node, "folder/get_content"); if (retval != 0) { @@ -140,10 +139,7 @@ static int _decode_folder_get_content_folders(mfhttp * conn, void *user_ptr) return retval; } - /*json_t *result = json_object_by_path(root, "response/action"); - fprintf(stderr, "response/action: %s\n", (char*)json_string_value(result)); */ - - node = json_object_by_path(root, "response/folder_content"); + node = json_object_get(node, "folder_content"); folders_array = json_object_get(node, "folders"); if (!json_is_array(folders_array)) { @@ -247,7 +243,7 @@ static int _decode_folder_get_content_files(mfhttp * conn, void *user_ptr) return -1; } - node = json_object_by_path(root, "response"); + node = json_object_get(root, "response"); retval = mfapi_check_response(node, "folder/get_content"); if (retval != 0) { @@ -256,7 +252,7 @@ static int _decode_folder_get_content_files(mfhttp * conn, void *user_ptr) return retval; } - node = json_object_by_path(root, "response/folder_content"); + node = json_object_get(node, "folder_content"); files_array = json_object_get(node, "files"); if (!json_is_array(files_array)) { diff --git a/mfapi/apicalls/folder_get_info.c b/mfapi/apicalls/folder_get_info.c index 1d038ca..a12c600 100644 --- a/mfapi/apicalls/folder_get_info.c +++ b/mfapi/apicalls/folder_get_info.c @@ -25,7 +25,6 @@ #include #include "../../utils/http.h" -#include "../../utils/json.h" #include "../folder.h" #include "../mfconn.h" #include "../apicalls.h" // IWYU pragma: keep @@ -99,7 +98,7 @@ static int _decode_folder_get_info(mfhttp * conn, void *data) return -1; } - node = json_object_by_path(root, "response"); + node = json_object_get(root, "response"); retval = mfapi_check_response(node, "folder/get_info"); if (retval != 0) { @@ -108,7 +107,7 @@ static int _decode_folder_get_info(mfhttp * conn, void *data) return retval; } - node = json_object_by_path(root, "response/folder_info"); + node = json_object_get(node, "folder_info"); folderkey = json_object_get(node, "folderkey"); if (folderkey != NULL) diff --git a/mfapi/apicalls/upload_poll_upload.c b/mfapi/apicalls/upload_poll_upload.c index 78ac10f..7c5454f 100644 --- a/mfapi/apicalls/upload_poll_upload.c +++ b/mfapi/apicalls/upload_poll_upload.c @@ -24,7 +24,6 @@ #include #include "../../utils/http.h" -#include "../../utils/json.h" #include "../mfconn.h" #include "../apicalls.h" // IWYU pragma: keep @@ -94,7 +93,7 @@ static int _decode_upload_poll_upload(mfhttp * conn, void *user_ptr) return -1; } - node = json_object_by_path(root, "response"); + node = json_object_get(root, "response"); retval = mfapi_check_response(node, "upload/poll_upload"); if (retval != 0) { @@ -103,7 +102,7 @@ static int _decode_upload_poll_upload(mfhttp * conn, void *user_ptr) return retval; } - node = json_object_by_path(root, "response/doupload"); + node = json_object_get(node, "doupload"); // make sure that the result code is zero (success) j_obj = json_object_get(node, "result"); diff --git a/mfapi/apicalls/upload_simple.c b/mfapi/apicalls/upload_simple.c index 6467fc4..fcf7169 100644 --- a/mfapi/apicalls/upload_simple.c +++ b/mfapi/apicalls/upload_simple.c @@ -28,7 +28,6 @@ #include #include "../../utils/http.h" -#include "../../utils/json.h" #include "../../utils/hash.h" #include "../mfconn.h" #include "../apicalls.h" // IWYU pragma: keep @@ -114,7 +113,7 @@ static int _decode_upload_simple(mfhttp * conn, void *user_ptr) return -1; } - node = json_object_by_path(root, "response"); + node = json_object_get(root, "response"); retval = mfapi_check_response(node, "upload/simple"); if (retval != 0) { @@ -123,7 +122,7 @@ static int _decode_upload_simple(mfhttp * conn, void *user_ptr) return retval; } - node = json_object_by_path(root, "response/doupload"); + node = json_object_get(node, "doupload"); j_obj = json_object_get(node, "key"); if (j_obj != NULL) { diff --git a/mfapi/apicalls/user_get_info.c b/mfapi/apicalls/user_get_info.c index adecb49..7513f1b 100644 --- a/mfapi/apicalls/user_get_info.c +++ b/mfapi/apicalls/user_get_info.c @@ -22,7 +22,6 @@ #include #include "../../utils/http.h" -#include "../../utils/json.h" #include "../mfconn.h" #include "../apicalls.h" // IWYU pragma: keep @@ -73,7 +72,7 @@ static int _decode_user_get_info(mfhttp * conn, void *data) return -1; } - node = json_object_by_path(root, "response"); + node = json_object_get(root, "response"); retval = mfapi_check_response(node, "user/get_info"); if (retval != 0) { @@ -82,7 +81,7 @@ static int _decode_user_get_info(mfhttp * conn, void *data) return retval; } - node = json_object_by_path(root, "response/user_info"); + node = json_object_get(node, "user_info"); email = json_object_get(node, "email"); if (email != NULL) diff --git a/mfapi/apicalls/user_get_session_token.c b/mfapi/apicalls/user_get_session_token.c index fb2a79d..6fcf248 100644 --- a/mfapi/apicalls/user_get_session_token.c +++ b/mfapi/apicalls/user_get_session_token.c @@ -26,7 +26,6 @@ #include #include "../../utils/http.h" -#include "../../utils/json.h" #include "../../utils/strings.h" #include "../mfconn.h" #include "../apicalls.h" // IWYU pragma: keep @@ -116,7 +115,7 @@ static int _decode_get_session_token(mfhttp * conn, void *user_ptr) return -1; } - node = json_object_by_path(root, "response"); + node = json_object_get(root, "response"); retval = mfapi_check_response(node, "user/get_session_token"); if (retval != 0) { diff --git a/utils/json.c b/utils/json.c deleted file mode 100644 index ae667ea..0000000 --- a/utils/json.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2013 Bryan Christ - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2, as published by - * the Free Software Foundation. - * - * This program 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 - * this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include - -#include "json.h" -#include "stringv.h" - -json_t *json_object_by_path(json_t * start, const char *path) -{ - char **path_nodes; - char **curr; - json_t *node = NULL; - json_t *data = NULL; - - if (start == NULL) - return NULL; - if (path == NULL) - return NULL; - - path_nodes = stringv_split((char *)path, "/", 10); - - if (path_nodes == NULL) - return NULL; - curr = path_nodes; - node = start; - - while (curr != NULL) { - if (*curr == NULL) - break; - - node = json_object_get(node, *curr); - if (node == NULL) - break; - - if (!json_is_object(node)) { - stringv_free(path_nodes, STRINGV_FREE_ALL); - return NULL; - } - - curr++; - data = node; - } - - stringv_free(path_nodes, STRINGV_FREE_ALL); - - return data; -} - - // fix a path with leading slashes -/* - while(strlen(path) > 0) - { - if(*path[0] == '\') - { - path++; - continue; - } - - len = strlen(path); - buffer = (char*)calloc(len + 1,sizeof(char)); - strncpy(buffer,path,len); - } - - // something went horribly wrong - if(buffer == NULL) return NULL; - - pos = buffer[strlen(buffer) - 1]; - - // fix a path with trailing slashes - while(pos != buffer) - { - if(pos[0] == '/') - { - pos[0] = '\0'; - pos--; - continue; - } - - break; - } - - // something else went horribly wrong - if(pos == buffer) - { - free(buffer); - return NULL; - } -*/ diff --git a/utils/json.h b/utils/json.h deleted file mode 100644 index dca74f1..0000000 --- a/utils/json.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2013 Bryan Christ - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2, as published by - * the Free Software Foundation. - * - * This program 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 - * this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef _MFSHELL_JSON_H_ -#define _MFSHELL_JSON_H_ - -#include - -json_t *json_object_by_path(json_t * start, const char *path); - -#endif