diff -r 04da681812a9 -r 457cd4423b8c omadrm/drmengine/server/src/drmrightsdb.cpp --- a/omadrm/drmengine/server/src/drmrightsdb.cpp Tue Apr 27 16:56:11 2010 +0300 +++ b/omadrm/drmengine/server/src/drmrightsdb.cpp Tue May 11 16:28:38 2010 +0300 @@ -22,6 +22,7 @@ #include // Type definitions #include // MD5 Algorithm // #include // Disk space checking +#include // Feature Manager #include #include #include @@ -69,8 +70,10 @@ // LOCAL CONSTANTS AND MACROS #ifdef RD_MULTIPLE_DRIVE // Backup Directory +#ifdef __DRM_OMA2 _LIT( KBackupDir, "%c:\\private\\101F51F2\\backup\\" ); #endif +#endif _LIT(KJavaExtension, ".jar"); @@ -89,16 +92,8 @@ _LIT(KCorruptionFlagFile, "invalid"); #ifdef __DRM_OMA2 -const TInt KMaxUDTDataSize = 256; -const TInt KDeviceDataSize = 256; const TInt KDeviceDataBlock = 128; -#else -const TInt KMaxUDTDataSize = 0; -const TInt KDeviceDataSize = 0; -const TInt KDeviceDataBlock = 0; #endif -const TInt KUdtDataPos = 4 + KDeviceDataSize; - const TInt KEncryptionKeySize = 16; const TInt KMaxEncryptionSize = 8192; @@ -111,8 +106,10 @@ // MODULE DATA STRUCTURES // LOCAL FUNCTION PROTOTYPES +#ifdef __DRM_OMA2 LOCAL_C void CleanupData( TAny* aPtr ); LOCAL_C void WriteIntToBlock( TInt aValue, TDes8& aBlock, TInt aOffset ); +#endif LOCAL_C void DeleteObject( TAny* aObject ); // FORWARD DECLARATIONS @@ -124,6 +121,7 @@ // Used to catch errors and delete the file if it's needed // ----------------------------------------------------------------------------- // +#ifdef __DRM_OMA2 LOCAL_C void CleanupData( TAny* aPtr ) { CDRMRightsDB* rdb = reinterpret_cast( aPtr ); @@ -139,7 +137,7 @@ aBlock[aOffset + 2] = (aValue & 0x0000ff00) >> 8; aBlock[aOffset + 3] = (aValue & 0x000000ff); } - +#endif // ---------------------------------------------------------------------------- // DeleteObject // Deletes the file by TFileName presented by aHandle @@ -205,6 +203,9 @@ } InitializeDatabaseL(); + + FeatureManager::InitializeLibL(); + }; // ----------------------------------------------------------------------------- @@ -268,6 +269,8 @@ } iMemStream.Close(); + + FeatureManager::UnInitializeLib(); DRMLOG( _L( "RDB Closing." ) ); }; @@ -1080,6 +1083,16 @@ HBufC8* CDRMRightsDB::GetUdtDataLC() { #ifdef __DRM_OMA2 + + if ( ! ( FeatureManager::FeatureSupported( KFeatureIdFfOmadrm2Support ) ) ) + { + User::Leave( KErrNotSupported ); + } + + const TInt KMaxUDTDataSize( 256 ); + const TInt KDeviceDataSize( 256 ); + const TInt KUdtDataPos = 4 + KDeviceDataSize; + HBufC8* udtData = HBufC8::NewMaxLC( KMaxUDTDataSize ); TFileName backupFile; RFile input; @@ -1135,6 +1148,12 @@ #endif // __DRM_OMA2 { #ifdef __DRM_OMA2 + + if ( ! ( FeatureManager::FeatureSupported( KFeatureIdFfOmadrm2Support ) ) ) + { + User::Leave( KErrNotSupported ); + } + TFileName backupFile; RFile input; HBufC8* keyData = NULL; @@ -1370,7 +1389,10 @@ stream.WriteInt32L( fileSize ); #ifdef __DRM_OMA2 - AddUDTDataL( stream ); + if ( FeatureManager::FeatureSupported ( KFeatureIdFfOmadrm2Support ) ) + { + AddUDTDataL( stream ); + } #endif encIV.SetLength(KEncryptionKeySize); @@ -1617,13 +1639,20 @@ // void CDRMRightsDB::RestoreContentFromFileL( RFile& aBackupFile, const TDesC8& aEncryptionKey, - const TInt aMode ) + const TInt aMode ) { + // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreContentFromFileL\n\r")); TInt8 continueMarker = 1; TBuf8<16> key; TBuf8<16> encryptionKey; TInt permissions = 0; + + // Default values when OMA2 DRM is not supported + TInt maxUDTDataSize( 0 ); + TInt deviceDataSize( 0 ); + TInt udtDataPos( 4 + deviceDataSize ); + CDRMPermission* permission = CDRMPermission::NewLC(); CDRMCommonData *commonData = NULL; CDRMPointerArray *permissionArray = CDRMPointerArray::NewLC(); @@ -1634,11 +1663,19 @@ TInt size = 0; TInt dataLeft = 0; TPtr8 keyData(NULL,0,0); - + +#ifdef __DRM_OMA2 + if ( FeatureManager::FeatureSupported( KFeatureIdFfOmadrm2Support ) ) + { + maxUDTDataSize = 256; + deviceDataSize = 256; + udtDataPos = 4 + deviceDataSize; + } +#endif + // maintain knowledge about stateful rights not being restored TBool stateful = EFalse; - DRMLOG( _L( "CDRMRightsDB::RestoreContentFromFileL ->" ) ); // Indicate that the DB is updated @@ -1686,7 +1723,7 @@ // Check that the decryption works, if it doesn't then the // key is faulty User::LeaveIfError( aBackupFile.Size( readPos ) ); - if( readPos < KUdtDataPos+KMaxUDTDataSize+(KEncryptionKeySize*2) ) + if( readPos < udtDataPos+maxUDTDataSize+(KEncryptionKeySize*2) ) { // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreContentFromFileL : corrupt\n\r")); User::Leave(KErrCorrupt); @@ -1715,7 +1752,7 @@ //----------------------------------------------------------------------- // Duplicate file handle - readPos = KUdtDataPos+KMaxUDTDataSize; + readPos = udtDataPos+maxUDTDataSize; User::LeaveIfError( fileHandle.Seek( ESeekStart, readPos ) ); iMemStream.Close(); @@ -1812,7 +1849,6 @@ } } - // Encrypt the key if( keyExists ) { @@ -1878,9 +1914,6 @@ User::Leave( KErrGeneral ); } - - - if( insertPerm == -1 ) // Add everything no checks needed { for( TInt count = 0; count < permissions; count++ ) @@ -1937,7 +1970,6 @@ } - for( TInt count = 0; count < permissions; count++ ) { if( dataLeft < 4 ) @@ -2034,6 +2066,7 @@ { User::Leave( KErrPermissionDenied ); } + }; @@ -2187,6 +2220,13 @@ #endif // __DRM_OMA2 { #ifdef __DRM_OMA2 + + if ( ! ( FeatureManager::FeatureSupported( KFeatureIdFfOmadrm2Support ) ) ) + { + User::Leave( KErrNotSupported ); + } + + const TInt KMaxUDTDataSize( 256 ); TBuf8 serialNumber; TBuf8 buffer; TUint8* ptr = const_cast(buffer.Ptr()); @@ -2357,6 +2397,12 @@ void CDRMRightsDB::CreateDummyUDTFileL() { #ifdef __DRM_OMA2 + + if ( ! ( FeatureManager::FeatureSupported( KFeatureIdFfOmadrm2Support ) ) ) + { + User::Leave( KErrNotSupported ); + } + TFileName backupFile; RFile input; TInt fileSize = 4 + 256 + 256; @@ -2386,6 +2432,12 @@ void CDRMRightsDB::CleanUdtData() { #ifdef __DRM_OMA2 + + if ( ! ( FeatureManager::FeatureSupported( KFeatureIdFfOmadrm2Support ) ) ) + { + return; + } + TFileName backupFile; #ifndef RD_MULTIPLE_DRIVE