diff -r 1221b68b8a5f -r 1481bf457703 omadrm/drmplugins/drmrohandler/src/rohandlerdmgrwrapper.cpp --- a/omadrm/drmplugins/drmrohandler/src/rohandlerdmgrwrapper.cpp Tue Aug 31 15:29:38 2010 +0300 +++ b/omadrm/drmplugins/drmrohandler/src/rohandlerdmgrwrapper.cpp Wed Sep 01 12:21:16 2010 +0100 @@ -1,5 +1,5 @@ /* -* Copyright (c) 2008 - 2010 Nokia Corporation and/or its subsidiary(-ies). +* Copyright (c) 2008 - 2009 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" @@ -21,6 +21,10 @@ #include #include +#ifdef __SERIES60_NATIVE_BROWSER +#include +#endif + #include #include #include @@ -32,6 +36,8 @@ #include +#include + #include // tconnectioninfo #include // rconnection rsocket #include @@ -39,15 +45,7 @@ #include #include "RoapSyncWrapper.h" -// Download manager apis -#include -#include -#include - #include "rohandlerdmgrwrapper.h" -#include "cleanupresetanddestroy.h" -#include "buffercontainers.h" -#include "qrohandlerdmgreventhandler.h" #ifdef _DEBUG #define DRMDEBUG( a ) RDebug::Print( a ) @@ -95,6 +93,9 @@ _LIT( KMethConstructL, "ConstructL" ); _LIT( KMethNewL, "NewL" ); _LIT( KMethNewLC, "NewLC" ); + _LIT( KMethDownloadAndHandleRoapTriggerL, "DownloadAndHandleRoapTriggerL" ); + _LIT( KMethDownloadAndHandleRoapTriggerFromPrUrlL, + "DownloadAndHandleRoapTriggerFromPrUrlL" ); _LIT( KMethDoDownloadAndHandleRoapTriggerL, "DoDownloadAndHandleRoapTriggerL" ); _LIT( KFormatDoDlHdlRoapTrigL, "DoDownloadAndHandleRoapTriggerL: %S" ); @@ -102,6 +103,7 @@ _LIT( KStrDlFinished, "download finished" ); _LIT( KMethSetDefaultAccessPointL, "SetDefaultAccessPointL" ); + _LIT( KMiIapId, "iIapId" ); _LIT( KMethHandleDMgrEventL, "HandleDMgrEventL" ); _LIT( KFormatMethHandleDMgrEventL, "HandleDMgrEventL %S" ); @@ -114,7 +116,8 @@ _LIT( KStrEConnectionFailed, "EConnectionFailed" ); _LIT( KFormatEDlAttrErrorId, "EDlAttrErrorId = %d" ); - _LIT( KMiState, "iState" ); + _LIT( KMiDownLoadState, "iDownLoadState" ); + _LIT( KMiProgressState, "iProgressState" ); } @@ -132,12 +135,41 @@ //#define LOG2( a, b ) #endif +#ifndef __SERIES60_NATIVE_BROWSER +const TUid KCRUidBrowser = + {0x10008D39}; +const TUint32 KBrowserDefaultAccessPoint = 0x0000000E; +const TUint32 KBrowserAccessPointSelectionMode = 0x0000001E; +const TUint32 KBrowserNGDefaultSnapId = 0x00000053; +#endif + // CONSTANTS #ifndef RD_MULTIPLE_DRIVE _LIT( KHelperTriggerFilePath, "d:\\" ); #endif -using namespace WRT; +// ============================== LOCAL FUNCTIONS ============================== + +// --------------------------------------------------------------------------- +// DoResetAndDestroy +// Does RPointerArray< typename >->ResetAndDestroy() for the given array aPtr. +// --------------------------------------------------------------------------- +// +template< typename elemType > +LOCAL_C void DoResetAndDestroy( TAny* aPtr ) + { + ( reinterpret_cast< RPointerArray< elemType >* >( aPtr ) )-> + ResetAndDestroy(); + } + +// --------------------------------------------------------------------------- +// DeleteHttpDowload +// --------------------------------------------------------------------------- +// +LOCAL_C void DeleteHttpDowload( TAny* aDownload ) + { + reinterpret_cast< RHttpDownload* >( aDownload )->Delete(); + } // --------------------------------------------------------------------------- // UpdateBufferL @@ -157,6 +189,34 @@ } } +// --------------------------------------------------------------------------- +// IapIdOfDefaultSnapL +// for trapping purposes only +// --------------------------------------------------------------------------- +// +LOCAL_C TUint32 IapIdOfDefaultSnapL( + RCmManager& aCmManager, + const TUint32 aDefaultSnap ) + { + RCmDestination dest( aCmManager.DestinationL( aDefaultSnap ) ); + CleanupClosePushL( dest ); + TUint32 iapIdOfDest( 0 ); + + if ( dest.ConnectionMethodCount() <= 0 ) + { + User::Leave( KErrNotFound ); + } + + RCmConnectionMethod cMeth( dest.ConnectionMethodL( 0 ) ); + CleanupClosePushL( cMeth ); + + iapIdOfDest = cMeth.GetIntAttributeL( CMManager::ECmIapId ); + CleanupStack::PopAndDestroy( &cMeth ); + CleanupStack::PopAndDestroy( &dest ); + return iapIdOfDest; + } + + // ============================= MEMBER FUNCTIONS ============================== // --------------------------------------------------------------------------- @@ -179,15 +239,7 @@ DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethConstructL() ); // Get UID from process const TInt KRoHandlerDMgrWrapperUid = 0x101F7B92; - try - { - QString roHandlerDmgrWrapperUid(QString::number(KRoHandlerDMgrWrapperUid)); - iDlMgr = q_check_ptr(new DownloadManager(roHandlerDmgrWrapperUid)); - } - catch(const std::exception& exception) - { - qt_symbian_exception2LeaveL(exception); - } + iDlMgr.ConnectL( TUid::Uid( KRoHandlerDMgrWrapperUid ), *this, EFalse ); User::LeaveIfError( iFs.Connect() ); User::LeaveIfError( iFs.ShareProtected() ); @@ -232,15 +284,24 @@ delete iFileName; delete iRoapEng; - delete iDlMgr; - delete iRoHandlerDMgrEventHandler; - +#ifdef _DEBUG + + if ( iDlMgr.Handle() ) + { + iDlMgr.Close(); + } + +#else + + iDlMgr.Close(); + +#endif + iFs.Close(); - } // --------------------------------------------------------------------------- -// CRoHandlerDMgrWrapper::HandleRoapTriggerL +// CRoHandlerDMgrWrapper::DownloadAndHandleRoapTriggerL // --------------------------------------------------------------------------- // void CRoHandlerDMgrWrapper::HandleRoapTriggerL( const TDesC8& aTrigger ) @@ -256,13 +317,50 @@ } // --------------------------------------------------------------------------- +// CRoHandlerDMgrWrapper::DownloadAndHandleRoapTriggerL +// --------------------------------------------------------------------------- +// +void CRoHandlerDMgrWrapper::DownloadAndHandleRoapTriggerL( const HBufC8* aUrl ) + { + DRMDEBUGMETHOD( + RoHdlrDMgrWrDebugLiterals::KMethDownloadAndHandleRoapTriggerL() ); + if ( iState != EInit || iWait.IsStarted() ) + { + User::Leave( KErrNotReady ); + } + + UpdateBufferL< HBufC8, TDesC8 >( iTriggerUrl, *aUrl ); + Continue( EGetMeteringTrigger, KErrNone ); + iWait.Start(); + } + +// --------------------------------------------------------------------------- +// CRoHandlerDMgrWrapper::DownloadAndHandleRoapTriggerFromPrUrlL +// --------------------------------------------------------------------------- +// +void CRoHandlerDMgrWrapper::DownloadAndHandleRoapTriggerFromPrUrlL( + const HBufC8* aUrl ) + { + DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethDownloadAndHandleRoapTriggerFromPrUrlL() ); + if ( iState != EInit || iWait.IsStarted() ) + { + User::Leave( KErrNotReady ); + } + + UpdateBufferL< HBufC8, TDesC8 >( iTriggerUrl, *aUrl ); + Continue( EGetPrUrlTrigger, KErrNone ); + iWait.Start(); + } + +// --------------------------------------------------------------------------- // CRoHandlerDMgrWrapper::DoDownloadRoapTriggerL // --------------------------------------------------------------------------- // void CRoHandlerDMgrWrapper::DoDownloadRoapTriggerL( TMeterState aNextState ) { RFile roapTrigger; - DRM::CFileNameContainer* triggerFileName(NULL); + TBool result( EFalse ); + TFileName triggerFileName; DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethDoDownloadAndHandleRoapTriggerL() ); // If no Trigger URL then nothing to download. So finish transaction @@ -272,11 +370,10 @@ return; } - triggerFileName=DRM::CFileNameContainer::NewLC(); #ifndef RD_MULTIPLE_DRIVE User::LeaveIfError( roapTrigger.Temp( - iFs, KHelperTriggerFilePath, triggerFileName->iBuffer, EFileWrite ) ); + iFs, KHelperTriggerFilePath, triggerFileName, EFileWrite ) ); #else //RD_MULTIPLE_DRIVE _LIT( KDrive, "%c:\\" ); @@ -285,69 +382,46 @@ DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRam, driveNumber ); iFs.DriveToChar( driveNumber, driveLetter ); - DRM::CFileNameContainer* - helperTriggerFilePath( DRM::CFileNameContainer::NewLC() ); - - helperTriggerFilePath->iBuffer.Format( KDrive, ( TUint )driveLetter ); + TFileName helperTriggerFilePath; - User::LeaveIfError( roapTrigger.Temp( iFs, helperTriggerFilePath->iBuffer, - triggerFileName->iBuffer, EFileWrite ) ); - CleanupStack::PopAndDestroy( helperTriggerFilePath ); - helperTriggerFilePath=NULL; + helperTriggerFilePath.Format( KDrive, ( TUint )driveLetter ); + + User::LeaveIfError( roapTrigger.Temp( iFs, helperTriggerFilePath, + triggerFileName, EFileWrite ) ); #endif - UpdateBufferL< HBufC, TFileName >( iFileName, triggerFileName->iBuffer ); - CleanupStack::PopAndDestroy( triggerFileName ); - triggerFileName=NULL; + UpdateBufferL< HBufC, TFileName >( iFileName, triggerFileName ); - try - { - // create and start download - QString downloadUrl((QChar*)iTriggerUrl->Des().Ptr(),iTriggerUrl->Length()); - iDownload = iDlMgr->createDownload( downloadUrl ); - iRoHandlerDMgrEventHandler = q_check_ptr(new QRoHandlerDMgrEventHandler(*this, *iDownload)); - } - catch(const std::exception& exception) - { - qt_symbian_exception2LeaveL(exception); - } - + // create and start download + RHttpDownload& download = iDlMgr.CreateDownloadL( *iTriggerUrl, result ); + // Put download for proper cleanup. + TCleanupItem item( DeleteHttpDowload, &download ); + CleanupStack::PushL( item ); + CleanupClosePushL( roapTrigger ); - - DRMDEBUG2( - RoHdlrDMgrWrDebugLiterals::KFormatDoDlHdlRoapTrigL(), - &RoHdlrDMgrWrDebugLiterals::KStrDlCreated() ); - iDownloadSuccess = EFalse; - iConnectionError = EFalse; + if ( result ) + { + DRMDEBUG2( + RoHdlrDMgrWrDebugLiterals::KFormatDoDlHdlRoapTrigL(), + &RoHdlrDMgrWrDebugLiterals::KStrDlCreated() ); + iDownloadSuccess = EFalse; + iConnectionError = EFalse; - SetDefaultAccessPointL(); - - try - { - RBuf fileName; - User::LeaveIfError(fileName.Create(KMaxFileName)); - CleanupClosePushL(fileName); - roapTrigger.Name(fileName); - const QVariant& roapTriggerValue( QString((QChar*) fileName.Ptr(), fileName.Length()) ); - CleanupStack::PopAndDestroy(&fileName); - iDownload->setAttribute(FileName,roapTriggerValue); - const QVariant& val(ETrue); - iDownload->setAttribute(ContentType, val); - iDownload->start(); - } - catch(const std::exception& exception) - { - qt_symbian_exception2LeaveL(exception); - } - - // wait until download is finished - iState = aNextState; - TRequestStatus* status( &iStatus ); - *status = KRequestPending; - SetActive(); - + SetDefaultAccessPointL(); + User::LeaveIfError( download.SetFileHandleAttribute( roapTrigger ) ); + User::LeaveIfError( download.SetBoolAttribute( + EDlAttrNoContentTypeCheck, ETrue ) ); + User::LeaveIfError( download.Start() ); + + // wait until download is finished + iState = aNextState; + TRequestStatus* status( &iStatus ); + *status = KRequestPending; + SetActive(); + } CleanupStack::PopAndDestroy( &roapTrigger ); + CleanupStack::Pop( &download ); // Left open for DoSaveRoapTrigger } // --------------------------------------------------------------------------- // CRoHandlerDMgrWrapper::DoSaveRoapTriggerL @@ -360,23 +434,15 @@ RoHdlrDMgrWrDebugLiterals::KFormatDoDlHdlRoapTrigL(), &RoHdlrDMgrWrDebugLiterals::KStrDlFinished() ); - try - { - // Fetch download created in DoDownloadRoapTriggerL - QString downloadUrl((QChar*)iTriggerUrl->Des().Ptr(),iTriggerUrl->Length()); - //uncomment - iDownload = NULL; //iDlMgr->findDownload( downloadUrl ); - } - catch(const std::exception& exception) - { - qt_symbian_exception2LeaveL(exception); - } - + // Fetch download created in DoDownloadRoapTriggerL + RHttpDownload* download = iDlMgr.FindDownload( *iTriggerUrl, KNullDesC8() ); // Delete trigger URL so that it is possible to check // whether or not meteringResponse has PrUrl. delete iTriggerUrl; iTriggerUrl = NULL; - + // Put download for proper cleanup. + TCleanupItem item( DeleteHttpDowload, download ); + CleanupStack::PushL( item ); RFile roapTrigger; if ( !iDownloadSuccess ) @@ -419,7 +485,8 @@ // And let ROAP handle it... CleanupStack::PopAndDestroy( &readBuf ); CleanupStack::PopAndDestroy( &roapTrigger ); - + CleanupStack::PopAndDestroy( download ); + iFs.Delete( *iFileName ); delete iFileName; iFileName=NULL; @@ -437,7 +504,9 @@ Roap::TDomainOperation domainOperation; RPointerArray< HBufC8 > contentIds; - CleanupResetAndDestroyPushL( contentIds ); + + TCleanupItem cleanup( DoResetAndDestroy< HBufC8 >, &contentIds ); + CleanupStack::PushL( cleanup ); iRoapEng = Roap::CRoapEng::NewL(); @@ -466,12 +535,55 @@ // void CRoHandlerDMgrWrapper::SetDefaultAccessPointL() { + const TInt KDestinationSelectionMode( 2 ); + CRepository* repository( NULL ); + TInt ap( 0 ); + TInt alwaysAsk( 0 ); + TUint32 iapd32( 0 ); + TInt defaultSnap( 0 ); + TInt err( KErrNone ); + DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethSetDefaultAccessPointL() ); - if ( iIapId ) + if ( !iIapId ) { - QVariant iapId((unsigned long long)iIapId); - iDlMgr->setAttribute(DefaultDestinationPath, iapId); + repository = CRepository::NewL( KCRUidBrowser ); + CleanupStack::PushL( repository ); + repository->Get( KBrowserDefaultAccessPoint, ap ); + repository->Get( KBrowserAccessPointSelectionMode, alwaysAsk ); + repository->Get( KBrowserNGDefaultSnapId, defaultSnap ); + if ( ap <= KErrNotFound && defaultSnap <= KErrNotFound ) + { + alwaysAsk = ETrue; + } + else + { + RCmManager cmManager; + cmManager.OpenLC(); + if ( !alwaysAsk ) + { + TRAP( err, iapd32 = cmManager.GetConnectionMethodInfoIntL( + ap, CMManager::ECmIapId ) ); + } + else if ( alwaysAsk == KDestinationSelectionMode ) + { + TRAP( err, iapd32 = IapIdOfDefaultSnapL( + cmManager, defaultSnap ) ); + } + CleanupStack::PopAndDestroy( &cmManager ); + } + if ( !err && ( !alwaysAsk || alwaysAsk == KDestinationSelectionMode ) ) + { + iIapId = iapd32; + DRMDEBUG3( RoHdlrDMgrWrDebugLiterals::KFormatMembValInt(), + &RoHdlrDMgrWrDebugLiterals::KMiIapId(), iIapId ); + err = iDlMgr.SetIntAttribute( EDlMgrIap, iapd32 ); + } + CleanupStack::PopAndDestroy( repository ); + } + else + { + err = iDlMgr.SetIntAttribute( EDlMgrIap, iIapId ); } } @@ -496,41 +608,48 @@ // CRoHandlerDMgrWrapper::HandleDMgrEventL // --------------------------------------------------------------------------- // -void CRoHandlerDMgrWrapper::HandleDownloadEventL( WRT::DownloadEvent* aEvent ) +void CRoHandlerDMgrWrapper::HandleDMgrEventL( RHttpDownload& aDownload, + THttpDownloadEvent aEvent ) { - QString KDRMHelperMimeTypeROAPTrigger("application/vnd.oma.drm.roap-trigger+xml" ); + _LIT8( KDRMHelperMimeTypeROAPTrigger, "application/vnd.oma.drm.roap-trigger+xml" ); DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethHandleDMgrEventL() ); DRMDEBUG3( RoHdlrDMgrWrDebugLiterals::KFormatMembValInt(), - &RoHdlrDMgrWrDebugLiterals::KMiState(), aEvent->type() ); - - if ( aEvent->type() == DownloadEvent::HeadersReceived ) + &RoHdlrDMgrWrDebugLiterals::KMiDownLoadState(), aEvent.iDownloadState ); + DRMDEBUG3( RoHdlrDMgrWrDebugLiterals::KFormatMembValInt(), + &RoHdlrDMgrWrDebugLiterals::KMiProgressState(), aEvent.iProgressState ); + + if ( aEvent.iProgressState == EHttpContentTypeReceived ) { DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), &RoHdlrDMgrWrDebugLiterals::KStrEHttpContentTypeReceived() ); // check received mimetype - QString contentType = iDownload->attribute( ContentType).toString(); - if ( contentType.contains( KDRMHelperMimeTypeROAPTrigger ) == EFalse ) + RBuf8 contentType; + contentType.CleanupClosePushL(); + contentType.CreateL( KMaxContentTypeLength ); + User::LeaveIfError( aDownload.GetStringAttribute( EDlAttrContentType, + contentType ) ); + if ( !contentType.FindF( KDRMHelperMimeTypeROAPTrigger ) ) { // ROAP trigger found, continue download - iDownload->start(); + User::LeaveIfError( aDownload.Start() ); } else { // wrong MIME type?, stop download iDownloadSuccess = EFalse; - iDownload->cancel(); + User::LeaveIfError( aDownload.Delete() ); } CleanupStack::PopAndDestroy( &contentType ); } - if ( aEvent->type() == DownloadEvent::Created ) + if ( aEvent.iDownloadState == EHttpDlCreated ) { DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlCreated() ); } else - if ( aEvent->type() == DownloadEvent::NetworkLoss ) + if ( aEvent.iProgressState == EHttpProgDisconnected ) { DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), &RoHdlrDMgrWrDebugLiterals::KStrEHttpProgDisconnected() ); @@ -541,47 +660,49 @@ TRequestStatus* status( &iStatus ); User::RequestComplete( status, KErrCancel ); } - else - if ( aEvent->type() == DownloadEvent::InProgress ) - { - DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), - &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlInprogress() ); - } - else - if ( aEvent->type() == DownloadEvent::Completed ) - { - // store success - DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), - &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlCompleted() ); - iDownloadSuccess = ETrue; + else + if ( aEvent.iDownloadState == EHttpDlInprogress ) + { + DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), + &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlInprogress() ); + } + else + if ( aEvent.iDownloadState == EHttpDlCompleted ) + { + // store success + DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), + &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlCompleted() ); + iDownloadSuccess = ETrue; - // finished - TRequestStatus* status( &iStatus ); - User::RequestComplete( status, KErrNone ); - } - else - if ( aEvent->type() == DownloadEvent::Failed ) - { - TInt32 err; + // finished + TRequestStatus* status( &iStatus ); + User::RequestComplete( status, KErrNone ); + } + else + if ( aEvent.iDownloadState == EHttpDlFailed ) + { + TInt32 err; - DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), - &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlFailed() ); - // store failure - iDownloadSuccess = EFalse; - err = iDownload->attribute(LastError ).toInt(); - DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatEDlAttrErrorId(), err ); + DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), + &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlFailed() ); + // store failure + iDownloadSuccess = EFalse; + User::LeaveIfError( aDownload.GetIntAttribute( + EDlAttrErrorId, err ) ); + DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatEDlAttrErrorId(), err ); - if ( err == ConnectionFailed || err == TransactionFailed ) - { - DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), - &RoHdlrDMgrWrDebugLiterals::KStrEConnectionFailed() ); - iConnectionError = ETrue; - } + if ( err == EConnectionFailed || err + == ETransactionFailed ) + { + DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), + &RoHdlrDMgrWrDebugLiterals::KStrEConnectionFailed() ); + iConnectionError = ETrue; + } - // finished - TRequestStatus* status( &iStatus ); - User::RequestComplete( status, KErrCancel ); - } + // finished + TRequestStatus* status( &iStatus ); + User::RequestComplete( status, KErrCancel ); + } } @@ -760,4 +881,3 @@ } return KErrNone; } -