Changeset 35 in cheroxy for trunk/src


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

#1 add debugging message

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • 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.