diff options
author | Alexander Tkachev | 2016-07-26 14:10:54 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | 6be736b5ed92800e1cd329d0de4ed0bb7ff2ea38 (patch) | |
tree | d94a5681d7ef387f9684d0715f5eb5d62a9eb60d /backends/cloud | |
parent | a2e019972779575bcc9038949bca73d78f7bf07b (diff) | |
download | scummvm-rg350-6be736b5ed92800e1cd329d0de4ed0bb7ff2ea38.tar.gz scummvm-rg350-6be736b5ed92800e1cd329d0de4ed0bb7ff2ea38.tar.bz2 scummvm-rg350-6be736b5ed92800e1cd329d0de4ed0bb7ff2ea38.zip |
CLOUD: Update Dropbox Requests
Adding more JSON checks there.
Diffstat (limited to 'backends/cloud')
-rw-r--r-- | backends/cloud/dropbox/dropboxcreatedirectoryrequest.cpp | 14 | ||||
-rw-r--r-- | backends/cloud/dropbox/dropboxinforequest.cpp | 65 |
2 files changed, 65 insertions, 14 deletions
diff --git a/backends/cloud/dropbox/dropboxcreatedirectoryrequest.cpp b/backends/cloud/dropbox/dropboxcreatedirectoryrequest.cpp index 6cc6801bc0..97090b44f8 100644 --- a/backends/cloud/dropbox/dropboxcreatedirectoryrequest.cpp +++ b/backends/cloud/dropbox/dropboxcreatedirectoryrequest.cpp @@ -79,19 +79,27 @@ void DropboxCreateDirectoryRequest::responseCallback(Networking::JsonResponse re if (rq && rq->getNetworkReadStream()) error.httpResponseCode = rq->getNetworkReadStream()->httpResponseCode(); - if (!json) { - warning("DropboxCreateDirectoryRequest: NULL passed instead of JSON"); + if (json == nullptr) { + error.response = "Failed to parse JSON, null passed!"; finishError(error); return; } + if (!json->isObject()) { + error.response = "Passed JSON is not an object!"; + finishError(error); + delete json; + return; + } + Common::JSONObject info = json->asObject(); if (info.contains("id")) { finishCreation(true); } else { - if (info.contains("error_summary") && info.getVal("error_summary")->isString()) { + if (Networking::CurlJsonRequest::jsonContainsString(info, "error_summary", "DropboxCreateDirectoryRequest")) { Common::String summary = info.getVal("error_summary")->asString(); if (summary.contains("path") && summary.contains("conflict") && summary.contains("folder")) { + // existing directory - not an error for CreateDirectoryRequest finishCreation(false); delete json; return; diff --git a/backends/cloud/dropbox/dropboxinforequest.cpp b/backends/cloud/dropbox/dropboxinforequest.cpp index c5cbb9d917..6cdbe3321b 100644 --- a/backends/cloud/dropbox/dropboxinforequest.cpp +++ b/backends/cloud/dropbox/dropboxinforequest.cpp @@ -76,18 +76,34 @@ void DropboxInfoRequest::userResponseCallback(Networking::JsonResponse response) if (rq && rq->getNetworkReadStream()) error.httpResponseCode = rq->getNetworkReadStream()->httpResponseCode(); - if (!json) { - warning("DropboxInfoRequest: NULL passed instead of JSON"); + if (json == nullptr) { + error.response = "Failed to parse JSON, null passed!"; finishError(error); return; } + if (!json->isObject()) { + error.response = "Passed JSON is not an object!"; + finishError(error); + delete json; + return; + } + //Dropbox documentation states there are no errors for this API method Common::JSONObject info = json->asObject(); - Common::JSONObject nameInfo = info.getVal("name")->asObject(); - _uid = info.getVal("account_id")->asString(); - _name = nameInfo.getVal("display_name")->asString(); - _email = info.getVal("email")->asString(); + if (Networking::CurlJsonRequest::jsonContainsAttribute(info, "name", "DropboxInfoRequest") && + Networking::CurlJsonRequest::jsonIsObject(info.getVal("name"), "DropboxInfoRequest")) { + Common::JSONObject nameInfo = info.getVal("name")->asObject(); + if (Networking::CurlJsonRequest::jsonContainsString(nameInfo, "display_name", "DropboxInfoRequest")) { + _name = nameInfo.getVal("display_name")->asString(); + } + } + if (Networking::CurlJsonRequest::jsonContainsString(info, "account_id", "DropboxInfoRequest")) { + _uid = info.getVal("account_id")->asString(); + } + if (Networking::CurlJsonRequest::jsonContainsString(info, "email", "DropboxInfoRequest")) { + _email = info.getVal("email")->asString(); + } CloudMan.setStorageUsername(kStorageDropboxId, _email); delete json; @@ -114,17 +130,44 @@ void DropboxInfoRequest::quotaResponseCallback(Networking::JsonResponse response if (rq && rq->getNetworkReadStream()) error.httpResponseCode = rq->getNetworkReadStream()->httpResponseCode(); - if (!json) { - warning("DropboxInfoRequest: NULL passed instead of JSON"); + if (json == nullptr) { + error.response = "Failed to parse JSON, null passed!"; finishError(error); return; } + if (!json->isObject()) { + error.response = "Passed JSON is not an object!"; + finishError(error); + delete json; + return; + } + //Dropbox documentation states there are no errors for this API method Common::JSONObject info = json->asObject(); - Common::JSONObject allocation = info.getVal("allocation")->asObject(); - uint64 used = info.getVal("used")->asIntegerNumber(); - uint64 allocated = allocation.getVal("allocated")->asIntegerNumber(); + + if (!Networking::CurlJsonRequest::jsonContainsIntegerNumber(info, "used", "DropboxInfoRequest")) { + error.response = "Passed JSON misses 'used' attribute!"; + finishError(error); + delete json; + return; + } + + uint64 used = info.getVal("used")->asIntegerNumber(), allocated = 0; + + if (Networking::CurlJsonRequest::jsonContainsAttribute(info, "allocation", "DropboxInfoRequest") && + Networking::CurlJsonRequest::jsonIsObject(info.getVal("allocation"), "DropboxInfoRequest")) { + Common::JSONObject allocation = info.getVal("allocation")->asObject(); + if (!Networking::CurlJsonRequest::jsonContainsIntegerNumber(allocation, "allocated", "DropboxInfoRequest")) { + error.response = "Passed JSON misses 'allocation/allocated' attribute!"; + finishError(error); + delete json; + return; + } + + allocated = allocation.getVal("allocated")->asIntegerNumber(); + } + finishInfo(StorageInfo(_uid, _name, _email, used, allocated)); delete json; } |