omadrm/drmengine/server/src/drmrightsdb.cpp
branchRCL_3
changeset 55 ad2863178d17
parent 32 457cd4423b8c
child 71 1221b68b8a5f
equal deleted inserted replaced
41:29f3cf766061 55:ad2863178d17
    44 #include "DRMRightsCleaner.h"
    44 #include "DRMRightsCleaner.h"
    45 #include "DRMRightsServer.h"
    45 #include "DRMRightsServer.h"
    46 #include "DrmKeyStorage.h"
    46 #include "DrmKeyStorage.h"
    47 #include "utf.h" // charconv, ConvertFromUnicodeToUtf8L
    47 #include "utf.h" // charconv, ConvertFromUnicodeToUtf8L
    48 #include "drmlog.h"
    48 #include "drmlog.h"
       
    49 #include "DRMRightsServer.h"
    49 
    50 
    50 #ifdef RD_DRM_RIGHTS_MANAGER_REMOVAL
    51 #ifdef RD_DRM_RIGHTS_MANAGER_REMOVAL
    51 #include "DRMClockClient.h"
    52 #include "DRMClockClient.h"
    52 #endif // RD_DRM_RIGHTS_MANAGER_REMOVAL
    53 #endif // RD_DRM_RIGHTS_MANAGER_REMOVAL
    53 
    54 
   157 // CDRMRightsDB::CDRMRightsDB
   158 // CDRMRightsDB::CDRMRightsDB
   158 // C++ default constructor can NOT contain any code, that
   159 // C++ default constructor can NOT contain any code, that
   159 // might leave.
   160 // might leave.
   160 // -----------------------------------------------------------------------------
   161 // -----------------------------------------------------------------------------
   161 //
   162 //
   162 CDRMRightsDB::CDRMRightsDB( RFs& aFs ) :
   163 CDRMRightsDB::CDRMRightsDB( RFs& aFs, CDRMRightsServer* aServer ) :
   163     iFileServer( aFs ),
   164     iFileServer( aFs ),
   164     iImei( NULL ),
   165     iImei( NULL ),
   165     iLastUpdate( Time::NullTTime() )
   166     iLastUpdate( Time::NullTTime() ),
       
   167     iRightsServer( aServer )    
   166     {
   168     {
   167     };
   169     };
   168 
   170 
   169 
   171 
   170 // -----------------------------------------------------------------------------
   172 // -----------------------------------------------------------------------------
   214 // -----------------------------------------------------------------------------
   216 // -----------------------------------------------------------------------------
   215 //
   217 //
   216 CDRMRightsDB* CDRMRightsDB::NewLC( RFs& aFs,
   218 CDRMRightsDB* CDRMRightsDB::NewLC( RFs& aFs,
   217                                    const TDesC& aDatabasePath,
   219                                    const TDesC& aDatabasePath,
   218                                    const TDesC8& aKey,
   220                                    const TDesC8& aKey,
   219                                    const TDesC& aImei )
   221                                    const TDesC& aImei,
   220     {
   222                                    CDRMRightsServer* aServer )
   221     CDRMRightsDB* self = new( ELeave ) CDRMRightsDB( aFs );
   223     {
       
   224     CDRMRightsDB* self = new( ELeave ) CDRMRightsDB( aFs, aServer );
   222     CleanupStack::PushL( self );
   225     CleanupStack::PushL( self );
   223     self->ConstructL( aDatabasePath, aKey, aImei );
   226     self->ConstructL( aDatabasePath, aKey, aImei );
   224 
   227 
   225     return self;
   228     return self;
   226     };
   229     };
   231 // -----------------------------------------------------------------------------
   234 // -----------------------------------------------------------------------------
   232 //
   235 //
   233 CDRMRightsDB* CDRMRightsDB::NewL( RFs& aFs,
   236 CDRMRightsDB* CDRMRightsDB::NewL( RFs& aFs,
   234                                   const TDesC& aDatabaseFile,
   237                                   const TDesC& aDatabaseFile,
   235                                   const TDesC8& aKey,
   238                                   const TDesC8& aKey,
   236                                   const TDesC& aImei )
   239                                   const TDesC& aImei,
   237     {
   240                                   CDRMRightsServer* aServer )
   238     CDRMRightsDB* self = NewLC( aFs, aDatabaseFile, aKey, aImei );
   241     {
       
   242     CDRMRightsDB* self = NewLC( aFs, aDatabaseFile, aKey, aImei, aServer );
   239     CleanupStack::Pop();
   243     CleanupStack::Pop();
   240 
   244 
   241     return self;
   245     return self;
   242     };
   246     };
   243 
   247 
   316         {
   320         {
   317         time = Time::NullTTime();
   321         time = Time::NullTTime();
   318         }
   322         }
   319 
   323 
   320     // Delete expired:
   324     // Delete expired:
   321     TRAP_IGNORE( deleteAllowed = DeleteExpiredL( path, time ) );
   325     TRAP_IGNORE( deleteAllowed = DeleteExpiredL( path, time, aContentID ) );
   322 
   326 
   323     // Check if it's possible to delete the file as well
   327     // Check if it's possible to delete the file as well
   324     if( deleteAllowed )
   328     if( deleteAllowed )
   325         {
   329         {
   326         iFileServer.Delete( path );
   330         iFileServer.Delete( path );
  1069             }
  1073             }
  1070         }
  1074         }
  1071     CleanupStack::PopAndDestroy(); // rights
  1075     CleanupStack::PopAndDestroy(); // rights
  1072 
  1076 
  1073     DRMLOG( _L( "CDRMRightsDB::DeleteExpiredL <-" ) );
  1077     DRMLOG( _L( "CDRMRightsDB::DeleteExpiredL <-" ) );
       
  1078 
       
  1079     return retVal;
       
  1080     }
       
  1081 
       
  1082 
       
  1083 // -----------------------------------------------------------------------------
       
  1084 // CDRMRightsDB::DeleteExpiredL
       
  1085 // -----------------------------------------------------------------------------
       
  1086 //
       
  1087 TBool CDRMRightsDB::DeleteExpiredL( const TFileName& aFileName,
       
  1088                                    const TTime& aTime,
       
  1089                                    const TDesC8& aContentId )
       
  1090     {
       
  1091     CDRMRightsData* rights = NULL;
       
  1092     TInt amountLeft = -1;
       
  1093     TBool retVal = EFalse;
       
  1094     TBool parents = EFalse;
       
  1095 
       
  1096     DRMLOG( _L( "CDRMRightsDB::DeleteExpiredL(2) ->" ) );
       
  1097 
       
  1098     // if there is a consumption session ongoing, we can't delete it at all
       
  1099     // or the decryption will not function properly after pause etc
       
  1100     if( iRightsServer->IsAccessingUrl( aContentId ) != KErrNotFound )
       
  1101         {
       
  1102         return EFalse;    
       
  1103         }
       
  1104 
       
  1105     // Indicate that the DB is updated
       
  1106     iLastUpdate.HomeTime();
       
  1107 
       
  1108     // Open the rights file
       
  1109     DRMLOG( _L("Opening the file"));
       
  1110     rights = CDRMRightsData::OpenLC( aFileName, iFileServer );
       
  1111 
       
  1112     DRMLOG( _L("Running Delete"));
       
  1113     amountLeft = rights->DeleteExpiredPermissionsL( aTime, parents );
       
  1114 
       
  1115     DRMLOG2( _L("Checking for left RO:s %d"), amountLeft );
       
  1116 
       
  1117     // See if any permissions are left if not check if the whole file
       
  1118     // can be proposed to be deleted or not, Java files require uninstallation
       
  1119     // so those need to be checked
       
  1120     if( !amountLeft && !parents )
       
  1121         {
       
  1122         // get the common data
       
  1123         const CDRMCommonData* common= rights->GetCommonDataL();
       
  1124 
       
  1125         // If it is a java file, dont allow deletion
       
  1126         if( !common->ContentName().Right(4).CompareF(KJavaExtension) )
       
  1127             {
       
  1128             DRMLOG( _L("Is java file, do not delete"));
       
  1129             retVal = EFalse;
       
  1130             }
       
  1131         else if( !common->ContentName().Right(4).CompareF(KSISExtension) )
       
  1132             {
       
  1133             DRMLOG( _L("Is an installation package, do not delete"));
       
  1134             retVal = EFalse;
       
  1135             }
       
  1136         else
       
  1137             {
       
  1138             retVal = ETrue;
       
  1139             }
       
  1140         }
       
  1141     CleanupStack::PopAndDestroy(); // rights
       
  1142 
       
  1143     DRMLOG( _L( "CDRMRightsDB::DeleteExpiredL <-" ) );
       
  1144 
       
  1145     if( iRightsServer->HasActiveCountConstraint( aContentId ))
       
  1146         {
       
  1147         retVal = EFalse;    
       
  1148         }
  1074 
  1149 
  1075     return retVal;
  1150     return retVal;
  1076     }
  1151     }
  1077 
  1152 
  1078 
  1153