--- a/omadrm/drmengine/server/src/DRMRightsData.cpp Fri Mar 12 15:43:46 2010 +0200
+++ b/omadrm/drmengine/server/src/DRMRightsData.cpp Mon Mar 15 12:41:43 2010 +0200
@@ -24,12 +24,12 @@
#include "DRMPointerArray.h"
#include "DRMCommonData.h"
-#include "DRMPermission.h"
+#include "DrmPermission.h"
#include "DRMRightsData.h"
// EXTERNAL DATA STRUCTURES
-// EXTERNAL FUNCTION PROTOTYPES
+// EXTERNAL FUNCTION PROTOTYPES
// CONSTANTS
const TInt KEncryptionKeySize = 16;
@@ -44,16 +44,16 @@
// FORWARD DECLARATIONS
-class TPermData
+class TPermData
{
public: // Constructor
TPermData( HBufC8* aParentId, const TInt aIndex, TBool aIsValid ) :
iParentId( aParentId ),
iIndex( aIndex ),
iIsValid( aIsValid ) { };
-
- public: // Member variables
- HBufC8* iParentId;
+
+ public: // Member variables
+ HBufC8* iParentId;
TInt iIndex;
TBool iIsValid;
};
@@ -67,7 +67,7 @@
// -----------------------------------------------------------------------------
//
CDRMRightsData* CDRMRightsData::NewLC( CDRMCommonData* aData,
- const TDesC8& aKey,
+ const TDesC8& aKey,
const TFileName& aRightsFile,
RFs& aFileServer )
{
@@ -75,24 +75,24 @@
CleanupStack::PushL( self );
self->ConstructL( aRightsFile, aKey );
- return self;
+ return self;
};
-
+
// -----------------------------------------------------------------------------
// CDRMRightsData::NewL
// -----------------------------------------------------------------------------
//
-CDRMRightsData* CDRMRightsData::NewL( CDRMCommonData* aData,
+CDRMRightsData* CDRMRightsData::NewL( CDRMCommonData* aData,
const TDesC8& aKey,
const TFileName& aRightsFile,
RFs& aFileServer )
{
CDRMRightsData* self = NewLC( aData, aKey, aRightsFile, aFileServer );
- CleanupStack::Pop();
-
- return self;
+ CleanupStack::Pop();
+
+ return self;
};
-
+
// -----------------------------------------------------------------------------
// CDRMRightsData::OpenLC
// -----------------------------------------------------------------------------
@@ -103,12 +103,12 @@
CDRMCommonData* common = CDRMCommonData::NewL();
CDRMRightsData* self = new( ELeave ) CDRMRightsData( common, aFileServer );
- CleanupStack::PushL( self );
+ CleanupStack::PushL( self );
self->ConstructL( aRightsFile );
-
+
return self;
- };
-
+ };
+
// -----------------------------------------------------------------------------
// CDRMRightsData::OpenL
// -----------------------------------------------------------------------------
@@ -118,14 +118,14 @@
{
CDRMRightsData* self = OpenLC( aRightsFile, aFileServer );
CleanupStack::Pop();
-
- return self;
- };
-
+
+ return self;
+ };
+
// -----------------------------------------------------------------------------
// Destructor
// -----------------------------------------------------------------------------
-//
+//
CDRMRightsData::~CDRMRightsData()
{
// Permanent File Store
@@ -134,17 +134,17 @@
delete iStore;
iStore = NULL;
}
-
- // index array
+
+ // index array
iArray.Close();
-
+
// Common Data
if( iData )
{
delete iData;
iData = NULL;
}
- };
+ };
// -----------------------------------------------------------------------------
@@ -169,35 +169,35 @@
{
User::Leave( KErrArgument );
}
-
- // Open the stream
+
+ // Open the stream
stream.ReplaceLC( *iStore, iCommonId );
-
+
// Delete the old data if it's around
// if the old data has been modified, write it as such
if( iData != aData )
- {
+ {
if( iData )
- {
- delete iData;
- iData = NULL;
- }
- iData = aData;
+ {
+ delete iData;
+ iData = NULL;
+ }
+ iData = aData;
}
-
+
// Write the data to the stream
iData->ExternalizeL( stream );
-
+
// commit the stream
stream.CommitL();
-
+
// commit the store
iStore->CommitL();
-
+
// pop the stream
CleanupStack::PopAndDestroy();
- };
-
+ };
+
// -----------------------------------------------------------------------------
// CDRMRightsData::StoreNewPermissionL
// -----------------------------------------------------------------------------
@@ -209,40 +209,40 @@
TStreamId rootId;
RStoreWriteStream stream;
RStoreWriteStream rootStream;
-
+
// Create a new stream to the store:
sid = stream.CreateLC( *iStore );
-
- aPermission.iUniqueID = sid.Value();
+
+ aPermission.iUniqueID = sid.Value();
aStream = sid.Value();
-
+
// Externalize the permission data
aPermission.ExternalizeL( stream );
stream.CommitL();
-
+
// add the id to the array
iArray.InsertInUnsignedKeyOrder( aStream );
// Get the stream id of the root
rootId = iStore->Root();
-
+
// Open the root stream
rootStream.ReplaceLC( *iStore, rootId );
-
+
// Store the changed index
- StoreIndexL( rootStream );
+ StoreIndexL( rootStream );
rootStream.CommitL();
// Commit the store
iStore->CommitL();
-
+
CleanupStack::PopAndDestroy(); // root stream
CleanupStack::PopAndDestroy(); // stream
-
+
iStore->CompactL();
iStore->CommitL();
- };
-
+ };
+
// -----------------------------------------------------------------------------
// CDRMRightsData::UpdatePermissionL
// -----------------------------------------------------------------------------
@@ -252,30 +252,30 @@
TStreamId sid( aPermission.iUniqueID );
RStoreWriteStream stream;
TInt index = 0;
-
+
// get the id from the array if it doesn't exist, error
index = iArray.FindInUnsignedKeyOrder( aPermission.iUniqueID );
-
+
if( index == KErrNotFound )
{
User::Leave( KErrCANoPermission );
}
-
+
// Replace the existing stream
stream.ReplaceLC( *iStore, sid );
-
+
// Externalize the permission data
aPermission.ExternalizeL( stream );
-
+
// Required by the ReplaceLC
stream.CommitL();
- // Commit the store
+ // Commit the store
iStore->CommitL();
-
+
CleanupStack::PopAndDestroy();
};
-
+
// -----------------------------------------------------------------------------
// CDRMRightsData::FetchPermissionL
// -----------------------------------------------------------------------------
@@ -283,28 +283,28 @@
void CDRMRightsData::FetchPermissionL( CDRMPermission& aPermission,
const TDRMUniqueID& aStream ) const
{
- TStreamId sid( aStream );
+ TStreamId sid( aStream );
RStoreReadStream stream;
TInt index = 0;
// get the id from the array if it doesn't exist, error
index = iArray.FindInUnsignedKeyOrder( aStream );
-
+
if( index == KErrNotFound )
{
User::Leave( KErrCANoPermission );
}
-
+
// Open the root stream
stream.OpenLC( *iStore, sid );
// Read the common id
aPermission.InternalizeL( stream );
-
+
// Close the stream
- CleanupStack::PopAndDestroy();
+ CleanupStack::PopAndDestroy();
};
-
+
// -----------------------------------------------------------------------------
// CDRMRightsData::DeletePermissionL
// -----------------------------------------------------------------------------
@@ -315,10 +315,10 @@
TStreamId rootId;
TInt index = 0;
RStoreWriteStream rootStream;
-
+
// get the id from the array if it doesn't exist, error
index = iArray.FindInUnsignedKeyOrder( aStream );
-
+
if( index == KErrNotFound )
{
User::Leave( KErrCANoPermission );
@@ -326,52 +326,52 @@
// Delete the stream from the store
iStore->DeleteL( sid );
-
- iArray.Remove( index );
-
-
+
+ iArray.Remove( index );
+
+
// Get the stream id of the root
rootId = iStore->Root();
-
+
// Open the root stream
rootStream.ReplaceLC( *iStore, rootId );
-
+
// Store the changed index
- StoreIndexL( rootStream );
+ StoreIndexL( rootStream );
rootStream.CommitL();
// Commit the store
iStore->CommitL();
-
+
CleanupStack::PopAndDestroy(); // root stream
-
+
// Compact and commit the changes
iStore->CompactL();
- iStore->CommitL();
+ iStore->CommitL();
};
-
+
// -----------------------------------------------------------------------------
// CDRMRightsData::FetchAllPermissionsL
// -----------------------------------------------------------------------------
//
-void CDRMRightsData::FetchAllPermissionsL( RPointerArray<CDRMPermission>&
+void CDRMRightsData::FetchAllPermissionsL( RPointerArray<CDRMPermission>&
aPointerArray)
{
CDRMPermission* perm = NULL;
- if ( iArray.Count() == 0)
+ if ( iArray.Count() == 0)
{
User::Leave( KErrCANoPermission );
}
-
+
for( TInt count = 0; count < iArray.Count(); count++ )
{
perm = CDRMPermission::NewLC();
FetchPermissionL( *perm, iArray[ count ] );
aPointerArray.AppendL( perm );
- CleanupStack::Pop();
+ CleanupStack::Pop();
}
- };
+ };
// -----------------------------------------------------------------------------
// CDRMRightsData::DeleteAllPermissionsL
@@ -381,35 +381,35 @@
{
TStreamId rootId;
RStoreWriteStream rootStream;
-
+
// Delete all permissions from the store
for( TInt i = 0; i < iArray.Count(); i++ )
{
TStreamId sid( iArray[i] );
iStore->DeleteL( sid );
}
-
- // Reset the array
+
+ // Reset the array
iArray.Reset();
-
+
// Get the stream id of the root
rootId = iStore->Root();
-
+
// Open the root stream
rootStream.ReplaceLC( *iStore, rootId );
-
+
// Store the changed index
- StoreIndexL( rootStream );
+ StoreIndexL( rootStream );
rootStream.CommitL();
// Commit the store
iStore->CommitL();
-
+
CleanupStack::PopAndDestroy(); // root stream
-
+
// Compact and Commit the store
iStore->CompactL();
- iStore->CommitL();
+ iStore->CommitL();
};
// -----------------------------------------------------------------------------
@@ -420,21 +420,21 @@
// -----------------------------------------------------------------------------
//
TInt CDRMRightsData::DeleteExpiredPermissionsL( const TTime& aTime, TBool& aParents )
- {
- CDRMPermission* permission = NULL;
- RStoreReadStream stream;
+ {
+ CDRMPermission* permission = NULL;
+ RStoreReadStream stream;
TStreamId rootId;
RStoreWriteStream rootStream;
TBool remove = EFalse;
TInt k = 0;
TBool performDelete = ETrue;
-
+
// A list for the permissions:
CDRMPointerArray<CDRMPermission>* permList = CDRMPointerArray<CDRMPermission>::NewLC();
permList->SetAutoCleanup( ETrue );
CDRMPointerArray<TPermData>* permDataList = CDRMPointerArray<TPermData>::NewLC();
permDataList->SetAutoCleanup( ETrue );
-
+
// Fill the array:
for( TInt j = 0 ; j < iArray.Count(); j++ )
{
@@ -442,27 +442,27 @@
// Create the sid:
TStreamId psid( iArray[j] );
- // Open the correct stream
- stream.OpenLC( *iStore, psid );
+ // Open the correct stream
+ stream.OpenLC( *iStore, psid );
- permission = CDRMPermission::NewLC();
+ permission = CDRMPermission::NewLC();
- // Read the permission
- permission->InternalizeL( stream );
-
+ // Read the permission
+ permission->InternalizeL( stream );
+
permList->AppendL( permission );
- CleanupStack::Pop(); // permission
-
+ CleanupStack::Pop(); // permission
+
// if the permission has a parent check if we found now or have found an
// expired one or a valid one,
- // store info if required
+ // store info if required
if( permission->iParentUID )
{
- if( !aParents )
+ if( !aParents )
{
aParents = ETrue;
}
-
+
for( k = 0; k < permDataList->Count(); k++ )
{
if( !(*permDataList)[k]->iParentId->Compare( *permission->iParentUID ) )
@@ -476,7 +476,7 @@
break;
}
}
-
+
// if it's not found, add it:
if( k == permDataList->Count() )
{
@@ -484,99 +484,99 @@
{
perm = new(ELeave) TPermData( permission->iParentUID, j, ETrue);
}
- else
+ else
{
- perm = new(ELeave) TPermData( permission->iParentUID, j, EFalse);
+ perm = new(ELeave) TPermData( permission->iParentUID, j, EFalse);
}
CleanupStack::PushL( perm );
permDataList->AppendL( perm );
- CleanupStack::Pop(); // perm
+ CleanupStack::Pop(); // perm
}
}
-
+
// Close the stream
- CleanupStack::PopAndDestroy(); // stream
+ CleanupStack::PopAndDestroy(); // stream
}
-
+
// Delete all expired permissions from the store
for( TInt i = iArray.Count() - 1 ; i >= 0; i-- )
{
permission = (*permList)[i];
-
- // Check if the permission is expired
- // if it is, check if it has a parent and if it can be deleted
- if( permission->Expired( aTime ) )
- {
- // if it has a parent go through the list and see if this can be deleted
- // or not
- if( permission->iParentUID )
- {
- performDelete = EFalse;
- for( k = 0; k < permDataList->Count(); k++ )
- {
- TPermData* aData = (*permDataList)[k];
-
- // since it's set up like this a pointer comparison is enough:
- if( !(*permDataList)[k]->iParentId->Compare( *permission->iParentUID ) )
- {
- if( i != (*permDataList)[k]->iIndex )
- {
- performDelete = ETrue;
- }
- }
- }
- }
-
- if( performDelete )
- {
+
+ // Check if the permission is expired
+ // if it is, check if it has a parent and if it can be deleted
+ if( permission->Expired( aTime ) )
+ {
+ // if it has a parent go through the list and see if this can be deleted
+ // or not
+ if( permission->iParentUID )
+ {
+ performDelete = EFalse;
+ for( k = 0; k < permDataList->Count(); k++ )
+ {
+ TPermData* aData = (*permDataList)[k];
+
+ // since it's set up like this a pointer comparison is enough:
+ if( !(*permDataList)[k]->iParentId->Compare( *permission->iParentUID ) )
+ {
+ if( i != (*permDataList)[k]->iIndex )
+ {
+ performDelete = ETrue;
+ }
+ }
+ }
+ }
+
+ if( performDelete )
+ {
// Create the sid:
TStreamId sid( iArray[i] );
-
- iStore->Delete( sid );
-
- // remove from the array
- iArray.Remove( i );
-
- if( !remove )
- {
- remove = ETrue;
- }
- }
- }
- performDelete = ETrue;
+
+ iStore->Delete( sid );
+
+ // remove from the array
+ iArray.Remove( i );
+
+ if( !remove )
+ {
+ remove = ETrue;
+ }
+ }
+ }
+ performDelete = ETrue;
}
- CleanupStack::PopAndDestroy( 2 ); // permDataList, permList
-
- // Write the data into the the file
+ CleanupStack::PopAndDestroy( 2 ); // permDataList, permList
+
+ // Write the data into the the file
// if some of the rights have been removed
- if( remove )
+ if( remove )
{
// Get the stream id of the root
rootId = iStore->Root();
-
+
// Open the root stream
rootStream.ReplaceLC( *iStore, rootId );
-
+
// Store the changed index
- StoreIndexL( rootStream );
+ StoreIndexL( rootStream );
rootStream.CommitL();
// Commit the store
iStore->CommitL();
-
+
CleanupStack::PopAndDestroy(); // root stream
-
+
// Compact and Commit the store
iStore->CompactL();
- iStore->CommitL();
+ iStore->CommitL();
}
-
- return iArray.Count();
- }
-
+ return iArray.Count();
+ }
+
+
// -----------------------------------------------------------------------------
// CDRMRightsData::StoreKeyL
// -----------------------------------------------------------------------------
@@ -585,24 +585,24 @@
{
RStoreWriteStream stream;
TUint32 size = 0;
-
+
stream.OpenLC( *iStore, iKeyId );
-
- if( iKeyExists )
+
+ if( iKeyExists )
{
size = KEncryptionKeySize;
}
-
- stream.WriteUint32L( size );
-
+
+ stream.WriteUint32L( size );
+
if( size )
{
- stream.WriteL( iKey, KEncryptionKeySize );
+ stream.WriteL( iKey, KEncryptionKeySize );
}
-
+
stream.CommitL();
iStore->CommitL();
-
+
CleanupStack::PopAndDestroy();
};
@@ -613,16 +613,16 @@
HBufC8* CDRMRightsData::GetKeyL() const
{
HBufC8* key = NULL;
-
+
if( iKeyExists )
{
key = HBufC8::NewL( KEncryptionKeySize );
*key = iKey;
}
-
+
return key;
}
-
+
// -----------------------------------------------------------------------------
// CDRMRightsData::FetchKeyL
// -----------------------------------------------------------------------------
@@ -631,23 +631,23 @@
{
RStoreReadStream stream;
TUint32 size = 0;
-
+
// Open the root stream
stream.OpenLC( *iStore, iKeyId );
-
- size = stream.ReadUint32L();
-
- if( !size )
+
+ size = stream.ReadUint32L();
+
+ if( !size )
{
iKeyExists = EFalse;
}
- else
+ else
{
stream.ReadL( iKey, KEncryptionKeySize );
iKeyExists = ETrue;
}
-
- CleanupStack::PopAndDestroy();
+
+ CleanupStack::PopAndDestroy();
};
// -----------------------------------------------------------------------------
@@ -658,35 +658,35 @@
{
TStreamId rootId;
RStoreWriteStream stream;
- RStoreWriteStream stream2;
+ RStoreWriteStream stream2;
RStoreWriteStream rootStream;
- TUint32 size = 0;
-
+ TUint32 size = 0;
+
// Create and initialize the permanent file store
iStore = CPermanentFileStore::ReplaceL( iFileServer, aRightsStore,
- EFileRead|EFileWrite );
+ EFileRead|EFileWrite );
iStore->SetTypeL( KPermanentFileStoreLayoutUid );
- iStore->CommitL();
-
- // Create the root stream:
+ iStore->CommitL();
+
+ // Create the root stream:
rootId = rootStream.CreateLC( *iStore );
rootStream.CommitL();
- iStore->SetRootL( rootId );
- iStore->CommitL();
-
+ iStore->SetRootL( rootId );
+ iStore->CommitL();
+
// Create the common data
iCommonId = stream.CreateLC( *iStore );
iData->ExternalizeL( stream );
stream.CommitL();
- iStore->CommitL();
-
+ iStore->CommitL();
+
CleanupStack::PopAndDestroy(); // stream
-
+
// Create the key
iKeyId = stream2.CreateLC( *iStore );
// if the key exists set the key size accordingly
- if( iKeyExists )
+ if( iKeyExists )
{
size = KEncryptionKeySize;
}
@@ -697,21 +697,21 @@
stream2.WriteL( iKey, KEncryptionKeySize );
}
stream2.CommitL();
- iStore->CommitL();
-
- CleanupStack::PopAndDestroy(); // stream2
- CleanupStack::PopAndDestroy(); // rootStream
-
+ iStore->CommitL();
+
+ CleanupStack::PopAndDestroy(); // stream2
+ CleanupStack::PopAndDestroy(); // rootStream
+
// Create the index now that we have all the data
- rootId = iStore->Root();
-
+ rootId = iStore->Root();
+
rootStream.ReplaceLC(*iStore, rootId);
StoreIndexL( rootStream );
rootStream.CommitL();
- iStore->CommitL();
-
+ iStore->CommitL();
+
// Commit the changes to the store as well
- CleanupStack::PopAndDestroy(); // rootStream
+ CleanupStack::PopAndDestroy(); // rootStream
};
@@ -723,19 +723,19 @@
{
// Write the common id to the stream
iCommonId.ExternalizeL( aStream );
-
+
// Write the key id to the stream
iKeyId.ExternalizeL( aStream );
-
+
// Write the array size and possibly the array to the stream
aStream.WriteInt32L( iArray.Count() );
-
+
for( TInt count = 0; count < iArray.Count(); count++ )
{
aStream.WriteUint32L( iArray[ count ] );
}
};
-
+
// -----------------------------------------------------------------------------
// CDRMRightsData::FetchIndexL
// -----------------------------------------------------------------------------
@@ -746,36 +746,36 @@
RStoreReadStream stream;
TInt count = 0;
TDRMUniqueID id;
-
+
// Get the stream id of the root
rootId = iStore->Root();
-
+
// Open the root stream
stream.OpenLC( *iStore, rootId );
-
+
// Do the actual reading, reading also the key id and the common id
// Read the common id
iCommonId.InternalizeL( stream );
-
- // Read the key id
+
+ // Read the key id
iKeyId.InternalizeL( stream );
-
+
// read the count of the array:
iArray.Reset();
-
+
count = stream.ReadInt32L();
-
+
for( ; count > 0; count-- )
{
id = stream.ReadUint32L();
iArray.InsertInUnsignedKeyOrder( id );
}
-
+
// Close the stream
- CleanupStack::PopAndDestroy();
+ CleanupStack::PopAndDestroy();
};
-
+
// -----------------------------------------------------------------------------
// CDRMRightsData::FetchCommonDataL
// -----------------------------------------------------------------------------
@@ -783,15 +783,15 @@
void CDRMRightsData::FetchCommonDataL()
{
RStoreReadStream stream;
-
+
// Open the root stream
stream.OpenLC( *iStore, iCommonId );
-
+
iData->InternalizeL( stream );
-
+
CleanupStack::PopAndDestroy();
};
-
+
// -----------------------------------------------------------------------------
// Default Constructor - First phase.
@@ -811,13 +811,13 @@
{
// Open the file store
iStore = CPermanentFileStore::OpenL( iFileServer, aRightsStore, EFileRead|EFileWrite );
-
+
// Get the index
FetchIndexL();
-
+
// Get the common data
FetchCommonDataL();
-
+
// Get the key
FetchKeyL();
};
@@ -829,9 +829,9 @@
void CDRMRightsData::ConstructL( const TFileName& aRightsStore,
const TDesC8& aKey )
{
-
+
// Check if the key is given or a null desc
- if( aKey.Length() )
+ if( aKey.Length() )
{
iKey = aKey;
iKeyExists = ETrue;
@@ -839,11 +839,11 @@
else
{
iKeyExists = EFalse;
- }
-
+ }
+
// Creates the required stores and indexes
CreateAndInitializeStoreL( aRightsStore );
};
-
-
+
+
// End of File