diff options
author | Alexander Tkachev | 2016-07-26 14:40:21 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | d34b9b91add07c8bed2d2cef6421fc1b93b2e09e (patch) | |
tree | bedf1921104178b44e8791978693c5d4008a2047 /backends/cloud | |
parent | a381e06fda82508d16367b9999593de45c907e90 (diff) | |
download | scummvm-rg350-d34b9b91add07c8bed2d2cef6421fc1b93b2e09e.tar.gz scummvm-rg350-d34b9b91add07c8bed2d2cef6421fc1b93b2e09e.tar.bz2 scummvm-rg350-d34b9b91add07c8bed2d2cef6421fc1b93b2e09e.zip |
CLOUD: Update GoogleDriveUploadRequest
JSON checks in callback.
Diffstat (limited to 'backends/cloud')
-rw-r--r-- | backends/cloud/googledrive/googledriveuploadrequest.cpp | 68 |
1 files changed, 35 insertions, 33 deletions
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; |