From e4bb7c4e750d53434140a8d1a401e7fa6ee221ab Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Sat, 9 Jul 2016 15:49:18 +0600 Subject: CLOUD: Add UploadFileClientHandler Now Client reads the first headers block, then LocalWebserver decides which Handler to use. In case of "/upload", UploadFileHandler is used. But now it only knows the "path" parameter. If that's valid, actual UploadFileClientHandler is created, which reads the contents of the request and, when finds there an "upload_file" field, starts saving it in the directory specified by "path". With that we don't need temp files approach from Reader class. --- .../networking/sdl_net/uploadfileclienthandler.h | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 backends/networking/sdl_net/uploadfileclienthandler.h (limited to 'backends/networking/sdl_net/uploadfileclienthandler.h') diff --git a/backends/networking/sdl_net/uploadfileclienthandler.h b/backends/networking/sdl_net/uploadfileclienthandler.h new file mode 100644 index 0000000000..4f2ce621fb --- /dev/null +++ b/backends/networking/sdl_net/uploadfileclienthandler.h @@ -0,0 +1,57 @@ +/* ScummVM - Graphic Adventure Engine +* +* ScummVM is the legal property of its developers, whose names +* are too numerous to list here. Please refer to the COPYRIGHT +* file distributed with this source distribution. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +* +*/ + +#ifndef BACKENDS_NETWORKING_SDL_NET_UPLOADFILECLIENTHANDLER_H +#define BACKENDS_NETWORKING_SDL_NET_UPLOADFILECLIENTHANDLER_H + +#include "backends/networking/sdl_net/client.h" +#include "common/stream.h" + +namespace Networking { + +enum UploadFileHandlerState { + UFH_READING_CONTENT, + UFH_READING_BLOCK_HEADERS, + UFH_READING_BLOCK_CONTENT, + UFH_ERROR +}; + +class UploadFileClientHandler: public ClientHandler { + UploadFileHandlerState _state; + Common::MemoryReadWriteStream *_headersStream; + Common::WriteStream *_contentStream; + Common::String _parentDirectoryPath; + + void handleBlockHeaders(Client *client); + bool validFilename(Client &client, Common::String filename, Common::String &errorMessage); + void setErrorMessageHandler(Client &client, Common::String message); + +public: + UploadFileClientHandler(Common::String parentDirectoryPath); + virtual ~UploadFileClientHandler(); + + virtual void handle(Client *client); +}; + +} // End of namespace Networking + +#endif -- cgit v1.2.3 From 7fcdcc10cb8f6dad370e942ef917ff00e888e2ec Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Sat, 9 Jul 2016 16:10:58 +0600 Subject: CLOUD: Cleanup in UploadFileClientHandler Adds Client::noMoreContent() and Reader::noMoreContent(), which return true when whole client's request was read. --- backends/networking/sdl_net/uploadfileclienthandler.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'backends/networking/sdl_net/uploadfileclienthandler.h') diff --git a/backends/networking/sdl_net/uploadfileclienthandler.h b/backends/networking/sdl_net/uploadfileclienthandler.h index 4f2ce621fb..de6941bf4f 100644 --- a/backends/networking/sdl_net/uploadfileclienthandler.h +++ b/backends/networking/sdl_net/uploadfileclienthandler.h @@ -32,7 +32,8 @@ enum UploadFileHandlerState { UFH_READING_CONTENT, UFH_READING_BLOCK_HEADERS, UFH_READING_BLOCK_CONTENT, - UFH_ERROR + UFH_ERROR, + UFH_STOP }; class UploadFileClientHandler: public ClientHandler { @@ -42,7 +43,7 @@ class UploadFileClientHandler: public ClientHandler { Common::String _parentDirectoryPath; void handleBlockHeaders(Client *client); - bool validFilename(Client &client, Common::String filename, Common::String &errorMessage); + void handleBlockContent(Client *client); void setErrorMessageHandler(Client &client, Common::String message); public: -- cgit v1.2.3 From 389c669a4744629e19e48e8243dac1a8875e60c2 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 12 Jul 2016 10:48:10 +0600 Subject: CLOUD: Add "directory" form for webserver "/upload" The attribute is Chrome-only. --- backends/networking/sdl_net/uploadfileclienthandler.h | 1 + 1 file changed, 1 insertion(+) (limited to 'backends/networking/sdl_net/uploadfileclienthandler.h') diff --git a/backends/networking/sdl_net/uploadfileclienthandler.h b/backends/networking/sdl_net/uploadfileclienthandler.h index de6941bf4f..f61a2fab5e 100644 --- a/backends/networking/sdl_net/uploadfileclienthandler.h +++ b/backends/networking/sdl_net/uploadfileclienthandler.h @@ -41,6 +41,7 @@ class UploadFileClientHandler: public ClientHandler { Common::MemoryReadWriteStream *_headersStream; Common::WriteStream *_contentStream; Common::String _parentDirectoryPath; + uint32 _uploadedFiles; void handleBlockHeaders(Client *client); void handleBlockContent(Client *client); -- cgit v1.2.3 From 01161ae7ddbc5f147dd9e71991eb2f1a1c9a7b06 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Wed, 20 Jul 2016 19:51:39 +0600 Subject: CLOUD: Do some refactoring/cleanup in Networking --- backends/networking/sdl_net/uploadfileclienthandler.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'backends/networking/sdl_net/uploadfileclienthandler.h') diff --git a/backends/networking/sdl_net/uploadfileclienthandler.h b/backends/networking/sdl_net/uploadfileclienthandler.h index f61a2fab5e..4aa6929888 100644 --- a/backends/networking/sdl_net/uploadfileclienthandler.h +++ b/backends/networking/sdl_net/uploadfileclienthandler.h @@ -36,6 +36,16 @@ enum UploadFileHandlerState { UFH_STOP }; +/** + * This class handles POST form/multipart upload. + * + * handleBlockHeaders() looks for filename and, if it's found, + * handleBlockContent() saves content into the file with such name. + * + * If no file found or other error occurs, it sets + * default error message handler. + */ + class UploadFileClientHandler: public ClientHandler { UploadFileHandlerState _state; Common::MemoryReadWriteStream *_headersStream; -- cgit v1.2.3 From 712410496e4e59fe1ee1968a94eeb73b51223996 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Fri, 29 Jul 2016 12:22:42 +0600 Subject: CLOUD: Fix UploadFileClientHandler It now redirects user on success not only when file was the last field in the content, but also when it was uploaded already and Handler worked further to search for more files. --- backends/networking/sdl_net/uploadfileclienthandler.h | 1 + 1 file changed, 1 insertion(+) (limited to 'backends/networking/sdl_net/uploadfileclienthandler.h') diff --git a/backends/networking/sdl_net/uploadfileclienthandler.h b/backends/networking/sdl_net/uploadfileclienthandler.h index 4aa6929888..b6481cf18f 100644 --- a/backends/networking/sdl_net/uploadfileclienthandler.h +++ b/backends/networking/sdl_net/uploadfileclienthandler.h @@ -56,6 +56,7 @@ class UploadFileClientHandler: public ClientHandler { void handleBlockHeaders(Client *client); void handleBlockContent(Client *client); void setErrorMessageHandler(Client &client, Common::String message); + void setSuccessHandler(Client &client); public: UploadFileClientHandler(Common::String parentDirectoryPath); -- cgit v1.2.3