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 
56  uint32 fillWithSendingContents(char *bufferToFill, uint32 maxSize);
57 
63  uint32 addResponseHeaders(char *buffer, uint32 bufferSize);
64 
65  NetworkReadStream(bool keepAlive, long keepAliveIdle, long keepAliveInterval)
66  : _backingStream(DisposeAfterUse::YES), _eos(false), _requestComplete(false), _sendingContentsBuffer(nullptr),
67  _sendingContentsSize(0), _sendingContentsPos(0), _progressDownloaded(0), _progressTotal(0),
68  _keepAlive(keepAlive), _keepAliveIdle(keepAliveIdle), _keepAliveInterval(keepAliveInterval) {
69  }
70 
71 public:
72  /* Implementation-defined Constructors */
73 
75  static NetworkReadStream *make(const char *url, RequestHeaders *headersList, const Common::String &postFields,
76  bool uploading = false, bool usingPatch = false,
77  bool keepAlive = false, long keepAliveIdle = 120, long keepAliveInterval = 60);
78 
80  static NetworkReadStream *make(const char *url, RequestHeaders *headersList,
82  bool keepAlive = false, long keepAliveIdle = 120, long keepAliveInterval = 60);
83 
85  static NetworkReadStream *make(const char *url, RequestHeaders *headersList, const byte *buffer, uint32 bufferSize,
86  bool uploading = false, bool usingPatch = false, bool post = true,
87  bool keepAlive = false, long keepAliveIdle = 120, long keepAliveInterval = 60);
88 
90  virtual bool reuse(const char *url, RequestHeaders *headersList, const Common::String &postFields, bool uploading = false, bool usingPatch = false) = 0;
92  virtual bool reuse(
93  const char *url, RequestHeaders *headersList,
97  virtual bool reuse(const char *url, RequestHeaders *headersList, const byte *buffer, uint32 bufferSize, bool uploading = false, bool usingPatch = false, bool post = true) = 0;
108  bool eos() const override { return _eos; }
109 
122  uint32 read(void *dataPtr, uint32 dataSize) override;
123 
130  virtual long httpResponseCode() const = 0;
131 
138  virtual Common::String currentLocation() const = 0;
139 
147 
149  double getProgress() const;
150 
152  void setProgress(uint64 downloaded, uint64 total);
153 
154  bool keepAlive() const { return _keepAlive; }
155 
156  virtual bool hasError() const = 0;
157  virtual const char *getError() const = 0;
158 };
159 
160 } // End of namespace Networking
161 
162 #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:108
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
uint32 addResponseHeaders(char *buffer, uint32 bufferSize)
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