ScummVM API documentation
networkreadstream.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_HTTP_NETWORKREADSTREAM_H
23 #define BACKENDS_NETWORKING_HTTP_NETWORKREADSTREAM_H
24 
25 #include "common/array.h"
26 #include "common/hash-str.h"
27 #include "common/hashmap.h"
28 #include "common/memstream.h"
29 #include "common/path.h"
30 #include "common/str.h"
31 #include "common/stream.h"
32 
33 namespace Networking {
34 typedef Common::Array<Common::String> RequestHeaders;
35 
36 // Simple interface for platform-specific NetworkReadStream implementations
38 protected:
39  Common::MemoryReadWriteStream _backingStream;
40  bool _keepAlive;
41  long _keepAliveIdle, _keepAliveInterval;
42  bool _eos, _requestComplete;
43  const byte *_sendingContentsBuffer;
44  uint32 _sendingContentsSize;
45  uint32 _sendingContentsPos;
46  Common::String _responseHeaders;
47  uint64 _progressDownloaded, _progressTotal;
48 
55  virtual void resetStream() = 0;
56 
57  virtual void setupBufferContents(const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post) = 0;
58  virtual void setupFormMultipart(const Common::HashMap<Common::String, Common::String> &formFields, const Common::HashMap<Common::String, Common::Path> &formFiles) = 0;
59 
67  uint32 fillWithSendingContents(char *bufferToFill, uint32 maxSize);
68 
74  uint32 addResponseHeaders(char *buffer, uint32 bufferSize);
75 
76  NetworkReadStream(bool keepAlive, long keepAliveIdle, long keepAliveInterval)
77  : _backingStream(DisposeAfterUse::YES), _eos(false), _requestComplete(false), _sendingContentsBuffer(nullptr),
78  _sendingContentsSize(0), _sendingContentsPos(0), _progressDownloaded(0), _progressTotal(0),
79  _keepAlive(keepAlive), _keepAliveIdle(keepAliveIdle), _keepAliveInterval(keepAliveInterval) {
80  }
81 
82 public:
83  /* Implementation-defined Constructors */
84 
86  static NetworkReadStream *make(const char *url, RequestHeaders *headersList, const Common::String &postFields,
87  bool uploading = false, bool usingPatch = false,
88  bool keepAlive = false, long keepAliveIdle = 120, long keepAliveInterval = 60);
89 
91  static NetworkReadStream *make(const char *url, RequestHeaders *headersList,
93  bool keepAlive = false, long keepAliveIdle = 120, long keepAliveInterval = 60);
94 
96  static NetworkReadStream *make(const char *url, RequestHeaders *headersList, const byte *buffer, uint32 bufferSize,
97  bool uploading = false, bool usingPatch = false, bool post = true,
98  bool keepAlive = false, long keepAliveIdle = 120, long keepAliveInterval = 60);
99 
101  virtual bool reuse(const char *url, RequestHeaders *headersList, const Common::String &postFields, bool uploading = false, bool usingPatch = false) = 0;
103  virtual bool reuse(
104  const char *url, RequestHeaders *headersList,
106  const Common::HashMap<Common::String, Common::Path> &formFiles) = 0;
108  virtual bool reuse(const char *url, RequestHeaders *headersList, const byte *buffer, uint32 bufferSize, bool uploading = false, bool usingPatch = false, bool post = true) = 0;
119  bool eos() const override { return _eos; }
120 
133  uint32 read(void *dataPtr, uint32 dataSize) override;
134 
141  virtual long httpResponseCode() const = 0;
142 
149  virtual Common::String currentLocation() const = 0;
150 
157  return _responseHeaders;
158  }
159 
167 
169  double getProgress() const;
170 
172  void setProgress(uint64 downloaded, uint64 total);
173 
174  bool keepAlive() const { return _keepAlive; }
175 
176  virtual bool hasError() const = 0;
177  virtual const char *getError() const = 0;
178 };
179 
180 } // End of namespace Networking
181 
182 #endif
virtual Common::HashMap< Common::String, Common::String > responseHeadersMap() const =0
void setProgress(uint64 downloaded, uint64 total)
Definition: str.h:59
virtual bool reuse(const char *url, RequestHeaders *headersList, const Common::String &postFields, bool uploading=false, bool usingPatch=false)=0
Definition: scummvmcloud.h:32
bool eos() const override
Definition: networkreadstream.h:119
static NetworkReadStream * make(const char *url, RequestHeaders *headersList, const Common::String &postFields, bool uploading=false, bool usingPatch=false, bool keepAlive=false, long keepAliveIdle=120, long keepAliveInterval=60)
virtual long httpResponseCode() const =0
virtual void resetStream()=0
uint32 addResponseHeaders(char *buffer, uint32 bufferSize)
Common::String responseHeaders() const
Definition: networkreadstream.h:156
Definition: memstream.h:283
uint32 fillWithSendingContents(char *bufferToFill, uint32 maxSize)
Definition: networkreadstream.h:37
uint32 read(void *dataPtr, uint32 dataSize) override
virtual Common::String currentLocation() const =0
Definition: stream.h:385