2016-06-15 16:38:37 +06:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2016-09-03 12:46:38 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
2016-06-15 16:38:37 +06:00
|
|
|
|
|
|
|
#ifndef BACKENDS_NETWORKING_SDL_NET_LOCALWEBSERVER_H
|
|
|
|
#define BACKENDS_NETWORKING_SDL_NET_LOCALWEBSERVER_H
|
|
|
|
|
2016-06-15 21:36:20 +06:00
|
|
|
#include "backends/networking/sdl_net/client.h"
|
2016-07-06 16:48:56 +06:00
|
|
|
#include "backends/networking/sdl_net/handlers/basehandler.h"
|
2016-07-06 18:33:34 +06:00
|
|
|
#include "backends/networking/sdl_net/handlers/createdirectoryhandler.h"
|
2016-07-06 19:09:29 +06:00
|
|
|
#include "backends/networking/sdl_net/handlers/downloadfilehandler.h"
|
2016-07-19 12:15:51 +06:00
|
|
|
#include "backends/networking/sdl_net/handlers/filesajaxpagehandler.h"
|
2016-07-06 16:48:56 +06:00
|
|
|
#include "backends/networking/sdl_net/handlers/filespagehandler.h"
|
|
|
|
#include "backends/networking/sdl_net/handlers/indexpagehandler.h"
|
2016-07-18 19:00:14 +06:00
|
|
|
#include "backends/networking/sdl_net/handlers/listajaxhandler.h"
|
2016-07-06 16:48:56 +06:00
|
|
|
#include "backends/networking/sdl_net/handlers/resourcehandler.h"
|
2016-07-08 16:00:11 +06:00
|
|
|
#include "backends/networking/sdl_net/handlers/uploadfilehandler.h"
|
2016-06-16 14:19:18 +06:00
|
|
|
#include "common/hash-str.h"
|
2016-06-18 14:15:25 +06:00
|
|
|
#include "common/mutex.h"
|
2016-06-15 16:38:37 +06:00
|
|
|
#include "common/singleton.h"
|
|
|
|
#include "common/scummsys.h"
|
|
|
|
|
2016-06-16 19:34:57 +06:00
|
|
|
namespace Common {
|
|
|
|
class SeekableReadStream;
|
|
|
|
}
|
|
|
|
|
2016-06-15 16:38:37 +06:00
|
|
|
typedef struct _SDLNet_SocketSet *SDLNet_SocketSet;
|
|
|
|
typedef struct _TCPsocket *TCPsocket;
|
|
|
|
|
|
|
|
namespace Networking {
|
|
|
|
|
2016-07-20 16:36:44 +06:00
|
|
|
#define NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE
|
|
|
|
|
2016-06-15 16:38:37 +06:00
|
|
|
class LocalWebserver : public Common::Singleton<LocalWebserver> {
|
|
|
|
static const uint32 FRAMES_PER_SECOND = 20;
|
|
|
|
static const uint32 TIMER_INTERVAL = 1000000 / FRAMES_PER_SECOND;
|
|
|
|
static const uint32 MAX_CONNECTIONS = 10;
|
|
|
|
|
|
|
|
friend void localWebserverTimer(void *); //calls handle()
|
|
|
|
|
|
|
|
SDLNet_SocketSet _set;
|
|
|
|
TCPsocket _serverSocket;
|
2016-06-15 21:36:20 +06:00
|
|
|
Client _client[MAX_CONNECTIONS];
|
2017-01-17 08:27:04 +00:00
|
|
|
uint32 _clients;
|
2016-08-01 12:54:54 +06:00
|
|
|
bool _timerStarted, _stopOnIdle, _minimalMode;
|
2016-07-30 08:45:11 +02:00
|
|
|
Common::HashMap<Common::String, BaseHandler*> _pathHandlers;
|
|
|
|
BaseHandler *_defaultHandler;
|
2016-06-16 15:19:13 +06:00
|
|
|
IndexPageHandler _indexPageHandler;
|
2016-07-06 16:48:56 +06:00
|
|
|
FilesPageHandler _filesPageHandler;
|
2016-07-06 18:33:34 +06:00
|
|
|
CreateDirectoryHandler _createDirectoryHandler;
|
2016-07-06 19:09:29 +06:00
|
|
|
DownloadFileHandler _downloadFileHandler;
|
2016-07-08 16:00:11 +06:00
|
|
|
UploadFileHandler _uploadFileHandler;
|
2016-07-18 19:00:14 +06:00
|
|
|
ListAjaxHandler _listAjaxHandler;
|
2016-07-19 12:15:51 +06:00
|
|
|
FilesAjaxPageHandler _filesAjaxPageHandler;
|
2016-07-06 16:48:56 +06:00
|
|
|
ResourceHandler _resourceHandler;
|
2016-06-16 19:34:57 +06:00
|
|
|
uint32 _idlingFrames;
|
2016-06-18 14:15:25 +06:00
|
|
|
Common::Mutex _handleMutex;
|
2016-07-05 16:31:52 +06:00
|
|
|
Common::String _address;
|
2016-07-20 15:55:30 +06:00
|
|
|
uint32 _serverPort;
|
2016-06-15 16:38:37 +06:00
|
|
|
|
|
|
|
void startTimer(int interval = TIMER_INTERVAL);
|
|
|
|
void stopTimer();
|
|
|
|
void handle();
|
2016-06-15 21:36:20 +06:00
|
|
|
void handleClient(uint32 i);
|
|
|
|
void acceptClient();
|
2016-07-20 19:51:39 +06:00
|
|
|
void resolveAddress(void *ipAddress);
|
2016-07-30 08:45:11 +02:00
|
|
|
void addPathHandler(Common::String path, BaseHandler *handler);
|
2016-07-21 11:44:36 +06:00
|
|
|
|
2016-06-15 16:38:37 +06:00
|
|
|
public:
|
2016-07-20 16:36:44 +06:00
|
|
|
static const uint32 DEFAULT_SERVER_PORT = 12345;
|
|
|
|
|
2016-06-15 16:38:37 +06:00
|
|
|
LocalWebserver();
|
|
|
|
virtual ~LocalWebserver();
|
|
|
|
|
2016-08-01 12:54:54 +06:00
|
|
|
void start(bool useMinimalMode = false);
|
2016-06-15 16:38:37 +06:00
|
|
|
void stop();
|
2016-06-16 15:19:13 +06:00
|
|
|
void stopOnIdle();
|
|
|
|
|
2016-07-05 16:31:52 +06:00
|
|
|
Common::String getAddress();
|
2016-06-16 15:19:13 +06:00
|
|
|
IndexPageHandler &indexPageHandler();
|
2016-07-05 16:31:52 +06:00
|
|
|
bool isRunning();
|
2016-07-20 15:55:30 +06:00
|
|
|
static uint32 getPort();
|
2016-06-16 15:19:13 +06:00
|
|
|
|
2016-06-16 19:34:57 +06:00
|
|
|
static void setClientGetHandler(Client &client, Common::String response, long code = 200, const char *mimeType = nullptr);
|
|
|
|
static void setClientGetHandler(Client &client, Common::SeekableReadStream *responseStream, long code = 200, const char *mimeType = nullptr);
|
2016-07-06 18:33:34 +06:00
|
|
|
static void setClientRedirectHandler(Client &client, Common::String response, Common::String location, const char *mimeType = nullptr);
|
|
|
|
static void setClientRedirectHandler(Client &client, Common::SeekableReadStream *responseStream, Common::String location, const char *mimeType = nullptr);
|
2016-07-06 18:03:56 +06:00
|
|
|
static Common::String urlDecode(Common::String value);
|
2016-07-07 15:01:07 +06:00
|
|
|
static Common::String urlEncodeQueryParameterValue(Common::String value);
|
2016-06-15 16:38:37 +06:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Shortcut for accessing the local webserver. */
|
2016-07-21 09:29:54 +02:00
|
|
|
#define LocalServer Networking::LocalWebserver::instance()
|
2016-06-15 16:38:37 +06:00
|
|
|
|
|
|
|
} // End of namespace Networking
|
|
|
|
|
|
|
|
#endif
|