1 | /**
|
---|
2 | * CRXProxy.h
|
---|
3 | */
|
---|
4 | #ifndef __CRXPROXY_H__
|
---|
5 | #define __CRXPROXY_H__
|
---|
6 |
|
---|
7 | #include "CRXException.h"
|
---|
8 | #include "CRXSocket.h"
|
---|
9 | #include "CRXHttpMessage.h"
|
---|
10 | #include "CRXHttpRequest.h"
|
---|
11 | #include "CRXHttpResponse.h"
|
---|
12 | #include "CRXFilter.h"
|
---|
13 |
|
---|
14 | #define ERROR_PROXY -10000
|
---|
15 | #define ERROR_PROXY_FAILED_TO_RECEIVE_REQUEST ERROR_PROXY - 1
|
---|
16 | #define ERROR_PROXY_FAILED_TO_SEND_REQUEST ERROR_PROXY - 2
|
---|
17 | #define ERROR_PROXY_FAILED_TO_RECEIVE_RESPONSE ERROR_PROXY - 3
|
---|
18 | #define ERROR_PROXY_FAILED_TO_SEND_RESPONSE ERROR_PROXY - 4
|
---|
19 | #define ERROR_PROXY_FAILED_TO_CONNECT_TO_SERVER ERROR_PROXY - 5
|
---|
20 | #define ERROR_PROXY_FAILED_TO_SET_RESPONSE ERROR_PROXY - 6
|
---|
21 |
|
---|
22 |
|
---|
23 | class CRXProxy : public CRXException
|
---|
24 | {
|
---|
25 | private:
|
---|
26 | CRXSocket mClient;
|
---|
27 | CRXSocket mServer;
|
---|
28 |
|
---|
29 | int mServerTimeout;
|
---|
30 |
|
---|
31 | CRXHttpRequest mHttpRequest;
|
---|
32 | CRXHttpResponse mHttpResponse;
|
---|
33 |
|
---|
34 | static CRXFilter mFilter;
|
---|
35 |
|
---|
36 | public:
|
---|
37 | CRXProxy (void);
|
---|
38 | ~CRXProxy (void);
|
---|
39 |
|
---|
40 | static CRXProxy * GetNewInstance (void);
|
---|
41 |
|
---|
42 | public:
|
---|
43 | /* common utilities */
|
---|
44 | void ReleaseInstance (void);
|
---|
45 |
|
---|
46 | void SetClientSocket (const int aSocket);
|
---|
47 | void SetServerTimeout (const int aTimeout = TCPSOCKET_NO_TIMEOUT);
|
---|
48 | void Close (void);
|
---|
49 |
|
---|
50 | public:
|
---|
51 | /* interface to filter */
|
---|
52 | void SetRequestFilter (const E_CRX_FILTER_REQUEST aType,
|
---|
53 | const bool aIsMatched,
|
---|
54 | const std::string aValue);
|
---|
55 | void RemoveRequestFilter (const E_CRX_FILTER_REQUEST aType);
|
---|
56 | bool CheckRequestFilter (const E_CRX_FILTER_REQUEST aType);
|
---|
57 |
|
---|
58 | public:
|
---|
59 | /* for communication */
|
---|
60 | int Forward (void);
|
---|
61 |
|
---|
62 | int ReceiveRequest (void);
|
---|
63 | int SendRequest (void);
|
---|
64 |
|
---|
65 | int ReceiveResponse (void);
|
---|
66 | int SendResponse (void);
|
---|
67 |
|
---|
68 | public:
|
---|
69 | /* HTTP data */
|
---|
70 | void SetHttpRequest (const char * aHttpRequest);
|
---|
71 | char * GetHttpRequest (char * aBuffer,
|
---|
72 | const int aBufferSize) const;
|
---|
73 | int GetHttpRequestLength (void) const;
|
---|
74 |
|
---|
75 | void SetHttpResponse (const char * aHttpResponse);
|
---|
76 | char * GetHttpResponseHeader (char * aBuffer,
|
---|
77 | const int aBufferSize) const;
|
---|
78 | int GetHttpResponseHeaderLength (void) const;
|
---|
79 | char * GetHttpResponseBody (char * aBuffer,
|
---|
80 | const int aBufferSize) const;
|
---|
81 | int GetHttpResponseBodyLength (void) const;
|
---|
82 |
|
---|
83 | };
|
---|
84 |
|
---|
85 | #endif // #ifndef __CRXPROXY_H__
|
---|