--- a/omadrm/drmengine/server/src/drmrightsdb.cpp Tue Aug 31 15:29:38 2010 +0300
+++ b/omadrm/drmengine/server/src/drmrightsdb.cpp Wed Sep 01 12:21:16 2010 +0100
@@ -22,6 +22,7 @@
#include <e32def.h> // Type definitions
#include <hash.h> // MD5 Algorithm
// #include <SysUtil.h> // Disk space checking
+#include <featmgr.h> // Feature Manager
#include <f32file.h>
#include <s32strm.h>
#include <s32file.h>
@@ -70,8 +71,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");
@@ -90,16 +93,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;
@@ -112,8 +107,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
@@ -125,6 +122,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<CDRMRightsDB*>( aPtr );
@@ -140,7 +138,7 @@
aBlock[aOffset + 2] = (aValue & 0x0000ff00) >> 8;
aBlock[aOffset + 3] = (aValue & 0x000000ff);
}
-
+#endif
// ----------------------------------------------------------------------------
// DeleteObject
// Deletes the file by TFileName presented by aHandle
@@ -207,6 +205,9 @@
}
InitializeDatabaseL();
+
+ FeatureManager::InitializeLibL();
+
};
// -----------------------------------------------------------------------------
@@ -272,6 +273,8 @@
}
iMemStream.Close();
+
+ FeatureManager::UnInitializeLib();
DRMLOG( _L( "RDB Closing." ) );
};
@@ -1155,6 +1158,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;
@@ -1210,6 +1223,12 @@
#endif // __DRM_OMA2
{
#ifdef __DRM_OMA2
+
+ if ( ! ( FeatureManager::FeatureSupported( KFeatureIdFfOmadrm2Support ) ) )
+ {
+ User::Leave( KErrNotSupported );
+ }
+
TFileName backupFile;
RFile input;
HBufC8* keyData = NULL;
@@ -1445,7 +1464,10 @@
stream.WriteInt32L( fileSize );
#ifdef __DRM_OMA2
- AddUDTDataL( stream );
+ if ( FeatureManager::FeatureSupported ( KFeatureIdFfOmadrm2Support ) )
+ {
+ AddUDTDataL( stream );
+ }
#endif
encIV.SetLength(KEncryptionKeySize);
@@ -1692,13 +1714,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<CDRMPermission> *permissionArray = CDRMPointerArray<CDRMPermission>::NewLC();
@@ -1709,11 +1738,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
@@ -1761,7 +1798,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);
@@ -1790,7 +1827,7 @@
//-----------------------------------------------------------------------
// Duplicate file handle
- readPos = KUdtDataPos+KMaxUDTDataSize;
+ readPos = udtDataPos+maxUDTDataSize;
User::LeaveIfError( fileHandle.Seek( ESeekStart, readPos ) );
iMemStream.Close();
@@ -1887,7 +1924,6 @@
}
}
-
// Encrypt the key
if( keyExists )
{
@@ -1953,9 +1989,6 @@
User::Leave( KErrGeneral );
}
-
-
-
if( insertPerm == -1 ) // Add everything no checks needed
{
for( TInt count = 0; count < permissions; count++ )
@@ -2012,7 +2045,6 @@
}
-
for( TInt count = 0; count < permissions; count++ )
{
if( dataLeft < 4 )
@@ -2109,6 +2141,7 @@
{
User::Leave( KErrPermissionDenied );
}
+
};
@@ -2262,6 +2295,13 @@
#endif // __DRM_OMA2
{
#ifdef __DRM_OMA2
+
+ if ( ! ( FeatureManager::FeatureSupported( KFeatureIdFfOmadrm2Support ) ) )
+ {
+ User::Leave( KErrNotSupported );
+ }
+
+ const TInt KMaxUDTDataSize( 256 );
TBuf8<MDrmKeyStorage::KRdbSerialNumberLength> serialNumber;
TBuf8<KMaxUDTDataSize> buffer;
TUint8* ptr = const_cast<TUint8*>(buffer.Ptr());
@@ -2432,6 +2472,12 @@
void CDRMRightsDB::CreateDummyUDTFileL()
{
#ifdef __DRM_OMA2
+
+ if ( ! ( FeatureManager::FeatureSupported( KFeatureIdFfOmadrm2Support ) ) )
+ {
+ User::Leave( KErrNotSupported );
+ }
+
TFileName backupFile;
RFile input;
TInt fileSize = 4 + 256 + 256;
@@ -2461,6 +2507,12 @@
void CDRMRightsDB::CleanUdtData()
{
#ifdef __DRM_OMA2
+
+ if ( ! ( FeatureManager::FeatureSupported( KFeatureIdFfOmadrm2Support ) ) )
+ {
+ return;
+ }
+
TFileName backupFile;
#ifndef RD_MULTIPLE_DRIVE