ScummVM API documentation
curljsonrequest.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BACKENDS_NETWORKING_CURL_CURLJSONREQUEST_H
23 #define BACKENDS_NETWORKING_CURL_CURLJSONREQUEST_H
24 
25 #include "backends/networking/curl/curlrequest.h"
26 #include "common/memstream.h"
27 #include "common/formats/json.h"
28 
29 namespace Networking {
30 
31 typedef Response<const Common::JSONValue *> JsonResponse;
32 typedef Common::BaseCallback<const JsonResponse &> *JsonCallback;
33 typedef Common::BaseCallback<const Common::JSONValue *> *JSONValueCallback;
34 
35 #define CURL_JSON_REQUEST_BUFFER_SIZE 512 * 1024
36 
38 protected:
39  JsonCallback _jsonCallback;
40  Common::MemoryWriteStreamDynamic _contentsStream;
41  byte *_buffer;
42 
44  virtual void finishJson(const Common::JSONValue *json);
45 
46 public:
47  CurlJsonRequest(JsonCallback cb, ErrorCallback ecb, const Common::String &url);
48  ~CurlJsonRequest() override;
49 
50  void handle() override;
51  void restart() override;
52 
53  static bool jsonIsObject(const Common::JSONValue *item, const char *warningPrefix);
54  static bool jsonContainsObject(const Common::JSONObject &item, const char *key, const char *warningPrefix, bool isOptional = false);
55  static bool jsonContainsString(const Common::JSONObject &item, const char *key, const char *warningPrefix, bool isOptional = false);
56  static bool jsonContainsIntegerNumber(const Common::JSONObject &item, const char *key, const char *warningPrefix, bool isOptional = false);
57  static bool jsonContainsArray(const Common::JSONObject &item, const char *key, const char *warningPrefix, bool isOptional = false);
58  static bool jsonContainsStringOrIntegerNumber(const Common::JSONObject &item, const char *key, const char *warningPrefix, bool isOptional = false);
59  static bool jsonContainsAttribute(const Common::JSONObject &item, const char *key, const char *warningPrefix, bool isOptional = false);
60 };
61 
62 } // End of namespace Networking
63 
64 #endif
Definition: str.h:59
Definition: scummvmcloud.h:31
Definition: memstream.h:194
Definition: json.h:90
Definition: hashmap.h:85
virtual void finishJson(const Common::JSONValue *json)
Definition: curlrequest.h:41
Definition: curljsonrequest.h:37