- Timestamp:
- 11/20/12 19:06:30 (11 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/CRXException.h
r24 r35 12 12 #endif 13 13 14 #define CRX_ERROR(__CODE,__FMT,...) \ 14 #ifdef _DEBUG 15 #include <stdio.h> 16 #include <ctype.h> 17 #define CRX_DEBUG_TRACE(FMT, ...) \ 18 do{ \ 19 fprintf(stderr,"[DEBUG][%s %s(%d)] ",__FILE__,__func__,__LINE__); \ 20 fprintf(stderr,FMT,##__VA_ARGS__); \ 21 }while(0) 22 #define CRX_DEBUG_TRACE_BIN(__VAL,__LEN,FMT,...) \ 23 CRX_DEBUG_TRACE(FMT,##__VA_ARGS__); \ 24 do{ \ 25 int __i, __j; \ 26 unsigned char * __U_V = (unsigned char *)__VAL; \ 27 for (__i=0 ; __i<__LEN; __i+=16) \ 28 { \ 29 fprintf(stderr, "[DEBUG][%s %s(%d)] ",__FILE__,__func__,__LINE__); \ 30 fprintf(stderr, "%06x : ", __i); \ 31 for (__j=0 ; __j<16 ; __j++) \ 32 { \ 33 if (__i+__j < __LEN) \ 34 fprintf(stderr, "%02x ", __U_V[__i+__j]); \ 35 else \ 36 fprintf(stderr, " "); \ 37 } \ 38 fprintf(stderr," "); \ 39 for (__j=0 ; __j<16 ; __j++) \ 40 { \ 41 if (__i+__j < __LEN) \ 42 fprintf(stderr,"%c", \ 43 ' ' <= __U_V[__i+__j] && __U_V[__i+__j] <= '~' ? __U_V[__i+__j] : '.'); \ 44 } \ 45 fprintf(stderr,"\n"); \ 46 } \ 47 }while(0) 48 #endif 49 50 #define CRX_ERROR_SET(__CODE,__FMT,...) \ 15 51 do { \ 16 SetErrorCode (__CODE); \52 SetErrorCode (__CODE); \ 17 53 SetErrorMessage (__FILE__,__func__,__LINE__,__FMT,##__VA_ARGS__); \ 18 54 } while (0) 19 55 20 #define CRX_ ERROR_ADD(__MESSAGE)\56 #define CRX_ADD_SUBCLASS_ERROR(__SUB_CLASS) \ 21 57 do { \ 22 AddMessage (__ MESSAGE);\58 AddMessage (__SUB_CLASS.GetErrorMessage ().c_str ()); \ 23 59 } while (0) 24 60 -
trunk/include/CRXProxy.h
r28 r35 65 65 66 66 void SetHttpResponse (const char * aHttpResponse); 67 char * GetHttpResponse 67 char * GetHttpResponseHeader (char * aBuffer, 68 68 const int aBufferSize) const; 69 int GetHttpResponseLength (void) const; 69 int GetHttpResponseHeaderLength (void) const; 70 char * GetHttpResponseBody (char * aBuffer, 71 const int aBufferSize) const; 72 int GetHttpResponseBodyLength (void) const; 70 73 71 74 int ReceiveRequest (void); -
trunk/src/CRXProxy.cpp
r34 r35 99 99 { 100 100 aResult = ERROR_PROXY_FAILED_TO_RECEIVE_REQUEST; 101 CRX_ERROR (aResult, "Failed to receive from client");101 CRX_ERROR_SET (aResult, "Failed to receive from client."); 102 102 } 103 103 … … 106 106 { 107 107 aResult = ERROR_PROXY_FAILED_TO_SEND_REQUEST; 108 CRX_ERROR (aResult, "Failed to send to server");108 CRX_ERROR_SET (aResult, "Failed to send to server."); 109 109 return aResult; 110 110 } … … 114 114 { 115 115 aResult = ERROR_PROXY_FAILED_TO_RECEIVE_RESPONSE; 116 CRX_ERROR (aResult, "Failed to receive from server");116 CRX_ERROR_SET (aResult, "Failed to receive from server."); 117 117 } 118 118 … … 121 121 { 122 122 aResult = ERROR_PROXY_FAILED_TO_SEND_RESPONSE; 123 CRX_ERROR (aResult, "Failed to send to client");123 CRX_ERROR_SET (aResult, "Failed to send to client."); 124 124 return aResult; 125 125 } … … 177 177 178 178 char * 179 CRXProxy::GetHttpResponse (char* aBuffer,180 179 CRXProxy::GetHttpResponseHeader (char * aBuffer, 180 const int aBufferSize) const 181 181 { 182 182 void * aPtr = static_cast<void *> (aBuffer); … … 185 185 int aRemainLength = aBufferSize; 186 186 const int aHeaderLength = mHttpResponse.GetHeader ().length (); 187 const int aContentLength = mHttpResponse.GetContentLength ();188 187 189 188 /*----------------------------------------------------------------*/ … … 194 193 if (aCopyLength > 0) 195 194 memcpy (aPtr, mHttpResponse.GetHeader ().c_str (), aCopyLength); 196 197 aRemainLength -= aCopyLength; 195 /*----------------------------------------------------------------*/ 196 197 return aBuffer; 198 } 199 200 int 201 CRXProxy::GetHttpResponseHeaderLength (void) const 202 { 203 /*----------------------------------------------------------------*/ 204 /*----------------------------------------------------------------*/ 205 206 return mHttpResponse.GetHeader ().length (); 207 } 208 209 char * 210 CRXProxy::GetHttpResponseBody (char * aBuffer, 211 const int aBufferSize) const 212 { 213 void * aPtr = static_cast<void *> (aBuffer); 214 215 int aCopyLength = 0; 216 int aRemainLength = aBufferSize; 217 const int aContentLength = mHttpResponse.GetContentLength (); 218 219 /*----------------------------------------------------------------*/ 220 if (aPtr == NULL) 221 return NULL; 198 222 199 223 aCopyLength = aRemainLength < aContentLength ? aRemainLength : aContentLength; … … 206 230 207 231 int 208 CRXProxy::GetHttpResponseLength (void) const 209 { 210 /*----------------------------------------------------------------*/ 211 /*----------------------------------------------------------------*/ 212 213 return mHttpResponse.GetHeader ().length () 214 + mHttpResponse.GetContentLength (); 232 CRXProxy::GetHttpResponseBodyLength (void) const 233 { 234 /*----------------------------------------------------------------*/ 235 /*----------------------------------------------------------------*/ 236 237 return mHttpResponse.GetContentLength (); 215 238 } 216 239 … … 228 251 { 229 252 aResult = ERROR_PROXY_FAILED_TO_RECEIVE_REQUEST; 230 CRX_ ERROR_ADD (mClient.GetErrorMessage ().c_str ());231 CRX_ERROR (aResult, "Failed to receive from client");253 CRX_ADD_SUBCLASS_ERROR (mClient); 254 CRX_ERROR_SET (aResult, "Failed to receive from client."); 232 255 return aResult; 233 256 } … … 254 277 { 255 278 aResult = ERROR_PROXY_FAILED_TO_CONNECT_TO_SERVER; 256 CRX_ ERROR_ADD (mServer.GetErrorMessage ().c_str ());257 CRX_ERROR (aResult, "Failed to connect to server <%s>", mHttpRequest.GetURL ().c_str ());279 CRX_ADD_SUBCLASS_ERROR (mServer); 280 CRX_ERROR_SET (aResult, "Failed to connect to server <%s>.", mHttpRequest.GetURL ().c_str ()); 258 281 return aResult; 259 282 } … … 263 286 if (aResult != aSize) 264 287 { 265 CRX_ ERROR_ADD (mServer.GetErrorMessage ().c_str ());266 CRX_ERROR (aResult, "Failed to send to server <%s>", mHttpRequest.GetURL ().c_str ());288 CRX_ADD_SUBCLASS_ERROR (mServer); 289 CRX_ERROR_SET (aResult, "Failed to send to server <%s>.", mHttpRequest.GetURL ().c_str ()); 267 290 } 268 291 /*----------------------------------------------------------------*/ … … 290 313 { 291 314 aResult = ERROR_PROXY_FAILED_TO_RECEIVE_REQUEST; 292 CRX_ ERROR_ADD (mServer.GetErrorMessage ().c_str ());293 CRX_ERROR (aResult, "Failed to receive from server");315 CRX_ADD_SUBCLASS_ERROR (mServer); 316 CRX_ERROR_SET (aResult, "Failed to receive from server."); 294 317 return aResult; 295 318 } … … 303 326 { 304 327 aResult = ERROR_PROXY_FAILED_TO_SET_RESPONSE; 305 CRX_ERROR (aResult, "Failed to set response");328 CRX_ERROR_SET (aResult, "Failed to set response."); 306 329 return aResult; 330 } 331 332 if (!CheckRequestFilter (CRX_FILTER_REQUEST_FILE_EXTENSION) && 333 mHttpResponse.GetContentLength () > 0) 334 { 335 CRX_DEBUG_TRACE_BIN (mHttpResponse.GetContentBody (), 336 mHttpResponse.GetContentLength (), 337 ""); 307 338 } 308 339 } … … 323 354 if (aResult != aSize) 324 355 { 325 CRX_ ERROR_ADD (mClient.GetErrorMessage ().c_str ());326 CRX_ERROR (aResult, "Failed to send to client");356 CRX_ADD_SUBCLASS_ERROR (mClient); 357 CRX_ERROR_SET (aResult, "Failed to send to client."); 327 358 return aResult; 328 359 } … … 332 363 if (aResult != aSize) 333 364 { 334 CRX_ ERROR_ADD (mClient.GetErrorMessage ().c_str ());335 CRX_ERROR (aResult, "Failed to send to client");365 CRX_ADD_SUBCLASS_ERROR (mClient); 366 CRX_ERROR_SET (aResult, "Failed to send to client."); 336 367 } 337 368 /*----------------------------------------------------------------*/ -
trunk/src/CRXSocket.cpp
r24 r35 112 112 { 113 113 aResult = ERROR_TCPSOCKET_FAILED_TO_SETSOCKOPT; 114 CRX_ERROR (aResult, "Failed to set socket option.");114 CRX_ERROR_SET (aResult, "Failed to set socket option."); 115 115 } 116 116 /*----------------------------------------------------------------*/ … … 188 188 { 189 189 aResult = ERROR_TCPSOCKET_ALREADY_IN_USE; 190 CRX_ERROR (aResult, "Already in use.");190 CRX_ERROR_SET (aResult, "Already in use."); 191 191 return aResult; 192 192 } … … 196 196 { 197 197 aResult = ERROR_TCPSOCKET_FAILED_TO_CREATE_SOCKET; 198 CRX_ERROR (aResult, "Failed to create socket(%d).", GetSystemErrorCode ());198 CRX_ERROR_SET (aResult, "Failed to create socket(%d).", GetSystemErrorCode ()); 199 199 return aResult; 200 200 } … … 219 219 { 220 220 aResult = ERROR_TCPSOCKET_FAILED_TO_CREATE_SOCKET; 221 CRX_ERROR (aResult, "Failed to create socket(%d).", GetSystemErrorCode ());221 CRX_ERROR_SET (aResult, "Failed to create socket(%d).", GetSystemErrorCode ()); 222 222 return aResult; 223 223 } … … 233 233 { 234 234 aResult = ERROR_TCPSOCKET_FAILED_TO_GET_HOSTNAME; 235 CRX_ERROR (aResult, "Failed to get hostname.");235 CRX_ERROR_SET (aResult, "Failed to get hostname."); 236 236 return aResult; 237 237 } … … 244 244 { 245 245 aResult = ERROR_TCPSOCKET_FAILED_TO_SETSOCKOPT; 246 CRX_ERROR (aResult, "Failed to set timeout (%d).", GetSystemErrorCode ());246 CRX_ERROR_SET (aResult, "Failed to set timeout (%d).", GetSystemErrorCode ()); 247 247 return aResult; 248 248 } … … 252 252 { 253 253 aResult = ERROR_TCPSOCKET_FAILED_TO_CONNECT; 254 CRX_ERROR (aResult, "Failed to connect (%d).", GetSystemErrorCode ());254 CRX_ERROR_SET (aResult, "Failed to connect (%d).", GetSystemErrorCode ()); 255 255 } 256 256 … … 271 271 { 272 272 aResult = ERROR_TCPSOCKET_FAILED_TO_CREATE_SOCKET; 273 CRX_ERROR (aResult, "Failed to create socket(%d).", GetSystemErrorCode ());273 CRX_ERROR_SET (aResult, "Failed to create socket(%d).", GetSystemErrorCode ()); 274 274 return aResult; 275 275 } … … 283 283 { 284 284 aResult = ERROR_TCPSOCKET_FAILED_TO_BIND; 285 CRX_ERROR (aResult, "Failed to bind(%d).", GetSystemErrorCode ());285 CRX_ERROR_SET (aResult, "Failed to bind(%d).", GetSystemErrorCode ()); 286 286 return aResult; 287 287 } … … 291 291 { 292 292 aResult = ERROR_TCPSOCKET_FAILED_TO_LISTEN; 293 CRX_ERROR (aResult, "Failed to listen(%d).", GetSystemErrorCode ());293 CRX_ERROR_SET (aResult, "Failed to listen(%d).", GetSystemErrorCode ()); 294 294 return aResult; 295 295 } … … 322 322 { 323 323 aResult = ERROR_TCPSOCKET_FAILED_TO_ACCEPT; 324 CRX_ERROR (aResult, "Failed to accept(%d).", GetSystemErrorCode ());324 CRX_ERROR_SET (aResult, "Failed to accept(%d).", GetSystemErrorCode ()); 325 325 return aResult; 326 326 } … … 353 353 { 354 354 aResult = ERROR_TCPSOCKET_FAILED_TO_SEND; 355 CRX_ERROR (aResult, "Failed to send(%d).", GetSystemErrorCode ());355 CRX_ERROR_SET (aResult, "Failed to send(%d).", GetSystemErrorCode ()); 356 356 return aResult; 357 357 } … … 375 375 { 376 376 aResult = ERROR_TCPSOCKET_FAILED_TO_RECEIVE; 377 CRX_ERROR (aResult, "Failed to receive(%d).", GetSystemErrorCode ());378 return aResult; 379 } 380 381 /*----------------------------------------------------------------*/ 382 return aResult; 383 } 377 CRX_ERROR_SET (aResult, "Failed to receive(%d).", GetSystemErrorCode ()); 378 return aResult; 379 } 380 381 /*----------------------------------------------------------------*/ 382 return aResult; 383 } -
trunk/src/main.cpp
r34 r35 77 77 CRXProxy * aProxy = NULL; 78 78 79 char aFilterFileExtension[] = "exe|gif|jpg|png|css|js|ico| ";79 char aFilterFileExtension[] = "exe|gif|jpg|png|css|js|ico|swf|"; 80 80 char * aHttpMessage = NULL; 81 81 int aHttpMessageLength = 0; … … 106 106 if (aResult < 0) 107 107 { 108 c err<< aProxy->GetErrorMessage () << endl;108 cout << aProxy->GetErrorMessage () << endl; 109 109 } 110 110 … … 116 116 free (aHttpMessage); 117 117 118 aHttpMessageLength = aProxy->GetHttpResponse Length ();118 aHttpMessageLength = aProxy->GetHttpResponseHeaderLength (); 119 119 aHttpMessage = (char *) calloc (aHttpMessageLength + 1, 1); 120 cout << aProxy->GetHttpResponse (aHttpMessage, aHttpMessageLength) << endl;120 cout << aProxy->GetHttpResponseHeader (aHttpMessage, aHttpMessageLength) << endl; 121 121 free (aHttpMessage); 122 122 } … … 125 125 } 126 126 127 c err<< " thread exit." << endl;127 cout << " thread exit." << endl; 128 128 /*----------------------------------------------------------------*/ 129 129
Note:
See TracChangeset
for help on using the changeset viewer.