omadrm/drmplugins/drmrohandler/src/rohandlerdmgrwrapper.cpp
changeset 29 3bdc3b853094
parent 23 493788a4a8a4
child 49 69d8e75812b7
equal deleted inserted replaced
23:493788a4a8a4 29:3bdc3b853094
     1 /*
     1 /*
     2 * Copyright (c) 2008 - 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008 - 2010 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 
       
    28 #include <cmconnectionmethod.h>
    24 #include <cmconnectionmethod.h>
    29 #include <cmdestination.h>
    25 #include <cmdestination.h>
    30 #include <cmconnectionmethoddef.h>
    26 #include <cmconnectionmethoddef.h>
    31 #include <cmmanager.h>
    27 #include <cmmanager.h>
    32 
    28 
    44 #include <RoapDef.h>
    40 #include <RoapDef.h>
    45 #include <RoapObserver.h>
    41 #include <RoapObserver.h>
    46 #include "RoapSyncWrapper.h"
    42 #include "RoapSyncWrapper.h"
    47 
    43 
    48 #include "rohandlerdmgrwrapper.h"
    44 #include "rohandlerdmgrwrapper.h"
       
    45 #include "cleanupresetanddestroy.h"
       
    46 #include "buffercontainers.h"
    49 
    47 
    50 #ifdef _DEBUG
    48 #ifdef _DEBUG
    51 #define DRMDEBUG( a ) RDebug::Print( a )
    49 #define DRMDEBUG( a ) RDebug::Print( a )
    52 #define DRMDEBUG2( a, b ) RDebug::Print( a, b )
    50 #define DRMDEBUG2( a, b ) RDebug::Print( a, b )
    53 #define DRMDEBUG3( a, b, c ) RDebug::Print( a, b, c )
    51 #define DRMDEBUG3( a, b, c ) RDebug::Print( a, b, c )
    91     _LIT( KMethDestructor, "~CRoHandlerDMgrWrapper" );
    89     _LIT( KMethDestructor, "~CRoHandlerDMgrWrapper" );
    92     //Methods
    90     //Methods
    93     _LIT( KMethConstructL, "ConstructL" );
    91     _LIT( KMethConstructL, "ConstructL" );
    94     _LIT( KMethNewL, "NewL" );
    92     _LIT( KMethNewL, "NewL" );
    95     _LIT( KMethNewLC, "NewLC" );
    93     _LIT( KMethNewLC, "NewLC" );
    96     _LIT( KMethDownloadAndHandleRoapTriggerL, "DownloadAndHandleRoapTriggerL" );
       
    97     _LIT( KMethDownloadAndHandleRoapTriggerFromPrUrlL,
       
    98         "DownloadAndHandleRoapTriggerFromPrUrlL" );
       
    99     _LIT( KMethDoDownloadAndHandleRoapTriggerL,
    94     _LIT( KMethDoDownloadAndHandleRoapTriggerL,
   100         "DoDownloadAndHandleRoapTriggerL" );
    95         "DoDownloadAndHandleRoapTriggerL" );
   101     _LIT( KFormatDoDlHdlRoapTrigL, "DoDownloadAndHandleRoapTriggerL: %S" );
    96     _LIT( KFormatDoDlHdlRoapTrigL, "DoDownloadAndHandleRoapTriggerL: %S" );
   102     _LIT( KStrDlCreated, "download created" );
    97     _LIT( KStrDlCreated, "download created" );
   103     _LIT( KStrDlFinished, "download finished" );
    98     _LIT( KStrDlFinished, "download finished" );
   104 
    99 
   105     _LIT( KMethSetDefaultAccessPointL, "SetDefaultAccessPointL" );
   100     _LIT( KMethSetDefaultAccessPointL, "SetDefaultAccessPointL" );
   106     _LIT( KMiIapId, "iIapId" );
       
   107 
   101 
   108     _LIT( KMethHandleDMgrEventL, "HandleDMgrEventL" );
   102     _LIT( KMethHandleDMgrEventL, "HandleDMgrEventL" );
   109     _LIT( KFormatMethHandleDMgrEventL, "HandleDMgrEventL %S" );
   103     _LIT( KFormatMethHandleDMgrEventL, "HandleDMgrEventL %S" );
   110     _LIT( KStrEHttpDlCreated, "EHttpDlCreated" );
   104     _LIT( KStrEHttpDlCreated, "EHttpDlCreated" );
   111     _LIT( KStrEHttpContentTypeReceived, "EHttpContentTypeReceived" );
   105     _LIT( KStrEHttpContentTypeReceived, "EHttpContentTypeReceived" );
   133 //#define LOG( a )
   127 //#define LOG( a )
   134 //#define LOGHEX( ptr, len )
   128 //#define LOGHEX( ptr, len )
   135 //#define LOG2( a, b )
   129 //#define LOG2( a, b )
   136 #endif
   130 #endif
   137 
   131 
   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 
       
   146 // CONSTANTS
   132 // CONSTANTS
   147 #ifndef RD_MULTIPLE_DRIVE
   133 #ifndef RD_MULTIPLE_DRIVE
   148 _LIT( KHelperTriggerFilePath, "d:\\" );
   134 _LIT( KHelperTriggerFilePath, "d:\\" );
   149 #endif
   135 #endif
   150 
   136 
   151 // ============================== LOCAL FUNCTIONS ==============================
   137 // ============================== LOCAL FUNCTIONS ==============================
   152 
   138 
   153 // ---------------------------------------------------------------------------
   139 // ---------------------------------------------------------------------------
   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
   140 // DeleteHttpDowload
   167 // ---------------------------------------------------------------------------
   141 // ---------------------------------------------------------------------------
   168 //
   142 //
   169 LOCAL_C void DeleteHttpDowload( TAny* aDownload )
   143 LOCAL_C void DeleteHttpDowload( TAny* aDownload )
   170     {
   144     {
   186     if ( aSourceBuf.Length() )
   160     if ( aSourceBuf.Length() )
   187         {
   161         {
   188         aTargetBuf = aSourceBuf.AllocL();
   162         aTargetBuf = aSourceBuf.AllocL();
   189         }
   163         }
   190     }
   164     }
   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 
       
   219 
   165 
   220 // ============================= MEMBER FUNCTIONS ==============================
   166 // ============================= MEMBER FUNCTIONS ==============================
   221 
   167 
   222 // ---------------------------------------------------------------------------
   168 // ---------------------------------------------------------------------------
   223 // CRoHandlerDMgrWrapper::CRoHandlerDMgrWrapper
   169 // CRoHandlerDMgrWrapper::CRoHandlerDMgrWrapper
   299 
   245 
   300     iFs.Close();
   246     iFs.Close();
   301     }
   247     }
   302 
   248 
   303 // ---------------------------------------------------------------------------
   249 // ---------------------------------------------------------------------------
   304 // CRoHandlerDMgrWrapper::DownloadAndHandleRoapTriggerL
   250 // CRoHandlerDMgrWrapper::HandleRoapTriggerL
   305 // ---------------------------------------------------------------------------
   251 // ---------------------------------------------------------------------------
   306 //
   252 //
   307 void CRoHandlerDMgrWrapper::HandleRoapTriggerL( const TDesC8& aTrigger )
   253 void CRoHandlerDMgrWrapper::HandleRoapTriggerL( const TDesC8& aTrigger )
   308     {
   254     {
   309     if ( iState != EInit || iWait.IsStarted() )
   255     if ( iState != EInit || iWait.IsStarted() )
   315     Continue( EMeteringReportSubmit, KErrNone );
   261     Continue( EMeteringReportSubmit, KErrNone );
   316     iWait.Start();
   262     iWait.Start();
   317     }
   263     }
   318 
   264 
   319 // ---------------------------------------------------------------------------
   265 // ---------------------------------------------------------------------------
   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 // ---------------------------------------------------------------------------
       
   356 // CRoHandlerDMgrWrapper::DoDownloadRoapTriggerL
   266 // CRoHandlerDMgrWrapper::DoDownloadRoapTriggerL
   357 // ---------------------------------------------------------------------------
   267 // ---------------------------------------------------------------------------
   358 //
   268 //
   359 void CRoHandlerDMgrWrapper::DoDownloadRoapTriggerL( TMeterState aNextState )
   269 void CRoHandlerDMgrWrapper::DoDownloadRoapTriggerL( TMeterState aNextState )
   360     {
   270     {
   361     RFile roapTrigger;
   271     RFile roapTrigger;
   362     TBool result( EFalse );
   272     TBool result( EFalse );
   363     TFileName triggerFileName;
   273     DRM::CFileNameContainer* triggerFileName(NULL);
   364 
   274 
   365     DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethDoDownloadAndHandleRoapTriggerL() );
   275     DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethDoDownloadAndHandleRoapTriggerL() );
   366     // If no Trigger URL then nothing to download. So finish transaction
   276     // If no Trigger URL then nothing to download. So finish transaction
   367     if ( !iTriggerUrl || iTriggerUrl->Length() <= 0 )
   277     if ( !iTriggerUrl || iTriggerUrl->Length() <= 0 )
   368         {
   278         {
   369         Continue( EComplete, KErrNone );
   279         Continue( EComplete, KErrNone );
   370         return;
   280         return;
   371         }
   281         }
   372 
   282 
       
   283     triggerFileName=DRM::CFileNameContainer::NewLC();
   373 #ifndef RD_MULTIPLE_DRIVE
   284 #ifndef RD_MULTIPLE_DRIVE
   374 
   285 
   375     User::LeaveIfError( roapTrigger.Temp(
   286     User::LeaveIfError( roapTrigger.Temp(
   376             iFs, KHelperTriggerFilePath, triggerFileName, EFileWrite ) );
   287             iFs, KHelperTriggerFilePath, triggerFileName->iBuffer, EFileWrite ) );
   377 
   288 
   378 #else //RD_MULTIPLE_DRIVE
   289 #else //RD_MULTIPLE_DRIVE
   379     _LIT( KDrive, "%c:\\" );
   290     _LIT( KDrive, "%c:\\" );
   380     TInt driveNumber( -1 );
   291     TInt driveNumber( -1 );
   381     TChar driveLetter;
   292     TChar driveLetter;
   382     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRam, driveNumber );
   293     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRam, driveNumber );
   383     iFs.DriveToChar( driveNumber, driveLetter );
   294     iFs.DriveToChar( driveNumber, driveLetter );
   384 
   295 
   385     TFileName helperTriggerFilePath;
   296     DRM::CFileNameContainer*
   386 
   297         helperTriggerFilePath( DRM::CFileNameContainer::NewLC() );
   387     helperTriggerFilePath.Format( KDrive, ( TUint )driveLetter );
   298 
   388 
   299     helperTriggerFilePath->iBuffer.Format( KDrive, ( TUint )driveLetter );
   389     User::LeaveIfError( roapTrigger.Temp( iFs, helperTriggerFilePath,
   300 
   390             triggerFileName, EFileWrite ) );
   301     User::LeaveIfError( roapTrigger.Temp( iFs, helperTriggerFilePath->iBuffer,
       
   302                 triggerFileName->iBuffer, EFileWrite ) );
       
   303     CleanupStack::PopAndDestroy( helperTriggerFilePath );
       
   304     helperTriggerFilePath=NULL;
   391 
   305 
   392 #endif
   306 #endif
   393     UpdateBufferL< HBufC, TFileName >( iFileName, triggerFileName );
   307     UpdateBufferL< HBufC, TFileName >( iFileName, triggerFileName->iBuffer );
       
   308     CleanupStack::PopAndDestroy( triggerFileName );
       
   309     triggerFileName=NULL;
   394 
   310 
   395     // create and start download
   311     // create and start download
   396     RHttpDownload& download = iDlMgr.CreateDownloadL( *iTriggerUrl, result );
   312     RHttpDownload& download = iDlMgr.CreateDownloadL( *iTriggerUrl, result );
   397     // Put download for proper cleanup.
   313     // Put download for proper cleanup.
   398     TCleanupItem item( DeleteHttpDowload, &download );
   314     TCleanupItem item( DeleteHttpDowload, &download );
   502     Roap::TTriggerType triggerType;
   418     Roap::TTriggerType triggerType;
   503     Roap::TRiContextStatus contextStatus;
   419     Roap::TRiContextStatus contextStatus;
   504     Roap::TDomainOperation domainOperation;
   420     Roap::TDomainOperation domainOperation;
   505 
   421 
   506     RPointerArray< HBufC8 > contentIds;
   422     RPointerArray< HBufC8 > contentIds;
   507 
   423     CleanupResetAndDestroyPushL( contentIds );
   508     TCleanupItem cleanup( DoResetAndDestroy< HBufC8 >, &contentIds );
       
   509     CleanupStack::PushL( cleanup );
       
   510 
   424 
   511     iRoapEng = Roap::CRoapEng::NewL();
   425     iRoapEng = Roap::CRoapEng::NewL();
   512 
   426 
   513     iRoapEng->SetTriggerL( *iTriggerBuf, NULL, triggerType, contextStatus,
   427     iRoapEng->SetTriggerL( *iTriggerBuf, NULL, triggerType, contextStatus,
   514         domainOperation, contentIds );
   428         domainOperation, contentIds );
   533 // CRoHandlerDMgrWrapper::SetDefaultAccessPointL
   447 // CRoHandlerDMgrWrapper::SetDefaultAccessPointL
   534 // ---------------------------------------------------------------------------
   448 // ---------------------------------------------------------------------------
   535 //
   449 //
   536 void CRoHandlerDMgrWrapper::SetDefaultAccessPointL()
   450 void CRoHandlerDMgrWrapper::SetDefaultAccessPointL()
   537     {
   451     {
   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 
       
   546     DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethSetDefaultAccessPointL() );
   452     DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethSetDefaultAccessPointL() );
   547 
   453 
   548     if ( !iIapId )
   454     if ( iIapId )
   549         {
   455         {
   550         repository = CRepository::NewL( KCRUidBrowser );
   456         iDlMgr.SetIntAttribute( EDlMgrIap, iIapId );
   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 );
       
   587         }
   457         }
   588     }
   458     }
   589 
   459 
   590 // ---------------------------------------------------------------------------
   460 // ---------------------------------------------------------------------------
   591 // CRoHandlerDMgrWrapper::Continue
   461 // CRoHandlerDMgrWrapper::Continue