2016-07-07 16:57:14 +06:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BACKENDS_NETWORKING_SDL_NET_READER_H
|
|
|
|
#define BACKENDS_NETWORKING_SDL_NET_READER_H
|
|
|
|
|
|
|
|
#include "common/scummsys.h"
|
|
|
|
#include "common/str.h"
|
|
|
|
#include "common/hashmap.h"
|
|
|
|
#include "common/hash-str.h"
|
2016-07-08 13:31:47 +06:00
|
|
|
#include "common/random.h"
|
2016-07-07 16:57:14 +06:00
|
|
|
|
2016-07-08 11:53:53 +06:00
|
|
|
namespace Common {
|
2016-07-09 15:49:18 +06:00
|
|
|
class MemoryReadWriteStream;
|
2016-07-08 11:53:53 +06:00
|
|
|
class WriteStream;
|
|
|
|
}
|
|
|
|
|
2016-07-07 16:57:14 +06:00
|
|
|
namespace Networking {
|
|
|
|
|
2016-07-07 17:21:40 +06:00
|
|
|
enum ReaderState {
|
|
|
|
RS_NONE,
|
|
|
|
RS_READING_HEADERS,
|
|
|
|
RS_READING_CONTENT
|
|
|
|
};
|
|
|
|
|
2016-07-07 16:57:14 +06:00
|
|
|
class Reader {
|
2016-07-08 13:31:47 +06:00
|
|
|
Common::RandomSource _randomSource; //for temp file names
|
|
|
|
|
2016-07-07 17:21:40 +06:00
|
|
|
ReaderState _state;
|
2016-07-09 15:49:18 +06:00
|
|
|
Common::MemoryReadWriteStream *_content;
|
2016-07-07 17:21:40 +06:00
|
|
|
uint32 _bytesLeft;
|
2016-07-07 16:57:14 +06:00
|
|
|
|
2016-07-07 18:04:48 +06:00
|
|
|
byte *_window;
|
|
|
|
uint32 _windowUsed, _windowSize;
|
2016-07-07 16:57:14 +06:00
|
|
|
|
2016-07-07 17:21:40 +06:00
|
|
|
Common::String _headers;
|
2016-07-08 11:53:53 +06:00
|
|
|
Common::WriteStream *_stream;
|
2016-07-08 16:00:11 +06:00
|
|
|
bool _firstBlock;
|
2016-07-07 17:21:40 +06:00
|
|
|
|
2016-07-07 18:04:48 +06:00
|
|
|
///Common::String _headers;
|
|
|
|
Common::String _method, _path, _query, _anchor;
|
2016-07-07 18:18:34 +06:00
|
|
|
Common::HashMap<Common::String, Common::String> _queryParameters;
|
2016-07-07 16:57:14 +06:00
|
|
|
Common::HashMap<Common::String, Common::String> _attachedFiles;
|
2016-07-07 18:04:48 +06:00
|
|
|
uint32 _contentLength;
|
|
|
|
Common::String _boundary;
|
|
|
|
uint32 _availableBytes;
|
2016-07-08 12:28:33 +06:00
|
|
|
Common::String _currentFieldName, _currentFileName, _currentTempFileName;
|
2016-07-07 18:32:12 +06:00
|
|
|
bool _isFileField;
|
2016-07-07 18:04:48 +06:00
|
|
|
bool _isBadRequest;
|
2016-07-09 16:10:58 +06:00
|
|
|
bool _allContentRead;
|
2016-07-07 16:57:14 +06:00
|
|
|
|
2016-07-08 13:31:47 +06:00
|
|
|
void cleanup();
|
|
|
|
|
2016-07-09 15:49:18 +06:00
|
|
|
bool readWholeHeaders(); //true when ended reading
|
|
|
|
bool readWholeContent(); //true when ended reading
|
|
|
|
bool readWholeHeadersIntoStream(Common::WriteStream *stream); //true when ended reading
|
|
|
|
bool readWholeContentIntoStream(Common::WriteStream *stream); //true when ended reading
|
2016-07-07 16:57:14 +06:00
|
|
|
void handleHeaders(Common::String headers);
|
|
|
|
void handleFileContent(Common::String filename);
|
|
|
|
void handleValueContent(Common::String value);
|
|
|
|
|
2016-07-07 18:04:48 +06:00
|
|
|
void parseFirstLine(const Common::String &headers);
|
|
|
|
void parsePathQueryAndAnchor(Common::String path);
|
2016-07-07 18:18:34 +06:00
|
|
|
void parseQueryParameters();
|
2016-07-07 18:04:48 +06:00
|
|
|
|
2016-07-07 16:57:14 +06:00
|
|
|
void makeWindow(uint32 size);
|
2016-07-07 17:21:40 +06:00
|
|
|
void freeWindow();
|
2016-07-08 13:42:48 +06:00
|
|
|
bool readOneByteInStream(Common::WriteStream *stream, const Common::String &boundary);
|
|
|
|
bool readOneByteInString(Common::String &buffer, const Common::String &boundary);
|
2016-07-07 16:57:14 +06:00
|
|
|
|
|
|
|
byte readOne();
|
2016-07-07 17:21:40 +06:00
|
|
|
uint32 bytesLeft();
|
2016-07-07 16:57:14 +06:00
|
|
|
|
|
|
|
public:
|
|
|
|
Reader();
|
|
|
|
~Reader();
|
|
|
|
|
2016-07-08 13:31:47 +06:00
|
|
|
Reader &operator=(Reader &r);
|
|
|
|
|
2016-07-09 15:49:18 +06:00
|
|
|
bool readWholeRequest(); //true when ended reading
|
|
|
|
bool readFirstHeaders(); //true when ended reading
|
|
|
|
bool readFirstContent(Common::WriteStream *stream); //true when ended reading
|
|
|
|
bool readBlockHeaders(Common::WriteStream *stream); //true when ended reading
|
|
|
|
bool readBlockContent(Common::WriteStream *stream); //true when ended reading
|
|
|
|
void setContent(Common::MemoryReadWriteStream *stream);
|
2016-07-09 16:10:58 +06:00
|
|
|
bool badRequest() const;
|
|
|
|
bool noMoreContent() const;
|
2016-07-07 18:04:48 +06:00
|
|
|
|
|
|
|
Common::String method() const;
|
|
|
|
Common::String path() const;
|
|
|
|
Common::String query() const;
|
2016-07-07 18:18:34 +06:00
|
|
|
Common::String queryParameter(Common::String name) const;
|
2016-07-08 16:00:11 +06:00
|
|
|
Common::String attachedFile(Common::String name) const;
|
2016-07-07 18:04:48 +06:00
|
|
|
Common::String anchor() const;
|
2016-07-07 16:57:14 +06:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End of namespace Networking
|
|
|
|
|
|
|
|
#endif
|