aboutsummaryrefslogtreecommitdiff
path: root/backends/networking/sdl_net/localwebserver.cpp
diff options
context:
space:
mode:
authorAlexander Tkachev2016-06-16 14:19:18 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit3946f23d172f55411748171af9822d2be3863701 (patch)
treecc4eba5d489c153b5d364f9c82ff34d225a82109 /backends/networking/sdl_net/localwebserver.cpp
parentceb86a0dd8421047fc3d067da2a4c7faccc2f782 (diff)
downloadscummvm-rg350-3946f23d172f55411748171af9822d2be3863701.tar.gz
scummvm-rg350-3946f23d172f55411748171af9822d2be3863701.tar.bz2
scummvm-rg350-3946f23d172f55411748171af9822d2be3863701.zip
CLOUD: Prepare code for path handlers
LocalWebserver would storage the handlers. Client now has methods like path() or query() to access different parts of the request.
Diffstat (limited to 'backends/networking/sdl_net/localwebserver.cpp')
-rw-r--r--backends/networking/sdl_net/localwebserver.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/backends/networking/sdl_net/localwebserver.cpp b/backends/networking/sdl_net/localwebserver.cpp
index a25dd74121..689bab4cb9 100644
--- a/backends/networking/sdl_net/localwebserver.cpp
+++ b/backends/networking/sdl_net/localwebserver.cpp
@@ -110,6 +110,11 @@ void LocalWebserver::stop() {
}
}
+void LocalWebserver::addPathHandler(Common::String path, ClientHandler handler) {
+ if (_pathHandlers.contains(path)) warning("LocalWebserver::addPathHandler: path already had a handler");
+ _pathHandlers[path] = handler;
+}
+
void LocalWebserver::handle() {
int numready = SDLNet_CheckSockets(_set, 0);
if (numready == -1) {
@@ -127,10 +132,13 @@ void LocalWebserver::handleClient(uint32 i) {
case READ_HEADERS: //decide what to do next with that client
//if GET, check whether we know a handler for such URL
//if PUT, check whether we know a handler for that URL
+ if (_pathHandlers.contains(_client[i].path()))
+ (*_pathHandlers[_client[i].path()])(_client[i]);
+
+ if (_client[i].state() == BEING_HANDLED || _client[i].state() == INVALID) break;
+
//if no handler, answer with default BAD REQUEST
- warning("headers %s", _client[i].headers().c_str());
- setClientGetHandler(_client[i], "<html><head><title>ScummVM</title></head><body>Hello, World!</body></html>");
- break;
+ //fallthrough
case BAD_REQUEST:
setClientGetHandler(_client[i], "<html><head><title>ScummVM - Bad Request</title></head><body>BAD REQUEST</body></html>", 400);
break;