diff options
author | Alexander Tkachev | 2016-07-22 20:02:36 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | f3959e140106334b33cf74832fc5b20d27407d0a (patch) | |
tree | 420bfa32f00fa24723176bd85dbc4b25cbda45df /backends/cloud | |
parent | f95073f0084b3fae3e2cbf14fd98135c37eabbdf (diff) | |
download | scummvm-rg350-f3959e140106334b33cf74832fc5b20d27407d0a.tar.gz scummvm-rg350-f3959e140106334b33cf74832fc5b20d27407d0a.tar.bz2 scummvm-rg350-f3959e140106334b33cf74832fc5b20d27407d0a.zip |
CLOUD: Upload ListDirectory Requests
Lots of checks to avoid JSON-related segfaults added.
Diffstat (limited to 'backends/cloud')
4 files changed, 54 insertions, 34 deletions
diff --git a/backends/cloud/box/boxlistdirectorybyidrequest.cpp b/backends/cloud/box/boxlistdirectorybyidrequest.cpp index 697ca48db7..0171b52a0f 100644 --- a/backends/cloud/box/boxlistdirectorybyidrequest.cpp +++ b/backends/cloud/box/boxlistdirectorybyidrequest.cpp @@ -43,15 +43,13 @@ BoxListDirectoryByIdRequest::BoxListDirectoryByIdRequest(BoxStorage *storage, Co BoxListDirectoryByIdRequest::~BoxListDirectoryByIdRequest() { _ignoreCallback = true; - if (_workingRequest) - _workingRequest->finish(); + if (_workingRequest) _workingRequest->finish(); delete _listDirectoryCallback; } void BoxListDirectoryByIdRequest::start() { _ignoreCallback = true; - if (_workingRequest) - _workingRequest->finish(); + if (_workingRequest) _workingRequest->finish(); _files.clear(); _ignoreCallback = false; @@ -76,8 +74,11 @@ void BoxListDirectoryByIdRequest::makeRequest(uint32 offset) { void BoxListDirectoryByIdRequest::responseCallback(Networking::JsonResponse response) { _workingRequest = nullptr; - if (_ignoreCallback) + if (_ignoreCallback) { + delete response.value; return; + } + if (response.request) _date = response.request->date(); @@ -103,7 +104,7 @@ void BoxListDirectoryByIdRequest::responseCallback(Networking::JsonResponse resp Common::JSONObject responseObject = json->asObject(); //debug(9, "%s", json->stringify(true).c_str()); - //TODO: check that error is returned the right way + //TODO: handle error messages passed as JSON /* if (responseObject.contains("error") || responseObject.contains("error_summary")) { warning("Box returned error: %s", responseObject.getVal("error_summary")->asString().c_str()); @@ -129,22 +130,15 @@ void BoxListDirectoryByIdRequest::responseCallback(Networking::JsonResponse resp Common::JSONArray items = responseObject.getVal("entries")->asArray(); for (uint32 i = 0; i < items.size(); ++i) { - if (!Networking::CurlJsonRequest::jsonIsObject(items[i], "BoxListDirectoryByIdRequest")) - continue; + if (!Networking::CurlJsonRequest::jsonIsObject(items[i], "BoxListDirectoryByIdRequest")) continue; Common::JSONObject item = items[i]->asObject(); - if (!Networking::CurlJsonRequest::jsonContainsString(item, "id", "BoxListDirectoryByIdRequest")) - continue; - if (!Networking::CurlJsonRequest::jsonContainsString(item, "name", "BoxListDirectoryByIdRequest")) - continue; - if (!Networking::CurlJsonRequest::jsonContainsString(item, "type", "BoxListDirectoryByIdRequest")) - continue; - if (!Networking::CurlJsonRequest::jsonContainsString(item, "modified_at", "BoxListDirectoryByIdRequest")) - continue; - if (!Networking::CurlJsonRequest::jsonContainsString(item, "size", "BoxListDirectoryByIdRequest") && - !Networking::CurlJsonRequest::jsonContainsIntegerNumber(item, "size", "BoxListDirectoryByIdRequest")) - continue; + if (!Networking::CurlJsonRequest::jsonContainsString(item, "id", "BoxListDirectoryByIdRequest")) continue; + if (!Networking::CurlJsonRequest::jsonContainsString(item, "name", "BoxListDirectoryByIdRequest")) continue; + if (!Networking::CurlJsonRequest::jsonContainsString(item, "type", "BoxListDirectoryByIdRequest")) continue; + if (!Networking::CurlJsonRequest::jsonContainsString(item, "modified_at", "BoxListDirectoryByIdRequest")) continue; + if (!Networking::CurlJsonRequest::jsonContainsStringOrIntegerNumber(item, "size", "BoxListDirectoryByIdRequest")) continue; Common::String id = item.getVal("id")->asString(); Common::String name = item.getVal("name")->asString(); @@ -172,20 +166,16 @@ void BoxListDirectoryByIdRequest::responseCallback(Networking::JsonResponse resp received += responseObject.getVal("limit")->asIntegerNumber(); bool hasMore = (received < totalCount); - if (hasMore) - makeRequest(received); - else - finishListing(_files); + if (hasMore) makeRequest(received); + else finishListing(_files); delete json; } void BoxListDirectoryByIdRequest::errorCallback(Networking::ErrorResponse error) { _workingRequest = nullptr; - if (_ignoreCallback) - return; - if (error.request) - _date = error.request->date(); + if (_ignoreCallback) return; + if (error.request) _date = error.request->date(); finishError(error); } @@ -197,8 +187,7 @@ Common::String BoxListDirectoryByIdRequest::date() const { return _date; } void BoxListDirectoryByIdRequest::finishListing(Common::Array<StorageFile> &files) { Request::finishSuccess(); - if (_listDirectoryCallback) - (*_listDirectoryCallback)(Storage::ListDirectoryResponse(this, files)); + if (_listDirectoryCallback) (*_listDirectoryCallback)(Storage::ListDirectoryResponse(this, files)); } } // End of namespace Box diff --git a/backends/cloud/dropbox/dropboxlistdirectoryrequest.cpp b/backends/cloud/dropbox/dropboxlistdirectoryrequest.cpp index def9155f4e..2e1d61812a 100644 --- a/backends/cloud/dropbox/dropboxlistdirectoryrequest.cpp +++ b/backends/cloud/dropbox/dropboxlistdirectoryrequest.cpp @@ -71,8 +71,10 @@ void DropboxListDirectoryRequest::start() { void DropboxListDirectoryRequest::responseCallback(Networking::JsonResponse response) { _workingRequest = nullptr; - if (_ignoreCallback) + if (_ignoreCallback) { + delete response.value; return; + } if (response.request) _date = response.request->date(); diff --git a/backends/cloud/googledrive/googledrivelistdirectorybyidrequest.cpp b/backends/cloud/googledrive/googledrivelistdirectorybyidrequest.cpp index d2e94a7196..5597d78704 100644 --- a/backends/cloud/googledrive/googledrivelistdirectorybyidrequest.cpp +++ b/backends/cloud/googledrive/googledrivelistdirectorybyidrequest.cpp @@ -72,8 +72,10 @@ void GoogleDriveListDirectoryByIdRequest::makeRequest(Common::String pageToken) void GoogleDriveListDirectoryByIdRequest::responseCallback(Networking::JsonResponse response) { _workingRequest = nullptr; - if (_ignoreCallback) + if (_ignoreCallback) { + delete response.value; return; + } if (response.request) _date = response.request->date(); diff --git a/backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp b/backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp index 30a89a79d0..069d6fdfb1 100644 --- a/backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp +++ b/backends/cloud/onedrive/onedrivelistdirectoryrequest.cpp @@ -104,20 +104,40 @@ void OneDriveListDirectoryRequest::listedDirectoryCallback(Networking::JsonRespo if (rq && rq->getNetworkReadStream()) error.httpResponseCode = rq->getNetworkReadStream()->httpResponseCode(); - if (!json) { - error.failed = true; + 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 object = json->asObject(); - //TODO: check that ALL keys exist AND HAVE RIGHT TYPE to avoid segfaults + //check that ALL keys exist AND HAVE RIGHT TYPE to avoid segfaults + if (!Networking::CurlJsonRequest::jsonContainsArray(object, "value", "OneDriveListDirectoryRequest")) { + error.response = "\"value\" not found or that's not an array!"; + finishError(error); + delete json; + return; + } Common::JSONArray items = object.getVal("value")->asArray(); for (uint32 i = 0; i < items.size(); ++i) { + if (!Networking::CurlJsonRequest::jsonIsObject(items[i], "OneDriveListDirectoryRequest")) continue; + Common::JSONObject item = items[i]->asObject(); + if (!Networking::CurlJsonRequest::jsonContainsAttribute(item, "folder", "OneDriveListDirectoryRequest", true)) continue; + if (!Networking::CurlJsonRequest::jsonContainsString(item, "name", "OneDriveListDirectoryRequest")) continue; + if (!Networking::CurlJsonRequest::jsonContainsIntegerNumber(item, "size", "OneDriveListDirectoryRequest")) continue; + if (!Networking::CurlJsonRequest::jsonContainsString(item, "lastModifiedDateTime", "OneDriveListDirectoryRequest")) continue; + Common::String path = _currentDirectory + item.getVal("name")->asString(); bool isDirectory = item.contains("folder"); uint32 size = item.getVal("size")->asIntegerNumber(); @@ -132,6 +152,13 @@ void OneDriveListDirectoryRequest::listedDirectoryCallback(Networking::JsonRespo bool hasMore = object.contains("@odata.nextLink"); if (hasMore) { + if (!Networking::CurlJsonRequest::jsonContainsString(object, "@odata.nextLink", "OneDriveListDirectoryRequest")) { + error.response = "\"@odata.nextLink\" is not a string!"; + finishError(error); + delete json; + return; + } + makeRequest(object.getVal("@odata.nextLink")->asString()); } else { listNextDirectory(); |