ServerWebServer.h

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2003
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #if !defined(__INCLUDE_ServerWebServerh_INCLUDE__)
00022 #define __INCLUDE_ServerWebServerh_INCLUDE__
00023 
00024 #include <net/NetServerTCP.h>
00025 #include <common/FileLogger.h>
00026 #include <webserver/ServerWebServerQueue.h>
00027 
00028 class ServerWebServer : public NetMessageHandlerI
00029 {
00030 public:
00031         static ServerWebServer *instance();
00032 
00033         void start(int port);
00034         void processMessages();
00035         void addRequestHandler(const char *url,
00036                 ServerWebServerI *handler);
00037         void addThrededRequestHandler(const char *url,
00038                 ServerWebServerI *handler);
00039         void addAsyncRequestHandler(const char *url,
00040                 ServerWebServerI *handler);
00041 
00042 protected:
00043         static ServerWebServer *instance_;
00044 
00045         struct HandlerEntry
00046         {
00047                 enum Flags
00048                 {
00049                         eAsync = 1,
00050                         eThreaded = 2
00051                 };
00052 
00053                 ServerWebServerI *handler;
00054                 unsigned int flags;
00055         };
00056         std::map<std::string, HandlerEntry> handlers_;
00057 
00058         ServerWebServerQueue asyncQueue_;
00059         ServerWebServerQueue threadedQueue_;
00060         ServerWebServerQueue normalQueue_;
00061 
00062         unsigned int asyncTimer_;
00063         std::list<std::pair<unsigned int, NetMessage *> > delayedMessages_;
00064 
00065         SDL_Thread *sendThread_;
00066         NetServerTCP netServer_;
00067         FileLogger *logger_;
00068 
00069         bool processRequest(
00070                 unsigned int destinationId,
00071                 const char *ip,
00072                 const char *url,
00073                 std::map<std::string, std::string> &fields,
00074                 std::map<std::string, NetMessage *> &parts);
00075         bool validateUser(
00076                 const char *ip,
00077                 const char *url,
00078                 std::map<std::string, std::string> &fields);
00079         unsigned int validateSession(
00080                 const char *ip,
00081                 const char *url,
00082                 std::map<std::string, std::string> &fields);
00083 
00084         static int sendThreadFunc(void *);
00085         bool processQueue(ServerWebServerQueue &queue, bool keepEntries);
00086 
00087         // Inherited from NetMessageHandlerI
00088         virtual void processMessage(NetMessage &message);
00089 
00090 private:
00091         ServerWebServer();
00092         virtual ~ServerWebServer();
00093 };
00094 
00095 #endif

Generated on Mon Feb 16 15:14:53 2009 for Scorched3D by  doxygen 1.5.3