diff options
author | Alexander Tkachev | 2016-07-26 14:19:37 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | b3aa9f663f3ac0ac325225c1eaf8f78fb8bf9009 (patch) | |
tree | f9a081c9fa737d4c080f3497ea7947abda3e5738 /backends/cloud/dropbox | |
parent | 364c74df930633bf897cacf391f6dc24dbc183b8 (diff) | |
download | scummvm-rg350-b3aa9f663f3ac0ac325225c1eaf8f78fb8bf9009.tar.gz scummvm-rg350-b3aa9f663f3ac0ac325225c1eaf8f78fb8bf9009.tar.bz2 scummvm-rg350-b3aa9f663f3ac0ac325225c1eaf8f78fb8bf9009.zip |
CLOUD: Update DropboxUploadRequest
JSON checks.
Diffstat (limited to 'backends/cloud/dropbox')
-rw-r--r-- | backends/cloud/dropbox/dropboxuploadrequest.cpp | 70 |
1 files changed, 36 insertions, 34 deletions
diff --git a/backends/cloud/dropbox/dropboxuploadrequest.cpp b/backends/cloud/dropbox/dropboxuploadrequest.cpp index dd3a381b7a..945493b1eb 100644 --- a/backends/cloud/dropbox/dropboxuploadrequest.cpp +++ b/backends/cloud/dropbox/dropboxuploadrequest.cpp @@ -132,51 +132,53 @@ void DropboxUploadRequest::partUploadedCallback(Networking::JsonResponse respons if (rq && rq->getNetworkReadStream()) error.httpResponseCode = rq->getNetworkReadStream()->httpResponseCode(); - // TODO: add more JSON-related warnings Common::JSONValue *json = response.value; - if (json) { - bool needsFinishRequest = false; + if (json == nullptr) { + error.response = "Failed to parse JSON, null passed!"; + finishError(error); + return; + } - if (json->isObject()) { - Common::JSONObject object = json->asObject(); + bool needsFinishRequest = false; - //debug(9, "%s", json->stringify(true).c_str()); + if (json->isObject()) { + Common::JSONObject object = json->asObject(); - if (object.contains("error") || object.contains("error_summary")) { - warning("Dropbox returned error: %s", object.getVal("error_summary")->asString().c_str()); - error.response = json->stringify(true); - finishError(error); - delete json; - return; - } + //debug(9, "%s", json->stringify(true).c_str()); - if (object.contains("server_modified")) { - //finished - Common::String path = object.getVal("path_lower")->asString(); - uint32 size = object.getVal("size")->asIntegerNumber(); - uint32 timestamp = ISO8601::convertToTimestamp(object.getVal("server_modified")->asString()); - finishUpload(StorageFile(path, size, timestamp, false)); - return; + if (object.contains("error") || object.contains("error_summary")) { + if (Networking::CurlJsonRequest::jsonContainsString(object, "error_summary", "DropboxUploadRequest")) { + warning("Dropbox returned error: %s", object.getVal("error_summary")->asString().c_str()); } + error.response = json->stringify(true); + finishError(error); + delete json; + return; + } - if (_sessionId == "") { - if (object.contains("session_id")) - _sessionId = object.getVal("session_id")->asString(); - else - warning("DropboxUploadRequest: no session_id found"); - needsFinishRequest = true; - } + if (Networking::CurlJsonRequest::jsonContainsString(object, "path_lower", "DropboxUploadRequest") && + Networking::CurlJsonRequest::jsonContainsString(object, "server_modified", "DropboxUploadRequest") && + Networking::CurlJsonRequest::jsonContainsIntegerNumber(object, "size", "DropboxUploadRequest")) { + //finished + Common::String path = object.getVal("path_lower")->asString(); + uint32 size = object.getVal("size")->asIntegerNumber(); + uint32 timestamp = ISO8601::convertToTimestamp(object.getVal("server_modified")->asString()); + finishUpload(StorageFile(path, size, timestamp, false)); + return; } - if (!needsFinishRequest && (_contentsStream->eos() || _contentsStream->pos() >= _contentsStream->size() - 1)) { - warning("DropboxUploadRequest: no file info to return"); - finishUpload(StorageFile(_savePath, 0, 0, false)); - } else { - uploadNextPart(); + if (_sessionId == "") { + if (Networking::CurlJsonRequest::jsonContainsString(object, "session_id", "DropboxUploadRequest")) + _sessionId = object.getVal("session_id")->asString(); + needsFinishRequest = true; } + } + + if (!needsFinishRequest && (_contentsStream->eos() || _contentsStream->pos() >= _contentsStream->size() - 1)) { + warning("DropboxUploadRequest: no file info to return"); + finishUpload(StorageFile(_savePath, 0, 0, false)); } else { - warning("DropboxUploadRequest: null, not json"); - finishError(error); + uploadNextPart(); } delete json; |