omadrm/drmengine/server/src/drmrightsdb.cpp
branchRCL_3
changeset 55 ad2863178d17
parent 32 457cd4423b8c
child 71 1221b68b8a5f
--- a/omadrm/drmengine/server/src/drmrightsdb.cpp	Wed Jun 09 09:59:43 2010 +0300
+++ b/omadrm/drmengine/server/src/drmrightsdb.cpp	Mon Jun 21 15:58:55 2010 +0300
@@ -46,6 +46,7 @@
 #include "DrmKeyStorage.h"
 #include "utf.h" // charconv, ConvertFromUnicodeToUtf8L
 #include "drmlog.h"
+#include "DRMRightsServer.h"
 
 #ifdef RD_DRM_RIGHTS_MANAGER_REMOVAL
 #include "DRMClockClient.h"
@@ -159,10 +160,11 @@
 // might leave.
 // -----------------------------------------------------------------------------
 //
-CDRMRightsDB::CDRMRightsDB( RFs& aFs ) :
+CDRMRightsDB::CDRMRightsDB( RFs& aFs, CDRMRightsServer* aServer ) :
     iFileServer( aFs ),
     iImei( NULL ),
-    iLastUpdate( Time::NullTTime() )
+    iLastUpdate( Time::NullTTime() ),
+    iRightsServer( aServer )    
     {
     };
 
@@ -216,9 +218,10 @@
 CDRMRightsDB* CDRMRightsDB::NewLC( RFs& aFs,
                                    const TDesC& aDatabasePath,
                                    const TDesC8& aKey,
-                                   const TDesC& aImei )
+                                   const TDesC& aImei,
+                                   CDRMRightsServer* aServer )
     {
-    CDRMRightsDB* self = new( ELeave ) CDRMRightsDB( aFs );
+    CDRMRightsDB* self = new( ELeave ) CDRMRightsDB( aFs, aServer );
     CleanupStack::PushL( self );
     self->ConstructL( aDatabasePath, aKey, aImei );
 
@@ -233,9 +236,10 @@
 CDRMRightsDB* CDRMRightsDB::NewL( RFs& aFs,
                                   const TDesC& aDatabaseFile,
                                   const TDesC8& aKey,
-                                  const TDesC& aImei )
+                                  const TDesC& aImei,
+                                  CDRMRightsServer* aServer )
     {
-    CDRMRightsDB* self = NewLC( aFs, aDatabaseFile, aKey, aImei );
+    CDRMRightsDB* self = NewLC( aFs, aDatabaseFile, aKey, aImei, aServer );
     CleanupStack::Pop();
 
     return self;
@@ -318,7 +322,7 @@
         }
 
     // Delete expired:
-    TRAP_IGNORE( deleteAllowed = DeleteExpiredL( path, time ) );
+    TRAP_IGNORE( deleteAllowed = DeleteExpiredL( path, time, aContentID ) );
 
     // Check if it's possible to delete the file as well
     if( deleteAllowed )
@@ -1077,6 +1081,77 @@
 
 
 // -----------------------------------------------------------------------------
+// CDRMRightsDB::DeleteExpiredL
+// -----------------------------------------------------------------------------
+//
+TBool CDRMRightsDB::DeleteExpiredL( const TFileName& aFileName,
+                                   const TTime& aTime,
+                                   const TDesC8& aContentId )
+    {
+    CDRMRightsData* rights = NULL;
+    TInt amountLeft = -1;
+    TBool retVal = EFalse;
+    TBool parents = EFalse;
+
+    DRMLOG( _L( "CDRMRightsDB::DeleteExpiredL(2) ->" ) );
+
+    // if there is a consumption session ongoing, we can't delete it at all
+    // or the decryption will not function properly after pause etc
+    if( iRightsServer->IsAccessingUrl( aContentId ) != KErrNotFound )
+        {
+        return EFalse;    
+        }
+
+    // Indicate that the DB is updated
+    iLastUpdate.HomeTime();
+
+    // Open the rights file
+    DRMLOG( _L("Opening the file"));
+    rights = CDRMRightsData::OpenLC( aFileName, iFileServer );
+
+    DRMLOG( _L("Running Delete"));
+    amountLeft = rights->DeleteExpiredPermissionsL( aTime, parents );
+
+    DRMLOG2( _L("Checking for left RO:s %d"), amountLeft );
+
+    // See if any permissions are left if not check if the whole file
+    // can be proposed to be deleted or not, Java files require uninstallation
+    // so those need to be checked
+    if( !amountLeft && !parents )
+        {
+        // get the common data
+        const CDRMCommonData* common= rights->GetCommonDataL();
+
+        // If it is a java file, dont allow deletion
+        if( !common->ContentName().Right(4).CompareF(KJavaExtension) )
+            {
+            DRMLOG( _L("Is java file, do not delete"));
+            retVal = EFalse;
+            }
+        else if( !common->ContentName().Right(4).CompareF(KSISExtension) )
+            {
+            DRMLOG( _L("Is an installation package, do not delete"));
+            retVal = EFalse;
+            }
+        else
+            {
+            retVal = ETrue;
+            }
+        }
+    CleanupStack::PopAndDestroy(); // rights
+
+    DRMLOG( _L( "CDRMRightsDB::DeleteExpiredL <-" ) );
+
+    if( iRightsServer->HasActiveCountConstraint( aContentId ))
+        {
+        retVal = EFalse;    
+        }
+
+    return retVal;
+    }
+
+
+// -----------------------------------------------------------------------------
 // CDRMRightsDB::GetUdtDataLC
 // -----------------------------------------------------------------------------
 //