Changeset 44 in cheroxy for trunk/src/CRXProxy.cpp


Ignore:
Timestamp:
11/22/12 15:21:02 (11 years ago)
Author:
cheese
Message:

#1 change logic more detail

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/CRXProxy.cpp

    r40 r44  
    2525}
    2626
    27 CRXProxy *
    28 CRXProxy::GetNewInstance (void)
    29 {
    30     /*----------------------------------------------------------------*/
    31     /*----------------------------------------------------------------*/
    32 
    33     return new(std::nothrow) CRXProxy ();
    34 }
    35 
    36 void
    37 CRXProxy::ReleaseInstance (void)
    38 {
    39     /*----------------------------------------------------------------*/
    40     delete this;
    41     /*----------------------------------------------------------------*/
    42 }
    43 
    4427void
    4528CRXProxy::SetClientSocket (const int aSocket)
     
    141124{
    142125    /*----------------------------------------------------------------*/
    143     mHttpRequest = aHttpRequest;
     126    mHttpRequest.SetHeader (aHttpRequest);
    144127    /*----------------------------------------------------------------*/
    145128}
     
    158141    if (aPtr == NULL)
    159142        return NULL;
    160    
     143
    161144    aCopyLength = aRemainLength < aHeaderLength ? aBufferSize : aHeaderLength;
    162145    if (aCopyLength > 0)
     
    180163{
    181164    /*----------------------------------------------------------------*/
    182     mHttpResponse = aHttpResponse;
     165    mHttpResponse.SetHeader (aHttpResponse);
    183166    /*----------------------------------------------------------------*/
    184167}
     
    249232CRXProxy::ReceiveRequest (void)
    250233{
    251     int                 aResult     = 0;
    252 
    253     const unsigned int  aBufferSize = 1024 * 56;
    254     char                aBuffer[aBufferSize + 1] = {0x00, };
    255 
    256     /*----------------------------------------------------------------*/
    257     aResult = mClient.Receive (aBuffer, aBufferSize);
    258     if (aResult < 0)
    259     {
    260         aResult = ERROR_PROXY_FAILED_TO_RECEIVE_REQUEST;
    261         CRX_ADD_SUBCLASS_ERROR (mClient);
    262         CRX_ERROR_SET (aResult, "Failed to receive from client.");
    263         return aResult;
    264     }
    265 
    266     /* parse http request */
    267     mHttpRequest = aBuffer;
     234    int         aResult = 0;
     235    char        aBuffer;
     236
     237    std::string aHttpHeader;
     238    /*----------------------------------------------------------------*/
     239    for (;;)
     240    {
     241        aResult = mClient.Receive (&aBuffer, 1);
     242        if (aResult < 0)
     243        {
     244            aResult = ERROR_PROXY_FAILED_TO_RECEIVE_REQUEST;
     245            CRX_ADD_SUBCLASS_ERROR (mClient);
     246            CRX_ERROR_SET (aResult, "Failed to receive from client.");
     247            return aResult;
     248        }
     249        aHttpHeader += aBuffer;
     250        if (aHttpHeader.rfind (CRLF2) != std::string::npos)
     251            break;
     252    }
     253
     254    mHttpRequest.SetHeader (aHttpHeader.c_str ());
    268255    /*----------------------------------------------------------------*/
    269256
     
    292279            return aResult;
    293280        }
    294 
    295         if (getsockname (mServer, (struct sockaddr *) &aSockName, &aSockLen) == 0)
    296             CRX_DEBUG_TRACE ("Connected on port number (%d)\n", ntohs (aSockName.sin_port));
    297281    }
    298282
     
    315299    const unsigned int  aBufferSize     = 1024 * 64;
    316300    char                aBuffer[aBufferSize + 1] = {0x00, };
    317 
    318     std::string         aHttpResponse;
    319301
    320302    /*----------------------------------------------------------------*/
     
    331313            return aResult;
    332314        }
    333         else if (aResult == 0)
    334         {
    335             break;
    336         }
    337 
    338         aResult = mHttpResponse.SetResponse (aBuffer, aResult);
     315
     316        aResult = mHttpResponse.SetResponseAll (aBuffer, aResult);
    339317        if (aResult)
    340318        {
     
    343321            return aResult;
    344322        }
    345 
    346         if (!CheckRequestFilter (CRX_FILTER_REQUEST_FILE_EXTENSION) &&
    347             mHttpResponse.GetContentLength () > 0)
    348         {
    349             CRX_DEBUG_TRACE_BIN (mHttpResponse.GetContentBody (),
    350                                  mHttpResponse.GetContentLength (),
    351                                  "");
    352         }
    353323    }
    354324    /*----------------------------------------------------------------*/
Note: See TracChangeset for help on using the changeset viewer.