aboutsummaryrefslogtreecommitdiff
path: root/backends/cloud
diff options
context:
space:
mode:
authorAlexander Tkachev2016-07-26 14:59:01 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commitd5aca1f4fae400250b87d35e3517416dd4f26a8f (patch)
tree8e44798bbfa9631638609b025849a26df7cebcbc /backends/cloud
parentfc8e29d5832728a513cab0f10be218c6a632758a (diff)
downloadscummvm-rg350-d5aca1f4fae400250b87d35e3517416dd4f26a8f.tar.gz
scummvm-rg350-d5aca1f4fae400250b87d35e3517416dd4f26a8f.tar.bz2
scummvm-rg350-d5aca1f4fae400250b87d35e3517416dd4f26a8f.zip
CLOUD: Update OneDriveUploadRequest
More JSON checks.
Diffstat (limited to 'backends/cloud')
-rw-r--r--backends/cloud/onedrive/onedriveuploadrequest.cpp70
1 files changed, 36 insertions, 34 deletions
diff --git a/backends/cloud/onedrive/onedriveuploadrequest.cpp b/backends/cloud/onedrive/onedriveuploadrequest.cpp
index 172266ce2a..41e6e2a37b 100644
--- a/backends/cloud/onedrive/onedriveuploadrequest.cpp
+++ b/backends/cloud/onedrive/onedriveuploadrequest.cpp
@@ -125,44 +125,46 @@ void OneDriveUploadRequest::partUploadedCallback(Networking::JsonResponse respon
error.httpResponseCode = rq->getNetworkReadStream()->httpResponseCode();
Common::JSONValue *json = response.value;
- if (json) {
- if (json->isObject()) {
- Common::JSONObject object = json->asObject();
-
- if (object.contains("error")) {
- warning("OneDriveUploadRequest: error: %s", json->stringify(true).c_str());
- error.response = json->stringify(true);
- finishError(error);
- delete json;
- return;
- }
-
- if (object.contains("id") && object.contains("name")) {
- //finished
- Common::String path = _savePath;
- uint32 size = object.getVal("size")->asIntegerNumber();
- uint32 timestamp = ISO8601::convertToTimestamp(object.getVal("lastModifiedDateTime")->asString());
- finishUpload(StorageFile(path, size, timestamp, false));
- return;
- }
-
- if (_uploadUrl == "") {
- if (object.contains("uploadUrl"))
- _uploadUrl = object.getVal("uploadUrl")->asString();
- else
- warning("OneDriveUploadRequest: no uploadUrl found");
- }
+ if (json == nullptr) {
+ error.response = "Failed to parse JSON, null passed!";
+ finishError(error);
+ return;
+ }
+
+ if (json->isObject()) {
+ Common::JSONObject object = json->asObject();
+
+ if (object.contains("error")) {
+ warning("OneDriveUploadRequest: 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("OneDriveUploadRequest: no file info to return");
- finishUpload(StorageFile(_savePath, 0, 0, false));
- } else {
- uploadNextPart();
+ if (Networking::CurlJsonRequest::jsonContainsString(object, "id", "OneDriveUploadRequest") &&
+ Networking::CurlJsonRequest::jsonContainsString(object, "name", "OneDriveUploadRequest") &&
+ Networking::CurlJsonRequest::jsonContainsIntegerNumber(object, "size", "OneDriveUploadRequest") &&
+ Networking::CurlJsonRequest::jsonContainsString(object, "lastModifiedDateTime", "OneDriveUploadRequest")) {
+ //finished
+ Common::String path = _savePath;
+ uint32 size = object.getVal("size")->asIntegerNumber();
+ uint32 timestamp = ISO8601::convertToTimestamp(object.getVal("lastModifiedDateTime")->asString());
+ finishUpload(StorageFile(path, size, timestamp, false));
+ return;
}
+
+ if (_uploadUrl == "") {
+ if (Networking::CurlJsonRequest::jsonContainsString(object, "uploadUrl", "OneDriveUploadRequest"))
+ _uploadUrl = object.getVal("uploadUrl")->asString();
+ }
+ }
+
+ if (_contentsStream->eos() || _contentsStream->pos() >= _contentsStream->size() - 1) {
+ warning("OneDriveUploadRequest: no file info to return");
+ finishUpload(StorageFile(_savePath, 0, 0, false));
} else {
- warning("OneDriveUploadRequest: null, not json");
- finishError(error);
+ uploadNextPart();
}
delete json;