diff options
author | Alexander Tkachev | 2016-07-07 18:18:34 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | c82ed40fdd95761310855355c7c2a032512afd84 (patch) | |
tree | 639b789854bfec3f96cfde716ec2380b12b63e85 /backends/networking/sdl_net/reader.cpp | |
parent | f91bb39192cd11a0cb30a39bfb630d2fd9fad89e (diff) | |
download | scummvm-rg350-c82ed40fdd95761310855355c7c2a032512afd84.tar.gz scummvm-rg350-c82ed40fdd95761310855355c7c2a032512afd84.tar.bz2 scummvm-rg350-c82ed40fdd95761310855355c7c2a032512afd84.zip |
CLOUD: Move method/path/etc info in Reader
Query parameters are now parsed once and then just searched in the
HashMap.
Diffstat (limited to 'backends/networking/sdl_net/reader.cpp')
-rw-r--r-- | backends/networking/sdl_net/reader.cpp | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/backends/networking/sdl_net/reader.cpp b/backends/networking/sdl_net/reader.cpp index 3f7983506a..452520abfe 100644 --- a/backends/networking/sdl_net/reader.cpp +++ b/backends/networking/sdl_net/reader.cpp @@ -23,7 +23,8 @@ #define FORBIDDEN_SYMBOL_ALLOW_ALL #include "backends/networking/sdl_net/reader.h" -#include <common/debug.h> +#include "backends/networking/sdl_net/localwebserver.h" +#include "common/debug.h" namespace Networking { @@ -46,7 +47,7 @@ Reader::Reader() { Reader::~Reader() {} -bool Reader::readResponse() { +bool Reader::readRequest() { if (_state == RS_NONE) _state = RS_READING_HEADERS; while (true) { @@ -210,6 +211,34 @@ void Reader::parsePathQueryAndAnchor(Common::String path) { } else _query += path[i]; } else _anchor += path[i]; } + + parseQueryParameters(); +} + +void Reader::parseQueryParameters() { + Common::String key = ""; + Common::String value = ""; + bool readingKey = true; + for (uint32 i = 0; i < _query.size(); ++i) { + if (readingKey) { + if (_query[i] == '=') { + readingKey = false; + value = ""; + } else key += _query[i]; + } else { + if (_query[i] == '&') { + if (_queryParameters.contains(key)) warning("Query parameter \"%s\" is already set!"); + else _queryParameters[key] = LocalWebserver::urlDecode(value); + readingKey = true; + key = ""; + } else value += _query[i]; + } + } + + if (!key.empty()) { + if (_queryParameters.contains(key)) warning("Query parameter \"%s\" is already set!"); + else _queryParameters[key] = LocalWebserver::urlDecode(value); + } } bool Reader::readContent() { @@ -246,7 +275,7 @@ void Reader::handleFileContent(Common::String filename) { void Reader::handleValueContent(Common::String value) { debug("\nHANDLE CONTENT:\n>>%s<<", value.c_str()); - _fields[_currentFieldName] = value; + _queryParameters[_currentFieldName] = value; } void Reader::makeWindow(uint32 size) { @@ -322,6 +351,8 @@ Common::String Reader::path() const { return _path; } Common::String Reader::query() const { return _query; } +Common::String Reader::queryParameter(Common::String name) const { return _queryParameters[name]; } + Common::String Reader::anchor() const { return _anchor; } } // End of namespace Networking |