Exemple #1
0
void CHttpTestCase9::MHFRunL(RHTTPTransaction aTransaction,
							 const THTTPEvent& aEvent)
	{
	switch (aEvent.iStatus)
		{
	case THTTPEvent::EGotResponseHeaders:
		{
		// HTTP response headers have been received
		iEngine->Utils().LogIt(_L("<EGotResponseHeaders>\n"));
		TInt  statusCode = aTransaction.Response().StatusCode();
		iEngine->Utils().LogIt(_L("Status Code: %d \n"),statusCode);
		DumpRespHeaders(aTransaction);
		iEngine->SetCurrentStatusCode(statusCode);
		} break;
	case THTTPEvent::EGotResponseBodyData:
		{
		// Some (more) body data has been received (in the HTTP response)
		iEngine->Utils().LogIt(_L("<EGotResponseBodyData received>\n"));
		// for each chunk of data received we have to empty the buffer before
		// to be able to receive 
		MHTTPDataSupplier* body = aTransaction.Response().Body();
		body->ReleaseData();
		} break;
	case THTTPEvent::EResponseComplete:
		{
		// The transaction's response is complete
		iEngine->Utils().LogIt(_L("<EResponseComplete received >\n"));
		} break;
	case THTTPEvent::ESucceeded:
		{
		iEngine->Utils().LogIt(_L("<ESucceeded received>\n"));
		iTestFail=1;
		iEngine->Utils().LogIt(_L("<The Test will fail :ESucceeded received instead ofEFailed>\n"));
		CActiveScheduler::Stop();
		} break;
	case THTTPEvent::EFailed:
		{
		iEngine->Utils().LogIt(_L("<EFailed received>\n"));
		iEngine->Utils().LogIt(_L("<Test passed>\n"));		
		CActiveScheduler::Stop();
		} break;
	default:
		{
		iEngine->Utils().LogIt(_L("<unrecognised event>\n %d"),aEvent.iStatus);
		if (aEvent.iStatus < THTTPEvent::ERedirectedPermanently)
			{
			iTestFail=1;
			iEngine->Utils().LogIt(_L("Test Failed: The event received was not expected and it's not just a warning\n"));
			iEngine->PressAnyKey();
			CActiveScheduler::Stop();
			}
		} 
		break;
		}
	}
void CHttpEventHandler::ParseCookieL(RHTTPTransaction& aTrans)
{
	RHTTPResponse response = aTrans.Response();
	RHTTPResponse resp = aTrans.Response();
	RStringPool pool = aTrans.Session().StringPool();
    RHTTPHeaders headers = resp.GetHeaderCollection();
    
	RStringF fieldName = pool.StringF(HTTP::ESetCookie,RHTTPSession::GetTable());
	
	_LIT(KSeparator,";");
	_LIT(KPathName,";path=");
	_LIT(KEqual,"=");
	
	THTTPHdrVal val;
	if (headers.GetField(fieldName, 0, val) != KErrNotFound)
	{
		RStringF cookieValueName = pool.StringF(HTTP::ECookieValue,RHTTPSession::GetTable());
		RStringF cookieNameName = pool.StringF(HTTP::ECookieName,RHTTPSession::GetTable());
		RStringF cookiePathName = pool.StringF(HTTP::EPath,RHTTPSession::GetTable());
	
		if (val.StrF() == pool.StringF(HTTP::ECookie, RHTTPSession::GetTable()))
		{
			THTTPHdrVal cookieValue;
			THTTPHdrVal cookieName;
			THTTPHdrVal cookiePath;
			
			TInt parts = headers.FieldPartsL(fieldName);
	
			Mem::Fill((void*)iCookies.Ptr(), 1024, 0);
			
			// Get all the cookies.
			for (TInt i = 0; i < parts; i++)
			{
				headers.GetParam(fieldName, cookieValueName, cookieValue, i);
				headers.GetParam(fieldName, cookieNameName, cookieName, i);
				headers.GetParam(fieldName, cookiePathName, cookiePath, i);
				
				if ( GetHdrVal( cookieName, pool) )
					iCookies.Append(KEqual);
					
				if ( GetHdrVal( cookieValue, pool) )
				{	
					iCookies.Append(KPathName);
					GetHdrVal( cookiePath, pool);
					iCookies.Append(KSeparator);
				}
			}
		}
	}
}
//------------------------------------------------------------------------
// CTestFilter::MHFRunL
// See MHTTPFilterBase::MHFRunL 
//------------------------------------------------------------------------
//
void CTestFilter::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
{
	if (aEvent.iUID != KHTTPUid) 
		return;

	switch(aEvent.iStatus)
	{
		case THTTPEvent::ESubmit:
		{
			DoSubmitL(aTransaction);
		}
		break;

		case THTTPEvent::EGotResponseHeaders:
		{
			// Get HTTP status code from header (e.g. 200)
			RHTTPResponse resp = aTransaction.Response();
			CheckHeadersL( aTransaction );
		}
		break;
		default: 
		{
		}
		break;
	}
	
}
Exemple #4
0
// methods derived from MHTTPDataSuplier
void CHttpTestCase2::MHFRunL(RHTTPTransaction aTransaction,
							 const THTTPEvent& aEvent)
	{
	switch (aEvent.iStatus)
			{
	case THTTPEvent::EGotResponseHeaders:
		{
		iEngine->Utils().LogIt(_L("<EGotResponseHeaders received>\n"));
		DumpRespHeaders(aTransaction);
		iEngine->SetCurrentStatusCode(aTransaction.Response().StatusCode());
		} break;
	case THTTPEvent::EGotResponseBodyData:
		{
		// Some (more) body data has been received (in the HTTP response)
		iEngine->Utils().LogIt(_L("<EGotResponseBodyData received>\n"));
		DumpResponseBody(aTransaction);
		} break;
	case THTTPEvent::EResponseComplete:
		{
		// The transaction's response is complete
		iEngine->Utils().LogIt(_L("<EResponseComplete received>\n"));
		} break;
	default:
		{
		iTestFail=1;
		iEngine->Utils().LogIt(_L("<unrecognised event>\n %d"),aEvent.iStatus);
		iEngine->PressAnyKey();
		CActiveScheduler::Stop();
		} 
		break;
		}
	}
void CINC052596::ProcessHeadersL(RHTTPTransaction aTrans)
	{
	RStringF haaderName = aTrans.Session().StringPool().StringF(HTTP::EWWWAuthenticate, aTrans.Session().GetTable());
	THTTPHdrVal headerVal;
	RHTTPHeaders headers = aTrans.Response().GetHeaderCollection();
	User::LeaveIfError(headers.GetField(haaderName, 0, headerVal));
	}
void CHttpController::CheckStatusCodeL( RHTTPTransaction& aTransaction )
	{
	TInt httpStatus( aTransaction.Response().StatusCode() );
	if ( httpStatus / 100 != 2 )//responce 200 - 299, no redirections allowed
		{
		User::Leave( KHttpErrorBase - httpStatus );
		}
	}
EXPORT_C void CHttpTestTransBase::MHFRunL(RHTTPTransaction aTransaction,
						 const THTTPEvent& aEvent)
	{
	switch (aEvent.iStatus)
		{
	case THTTPEvent::EGotResponseHeaders:
		{
		// HTTP response headers have been received
		iEngine->Utils().LogIt(_L("<EGotResponseHeaders>\n"));
		DumpRespHeaders(aTransaction);
		iEngine->SetCurrentStatusCode(aTransaction.Response().StatusCode());
		} break;
	case THTTPEvent::EGotResponseBodyData:
		{
		// Some (more) body data has been received (in the HTTP response)
		iEngine->Utils().LogIt(_L("<EGotResponseBodyData received>\n"));
		// for each chunk of data received we have to empty the buffer before to be able to receive 
		MHTTPDataSupplier* body = aTransaction.Response().Body();
		body->ReleaseData();
		} break;
	case THTTPEvent::EResponseComplete:
		{
		// The transaction's response is complete
		iEngine->Utils().LogIt(_L("<EResponseComplete received >\n"));
		} break;
	case THTTPEvent::ESucceeded:
		{
		iEngine->Utils().LogIt(_L("<ESucceeded received from the VF>\n"));
		CActiveScheduler::Stop();
		} break;
	case THTTPEvent::EFailed:
		{
		iEngine->Utils().LogIt(_L("<EFailed received from the VF>\n"));
		CActiveScheduler::Stop();
		} break;
	default:
		{
		iEngine->Utils().LogIt(_L("<unrecognised event>\n %d"),aEvent.iStatus);
		iEngine->Utils().LogIt(_L("Test Failed\n"));
		iEngine->PressAnyKey();
		CActiveScheduler::Stop();
		} 
		break;
		}
	}
void CHttpEventHandler::DumpRespBody(RHTTPTransaction& aTrans)
	{
	MHTTPDataSupplier* body = aTrans.Response().Body();
	TPtrC8 dataChunk;
	TBool isLast = body->GetNextDataPart(dataChunk);
	DumpIt(dataChunk);
	if (isLast)
		iTest->Console()->Printf(_L("Got last data chunk.\n"));
	}
EXPORT_C void CHttpTestTransBase::DumpResponseBody(RHTTPTransaction& aTrans)
//dump all the body's chunks 
	{
	MHTTPDataSupplier* body = aTrans.Response().Body();
	TPtrC8 dataChunk;
	TBool isLast = body->GetNextDataPart(dataChunk);
	iEngine->Utils().DumpData(dataChunk);
	if (isLast && !iEngine->IsSilent())
		iEngine->Utils().LogIt(_L("Got last data chunk.\n"));
	body->ReleaseData();
	}
void CRecvBufSizeTest1::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
	{
	switch (aEvent.iStatus)
		{
		case THTTPEvent::EGotResponseHeaders:
			{
			iEngine->Utils().LogIt(_L("<Got response headers>"));
			} break;
		case THTTPEvent::EGotResponseBodyData:
			{
			iEngine->Utils().LogIt(_L("<Got a chunk of data>"));

			MHTTPDataSupplier* iRespBody = aTransaction.Response().Body();

			TPtrC8 bodyData;
			TBool lastChunk = iRespBody->GetNextDataPart( bodyData );

			iRespBody->ReleaseData();
			} break;
		case THTTPEvent::EResponseComplete:
			{
			iEngine->Utils().LogIt(_L("<Transaction Complete>"));
			} break;
		case THTTPEvent::ESucceeded:
			{
			iEngine->Utils().LogIt(_L("<Transaction succeeded>"));
			aTransaction.Close();
			CActiveScheduler::Stop();
			}
			break;
		case THTTPEvent::EFailed:
			{
			iEngine->Utils().LogIt(_L("<Transaction failed>"));
			aTransaction.Close();
			CActiveScheduler::Stop();
			} break;
		default:
			{
			_LIT(KLogDescription, "<unrecognised event> %d");
			iEngine->Utils().LogIt(KLogDescription,aEvent.iStatus);
			if (aEvent.iStatus < 0)
				{
				iFailureError = aEvent.iStatus;
				CActiveScheduler::Stop();
				}
			} 
			break;
		}
	
	return;
	
	}
void CHttpController::ProcessResponseHeadersL( RHTTPTransaction& aTransaction )
	{
	CheckStatusCodeL( aTransaction );
	ParseHeadersL( aTransaction );
	if ( !iOutputStream )
		{
		delete iResponseData;
		iResponseData = NULL;
		TInt len = ContentLength( aTransaction.Response().GetHeaderCollection(), iSession );
		iResponseData = HBufC8::NewL( len > 0 ? len : KMaxMemoryBuffer );
		}
	StartTimeout();
	}
void CTestTransaction::DumpResponseBody(RHTTPTransaction &aTrans)
	{
	
	MHTTPDataSupplier *body = aTrans.Response().Body();
	TPtrC8 dataChunk;
	TBool isLast = body->GetNextDataPart(dataChunk);
	Machine()->DumpData(dataChunk);
	if (isLast)// && !iEngine->IsSilent())
		{
		//	date stamp the response
		WriteDateStamp();
		Log(_L("  - Got last data chunk."));
		}
	body->ReleaseData();
	}
void CHeaderDecode::ProcessHeadersL(RHTTPTransaction aTrans)
	{
	RStringPool stringPool = aTrans.Session().StringPool();
	RHTTPHeaders headers = aTrans.Response().GetHeaderCollection();
	THTTPHdrVal hdrVal;

	//Check Content-Length header parameter is stored correctly
	RStringF contentLengthStr = stringPool.StringF(HTTP::EContentLength, aTrans.Session().GetTable());
	User::LeaveIfError(headers.GetField(contentLengthStr,0,hdrVal));

	if(headers.FieldPartsL(contentLengthStr) != 1)
		User::Leave(KErrArgument);

	if (hdrVal.Int() != 6)
		User::Leave(KErrArgument);
	}
// -----------------------------------------------------------------------------
// CHttpCacheManager::ReceivedResponseHeadersL
//
// -----------------------------------------------------------------------------
//
EXPORT_C void CHttpCacheManager::ReceivedResponseHeadersL(
  RHTTPTransaction& aTrans,
    THttpCacheEntry& aCacheEntry )
    {
    if ( iCacheEnabled || iVSSCacheEnabled )
        {
        if ( iVSSCacheEnabled &&
             VSSRequestCheckL( aTrans, aTrans.Response().GetHeaderCollection(),
                               aTrans.Request().URI().UriDes() ) )
            {
            //Modify the cache handler if VSS specific
            aCacheEntry.iCacheHandler = iphoneSpecificCache;
            }
        if ( aCacheEntry.iCacheHandler )
            {
            aCacheEntry.iCacheHandler->ReceivedResponseHeadersL( aTrans, aCacheEntry );
            }
        }
    }
void CTextModeTestMultiTrans::ValidateBodyL(RHTTPTransaction aTransaction)
{
    // In this test, the test URLs point to resources that contain just characters from the test number
    // i.e. http:/xxx/1.txt will contain only the char 1, CR or LF.
    // These numbers should also align with the transaction ID, since they were created in order
    RHTTPResponse resp = aTransaction.Response();
    MHTTPDataSupplier* body = resp.Body();
    TPtrC8 data;
    body->GetNextDataPart(data);
    TChar reqdCh = (TChar)(aTransaction.Id() + 48);
    for (TInt ii = 0; ii < data.Length(); ii++)
    {
        TChar ch = data[ii];
        if ((ch != reqdCh) && (ch != (TChar)0x0d) && (ch != (TChar)0x0a))
            User::Leave(KMultiTransFailed);
    }

    // OK - release the block
    body->ReleaseData();
}
void CHttpClientFilter::EnsureContentTypePresentL(RHTTPTransaction aTransaction)
	{
	// From RFC 2616 Section 7.2.1 - 
	//
	// Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type
	// header field defining the media type of that body. If and only if the 
	// media type is not given by a Content-Type field, the recipient MAY attempt
	// to guess the media type via inspection of its content and/or the name 
	// extension(s) of the URI used to identify the resource. If the media type
	// remains unknown, the recipient SHOULD treat it as type "application/octet-stream".

	RHTTPHeaders headers = aTransaction.Response().GetHeaderCollection();
	THTTPHdrVal contentType;
	RStringF contentTypeString = iStringPool.StringF(HTTP::EContentType, iStringTable);
	if( headers.GetField(contentTypeString, 0, contentType) == KErrNotFound )
		{
		// There is no Content-Type header - add it with a value of 
		// "application/octet-stream".
		contentType.SetStrF(iStringPool.StringF(HTTP::EApplicationOctetStream, iStringTable));
		headers.SetFieldL(contentTypeString, contentType);
		}
	}
void CHttpController::ProcessResponseBodyDataL( RHTTPTransaction& aTransaction )
	{
	MHTTPDataSupplier* body = aTransaction.Response().Body();

	TPtrC8 dataPart;
	body->GetNextDataPart( dataPart );

	if ( iOutputStream )
		{
		iOutputStream->WriteL( dataPart );
		}
	else
		{
		TInt bufLength( iResponseData->Des().Length() );
		TInt maxBufLength( iResponseData->Des().MaxLength() );
		if ( bufLength + dataPart.Length() > maxBufLength )
			{
			iResponseData = iResponseData->ReAllocL( bufLength + dataPart.Length() );
			}
		iResponseData->Des().Append( dataPart );
		}
	body->ReleaseData();
	StartTimeout();
	}
TInt CTestTransaction::MHFRunError(TInt aError, 
								  RHTTPTransaction aTransaction,
								  const THTTPEvent& aEvent)
	{
	//	date stamp the response
	WriteDateStamp();
	Log(_L("MHFRunError  : Test failed with error code %d"), aError);

	Machine()->SetErrorDefine(iTransactionName, aEvent.iStatus);

	//	set the response status code for processing l8r...
	TInt statusCode = aTransaction.Response().StatusCode();

	//	date stamp the response
	WriteDateStamp();

	Log(_L("Event Status Code: %d"), statusCode);

	Machine()->SetResultDefine(iTransactionName, statusCode);

	// SetCompletionCode(statusCode);

	return KErrNone;
	}
// ----------------------------------------------------------------------------
// CWmDrmDlaDefaultHttpManager::MHFRunL
// ----------------------------------------------------------------------------
void CWmDrmDlaDefaultHttpManager::MHFRunL(
    RHTTPTransaction aTransaction,
    const THTTPEvent& aEvent )
    {
    LOGFN( "CWmDrmDlaDefaultHttpManager::MHFRunL" );
    RHTTPResponse response;
    TPtrC8 dataChunk;

    // Either ESucceeded or EFailed will eventually occur
    switch ( aEvent.iStatus )
        {
        case THTTPEvent::EGotResponseHeaders:
            response = aTransaction.Response();

            iInCallback = ETrue;
            iObserver.OnResponseHeadersL(
                response,
                response.GetHeaderCollection(),
                iHttpSession.StringPool(),
                response.StatusCode() );

            break;

        case THTTPEvent::EGotResponseBodyData:
            // A member variable is used to store the body to avoid two
            // potential problems:
            // - OnResponseBodyDataL leaves
            // - Stop is called from within OnResponseBodyDataL
            iBody = aTransaction.Response().Body();
            User::LeaveIfNull( iBody );

            iBody->GetNextDataPart( dataChunk );

            iInCallback = ETrue;
            iObserver.OnResponseBodyDataL( dataChunk );

            // Verify that iBody wasn't already released
            // for example by calling Stop within ResponseBodyDataL
            if ( iBody )
                {
                iBody->ReleaseData();
                iBody = NULL;
                }

            break;

        case THTTPEvent::ESucceeded:
        case THTTPEvent::EFailed:
            // Deal with both the same as iError will either be negative or
            // KErrNone
            // If the user cancelled the credentials dialog then make sure we
            // return KErrCancel
            HandleDownloadComplete( iCredentialsOk ? iError : KErrCancel );
            break;

        default:
            // This will capture system and HTTP lib errors
            // For positive codes iError will remain to KErrNone
            if ( aEvent.iStatus < KErrNone )
                {
                iError = aEvent.iStatus;
                }
            break;
        }

    iInCallback = EFalse;
    }
void CINC097492_3::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
	{
	switch (aEvent.iStatus)
		{
		case THTTPEvent::EGotResponseHeaders:
			{
			// HTTP response headers have been received
			iEngine->Utils().LogIt(_L("<Got response headers>"));
			MHTTPDataSupplier* body = aTransaction.Response().Body ();
			if ( body )
				{
				body->ReleaseData ();
				}
			} break;
		case THTTPEvent::ESubmit:
			{
			} break;
		case THTTPEvent::EGotResponseBodyData:
			{
			// Some (more) body data has been received (in the HTTP response)
			iEngine->Utils().LogIt(_L("<Got a chunk of data>"));
			// Get the body data supplier
			MHTTPDataSupplier* iRespBody = aTransaction.Response().Body();
			// Append to the output file.
			TPtrC8 bodyData;
			TBool lastChunk = iRespBody->GetNextDataPart( bodyData );
			iRespBody->ReleaseData();
			} break;
		case THTTPEvent::EResponseComplete:
			{
			// The transaction's response is complete
			iEngine->Utils().LogIt(_L("<Transaction Complete>"));
			} break;
		case THTTPEvent::ESucceeded:
			{
			// The transaction succeeded
			iEngine->Utils().LogIt(_L("<Transaction succeeded>"));
			aTransaction.Close();
			if(--iOpenTransCount == 0)
				{
				CActiveScheduler::Stop();
				}
			}
			break;
		case THTTPEvent::EFailed:
			{
			// The transaction failed so fail the test
			iEngine->Utils().LogIt(_L("<Transaction failed>"));
			aTransaction.Close();
			if(--iOpenTransCount == 0)
				{
				CActiveScheduler::Stop();
				}
			} break;
		default:
			{
			_LIT(KLogDescription, "<unrecognised event> %d");
			iEngine->Utils().LogIt(KLogDescription,aEvent.iStatus);
			if (aEvent.iStatus < 0)
				{
				iFailureError = aEvent.iStatus;
				CActiveScheduler::Stop();
				}
			} 
			break;
		}
	
	return;
	}
// ---------------------------------------------------------
// CTransactionObserver::MHFRunL
// ---------------------------------------------------------
//
void CTransactionObserver::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
    {
    switch( aEvent.iStatus )
        {
        case THTTPEvent::EGotResponseBodyData:
            {
            MHTTPDataSupplier* respBody = aTransaction.Response().Body();
            TPtrC8 buf;

            respBody->GetNextDataPart( buf );

            iDownload->SetStringAttribute( EDlAttrContinueBody, buf );

            respBody->ReleaseData();
            }
            break;

        case THTTPEvent::ESucceeded:
            {
            iDownload->SetIntAttribute( EDlAttrSucceeded, 0 );
            }
            break;

        case THTTPEvent::EFailed:
        case THTTPEvent::EMoreDataReceivedThanExpected:
        case THTTPEvent::EUnrecoverableError:
        case THTTPEvent::ETooMuchRequestData:
            {
            iDownload->SetIntAttribute( EDlAttrFailed, aEvent.iStatus );
            }
            break;

        case THTTPEvent::ERedirectedPermanently:
            {
            iDownload->SetStringAttribute( EDlAttrRedirectedPermanently, 
                                           aTransaction.Request().URI().UriDes() );
            }
            break;

        case THTTPEvent::ERedirectedTemporarily:
            {
            iDownload->SetStringAttribute( EDlAttrRedirectedTemporary, 
                                           aTransaction.Request().URI().UriDes() );
            }
            break;
            
        default:
            {
            if ( aEvent.iStatus == KErrHttpPartialResponseReceived )
                {
                //Partial response has been received and connection has been disconnected. This error will be 
                //propagated to the client only, if the HTTP:ENotifyOnDisconnect property is set with a value
                //HTTP::EEnableDisconnectNotification
                
                //This error code was cancelling the pausable download. This error shud be ignored to keep the
                //paused download.
                //TSW Err ID : SXUU-77SRWL
                }
                
            else if( aEvent.iStatus < 0 )
                // error occured -> leave will be handled in OnError()
                {
                iDownload->SetIntAttribute( EDlAttrFailed, aEvent.iStatus );
                }
            }
            break;
        }
    }
void CHttpEventHandler::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
	{
	switch (aEvent.iStatus)
		{
		case THTTPEvent::EGotResponseHeaders:
			{
			// HTTP response headers have been received. We can determine now if there is
			// going to be a response body to save.
			RHTTPResponse resp = aTransaction.Response();
			TInt status = resp.StatusCode();
			
			if (iVerbose)
			{
				RStringF statusStr = resp.StatusText();
				TBuf<32> statusStr16;
				statusStr16.Copy(statusStr.DesC());
				iTest->Console()->Printf(_L("Status: %d (%S)\n"), status, &statusStr16);

				// Dump the headers if we're being verbose
				DumpRespHeadersL(aTransaction);
			}
			// Determine if the body will be saved to disk
			iSavingResponseBody = EFalse;
			if (resp.HasBody() && (status >= 200) && (status < 300) && (status != 204))
			{
				if (iVerbose)
				{
					TInt dataSize = resp.Body()->OverallDataSize();
					if (dataSize >= 0)
						iTest->Console()->Printf(_L("Response body size is %d\n"), dataSize);
					else
						iTest->Console()->Printf(_L("Response body size is unknown\n"));
				}
				iSavingResponseBody = ETrue;
			}
			else
			{
				if (iVerbose)
					iTest->Console()->Printf(_L("Response status is bad\n"));
			}

			if ((status >= 200) && (status < 300) && (status != 204))
			{
				ParseCookieL(aTransaction);
			}
			
			if (iSavingResponseBody) // If we're saving, then open a file handle for the new file
			{
				if ( iUsingFile )
				{
					iHttpFileManager->GetNewFile(iRespBodyFilePath, iRespBodyFileName, EFalse);
					
					// Check it exists and open a file handle
					TInt valid = iFileServ.IsValidName(iRespBodyFilePath);
					if (!valid)
					{
						if (iVerbose)
							iTest->Console()->Printf(_L("The specified filename is not valid!.\n"));
						
						iSavingResponseBody = EFalse;
					}
					else
					{
						TInt err = iRespBodyFile.Create(iFileServ,
													  iRespBodyFilePath,
													  EFileWrite|EFileShareExclusive);
						if (err)
						{
							iSavingResponseBody = EFalse;
							User::Leave(err);
						}
					}
				}
				else
				{
					TInt dataSize = resp.Body()->OverallDataSize();
					
					if ( iResBodyBuffer )
						delete iResBodyBuffer;
						
					iResBodyBuffer = NULL;
					
					if ( dataSize > 50 * 1024) //skip large chunks of data
					{
						iSavingResponseBody = false;
						//try to stop current connection
						if (iVerbose)
							iTest->Console()->Printf(_L("Transaction Failed\n"));
						aTransaction.Close();
						CActiveScheduler::Stop();
					}
					else
					{
						iResBodyBuffer = HBufC8::NewMaxL(dataSize);
						iResBodyBufferPtr.Set(iResBodyBuffer->Des());
					}					
					iCurPos = 0;
				}
			}
			
		} break;
		case THTTPEvent::EGotResponseBodyData:
			{
			// Get the body data supplier
			iRespBody = aTransaction.Response().Body();

			// Some (more) body data has been received (in the HTTP response)
			if (iVerbose)
				DumpRespBody(aTransaction);
			
			// Append to the output file if we're saving responses
			if (iSavingResponseBody)
			{
				TPtrC8 bodyData;
				TBool lastChunk = iRespBody->GetNextDataPart(bodyData);
								
				if ( iUsingFile )
				{
					iRespBodyFile.Write(bodyData);
					if (lastChunk)
					{
						iRespBodyFile.Flush();
						iRespBodyFile.Rename(iRespBodyFileName);
						iRespBodyFile.Close();
					}
				}
				else
				{
					Mem::Copy((void*)(iResBodyBuffer->Ptr()+iCurPos), (void*)bodyData.Ptr(), bodyData.Size());
					iCurPos += bodyData.Size();
				}
			}

			// Done with that bit of body data
			iRespBody->ReleaseData();
			} break;
		case THTTPEvent::EResponseComplete:
			{
			// The transaction's response is complete
			if (iVerbose)
				iTest->Console()->Printf(_L("\nTransaction Complete\n"));
			} break;
		case THTTPEvent::ESucceeded:
			{
			if (iVerbose)
				iTest->Console()->Printf(_L("Transaction Successful\n"));
			aTransaction.Close();
			CActiveScheduler::Stop();
			} break;
		case THTTPEvent::EFailed:
			{
			if (iVerbose)
				iTest->Console()->Printf(_L("Transaction Failed\n"));
			aTransaction.Close();
			CActiveScheduler::Stop();
			} break;
		case THTTPEvent::ERedirectedPermanently:
			{
			if (iVerbose)
				iTest->Console()->Printf(_L("Permanent Redirection\n"));
			} break;
		case THTTPEvent::ERedirectedTemporarily:
			{
			if (iVerbose)
				iTest->Console()->Printf(_L("Temporary Redirection\n"));
			} break;
		default:
			{
			if (iVerbose)
				iTest->Console()->Printf(_L("<unrecognised event: %d>\n"), aEvent.iStatus);
			// close off the transaction if it's an error
			if (aEvent.iStatus < 0)
				{
				aTransaction.Close();
				CActiveScheduler::Stop();
				}
			} break;
		}
	}
void CTestTransaction::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
{
	//	log the event code 
	THTTPEvent	receivedError = aEvent;

	Machine()->SetErrorDefine(iTransactionName, receivedError.iStatus);

	if (aEvent.iStatus < 0)
		{
		WriteDateStamp();

		switch (aEvent.iStatus)
			{
			case KErrEtelNoAnswer : 
				Log(_L("CCmdTransaction::MHFRunL(%S) - No Answer! Has the RAS or Internet Connection been enabled???"), &iTransactionName); 
				break;
			case -3606 : 
				Log(_L("CCmdTransaction::MHFRunL(%S) - Not able to make connection due to invalid or undefined COMMSDB configuration"), &iTransactionName); 
				break;
			case KErrHttpGeneralHeaderMissingHost : 
				Log(_L("CCmdTransaction::MHFRunL(%S) - General Header missing host information"), &iTransactionName); 
				break;
			case KErrHttpCantResetRequestBody : 
				Log(_L("CCmdTransaction::MHFRunL(%S) - Cannot reset request body. Redirect received"), &iTransactionName); 
				break;
			case KErrHttpInvalidHeaderInRequest : 
				Log(_L("CCmdTransaction::MHFRunL(%S) - Invalid Header in Request"), &iTransactionName); 
				break;
			case KErrHttpEncodeUserAgent : 
				Log(_L("CCmdTransaction::MHFRunL(%S) - Invalid Encode User Agent Header in Request"), &iTransactionName); 
				break;
			default : 
				Log(_L("CCmdTransaction::MHFRunL(%S) - The error [%d] was unexpected"), &iTransactionName, aEvent.iStatus); 
				break;
			}
			
		return;
		}

	
	TInt statusCode = aTransaction.Response().StatusCode();

	WriteDateStamp();

	Log(_L("CCmdTransaction::MHFRunL( %S: Event Status Code: %d"), &iTransactionName, statusCode);

	Machine()->SetResultDefine(iTransactionName, statusCode);

	switch (aEvent.iStatus)
		{
		// The transaction's response is complete
		case THTTPEvent::EResponseComplete:
			Log(_L("(%S)  : EResponseComplete received (Event Status: %d)"),&iTransactionName, aEvent.iStatus);
			break;

		//	transaction completed (and successful)
		case THTTPEvent::ESucceeded:
			Log(_L("(%S)  : ESucceeded received from the VF (Event Status: %d)"), &iTransactionName, aEvent.iStatus);
			CloseTransaction();
			break;

		//	transaction completed (and successful)
		case THTTPEvent::EFailed:
			Log(_L("(%S)  : Transaction EFailed received (Event Status: %d)"), &iTransactionName, aEvent.iStatus);
			CloseTransaction();
			//Validate(aTransaction);
			break;

		case THTTPEvent::EGotResponseHeaders:
			{
			// HTTP response headers have been received
			Log(_L("(%S)  : EGotResponseHeaders (%d)"),&iTransactionName, aEvent.iStatus);
			
			//TInt statusCode = aTransaction.Response().StatusCode();
			//Log(_L("Status Code: %d "), statusCode);
			//SetCompletionCode(statusCode);
			DumpRespHeaders(aTransaction);
			}
			break;

		case THTTPEvent::EGotResponseBodyData:
			{
			// Some (more) body data has been received (in the HTTP response)
			Log(_L("(%S)  : EGotResponseBodyData received (Event Status: %d"), &iTransactionName, aEvent.iStatus);

			// for each chunk of data received we have to empty the buffer before to be able to receive 
			MHTTPDataSupplier *body = aTransaction.Response().Body();
			body->ReleaseData();
			} 
			break;

		case KErrHttpRequestHasBody:
			Log(_L("(%S)  : KErrHttpRequestHasBody received from the VF (Event Status: %d)"), &iTransactionName, aEvent.iStatus);
			break;

		case KErrHttpEntityHeaderMissingContentType:
			Log(_L("(%S)  : KErrHttpEntityHeaderMissingContentType received from the VF (Event Status: %d)"), &iTransactionName, aEvent.iStatus);
			break;

		case KErrHttpRequestBodyMissing:
			Log(_L("(%S)  : KErrHttpRequestBodyMissing  received from the VF (Event Status: %d)"), &iTransactionName, aEvent.iStatus);
			break;

		case KErrTimedOut:							//-33
			Log(_L("(%S)  : KErrTimedOut  received from the VF (Event Status: %d)"), &iTransactionName, aEvent.iStatus);
			break;

		case KErrHttpRedirectExceededLimit:			
			Log(_L("(%S)  : KErrHttpRedirectExceededLimit received (Event Status: %d)"), &iTransactionName, aEvent.iStatus);
			break;

		case KErrHttpRedirectNoLocationField:	
			Log(_L("(%S)  : KErrHttpRedirectNoLocationField received (Event Status: %d)"), &iTransactionName, aEvent.iStatus);
			break;

		default:
			Log(_L("(%S)  : unrecognised event> (Event Status: %d)"), &iTransactionName, aEvent.iStatus);
			if (aEvent.iStatus < THTTPEvent::ERedirectedPermanently)
				{
				Log(_L("Test Failed: The event received was not expected and it's not just a warning"));
				}
			break;
	}

	if (receivedError == THTTPEvent::EResponseComplete)
		{
		Log(_L("CCmdTransaction::MHFRunL (%S) receivedError == EResponseComplete"), &iTransactionName);
		}
	else if (receivedError == THTTPEvent::ESucceeded)
		{
		Log(_L("CCmdTransaction::MHFRunL (%S) : receivedError == ESucceeded"), &iTransactionName);
//		Machine()->Domains()->Delete(transNameValueBuf);
		DoneWaitEvents();
		}
	else if (receivedError == THTTPEvent::EFailed)
		{
//		Machine()->Domains()->Delete(transNameValueBuf);
		DoneWaitEvents();
		}
	else 
		{
//			Log(_L("CCmdTransaction::MHFRunL : (%S) iTestFail is TRUE"), &transNameValueBuf);
		DoneWaitEvents();
		}
}
void CTestTransaction::DumpRespHeaders(RHTTPTransaction &aTrans)
	{
		
	RHTTPResponse resp = aTrans.Response();
	RStringPool strP = aTrans.Session().StringPool();
	RHTTPHeaders hdr = resp.GetHeaderCollection();
	THTTPHdrFieldIter it = hdr.Fields();

	TBuf<32>  fieldName16;
	TBuf<128> fieldVal16;

	while (it.AtEnd() == EFalse)
		{
		RStringTokenF fieldNameTk = it();
		RStringF fieldName = strP.StringF(fieldNameTk);
		THTTPHdrVal hVal;
		if (hdr.GetField(fieldName, 0, hVal) == KErrNone)
			{
			TPtrC8 fieldNameStr(strP.StringF(fieldName).DesC());
			if (fieldNameStr.Length() > 32)
				fieldNameStr.Set(fieldNameStr.Left(32));

			fieldName16.Copy(fieldNameStr);

			THTTPHdrVal fieldVal;
			hdr.GetField(fieldName, 0, fieldVal);
			switch (fieldVal.Type())
				{
				case THTTPHdrVal::KTIntVal: Log(_L("%S: %d"), &fieldName16, fieldVal.Int()); break;
				case THTTPHdrVal::KStrVal:
				case THTTPHdrVal::KStrFVal:
					{
					TPtrC8 fieldValStr(strP.StringF(fieldVal.StrF()).DesC());
					if (fieldValStr.Length() > 128)
						fieldValStr.Set(fieldValStr.Left(128));

					fieldVal16.Copy(fieldValStr);
					Log(_L("%S: %S"), &fieldName16, &fieldVal16);

					//	see if we've got the Content-Type header
					if (fieldName16.Find(KHTTPContentType) != KErrNotFound)
						{
						//	check that the contenttype script sets matches (in some way) received header
						TBuf8<KMaxContentTypeSize> contTypeBuf;
						contTypeBuf.Copy(Machine()->GetDefine(KITHContentType));

						TInt iPos = fieldValStr.Find(contTypeBuf);
						if (iPos == KErrNotFound)
							Log(_L("  - Content Type string [%S:%S] is different to ContentType setting"), &fieldName16, &fieldVal16);
						else	
							Log(_L("  - Content Type [%S:%S] acknowledged"), &fieldName16, &fieldVal16);
						}
					} 
					break;
				case THTTPHdrVal::KDateVal: 
					{
					TDateTime myDate = fieldVal.DateTime();
					WriteDateStamp(myDate); 
					Log(_L(" : %S"), &fieldName16);
					}
					break;

				default: Log(_L("%S: <unrecognised value type>"), &fieldName16); break;
				}
			}
		++it;
		}
	}
EXPORT_C void CHttpTestTransBase::DumpRespHeaders(RHTTPTransaction& aTrans)
//dump the message's headers
	{
	//dump the message's headers
	RHTTPResponse resp = aTrans.Response();
	TInt status = resp.StatusCode();
	if (!iEngine->IsSilent())
		iEngine->Utils().LogIt(_L("Status code = %d\n"), status);

	RStringPool strP = aTrans.Session().StringPool();
	RHTTPHeaders hdr = resp.GetHeaderCollection();
	THTTPHdrFieldIter it = hdr.Fields();

	TBuf<32>  fieldName16;
	TBuf<128> fieldVal16;

	while (it.AtEnd() == EFalse)
		{
		RStringTokenF fieldNameTk = it();
		RStringF fieldName = strP.StringF(fieldNameTk);
		THTTPHdrVal hVal;
		if (hdr.GetField(fieldName,0,hVal) == KErrNone)
			{
			TPtrC8 fieldNameStr(strP.StringF(fieldName).DesC());
			if (fieldNameStr.Length() > 32)
				fieldNameStr.Set(fieldNameStr.Left(32));

			fieldName16.Copy(fieldNameStr);

			THTTPHdrVal fieldVal;
			hdr.GetField(fieldName,0,fieldVal);
			switch (fieldVal.Type())
				{
				case THTTPHdrVal::KTIntVal:
					{
					iEngine->Utils().LogIt(_L("%S: %d\n"), &fieldName16, fieldVal.Int());
					} break;
				case THTTPHdrVal::KStrVal:
				case THTTPHdrVal::KStrFVal:
					{
					TPtrC8 fieldValStr(strP.StringF(fieldVal.StrF()).DesC());
					if (fieldValStr.Length() > 128)
						fieldValStr.Set(fieldValStr.Left(128));

					fieldVal16.Copy(fieldValStr);
					iEngine->Utils().LogIt(_L("%S: %S\n"), &fieldName16, &fieldVal16);
					} break;
				case THTTPHdrVal::KDateVal:
					{
					TDateTime date = fieldVal.DateTime();
					TTime t(date);
					TBuf<128> dateTimeString;
					TRAPD(err,t.FormatL(dateTimeString,KDateFormat));
					if (err == KErrNone)
						iEngine->Utils().LogIt(_L("%S: %S\n"), &fieldName16, &dateTimeString);
					} break;
				default:
					{
					iEngine->Utils().LogIt(_L("%S: <unrecognised value type>\n"), &fieldName16);
					}
				}
			}
		++it;
		}
	}
Exemple #26
0
void CHttpTestCase5::MHFRunL(RHTTPTransaction aTransaction,
						 const THTTPEvent& aEvent)
	{
	switch (aEvent.iStatus)
			{
	case THTTPEvent::EGotResponseHeaders:
		{
		// HTTP response headers have been received
		iEngine->Utils().LogIt(_L("<EGotResponseHeaders>\n"));
		TInt  statusCode = aTransaction.Response().StatusCode();
		iEngine->Utils().LogIt(_L("Status Code: %d \n"),statusCode);
		DumpRespHeaders(aTransaction);
		iEngine->SetCurrentStatusCode(statusCode);
		//define 2 RStringF : I want to find a header-field header-vaulue match in the response headers
		_LIT8(KContentTypeValSyncMl, "application/vnd.syncml-xml"); // ota content type header
  		RStringF contTypeStr = iMyStrP.StringF(HTTP::EContentType,RHTTPSession::GetTable());
		RStringF syncmlStr = iMyStrP.OpenFStringL(KContentTypeValSyncMl);
		// get  a handle for the headers
		RHTTPHeaders hdr =aTransaction.Response().GetHeaderCollection();
		//parse the headers and look for application/vnd.syncml-xml header
		THTTPHdrVal hVal;
		if(hdr.GetField(contTypeStr,0,hVal)== KErrNone) 
			{// Content-Type header is present
			if (hVal.StrF()==syncmlStr)
				iEngine->Utils().LogIt(_L("\nOk header application/vnd.syncml-xml found"));
			else 
				iEngine->Utils().LogIt(_L("\nThe server doesn't support the application/vnd.syncml-xml header"));
			}
		syncmlStr.Close();
		if (iExpectedStatusCode != statusCode)
			{
			iTestFail=1;
			iEngine->Utils().LogIt(_L("<The Test will fail :The expected status code doesn't match the actual status code received>\n"));
			}
		} break;
	case THTTPEvent::EGotResponseBodyData:
		{
		// Some (more) body data has been received (in the HTTP response)
		iEngine->Utils().LogIt(_L("<EGotResponseBodyData received>\n"));
		DumpResponseBody(aTransaction);
		} break;
	case THTTPEvent::EResponseComplete:
		{
		// The transaction's response is complete
		iEngine->Utils().LogIt(_L("<EResponseComplete received >\n"));
		} break;
	case THTTPEvent::ESucceeded:
		{
		iEngine->Utils().LogIt(_L("<ESucceeded received >\n"));
		CActiveScheduler::Stop();
		} break;
	default:
		{
		iEngine->Utils().LogIt(_L("<unrecognised event>\n %d"),aEvent.iStatus);
		if (aEvent.iStatus < THTTPEvent::ERedirectedPermanently)
			{
			iTestFail=1;
			iEngine->Utils().LogIt(_L("Test Failed: The event received was not expected and it's not just a warning\n"));
			iEngine->PressAnyKey();
			CActiveScheduler::Stop();
			}
		} 
		break;
		}
	}
void CHttpController::ParseHeadersL( RHTTPTransaction& aTransaction )
	{
	const TInt KMaxNumericLen = 32;

	RStringPool stringPool = aTransaction.Session().StringPool();
	RHTTPHeaders header = aTransaction.Response().GetHeaderCollection();
	THTTPHdrFieldIter iterator = header.Fields();

	HBufC8* fieldName8 = NULL;
	HBufC8* fieldVal8 = NULL;
	CHttpHeaders* headers = CHttpHeaders::NewLC();
	while ( !iterator.AtEnd() )
		{
		RStringTokenF fieldName = iterator();
		RStringF fieldNameStr = stringPool.StringF( fieldName );
		THTTPHdrVal fieldVal;
		if ( header.GetField( fieldNameStr, 0, fieldVal ) == KErrNone )
			{
			fieldName8 = fieldNameStr.DesC().AllocLC();
			switch ( fieldVal.Type() )
				{
				case THTTPHdrVal::KTIntVal:
					{
					fieldVal8 = HBufC8::NewLC( KMaxNumericLen );
					TPtr8 ptr( fieldVal8->Des() );
					ptr.Num( fieldVal.Int() );
					break;
					}
				case THTTPHdrVal::KStrFVal:
					{
					RStringF fieldValStr = stringPool.StringF( fieldVal.StrF() );
					fieldVal8 = fieldValStr.DesC().AllocLC();
					break;
					}
				case THTTPHdrVal::KStrVal:
					{
					RString fieldValStr = stringPool.String( fieldVal.Str() );
					fieldVal8 = fieldValStr.DesC().AllocLC();
					break;
					}
				case THTTPHdrVal::KDateVal:
					{
					_LIT(KDateFormat,"%D%M%Y%/0%1%/1%2%/2%3%/3 %:0%H%:1%T%:2%S.%C%:3");
					TDateTime date = fieldVal.DateTime();
					const TInt KMaxDateBuferLength = 100;
					TBuf< KMaxDateBuferLength > dateBuffer;
					TTime time( date );
					time.FormatL( dateBuffer, KDateFormat );
					fieldVal8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( dateBuffer );
					CleanupDeletePushL( fieldVal8 );
					break;
					}
				default:
					User::Leave( KErrNotSupported );//new field types will be added in future
					break;
				}
			if ( !fieldVal8 )
				{
				CleanupStack::PopAndDestroy( fieldName8 );
				}
			else
				{
				headers->AddL( *fieldName8, *fieldVal8 );
				CleanupStack::PopAndDestroy( 2, fieldName8 );
				}
			fieldVal8 = NULL;
			fieldName8 = NULL;
			}
		++iterator;
		}

	iObserver->HeadersReceivedL( headers );
	CleanupStack::Pop( headers );
	}
Exemple #28
0
// ----------------------------------------------------------------------------
// CClientEngine::MHFRunL()
//
// Inherited from MHTTPTransactionCallback
// Called by framework to pass transaction events.
// ----------------------------------------------------------------------------
void CClientEngine::MHFRunL(RHTTPTransaction aTransaction,
						  const THTTPEvent& aEvent)
	{
	switch (aEvent.iStatus)
		{
		case THTTPEvent::EGotResponseHeaders:
			{
			// HTTP response headers have been received. Use
			// aTransaction.Response() to get the response. However, it's not
			// necessary to do anything with the response when this event occurs.

			// Get HTTP status code from header (e.g. 200)
			RHTTPResponse resp = aTransaction.Response();
			TInt status = resp.StatusCode();

			// Get status text (e.g. "OK")
			TBuf<KStatustextBufferSize> statusText;
			statusText.Copy(resp.StatusText().DesC());

			TBuf<KDefaultBufferSize> text;
			_LIT(KHeaderReceived, "Header received. Status: %d %S");
			text.Format(KHeaderReceived, status, &statusText);
			iObserver.ClientEvent(text);
			}
			break;

		case THTTPEvent::EGotResponseBodyData:
			{
			// Part (or all) of response's body data received. Use
			// aTransaction.Response().Body()->GetNextDataPart() to get the actual
			// body data.
	
			// Get the body data supplier
			MHTTPDataSupplier* body = aTransaction.Response().Body();
			TPtrC8 dataChunk;

			// GetNextDataPart() returns ETrue, if the received part is the last
			// one.
			TBool isLast = body->GetNextDataPart(dataChunk);
			iObserver.ClientBodyReceived(dataChunk);

			TBuf<KInfotextBufferSize> text;
			_LIT(KBodyPartReceived, "%d bytes received... ");
			text.Format(KBodyPartReceived, dataChunk.Length());
			iObserver.ClientEvent(text);

			// NOTE: isLast may not be ETrue even if last data part received.
			// (e.g. multipart response without content length field)
			// Use EResponseComplete to reliably determine when body is completely
			// received.
			if (isLast)
				{
				_LIT(KBodyReceived,"Body received");
				iObserver.ClientEvent(KBodyReceived);
				}

			// Always remember to release the body data.
			body->ReleaseData();
			}
			break;

		case THTTPEvent::EResponseComplete:
			{
			// Indicates that header & body of response is completely received.
			// No further action here needed.
			_LIT(KTransactionComplete, "Transaction Complete");
			iObserver.ClientEvent(KTransactionComplete);
			}
			break;

		case THTTPEvent::ESucceeded:
			{
			// Indicates that transaction succeeded.
			_LIT(KTransactionSuccessful, "Transaction Successful");
			iObserver.ClientEvent(KTransactionSuccessful);

			// Transaction can be closed now. It's not needed anymore.
			aTransaction.Close();
			iRunning = EFalse;
			}
			break;

		case THTTPEvent::EFailed:
			{
			// Transaction completed with failure.
			_LIT(KTransactionFailed, "Transaction Failed");
			iObserver.ClientEvent(KTransactionFailed);
			aTransaction.Close();
			iRunning = EFalse;
			}
			break;

		default:
			// There are more events in THTTPEvent, but they are not usually
			// needed. However, event status smaller than zero should be handled
			// correctly since it's error.
			{
			TBuf<KInfotextBufferSize> text;
			if (aEvent.iStatus < 0)
				{
				_LIT(KErrorStr, "Error: %d");
				text.Format(KErrorStr, aEvent.iStatus);
				// Just close the transaction on errors
				aTransaction.Close();
				iRunning = EFalse;
				} 
			else 
				{
				// Other events are not errors (e.g. permanent and temporary
				// redirections)
				_LIT(KUnrecognisedEvent, "Unrecognised event: %d");
				text.Format(KUnrecognisedEvent, aEvent.iStatus);
				}
			iObserver.ClientEvent(text);
			}
			break;
		}
	}
/**
 * CSymbianTransportAgent::MHFRunL()
 * Inherited from MHTTPTransactionCallback
 * Called by framework to pass transaction events.
 */
void CSymbianTransportAgent::MHFRunL( RHTTPTransaction aTransaction, 
                                const THTTPEvent& aEvent )
{
    LOG.debug("entering CSymbianTransportAgent::MHFRunL: iStatus = %d", aEvent.iStatus);

    switch ( aEvent.iStatus ) 
    {
        case THTTPEvent::EGotResponseHeaders:
        {
            LOG.debug(" -> EGotResponseHeaders");
            // HTTP response headers have been received. Use
            // aTransaction.Response() to get the response. However, it's not
            // necessary to do anything with the response when this event occurs.
            // Get HTTP status code from header (e.g. 200)
            RHTTPResponse resp = aTransaction.Response();
            TInt status = resp.StatusCode();

            // Get status text (e.g. "OK")
            // TBuf<32> statusText;
            // statusText.Copy( resp.StatusText().DesC() );
        
            // Please see
            // Symbian OS v9.1 << Symbian OS reference >> C++ component reference
            // << Application protocols HTTP >> HTTPStatus
            // for other status methods and constants
            HTTPStatus httpStatus;
            if (httpStatus.IsClientError(status)) {
                // errors in range 4xx
                SetHttpClientError(status);
            } else if (httpStatus.IsServerError(status)) {
                // errors in range 5xx
                SetHttpServerError(status);
            }
            LOG.debug("Returned HTTP status: %d", status);
        }
        break;

        case THTTPEvent::EGotResponseBodyData:
        {
            LOG.debug(" -> EGotResponseBodyData: setting the response");
            // Part (or all) of response's body data received. Use 
            // aTransaction.Response().Body()->GetNextDataPart() to get the actual
            // body data.
            // Get body data
            MHTTPDataSupplier* dataSupplier = aTransaction.Response().Body();
            TPtrC8 ptr;
            dataSupplier->GetNextDataPart(ptr);

            // Append to buffer
            if(!iResponseBody)
            {
                iResponseBody = HBufC8::NewL(ptr.Length());
                iResponseBody->Des().Copy(ptr);
            }
            else
            {
                iResponseBody = iResponseBody->ReAllocL(iResponseBody->Length()+ptr.Length());
                iResponseBody->Des().Append(ptr);
            }
            
            // release the body data
            dataSupplier->ReleaseData();

        }
        break;

        case THTTPEvent::EResponseComplete:
        {
            LOG.debug(" -> EResponseComplete");
            // Indicates that header & body of response is completely received.
            // No further action here needed.
        }
        break;

        case THTTPEvent::ESucceeded:
        {
            LOG.debug(" -> ESucceeded: stopping the AScheduler");
            // Indicates that transaction succeeded. 
            iTransFailed = EFalse;
            iASWait->AsyncStop();
        }
        break;

        case THTTPEvent::EFailed:
        {
            LOG.debug(" -> EFailed: stopping the AScheduler");
            iTransFailed = ETrue;
            iASWait->AsyncStop();
        }
        break;

        default:
        {
            // There are more events in THTTPEvent, but they are not usually 
            // needed. However, event status smaller than zero should be handled 
            // correctly since it's error.     
            LOG.debug(" -> default");
            
            if (aEvent.iStatus < 0) {
                LOG.debug("error status: stopping the AScheduler");
                // Signal the active scheduler on errors
                iTransFailed = ETrue;
                iASWait->AsyncStop();
            } 
            else {
                LOG.debug("non error status: ignoring");
                // Other events are not errors (e.g. permanent and temporary redirections)
            }
        }
        break;
    }
    
    LOG.debug("exiting CSymbianTransportAgent::MHFRunL");
}
void UPPayHttpConnection::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
{
	
	switch (aEvent.iStatus)
	{
	case THTTPEvent::ERedirectedPermanently:
	case THTTPEvent::ERedirectedTemporarily:

		break;
	case THTTPEvent::EGotResponseHeaders:
	{
		RHTTPResponse resp = aTransaction.Response();
		ParaseResponseHeaders(resp);
		iEngineStatus = EGetHeader;
		if (iObserver)
		{
			iObserver->StateChange(EGetHeader);
		}
		
		AddTimer();
		//iObserver.ProgressNotify(iContentLength,0);
	}
		break;

	case THTTPEvent::EGotResponseBodyData:
	{
		MHTTPDataSupplier* dataSupplier = aTransaction.Response().Body();
		TPtrC8 ptr;
		TBool isLast = dataSupplier->GetNextDataPart(ptr);
		if (iContentLength > 0)
		{
			if (!iResponseBuffer)
			{
				iResponseBuffer = HBufC8::NewL(iContentLength);
			}
			iResponseBuffer->Des().Append(ptr);
		}
		else
		{
			if (!iResponseBuffer)
			{
				iResponseBuffer = ptr.Alloc();
			}
			else
			{
				iResponseBuffer = iResponseBuffer->ReAllocL(iResponseBuffer->Length() + ptr.Length());
				iResponseBuffer->Des().Append(ptr);
			}
		}
		dataSupplier->ReleaseData();
		if (iResponseBuffer && iObserver)
		{
			iObserver->ProgressNotify(iContentLength, iResponseBuffer->Length());
		}
		if (isLast)
		{
			
			iEngineStatus = EHttpFinished;
			Stop();
			if (iObserver)
			{
				iObserver->ResponseReceivedL(iResponseBuffer);
			}
			if (iObserver)
			{
				iObserver->StateChange(EHttpFinished);
			}

		}
		else
		{
			
			iEngineStatus = EGetBody;
			AddTimer();
		}
	}
		break;

	case THTTPEvent::EResponseComplete:
	{
		iEngineStatus = EHttpFinished;

		if (iResponseBuffer && iObserver)
		{
			iObserver->ProgressNotify(iContentLength, iResponseBuffer->Length());
		}
		if (iObserver)
		{
			iObserver->StateChange(EHttpFinished);
		}
		Stop();

	}
		break;
	case THTTPEvent::ESucceeded:
	{
		iEngineStatus = EHttpFinished;
		if (iResponseBuffer && iObserver)
		{
			iObserver->ProgressNotify(iContentLength, iResponseBuffer->Length());
		}
		if (iObserver)
		{
			iObserver->StateChange(EHttpFinished);
		}
		Stop();
	}
		break;
	case THTTPEvent::EFailed:
	{
		Stop();
		if (iObserver)
		{
			iObserver->StateChange(EHttpError);
		}
	}
		break;
	default:
		break;
	}
}