00001 00002 // Program Name: httpserver.h 00003 // 00004 // Purpose - HTTP 1.1 Mini Server Implmenetation 00005 // Used for UPnp/AV implementation & status information 00006 // 00007 // Created By : David Blain Created On : Oct. 1, 2005 00008 // Modified By : Modified On: 00009 // 00011 00012 #ifndef __HTTPSERVER_H__ 00013 #define __HTTPSERVER_H__ 00014 00015 // POSIX headers 00016 #include <sys/types.h> 00017 #ifndef USING_MINGW 00018 #include <netinet/in.h> 00019 #include <arpa/inet.h> 00020 #endif 00021 00022 // Qt headers 00023 #include <qthread.h> 00024 #include <qserversocket.h> 00025 #include <qsocketdevice.h> 00026 #include <qsocket.h> 00027 #include <qdom.h> 00028 #include <qdatetime.h> 00029 #include <qtimer.h> 00030 #include <qptrlist.h> 00031 00032 // MythTV headers 00033 #include "upnputil.h" 00034 #include "httprequest.h" 00035 #include "threadpool.h" 00036 #include "refcounted.h" 00037 #include "compat.h" 00038 00039 typedef struct timeval TaskTime; 00040 00041 class HttpWorkerThread; 00042 class HttpServer; 00043 00046 // 00047 // HttpServerExtension Class Definition 00048 // 00051 00052 class HttpServerExtension 00053 { 00054 public: 00055 00056 QString m_sName; 00057 QString m_sSharePath; 00058 00059 public: 00060 00061 HttpServerExtension( const QString &sName ):m_sName( sName ) {}; 00062 00063 virtual ~HttpServerExtension() {}; 00064 00065 // virtual bool Initialize ( HttpServer *pServer ) = 0; 00066 virtual bool ProcessRequest( HttpWorkerThread *pThread, 00067 HTTPRequest *pRequest ) = 0; 00068 // virtual bool Uninitialize ( ) = 0; 00069 }; 00070 00071 typedef QPtrList< HttpServerExtension > HttpServerExtensionList; 00072 00075 // 00076 // HttpServer Class Definition 00077 // 00080 00081 class HttpServer : public QServerSocket, 00082 public ThreadPool 00083 { 00084 00085 protected: 00086 00087 QMutex m_mutex; 00088 HttpServerExtensionList m_extensions; 00089 00090 virtual WorkerThread *CreateWorkerThread( ThreadPool *, 00091 const QString &sName ); 00092 virtual void newConnection ( int socket ); 00093 00094 public: 00095 00096 static QString g_sPlatform; 00097 QString m_sSharePath; 00098 00099 public: 00100 00101 HttpServer( int nPort ); 00102 virtual ~HttpServer(); 00103 00104 void RegisterExtension ( HttpServerExtension *pExtension ); 00105 void UnregisterExtension( HttpServerExtension *pExtension ); 00106 00107 void DelegateRequest ( HttpWorkerThread *pThread, 00108 HTTPRequest *pRequest ); 00109 00110 }; 00111 00114 // 00115 // Base class for WorkerThread Specific data 00116 // 00119 00120 class HttpWorkerData 00121 { 00122 public: 00123 00124 HttpWorkerData() {}; 00125 virtual ~HttpWorkerData() {}; 00126 }; 00127 00130 // 00131 // HttpWorkerThread Class Definition 00132 // 00135 00136 class HttpWorkerThread : public WorkerThread 00137 { 00138 protected: 00139 00140 HttpServer *m_pHttpServer; 00141 int m_nSocket; 00142 int m_nSocketTimeout; 00143 00144 HttpWorkerData *m_pData; 00145 00146 protected: 00147 00148 virtual void ProcessWork(); 00149 00150 public: 00151 00152 HttpWorkerThread( HttpServer *pParent, const QString &sName ); 00153 virtual ~HttpWorkerThread(); 00154 00155 void StartWork( int nSocket ); 00156 00157 void SetWorkerData( HttpWorkerData *pData ); 00158 HttpWorkerData *GetWorkerData( ) { return( m_pData ); } 00159 }; 00160 00161 00162 #endif
1.5.5