diff options
author | Alexander Tkachev | 2016-07-22 18:27:49 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | cccfe7c247fed9b00c100e64433439386d6ef077 (patch) | |
tree | 91316ef86d15857b03aa5be8bafc1321cadc1b8e /backends/networking/curl/curljsonrequest.cpp | |
parent | 43c940c98579e669826de838eff9dcb372d453f7 (diff) | |
download | scummvm-rg350-cccfe7c247fed9b00c100e64433439386d6ef077.tar.gz scummvm-rg350-cccfe7c247fed9b00c100e64433439386d6ef077.tar.bz2 scummvm-rg350-cccfe7c247fed9b00c100e64433439386d6ef077.zip |
CLOUD: Update BoxListDirectoryByIdRequest
It now uses special CurlJsonRequest static methods to check whether JSON
is an object, has a string or integer parameter.
Diffstat (limited to 'backends/networking/curl/curljsonrequest.cpp')
-rw-r--r-- | backends/networking/curl/curljsonrequest.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/backends/networking/curl/curljsonrequest.cpp b/backends/networking/curl/curljsonrequest.cpp index 875f5e7fbd..7f7cbca2e0 100644 --- a/backends/networking/curl/curljsonrequest.cpp +++ b/backends/networking/curl/curljsonrequest.cpp @@ -31,7 +31,7 @@ namespace Networking { -CurlJsonRequest::CurlJsonRequest(JsonCallback cb, ErrorCallback ecb, Common::String url): +CurlJsonRequest::CurlJsonRequest(JsonCallback cb, ErrorCallback ecb, Common::String url) : CurlRequest(nullptr, ecb, url), _jsonCallback(cb), _contentsStream(DisposeAfterUse::YES), _buffer(new byte[CURL_JSON_REQUEST_BUFFER_SIZE]) {} @@ -97,4 +97,43 @@ void CurlJsonRequest::finishJson(Common::JSONValue *json) { else delete json; } +bool CurlJsonRequest::jsonIsObject(Common::JSONValue *item, const char *warningPrefix) { + if (item == nullptr) { + warning("%s: passed item is NULL", warningPrefix); + return false; + } + + if (item->isObject()) return true; + + warning("%s: passed item is not an object!", warningPrefix); + debug(9, "%s", item->stringify(true).c_str()); + return false; +} + +bool CurlJsonRequest::jsonContainsString(Common::JSONObject &item, const char *key, const char *warningPrefix) { + if (!item.contains(key)) { + warning("%s: passed item misses the \"%s\" attribute!", warningPrefix, key); + return false; + } + + if (item.getVal(key)->isString()) return true; + + warning("%s: passed item's \"%s\" attribute is not a string!", warningPrefix, key); + debug(9, "%s", item.getVal(key)->stringify(true).c_str()); + return false; +} + +bool CurlJsonRequest::jsonContainsIntegerNumber(Common::JSONObject &item, const char *key, const char *warningPrefix) { + if (!item.contains(key)) { + warning("%s: passed item misses the \"%s\" attribute!", warningPrefix, key); + return false; + } + + if (item.getVal(key)->isIntegerNumber()) return true; + + warning("%s: passed item's \"%s\" attribute is not an integer!", warningPrefix, key); + debug(9, "%s", item.getVal(key)->stringify(true).c_str()); + return false; +} + } // End of namespace Networking |