Changeset 35 in cheroxy


Ignore:
Timestamp:
11/20/12 19:06:30 (11 years ago)
Author:
cheese
Message:

#1 add debugging message

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/CRXException.h

    r24 r35  
    1212#endif
    1313
    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,...)                                     \
    1551    do {                                                                    \
    16         SetErrorCode (__CODE);                                          \
     52        SetErrorCode (__CODE);                                              \
    1753        SetErrorMessage (__FILE__,__func__,__LINE__,__FMT,##__VA_ARGS__);   \
    1854    } while (0)
    1955
    20 #define CRX_ERROR_ADD(__MESSAGE)                                            \
     56#define CRX_ADD_SUBCLASS_ERROR(__SUB_CLASS)                                 \
    2157    do {                                                                    \
    22         AddMessage (__MESSAGE);                                             \
     58        AddMessage (__SUB_CLASS.GetErrorMessage ().c_str ());               \
    2359    } while (0)
    2460
  • trunk/include/CRXProxy.h

    r28 r35  
    6565
    6666    void    SetHttpResponse             (const char * aHttpResponse);
    67     char *  GetHttpResponse             (char       * aBuffer,
     67    char *  GetHttpResponseHeader       (char       * aBuffer,
    6868                                         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;
    7073   
    7174    int     ReceiveRequest              (void);
  • trunk/src/CRXProxy.cpp

    r34 r35  
    9999    {
    100100        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.");
    102102    }
    103103
     
    106106    {
    107107        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.");
    109109        return aResult;
    110110    }
     
    114114    {
    115115        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.");
    117117    }
    118118
     
    121121    {
    122122        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.");
    124124        return aResult;
    125125    }
     
    177177
    178178char *
    179 CRXProxy::GetHttpResponse (char         * aBuffer,
    180                           const int    aBufferSize) const
     179CRXProxy::GetHttpResponseHeader (char       * aBuffer,
     180                                const int  aBufferSize) const
    181181{
    182182    void        * aPtr = static_cast<void *> (aBuffer);
     
    185185    int         aRemainLength   = aBufferSize;
    186186    const int   aHeaderLength   = mHttpResponse.GetHeader ().length ();
    187     const int   aContentLength  = mHttpResponse.GetContentLength ();
    188187
    189188    /*----------------------------------------------------------------*/
     
    194193    if (aCopyLength > 0)
    195194        memcpy (aPtr, mHttpResponse.GetHeader ().c_str (), aCopyLength);
    196 
    197     aRemainLength -= aCopyLength;
     195    /*----------------------------------------------------------------*/
     196
     197    return aBuffer;
     198}
     199
     200int
     201CRXProxy::GetHttpResponseHeaderLength (void) const
     202{
     203    /*----------------------------------------------------------------*/
     204    /*----------------------------------------------------------------*/
     205
     206    return mHttpResponse.GetHeader ().length ();
     207}
     208
     209char *
     210CRXProxy::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;
    198222
    199223    aCopyLength = aRemainLength < aContentLength ? aRemainLength : aContentLength;
     
    206230
    207231int
    208 CRXProxy::GetHttpResponseLength (void) const
    209 {
    210     /*----------------------------------------------------------------*/
    211     /*----------------------------------------------------------------*/
    212 
    213     return mHttpResponse.GetHeader ().length ()
    214          + mHttpResponse.GetContentLength ();
     232CRXProxy::GetHttpResponseBodyLength (void) const
     233{
     234    /*----------------------------------------------------------------*/
     235    /*----------------------------------------------------------------*/
     236
     237    return mHttpResponse.GetContentLength ();
    215238}
    216239
     
    228251    {
    229252        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.");
    232255        return aResult;
    233256    }
     
    254277        {
    255278            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 ());
    258281            return aResult;
    259282        }
     
    263286    if (aResult != aSize)
    264287    {
    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 ());
    267290    }
    268291    /*----------------------------------------------------------------*/
     
    290313        {
    291314            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.");
    294317            return aResult;
    295318        }
     
    303326        {
    304327            aResult = ERROR_PROXY_FAILED_TO_SET_RESPONSE;
    305             CRX_ERROR (aResult, "Failed to set response");
     328            CRX_ERROR_SET (aResult, "Failed to set response.");
    306329            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                                 "");
    307338        }
    308339    }
     
    323354    if (aResult != aSize)
    324355    {
    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.");
    327358        return aResult;
    328359    }
     
    332363    if (aResult != aSize)
    333364    {
    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.");
    336367    }
    337368    /*----------------------------------------------------------------*/
  • trunk/src/CRXSocket.cpp

    r24 r35  
    112112    {
    113113        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.");
    115115    }
    116116    /*----------------------------------------------------------------*/
     
    188188    {
    189189        aResult = ERROR_TCPSOCKET_ALREADY_IN_USE;
    190         CRX_ERROR (aResult, "Already in use.");
     190        CRX_ERROR_SET (aResult, "Already in use.");
    191191        return aResult;
    192192    }
     
    196196    {
    197197        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 ());
    199199        return aResult;
    200200    }
     
    219219    {
    220220        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 ());
    222222        return aResult;
    223223    }
     
    233233        {
    234234            aResult = ERROR_TCPSOCKET_FAILED_TO_GET_HOSTNAME;
    235             CRX_ERROR (aResult, "Failed to get hostname.");
     235            CRX_ERROR_SET (aResult, "Failed to get hostname.");
    236236            return aResult;
    237237        }
     
    244244    {
    245245        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 ());
    247247        return aResult;
    248248    }
     
    252252    {
    253253        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 ());
    255255    }
    256256
     
    271271    {
    272272        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 ());
    274274        return aResult;
    275275    }
     
    283283    {
    284284        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 ());
    286286        return aResult;
    287287    }
     
    291291    {
    292292        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 ());
    294294        return aResult;
    295295    }
     
    322322    {
    323323        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 ());
    325325        return aResult;
    326326    }
     
    353353    {
    354354        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 ());
    356356        return aResult;
    357357    }
     
    375375    {
    376376        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  
    7777    CRXProxy    * aProxy = NULL;
    7878
    79     char        aFilterFileExtension[] = "exe|gif|jpg|png|css|js|ico|";
     79    char        aFilterFileExtension[] = "exe|gif|jpg|png|css|js|ico|swf|";
    8080    char        * aHttpMessage = NULL;
    8181    int         aHttpMessageLength = 0;
     
    106106        if (aResult < 0)
    107107        {
    108             cerr << aProxy->GetErrorMessage () << endl;
     108            cout << aProxy->GetErrorMessage () << endl;
    109109        }
    110110
     
    116116            free (aHttpMessage);
    117117
    118             aHttpMessageLength = aProxy->GetHttpResponseLength ();
     118            aHttpMessageLength = aProxy->GetHttpResponseHeaderLength ();
    119119            aHttpMessage = (char *) calloc (aHttpMessageLength + 1, 1);
    120             cout << aProxy->GetHttpResponse (aHttpMessage, aHttpMessageLength) << endl;
     120            cout << aProxy->GetHttpResponseHeader (aHttpMessage, aHttpMessageLength) << endl;
    121121            free (aHttpMessage);
    122122        }
     
    125125    }
    126126
    127     cerr << " thread exit." << endl;
     127    cout << " thread exit." << endl;
    128128    /*----------------------------------------------------------------*/
    129129
Note: See TracChangeset for help on using the changeset viewer.