ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

localwebserver.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef BACKENDS_NETWORKING_SDL_NET_LOCALWEBSERVER_H
00024 #define BACKENDS_NETWORKING_SDL_NET_LOCALWEBSERVER_H
00025 
00026 #include "backends/networking/sdl_net/client.h"
00027 #include "backends/networking/sdl_net/handlers/basehandler.h"
00028 #include "backends/networking/sdl_net/handlers/createdirectoryhandler.h"
00029 #include "backends/networking/sdl_net/handlers/downloadfilehandler.h"
00030 #include "backends/networking/sdl_net/handlers/filesajaxpagehandler.h"
00031 #include "backends/networking/sdl_net/handlers/filespagehandler.h"
00032 #include "backends/networking/sdl_net/handlers/indexpagehandler.h"
00033 #include "backends/networking/sdl_net/handlers/listajaxhandler.h"
00034 #include "backends/networking/sdl_net/handlers/resourcehandler.h"
00035 #include "backends/networking/sdl_net/handlers/uploadfilehandler.h"
00036 #include "common/hash-str.h"
00037 #include "common/mutex.h"
00038 #include "common/singleton.h"
00039 #include "common/scummsys.h"
00040 
00041 namespace Common {
00042 class SeekableReadStream;
00043 }
00044 
00045 typedef struct _SDLNet_SocketSet *SDLNet_SocketSet;
00046 typedef struct _TCPsocket *TCPsocket;
00047 
00048 namespace Networking {
00049 
00050 #define NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE
00051 
00052 class LocalWebserver : public Common::Singleton<LocalWebserver> {
00053     static const uint32 FRAMES_PER_SECOND = 20;
00054     static const uint32 TIMER_INTERVAL = 1000000 / FRAMES_PER_SECOND;
00055     static const uint32 MAX_CONNECTIONS = 10;
00056 
00057     friend void localWebserverTimer(void *); //calls handle()
00058 
00059     SDLNet_SocketSet _set;
00060     TCPsocket _serverSocket;
00061     Client _client[MAX_CONNECTIONS];
00062     uint32 _clients;
00063     bool _timerStarted, _stopOnIdle, _minimalMode;
00064     Common::HashMap<Common::String, BaseHandler*> _pathHandlers;
00065     BaseHandler *_defaultHandler;
00066     IndexPageHandler _indexPageHandler;
00067     FilesPageHandler _filesPageHandler;
00068     CreateDirectoryHandler _createDirectoryHandler;
00069     DownloadFileHandler _downloadFileHandler;
00070     UploadFileHandler _uploadFileHandler;
00071     ListAjaxHandler _listAjaxHandler;
00072     FilesAjaxPageHandler _filesAjaxPageHandler;
00073     ResourceHandler _resourceHandler;
00074     uint32 _idlingFrames;
00075     Common::Mutex _handleMutex;
00076     Common::String _address;
00077     uint32 _serverPort;
00078 
00079     void startTimer(int interval = TIMER_INTERVAL);
00080     void stopTimer();
00081     void handle();
00082     void handleClient(uint32 i);
00083     void acceptClient();
00084     void resolveAddress(void *ipAddress);
00085     void addPathHandler(Common::String path, BaseHandler *handler);
00086 
00087 public:
00088     static const uint32 DEFAULT_SERVER_PORT = 12345;
00089 
00090     LocalWebserver();
00091     virtual ~LocalWebserver();
00092 
00093     void start(bool useMinimalMode = false);
00094     void stop();
00095     void stopOnIdle();
00096 
00097     Common::String getAddress();
00098     IndexPageHandler &indexPageHandler();
00099     bool isRunning();
00100     static uint32 getPort();
00101 
00102     static void setClientGetHandler(Client &client, Common::String response, long code = 200, const char *mimeType = nullptr);
00103     static void setClientGetHandler(Client &client, Common::SeekableReadStream *responseStream, long code = 200, const char *mimeType = nullptr);
00104     static void setClientRedirectHandler(Client &client, Common::String response, Common::String location, const char *mimeType = nullptr);
00105     static void setClientRedirectHandler(Client &client, Common::SeekableReadStream *responseStream, Common::String location, const char *mimeType = nullptr);
00106     static Common::String urlDecode(Common::String value);
00107     static Common::String urlEncodeQueryParameterValue(Common::String value);
00108 };
00109 
00111 #define LocalServer     Networking::LocalWebserver::instance()
00112 
00113 } // End of namespace Networking
00114 
00115 #endif


Generated on Sat May 25 2019 05:00:48 for ResidualVM by doxygen 1.7.1
curved edge   curved edge