1 /*
2  * COPYRIGHT:   See COPYING in the top level directory
3  * PROJECT:     ReactOS HTTP Daemon
4  * FILE:        include/httpd.h
5  */
6 #ifndef __HTTPD_H
7 #define __HTTPD_H
8 
9 #include <socket.h>
10 #include <thread.h>
11 #include <http.h>
12 
13 #define HTTPD_START     WM_USER + 1
14 #define HTTPD_STOP      WM_USER + 2
15 #define HTTPD_SUSPEND   WM_USER + 3
16 #define HTTPD_RESUME    WM_USER + 4
17 
18 enum HTTPdState {
19     hsStopped = 0,
20     hsRunning,
21     hsSuspended
22 };
23 
24 class CHttpDaemon;
25 
26 class CHttpClient : public CServerClientSocket {
27 public:
28 	CHttpClient();
29     CHttpClient(LPCServerSocket lpServerSocket);
30 	virtual void OnRead();
31 	//virtual void OnWrite();
32 	virtual void OnClose();
33     HANDLE ThreadHandle;
34     DWORD ThreadId;
35     CHttpParser Parser;
36     void SplitUri(const LPSTR lpsUri, LPSTR lpsHost, LPSTR lpsResource, LPSTR lpsParams);
37 	void SplitResource(const LPSTR lpsResource, LPSTR lpsPath, LPSTR lpsFilename, LPSTR lpsExtension);
38     void ProcessRequest();
39     void SendFile(const LPSTR lpsFilename);
40     void Report(LPCSTR lpsCode, const LPSTR lpsStr);
41 private:
42 	BOOL bStop;
43 	LPSTR lpsBuffer;
44 	LONG nBufferSize;
45 	//    unsigned __int64 nTotalRead;
46 	unsigned long long nTotalRead;
47 	//	unsigned __int64 nFileSize;
48 	unsigned long long nFileSize;
49     HANDLE hFile;
50 };
51 typedef CHttpClient* LPCHttpClient;
52 
53 class CHttpClientThread : public CServerClientThread {
54 public:
55 	CHttpClientThread() {};
56 	CHttpClientThread(LPCServerClientSocket Socket);
57 	virtual void Execute();
58 };
59 typedef CHttpClientThread* LPCHttpClientThread;
60 
61 class CHttpDaemon : public CServerSocket {
62 public:
63     CHttpDaemon();
64     virtual ~CHttpDaemon();
65 	HTTPdState GetState() const;
66 	virtual BOOL Start();
67 	virtual BOOL Stop();
68 	virtual LPCServerClientSocket OnGetSocket(LPCServerSocket lpServerSocket);
69 	virtual LPCServerClientThread OnGetThread(LPCServerClientSocket Socket);
70 	virtual void OnAccept(const LPCServerClientThread lpThread);
71 private:
72 	HTTPdState State;
73 };
74 typedef CHttpDaemon* LPCHttpDaemon;
75 
76 class CHttpDaemonThread : public CThread {
77 public:
78 	CHttpDaemonThread() {};
79 	virtual void Execute();
80 private:
81 	CHttpDaemon *Daemon;
82 };
83 typedef CHttpDaemonThread* LPCHttpDaemonThread;
84 
85 #endif /* __HTTPD_H */
86