ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

reader.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef BACKENDS_NETWORKING_SDL_NET_READER_H
00024 #define BACKENDS_NETWORKING_SDL_NET_READER_H
00025 
00026 #include "common/str.h"
00027 #include "common/hashmap.h"
00028 #include "common/hash-str.h"
00029 
00030 namespace Common {
00031 class MemoryReadWriteStream;
00032 class WriteStream;
00033 }
00034 
00035 namespace Networking {
00036 
00037 enum ReaderState {
00038     RS_NONE,
00039     RS_READING_HEADERS,
00040     RS_READING_CONTENT
00041 };
00042 
00075 class Reader {
00076     ReaderState _state;
00077     Common::MemoryReadWriteStream *_content;
00078     uint32 _bytesLeft;
00079 
00080     byte *_window;
00081     uint32 _windowUsed, _windowSize;
00082 
00083     Common::MemoryReadWriteStream *_headersStream;
00084 
00085     Common::String _headers;
00086     Common::String _method, _path, _query, _anchor;
00087     Common::HashMap<Common::String, Common::String> _queryParameters;
00088     uint32 _contentLength;
00089     Common::String _boundary;
00090     uint32 _availableBytes;
00091     bool _firstBlock;
00092     bool _isBadRequest;
00093     bool _allContentRead;
00094 
00095     void cleanup();
00096 
00097     bool readAndHandleFirstHeaders(); //true when ended reading
00098     bool readBlockHeadersIntoStream(Common::WriteStream *stream); //true when ended reading
00099     bool readContentIntoStream(Common::WriteStream *stream); //true when ended reading
00100 
00101     void handleFirstHeaders(Common::MemoryReadWriteStream *headers);
00102     void parseFirstLine(const Common::String &headers);
00103     void parsePathQueryAndAnchor(Common::String pathToParse);
00104     void parseQueryParameters();
00105 
00106     void makeWindow(uint32 size);
00107     void freeWindow();
00108     bool readOneByteInStream(Common::WriteStream *stream, const Common::String &boundary);
00109 
00110     byte readOne();
00111     uint32 bytesLeft() const;
00112 
00113 public:
00114     static const uint32 SUSPICIOUS_HEADERS_SIZE = 1024 * 1024; // 1 MB is really a lot
00115 
00116     Reader();
00117     ~Reader();
00118 
00119     Reader &operator=(Reader &r);
00120 
00121     bool readFirstHeaders(); //true when ended reading
00122     bool readFirstContent(Common::WriteStream *stream); //true when ended reading
00123     bool readBlockHeaders(Common::WriteStream *stream); //true when ended reading
00124     bool readBlockContent(Common::WriteStream *stream); //true when ended reading
00125 
00126     void setContent(Common::MemoryReadWriteStream *stream);
00127 
00128     bool badRequest() const;
00129     bool noMoreContent() const;
00130 
00131     Common::String headers() const;
00132     Common::String method() const;
00133     Common::String path() const;
00134     Common::String query() const;
00135     Common::String queryParameter(Common::String name) const;
00136     Common::String anchor() const;
00137 
00138     static Common::String readEverythingFromMemoryStream(Common::MemoryReadWriteStream *stream);
00139 };
00140 
00141 } // End of namespace Networking
00142 
00143 #endif


Generated on Sat Jul 20 2019 05:00:45 for ResidualVM by doxygen 1.7.1
curved edge   curved edge