mirror of
https://github.com/xorgy/mediafire-fuse
synced 2026-01-13 13:14:29 -08:00
remove json_object_by_path
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#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) {
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#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)) {
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#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) {
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#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) {
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#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) {
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <time.h>
|
||||
|
||||
#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)
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#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) {
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#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)) {
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <time.h>
|
||||
|
||||
#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)
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#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");
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <openssl/sha.h>
|
||||
|
||||
#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) {
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#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)
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#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) {
|
||||
|
||||
104
utils/json.c
104
utils/json.c
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
||||
*
|
||||
* 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 <stdlib.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
*/
|
||||
26
utils/json.h
26
utils/json.h
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Bryan Christ <bryan.christ@mediafire.com>
|
||||
*
|
||||
* 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 <jansson.h>
|
||||
|
||||
json_t *json_object_by_path(json_t * start, const char *path);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user