From d34b9b91add07c8bed2d2cef6421fc1b93b2e09e Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 26 Jul 2016 14:40:21 +0600 Subject: CLOUD: Update GoogleDriveUploadRequest JSON checks in callback. --- .../cloud/googledrive/googledriveuploadrequest.cpp | 68 +++++++++++----------- 1 file changed, 35 insertions(+), 33 deletions(-) (limited to 'backends/cloud') diff --git a/backends/cloud/googledrive/googledriveuploadrequest.cpp b/backends/cloud/googledrive/googledriveuploadrequest.cpp index 14f43eecde..5f61dcd2a8 100644 --- a/backends/cloud/googledrive/googledriveuploadrequest.cpp +++ b/backends/cloud/googledrive/googledriveuploadrequest.cpp @@ -275,44 +275,46 @@ void GoogleDriveUploadRequest::partUploadedCallback(Networking::JsonResponse res } Common::JSONValue *json = response.value; - if (json) { - if (json->isObject()) { - Common::JSONObject object = json->asObject(); - - if (object.contains("error")) { - warning("GoogleDrive returned error: %s", json->stringify(true).c_str()); - error.response = json->stringify(true); - finishError(error); - delete json; - return; - } + if (json == nullptr) { + error.response = "Failed to parse JSON, null passed!"; + finishError(error); + return; + } - if (object.contains("id") && object.contains("name")) { - //finished - Common::String id = object.getVal("id")->asString(); - Common::String name = object.getVal("name")->asString(); - bool isDirectory = (object.getVal("mimeType")->asString() == "application/vnd.google-apps.folder"); - uint32 size = 0, timestamp = 0; - if (object.contains("size") && object.getVal("size")->isString()) - size = object.getVal("size")->asString().asUint64(); - if (object.contains("modifiedTime") && object.getVal("modifiedTime")->isString()) - timestamp = ISO8601::convertToTimestamp(object.getVal("modifiedTime")->asString()); - - //as we list directory by id, we can't determine full path for the file, so we leave it empty - finishUpload(StorageFile(id, _savePath, name, size, timestamp, isDirectory)); - return; - } + if (json->isObject()) { + Common::JSONObject object = json->asObject(); + + if (object.contains("error")) { + warning("GoogleDrive returned error: %s", json->stringify(true).c_str()); + error.response = json->stringify(true); + finishError(error); + delete json; + return; } - if (_contentsStream->eos() || _contentsStream->pos() >= _contentsStream->size() - 1) { - warning("GoogleDriveUploadRequest: no file info to return"); - finishUpload(StorageFile(_savePath, 0, 0, false)); - } else { - uploadNextPart(); + if (Networking::CurlJsonRequest::jsonContainsString(object, "id", "GoogleDriveUploadRequest") && + Networking::CurlJsonRequest::jsonContainsString(object, "name", "GoogleDriveUploadRequest") && + Networking::CurlJsonRequest::jsonContainsString(object, "mimeType", "GoogleDriveUploadRequest")) { + //finished + Common::String id = object.getVal("id")->asString(); + Common::String name = object.getVal("name")->asString(); + bool isDirectory = (object.getVal("mimeType")->asString() == "application/vnd.google-apps.folder"); + uint32 size = 0, timestamp = 0; + if (Networking::CurlJsonRequest::jsonContainsString(object, "size", "GoogleDriveUploadRequest", true)) + size = object.getVal("size")->asString().asUint64(); + if (Networking::CurlJsonRequest::jsonContainsString(object, "modifiedTime", "GoogleDriveUploadRequest", true)) + timestamp = ISO8601::convertToTimestamp(object.getVal("modifiedTime")->asString()); + + finishUpload(StorageFile(id, _savePath, name, size, timestamp, isDirectory)); + return; } + } + + if (_contentsStream->eos() || _contentsStream->pos() >= _contentsStream->size() - 1) { + warning("GoogleDriveUploadRequest: no file info to return"); + finishUpload(StorageFile(_savePath, 0, 0, false)); } else { - warning("GoogleDriveUploadRequest: null, not json"); - finishError(error); + uploadNextPart(); } delete json; -- cgit v1.2.3