aboutsummaryrefslogtreecommitdiff
path: root/backends/networking/curl/curljsonrequest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'backends/networking/curl/curljsonrequest.cpp')
-rw-r--r--backends/networking/curl/curljsonrequest.cpp41
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