omadrm/drmplugins/drmrohandler/src/rohandlerdmgrwrapper.cpp
branchRCL_3
changeset 72 1481bf457703
parent 71 1221b68b8a5f
equal deleted inserted replaced
71:1221b68b8a5f 72:1481bf457703
     1 /*
     1 /*
     2 * Copyright (c) 2008 - 2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008 - 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    19 #include <es_enum_partner.h>
    19 #include <es_enum_partner.h>
    20 #endif
    20 #endif
    21 #include <centralrepository.h>
    21 #include <centralrepository.h>
    22 #include <cdblen.h>
    22 #include <cdblen.h>
    23 
    23 
       
    24 #ifdef __SERIES60_NATIVE_BROWSER
       
    25 #include <browseruisdkcrkeys.h>
       
    26 #endif
       
    27 
    24 #include <cmconnectionmethod.h>
    28 #include <cmconnectionmethod.h>
    25 #include <cmdestination.h>
    29 #include <cmdestination.h>
    26 #include <cmconnectionmethoddef.h>
    30 #include <cmconnectionmethoddef.h>
    27 #include <cmmanager.h>
    31 #include <cmmanager.h>
    28 
    32 
    29 #ifdef RD_MULTIPLE_DRIVE
    33 #ifdef RD_MULTIPLE_DRIVE
    30 #include <driveinfo.h>
    34 #include <driveinfo.h>
    31 #endif
    35 #endif
    32 
    36 
    33 #include <data_caging_path_literals.hrh>
    37 #include <data_caging_path_literals.hrh>
       
    38 
       
    39 #include <downloadmgrclient.h>
    34 
    40 
    35 #include <es_enum.h> // tconnectioninfo
    41 #include <es_enum.h> // tconnectioninfo
    36 #include <es_sock.h> // rconnection rsocket
    42 #include <es_sock.h> // rconnection rsocket
    37 #include <RoapEng.h>
    43 #include <RoapEng.h>
    38 #include <RoapDef.h>
    44 #include <RoapDef.h>
    39 #include <RoapObserver.h>
    45 #include <RoapObserver.h>
    40 #include "RoapSyncWrapper.h"
    46 #include "RoapSyncWrapper.h"
    41 
    47 
    42 // Download manager apis
       
    43 #include <qobject.h>
       
    44 #include <downloadmanager.h>
       
    45 #include <download.h>
       
    46 
       
    47 #include "rohandlerdmgrwrapper.h"
    48 #include "rohandlerdmgrwrapper.h"
    48 #include "cleanupresetanddestroy.h"
       
    49 #include "buffercontainers.h"
       
    50 #include "qrohandlerdmgreventhandler.h"
       
    51 
    49 
    52 #ifdef _DEBUG
    50 #ifdef _DEBUG
    53 #define DRMDEBUG( a ) RDebug::Print( a )
    51 #define DRMDEBUG( a ) RDebug::Print( a )
    54 #define DRMDEBUG2( a, b ) RDebug::Print( a, b )
    52 #define DRMDEBUG2( a, b ) RDebug::Print( a, b )
    55 #define DRMDEBUG3( a, b, c ) RDebug::Print( a, b, c )
    53 #define DRMDEBUG3( a, b, c ) RDebug::Print( a, b, c )
    93     _LIT( KMethDestructor, "~CRoHandlerDMgrWrapper" );
    91     _LIT( KMethDestructor, "~CRoHandlerDMgrWrapper" );
    94     //Methods
    92     //Methods
    95     _LIT( KMethConstructL, "ConstructL" );
    93     _LIT( KMethConstructL, "ConstructL" );
    96     _LIT( KMethNewL, "NewL" );
    94     _LIT( KMethNewL, "NewL" );
    97     _LIT( KMethNewLC, "NewLC" );
    95     _LIT( KMethNewLC, "NewLC" );
       
    96     _LIT( KMethDownloadAndHandleRoapTriggerL, "DownloadAndHandleRoapTriggerL" );
       
    97     _LIT( KMethDownloadAndHandleRoapTriggerFromPrUrlL,
       
    98         "DownloadAndHandleRoapTriggerFromPrUrlL" );
    98     _LIT( KMethDoDownloadAndHandleRoapTriggerL,
    99     _LIT( KMethDoDownloadAndHandleRoapTriggerL,
    99         "DoDownloadAndHandleRoapTriggerL" );
   100         "DoDownloadAndHandleRoapTriggerL" );
   100     _LIT( KFormatDoDlHdlRoapTrigL, "DoDownloadAndHandleRoapTriggerL: %S" );
   101     _LIT( KFormatDoDlHdlRoapTrigL, "DoDownloadAndHandleRoapTriggerL: %S" );
   101     _LIT( KStrDlCreated, "download created" );
   102     _LIT( KStrDlCreated, "download created" );
   102     _LIT( KStrDlFinished, "download finished" );
   103     _LIT( KStrDlFinished, "download finished" );
   103 
   104 
   104     _LIT( KMethSetDefaultAccessPointL, "SetDefaultAccessPointL" );
   105     _LIT( KMethSetDefaultAccessPointL, "SetDefaultAccessPointL" );
       
   106     _LIT( KMiIapId, "iIapId" );
   105 
   107 
   106     _LIT( KMethHandleDMgrEventL, "HandleDMgrEventL" );
   108     _LIT( KMethHandleDMgrEventL, "HandleDMgrEventL" );
   107     _LIT( KFormatMethHandleDMgrEventL, "HandleDMgrEventL %S" );
   109     _LIT( KFormatMethHandleDMgrEventL, "HandleDMgrEventL %S" );
   108     _LIT( KStrEHttpDlCreated, "EHttpDlCreated" );
   110     _LIT( KStrEHttpDlCreated, "EHttpDlCreated" );
   109     _LIT( KStrEHttpContentTypeReceived, "EHttpContentTypeReceived" );
   111     _LIT( KStrEHttpContentTypeReceived, "EHttpContentTypeReceived" );
   112     _LIT( KStrEHttpDlCompleted, "EHttpDlCompleted" );
   114     _LIT( KStrEHttpDlCompleted, "EHttpDlCompleted" );
   113     _LIT( KStrEHttpDlFailed, "EHttpDlFailed" );
   115     _LIT( KStrEHttpDlFailed, "EHttpDlFailed" );
   114     _LIT( KStrEConnectionFailed, "EConnectionFailed" );
   116     _LIT( KStrEConnectionFailed, "EConnectionFailed" );
   115     _LIT( KFormatEDlAttrErrorId, "EDlAttrErrorId = %d" );
   117     _LIT( KFormatEDlAttrErrorId, "EDlAttrErrorId = %d" );
   116 
   118 
   117     _LIT( KMiState, "iState" );
   119     _LIT( KMiDownLoadState, "iDownLoadState" );
       
   120     _LIT( KMiProgressState, "iProgressState" );
   118 
   121 
   119     }
   122     }
   120 
   123 
   121 #else
   124 #else
   122 #define DRMDEBUG( a )
   125 #define DRMDEBUG( a )
   130 //#define LOG( a )
   133 //#define LOG( a )
   131 //#define LOGHEX( ptr, len )
   134 //#define LOGHEX( ptr, len )
   132 //#define LOG2( a, b )
   135 //#define LOG2( a, b )
   133 #endif
   136 #endif
   134 
   137 
       
   138 #ifndef __SERIES60_NATIVE_BROWSER
       
   139 const TUid KCRUidBrowser =
       
   140     {0x10008D39};
       
   141 const TUint32 KBrowserDefaultAccessPoint = 0x0000000E;
       
   142 const TUint32 KBrowserAccessPointSelectionMode = 0x0000001E;
       
   143 const TUint32 KBrowserNGDefaultSnapId = 0x00000053;
       
   144 #endif
       
   145 
   135 // CONSTANTS
   146 // CONSTANTS
   136 #ifndef RD_MULTIPLE_DRIVE
   147 #ifndef RD_MULTIPLE_DRIVE
   137 _LIT( KHelperTriggerFilePath, "d:\\" );
   148 _LIT( KHelperTriggerFilePath, "d:\\" );
   138 #endif
   149 #endif
   139 
   150 
   140 using namespace WRT;
   151 // ============================== LOCAL FUNCTIONS ==============================
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // DoResetAndDestroy
       
   155 // Does RPointerArray< typename >->ResetAndDestroy() for the given array aPtr.
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 template< typename elemType >
       
   159 LOCAL_C void DoResetAndDestroy( TAny* aPtr )
       
   160     {
       
   161     ( reinterpret_cast< RPointerArray< elemType >* >( aPtr ) )->
       
   162         ResetAndDestroy();
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // DeleteHttpDowload
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 LOCAL_C void DeleteHttpDowload( TAny* aDownload )
       
   170     {
       
   171     reinterpret_cast< RHttpDownload* >( aDownload )->Delete();
       
   172     }
   141 
   173 
   142 // ---------------------------------------------------------------------------
   174 // ---------------------------------------------------------------------------
   143 // UpdateBufferL
   175 // UpdateBufferL
   144 // ---------------------------------------------------------------------------
   176 // ---------------------------------------------------------------------------
   145 //
   177 //
   154     if ( aSourceBuf.Length() )
   186     if ( aSourceBuf.Length() )
   155         {
   187         {
   156         aTargetBuf = aSourceBuf.AllocL();
   188         aTargetBuf = aSourceBuf.AllocL();
   157         }
   189         }
   158     }
   190     }
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 // IapIdOfDefaultSnapL
       
   194 // for trapping purposes only
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 LOCAL_C TUint32 IapIdOfDefaultSnapL(
       
   198     RCmManager& aCmManager,
       
   199     const TUint32 aDefaultSnap )
       
   200     {
       
   201     RCmDestination dest( aCmManager.DestinationL( aDefaultSnap ) );
       
   202     CleanupClosePushL( dest );
       
   203     TUint32 iapIdOfDest( 0 );
       
   204 
       
   205     if ( dest.ConnectionMethodCount() <= 0 )
       
   206         {
       
   207         User::Leave( KErrNotFound );
       
   208         }
       
   209 
       
   210     RCmConnectionMethod cMeth( dest.ConnectionMethodL( 0 ) );
       
   211     CleanupClosePushL( cMeth );
       
   212 
       
   213     iapIdOfDest = cMeth.GetIntAttributeL( CMManager::ECmIapId );
       
   214     CleanupStack::PopAndDestroy( &cMeth );
       
   215     CleanupStack::PopAndDestroy( &dest );
       
   216     return iapIdOfDest;
       
   217     }
       
   218 
   159 
   219 
   160 // ============================= MEMBER FUNCTIONS ==============================
   220 // ============================= MEMBER FUNCTIONS ==============================
   161 
   221 
   162 // ---------------------------------------------------------------------------
   222 // ---------------------------------------------------------------------------
   163 // CRoHandlerDMgrWrapper::CRoHandlerDMgrWrapper
   223 // CRoHandlerDMgrWrapper::CRoHandlerDMgrWrapper
   177 void CRoHandlerDMgrWrapper::ConstructL()
   237 void CRoHandlerDMgrWrapper::ConstructL()
   178     {
   238     {
   179     DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethConstructL() );
   239     DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethConstructL() );
   180     // Get UID from process
   240     // Get UID from process
   181     const TInt KRoHandlerDMgrWrapperUid = 0x101F7B92;
   241     const TInt KRoHandlerDMgrWrapperUid = 0x101F7B92;
   182     try
   242     iDlMgr.ConnectL( TUid::Uid( KRoHandlerDMgrWrapperUid ), *this, EFalse );
   183 		{
       
   184 		QString roHandlerDmgrWrapperUid(QString::number(KRoHandlerDMgrWrapperUid));
       
   185 		iDlMgr = q_check_ptr(new DownloadManager(roHandlerDmgrWrapperUid));
       
   186 		}
       
   187     catch(const std::exception& exception)
       
   188     	{
       
   189 		qt_symbian_exception2LeaveL(exception);
       
   190     	}
       
   191     User::LeaveIfError( iFs.Connect() );
   243     User::LeaveIfError( iFs.Connect() );
   192     User::LeaveIfError( iFs.ShareProtected() );
   244     User::LeaveIfError( iFs.ShareProtected() );
   193 
   245 
   194     }
   246     }
   195 
   247 
   230     delete iTriggerUrl;
   282     delete iTriggerUrl;
   231     delete iTriggerBuf;
   283     delete iTriggerBuf;
   232     delete iFileName;
   284     delete iFileName;
   233     delete iRoapEng;
   285     delete iRoapEng;
   234 
   286 
   235     delete iDlMgr;
   287 #ifdef _DEBUG
   236     delete iRoHandlerDMgrEventHandler;
   288 
   237     
   289     if ( iDlMgr.Handle() )
       
   290         {
       
   291         iDlMgr.Close();
       
   292         }
       
   293 
       
   294 #else
       
   295 
       
   296     iDlMgr.Close();
       
   297 
       
   298 #endif
       
   299 
   238     iFs.Close();
   300     iFs.Close();
   239     
   301     }
   240     }
   302 
   241 
   303 // ---------------------------------------------------------------------------
   242 // ---------------------------------------------------------------------------
   304 // CRoHandlerDMgrWrapper::DownloadAndHandleRoapTriggerL
   243 // CRoHandlerDMgrWrapper::HandleRoapTriggerL
       
   244 // ---------------------------------------------------------------------------
   305 // ---------------------------------------------------------------------------
   245 //
   306 //
   246 void CRoHandlerDMgrWrapper::HandleRoapTriggerL( const TDesC8& aTrigger )
   307 void CRoHandlerDMgrWrapper::HandleRoapTriggerL( const TDesC8& aTrigger )
   247     {
   308     {
   248     if ( iState != EInit || iWait.IsStarted() )
   309     if ( iState != EInit || iWait.IsStarted() )
   254     Continue( EMeteringReportSubmit, KErrNone );
   315     Continue( EMeteringReportSubmit, KErrNone );
   255     iWait.Start();
   316     iWait.Start();
   256     }
   317     }
   257 
   318 
   258 // ---------------------------------------------------------------------------
   319 // ---------------------------------------------------------------------------
       
   320 // CRoHandlerDMgrWrapper::DownloadAndHandleRoapTriggerL
       
   321 // ---------------------------------------------------------------------------
       
   322 //
       
   323 void CRoHandlerDMgrWrapper::DownloadAndHandleRoapTriggerL( const HBufC8* aUrl )
       
   324     {
       
   325     DRMDEBUGMETHOD(
       
   326         RoHdlrDMgrWrDebugLiterals::KMethDownloadAndHandleRoapTriggerL() );
       
   327     if ( iState != EInit || iWait.IsStarted() )
       
   328         {
       
   329         User::Leave( KErrNotReady );
       
   330         }
       
   331 
       
   332     UpdateBufferL< HBufC8, TDesC8 >( iTriggerUrl, *aUrl );
       
   333     Continue( EGetMeteringTrigger, KErrNone );
       
   334     iWait.Start();
       
   335     }
       
   336 
       
   337 // ---------------------------------------------------------------------------
       
   338 // CRoHandlerDMgrWrapper::DownloadAndHandleRoapTriggerFromPrUrlL
       
   339 // ---------------------------------------------------------------------------
       
   340 //
       
   341 void CRoHandlerDMgrWrapper::DownloadAndHandleRoapTriggerFromPrUrlL(
       
   342         const HBufC8* aUrl )
       
   343     {
       
   344     DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethDownloadAndHandleRoapTriggerFromPrUrlL() );
       
   345     if ( iState != EInit || iWait.IsStarted() )
       
   346         {
       
   347         User::Leave( KErrNotReady );
       
   348         }
       
   349 
       
   350     UpdateBufferL< HBufC8, TDesC8 >( iTriggerUrl, *aUrl );
       
   351     Continue( EGetPrUrlTrigger, KErrNone );
       
   352     iWait.Start();
       
   353     }
       
   354 
       
   355 // ---------------------------------------------------------------------------
   259 // CRoHandlerDMgrWrapper::DoDownloadRoapTriggerL
   356 // CRoHandlerDMgrWrapper::DoDownloadRoapTriggerL
   260 // ---------------------------------------------------------------------------
   357 // ---------------------------------------------------------------------------
   261 //
   358 //
   262 void CRoHandlerDMgrWrapper::DoDownloadRoapTriggerL( TMeterState aNextState )
   359 void CRoHandlerDMgrWrapper::DoDownloadRoapTriggerL( TMeterState aNextState )
   263     {
   360     {
   264     RFile roapTrigger;
   361     RFile roapTrigger;
   265     DRM::CFileNameContainer* triggerFileName(NULL);
   362     TBool result( EFalse );
       
   363     TFileName triggerFileName;
   266 
   364 
   267     DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethDoDownloadAndHandleRoapTriggerL() );
   365     DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethDoDownloadAndHandleRoapTriggerL() );
   268     // If no Trigger URL then nothing to download. So finish transaction
   366     // If no Trigger URL then nothing to download. So finish transaction
   269     if ( !iTriggerUrl || iTriggerUrl->Length() <= 0 )
   367     if ( !iTriggerUrl || iTriggerUrl->Length() <= 0 )
   270         {
   368         {
   271         Continue( EComplete, KErrNone );
   369         Continue( EComplete, KErrNone );
   272         return;
   370         return;
   273         }
   371         }
   274 
   372 
   275     triggerFileName=DRM::CFileNameContainer::NewLC();
       
   276 #ifndef RD_MULTIPLE_DRIVE
   373 #ifndef RD_MULTIPLE_DRIVE
   277 
   374 
   278     User::LeaveIfError( roapTrigger.Temp(
   375     User::LeaveIfError( roapTrigger.Temp(
   279             iFs, KHelperTriggerFilePath, triggerFileName->iBuffer, EFileWrite ) );
   376             iFs, KHelperTriggerFilePath, triggerFileName, EFileWrite ) );
   280 
   377 
   281 #else //RD_MULTIPLE_DRIVE
   378 #else //RD_MULTIPLE_DRIVE
   282     _LIT( KDrive, "%c:\\" );
   379     _LIT( KDrive, "%c:\\" );
   283     TInt driveNumber( -1 );
   380     TInt driveNumber( -1 );
   284     TChar driveLetter;
   381     TChar driveLetter;
   285     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRam, driveNumber );
   382     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRam, driveNumber );
   286     iFs.DriveToChar( driveNumber, driveLetter );
   383     iFs.DriveToChar( driveNumber, driveLetter );
   287 
   384 
   288     DRM::CFileNameContainer*
   385     TFileName helperTriggerFilePath;
   289         helperTriggerFilePath( DRM::CFileNameContainer::NewLC() );
   386 
   290 
   387     helperTriggerFilePath.Format( KDrive, ( TUint )driveLetter );
   291     helperTriggerFilePath->iBuffer.Format( KDrive, ( TUint )driveLetter );
   388 
   292 
   389     User::LeaveIfError( roapTrigger.Temp( iFs, helperTriggerFilePath,
   293     User::LeaveIfError( roapTrigger.Temp( iFs, helperTriggerFilePath->iBuffer,
   390             triggerFileName, EFileWrite ) );
   294                 triggerFileName->iBuffer, EFileWrite ) );
       
   295     CleanupStack::PopAndDestroy( helperTriggerFilePath );
       
   296     helperTriggerFilePath=NULL;
       
   297 
   391 
   298 #endif
   392 #endif
   299     UpdateBufferL< HBufC, TFileName >( iFileName, triggerFileName->iBuffer );
   393     UpdateBufferL< HBufC, TFileName >( iFileName, triggerFileName );
   300     CleanupStack::PopAndDestroy( triggerFileName );
   394 
   301     triggerFileName=NULL;
   395     // create and start download
   302 
   396     RHttpDownload& download = iDlMgr.CreateDownloadL( *iTriggerUrl, result );
   303     try
   397     // Put download for proper cleanup.
   304 		{
   398     TCleanupItem item( DeleteHttpDowload, &download );
   305 		// create and start download
   399     CleanupStack::PushL( item );
   306         QString downloadUrl((QChar*)iTriggerUrl->Des().Ptr(),iTriggerUrl->Length());
   400 
   307         iDownload = iDlMgr->createDownload( downloadUrl );
       
   308 		iRoHandlerDMgrEventHandler = q_check_ptr(new QRoHandlerDMgrEventHandler(*this, *iDownload));
       
   309 		}
       
   310     catch(const std::exception& exception)
       
   311 		{
       
   312 		qt_symbian_exception2LeaveL(exception);
       
   313 		}
       
   314     		
       
   315     CleanupClosePushL( roapTrigger );
   401     CleanupClosePushL( roapTrigger );
   316 
   402 
   317     
   403     if ( result )
   318 	DRMDEBUG2(
   404         {
   319 		RoHdlrDMgrWrDebugLiterals::KFormatDoDlHdlRoapTrigL(),
   405         DRMDEBUG2(
   320 		&RoHdlrDMgrWrDebugLiterals::KStrDlCreated() );
   406             RoHdlrDMgrWrDebugLiterals::KFormatDoDlHdlRoapTrigL(),
   321 	iDownloadSuccess = EFalse;
   407             &RoHdlrDMgrWrDebugLiterals::KStrDlCreated() );
   322 	iConnectionError = EFalse;
   408         iDownloadSuccess = EFalse;
   323 
   409         iConnectionError = EFalse;
   324 	SetDefaultAccessPointL();
   410 
   325         
   411         SetDefaultAccessPointL();
   326 	try
   412         User::LeaveIfError( download.SetFileHandleAttribute( roapTrigger ) );
   327 		{
   413         User::LeaveIfError( download.SetBoolAttribute(
   328 		RBuf fileName;
   414                 EDlAttrNoContentTypeCheck, ETrue ) );
   329 		User::LeaveIfError(fileName.Create(KMaxFileName));
   415         User::LeaveIfError( download.Start() );
   330 		CleanupClosePushL(fileName);
   416 
   331 		roapTrigger.Name(fileName);
   417         // wait until download is finished
   332 		const QVariant& roapTriggerValue( QString((QChar*) fileName.Ptr(), fileName.Length()) );
   418         iState = aNextState;
   333 		CleanupStack::PopAndDestroy(&fileName);
   419         TRequestStatus* status( &iStatus );
   334 		iDownload->setAttribute(FileName,roapTriggerValue);
   420         *status = KRequestPending;
   335 		const QVariant& val(ETrue);
   421         SetActive();
   336 		iDownload->setAttribute(ContentType, val);
   422         }
   337 		iDownload->start();
       
   338 		}
       
   339 	catch(const std::exception& exception)
       
   340 		{
       
   341 		qt_symbian_exception2LeaveL(exception);
       
   342 		}
       
   343 	
       
   344 	// wait until download is finished
       
   345 	iState = aNextState;
       
   346 	TRequestStatus* status( &iStatus );
       
   347 	*status = KRequestPending;
       
   348 	SetActive();
       
   349         
       
   350     CleanupStack::PopAndDestroy( &roapTrigger );
   423     CleanupStack::PopAndDestroy( &roapTrigger );
       
   424     CleanupStack::Pop( &download ); // Left open for DoSaveRoapTrigger
   351     }
   425     }
   352 // ---------------------------------------------------------------------------
   426 // ---------------------------------------------------------------------------
   353 // CRoHandlerDMgrWrapper::DoSaveRoapTriggerL
   427 // CRoHandlerDMgrWrapper::DoSaveRoapTriggerL
   354 // ---------------------------------------------------------------------------
   428 // ---------------------------------------------------------------------------
   355 //
   429 //
   358     // Check success of download
   432     // Check success of download
   359     DRMDEBUG2(
   433     DRMDEBUG2(
   360         RoHdlrDMgrWrDebugLiterals::KFormatDoDlHdlRoapTrigL(),
   434         RoHdlrDMgrWrDebugLiterals::KFormatDoDlHdlRoapTrigL(),
   361         &RoHdlrDMgrWrDebugLiterals::KStrDlFinished() );
   435         &RoHdlrDMgrWrDebugLiterals::KStrDlFinished() );
   362 
   436 
   363     try
   437     // Fetch download created in DoDownloadRoapTriggerL
   364 		{
   438     RHttpDownload* download = iDlMgr.FindDownload( *iTriggerUrl, KNullDesC8() );
   365 		// Fetch download created in DoDownloadRoapTriggerL
       
   366 		QString downloadUrl((QChar*)iTriggerUrl->Des().Ptr(),iTriggerUrl->Length());
       
   367 		//uncomment
       
   368 		iDownload = NULL; //iDlMgr->findDownload( downloadUrl );
       
   369 		}
       
   370     catch(const std::exception& exception)
       
   371 		{
       
   372 		qt_symbian_exception2LeaveL(exception);
       
   373 		} 
       
   374     
       
   375     // Delete trigger URL so that it is possible to check
   439     // Delete trigger URL so that it is possible to check
   376     // whether or not meteringResponse has PrUrl.
   440     // whether or not meteringResponse has PrUrl.
   377     delete iTriggerUrl;
   441     delete iTriggerUrl;
   378     iTriggerUrl = NULL;
   442     iTriggerUrl = NULL;
   379     
   443     // Put download for proper cleanup.
       
   444     TCleanupItem item( DeleteHttpDowload, download );
       
   445     CleanupStack::PushL( item );
   380     RFile roapTrigger;
   446     RFile roapTrigger;
   381 
   447 
   382     if ( !iDownloadSuccess )
   448     if ( !iDownloadSuccess )
   383         {
   449         {
   384             if ( iConnectionError )
   450             if ( iConnectionError )
   417         }
   483         }
   418 
   484 
   419     // And let ROAP handle it...
   485     // And let ROAP handle it...
   420     CleanupStack::PopAndDestroy( &readBuf );
   486     CleanupStack::PopAndDestroy( &readBuf );
   421     CleanupStack::PopAndDestroy( &roapTrigger );
   487     CleanupStack::PopAndDestroy( &roapTrigger );
   422     
   488     CleanupStack::PopAndDestroy( download );
       
   489 
   423     iFs.Delete( *iFileName );
   490     iFs.Delete( *iFileName );
   424     delete iFileName;
   491     delete iFileName;
   425     iFileName=NULL;
   492     iFileName=NULL;
   426     Continue( aNextState, KErrNone );
   493     Continue( aNextState, KErrNone );
   427     }
   494     }
   435     Roap::TTriggerType triggerType;
   502     Roap::TTriggerType triggerType;
   436     Roap::TRiContextStatus contextStatus;
   503     Roap::TRiContextStatus contextStatus;
   437     Roap::TDomainOperation domainOperation;
   504     Roap::TDomainOperation domainOperation;
   438 
   505 
   439     RPointerArray< HBufC8 > contentIds;
   506     RPointerArray< HBufC8 > contentIds;
   440     CleanupResetAndDestroyPushL( contentIds );
   507 
       
   508     TCleanupItem cleanup( DoResetAndDestroy< HBufC8 >, &contentIds );
       
   509     CleanupStack::PushL( cleanup );
   441 
   510 
   442     iRoapEng = Roap::CRoapEng::NewL();
   511     iRoapEng = Roap::CRoapEng::NewL();
   443 
   512 
   444     iRoapEng->SetTriggerL( *iTriggerBuf, NULL, triggerType, contextStatus,
   513     iRoapEng->SetTriggerL( *iTriggerBuf, NULL, triggerType, contextStatus,
   445         domainOperation, contentIds );
   514         domainOperation, contentIds );
   464 // CRoHandlerDMgrWrapper::SetDefaultAccessPointL
   533 // CRoHandlerDMgrWrapper::SetDefaultAccessPointL
   465 // ---------------------------------------------------------------------------
   534 // ---------------------------------------------------------------------------
   466 //
   535 //
   467 void CRoHandlerDMgrWrapper::SetDefaultAccessPointL()
   536 void CRoHandlerDMgrWrapper::SetDefaultAccessPointL()
   468     {
   537     {
       
   538     const TInt KDestinationSelectionMode( 2 );
       
   539     CRepository* repository( NULL );
       
   540     TInt ap( 0 );
       
   541     TInt alwaysAsk( 0 );
       
   542     TUint32 iapd32( 0 );
       
   543     TInt defaultSnap( 0 );
       
   544     TInt err( KErrNone );
       
   545 
   469     DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethSetDefaultAccessPointL() );
   546     DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethSetDefaultAccessPointL() );
   470 
   547 
   471     if ( iIapId )
   548     if ( !iIapId )
   472         {
   549         {
   473         QVariant iapId((unsigned long long)iIapId);
   550         repository = CRepository::NewL( KCRUidBrowser );
   474         iDlMgr->setAttribute(DefaultDestinationPath, iapId);
   551         CleanupStack::PushL( repository );
       
   552         repository->Get( KBrowserDefaultAccessPoint, ap );
       
   553         repository->Get( KBrowserAccessPointSelectionMode, alwaysAsk );
       
   554         repository->Get( KBrowserNGDefaultSnapId, defaultSnap );
       
   555         if ( ap <= KErrNotFound && defaultSnap <= KErrNotFound )
       
   556             {
       
   557             alwaysAsk = ETrue;
       
   558             }
       
   559         else
       
   560             {
       
   561             RCmManager cmManager;
       
   562             cmManager.OpenLC();
       
   563             if ( !alwaysAsk )
       
   564                 {
       
   565                 TRAP( err, iapd32 = cmManager.GetConnectionMethodInfoIntL(
       
   566                         ap, CMManager::ECmIapId ) );
       
   567                 }
       
   568             else if ( alwaysAsk == KDestinationSelectionMode )
       
   569                 {
       
   570                 TRAP( err, iapd32 = IapIdOfDefaultSnapL(
       
   571                         cmManager, defaultSnap ) );
       
   572                 }
       
   573             CleanupStack::PopAndDestroy( &cmManager );
       
   574             }
       
   575         if ( !err && ( !alwaysAsk || alwaysAsk == KDestinationSelectionMode ) )
       
   576             {
       
   577             iIapId = iapd32;
       
   578             DRMDEBUG3( RoHdlrDMgrWrDebugLiterals::KFormatMembValInt(),
       
   579                 &RoHdlrDMgrWrDebugLiterals::KMiIapId(), iIapId );
       
   580             err = iDlMgr.SetIntAttribute( EDlMgrIap, iapd32 );
       
   581             }
       
   582         CleanupStack::PopAndDestroy( repository );
       
   583         }
       
   584     else
       
   585         {
       
   586         err = iDlMgr.SetIntAttribute( EDlMgrIap, iIapId );
   475         }
   587         }
   476     }
   588     }
   477 
   589 
   478 // ---------------------------------------------------------------------------
   590 // ---------------------------------------------------------------------------
   479 // CRoHandlerDMgrWrapper::Continue
   591 // CRoHandlerDMgrWrapper::Continue
   494 
   606 
   495 // ---------------------------------------------------------------------------
   607 // ---------------------------------------------------------------------------
   496 // CRoHandlerDMgrWrapper::HandleDMgrEventL
   608 // CRoHandlerDMgrWrapper::HandleDMgrEventL
   497 // ---------------------------------------------------------------------------
   609 // ---------------------------------------------------------------------------
   498 //
   610 //
   499 void CRoHandlerDMgrWrapper::HandleDownloadEventL( WRT::DownloadEvent* aEvent )
   611 void CRoHandlerDMgrWrapper::HandleDMgrEventL( RHttpDownload& aDownload,
   500     {
   612         THttpDownloadEvent aEvent )
   501     QString KDRMHelperMimeTypeROAPTrigger("application/vnd.oma.drm.roap-trigger+xml" );
   613     {
       
   614     _LIT8( KDRMHelperMimeTypeROAPTrigger, "application/vnd.oma.drm.roap-trigger+xml" );
   502 
   615 
   503     DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethHandleDMgrEventL() );
   616     DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethHandleDMgrEventL() );
   504     DRMDEBUG3( RoHdlrDMgrWrDebugLiterals::KFormatMembValInt(),
   617     DRMDEBUG3( RoHdlrDMgrWrDebugLiterals::KFormatMembValInt(),
   505             &RoHdlrDMgrWrDebugLiterals::KMiState(), aEvent->type() );
   618             &RoHdlrDMgrWrDebugLiterals::KMiDownLoadState(), aEvent.iDownloadState );
   506     
   619     DRMDEBUG3( RoHdlrDMgrWrDebugLiterals::KFormatMembValInt(),
   507     if ( aEvent->type() == DownloadEvent::HeadersReceived )
   620             &RoHdlrDMgrWrDebugLiterals::KMiProgressState(), aEvent.iProgressState );
       
   621 
       
   622     if ( aEvent.iProgressState == EHttpContentTypeReceived )
   508         {
   623         {
   509         DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(),
   624         DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(),
   510                 &RoHdlrDMgrWrDebugLiterals::KStrEHttpContentTypeReceived() );
   625                 &RoHdlrDMgrWrDebugLiterals::KStrEHttpContentTypeReceived() );
   511         // check received mimetype
   626         // check received mimetype
   512         QString contentType = iDownload->attribute( ContentType).toString();
   627         RBuf8 contentType;
   513         if ( contentType.contains( KDRMHelperMimeTypeROAPTrigger )  == EFalse )
   628         contentType.CleanupClosePushL();
       
   629         contentType.CreateL( KMaxContentTypeLength );
       
   630         User::LeaveIfError( aDownload.GetStringAttribute( EDlAttrContentType,
       
   631                 contentType ) );
       
   632         if ( !contentType.FindF( KDRMHelperMimeTypeROAPTrigger ) )
   514             {
   633             {
   515             // ROAP trigger found, continue download
   634             // ROAP trigger found, continue download
   516             iDownload->start();
   635             User::LeaveIfError( aDownload.Start() );
   517             }
   636             }
   518         else
   637         else
   519             {
   638             {
   520             // wrong MIME type?, stop download
   639             // wrong MIME type?, stop download
   521             iDownloadSuccess = EFalse;
   640             iDownloadSuccess = EFalse;
   522             iDownload->cancel();
   641             User::LeaveIfError( aDownload.Delete() );
   523             }
   642             }
   524         CleanupStack::PopAndDestroy( &contentType );
   643         CleanupStack::PopAndDestroy( &contentType );
   525         }
   644         }
   526 
   645 
   527     if ( aEvent->type() == DownloadEvent::Created )
   646     if ( aEvent.iDownloadState == EHttpDlCreated )
   528         {
   647         {
   529         DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(),
   648         DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(),
   530                 &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlCreated() );
   649                 &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlCreated() );
   531         }
   650         }
   532     else
   651     else
   533         if ( aEvent->type() == DownloadEvent::NetworkLoss )
   652         if ( aEvent.iProgressState == EHttpProgDisconnected )
   534             {
   653             {
   535             DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(),
   654             DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(),
   536                     &RoHdlrDMgrWrDebugLiterals::KStrEHttpProgDisconnected() );
   655                     &RoHdlrDMgrWrDebugLiterals::KStrEHttpProgDisconnected() );
   537             // store failure
   656             // store failure
   538             iDownloadSuccess = EFalse;
   657             iDownloadSuccess = EFalse;
   539             iConnectionError = ETrue;
   658             iConnectionError = ETrue;
   540             // finished
   659             // finished
   541             TRequestStatus* status( &iStatus );
   660             TRequestStatus* status( &iStatus );
   542             User::RequestComplete( status, KErrCancel );
   661             User::RequestComplete( status, KErrCancel );
   543             }
   662             }
   544 	else
   663         else
   545 		if ( aEvent->type() == DownloadEvent::InProgress )
   664             if ( aEvent.iDownloadState == EHttpDlInprogress )
   546 			{
   665                 {
   547 			DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(),
   666                 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(),
   548 					&RoHdlrDMgrWrDebugLiterals::KStrEHttpDlInprogress() );
   667                         &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlInprogress() );
   549 			}
   668                 }
   550 	else
   669             else
   551 		if ( aEvent->type() == DownloadEvent::Completed )
   670                 if ( aEvent.iDownloadState == EHttpDlCompleted )
   552 			{
   671                     {
   553 			// store success
   672                     // store success
   554 			DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(),
   673                     DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(),
   555 					&RoHdlrDMgrWrDebugLiterals::KStrEHttpDlCompleted() );
   674                             &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlCompleted() );
   556 			iDownloadSuccess = ETrue;
   675                     iDownloadSuccess = ETrue;
   557 
   676 
   558 			// finished
   677                     // finished
   559 			TRequestStatus* status( &iStatus );
   678                     TRequestStatus* status( &iStatus );
   560 			User::RequestComplete( status, KErrNone );
   679                     User::RequestComplete( status, KErrNone );
   561 			}
   680                     }
   562 	else
   681                 else
   563 		if ( aEvent->type() == DownloadEvent::Failed )
   682                     if ( aEvent.iDownloadState == EHttpDlFailed )
   564 			{
   683                         {
   565 			TInt32 err;
   684                         TInt32 err;
   566 
   685 
   567 			DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(),
   686                         DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(),
   568 					&RoHdlrDMgrWrDebugLiterals::KStrEHttpDlFailed() );
   687                                 &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlFailed() );
   569 			// store failure
   688                         // store failure
   570 			iDownloadSuccess = EFalse;
   689                         iDownloadSuccess = EFalse;
   571 			err = iDownload->attribute(LastError ).toInt();
   690                         User::LeaveIfError( aDownload.GetIntAttribute(
   572 			DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatEDlAttrErrorId(), err );
   691                                 EDlAttrErrorId, err ) );
   573 
   692                         DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatEDlAttrErrorId(), err );
   574 			if ( err == ConnectionFailed || err == TransactionFailed )
   693 
   575 				{
   694                         if ( err == EConnectionFailed || err
   576 				DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(),
   695                                 == ETransactionFailed )
   577 						&RoHdlrDMgrWrDebugLiterals::KStrEConnectionFailed() );
   696                             {
   578 				iConnectionError = ETrue;
   697                             DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(),
   579 				}
   698                                     &RoHdlrDMgrWrDebugLiterals::KStrEConnectionFailed() );
   580 
   699                             iConnectionError = ETrue;
   581 			// finished
   700                             }
   582 			TRequestStatus* status( &iStatus );
   701 
   583 			User::RequestComplete( status, KErrCancel );
   702                         // finished
   584 			}
   703                         TRequestStatus* status( &iStatus );
       
   704                         User::RequestComplete( status, KErrCancel );
       
   705                         }
   585     }
   706     }
   586 
   707 
   587 
   708 
   588 // RoapObserver methods
   709 // RoapObserver methods
   589 
   710 
   758         {
   879         {
   759         iWait.AsyncStop();
   880         iWait.AsyncStop();
   760         }
   881         }
   761     return KErrNone;
   882     return KErrNone;
   762     }
   883     }
   763