WebServer.h

00001 #pragma once
00002 
00003 #include <afxsock.h>
00004 #include <atlcoll.h>
00005 
00006 #define UTF8(str) UTF16To8(TToW(str))
00007 #define UTF8Arg(str) UrlEncode(UTF8(str))
00008 
00009 #define CMD_SETPOS "-1"
00010 #define CMD_SETVOLUME "-2"
00011 
00012 
00013 class CWebServerSocket;
00014 class CWebClientSocket;
00015 class CMainFrame;
00016 
00017 class CWebServer
00018 {
00019         CMainFrame* m_pMainFrame;
00020         int m_nPort;
00021 
00022         DWORD ThreadProc();
00023     static DWORD WINAPI StaticThreadProc(LPVOID lpParam);
00024     DWORD m_ThreadId;
00025     HANDLE m_hThread;
00026 
00027         CAutoPtrList<CWebClientSocket> m_clients;
00028 
00029         typedef bool (CWebClientSocket::*RequestHandler)(CStringA& hdr, CStringA& body, CStringA& mime);
00030         static CAtlMap<CString, RequestHandler, CStringElementTraits<CString> > m_internalpages;
00031         static CAtlMap<CString, UINT, CStringElementTraits<CString> > m_downloads;
00032         static CAtlMap<CStringA, CStringA, CStringElementTraits<CStringA> > m_mimes;
00033         CPath m_webroot;
00034 
00035         CAtlMap<CString, CString, CStringElementTraits<CString> > m_cgi;
00036         bool CallCGI(CWebClientSocket* pClient, CStringA& hdr, CStringA& body, CStringA& mime);
00037 
00038 public:
00039         CWebServer(CMainFrame* pMainFrame, int nPort = 13579);
00040         virtual ~CWebServer();
00041 
00042         static void Deploy(CString dir);
00043 
00044         bool ToLocalPath(CString& path, CString& redir);
00045         bool LoadPage(UINT resid, CStringA& str, CString path = _T(""));
00046 
00047         void OnAccept(CWebServerSocket* pServer);
00048         void OnClose(CWebClientSocket* pClient);
00049         void OnRequest(CWebClientSocket* pClient, CStringA& reshdr, CStringA& resbody);
00050 };

Generated on Tue Dec 13 14:47:05 2005 for guliverkli by  doxygen 1.4.5