diff -r 7333d7932ef7 -r 8b7f4e561641 ncdengine/engine/transport/src/catalogshttpdownload.cpp --- a/ncdengine/engine/transport/src/catalogshttpdownload.cpp Tue Aug 31 15:21:33 2010 +0300 +++ b/ncdengine/engine/transport/src/catalogshttpdownload.cpp Wed Sep 01 12:22:02 2010 +0100 @@ -23,13 +23,6 @@ #include #include // TDataType #include -#include -#include -#include -#include -#include -#include -#include #include "catalogshttpdownloadmanagerimpl.h" #include "catalogshttpobserver.h" @@ -102,7 +95,7 @@ // CCatalogsHttpDownload* CCatalogsHttpDownload::NewLC( CCatalogsHttpDownloadManager& aOwner, - Download* aDownload, + RHttpDownload* aDownload, const CCatalogsHttpConfig& aConfig ) { CCatalogsHttpDownload* self = new( ELeave ) CCatalogsHttpDownload( @@ -147,7 +140,7 @@ else { DLTRACE(( "Deleting download" )); - iOwner.GetDownloadManager()->removeOne(iDownload); + iDownload->Delete(); if ( iState.iOperationState != ECatalogsHttpOpCompleted ) { @@ -251,8 +244,8 @@ { iObserver = NULL; TInt32 state = 0; - - state = (Download::State)iDownload->attribute(State).toInt(); + iDownload->GetIntAttribute( EDlAttrState, state ); + if ( IsOneOf( static_cast( state ), EHttpDlCreated, @@ -480,14 +473,7 @@ TInt err = KErrNone; if ( iDownload ) { - try - { - iDownload->pause(); - } - catch(const std::exception& exception) - { - err = qt_symbian_exception2Error(exception); - } + err = iDownload->Pause(); } DLTRACE(("Pause err: %d", err )); @@ -694,7 +680,7 @@ // client-server communication with the Download manager server if ( iDownload && iContentSize <= 0 ) { - iContentSize = iDownload->attribute(TotalSize).toInt(); + iDownload->GetIntAttribute( EDlAttrLength, iContentSize ); DLTRACE(("Content size from download: %i", iContentSize )); } return iContentSize; @@ -720,8 +706,7 @@ TBool pausable = ETrue; if ( iDownload ) { - - pausable=iDownload->attribute(Pausable).toBool(); + iDownload->GetBoolAttribute( EDlAttrPausable, pausable ); } return pausable; } @@ -814,8 +799,7 @@ iConfig->InternalizeL( aStream ); HBufC8* contentType = NULL; InternalizeDesL( contentType, aStream ); - // HLa if ( contentType->Length() > KMaxContentTypeLength ) - if ( contentType->Length() > 256 ) + if ( contentType->Length() > KMaxContentTypeLength ) { DeletePtr( contentType ); DLERROR(("Content type was too long, leaving with KErrCorrupt")); @@ -855,152 +839,7 @@ return KErrNone; } -void CCatalogsHttpDownload::HandledownloadEventL(DownloadEvent& aEvent) -{ - - switch(aEvent.type()) - { - - case DownloadEvent::Started: - - break; - - case DownloadEvent::Error: - case DownloadEvent::Failed: - case DownloadEvent::NetworkLoss: - case DownloadEvent::ConnectionNeeded: - case DownloadEvent::ConnectionDisconnected: - { - TInt32 errorId = -1; - if ( aEvent.type() == DownloadEvent::NetworkLoss || - aEvent.type() == DownloadEvent::ConnectionNeeded || - aEvent.type() == DownloadEvent::ConnectionDisconnected ) - { - errorId = WRT::ConnectionFailed; - } - SetTransferring( EFalse ); - errorId = iDownload->attribute(LastError).toInt(); - if ( errorId > 0 ) - { - // Symbian error codes are always negative numbers - errorId = -1 * errorId; - } - - /*if ( ( errorId == ConnectionFailed || - errorId == TransactionFailed )) - { - DLTRACE(("Try to reconnect")); - iReconnectWhenFail = EFalse; - iDownload->start(); - break; - } - else if ( errorId == ContentExpired || - errorId == PartialContentModified ) - { - DLTRACE(("Content has changed, reset and restart")); - iReconnectWhenFail = EFalse; - iDownload->cancel(); - iDownload->start(); - break; - }*/ - iState.iOperationState = ECatalogsHttpOpFailed; - - TBool deleted = EFalse; - if ( iObserver ) - { - // Determine whether failure was due to a HTTP error or some - // other error. - //if ( errorId >= 400 ) - // { - // deleted = iObserver->HandleHttpError( - // *this, TCatalogsHttpError( - // ECatalogsHttpErrorHttp, - // errorId ) ); - // } - // else - { - AddRef(); - //iOwner.ConnectionManager().ReportConnectionError( - // TCatalogsConnectionMethod(), errorId ); - - if ( iRefCount > 1 ) - { - deleted = iObserver->HandleHttpError( - *this, TCatalogsHttpError( - ECatalogsHttpErrorGeneral, errorId ) ); - } - else - { - deleted = ETrue; - } - Release(); - } - } - if ( !deleted ) - { - iOwner.CompleteOperation( this ); - iState.iProgressState = ECatalogsHttpDone; - } - } - break; - - case DownloadEvent::Cancelled: - - break; - case DownloadEvent::ContentTypeChanged: - - break; - case DownloadEvent::HeadersReceived: - { - // Read the response headers from platform DL manager - UpdateResponseHeadersL(); - UpdateContentType(); - } - break; - - - case DownloadEvent::Completed: - { - // move/rename temp file as the target file - TRAPD( err, MoveFileL() ); - - // DLMAIN-546, delete DL manager's download before starting - // the next one so that downloads don't jam, again - if ( iDownload ) - { - iTransferredSize = iDownload->attribute(DownloadedSize).toInt(); - - - DLTRACE(("Deleting download")); - DeletePlatformDownload(); - } - iState.iProgressState = ECatalogsHttpDone; - iOwner.CompleteOperation( this ); - iState.iOperationState = ECatalogsHttpOpCompleted; - - if ( iObserver ) - { - iObserver->HandleHttpEventL( *this, iState ); - } - } - break; - - case DownloadEvent::InProgress: - { - iTransferredSize = iDownload->attribute(DownloadedSize).toInt(); - if ( iObserver ) - { - iObserver->HandleHttpEventL( *this, iState ); - } - } - break; - - default: - { - } - }; -} // --------------------------------------------------------------------------- // Handles events from the transaction // --------------------------------------------------------------------------- @@ -1152,8 +991,6 @@ // Handles events from the download manager // --------------------------------------------------------------------------- // - -/* HLa void CCatalogsHttpDownload::HandleEventL( THttpDownloadEvent aEvent ) { DLTRACEIN(("")); @@ -1188,20 +1025,20 @@ TInt32 statusCode = -1; - statusCode = (Download::State)iDownload->attribute(WRT::State).toInt(); - DLINFO( ("Response status: %i", statusCode ) ); + iDownload->GetIntAttribute( EDlAttrStatusCode, statusCode ); + DLINFO( ("Response status: %i", statusCode ) ); #ifdef CATALOGS_BUILD_CONFIG_DEBUG TInt32 errorId = 0; - errorId=iDownload->attribute(LastError).toInt(); + iDownload->GetIntAttribute( EDlAttrErrorId, errorId ); DLINFO( ("Error id: %i", errorId ) ); #endif TInt32 globalErrorId = 0; - globalErrorId= iDownload->attribute(LastError).toInt(); - + iDownload->GetIntAttribute( + EDlAttrGlobalErrorId, globalErrorId ); DLINFO( ("Global error id: %i", globalErrorId ) ); @@ -1248,7 +1085,7 @@ { DLTRACE(("Try to reconnect")); iReconnectWhenFail = EFalse; - iDownload->start(); + iDownload->Start(); break; } @@ -1306,9 +1143,9 @@ // DLMAIN-546, delete DL manager's download before starting // the next one so that downloads don't jam, again if ( iDownload ) - { - iTransferredSize = iDownload->attribute(DownloadedSize).toInt(); - + { + iDownload->GetIntAttribute( + EDlAttrDownloadedSize, iTransferredSize ); DLTRACE(("Deleting download")); DeletePlatformDownload(); @@ -1342,8 +1179,7 @@ DLTRACE(( "Download failed" )); TInt32 errorId = -1; SetTransferring( EFalse ); - errorId = iDownload->attribute(LastError).toInt(); - + iDownload->GetIntAttribute( EDlAttrErrorId, errorId ); DLINFO( ("Error id: %i", errorId ) ); DLINFO( ("Global error id: %i", globalErrorId ) ); @@ -1354,7 +1190,7 @@ { DLTRACE(("Try to reconnect")); iReconnectWhenFail = EFalse; - iDownload->start(); + iDownload->Start(); break; } else if ( errorId == EContentExpired || @@ -1362,8 +1198,8 @@ { DLTRACE(("Content has changed, reset and restart")); iReconnectWhenFail = EFalse; - iDownload->cancel(); - iDownload->start(); + iDownload->Reset(); + iDownload->Start(); break; } @@ -1446,7 +1282,6 @@ * Download process can be paused again. This event only occurs after * EHttpDlNonPausable. */ -/* HLa case EHttpDlPausable: { DLTRACE(( "Pausable" )); @@ -1482,14 +1317,13 @@ } } } -*/ + // --------------------------------------------------------------------------- // // --------------------------------------------------------------------------- // -/* void CCatalogsHttpDownload::HandleEventProgressL( const THttpDownloadEvent& aEvent ) { @@ -1554,7 +1388,8 @@ if ( !iPaused ) { TInt32 globalErrorId = 0; - globalErrorId = iDownload->attribute(LastError).toInt(); + iDownload->GetIntAttribute( + EDlAttrGlobalErrorId, globalErrorId ); DLINFO( ("Global error id: %i", globalErrorId ) ); if ( globalErrorId == KErrCancel ) @@ -1660,8 +1495,7 @@ iReconnectCount = KReconnectAttempts; TInt32 size = 0; - size = iDownload->attribute(DownloadedSize).toInt(); - + iDownload->GetIntAttribute( EDlAttrDownloadedSize, size ); DLTRACE(("Transferred size from download: %i", size)); if ( size != iTransferredSize ) @@ -1763,7 +1597,7 @@ break; } } - */ + // --------------------------------------------------------------------------- @@ -1802,7 +1636,7 @@ // CCatalogsHttpDownload::CCatalogsHttpDownload( CCatalogsHttpDownloadManager& aOwner, - Download* aDownload ) : + RHttpDownload* aDownload ) : iOwner( aOwner ), iDownload( aDownload ), iState( ECatalogsHttpOpCreated, ECatalogsHttpNone ), @@ -1825,8 +1659,7 @@ { // id part will be updated from disk iId = TCatalogsTransportOperationId( iOwner.SessionId(), KErrNotFound ); - iQTDownload = new CCatalogsHttpQTDownload(this,iDownload); - + UpdateSecondaryIdL(); User::LeaveIfError( SetDeleteState( EDownloadCanBeDeleted ) ); @@ -1867,12 +1700,8 @@ { // Download always exists when this is called so no need to check DLTRACE(("Updating the content type")); - QString contentType; - contentType= iDownload->attribute(WRT::ContentType).toString(); - // HLa TBuf ContentType(contentType.utf16()); - TBuf<256> ContentType(contentType.utf16()); - iContentType.Copy(ContentType); - + iDownload->GetStringAttribute( EDlAttrContentType, + iContentType ); } DLTRACEOUT(("Content-type: %S", &iContentType )); } @@ -1991,18 +1820,10 @@ // Get the current url of the download RBuf8 buf; CleanupClosePushL( buf ); - const TInt KMaxUrlLength = 2048; buf.CreateL( KMaxUrlLength ); - QString string; - try - { - string = iDownload->attribute(SourceUrl).toString(); - } - catch(const std::exception& exception) - { - qt_symbian_exception2LeaveL(exception); - } - + + User::LeaveIfError( iDownload->GetStringAttribute( EDlAttrCurrentUrl, + buf ) ); // DL manager has the encoded URI AssignDesL( iEncodedUri, buf ); @@ -2046,8 +1867,8 @@ } else { -/* User::LeaveIfError( iDownload->SetStringAttribute( - predefined, headers[i]->Value() ) );*/ + User::LeaveIfError( iDownload->SetStringAttribute( + predefined, headers[i]->Value() ) ); } } @@ -2056,8 +1877,8 @@ if ( iAddedRequestHeaders ) { DLTRACE(( "added request headers: %S", iAddedRequestHeaders )); - /* User::LeaveIfError( iDownload->SetStringAttribute( - EDlAttrRequestHeaderAddon, *iAddedRequestHeaders ) );*/ + User::LeaveIfError( iDownload->SetStringAttribute( + EDlAttrRequestHeaderAddon, *iAddedRequestHeaders ) ); delete iAddedRequestHeaders; iAddedRequestHeaders = NULL; } @@ -2222,7 +2043,6 @@ TUint CCatalogsHttpDownload::MatchWithPredefinedRequestHeader( const TDesC8& aHeader ) const { - /* HLa if ( aHeader.CompareF( KHttpRequestAcceptHeader ) == 0 ) { return EDlAttrRequestAccept; @@ -2267,7 +2087,7 @@ { return EDlAttrRequestVary; } - */ + return 0; } @@ -2280,7 +2100,6 @@ TUint CCatalogsHttpDownload::MatchWithPredefinedGeneralHeader( const TDesC8& aHeader ) const { - /* HLa if ( aHeader.CompareF( KHttpGeneralCacheControlHeader ) == 0 ) { return EDlAttrGeneralCacheControl; @@ -2300,8 +2119,7 @@ else if ( aHeader.CompareF( KHttpGeneralWarningHeader ) == 0 ) { return EDlAttrGeneralWarning; - } - */ + } return 0; } @@ -2314,7 +2132,6 @@ TUint CCatalogsHttpDownload::MatchWithPredefinedEntityHeader( const TDesC8& aHeader ) const { - /* if ( aHeader.CompareF( KHttpEntityAllowHeader ) == 0 ) { return EDlAttrEntityAllow; @@ -2339,7 +2156,6 @@ { return EDlAttrEntityLastModified; } - */ return 0; } @@ -2379,9 +2195,6 @@ TPtr8 ptr( aTarget->Des() ); - _LIT8( KHttpFieldSeparator, "\n"); // HLa - const TInt KColon( ':' ); // HLa - if( newSize ) { DLTRACE( ("Appending to existing headers") ); @@ -2432,25 +2245,7 @@ TRAPD( err, { - if ( Config().ConnectionMethod().iType == ECatalogsConnectionMethodTypeDestination ) - { - RCmManager cmManager; - CleanupClosePushL( cmManager ); - cmManager.OpenL(); - RCmDestination dest = cmManager.DestinationL( Config().ConnectionMethod().iId ); - CleanupClosePushL( dest ); - HBufC* temp = dest.NameLC(); - QString destname; - destname = XQConversions::s60DescToQString( *temp ); - CleanupStack::PopAndDestroy( temp ); - CleanupStack::PopAndDestroy( &dest ); - CleanupStack::PopAndDestroy( &cmManager ); - if ( iOwner.GetDownloadManager() ) - { - iOwner.GetDownloadManager()->attribute(AccessPoints).toStringList(); - iOwner.GetDownloadManager()->setAttribute(AccessPoint, destname); - } - } + iOwner.SetConnectionL( *iConnection ); // Update the configuration if ( iState.iProgressState == ECatalogsHttpNone ) @@ -2459,17 +2254,10 @@ InitializeDownloadL(); } }); - + if ( err == KErrNone ) { - try - { - iDownload->start(); - } - catch(const std::exception& exception) - { - qt_symbian_exception2LeaveL(exception); - } + err = iDownload->Start(); } return err; } @@ -2683,17 +2471,13 @@ TInt err = KErrNone; if ( iDownload ) { - - iStatus = aStatus; + err = iDownload->SetIntAttribute( EDlAttrUserData, aStatus ); } return err; } -CCatalogsHttpDownload::TDownloadDeleteState CCatalogsHttpDownload::GetStatusState() - { - return iStatus; - } + // --------------------------------------------------------------------------- // Gets delete status and download id from the platform download // --------------------------------------------------------------------------- @@ -2707,8 +2491,7 @@ TInt err = KErrNotReady; if ( iDownload ) { - - err = iStatus; + err = iDownload->GetIntAttribute( EDlAttrUserData, data ); DLTRACE(("Data: %d", data)); aStatus = static_cast( data ); } @@ -2787,18 +2570,10 @@ UpdateRequestHeadersL(); } - // Check if the - //download has been set progressive - /* MTA - * TBool progressive = EFalse; - try - { - progressive =iDownload->attribute(Progressive).toBool(); - } - catch(const std::exception& exception) - { - qt_symbian_exception2LeaveL(exception); - } + // Check if the download has been set progressive + TBool progressive = EFalse; + User::LeaveIfError( iDownload->GetBoolAttribute( + EDlAttrProgressive, progressive ) ); // We want to have progressive downloads because then DL manager uses @@ -2816,34 +2591,18 @@ !iFileIsSet ) { DLTRACE(("Setting download as progressive")); - try - { - iDownload->setAttribute(Progressive,ETrue); - } - catch(const std::exception& exception) - { - qt_symbian_exception2LeaveL(exception); - } - } + User::LeaveIfError( iDownload->SetBoolAttribute( + EDlAttrProgressive, ETrue ) ); + } // Doesn't pause the download after content type has been received - try - { - iDownload->setAttribute(Progressive,ETrue); - } - catch(const std::exception& exception) - { - qt_symbian_exception2LeaveL(exception); - } -**/ + User::LeaveIfError( iDownload->SetBoolAttribute( + EDlAttrNoContentTypeCheck, ETrue ) ); + if ( !iFileIsSet ) { DLTRACE(("Setting filehandle to download")); - // User::LeaveIfError( iDownload->SetFileHandleAttribute( file ) ); - file.Close(); - TInt ret = BaflUtils::DeleteFile( iFs, *iTempFilename ); - iDownload->setAttribute(DestinationPath,XQConversions::s60DescToQString(iConfig->Directory())); - iDownload->setAttribute(FileName, XQConversions::s60DescToQString(*iTempFilename)); + User::LeaveIfError( iDownload->SetFileHandleAttribute( file ) ); iFileIsSet = ETrue; } @@ -2851,10 +2610,7 @@ } } -Download* CCatalogsHttpDownload::GetDownload() -{ - return iDownload; -} + // --------------------------------------------------------------------------- // Delete platform download and reset secondary id // --------------------------------------------------------------------------- @@ -2863,7 +2619,7 @@ { if ( iDownload ) { - iOwner.GetDownloadManager()->removeOne(iDownload); + iDownload->Delete(); iDownload = NULL; iId.SetSecondaryId( KErrNotFound ); } @@ -2877,7 +2633,8 @@ void CCatalogsHttpDownload::UpdateSecondaryIdL() { TInt32 secondaryId = KErrNotFound; - secondaryId = iDownload->id(); + User::LeaveIfError( + iDownload->GetIntAttribute( EDlAttrId, secondaryId ) ); iId.SetSecondaryId( secondaryId ); } @@ -2918,22 +2675,3 @@ aName.Append( aExt ); } } - -CCatalogsHttpQTDownload::CCatalogsHttpQTDownload(CCatalogsHttpDownload* aHttpDownload,Download* aDownload) - { - iCatalogsHttpDownload = aHttpDownload; - iDownload = aDownload; - connect(iDownload, SIGNAL(downloadEvent(DownloadEvent*)), this,SLOT(downloadEventHandler(DownloadEvent*))); - connect(iDownload, SIGNAL(downloadError(Error)), this,SLOT(downloadErrorHandler(Error))); - } - -void CCatalogsHttpQTDownload::downloadEventHandler(DownloadEvent* aEvent) - { - iCatalogsHttpDownload->HandledownloadEventL(*aEvent); - } -void CCatalogsHttpQTDownload::downloadErrorHandler(Error) - { - //iCatalogsHttpDownload->HandledownloadEventL(*aEvent); - } - -