// ------------------------------------------------------------------------------------------------
// CHttpFilterConnHandler::MHFRunL
// Process a transaction event.
// ------------------------------------------------------------------------------------------------
//
void CHttpFilterConnHandler::MHFRunL(RHTTPTransaction aTransaction,
                                     const THTTPEvent& aEvent)
{
    TInt state = 0;
    TInt gprsState = 0;
    TInt wcdmaState = 0;
    TApBearerType bearerType;

    if (aEvent.iStatus == THTTPEvent::ESubmit)
    {
        THTTPHdrVal isNewConn;
        RHTTPConnectionInfo	connInfo = iSession->ConnectionInfo();
        RStringPool strPool = aTransaction.Session().StringPool();
        TBool ret = connInfo.Property (strPool.StringF(HttpFilterCommonStringsExt::EHttpNewConnFlag,
                                       HttpFilterCommonStringsExt::GetTable()), isNewConn);

        if ( LocalHostCheckL(aTransaction) && !( ret && isNewConn.Type() == THTTPHdrVal::KTIntVal ) )
            {
            return;
            }

        THTTPHdrVal callback;
        RHTTPTransactionPropertySet propSet = aTransaction.PropertySet();
        RStringF callbackStr = strPool.StringF( HttpFilterCommonStringsExt::EConnectionCallback, 
            HttpFilterCommonStringsExt::GetTable() );

        MConnectionCallback* callbackPtr = NULL;
    
        // this is a transaction, already forwarded to download manager
        if( propSet.Property( callbackStr, callback ) )
        {
            callbackPtr = REINTERPRET_CAST( MConnectionCallback*, callback.Int() );
        }        
Exemple #2
0
void CHttpTestCaseGet12::LogConnectionProperties()
	{
	RHTTPConnectionInfo	connectionInfo = iSession.ConnectionInfo();
	RStringPool stringPool = iSession.StringPool();
	THTTPHdrVal value;
	TBool hasValue = connectionInfo.Property (stringPool.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable()), value);
	if (hasValue)
		{
		RConnection* conn = REINTERPRET_CAST(RConnection*, value.Int());
		TUint count;
		//get the no of active connections
		TInt err = conn->EnumerateConnections(count);
		if(err==KErrNone)
			{
			for (TUint i=1; i<=count; ++i)
				{
				TPckgBuf<TConnectionInfo> connInfo;
				conn->GetConnectionInfo(i, connInfo);
				iEngine->Utils().LogIt(_L("Connection %d: IapId=%d, NetId=%d\n"),i, connInfo().iIapId, connInfo().iNetId);
				}
			}
		else
			{
			iEngine->Utils().LogIt(_L("Unable to enumerate number of connections, Error: %d"), err);
			}
		}
	}
TInt CHttpController::ContentLength( RHTTPHeaders aHeaderCollection, RHTTPSession& aSession )
	{
	RStringF contetnLength = aSession.StringPool().StringF( HTTP::EContentLength,
			RHTTPSession::GetTable() );
	THTTPHdrVal contetnLengthValue;
	TInt error( aHeaderCollection.GetField( contetnLength, 0, contetnLengthValue ) );
	if ( error == KErrNone )
		{
		return contetnLengthValue.Int();
		}
	return error;
	}
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);
	}
// -----------------------------------------------------------------------------
// CHttpFilterProxy::ReadProxyInfoL
// Purpose:	Reads the Proxy information from the comms database.
// Gives the Proxy usage, a proxy address (<proxy name>:<proxy port>),
// and proxy exceptions through the output arguments.
// -----------------------------------------------------------------------------
//
void CHttpFilterProxy::ReadProxyInfoL(const RStringPool aStringPool,
                                      TBool&      aUsage,
                                      RStringF&   aProxyAddress,
                                      RStringF&   aExceptions)

{
    // Let's find Internet Access point ID (ServiceId) in use from the RConnection associated with the HTTP framework
    THTTPHdrVal connValue;
    TUint32     serviceId;
    TUint pushCount = 0;
    RConnection* connPtr = NULL;
	THTTPHdrVal		iapId;
	TCommDbConnPref pref;
    TBool hasValue = iConnInfo.Property (aStringPool.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable()),
                     connValue);

    if (hasValue && connValue.Type() == THTTPHdrVal::KTIntVal)
    {
        connPtr = REINTERPRET_CAST(RConnection*, connValue.Int());
	}
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;
		}
	}
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);
		}
	}
}
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 );
	}
void CHttpClientHeaderWriter::EncodeHostL(RHeaderField& aHeader) const
/**
	Encodes the host header. RFC2616 section 14.23

		Host			=	"Host" ":" host [ ":" port ]

	The host header value may be empty.
	@internalComponent
	@param		aHeader	The host header field to encode.
	@leave		RHeaderField::BeginRawDataL
	@leave		RHeaderField::PartsL
	@leave		RHeaderField::WriteRawDataL
	@leave		KErrHttpEncodeHost	There were no parts, or the part value type
									or the parameter value type was not a string
									or a folded string.
*/
	{
	__START_PERFORMANCE_LOGGER();
	// Our convention will be that a string called HTTP::EPort will be used to
	// set a parameter holding the integer port number
	// Check part 1
	THeaderFieldPartIter iter1 = aHeader.PartsL();
	iter1.First();
	if( iter1.AtEnd() )
		{
		User::Leave(KErrHttpEncodeHost);
		}
	const CHeaderFieldPart* part = iter1();
	if( part == NULL)
		{
		User::Leave(KErrHttpEncodeHost);
		}
	THTTPHdrVal pt1val = part->Value();
	if( pt1val.Type() != THTTPHdrVal::KStrFVal )
		{
		User::Leave(KErrHttpEncodeHost);
		}
	// Write the host string
	RStringF hostStr = pt1val.StrF();
	aHeader.BeginRawDataL();
	aHeader.WriteRawDataL(hostStr.DesC());

	// Check for a port number
	THeaderFieldParamIter iter2 = part->Parameters();
	iter2.First();
	if( !iter2.AtEnd() )
		{
		// Got a parameter - if its the port, check then write it
		const CHeaderFieldParam* param = iter2();
		if( !param )
			{
			User::Leave(KErrHttpEncodeHostPort);
			}
		if( param->Name() == iStringPool.StringF(HTTP::EPort,iStringTable) )
			{
			// Get the port value
			THTTPHdrVal portVal = param->Value();
			if (portVal.Type() != THTTPHdrVal::KTIntVal)
				{
				User::Leave(KErrHttpEncodeHostPort);
				}
			TBuf8<KMaxNumPortDigits> portDesC;
			const TInt portValue = portVal.Int();
			if(portValue > KMaxNumPortValue) 
				{
				User::Leave(KErrHttpEncodeHostPort);
				}
			portDesC.Num(portValue);
			aHeader.WriteRawDataL(':');
			aHeader.WriteRawDataL(portDesC);
			}
		}
	aHeader.CommitRawData();
	__END_PERFORMANCE_LOGGER(_L(",CHttpClientHeaderWriter::EncodeHostL()"));
	}
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;
		}
	}
void CHttpEventHandler::DumpRespHeadersL(RHTTPTransaction& aTrans)
	{
	RHTTPResponse resp = aTrans.Response();
	RStringPool strP = aTrans.Session().StringPool();
	RHTTPHeaders hdr = resp.GetHeaderCollection();
	THTTPHdrFieldIter it = hdr.Fields();

	TBuf<CHttpConstants::KMaxHeaderNameLen>  fieldName16;
	TBuf<CHttpConstants::KMaxHeaderValueLen> fieldVal16;

	while (it.AtEnd() == EFalse)
		{
		RStringTokenF fieldName = it();
		RStringF fieldNameStr = strP.StringF(fieldName);
		THTTPHdrVal fieldVal;
		if (hdr.GetField(fieldNameStr,0,fieldVal) == KErrNone)
			{
			const TDesC8& fieldNameDesC = fieldNameStr.DesC();
			fieldName16.Copy(fieldNameDesC.Left(CHttpConstants::KMaxHeaderNameLen));
			switch (fieldVal.Type())
				{
			case THTTPHdrVal::KTIntVal:
				iTest->Console()->Printf(_L("%S: %d\n"), &fieldName16, fieldVal.Int());
				break;
			case THTTPHdrVal::KStrFVal:
				{
				RStringF fieldValStr = strP.StringF(fieldVal.StrF());
				const TDesC8& fieldValDesC = fieldValStr.DesC();
				fieldVal16.Copy(fieldValDesC.Left(CHttpConstants::KMaxHeaderValueLen));
				iTest->Console()->Printf(_L("%S: %S\n"), &fieldName16, &fieldVal16);
				}
				break;
			case THTTPHdrVal::KStrVal:
				{
				RString fieldValStr = strP.String(fieldVal.Str());
				const TDesC8& fieldValDesC = fieldValStr.DesC();
				fieldVal16.Copy(fieldValDesC.Left(CHttpConstants::KMaxHeaderValueLen));
				iTest->Console()->Printf(_L("%S: %S\n"), &fieldName16, &fieldVal16);
				}
				break;
			case THTTPHdrVal::KDateVal:
				{
				TDateTime date = fieldVal.DateTime();
				TBuf<40> dateTimeString;
				TTime t(date);
				t.FormatL(dateTimeString,CHttpConstants::KDateFormat);

				iTest->Console()->Printf(_L("%S: %S\n"), &fieldName16, &dateTimeString);
				} 
				break;
			default:
				iTest->Console()->Printf(_L("%S: <unrecognised value type>\n"), &fieldName16);
				break;
				}

			// Display realm for WWW-Authenticate header
			RStringF wwwAuth = strP.StringF(HTTP::EWWWAuthenticate,RHTTPSession::GetTable());
			if (fieldNameStr == wwwAuth)
				{
				// check the auth scheme is 'basic'
				RStringF basic = strP.StringF(HTTP::EBasic,RHTTPSession::GetTable());
				RStringF realm = strP.StringF(HTTP::ERealm,RHTTPSession::GetTable());
				THTTPHdrVal realmVal;
				if ((fieldVal.StrF() == basic) && 
					(!hdr.GetParam(wwwAuth, realm, realmVal)))
					{
					RStringF realmValStr = strP.StringF(realmVal.StrF());
					fieldVal16.Copy(realmValStr.DesC());
					iTest->Console()->Printf(_L("Realm is: %S\n"), &fieldVal16);
					}
				}
			}
		++it;
		}
	}