diff -r e16d72588c28 -r 8a03a285ab14 wmdrm/wmdrmengine/wmdrmserver/server/src/wmdrmdatastore.cpp --- a/wmdrm/wmdrmengine/wmdrmserver/server/src/wmdrmdatastore.cpp Fri Mar 12 15:43:46 2010 +0200 +++ b/wmdrm/wmdrmengine/wmdrmserver/server/src/wmdrmdatastore.cpp Mon Mar 15 12:41:43 2010 +0200 @@ -20,10 +20,10 @@ #include #include #include -#include +#include #include "wmdrmdatastore.h" -#include "wmdrmprivatecrkeys.h" +#include "WMDRMPrivateCRKeys.h" #include "wmdrmkeystorage.h" #include "slotdatacache.h" #include "wmdrmdb.h" @@ -56,7 +56,7 @@ return self; } -CWmDrmDataStore::CWmDrmDataStore( CWmDrmServer* aServer ) +CWmDrmDataStore::CWmDrmDataStore( CWmDrmServer* aServer ) : iServer( aServer ), iMinFreeSpace2( 0 ) { LOGFN( "CWmDrmDataStore::CWmDrmDataStore" ); @@ -67,23 +67,23 @@ TDrmScheme drmScheme( EDrmSchemeWmDrm ); TFileName tempFile, tempFile2; TChar driveLetter; - + LOGFN( "CWmDrmDataStore::ConstructL" ); - + // Check which drive is configured in the Central Repository Key // for the desired storing location of WM DRM rights (license store). - iWmDrmRightsConfigFound = DrmRightsStoringLocation::CheckDrmRightsStorageDriveL( - iServer->Fs(), drmScheme, driveLetter ); - - // If the storing location is configured to other drive than the default - // system drive, prepare utility files for that drive, too. + iWmDrmRightsConfigFound = DrmRightsStoringLocation::CheckDrmRightsStorageDriveL( + iServer->Fs(), drmScheme, driveLetter ); + + // If the storing location is configured to other drive than the default + // system drive, prepare utility files for that drive, too. if ( iWmDrmRightsConfigFound ) { PrepareInfoFilesL( ETrue, driveLetter, iDummyDb2 ); } - + // Prepare the utility files for the default system drive - PrepareInfoFilesL( EFalse, (TUint)iServer->Fs().GetSystemDriveChar(), + PrepareInfoFilesL( EFalse, (TUint)iServer->Fs().GetSystemDriveChar(), iDummyDb ); } @@ -111,53 +111,53 @@ CAESDecryptor* aesDecryptor = NULL; CPaddingPKCS7* padding = NULL; TInt size = 0; - + LOGFN( "CWmDrmDataStore::ReadInitialFreeSpaceL" ); User::LeaveIfError( file.Open( iServer->Fs(), aFileName, EFileRead ) ); CleanupClosePushL( file ); - + User::LeaveIfError( file.Size( size ) ); - - if( size != ( 2 * KAESKeyLength ) ) - { - User::Leave(KErrCorrupt); - } + + if( size != ( 2 * KAESKeyLength ) ) + { + User::Leave(KErrCorrupt); + } User::LeaveIfError( file.Read( iv ) ); - User::LeaveIfError( file.Read( encryptedData ) ); + User::LeaveIfError( file.Read( encryptedData ) ); #if defined(FF_PLATFORM_SIMULATOR) || defined(__WINSCW__) - key.Copy( KDummyKey ); + key.Copy( KDummyKey ); #else - iServer->Cache()->iKeyStorage->GetDeviceSpecificKeyL( key ); + iServer->Cache()->iKeyStorage->GetDeviceSpecificKeyL( key ); #endif - aesDecryptor = CAESDecryptor::NewL( key ); + aesDecryptor = CAESDecryptor::NewL( key ); CleanupStack::PushL( aesDecryptor ); - + cbcDecryptor = CModeCBCDecryptor::NewL( aesDecryptor, iv ); CleanupStack::Pop( aesDecryptor ); CleanupStack::PushL( cbcDecryptor ); - + padding = CPaddingPKCS7::NewL( KAESKeyLength ); CleanupStack::PushL( padding ); - + decryptor = CBufferedDecryptor::NewL( cbcDecryptor, padding ); CleanupStack::Pop( 2, cbcDecryptor ); //padding, cbcDecryptor CleanupStack::PushL( decryptor ); - - decryptor->ProcessFinalL( encryptedData, decryptedData ); - CleanupStack::PopAndDestroy( 2, &file ); //decryptor, file - TLex8 lex( decryptedData ); - - if ( aConfiguredDrive ) - { - User::LeaveIfError( lex.Val( iInitialFreeSpace2 ) ); - } - else - { - User::LeaveIfError( lex.Val( iInitialFreeSpace ) ); - } + + decryptor->ProcessFinalL( encryptedData, decryptedData ); + CleanupStack::PopAndDestroy( 2, &file ); //decryptor, file + TLex8 lex( decryptedData ); + + if ( aConfiguredDrive ) + { + User::LeaveIfError( lex.Val( iInitialFreeSpace2 ) ); + } + else + { + User::LeaveIfError( lex.Val( iInitialFreeSpace ) ); + } } - + void CWmDrmDataStore::WriteInitialFreeSpaceL( const TDesC& aFileName, TBool& aConfiguredDrive ) { @@ -170,7 +170,7 @@ CModeCBCEncryptor* cbcEncryptor = NULL; CAESEncryptor* aesEncryptor = NULL; CPaddingPKCS7* padding = NULL; - + LOGFN( "CWmDrmDataStore::WriteInitialFreeSpaceL" ); User::LeaveIfError( file.Create( iServer->Fs(), aFileName, EFileWrite ) ); CleanupClosePushL( file ); @@ -181,7 +181,7 @@ else { iInitialFreeSpace = iServer->FreeSpaceL( aConfiguredDrive ); - } + } iv.SetLength( KAESKeyLength ); TRandom::RandomL( iv ); #if defined(FF_PLATFORM_SIMULATOR) || defined(__WINSCW__) @@ -191,18 +191,18 @@ #endif aesEncryptor = CAESEncryptor::NewL( key ); CleanupStack::PushL( aesEncryptor ); - + cbcEncryptor = CModeCBCEncryptor::NewL( aesEncryptor, iv ); CleanupStack::Pop( aesEncryptor ); CleanupStack::PushL( cbcEncryptor ); - + padding = CPaddingPKCS7::NewL( KAESKeyLength ); CleanupStack::PushL( padding ); - + encryptor = CBufferedEncryptor::NewL( cbcEncryptor, padding ); CleanupStack::Pop( 2, cbcEncryptor ); //padding, cbcEncryptor CleanupStack::PushL( encryptor ); - + if ( aConfiguredDrive ) { decryptedData.AppendNum( iInitialFreeSpace2 ); @@ -210,8 +210,8 @@ else { decryptedData.AppendNum( iInitialFreeSpace ); - } - + } + encryptor->ProcessFinalL( decryptedData, encryptedData ); User::LeaveIfError( file.Write( iv ) ); User::LeaveIfError( file.Write( encryptedData ) ); @@ -228,25 +228,25 @@ TInt ratio( 0 ); TInt ratio2( 0 ); TBool internalMassDriveNotFull( ETrue ); - + LOGFN( "CWmDrmDataStore::DataStoreStateL" ); freeSpace = iServer->FreeSpaceL( EFalse ); - + if ( iWmDrmRightsConfigFound ) { // Check free space from the configured drive, too. freeSpace2 = iServer->FreeSpaceL( ETrue ); - - if ( freeSpace2 < iMinFreeSpace2 ) + + if ( freeSpace2 < iMinFreeSpace2 ) { internalMassDriveNotFull = EFalse; } - + dummyDbSize = DummyDBSizeL( ETrue ); dataStoreSize = DataStoreSizeL( ETrue ); ratio2 = dataStoreSize * 100 / iInitialFreeSpace2; freeSpace2 += dummyDbSize; -#ifdef _LOGGING +#ifdef _LOGGING TBuf free2; LOG1( "CWmDrmDataStore::DataStoreStateL: Free space (2): "); free2.AppendNumUC( freeSpace2, EDecimal ); @@ -255,15 +255,15 @@ LOG1( "CWmDrmDataStore::DataStoreStateL: Minimum free space (2): "); free2Min.AppendNumUC( iMinFreeSpace2, EDecimal ); LOG( free2Min ); -#endif +#endif } - - // Check the system drive storage space next. + + // Check the system drive storage space next. dummyDbSize = DummyDBSizeL( EFalse ); dataStoreSize = DataStoreSizeL( EFalse ); ratio = dataStoreSize * 100 / iInitialFreeSpace; freeSpace += dummyDbSize; -#ifdef _LOGGING +#ifdef _LOGGING TBuf free; LOG1( "CWmDrmDataStore::DataStoreStateL: Free space: "); free.AppendNumUC( freeSpace, EDecimal ); @@ -272,21 +272,21 @@ LOG1( "CWmDrmDataStore::DataStoreStateL: Minimum free space: "); freeMin.AppendNumUC( iMinFreeSpace, EDecimal ); LOG( freeMin ); -#endif - - // Select the state of the storage space. - if ( ( freeSpace > iMinFreeSpace ) && internalMassDriveNotFull ) +#endif + + // Select the state of the storage space. + if ( ( freeSpace > iMinFreeSpace ) && internalMassDriveNotFull ) { LOG1( "CWmDrmDataStore::DataStoreStateL: Store space Ok" ); state = EStoreSpaceOK; } else { - // The configured drive is running out of space. The system drive + // The configured drive is running out of space. The system drive // may also be running out of storage space, but calculate // the ratio of database size to initial free drive space and the // state of the drive storage space from the configured drive because - // it is likely to fill up faster since the media files may be synced to it. + // it is likely to fill up faster since the media files may be synced to it. if ( !internalMassDriveNotFull ) { LOG2( "Ratio (2): %d", ratio2 ); @@ -302,7 +302,7 @@ } } else - // Only the system drive is running out of storage space. + // Only the system drive is running out of storage space. { LOG2( "Ratio: %d", ratio ); if ( ratio <= iMaxSpaceRatio ) @@ -315,9 +315,9 @@ LOG1( "CWmDrmDataStore::DataStoreStateL Store space full" ); state = EStoreSpaceFull; } - } + } } - + LOG2( "DataStoreState: %d", state ); return state; } @@ -326,13 +326,13 @@ RFile& aDummyDb, TBool& aConfiguredDrive ) { TInt r( KErrNone ); - + LOGFN( "CWmDrmDataStore::InitializeDummyDbFileL" ); - + r = aDummyDb.Create( iServer->Fs(), aFileName, EFileWrite ); if ( r == KErrAlreadyExists ) { - User::LeaveIfError( + User::LeaveIfError( aDummyDb.Open( iServer->Fs(), aFileName, EFileWrite ) ); } else if( !r ) @@ -342,7 +342,7 @@ { if ( dataStoreSize <= iDummyDbInitialSize2 ) { - User::LeaveIfError( + User::LeaveIfError( aDummyDb.SetSize( iDummyDbInitialSize2 - dataStoreSize ) ); } else @@ -350,18 +350,18 @@ User::LeaveIfError( aDummyDb.SetSize( 0 ) ); } } - else + else { if ( dataStoreSize <= iDummyDbInitialSize ) { - User::LeaveIfError( + User::LeaveIfError( aDummyDb.SetSize( iDummyDbInitialSize - dataStoreSize ) ); } else { User::LeaveIfError( aDummyDb.SetSize( 0 ) ); } - } + } } else { @@ -379,26 +379,26 @@ LOG2( "dummyDbSize: %d", dummyDbSize ); if ( aSize <= dummyDbSize ) { - if ( aConfiguredDrive ) + if ( aConfiguredDrive ) { - User::LeaveIfError( iDummyDb2.SetSize( dummyDbSize - aSize ) ); - } + User::LeaveIfError( iDummyDb2.SetSize( dummyDbSize - aSize ) ); + } else - { - User::LeaveIfError( iDummyDb.SetSize( dummyDbSize - aSize ) ); - } - } + { + User::LeaveIfError( iDummyDb.SetSize( dummyDbSize - aSize ) ); + } + } else { if ( aConfiguredDrive ) - { - User::LeaveIfError( iDummyDb2.SetSize( 0 ) ); - } - else - { - User::LeaveIfError( iDummyDb.SetSize( 0 ) ); - } - } + { + User::LeaveIfError( iDummyDb2.SetSize( 0 ) ); + } + else + { + User::LeaveIfError( iDummyDb.SetSize( 0 ) ); + } + } } else { @@ -408,27 +408,27 @@ { if ( dataStoreSize <= iDummyDbInitialSize2 ) { - User::LeaveIfError( + User::LeaveIfError( iDummyDb2.SetSize( iDummyDbInitialSize2 - dataStoreSize ) ); - } - else - { - User::LeaveIfError( iDummyDb2.SetSize( 0 ) ); - } + } + else + { + User::LeaveIfError( iDummyDb2.SetSize( 0 ) ); + } } - else + else { if ( dataStoreSize <= iDummyDbInitialSize ) { - User::LeaveIfError( + User::LeaveIfError( iDummyDb.SetSize( iDummyDbInitialSize - dataStoreSize ) ); - } - else - { - User::LeaveIfError( iDummyDb.SetSize( 0 ) ); - } + } + else + { + User::LeaveIfError( iDummyDb.SetSize( 0 ) ); + } } - } + } } TInt CWmDrmDataStore::DataStoreSizeL( TBool aConfiguredDrive ) @@ -448,35 +448,35 @@ else { User::LeaveIfError( iDummyDb.Size( dummyDbSize ) ); - } + } return dummyDbSize; } -void CWmDrmDataStore::PrepareInfoFilesL( TBool aConfiguredDrive, +void CWmDrmDataStore::PrepareInfoFilesL( TBool aConfiguredDrive, TChar aDriveLetter, RFile& aDummyDb ) { LOGFN( "CWmDrmDataStore::PrepareInfoFilesL" ); CRepository* repository( NULL ); TInt r( KErrNone ); - TFileName dummyDbFile; + TFileName dummyDbFile; TFileName initialFreeSpaceFile; - + initialFreeSpaceFile.Format( KPrivateDir, (TUint)aDriveLetter ); iServer->Fs().MkDirAll( initialFreeSpaceFile ); initialFreeSpaceFile.Format( KInitialFreeSpaceFile, (TUint)aDriveLetter ); dummyDbFile.Format( KDummyDbFile, (TUint)aDriveLetter ); - - TRAP( r, WriteInitialFreeSpaceL( initialFreeSpaceFile, + + TRAP( r, WriteInitialFreeSpaceL( initialFreeSpaceFile, aConfiguredDrive ) ); if ( r ) { r = KErrNone; - + // catch the read error - TRAP( r, ReadInitialFreeSpaceL( initialFreeSpaceFile, + TRAP( r, ReadInitialFreeSpaceL( initialFreeSpaceFile, aConfiguredDrive ) ); - - // if an error occurs, this means that we are unable to read the info, + + // if an error occurs, this means that we are unable to read the info, // thus we need to delete the file and run write again. // hopefully this being a temporary error, but if we fail again we fail // until next ConstructL @@ -484,60 +484,60 @@ { // delete the file: iServer->Fs().Delete( initialFreeSpaceFile ); - + // Calc & Write the new info WriteInitialFreeSpaceL( initialFreeSpaceFile, aConfiguredDrive ); } } - + if ( aConfiguredDrive ) { -#ifdef _LOGGING +#ifdef _LOGGING TBuf freeSpace2; LOG1( "CWmDrmDataStore::DataStoreStateL: Initial free space (2): "); freeSpace2.AppendNumUC( iInitialFreeSpace2, EDecimal ); LOG( freeSpace2 ); -#endif +#endif if ( iInitialFreeSpace2 <= 0 ) { User::Leave( KErrNotReady ); } } - else + else { -#ifdef _LOGGING +#ifdef _LOGGING TBuf freeSpace; LOG1( "CWmDrmDataStore::DataStoreStateL: Initial free space: "); freeSpace.AppendNumUC( iInitialFreeSpace, EDecimal ); LOG( freeSpace ); -#endif +#endif if ( iInitialFreeSpace <= 0 ) { User::Leave( KErrNotReady ); } } - + //LOG1( "CWmDrmDataStore::PrepareInfoFilesL Check Cenrep" ); - + TRAP( r, repository = CRepository::NewL( KCRUidWMDRM ) ); if ( repository ) { TInt rate( 0 ); - + // Check the cenrep key parameters either for the default system drive // or for the internal mass drive depending whether the WMDRM rights // are configured to be partially stored to the internal mass drive or - // not. + // not. if ( !aConfiguredDrive ) - { + { r = repository->Get( KWMDRMLicStoreLowMem, rate ); if ( r ) { - iMinFreeSpace = KMegaByte; + iMinFreeSpace = KMegaByte; } else { - iMinFreeSpace = rate * KMegaByte; + iMinFreeSpace = rate * KMegaByte; } r = repository->Get( KWMDRMLicStoreSizeRatio, iMaxSpaceRatio ); if ( r ) @@ -547,19 +547,19 @@ r = repository->Get( KWMDRMLicStoreReservedSpace, rate ); if ( r ) { - iDummyDbInitialSize = KDummyDbInitialSize; + iDummyDbInitialSize = KDummyDbInitialSize; } else { - iDummyDbInitialSize = rate * KMegaByte; + iDummyDbInitialSize = rate * KMegaByte; } } - else + else { r = repository->Get( KWMDRM2LicStoreLowMem, rate ); if ( r ) { - iMinFreeSpace2 = KTwoHundredMegaBytes; + iMinFreeSpace2 = KTwoHundredMegaBytes; } else { @@ -573,31 +573,31 @@ r = repository->Get( KWMDRM2LicStoreReservedSpace, rate ); if ( r ) { - iDummyDbInitialSize2 = KDummyDbInitialSize; + iDummyDbInitialSize2 = KDummyDbInitialSize; } else { - iDummyDbInitialSize2 = rate * KMegaByte; + iDummyDbInitialSize2 = rate * KMegaByte; } - } + } delete repository; } else { if ( !aConfiguredDrive ) { - iMinFreeSpace = KMegaByte; + iMinFreeSpace = KMegaByte; iMaxSpaceRatio = KMaxSpaceRatio; iDummyDbInitialSize = KDummyDbInitialSize; } - else + else { - iMinFreeSpace2 = KTwoHundredMegaBytes; + iMinFreeSpace2 = KTwoHundredMegaBytes; iMaxSpaceRatio2 = KMaxSpaceRatio2; - iDummyDbInitialSize2 = KDummyDbInitialSize; + iDummyDbInitialSize2 = KDummyDbInitialSize; } } - + InitializeDummyDbFileL( dummyDbFile, aDummyDb, aConfiguredDrive ); - + }