From 3946f23d172f55411748171af9822d2be3863701 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Thu, 16 Jun 2016 14:19:18 +0600 Subject: 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. --- backends/networking/sdl_net/localwebserver.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'backends/networking/sdl_net/localwebserver.cpp') 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], "ScummVMHello, World!"); - break; + //fallthrough case BAD_REQUEST: setClientGetHandler(_client[i], "ScummVM - Bad RequestBAD REQUEST", 400); break; -- cgit v1.2.3