[18] | 1 | /**
|
---|
| 2 | * CRXProxy.h
|
---|
| 3 | */
|
---|
| 4 | #ifndef __CRXPROXY_H__
|
---|
| 5 | #define __CRXPROXY_H__
|
---|
| 6 |
|
---|
| 7 | #include "CRXException.h"
|
---|
[24] | 8 | #include "CRXSocket.h"
|
---|
| 9 | #include "CRXHttpMessage.h"
|
---|
| 10 | #include "CRXHttpRequest.h"
|
---|
| 11 | #include "CRXHttpResponse.h"
|
---|
[28] | 12 | #include "CRXFilter.h"
|
---|
[18] | 13 |
|
---|
[24] | 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
|
---|
[28] | 20 | #define ERROR_PROXY_FAILED_TO_SET_RESPONSE ERROR_PROXY - 6
|
---|
[18] | 21 |
|
---|
[24] | 22 |
|
---|
[18] | 23 | class CRXProxy : public CRXException
|
---|
| 24 | {
|
---|
| 25 | private:
|
---|
[20] | 26 | CRXSocket mClient;
|
---|
[24] | 27 | CRXSocket mServer;
|
---|
[18] | 28 |
|
---|
[36] | 29 | int mServerTimeout;
|
---|
| 30 |
|
---|
[24] | 31 | CRXHttpRequest mHttpRequest;
|
---|
| 32 | CRXHttpResponse mHttpResponse;
|
---|
| 33 |
|
---|
[28] | 34 | static CRXFilter mFilter;
|
---|
[24] | 35 |
|
---|
[18] | 36 | public:
|
---|
[24] | 37 | CRXProxy (void);
|
---|
| 38 | ~CRXProxy (void);
|
---|
[18] | 39 |
|
---|
[24] | 40 | static CRXProxy * GetNewInstance (void);
|
---|
| 41 |
|
---|
[18] | 42 | public:
|
---|
[28] | 43 | /* common utilities */
|
---|
[24] | 44 | void ReleaseInstance (void);
|
---|
[20] | 45 |
|
---|
[24] | 46 | void SetClientSocket (const int aSocket);
|
---|
[36] | 47 | void SetServerTimeout (const int aTimeout = TCPSOCKET_NO_TIMEOUT);
|
---|
[24] | 48 | void Close (void);
|
---|
| 49 |
|
---|
[28] | 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);
|
---|
[24] | 57 |
|
---|
[20] | 58 | public:
|
---|
[28] | 59 | /* for communication */
|
---|
[24] | 60 | int Forward (void);
|
---|
| 61 |
|
---|
[36] | 62 | int ReceiveRequest (void);
|
---|
| 63 | int SendRequest (void);
|
---|
| 64 |
|
---|
| 65 | int ReceiveResponse (void);
|
---|
| 66 | int SendResponse (void);
|
---|
| 67 |
|
---|
| 68 | public:
|
---|
| 69 | /* HTTP data */
|
---|
[24] | 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);
|
---|
[35] | 76 | char * GetHttpResponseHeader (char * aBuffer,
|
---|
[24] | 77 | const int aBufferSize) const;
|
---|
[35] | 78 | int GetHttpResponseHeaderLength (void) const;
|
---|
| 79 | char * GetHttpResponseBody (char * aBuffer,
|
---|
| 80 | const int aBufferSize) const;
|
---|
| 81 | int GetHttpResponseBodyLength (void) const;
|
---|
[24] | 82 |
|
---|
[18] | 83 | };
|
---|
| 84 |
|
---|
| 85 | #endif // #ifndef __CRXPROXY_H__
|
---|