Index: /trunk/include/CRXProxy.h
===================================================================
--- /trunk/include/CRXProxy.h	(revision 44)
+++ /trunk/include/CRXProxy.h	(revision 45)
@@ -19,4 +19,5 @@
 #define ERROR_PROXY_FAILED_TO_CONNECT_TO_SERVER	ERROR_PROXY - 5
 #define ERROR_PROXY_FAILED_TO_SET_RESPONSE		ERROR_PROXY - 6
+#define ERROR_PROXY_FAILED_TO_ACCEPT_CLIENT		ERROR_PROXY - 7
 
 
@@ -35,20 +36,11 @@
 
 public:
-	CRXProxy			(void);
+	CRXProxy			(const int aSocket);
 	~CRXProxy			(void);
 
 public:
 	/* common utilities */
-	void	SetClientSocket				(const int	aSocket);
 	void	SetServerTimeout			(const int	aTimeout = TCPSOCKET_NO_TIMEOUT);
 	void	Close						(void);
-
-public:
-	/* interface to filter */
-	void	SetRequestFilter			(const E_CRX_FILTER_REQUEST	aType,
-										 const bool					aIsMatched,
-										 const std::string			aValue);
-	void	RemoveRequestFilter			(const E_CRX_FILTER_REQUEST	aType);
-	bool	CheckRequestFilter			(const E_CRX_FILTER_REQUEST	aType);
 
 public:
@@ -64,17 +56,7 @@
 public:
 	/* HTTP data */
-	void	SetHttpRequest				(const char	* aHttpRequest);
-	char *	GetHttpRequest				(char		* aBuffer,
-										 const int	aBufferSize) const;
-	int		GetHttpRequestLength		(void) const;
-
-	void	SetHttpResponse				(const char	* aHttpResponse);
-	char *	GetHttpResponseHeader		(char		* aBuffer,
-										 const int	aBufferSize) const;
-	int		GetHttpResponseHeaderLength	(void) const;
-	char *	GetHttpResponseBody			(char		* aBuffer,
-										 const int	aBufferSize) const;
-	int		GetHttpResponseBodyLength	(void) const;
-	
+	CRXFilter &			GetFilter		(void) const;
+	CRXHttpRequest &	GetHttpRequest	(void);
+	CRXHttpResponse &	GetHttpResponse	(void);
 };
 
Index: /trunk/src/CRXHttpResponse.cpp
===================================================================
--- /trunk/src/CRXHttpResponse.cpp	(revision 44)
+++ /trunk/src/CRXHttpResponse.cpp	(revision 45)
@@ -162,5 +162,5 @@
 int
 CRXHttpResponse::SetContent (const char	* aContent,
-							   const int	aLength)
+							 const int	aLength)
 {
 	int		aResult = 0;
Index: /trunk/src/CRXProxy.cpp
===================================================================
--- /trunk/src/CRXProxy.cpp	(revision 44)
+++ /trunk/src/CRXProxy.cpp	(revision 45)
@@ -9,10 +9,12 @@
 CRXFilter	CRXProxy::mFilter;
 
-CRXProxy::CRXProxy (void)
-	: mClient (0),
-	  mServer (0),
-	  mServerTimeout (0)
-{
-	/*----------------------------------------------------------------*/
+CRXProxy::CRXProxy (const int aSocket)
+	: mServerTimeout (0)
+{
+	/*----------------------------------------------------------------*/
+	if (aSocket < 0)
+		return ;
+
+	mClient = aSocket;
 	/*----------------------------------------------------------------*/
 }
@@ -22,15 +24,4 @@
 	/*----------------------------------------------------------------*/
 	Close ();
-	/*----------------------------------------------------------------*/
-}
-
-void
-CRXProxy::SetClientSocket (const int aSocket)
-{
-	/*----------------------------------------------------------------*/
-	if (aSocket <= 0)
-		return ;
-
-	mClient = aSocket;
 	/*----------------------------------------------------------------*/
 }
@@ -51,31 +42,4 @@
 	mClient.Close ();
 	/*----------------------------------------------------------------*/
-}
-
-void
-CRXProxy::SetRequestFilter (const E_CRX_FILTER_REQUEST	aType,
-							const bool					aIsMatched,
-							const std::string			aValue)
-{
-	/*----------------------------------------------------------------*/
-	mFilter.SetRequestFilter (aType, aIsMatched, aValue);
-	/*----------------------------------------------------------------*/
-}
-
-void
-CRXProxy::RemoveRequestFilter (const E_CRX_FILTER_REQUEST aType)
-{
-	/*----------------------------------------------------------------*/
-	mFilter.RemoveRequestFilter (aType);
-	/*----------------------------------------------------------------*/
-}
-
-bool
-CRXProxy::CheckRequestFilter (const E_CRX_FILTER_REQUEST aType)
-{
-	/*----------------------------------------------------------------*/
-	/*----------------------------------------------------------------*/
-
-	return mFilter.CheckRequestFilter (aType, this->mHttpRequest);
 }
 
@@ -120,113 +84,4 @@
 }
 
-void
-CRXProxy::SetHttpRequest (const char * aHttpRequest)
-{
-	/*----------------------------------------------------------------*/
-	mHttpRequest.SetHeader (aHttpRequest);
-	/*----------------------------------------------------------------*/
-}
-
-char *
-CRXProxy::GetHttpRequest (char		* aBuffer,
-						  const int	aBufferSize) const
-{
-	void		* aPtr = static_cast<void *> (aBuffer);
-
-	int			aCopyLength		= 0;
-	int			aRemainLength	= aBufferSize;
-	const int	aHeaderLength	= mHttpRequest.GetHeader ().length ();
-
-	/*----------------------------------------------------------------*/
-	if (aPtr == NULL)
-		return NULL;
-
-	aCopyLength = aRemainLength < aHeaderLength ? aBufferSize : aHeaderLength;
-	if (aCopyLength > 0)
-		memcpy (aPtr, mHttpRequest.GetHeader ().c_str (), aCopyLength);
-	/*----------------------------------------------------------------*/
-
-	return aBuffer;
-}
-
-int
-CRXProxy::GetHttpRequestLength (void) const
-{
-	/*----------------------------------------------------------------*/
-	/*----------------------------------------------------------------*/
-
-	return mHttpRequest.GetHeader().length ();
-}
-
-void
-CRXProxy::SetHttpResponse (const char * aHttpResponse)
-{
-	/*----------------------------------------------------------------*/
-	mHttpResponse.SetHeader (aHttpResponse);
-	/*----------------------------------------------------------------*/
-}
-
-char *
-CRXProxy::GetHttpResponseHeader (char		* aBuffer,
-								 const int	aBufferSize) const
-{
-	void		* aPtr = static_cast<void *> (aBuffer);
-
-	int			aCopyLength		= 0;
-	int			aRemainLength	= aBufferSize;
-	const int	aHeaderLength	= mHttpResponse.GetHeader ().length ();
-
-	/*----------------------------------------------------------------*/
-	if (aPtr == NULL)
-		return NULL;
-
-	aCopyLength = aRemainLength < aHeaderLength ? aBufferSize : aHeaderLength;
-	if (aCopyLength > 0)
-		memcpy (aPtr, mHttpResponse.GetHeader ().c_str (), aCopyLength);
-	/*----------------------------------------------------------------*/
-
-	return aBuffer;
-}
-
-int
-CRXProxy::GetHttpResponseHeaderLength (void) const
-{
-	/*----------------------------------------------------------------*/
-	/*----------------------------------------------------------------*/
-
-	return mHttpResponse.GetHeader ().length ();
-}
-
-char *
-CRXProxy::GetHttpResponseBody (char			* aBuffer,
-							   const int	aBufferSize) const
-{
-	void		* aPtr = static_cast<void *> (aBuffer);
-
-	int			aCopyLength		= 0;
-	int			aRemainLength	= aBufferSize;
-	const int	aContentLength	= mHttpResponse.GetContentLength ();
-
-	/*----------------------------------------------------------------*/
-	if (aPtr == NULL)
-		return NULL;
-
-	aCopyLength = aRemainLength < aContentLength ? aRemainLength : aContentLength;
-	if (aCopyLength > 0)
-		memcpy (aPtr, mHttpResponse.GetContentBody (), aCopyLength);
-	/*----------------------------------------------------------------*/
-
-	return aBuffer;
-}
-
-int
-CRXProxy::GetHttpResponseBodyLength (void) const
-{
-	/*----------------------------------------------------------------*/
-	/*----------------------------------------------------------------*/
-
-	return mHttpResponse.GetContentLength ();
-}
-
 int
 CRXProxy::ReceiveRequest (void)
@@ -315,5 +170,5 @@
 
 		aResult = mHttpResponse.SetResponseAll (aBuffer, aResult);
-		if (aResult)
+		if (aResult < 0)
 		{
 			aResult = ERROR_PROXY_FAILED_TO_SET_RESPONSE;
@@ -354,2 +209,29 @@
 	return aResult < 0 ? aResult : 0;
 }
+
+CRXFilter &
+CRXProxy::GetFilter (void) const
+{
+	/*----------------------------------------------------------------*/
+	/*----------------------------------------------------------------*/
+
+	return mFilter;
+}
+
+CRXHttpRequest &
+CRXProxy::GetHttpRequest (void)
+{
+	/*----------------------------------------------------------------*/
+	/*----------------------------------------------------------------*/
+
+	return mHttpRequest;
+}
+
+CRXHttpResponse &
+CRXProxy::GetHttpResponse (void)
+{
+	/*----------------------------------------------------------------*/
+	/*----------------------------------------------------------------*/
+
+	return mHttpResponse;
+}
Index: /trunk/src/main.cpp
===================================================================
--- /trunk/src/main.cpp	(revision 44)
+++ /trunk/src/main.cpp	(revision 45)
@@ -68,76 +68,4 @@
 }
 
-THREAD_FUNCTION_RETURN
-THREAD_FUNCTION_CALLING_CONVENTION
-CRXProxyMTWrapper (void * aThreadArg)
-{
-	int			aResult = 0;
-
-	CRXSocket	* aProxySocket = (CRXSocket *)aThreadArg;
-	CRXProxy	* aProxy = NULL;
-
-	char		aFilterFileExtension[] = "exe|gif|jpg|png|css|js|ico|swf|";
-	char		* aHttpMessage = NULL;
-	int			aHttpMessageLength = 0;
-
-	/*----------------------------------------------------------------*/
-	for (;;)
-	{
-		aResult = aProxySocket->Accept ();
-		if (aResult < 0)
-		{
-			cerr << "Failed to accept." << endl;
-			break;
-		}
-
-		if ((aProxy = new(std::nothrow) CRXProxy ()) == NULL)
-		{
-			cerr << "Failed to get proxy." << endl;
-			aResult = -1;
-			break;
-		}
-
-		aProxy->SetClientSocket (aResult);
-		aProxy->SetServerTimeout (2);
-		aProxy->SetRequestFilter (CRX_FILTER_REQUEST_FILE_EXTENSION,
-								  CRX_FILTER_MATCHED,
-								  aFilterFileExtension);
-
-		aResult = aProxy->Forward ();
-		if (aResult < 0)
-		{
-			cout << aProxy->GetErrorMessage () << endl;
-		}
-
-		if (!aProxy->CheckRequestFilter (CRX_FILTER_REQUEST_FILE_EXTENSION))
-		{
-			aHttpMessageLength = aProxy->GetHttpRequestLength ();
-			aHttpMessage = (char *) calloc (aHttpMessageLength + 1, 1);
-			aProxy->GetHttpRequest (aHttpMessage, aHttpMessageLength);
-			CRX_DEBUG_TRACE ("== Request: \n%s\n", aHttpMessage);
-			free (aHttpMessage);
-
-			aHttpMessageLength = aProxy->GetHttpResponseHeaderLength ();
-			aHttpMessage = (char *) calloc (aHttpMessageLength + 1, 1);
-			aProxy->GetHttpResponseHeader (aHttpMessage, aHttpMessageLength);
-			CRX_DEBUG_TRACE ("== Response: \n%s\n", aHttpMessage);
-			free (aHttpMessage);
-
-			aHttpMessageLength = aProxy->GetHttpResponseBodyLength ();
-			aHttpMessage = (char *) calloc (aHttpMessageLength + 1, 1);
-			aProxy->GetHttpResponseBody (aHttpMessage, aHttpMessageLength);
-			CRX_DEBUG_TRACE_BIN (aHttpMessage, aHttpMessageLength, "== Content-Body: \n");
-			free (aHttpMessage);
-		}
-
-		delete aProxy;
-	}
-
-	cout << " thread exit." << endl;
-	/*----------------------------------------------------------------*/
-
-	return (THREAD_FUNCTION_RETURN)0;
-}
-
 int ThreadPool (CRXSocket	* aProxySocket,
 				const int	aThreadPoolCount)
@@ -171,2 +99,65 @@
 	return aResult;
 }
+
+THREAD_FUNCTION_RETURN
+THREAD_FUNCTION_CALLING_CONVENTION
+CRXProxyMTWrapper (void * aThreadArg)
+{
+	int			aResult = 0;
+
+	CRXSocket	& aProxySocket = *((CRXSocket *)aThreadArg);
+	CRXProxy	* aProxy = NULL;
+
+	char		aFilterFileExtension[] = "exe|gif|jpg|png|css|js|ico|swf|";
+
+	/*----------------------------------------------------------------*/
+	for (;;)
+	{
+		aResult = aProxySocket.Accept ();
+		if (aResult < 0)
+		{
+			cerr << aProxySocket.GetErrorMessage () << endl;
+			aResult = -1;
+			break;
+		}
+
+		aProxy = new(std::nothrow) CRXProxy (aResult);
+		if (aProxy == NULL)
+		{
+			cerr << "Failed to get proxy." << endl;
+			aResult = -1;
+			break;
+		}
+		aProxy->SetServerTimeout (2);
+
+		CRXFilter		& aFilter	= aProxy->GetFilter ();
+		CRXHttpRequest	& aRequest	= aProxy->GetHttpRequest ();
+		CRXHttpResponse	& aResponse	= aProxy->GetHttpResponse ();
+
+		aFilter.SetRequestFilter (CRX_FILTER_REQUEST_FILE_EXTENSION,
+								  CRX_FILTER_MATCHED,
+								  aFilterFileExtension);
+
+		aResult = aProxy->Forward ();
+		if (aResult < 0)
+		{
+			cerr << aProxy->GetErrorMessage () << endl;
+		}
+
+		if (!aFilter.CheckRequestFilter (CRX_FILTER_REQUEST_FILE_EXTENSION, aRequest))
+		{
+			CRX_DEBUG_TRACE ("== Request:  \n%s\n", aRequest.GetHeader ().c_str ());
+			CRX_DEBUG_TRACE ("== Response: \n%s\n", aResponse.GetHeader ().c_str ());
+			CRX_DEBUG_TRACE_BIN (aResponse.GetContentBody (),
+								 aResponse.GetContentLength (),
+								 "== Content-Body: \n");
+		}
+
+		delete aProxy;
+	}
+
+	cout << " thread exit." << endl;
+	/*----------------------------------------------------------------*/
+
+	return (THREAD_FUNCTION_RETURN)0;
+}
