// ----------------------------------------------------------------------------
// CSdpMediaField::DoInternalizeL
// ----------------------------------------------------------------------------
//
void CSdpMediaField::DoInternalizeL(RReadStream& aStream)
{
    RStringF media = iPool.OpenFStringL(GetTokenFromStreamL(aStream));
    CleanupClosePushL(media);
    SetMediaL(media);
    CleanupStack::Pop();//media
    media.Close();
    TUint32 port = aStream.ReadUint32L();
    //SetPortL(aStream.ReadUint32L());
    TUint flag = aStream.ReadUint8L();
    if(flag)
    {
        SetPortCountL(aStream.ReadUint32L());
    }
    RStringF protocol =iPool.OpenFStringL(GetTokenFromStreamL(aStream));
    CleanupClosePushL(protocol);
    SetProtocolL(protocol);
    CleanupStack::Pop();//protocol
    protocol.Close();
    SetPortL(port);
    SetFormatListL(GetTokenFromStreamL(aStream));
    SetInfoL(GetTokenFromStreamL(aStream));
    SdpCodecTemplate<CSdpConnectionField>::InternalizeArrayL(*iConnectionFields,
            aStream);
    SdpCodecTemplate<CSdpBandwidthField>::InternalizeArrayL(*iBandwidthFields,
            aStream);
    if(aStream.ReadUint8L())
    {
        SetKey(CSdpKeyField::InternalizeL(aStream));
    }
    SdpCodecTemplate<CSdpAttributeField>::InternalizeArrayL(*iAttributeFields,
            aStream);
    SdpCodecTemplate<CSdpFmtAttributeField>::InternalizeArrayL(*iFmtAttrFields,
            aStream);
}
Exemple #2
0
// ---------------------------------------------------------------------------
// SdpUtil::SetDefaultNetTypeAndAddrType
// Sets network type and address type to their "default" values
// ---------------------------------------------------------------------------
//
void SdpUtil::SetDefaultNetTypeAndAddrType( 
    RStringPool aPool, 
    const TInetAddr& aAddress,
    RStringF& aNetType, 
    RStringF& aAddressType )
    {
     // Sets network type to IN
    aNetType.Close();
    aNetType = aPool.StringF( SdpCodecStringConstants::ENetType,
                              SdpCodecStringConstants::Table ).Copy();
    // Address type       
    aAddressType.Close();

    TBuf16 <KMaxAddressLength> output;
    aAddress.Output(output);


    //addresstype for IPv4    
	if((aAddress.Address() &&  !aAddress.IsV4Mapped()) ||
       (!aAddress.Address() && aAddress.IsWildAddr() && 
        output.Match(KWildAddr) == 0))
        {
        aAddressType = aPool.StringF( SdpCodecStringConstants::EAddressTypeIP4,
                                      SdpCodecStringConstants::Table ).Copy();
        }
    else
        {
		//addresstype for IPv4-Mapped IPv6 && IPv6
        aAddressType = aPool.StringF( SdpCodecStringConstants::EAddressType,
                                      SdpCodecStringConstants::Table ).Copy();
        }
    }
/**
Sets the headers.
@internalTechnology
@test
@param		aHeaders 	Headers collection
@param		aHdrField 	Header field to be added
@return		aHdrValue	Header value to be added	
*/
void CTestHttpBaseStep::SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue)
	{
	RStringF valStr = iSess.StringPool().OpenFStringL(aHdrValue);
	THTTPHdrVal val(valStr);
	aHeaders.SetFieldL(iSess.StringPool().StringF(aHdrField,RHTTPSession::GetTable()), val);
	valStr.Close();
	}
/**
@SYMTestCaseID          SYSLIB-BAFL-CT-0489
@SYMTestCaseDesc        Tests for defect number DEF043985
@SYMTestPriority        High
@SYMTestActions         Check for Panic
@SYMTestExpectedResults Tests must not fail
@SYMREQ                 REQ0000
*/
TInt RStringPoolPanicTest::DEF043985_StringFTest_ThreadL(TAny*)
	{
	__UHEAP_MARK;

	RStringPool stringPool;
	stringPool.OpenL();

	// Create a table and make it so it passes some internal tests
	// for validity as we are testing a particular internal test
	TStringTable testTable;
	testTable.iCaseSensitive = EFalse;
	testTable.iCount = 1;

	// Test for Panic
	RStringF testString = stringPool.StringF(0, testTable);
	
	// Test should never get this far as it Panics

	testString.Close();
	stringPool.Close();

	__UHEAP_MARKEND;

	return KErrNone;		
	}
Exemple #5
0
void CHttpClient::SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue)
{
    RStringF valStr = iConnectionManager->GetHTTPSession().StringPool().OpenFStringL(aHdrValue);
    THTTPHdrVal val(valStr);
    aHeaders.SetFieldL(iConnectionManager->GetHTTPSession().StringPool().StringF(aHdrField,RHTTPSession::GetTable()), val);
    valStr.Close();
}
TBool CHttpHdrTest::CompareStringL(RStringF aStr, const TDesC8& aDes)
	{
	RStringF desStr = iStrP.OpenFStringL(aDes);
	TBool retVal = (desStr == aStr);
	desStr.Close();
	return retVal;
	}
TBool CHttpHdrTest::CompareStringTokenL(RStringTokenF aStrTk, const TDesC8& aDes)
	{
	RStringF desStr = iStrP.OpenFStringL(aDes);
	RStringTokenF desStrTk = desStr;
	TBool retVal = (desStrTk == aStrTk);
	desStr.Close();
	return retVal;
	}
void UPPayHttpConnection::AddHeaderL(RHTTPHeaders aHeaders, TInt aHeaderField, const TDesC8& aHeaderValue)
{
	RStringPool stringPool = iSession.StringPool();
	RStringF valStr = stringPool.OpenFStringL(aHeaderValue);
	THTTPHdrVal headerVal(valStr);
	aHeaders.SetFieldL(stringPool.StringF(aHeaderField, RHTTPSession::GetTable()), headerVal);
	valStr.Close();
}
void CHttpHdrTest::TestHdrValL()
	{
	// Open strings needed in this test
	RStringF accStr = iStrP.OpenFStringL(_L8("Accept"));

	THTTPHdrVal v1(accStr);
	TestL(CompareStringL(v1.StrF(), _L8("Accept")));
	TestL(v1.Type() == THTTPHdrVal::KStrFVal);

	THTTPHdrVal v2(3);
	TestL(v2.Int() == 3);
	TestL(v2.Type() == THTTPHdrVal::KTIntVal);


	TDateTime date(2001, EJanuary, 1, 12, 00, 00, 00);
	THTTPHdrVal v3(date);
	TestL(CompareDate(v3.DateTime(), date));
	TestL(v3.Type() == THTTPHdrVal::KDateVal);


	THTTPHdrVal v4 = accStr;
	TestL(v4.Type() == THTTPHdrVal::KStrFVal);


	THTTPHdrVal v5 = 3;
	TestL(v5.Type() == THTTPHdrVal::KTIntVal);

	
	THTTPHdrVal v6 = date;
	TestL(v6.Type() == THTTPHdrVal::KDateVal);

	RStringF str2 = v1;
	TestL(str2 == v1.StrF());

	
	TInt ii = v2;
	TestL(ii == v2.Int());


	TDateTime dt = v3;
	TestL(CompareDate(dt, date));


	v3 = str2;
	TestL(v3.Type() == THTTPHdrVal::KStrFVal);
	TestL(str2 == v3);

	v3 = 67;
	TestL(v3.Type() == THTTPHdrVal::KTIntVal);
	TestL(67 == v3);

	v3 = date;
	TestL(v3.Type() == THTTPHdrVal::KDateVal);
	TestL(CompareDate(date, v3.DateTime()));

	// Close strings used in this test
	accStr.Close();
	}
TBool CTestTransaction::AddAcceptHeaderL(RHTTPHeaders &aHeaders, RStringPool &aStrPool)
	{
	//	some tests may require specific 'Accept' parameters
	TBuf8<KMaxAcceptLengthSize> acceptBuf;
	acceptBuf.Copy(Machine()->GetDefine(KITHAccept));
	RStringF accept = (acceptBuf.Length() == 0) ?
		aStrPool.StringF(HTTP::EAnyAny, RHTTPSession::GetTable()) : aStrPool.OpenFStringL(acceptBuf);
	THTTPHdrVal acceptHdr(accept);
	aHeaders.SetFieldL(aStrPool.StringF(HTTP::EAccept, RHTTPSession::GetTable()), acceptHdr);
	accept.Close();
	return ETrue;
	}
TBool CTestTransaction::AcceptEncodingL(RHTTPHeaders &aHeaders, RStringPool &aStrPool)
	{
	TBuf8<KMaxAcceptEncodingSize> acceptEncodingBuf;
	acceptEncodingBuf.Copy(Machine()->GetDefine(KITHAcceptEncoding));
	if (acceptEncodingBuf.Length() > 0)
		{
		RStringF acceptEncoding = aStrPool.OpenFStringL(acceptEncodingBuf);
		THTTPHdrVal acceptEncodingHdr(acceptEncoding);
		aHeaders.SetFieldL(aStrPool.StringF(HTTP::EAcceptCharset, RHTTPSession::GetTable()), acceptEncodingHdr);
		acceptEncoding.Close();
		}

	return ETrue;
	}
TBool CTestTransaction::SetContentLengthL(RHTTPHeaders &aHeaders, RStringPool &aStrPool)
	{
	TBuf8<KMaxContentLengthSize> contLengthBuf;
	contLengthBuf.Copy(Machine()->GetDefine(KITHContentLength));
	if (contLengthBuf.Length() != 0)
		{
		RStringF contLengthStr = aStrPool.OpenFStringL(contLengthBuf);
		THTTPHdrVal contLength(contLengthStr);
		aHeaders.SetFieldL(aStrPool.StringF(HTTP::EContentLength, RHTTPSession::GetTable()), contLength);
		contLengthStr.Close();
		}

	return ETrue;
	}
TBool CTestTransaction::SetUserAgentL(RHTTPHeaders &aHeaders, RStringPool &aStrPool)
	{
	//	get the DEFINE for UserAgent
	TBuf8<KMaxUserAgentSize> userAgentBuf;
	userAgentBuf.Copy(Machine()->GetDefine(KITHUserAgent));

	TInt iLen = userAgentBuf.Length();
	//	assign the selection
	RStringF agent = (iLen == 0) ? aStrPool.OpenFStringL(KUserAgent) : aStrPool.OpenFStringL(userAgentBuf);
	THTTPHdrVal userAgent(agent);
	aHeaders.SetFieldL(aStrPool.StringF(HTTP::EUserAgent, RHTTPSession::GetTable()), userAgent);
	agent.Close();

	return ETrue;
	}
void UPPayHttpConnection::setRequestProperty(const char *property, const char *value)
{
	TInt len = User::StringLength((const TUint8*) property);
	if (!len)
		return;
	TPtr8 namePtr((TUint8 *) property, len, len);
	len = User::StringLength((const TUint8*) value);
	if (!len)
		return;
	TPtr8 valuePtr((TUint8 *) value, len, len);
	//CommonUtils::WriteLogL(namePtr, valuePtr);
	RStringF val;
	val = stringPool.OpenFStringL(namePtr);
	headers.SetRawFieldL(val, valuePtr, _L8(";"));
	val.Close();
}
TBool CTestTransaction::AddRequestBodyL( RHTTPHeaders &aHeaders,
									    RStringPool &aStrPool)
	{
	//	the content type info will be in $ContentType$. If NULL or Empty then an error generated
	TBuf8<KMaxContentTypeSize> contTypeBuf;
	contTypeBuf.Copy(Machine()->GetDefine(KITHContentType));
	if (contTypeBuf.Length() == 0)
		return EFalse; //Error(KErrArgument, THA_KErrNoContentTypeDefined, &transmthd);

	RStringF contTypeStr = aStrPool.OpenFStringL(contTypeBuf);
	THTTPHdrVal contType(contTypeStr);
	aHeaders.SetFieldL(aStrPool.StringF(HTTP::EContentType, RHTTPSession::GetTable()), contType);
	contTypeStr.Close();

	MHTTPDataSupplier *dataSupplier = this;
	
    iTransaction.Request().SetBody(*dataSupplier);

	return ETrue;
	}
// ---------------------------------------------------------------------------
// CSdpCodecParseUtil::FirstLineArrayElementL
// ---------------------------------------------------------------------------
//
RArray<TPtrC8> CSdpCodecParseUtil::FirstLineArrayElementL(RStringPool aPool,
        TInt aIndex,
        TInt aErrCode)
{
    if(!iLineArray.Count())
    {
        User::Leave(aErrCode);
    }
    RArray<TPtrC8> elementArray =
        SdpUtil::GetElementsFromLineL(iLineArray[0],aErrCode);
    CleanupClosePushL(elementArray);
    RStringF name = aPool.OpenFStringL(elementArray[0]);
    CleanupClosePushL(name);
    if(name!=(aPool.StringF(aIndex, SdpCodecStringConstants::Table)))
    {
        User::Leave(aErrCode);//parsererror
    }
    CleanupStack::Pop(2);//name, elementArray
    name.Close();
    return elementArray;
}
// ---------------------------------------------------------------------------
// CSdpCodecParseUtil::CheckOptionalFieldNameL
// ---------------------------------------------------------------------------
//
RArray<TPtrC8> CSdpCodecParseUtil::CheckOptionalFieldNameL(RStringPool aPool,
        TInt aIndex,
        const TDesC8& aValue,
        TInt aErrCode)
{
    RArray<TPtrC8> elementArray;
    elementArray.Reset();
    if(aValue.Length())
    {
        elementArray = SdpUtil::GetElementsFromLineL(aValue, aErrCode);
        CleanupClosePushL(elementArray);
        RStringF name = aPool.OpenFStringL(elementArray[0]);
        CleanupClosePushL(name);
        if(name!=(aPool.StringF(aIndex, SdpCodecStringConstants::Table)))
        {
            elementArray.Reset();
        }
        CleanupStack::Pop(2);//name, elementArray
        name.Close();
    }
    return elementArray;
}
// ---------------------------------------------------------------------------
// CSdpCodecParseUtil::CheckFieldNameL
// ---------------------------------------------------------------------------
//
RArray<TPtrC8> CSdpCodecParseUtil::CheckFieldNameL(RStringPool aPool,
        TInt aIndex,
        const TDesC8& aValue,
        TInt aErrCode)
{
    if(!aValue.Length())
    {
        User::Leave(KErrArgument);
    }
    RArray<TPtrC8> elementArray = SdpUtil::GetElementsFromLineL(aValue,
                                  aErrCode);
    CleanupClosePushL(elementArray);
    RStringF name = aPool.OpenFStringL(elementArray[0]);
    CleanupClosePushL(name);
    if(name!=(aPool.StringF(aIndex, SdpCodecStringConstants::Table)))
    {
        User::Leave(KErrArgument);//parsererror
    }
    CleanupStack::Pop(2);//name, elementArray
    name.Close();
    return elementArray;
}
// -----------------------------------------------------------------------------
// CResolvingResults::GetNext
// -----------------------------------------------------------------------------
//
TBool CResolvingResults::GetNext(TInetAddr& aAddress,
								 RStringF& aTransport,
								 TBool& aForceUDP)
	{
	TInt pos = 0;
	while (pos < iAddresses.Count() && iAddresses[pos]->Failed())
		{
		pos++;
		}

	if (pos < iAddresses.Count())
		{
		aAddress = iAddresses[pos]->Address();
		aTransport.Close();
		aTransport = iAddresses[pos]->Protocol().Copy();
		aForceUDP = iAddresses[pos]->ForceUDP();
		iAddresses[pos]->SetFailed(ETrue);
		return ETrue;
		}

	return EFalse;
	}
// ---------------------------------------------------------------------------
// TIRXMLElementFormat :: GetElementIdL
// The ElementId of the element from the StringPool
// ---------------------------------------------------------------------------
//
TIRXMLElement TIRXMLElementFormat::GetElementIdL( const TDesC8& aElement, 
                                  const RStringPool& aStringPool )
    {
    IRLOG_DEBUG( "TIRXMLElementFormat::GetElementIdL" );
    TBool validElement = EFalse;
    TInt  tableEntries;
    TInt  pos(0);
    tableEntries = IRPoolTable.iCount;
    while( pos < tableEntries && validElement == EFalse )
        {
        RStringF tableEntry;
        tableEntry = aStringPool.StringF( pos, IRPoolTable );
        HBufC8* ElementName = HBufC8::NewLC( tableEntry.DesC().Length() );
        ElementName->Des().Copy( tableEntry.DesC() );
        TLex8 string( *ElementName );
        TPtrC8 token = string.NextToken();
        TInt CompareResult = aElement.Compare( token );
        if ( CompareResult == 0 )
            {
             validElement = ETrue;
            }
        if ( validElement == EFalse )
            {
             pos++;
            }
        tableEntry.Close();
        CleanupStack::PopAndDestroy( ElementName );        
        }
    if ( validElement )
        {
        IRLOG_DEBUG( "CIRXMLContentHandler::GetElementIdL - Exiting (1)." );
        return static_cast<TIRXMLElement>( pos );
        }        
    IRLOG_DEBUG( "CIRXMLContentHandler::GetElementIdL - Exiting (2)." );
    return(EElementIDUnknown);
    } 
void UT_CMceSecureDesStream::SetupL(  )
    {
    //Set up the basic
    iSession = MceMediaManagerTestHelper::CreateMultimediaOutSessionL();
    RPointerArray<CMceComMediaStream>& streams = iSession->Streams();
    
    TInt count=streams.Count();
    if (count>0)
    	{
    	iStream1=streams[0];
    	}
    if (count>1)
    	{
    	iStream2=streams[1];
    	}
    
    iMcc = CMccControllerStub::Stub();
    
    iManager = CMceMediaManager::NewL( *this );
    
    RPointerArray<CMceComAudioCodec> audioCapabilities;
    RPointerArray<CMceComVideoCodec> videoCapabilities;
    MceCleanupResetAndDestroyPushL( audioCapabilities );
    MceCleanupResetAndDestroyPushL( videoCapabilities );
    iManager->GetCapabilitiesL( audioCapabilities );
    iManager->GetCapabilitiesL( videoCapabilities );
    CleanupStack::PopAndDestroy( 2 );//capas
    
    
    
    __ASSERT_ALWAYS( iManager->iSdpCodecs.Count() >= 2, User::Leave( KErrNotFound ) );
    iAudioSdpCodec = static_cast<CMceMediaSdpCodec*>( iManager->iSdpCodecs[ 0 ] );
    iVideoSdpCodec = static_cast<CMceMediaSdpCodec*>( iManager->iSdpCodecs[ 1 ] );

    iAudio = SdpCodecStringPool::StringPoolL().StringF( 
    											SdpCodecStringConstants::EMediaAudio, 
												SdpCodecStringPool::StringTableL());
												
    iVideo = SdpCodecStringPool::StringPoolL().StringF( 
    											SdpCodecStringConstants::EMediaVideo, 
												SdpCodecStringPool::StringTableL());
												
	iProtocol = SdpCodecStringPool::StringPoolL().StringF( 
												SdpCodecStringConstants::EProtocolRtpAvp, 
												SdpCodecStringPool::StringTableL() );
    
 // Create media line: m= This should correspond to the OFFER received!
    
	
	iMedia = CSdpMediaField::NewLC ( iVideo, 8000, iProtocol, _L8("96") );
	
	// Note the sendrcv, this should create bound stream as well since it's two way.
	RStringF attribute = SdpCodecStringPool::StringPoolL().StringF
    			( SdpCodecStringConstants::EAttributeSendrecv, SdpCodecStringPool::StringTableL() );
	CSdpAttributeField* mediaAttr = CSdpAttributeField::NewLC(attribute, _L8(""));
	iMedia->AttributeFields().AppendL( mediaAttr );
	attribute.Close();
    CleanupStack::Pop( mediaAttr );
    
    CleanupStack::Pop( iMedia );
    TUint payloadType = 96;
	// Get the encoding name
	TPtrC8 codecName = _L8("HMMH");	
	TUint clockRate = 90000;		

	// create rtpmap field for current codec
	CSdpFmtAttributeField* rtpmapAttribute = 
	    iVideoSdpCodec->EncodeRtpMapFieldsL( payloadType, 
											 codecName, 
										     clockRate,
										     KMceSdpOptionalEncodingParam );
	CleanupStack::PushL( rtpmapAttribute );
	iMedia->FormatAttributeFields().AppendL( rtpmapAttribute );
	CleanupStack::Pop( rtpmapAttribute );

	
	iOffer = CSdpDocument::NewL();
	CleanupStack::PushL( iOffer );
	iOffer->MediaFields().AppendL( iMedia );
   
    
     // Set session name: s=
    iOffer->SetSessionNameL( _L8("") );

    const TUint32 KInetAddr = INET_ADDR(10,10,10,10);
	TInetAddr localIpAddress;
	localIpAddress.SetAddress(KInetAddr);
	
    CSdpOriginField* originField = CSdpOriginField::NewL( _L8("username"),
                                                          55555,
                                                          55555,
                                                          localIpAddress );
    iOffer->SetOriginField( originField );
    
    // Create connection field: c=
    CSdpConnectionField* connectionField = CSdpConnectionField::NewL( localIpAddress );
    iOffer->SetConnectionField( connectionField );
    
    CleanupStack::Pop( iOffer );
    
    iInterface = CMccInterface::NewL( *iManager );
    
    iSecureInterface= CMccSecureInterface::NewL( *iInterface );
    
    iSecureSession = 
        CMceSecureMediaSession::NewL( *iSession, *iManager, *iSecureInterface );
    
    iSecureStream = 
        CMceSecureDesStream::NewL( *iSecureSession, *iMedia, 
                                   *iSecureInterface, *iStream1 );
	iSecureStream->AppendEmptyCryptoL( *iSecureStream->iCryptoOuts, KTotalCryptoAnswerCount );
    }
Exemple #22
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 UPPayHttpConnection::ParaseResponseHeaders(RHTTPResponse resp)
{
	RHTTPHeaders headers = resp.GetHeaderCollection();
	THTTPHdrVal aHeaderValue;
	iStatusCode = resp.StatusCode();
	if (iStatusCode >= 200 && iStatusCode < 300)
	{
		
		RStringF contLength = stringPool.OpenFStringL(_L8("Content-Length"));
		headers.GetField(contLength, 0, aHeaderValue);
		contLength.Close();
		if (aHeaderValue.Type() == THTTPHdrVal::KTIntVal)
		{
			iContentLength = aHeaderValue.Int();
		}
		else
		{
			iContentLength = 200 * 1024;
		}
		//		if(iContentStartPos != 0)
		//		{
		//			HBufC8* fieldValBuf = HBufC8::NewLC(KMaxHeaderValueLength);
		//			RStringF  contentrange= stringPool.OpenFStringL(_L8("Content-Range"));
		//			TPtrC8 rawField(fieldValBuf->Des());
		//			if(headers.GetRawField(contentrange,rawField)==KErrNone)
		//			{
		//				fieldValBuf->Des().Zero();
		//			}
		//			contentrange.Close ( );
		//			CleanupStack::PopAndDestroy(fieldValBuf);
		//		}
	}
	//
	//	else
	//	{
	//		Stop(); 
	//		iObserver.StateChange(EHttpError);
	//	}

	if (response_header)
	{
		delete response_header;
	}
	response_header = HBufC8::NewL(2048);
	Mem::FillZ((void*) response_header->Ptr(), 2048);
	TPtr8 headPtr = response_header->Des();
	TVersion ver = resp.Version();
	headPtr.AppendFormat(_L8("HTTP/%d.%d %d "), ver.iMajor, ver.iMinor, iStatusCode);
	headPtr.Append(resp.StatusText().DesC());
	headPtr.Append(add2);

	RHTTPHeaders hdr = resp.GetHeaderCollection();
	THTTPHdrFieldIter it = hdr.Fields();
	THTTPHdrVal fieldVal;
	HBufC8* fieldValBuf = HBufC8::NewLC(KMaxHeaderValueLength);
	while (it.AtEnd() == EFalse)
	{
		RStringTokenF fieldName = it();
		RStringF fieldNameStr = stringPool.StringF(fieldName);
		TPtrC8 rawField(fieldValBuf->Des());
		if (hdr.GetRawField(fieldNameStr, rawField) == KErrNone)
		{
			headPtr.Append(fieldNameStr.DesC());
			headPtr.Append(add1);
			headPtr.Append(rawField);
			headPtr.Append(add2);
			fieldValBuf->Des().Zero();
		}
		++it;
	}
	CleanupStack::PopAndDestroy(fieldValBuf);
	
	if (iStatusCode == 301 || iStatusCode == 302)
	{
		if (iObserver)
		{
			iObserver->StateChange(ERedirect);
		}
	}
}
Exemple #24
0
//Invoke http method
void CHttpClient::InvokeHttpMethodL(TInt aCommand)
{
    RStringF method;
    iHasARequestBody = EFalse;

    if ( iConnectionManager && !iConnectionManager->IsOfflineMode())
    {
        iConnectionManager->SetupConnection();

        RStringPool strP = iConnectionManager->GetHTTPSession().StringPool();

        switch (aCommand)
        {
        case CHttpConstants::EGet:
            method = strP.StringF(HTTP::EGET,RHTTPSession::GetTable());
            break;
        case CHttpConstants::EPost:
            method = strP.StringF(HTTP::EPOST,RHTTPSession::GetTable());
            iHasARequestBody = ETrue;
            break;
        default:
            return;//other commands not supported
        }

        //read body and url
        GetRequestBodyL();

        TInt realSize = 0;
        for ( TInt i = 0; i < CHttpConstants::KMaxUrlSize && iUriPtr[i]; i++)
        {
            realSize++;
        }

        TBuf8<CHttpConstants::KMaxUrlSize> tmp;
        tmp.Copy(iUriPtr.Ptr(), realSize);
        tmp.ZeroTerminate();

        TUriParser8 uri;
        uri.Parse(tmp);

        iTrans = iConnectionManager->GetHTTPSession().OpenTransactionL(uri, *iTransObs, method);
        RHTTPHeaders hdr = iTrans.Request().GetHeaderCollection();

        // Add headers appropriate to all methods
        SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
        SetHeaderL(hdr, HTTP::EAccept, KAccept);

        // Add headers and body data for methods that use request bodies
        if (iHasARequestBody)
        {
            // Content type header
            TBuf8<CHttpConstants::KMaxContentTypeSize> contTypeBuf;
            contTypeBuf.Copy(_L("text/html"));
            RStringF contTypeStr = iConnectionManager->GetHTTPSession().StringPool().OpenFStringL(contTypeBuf);
            THTTPHdrVal contType(contTypeStr);
            hdr.SetFieldL(iConnectionManager->GetHTTPSession().StringPool().StringF(HTTP::EContentType,RHTTPSession::GetTable()), contType);
            contTypeStr.Close();

            MHTTPDataSupplier* dataSupplier = this;
            iTrans.Request().SetBody(*dataSupplier);
        }

        // submit the transaction
        iTrans.SubmitL();

        // Start the scheduler, once the transaction completes or is cancelled on an error the scheduler will be
        // stopped in the event handler
        CActiveScheduler::Start();

        //close and delete request file
        iReqBodyFile.Close();
        iFileServ.Delete(iReqBodyFilePath);
    }
}
// ---------------------------------------------------------------------------
// CSdpMediaField::ParseMediaL
// ---------------------------------------------------------------------------
//
void CSdpMediaField::ParseMediaL()
{
    iElementArray = iSdpCodecParseUtil->FirstLineArrayElementL(iPool,
                    SdpCodecStringConstants::EMedia,
                    KErrSdpCodecMediaField);
    __ASSERT_ALWAYS (iElementArray.Count() >= 4,
                     User::Leave(KErrSdpCodecMediaField));

    RStringF media = iPool.OpenFStringL(iElementArray[1]);
    CleanupClosePushL(media);
    SetMediaL(media);
    CleanupStack::Pop();//media
    media.Close();

    iProtocol = iPool.OpenFStringL(iElementArray[3]);

    TInt lineEndPosition = iElementArray[2].Locate('/');
    TUint port;
    if(lineEndPosition == KErrNotFound)
    {
        User::LeaveIfError(
            TLex8(iElementArray[2]).Val(port, EDecimal));
        SetPortL(port);
    }
    else
    {
        User::LeaveIfError(TLex8(
                               (iElementArray[2]).Left(lineEndPosition)).Val(port, EDecimal));
        SetPortL(port);
        User::LeaveIfError(TLex8(
                               (iElementArray[2]).Mid(lineEndPosition +1)).Val(port, EDecimal));
        SetPortCountL(port);
    }
    __ASSERT_ALWAYS(SdpUtil::IsTokenCharWithOptionalSlash(iElementArray[3]),
                    User::Leave(KErrArgument));

    //iProtocol = iPool.OpenFStringL(iElementArray[3]);

    TInt length = 0;
    TInt i;
    for(i=4; i<iElementArray.Count(); i++)
    {
        length += iElementArray[i].Length();
        if(i + 1 <iElementArray.Count())
        {
            length += KSPStr().Length();
        }
    }
    HBufC8* value = HBufC8::NewLC(length);
    TPtr8 ptr(value->Des());
    for(i=4; i<iElementArray.Count(); i++)
    {
        ptr.Append(iElementArray[i]);
        if(i + 1 <iElementArray.Count())
        {
            ptr.Append(KSPStr);
        }
    }
    SetFormatListL(*value);
    CleanupStack::Pop();//value
    delete value;
    iElementArray.Reset();
    if (iSdpCodecParseUtil->LineArray().Count() > 0)
    {
        iSdpCodecParseUtil->LineArray().Remove(0);
    }
}
TBool CExampleCookieManager::ValidateCookieL(CCookie& aCookie, const TUriC8& aUri)
	{
	THTTPHdrVal attributeVal;

	if(aCookie.Attribute(CCookie::EPath, attributeVal) == KErrNone)
		{
		// if the path attribute exists check it is a prefix of the path
		// of the uri that issued it (if not reject)
		RStringF cookiePath = attributeVal.StrF();
		const TDesC8& uriPath = aUri.Extract(EUriPath);
		if(uriPath.FindF(RemoveQuotes(cookiePath.DesC())) != 0)
			return EFalse;
		}
	else
		{
		// if the path attribute doesn't exist add it
		THTTPHdrVal val(iStringPool.OpenFStringL(aUri.Extract(EUriPath)));
		aCookie.SetAttributeL(CCookie::EPath, val);
		}

	if(aCookie.Attribute(CCookie::EDomain, attributeVal) == KErrNone)
		{
		const TChar dot('.');
		const TDesC8& cookieDomain = attributeVal.StrF().DesC();
		const TDesC8& uriDomain = aUri.Extract(EUriHost);

		// if the domain does not exactly match the uri and does not begin
		// with a dot then add one
		if((cookieDomain.Compare(uriDomain) != 0) &&
		   (cookieDomain.Locate(dot) != 0))
			{
			_LIT8(KAddDotString, ".%S");
			HBufC8* newDomain = HBufC8::NewLC(cookieDomain.Length() + 1);
			newDomain->Des().AppendFormat(KAddDotString(), &cookieDomain);

			RStringF domain = iStringPool.OpenFStringL(*newDomain);
			CleanupStack::PopAndDestroy(newDomain);

			THTTPHdrVal val(domain);
			aCookie.SetAttributeL(CCookie::EDomain, val);
			domain.Close();
			}

		// if the domain does not contain an embedded dot then reject it
		// ie reject .com or .com.
		// Start by removing one character from each end. ie start at pos 1 and take a length
		// which is 2 shorter than the original descriptor
		TPtrC8 domainMiddle = cookieDomain.Mid(1, cookieDomain.Length() - 2);
		if(domainMiddle.Locate(dot) == KErrNotFound)
			return EFalse;

		// Reject the cookie if the domain differs by two or more levels from the uri
		// ie if uri=www.x.y.com then accept a cookie with .x.y.com but reject .y.com
		TInt pos = uriDomain.FindF(cookieDomain);
		if(pos > 2)
			{
			const TDesC8& domainDiff = uriDomain.Left(pos);

			// Remove one character from each end. ie start at pos 1 and take a length
			// which is 2 shorter than the original descriptor
			const TDesC8& diffMiddle = domainDiff.Mid(1, domainDiff.Length() - 2);
			if(diffMiddle.Locate(dot) != KErrNotFound)
				return EFalse;
			}
		}
	else
		{
		// if the domain attribute is not found add it
		THTTPHdrVal val(iStringPool.OpenFStringL(aUri.Extract(EUriHost)));
		aCookie.SetAttributeL(CCookie::EDomain, val);
		val.StrF().Close();
		}

	if(!CheckPortMatch(aCookie, aUri))
		return EFalse;

	return ETrue;
	}