Ejemplo n.º 1
0
RHTTPTransaction CTestCase10::GetTransactionL(TInt aIndex, RHTTPSession aSession, MHTTPTransactionCallback& aClient)
	{
	__ASSERT_ALWAYS(aIndex<KTransactionCount, User::Invariant());
	
	TPtrC8 uriDes;
	
	switch(aIndex)
		{
		case 0:
			{
			uriDes.Set(_L8("http://10.29.23.12"));
			} break;
		case 1:
			{
			uriDes.Set(_L8("http://10.29.23.12/manual/index.html"));
			} break;
		case 2:
			{
			uriDes.Set(_L8("http://10.29.23.12/manual/new_features_1_3.html"));
			} break;
		case 3:
			{
			uriDes.Set(_L8("http://10.29.23.12/wap/suite-08Jun2000/"));
			} break;
		case 4:
			{
			uriDes.Set(_L8("http://10.29.23.12/wap/suite-20Jun2000/"));
			} break;
		case 5:
			{
			uriDes.Set(_L8("http://10.29.23.12/manual/upgrading_to_1_3.html"));
			} break;
		case 6:
			{
			uriDes.Set(_L8("http://10.29.23.12/manual/install.html"));
			} break;
		case 7:
			{
			uriDes.Set(_L8("http://10.29.23.12/manual/invoking.html"));
			} break;
		case 8:
			{
			uriDes.Set(_L8("http://10.29.23.12/stats.html"));
			} break;
		case 9:
			{
			uriDes.Set(_L8("http://10.29.23.12/manual/stopping.html"));
			} break;
		case 10:
			{
			uriDes.Set(_L8("http://10.29.23.12/manual/mod/directives.html"));
			} break;
		case 11:
			{
			uriDes.Set(_L8("http://10.29.23.12/manual/images/custom_errordocs.gif"));
			} break;
		case 12:
			{
			uriDes.Set(_L8("http://10.29.23.12/manual/images/home.gif"));
			} break;
		case 13:
			{
			uriDes.Set(_L8("http://10.29.23.12/manual/images/index.gif"));
			} break;
		default:
			// Shouldn't happen!
			User::Invariant();
			break;
		}
	
	
	RStringF method = aSession.StringPool().StringF(HTTP::EGET,RHTTPSession::GetTable());
	TUriParser8 uri; 
	uri.Parse(uriDes);
	return aSession.OpenTransactionL(uri, aClient, method);
	}
Ejemplo n.º 2
0
void CTestTransaction::ConstructL(RHTTPSession& aSession)
	{
	TBool hasRequestBody = EFalse;

	switch (iTransactionType)
		{
		case HTTP::EPOST : 
		case HTTP::EPUT : 

			if (iFilename.Length() > 0)
				{
				User::LeaveIfError(SetFileNameL(iFilename));
				
				hasRequestBody = ETrue;
				}
		break ;
		
		case HTTP::EGET :
		case HTTP::EDELETE:
		case HTTP::EHEAD:
		case HTTP::ECONNECT :
		default:
		;
		}
	
	TUriParser8 KURI;
	KURI.Parse(iUri);		

	RStringPool strPool = aSession.StringPool();
	
	//	open a transaction within the required session and use the class callback object for 
	//	managing the subsequent events...

	iTransaction = aSession.OpenTransactionL(KURI, *this, strPool.StringF(iTransactionType, RHTTPSession::GetTable()));

	iState = EActive;
	
	RHTTPRequest request = iTransaction.Request();

	RHTTPHeaders headers = request.GetHeaderCollection();
	
	AddAcceptHeaderL(headers, strPool);

	SetUserAgentL(headers, strPool);

	SetContentLengthL(headers, strPool);

	AcceptEncodingL(headers, strPool);
	
	// Check to see if pipelining should be disabled

	if (Machine()->GetDefine(KITHDisablePipelining).CompareF(KITHYes)==0)
		{
		RHTTPTransactionPropertySet transactionPropertySet = iTransaction.PropertySet();
		RStringF name = strPool.StringF(HTTP::EHttpPipelining, RHTTPSession::GetTable());
		RStringF value = strPool.StringF(HTTP::EDisablePipelining,RHTTPSession::GetTable());
		transactionPropertySet.SetPropertyL(name,value);
		}
	
	

	//	Add request body
	if (hasRequestBody)
		{
		if (!AddRequestBodyL(headers, strPool))
			User::LeaveIfError(KErrArgument);
		}
	}
Ejemplo n.º 3
0
// ---------------------------------------------------------
// CUniObjectList::GetByUrlL
//
// GetByUrlL.
// ---------------------------------------------------------
//
EXPORT_C CUniObject* CUniObjectList::GetByUrlL( const TDesC& aUrl )
    {
    CUniObject* att = NULL;
    TBool found = EFalse;

    HBufC8* url8bit = HBufC8::NewLC( aUrl.Length() );

    CUri16* decodedUri = NULL;
    TUriParser8 parser;
	if( !url8bit )
        {
		return NULL;
		}

    if( aUrl.MatchF( KContentIdString ) == 0 )
        {
        //Remove "cid:" from the beginning
        url8bit->Des().Copy( aUrl.Right( aUrl.Length() - KContentIdString().Length() + 1 ) );
        parser.Parse( *url8bit );
        }
    else
        {
        url8bit->Des().Copy( aUrl );
        parser.Parse( *url8bit );
        }
    decodedUri = UriUtils::ConvertToDisplayFormL( parser );
    CleanupStack::PushL( decodedUri );

    TInt count = iObjectArray->Count();
    for ( TInt i = 0; i < count && !found ; ++i )
        {
        TPtrC contentLocation = iObjectArray->At( i )->MimeInfo()->ContentLocation();
        TPtrC8 contentIdPtr = iObjectArray->At( i )->MimeInfo()->ContentId();
        CUri16* contLocUri = NULL;
        CUri16* contIdUri = NULL;
        HBufC8* contentLoc = NULL;
        HBufC8* contentId = NULL;

        // Convert content location as well.
        if ( contentIdPtr.Length() )
            {
            //Copy string to 8-bit descriptor
            contentId = HBufC8::NewLC( contentIdPtr.Length() );

            if ( contentId->Find( KCidLeftAngle ) == 0 &&
                 contentId->Find( KCidRightAngle ) == contentId->Length() - 1 )
                {
                // When comparing against cid, remove "<" and ">"
                contentId->Des().Copy( contentIdPtr.Mid( 1, contentIdPtr.Length() - 2 ) );
                }
            else
                {
                contentId->Des().Copy( contentIdPtr );
                }

            parser.Parse( *contentId );
            contIdUri = UriUtils::ConvertToDisplayFormL( parser );
            CleanupStack::PushL( contIdUri );
            }
         if ( contentLocation.Length() )
            {
            //Copy string to 8-bit descriptor
            contentLoc = HBufC8::NewLC( contentLocation.Length() );
            contentLoc->Des().Copy( contentLocation );
            parser.Parse( *contentLoc );
            contLocUri = UriUtils::ConvertToDisplayFormL( parser );
            CleanupStack::PushL( contLocUri );
            }

        if (
            ( ( contentLocation.Length() ) && (decodedUri->Uri().UriDes().CompareF( contLocUri->Uri().UriDes() ) == 0 ) ) ||
            ( ( contentIdPtr.Length() ) && (decodedUri->Uri().UriDes().CompareF( contIdUri->Uri().UriDes() ) == 0 ) ) )
            {
            att = iObjectArray->At( i );
            }

        if ( contentLoc )
            {
            CleanupStack::PopAndDestroy( 2, contentLoc ); // contentLoc, contLocUri
            }
        if ( contentId )
            {
            CleanupStack::PopAndDestroy( 2, contentId ); // contentId, contIdUri
            }

        }
    CleanupStack::PopAndDestroy( 2, url8bit ); // decodedUri, url8bit
    return att;
    }
//---------------------------------------------------------------
// CNativeMmsUtility::getByUrlL
// @see header
//---------------------------------------------------------------
const QString CNativeMmsUtility::getByUrlL(const TDesC& url)
{
#ifdef _DEBUG_TRACES_
    qDebug() << " Enter CNativeMmsUtility::getByUrlL";
#endif

    CMsvAttachment* targetattachment = NULL;
    TBool found = EFalse;

    //newlc puts it on cleanupstack
    HBufC8* url8bit = HBufC8::NewLC(url.Length());

    CUri16* decodedUri = NULL;
    TUriParser8 parser;

    //get the uri in display format
    if (url.MatchF(KContentIdString) == 0)
    {
        //Remove "cid:" from the beginning
        url8bit->Des().Copy(url.Right(url.Length()
                - KContentIdString().Length() + 1));
        parser.Parse(*url8bit);
    }
    else
    {
        url8bit->Des().Copy(url);
        parser.Parse(*url8bit);
    }
    decodedUri = UriUtils::ConvertToDisplayFormL(parser);
    CleanupStack::PushL(decodedUri);

    //run through the attachements to check for a match
    TUint count = iattachmanager->AttachmentCount();
    for (int i = 0; i < count && !found; i++)
    {
        CMsvAttachment *attachment = iattachmanager->GetAttachmentInfoL(i);
        CleanupStack::PushL(attachment);

        //restore mimeheaders from the attachment
        CMsvMimeHeaders* mimeheaders = CMsvMimeHeaders::NewL();
        CleanupStack::PushL(mimeheaders);
        mimeheaders->RestoreL(*attachment);

        //check for a match with content-loc and then content-id
        if (resolvedByContentLocL(mimeheaders->ContentLocation(), *decodedUri)
                || resolvedByContentIdL(mimeheaders->ContentId(), *decodedUri))
        {
            targetattachment = CMsvAttachment::NewL(*attachment);
            found = ETrue;
        }

        CleanupStack::PopAndDestroy(2, attachment); //mimeheaders, attachment
    }

    CleanupStack::PopAndDestroy(decodedUri);
    if (url8bit)
        CleanupStack::PopAndDestroy(url8bit);

    if (targetattachment)
    {
#ifdef _DEBUG_TRACES_
        qDebug() << " Exit CNativeMmsUtility::getByUrlL";
#endif

        return XQConversions::s60DescToQString(targetattachment->FilePath());
    }
    else
    {
#ifdef _DEBUG_TRACES_
        qDebug() << " Exit CNativeMmsUtility::getByUrlL";
#endif

        return QString();
    }
}
// ----------------------------------------------------------------------------
// CWmDrmDlaDefaultHttpManager::SubmitL
// Handler for the states EOpen and EReconnect.
// ----------------------------------------------------------------------------
void CWmDrmDlaDefaultHttpManager::SubmitL()
    {
    LOGFN( "CWmDrmDlaDefaultHttpManager::SubmitL" );

    TConnectionInfo info;
    GetConnectionInfoL( info );
    iIapNumber = info.iIapId;

    // Close old session:
    iHttpSession.Close();    

    // Open session
    iHttpSession.OpenL();
    RStringPool pool = iHttpSession.StringPool();

    // Associate HTTP session with connection
    RHTTPConnectionInfo connInfo = iHttpSession.ConnectionInfo();

    // Specify socket server
    SET_HTTP_PROPERTY( connInfo, pool, HTTP::EHttpSocketServ,
        iSocketServer.Handle() );
    // Specify connectionn to use
    TInt connPtr = reinterpret_cast<TInt>(&iConnection);
    SET_HTTP_PROPERTY( connInfo, pool, HTTP::EHttpSocketConnection, connPtr );

    // Install HTTP authentication filter
    InstallAuthenticationL( iHttpSession );

    CHttpCookieFilter::InstallFilterL( iHttpSession );

    RHTTPFilterCollection filterColl = iHttpSession.FilterCollection();
    filterColl.RemoveFilter(
        iHttpSession.StringPool().StringF(
            HTTP::ERedirect, RHTTPSession::GetTable() ) );

    CHttpUAProfFilterInterface::InstallFilterL( iHttpSession );

    // Parse URI
    TUriParser8 srcAddress;
    User::LeaveIfError( srcAddress.Parse( *iSrcAddress ) );

    // Open HTTP transaction
    iHttpTransaction = iHttpSession.OpenTransactionL( srcAddress, *this,
        HTTP_STRING( (EGet == iOperation) ? HTTP::EGET : HTTP::EPOST ) );
    iTransactionOpen = ETrue;

    // Set the data supplier if a POST operation
    if ( EPost == iOperation )
        {
        iHttpTransaction.Request().SetBody( *iDataSupplier );
        }


    TInt pos = iSrcAddress->Locate( '?' );

    // If no query ('?') pos is rightmost character
    pos = (pos != KErrNotFound) ? pos : iSrcAddress->Length();
    TPtrC8 ptrUrl = iSrcAddress->Left( pos );

    // Only print if there is a ('?') and something to print after it
    if ( pos < iSrcAddress->Length() )
      {
      TPtrC8 ptrQs = iSrcAddress->Mid( pos );
      }
    // Set HTTP headers for the transaction
    RHTTPHeaders hdr = iHttpTransaction.Request().GetHeaderCollection();
    TInt nofheaders = iHdrValues.Count();

    for ( TInt i = 0; i < nofheaders; i++ )
        {
        TInt field = iHdrFields[i];
        const TDesC8& fieldStr = HTTP_STRING( field ).DesC();
        HBufC8* pValue = iHdrValues[i];
        SetHeaderL( hdr, field, *pValue );
        }

    // Submit HTTP transaction
    // This will set in motion the HTTP download
    iHttpTransaction.SubmitL();
    iState = ESubmit;
    }
Ejemplo n.º 6
0
void CHttpTestCase4::DoRunL()
	{
	// Literals used in the function
	_LIT8(KWapTestUrl,		"http://WapTestIP/perl/dumpform.pl");

	// Replace the host name in the URL
	HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile);
	CleanupStack::PushL(newUrl8);
	TPtr8 newUrlPtr8 = newUrl8->Des();

	TUriParser8 testURI;
	testURI.Parse(newUrlPtr8);

	//open a Session
	RHTTPSession mySession;
	mySession.OpenL();
	CleanupClosePushL(mySession);
	iEngine->Utils().LogIt(_L("Session Created(TC4)"));
	iEngine->Utils().LogIt(_L("Session parameters: Default"));
	
	//Get the mySession'string pool handle;
	iMyStrP = mySession.StringPool();

	//get strings this testcase needs
	RStringF textPlain = iMyStrP.StringF(HTTP::ETextPlain, RHTTPSession::GetTable());
	RStringF textHtml = iMyStrP.StringF(HTTP::ETextHtml, RHTTPSession::GetTable());
	RStringF mimeType = iMyStrP.StringF(HTTP::EApplicationXWwwFormUrlEncoded, RHTTPSession::GetTable());

	//Open a Transaction in mySession 
	RHTTPTransaction myTransaction;
	myTransaction = mySession.OpenTransactionL(testURI, *this, iMyStrP.StringF(HTTP::EPOST,RHTTPSession::GetTable()));
	CleanupClosePushL(myTransaction);
	iEngine->Utils().LogIt(_L("Transaction Created in mySession"));

	//Get a handle of the request in myTransaction
	RHTTPRequest myRequest = myTransaction.Request();
	RHTTPHeaders myHeaders = myRequest.GetHeaderCollection();

	//provide  some headers 
	THTTPHdrVal v2(textPlain);
	THTTPHdrVal v3(textHtml);
	THTTPHdrVal v4(6);
	THTTPHdrVal v5(mimeType);

	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept,RHTTPSession::GetTable()),v2);
	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept,RHTTPSession::GetTable()),v3);
	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentLength,RHTTPSession::GetTable()),v4);
	myHeaders.SetFieldL(iMyStrP.StringF(HTTP::EContentType,RHTTPSession::GetTable()), v5);

	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8);
	iEngine->Utils().LogIt(_L("Method:Post"));
	iEngine->Utils().LogIt(_L("Accept:test/plain,text/html"));
	iEngine->Utils().LogIt(_L("Content-Type: application/x-www-form-urlencoded"));
	iEngine->Utils().LogIt(_L("Content-Length: 6"));
		
	myRequest.SetBody(*this);
	myTransaction.SubmitL();
	CActiveScheduler::Start();
	
	//close Transaction and session
	myTransaction.Close();
	iEngine->Utils().LogIt(_L("Transaction terminated\n"));
	mySession.Close();
	iEngine->Utils().LogIt(_L("Session terminated"));
	if (iTestFail==1)
		{
		User::Leave(-1);
		}
	CleanupStack::Pop(2); // mySession, myTansaction
	CleanupStack::PopAndDestroy(newUrl8);
	}
Ejemplo n.º 7
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);
    }
}