aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorAlexander Tkachev2016-07-08 11:53:53 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit80cc3469e7a00c7c7eab5d8bfad0dcae8f05875f (patch)
tree536db5ad2e898d97e29bc3555144903740ab4672 /backends
parent83957c9666fce2e4b536c0974f22fc70f57b119c (diff)
downloadscummvm-rg350-80cc3469e7a00c7c7eab5d8bfad0dcae8f05875f.tar.gz
scummvm-rg350-80cc3469e7a00c7c7eab5d8bfad0dcae8f05875f.tar.bz2
scummvm-rg350-80cc3469e7a00c7c7eab5d8bfad0dcae8f05875f.zip
CLOUD: Add Reader::readOneByteInStream()
Diffstat (limited to 'backends')
-rw-r--r--backends/networking/sdl_net/reader.cpp38
-rw-r--r--backends/networking/sdl_net/reader.h7
2 files changed, 34 insertions, 11 deletions
diff --git a/backends/networking/sdl_net/reader.cpp b/backends/networking/sdl_net/reader.cpp
index 025f53492a..19c5b0a088 100644
--- a/backends/networking/sdl_net/reader.cpp
+++ b/backends/networking/sdl_net/reader.cpp
@@ -25,6 +25,8 @@
#include "backends/networking/sdl_net/reader.h"
#include "backends/networking/sdl_net/localwebserver.h"
#include "common/debug.h"
+#include "common/stream.h"
+#include "common/memstream.h"
namespace Networking {
@@ -39,6 +41,7 @@ Reader::Reader() {
_headers = "";
_buffer = "";
+ _stream = nullptr;
_contentLength = 0;
_availableBytes = 0;
@@ -46,7 +49,11 @@ Reader::Reader() {
_isBadRequest = false;
}
-Reader::~Reader() {}
+Reader::~Reader() {
+ //TODO: free everything
+ if (_window != nullptr) freeWindow();
+ delete _stream;
+}
bool Reader::readRequest() {
if (_state == RS_NONE) _state = RS_READING_HEADERS;
@@ -261,6 +268,9 @@ bool Reader::readContent() {
if (_window == nullptr) {
makeWindow(boundary.size());
_buffer = "";
+
+ if (_stream) delete _stream;
+ _stream = new Common::MemoryReadWriteStream(DisposeAfterUse::YES);
}
/*
@@ -273,10 +283,20 @@ bool Reader::readContent() {
handleFileContent(tempFileName);
} else {
*/
- while (readOneByteInString(_buffer, boundary)) {
+ while (readOneByteInStream(_stream, boundary)) {
if (!bytesLeft()) return false;
}
- handleValueContent(_buffer);
+ Common::MemoryReadWriteStream *dynamicStream = dynamic_cast<Common::MemoryReadWriteStream *>(_stream);
+ if (dynamicStream != nullptr)
+ if (dynamicStream->size() == 0)
+ handleValueContent("");
+ else
+ handleValueContent(Common::String((char *)dynamicStream->getData(), dynamicStream->size()));
+ else
+ if (_stream != nullptr)
+ warning("Stream somehow changed its type from MemoryReadWriteStream!");
+ else
+ warning("No stream was created!");
//}
freeWindow();
@@ -307,24 +327,22 @@ void Reader::freeWindow() {
_windowUsed = _windowSize = 0;
}
-/*
-bool Reader::readOneByteInStream(stream) {
- b = read(1);
+bool Reader::readOneByteInStream(Common::WriteStream *stream, const Common::String &boundary) {
+ byte b = readOne();
_window[_windowUsed++] = b;
if (_windowUsed < _windowSize) return true;
//when window is filled, check whether that's the boundary
- if (_window == "--" + _boundary)
+ if (Common::String((char *)_window, _windowSize) == boundary)
return false;
- //if not, write the first byte of the window to the stream
- stream.write(_window[0]);
+ //if not, add the first byte of the window to the string
+ stream->writeByte(_window[0]);
for (uint32 i = 1; i < _windowSize; ++i)
_window[i - 1] = _window[i];
--_windowUsed;
return true;
}
-*/
bool Reader::readOneByteInString(Common::String &buffer, const Common::String &boundary) {
byte b = readOne();
diff --git a/backends/networking/sdl_net/reader.h b/backends/networking/sdl_net/reader.h
index 74fcd4320f..5f5770149b 100644
--- a/backends/networking/sdl_net/reader.h
+++ b/backends/networking/sdl_net/reader.h
@@ -28,6 +28,10 @@
#include "common/hashmap.h"
#include "common/hash-str.h"
+namespace Common {
+class WriteStream;
+}
+
namespace Networking {
enum ReaderState {
@@ -46,6 +50,7 @@ class Reader {
Common::String _headers;
Common::String _buffer;
+ Common::WriteStream *_stream;
///Common::String _headers;
Common::String _method, _path, _query, _anchor;
@@ -70,7 +75,7 @@ class Reader {
void makeWindow(uint32 size);
void freeWindow();
- ///bool Reader::readOneByteInStream(stream);
+ bool Reader::readOneByteInStream(Common::WriteStream *stream, const Common::String &boundary);
bool Reader::readOneByteInString(Common::String &buffer, const Common::String &boundary);
byte readOne();