From a1de322c18d9efdf885ea5b760a404237dcdc0a8 Mon Sep 17 00:00:00 2001 From: Peter Bozsó Date: Sat, 30 Jul 2016 08:45:11 +0200 Subject: CLOUD: Use overriden handle() instead of ClientHandlerCallback in page handlers Using a dedicated callback object for this was an unnecessary overhead. --- backends/networking/sdl_net/handlers/basehandler.h | 5 +- .../sdl_net/handlers/createdirectoryhandler.cpp | 41 ++++---- .../sdl_net/handlers/createdirectoryhandler.h | 3 +- .../sdl_net/handlers/downloadfilehandler.cpp | 8 +- .../sdl_net/handlers/downloadfilehandler.h | 3 +- .../sdl_net/handlers/filesajaxpagehandler.cpp | 8 +- .../sdl_net/handlers/filesajaxpagehandler.h | 4 +- .../networking/sdl_net/handlers/filesbasehandler.h | 2 + .../sdl_net/handlers/filespagehandler.cpp | 110 ++++++++++----------- .../networking/sdl_net/handlers/filespagehandler.h | 4 +- .../sdl_net/handlers/indexpagehandler.cpp | 12 +-- .../networking/sdl_net/handlers/indexpagehandler.h | 4 +- .../sdl_net/handlers/listajaxhandler.cpp | 14 +-- .../networking/sdl_net/handlers/listajaxhandler.h | 4 +- .../sdl_net/handlers/resourcehandler.cpp | 32 +++--- .../networking/sdl_net/handlers/resourcehandler.h | 3 +- .../sdl_net/handlers/uploadfilehandler.cpp | 8 +- .../sdl_net/handlers/uploadfilehandler.h | 4 +- backends/networking/sdl_net/localwebserver.cpp | 22 ++--- backends/networking/sdl_net/localwebserver.h | 6 +- 20 files changed, 126 insertions(+), 171 deletions(-) (limited to 'backends/networking/sdl_net') diff --git a/backends/networking/sdl_net/handlers/basehandler.h b/backends/networking/sdl_net/handlers/basehandler.h index fd55b1372e..bf532688d7 100644 --- a/backends/networking/sdl_net/handlers/basehandler.h +++ b/backends/networking/sdl_net/handlers/basehandler.h @@ -24,18 +24,15 @@ #define BACKENDS_NETWORKING_SDL_NET_BASEHANDLER_H #include "backends/networking/sdl_net/client.h" -#include "common/callback.h" namespace Networking { -typedef Common::BaseCallback *ClientHandlerCallback; - class BaseHandler { public: BaseHandler() {} virtual ~BaseHandler() {} - virtual ClientHandlerCallback getHandler() = 0; + virtual void handle(Client &) = 0; }; } // End of namespace Networking diff --git a/backends/networking/sdl_net/handlers/createdirectoryhandler.cpp b/backends/networking/sdl_net/handlers/createdirectoryhandler.cpp index 474ac7465e..53e58b4ad2 100644 --- a/backends/networking/sdl_net/handlers/createdirectoryhandler.cpp +++ b/backends/networking/sdl_net/handlers/createdirectoryhandler.cpp @@ -25,6 +25,7 @@ #include "backends/networking/sdl_net/handlerutils.h" #include "backends/networking/sdl_net/localwebserver.h" #include "common/translation.h" +#include namespace Networking { @@ -32,6 +33,24 @@ CreateDirectoryHandler::CreateDirectoryHandler() {} CreateDirectoryHandler::~CreateDirectoryHandler() {} +void CreateDirectoryHandler::handleError(Client &client, Common::String message) const { + if (client.queryParameter("answer_json") == "true") + setJsonResponseHandler(client, "error", message); + else + HandlerUtils::setFilesManagerErrorMessageHandler(client, message); +} + +void CreateDirectoryHandler::setJsonResponseHandler(Client &client, Common::String type, Common::String message) const { + Common::JSONObject response; + response.setVal("type", new Common::JSONValue(type)); + response.setVal("message", new Common::JSONValue(message)); + + Common::JSONValue json = response; + LocalWebserver::setClientGetHandler(client, json.stringify(true)); +} + +/// public + void CreateDirectoryHandler::handle(Client &client) { Common::String path = client.queryParameter("path"); Common::String name = client.queryParameter("directory_name"); @@ -97,26 +116,4 @@ void CreateDirectoryHandler::handle(Client &client) { ); } -void CreateDirectoryHandler::handleError(Client &client, Common::String message) const { - if (client.queryParameter("answer_json") == "true") - setJsonResponseHandler(client, "error", message); - else - HandlerUtils::setFilesManagerErrorMessageHandler(client, message); -} - -void CreateDirectoryHandler::setJsonResponseHandler(Client &client, Common::String type, Common::String message) const { - Common::JSONObject response; - response.setVal("type", new Common::JSONValue(type)); - response.setVal("message", new Common::JSONValue(message)); - - Common::JSONValue json = response; - LocalWebserver::setClientGetHandler(client, json.stringify(true)); -} - -/// public - -ClientHandlerCallback CreateDirectoryHandler::getHandler() { - return new Common::Callback(this, &CreateDirectoryHandler::handle); -} - } // End of namespace Networking diff --git a/backends/networking/sdl_net/handlers/createdirectoryhandler.h b/backends/networking/sdl_net/handlers/createdirectoryhandler.h index bd0e8874da..2a18d5c4aa 100644 --- a/backends/networking/sdl_net/handlers/createdirectoryhandler.h +++ b/backends/networking/sdl_net/handlers/createdirectoryhandler.h @@ -28,14 +28,13 @@ namespace Networking { class CreateDirectoryHandler: public FilesBaseHandler { - void handle(Client &client); void handleError(Client &client, Common::String message) const; void setJsonResponseHandler(Client &client, Common::String type, Common::String message) const; public: CreateDirectoryHandler(); virtual ~CreateDirectoryHandler(); - virtual ClientHandlerCallback getHandler(); + virtual void handle(Client &client); }; } // End of namespace Networking diff --git a/backends/networking/sdl_net/handlers/downloadfilehandler.cpp b/backends/networking/sdl_net/handlers/downloadfilehandler.cpp index 20577de951..295acce0ff 100644 --- a/backends/networking/sdl_net/handlers/downloadfilehandler.cpp +++ b/backends/networking/sdl_net/handlers/downloadfilehandler.cpp @@ -33,6 +33,8 @@ DownloadFileHandler::DownloadFileHandler() {} DownloadFileHandler::~DownloadFileHandler() {} +/// public + void DownloadFileHandler::handle(Client &client) { Common::String path = client.queryParameter("path"); @@ -73,10 +75,4 @@ void DownloadFileHandler::handle(Client &client) { client.setHandler(handler); } -/// public - -ClientHandlerCallback DownloadFileHandler::getHandler() { - return new Common::Callback(this, &DownloadFileHandler::handle); -} - } // End of namespace Networking diff --git a/backends/networking/sdl_net/handlers/downloadfilehandler.h b/backends/networking/sdl_net/handlers/downloadfilehandler.h index afcedec72a..5fa5e5d55a 100644 --- a/backends/networking/sdl_net/handlers/downloadfilehandler.h +++ b/backends/networking/sdl_net/handlers/downloadfilehandler.h @@ -28,12 +28,11 @@ namespace Networking { class DownloadFileHandler: public FilesBaseHandler { - void handle(Client &client); public: DownloadFileHandler(); virtual ~DownloadFileHandler(); - virtual ClientHandlerCallback getHandler(); + virtual void handle(Client &client); }; } // End of namespace Networking diff --git a/backends/networking/sdl_net/handlers/filesajaxpagehandler.cpp b/backends/networking/sdl_net/handlers/filesajaxpagehandler.cpp index e0ecae9632..8c5ee29b70 100644 --- a/backends/networking/sdl_net/handlers/filesajaxpagehandler.cpp +++ b/backends/networking/sdl_net/handlers/filesajaxpagehandler.cpp @@ -50,6 +50,8 @@ Common::String encodeDoubleQuotesAndSlashes(Common::String s) { } +/// public + void FilesAjaxPageHandler::handle(Client &client) { // load stylish response page from the archive Common::SeekableReadStream *const stream = HandlerUtils::getArchiveFile(FILES_PAGE_NAME); @@ -76,10 +78,4 @@ void FilesAjaxPageHandler::handle(Client &client) { LocalWebserver::setClientGetHandler(client, response); } -/// public - -ClientHandlerCallback FilesAjaxPageHandler::getHandler() { - return new Common::Callback(this, &FilesAjaxPageHandler::handle); -} - } // End of namespace Networking diff --git a/backends/networking/sdl_net/handlers/filesajaxpagehandler.h b/backends/networking/sdl_net/handlers/filesajaxpagehandler.h index 8e39ac0678..1d9b125c2e 100644 --- a/backends/networking/sdl_net/handlers/filesajaxpagehandler.h +++ b/backends/networking/sdl_net/handlers/filesajaxpagehandler.h @@ -28,13 +28,11 @@ namespace Networking { class FilesAjaxPageHandler: public FilesBaseHandler { - void handle(Client &client); - public: FilesAjaxPageHandler(); virtual ~FilesAjaxPageHandler(); - virtual ClientHandlerCallback getHandler(); + virtual void handle(Client &client); }; } // End of namespace Networking diff --git a/backends/networking/sdl_net/handlers/filesbasehandler.h b/backends/networking/sdl_net/handlers/filesbasehandler.h index a960181ad1..1c7f4dd799 100644 --- a/backends/networking/sdl_net/handlers/filesbasehandler.h +++ b/backends/networking/sdl_net/handlers/filesbasehandler.h @@ -43,6 +43,8 @@ protected: public: FilesBaseHandler(); virtual ~FilesBaseHandler(); + + virtual void handle(Client &client) = 0; }; } // End of namespace Networking diff --git a/backends/networking/sdl_net/handlers/filespagehandler.cpp b/backends/networking/sdl_net/handlers/filespagehandler.cpp index abe6f42d8f..d79c9b3df7 100644 --- a/backends/networking/sdl_net/handlers/filespagehandler.cpp +++ b/backends/networking/sdl_net/handlers/filespagehandler.cpp @@ -74,61 +74,6 @@ Common::String getDisplayPath(Common::String s) { } } -void FilesPageHandler::handle(Client &client) { - Common::String response = - "" \ - "ScummVM" \ - "" \ - "

{create_directory_desc}

" \ - "
" \ - "" \ - "" \ - "" \ - "
" \ - "
" \ - "

{upload_file_desc}

" \ - "
" \ - "" \ - "{or_upload_directory_desc}" \ - "" \ - "" \ - "
" - "
" \ - "

{index_of_directory}

" \ - "{content}
" \ - "" \ - ""; - Common::String itemTemplate = "{name}{size}\n"; //TODO: load this template too? - - // load stylish response page from the archive - Common::SeekableReadStream *const stream = HandlerUtils::getArchiveFile(FILES_PAGE_NAME); - if (stream) - response = HandlerUtils::readEverythingFromStream(stream); - - Common::String path = client.queryParameter("path"); - Common::String content = ""; - - // show an error message if failed to list directory - if (!listDirectory(path, content, itemTemplate)) { - HandlerUtils::setFilesManagerErrorMessageHandler(client, _("ScummVM couldn't list the directory you specified.")); - return; - } - - //these occur twice: - replace(response, "{create_directory_button}", _("Create directory")); - replace(response, "{create_directory_button}", _("Create directory")); - replace(response, "{path}", encodeDoubleQuotes(client.queryParameter("path"))); - replace(response, "{path}", encodeDoubleQuotes(client.queryParameter("path"))); - replace(response, "{upload_files_button}", _("Upload files")); //tab - replace(response, "{upload_file_button}", _("Upload files")); //button in the tab - replace(response, "{create_directory_desc}", _("Type new directory name:")); - replace(response, "{upload_file_desc}", _("Select a file to upload:")); - replace(response, "{or_upload_directory_desc}", _("Or select a directory (works in Chrome only):")); - replace(response, "{index_of_directory}", Common::String::format(_("Index of %s"), encodeHtmlEntities(getDisplayPath(client.queryParameter("path"))).c_str())); - replace(response, "{content}", content); - LocalWebserver::setClientGetHandler(client, response); -} - bool FilesPageHandler::listDirectory(Common::String path, Common::String &content, const Common::String &itemTemplate) { if (path == "" || path == "/") { addItem(content, itemTemplate, IT_DIRECTORY, "/root/", _("File system root")); @@ -225,8 +170,59 @@ void FilesPageHandler::addItem(Common::String &content, const Common::String &it /// public -ClientHandlerCallback FilesPageHandler::getHandler() { - return new Common::Callback(this, &FilesPageHandler::handle); +void FilesPageHandler::handle(Client &client) { + Common::String response = + "" \ + "ScummVM" \ + "" \ + "

{create_directory_desc}

" \ + "
" \ + "" \ + "" \ + "" \ + "
" \ + "
" \ + "

{upload_file_desc}

" \ + "
" \ + "" \ + "{or_upload_directory_desc}" \ + "" \ + "" \ + "
" + "
" \ + "

{index_of_directory}

" \ + "{content}
" \ + "" \ + ""; + Common::String itemTemplate = "{name}{size}\n"; //TODO: load this template too? + + // load stylish response page from the archive + Common::SeekableReadStream *const stream = HandlerUtils::getArchiveFile(FILES_PAGE_NAME); + if (stream) + response = HandlerUtils::readEverythingFromStream(stream); + + Common::String path = client.queryParameter("path"); + Common::String content = ""; + + // show an error message if failed to list directory + if (!listDirectory(path, content, itemTemplate)) { + HandlerUtils::setFilesManagerErrorMessageHandler(client, _("ScummVM couldn't list the directory you specified.")); + return; + } + + //these occur twice: + replace(response, "{create_directory_button}", _("Create directory")); + replace(response, "{create_directory_button}", _("Create directory")); + replace(response, "{path}", encodeDoubleQuotes(client.queryParameter("path"))); + replace(response, "{path}", encodeDoubleQuotes(client.queryParameter("path"))); + replace(response, "{upload_files_button}", _("Upload files")); //tab + replace(response, "{upload_file_button}", _("Upload files")); //button in the tab + replace(response, "{create_directory_desc}", _("Type new directory name:")); + replace(response, "{upload_file_desc}", _("Select a file to upload:")); + replace(response, "{or_upload_directory_desc}", _("Or select a directory (works in Chrome only):")); + replace(response, "{index_of_directory}", Common::String::format(_("Index of %s"), encodeHtmlEntities(getDisplayPath(client.queryParameter("path"))).c_str())); + replace(response, "{content}", content); + LocalWebserver::setClientGetHandler(client, response); } } // End of namespace Networking diff --git a/backends/networking/sdl_net/handlers/filespagehandler.h b/backends/networking/sdl_net/handlers/filespagehandler.h index c66b79e093..e404036cb6 100644 --- a/backends/networking/sdl_net/handlers/filespagehandler.h +++ b/backends/networking/sdl_net/handlers/filespagehandler.h @@ -37,8 +37,6 @@ class FilesPageHandler: public FilesBaseHandler { IT_UNKNOWN }; - void handle(Client &client); - /** * Lists the directory . * @@ -56,7 +54,7 @@ public: FilesPageHandler(); virtual ~FilesPageHandler(); - virtual ClientHandlerCallback getHandler(); + virtual void handle(Client &client); }; } // End of namespace Networking diff --git a/backends/networking/sdl_net/handlers/indexpagehandler.cpp b/backends/networking/sdl_net/handlers/indexpagehandler.cpp index 116090be61..1c14e7daf2 100644 --- a/backends/networking/sdl_net/handlers/indexpagehandler.cpp +++ b/backends/networking/sdl_net/handlers/indexpagehandler.cpp @@ -32,6 +32,10 @@ IndexPageHandler::IndexPageHandler(): CommandSender(nullptr) {} IndexPageHandler::~IndexPageHandler() {} +/// public + +Common::String IndexPageHandler::code() const { return _code; } + void IndexPageHandler::handle(Client &client) { Common::String code = client.queryParameter("code"); @@ -54,12 +58,4 @@ void IndexPageHandler::handle(Client &client) { HandlerUtils::setMessageHandler(client, _("ScummVM got the code and already connects to your cloud storage!")); } -/// public - -Common::String IndexPageHandler::code() const { return _code; } - -ClientHandlerCallback IndexPageHandler::getHandler() { - return new Common::Callback(this, &IndexPageHandler::handle); -} - } // End of namespace Networking diff --git a/backends/networking/sdl_net/handlers/indexpagehandler.h b/backends/networking/sdl_net/handlers/indexpagehandler.h index 0e256b503f..ad4102ce88 100644 --- a/backends/networking/sdl_net/handlers/indexpagehandler.h +++ b/backends/networking/sdl_net/handlers/indexpagehandler.h @@ -31,14 +31,12 @@ class LocalWebserver; class IndexPageHandler: public BaseHandler, public GUI::CommandSender { Common::String _code; - - void handle(Client &client); public: IndexPageHandler(); virtual ~IndexPageHandler(); Common::String code() const; - virtual ClientHandlerCallback getHandler(); + virtual void handle(Client &client); }; } // End of namespace Networking diff --git a/backends/networking/sdl_net/handlers/listajaxhandler.cpp b/backends/networking/sdl_net/handlers/listajaxhandler.cpp index de349bd6ef..f0bf792aa6 100644 --- a/backends/networking/sdl_net/handlers/listajaxhandler.cpp +++ b/backends/networking/sdl_net/handlers/listajaxhandler.cpp @@ -32,13 +32,6 @@ ListAjaxHandler::ListAjaxHandler() {} ListAjaxHandler::~ListAjaxHandler() {} -void ListAjaxHandler::handle(Client &client) { - Common::String path = client.queryParameter("path"); - Common::JSONValue jsonResponse = listDirectory(path); - Common::String response = jsonResponse.stringify(true); - LocalWebserver::setClientGetHandler(client, response); -} - Common::JSONObject ListAjaxHandler::listDirectory(Common::String path) { Common::JSONArray itemsList; Common::JSONObject errorResult; @@ -145,8 +138,11 @@ void ListAjaxHandler::addItem(Common::JSONArray &responseItemsList, ItemType ite /// public -ClientHandlerCallback ListAjaxHandler::getHandler() { - return new Common::Callback(this, &ListAjaxHandler::handle); +void ListAjaxHandler::handle(Client &client) { + Common::String path = client.queryParameter("path"); + Common::JSONValue jsonResponse = listDirectory(path); + Common::String response = jsonResponse.stringify(true); + LocalWebserver::setClientGetHandler(client, response); } } // End of namespace Networking diff --git a/backends/networking/sdl_net/handlers/listajaxhandler.h b/backends/networking/sdl_net/handlers/listajaxhandler.h index c157e1b0ba..40840ad6c3 100644 --- a/backends/networking/sdl_net/handlers/listajaxhandler.h +++ b/backends/networking/sdl_net/handlers/listajaxhandler.h @@ -38,8 +38,6 @@ class ListAjaxHandler: public FilesBaseHandler { IT_UNKNOWN }; - void handle(Client &client); - /** * Lists the directory . * @@ -57,7 +55,7 @@ public: ListAjaxHandler(); virtual ~ListAjaxHandler(); - virtual ClientHandlerCallback getHandler(); + virtual void handle(Client &client); }; } // End of namespace Networking diff --git a/backends/networking/sdl_net/handlers/resourcehandler.cpp b/backends/networking/sdl_net/handlers/resourcehandler.cpp index 410665f3cc..890c2a7b95 100644 --- a/backends/networking/sdl_net/handlers/resourcehandler.cpp +++ b/backends/networking/sdl_net/handlers/resourcehandler.cpp @@ -30,22 +30,6 @@ ResourceHandler::ResourceHandler() {} ResourceHandler::~ResourceHandler() {} -void ResourceHandler::handle(Client &client) { - Common::String filename = client.path(); - filename.deleteChar(0); - - // if archive hidden file is requested, ignore - if (filename.size() && filename[0] == '.') - return; - - // if file not found, don't set handler either - Common::SeekableReadStream *file = HandlerUtils::getArchiveFile(filename); - if (file == nullptr) - return; - - LocalWebserver::setClientGetHandler(client, file, 200, determineMimeType(filename)); -} - const char *ResourceHandler::determineMimeType(Common::String &filename) { // text if (filename.hasSuffix(".html")) return "text/html"; @@ -68,8 +52,20 @@ const char *ResourceHandler::determineMimeType(Common::String &filename) { /// public -ClientHandlerCallback ResourceHandler::getHandler() { - return new Common::Callback(this, &ResourceHandler::handle); +void ResourceHandler::handle(Client &client) { + Common::String filename = client.path(); + filename.deleteChar(0); + + // if archive hidden file is requested, ignore + if (filename.size() && filename[0] == '.') + return; + + // if file not found, don't set handler either + Common::SeekableReadStream *file = HandlerUtils::getArchiveFile(filename); + if (file == nullptr) + return; + + LocalWebserver::setClientGetHandler(client, file, 200, determineMimeType(filename)); } } // End of namespace Networking diff --git a/backends/networking/sdl_net/handlers/resourcehandler.h b/backends/networking/sdl_net/handlers/resourcehandler.h index 813b80871e..8a1a15875c 100644 --- a/backends/networking/sdl_net/handlers/resourcehandler.h +++ b/backends/networking/sdl_net/handlers/resourcehandler.h @@ -28,13 +28,12 @@ namespace Networking { class ResourceHandler: public BaseHandler { - void handle(Client &client); static const char *determineMimeType(Common::String &filename); public: ResourceHandler(); virtual ~ResourceHandler(); - virtual ClientHandlerCallback getHandler(); + virtual void handle(Client &client); }; } // End of namespace Networking diff --git a/backends/networking/sdl_net/handlers/uploadfilehandler.cpp b/backends/networking/sdl_net/handlers/uploadfilehandler.cpp index 5642e3f948..02a7465b4a 100644 --- a/backends/networking/sdl_net/handlers/uploadfilehandler.cpp +++ b/backends/networking/sdl_net/handlers/uploadfilehandler.cpp @@ -33,6 +33,8 @@ UploadFileHandler::UploadFileHandler() {} UploadFileHandler::~UploadFileHandler() {} +/// public + void UploadFileHandler::handle(Client &client) { Common::String path = client.queryParameter("path"); @@ -64,10 +66,4 @@ void UploadFileHandler::handle(Client &client) { client.setHandler(new UploadFileClientHandler(path)); } -/// public - -ClientHandlerCallback UploadFileHandler::getHandler() { - return new Common::Callback(this, &UploadFileHandler::handle); -} - } // End of namespace Networking diff --git a/backends/networking/sdl_net/handlers/uploadfilehandler.h b/backends/networking/sdl_net/handlers/uploadfilehandler.h index 4cd6115182..cbff215156 100644 --- a/backends/networking/sdl_net/handlers/uploadfilehandler.h +++ b/backends/networking/sdl_net/handlers/uploadfilehandler.h @@ -28,13 +28,11 @@ namespace Networking { class UploadFileHandler: public FilesBaseHandler { - void handle(Client &client); - public: UploadFileHandler(); virtual ~UploadFileHandler(); - virtual ClientHandlerCallback getHandler(); + virtual void handle(Client &client); }; } // End of namespace Networking diff --git a/backends/networking/sdl_net/localwebserver.cpp b/backends/networking/sdl_net/localwebserver.cpp index afdee5585f..abf436958e 100644 --- a/backends/networking/sdl_net/localwebserver.cpp +++ b/backends/networking/sdl_net/localwebserver.cpp @@ -50,14 +50,14 @@ namespace Networking { LocalWebserver::LocalWebserver(): _set(nullptr), _serverSocket(nullptr), _timerStarted(false), _stopOnIdle(false), _clients(0), _idlingFrames(0), _serverPort(DEFAULT_SERVER_PORT) { - addPathHandler("/", _indexPageHandler.getHandler()); - addPathHandler("/files", _filesPageHandler.getHandler()); - addPathHandler("/create", _createDirectoryHandler.getHandler()); - addPathHandler("/download", _downloadFileHandler.getHandler()); - addPathHandler("/upload", _uploadFileHandler.getHandler()); - addPathHandler("/list", _listAjaxHandler.getHandler()); - addPathHandler("/filesAJAX", _filesAjaxPageHandler.getHandler()); - _defaultHandler = _resourceHandler.getHandler(); + addPathHandler("/", &_indexPageHandler); + addPathHandler("/files", &_filesPageHandler); + addPathHandler("/create", &_createDirectoryHandler); + addPathHandler("/download", &_downloadFileHandler); + addPathHandler("/upload", &_uploadFileHandler); + addPathHandler("/list", &_listAjaxHandler); + addPathHandler("/filesAJAX", &_filesAjaxPageHandler); + _defaultHandler = &_resourceHandler; } LocalWebserver::~LocalWebserver() { @@ -147,7 +147,7 @@ void LocalWebserver::stop() { void LocalWebserver::stopOnIdle() { _stopOnIdle = true; } -void LocalWebserver::addPathHandler(Common::String path, ClientHandlerCallback handler) { +void LocalWebserver::addPathHandler(Common::String path, BaseHandler *handler) { if (_pathHandlers.contains(path)) warning("LocalWebserver::addPathHandler: path already had a handler"); _pathHandlers[path] = handler; @@ -215,9 +215,9 @@ void LocalWebserver::handleClient(uint32 i) { //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]); + _pathHandlers[_client[i].path()]->handle(_client[i]); else if (_defaultHandler) - (*_defaultHandler)(_client[i]); //try default handler + _defaultHandler->handle(_client[i]); //try default handler if (_client[i].state() == BEING_HANDLED || _client[i].state() == INVALID) break; diff --git a/backends/networking/sdl_net/localwebserver.h b/backends/networking/sdl_net/localwebserver.h index f65d2a9551..5f5f7ef9fc 100644 --- a/backends/networking/sdl_net/localwebserver.h +++ b/backends/networking/sdl_net/localwebserver.h @@ -61,8 +61,8 @@ class LocalWebserver : public Common::Singleton { Client _client[MAX_CONNECTIONS]; int _clients; bool _timerStarted, _stopOnIdle; - Common::HashMap _pathHandlers; - ClientHandlerCallback _defaultHandler; + Common::HashMap _pathHandlers; + BaseHandler *_defaultHandler; IndexPageHandler _indexPageHandler; FilesPageHandler _filesPageHandler; CreateDirectoryHandler _createDirectoryHandler; @@ -82,7 +82,7 @@ class LocalWebserver : public Common::Singleton { void handleClient(uint32 i); void acceptClient(); void resolveAddress(void *ipAddress); - void addPathHandler(Common::String path, ClientHandlerCallback handler); + void addPathHandler(Common::String path, BaseHandler *handler); public: static const uint32 DEFAULT_SERVER_PORT = 12345; -- cgit v1.2.3