76 CDRMRightsDB* aDatabase, |
76 CDRMRightsDB* aDatabase, |
77 TRequestStatus& aStatus, |
77 TRequestStatus& aStatus, |
78 RWriteStream& aStream, |
78 RWriteStream& aStream, |
79 TBool aPerformScan ) |
79 TBool aPerformScan ) |
80 { |
80 { |
81 CDRMObsoleteFinder* self = new( ELeave ) CDRMObsoleteFinder( aFs, |
81 CDRMObsoleteFinder* self = new( ELeave ) CDRMObsoleteFinder( aFs, |
82 aDatabase, aStatus, |
82 aDatabase, aStatus, |
83 aStream ); |
83 aStream ); |
84 CleanupStack::PushL( self ); |
84 CleanupStack::PushL( self ); |
85 self->ConstructL( aPerformScan ); |
85 self->ConstructL( aPerformScan ); |
86 CleanupStack::Pop(); |
86 CleanupStack::Pop(); |
87 |
87 |
88 return self; |
88 return self; |
89 } |
89 } |
90 |
90 |
91 |
91 |
92 // ----------------------------------------------------------------------------- |
92 // ----------------------------------------------------------------------------- |
93 // Destructor |
93 // Destructor |
94 // ----------------------------------------------------------------------------- |
94 // ----------------------------------------------------------------------------- |
95 // |
95 // |
96 CDRMObsoleteFinder::~CDRMObsoleteFinder() |
96 CDRMObsoleteFinder::~CDRMObsoleteFinder() |
97 { |
97 { |
98 // just in case |
98 // just in case |
99 Cancel(); |
99 Cancel(); |
100 |
100 |
101 if( iDcfClient ) |
101 if( iDcfClient ) |
102 { |
102 { |
103 delete iDcfClient; |
103 delete iDcfClient; |
104 iDcfClient = NULL; |
104 iDcfClient = NULL; |
105 } |
105 } |
106 |
106 |
107 if( iContents ) |
107 if( iContents ) |
108 { |
108 { |
109 delete iContents; |
109 delete iContents; |
110 iContents = NULL; |
110 iContents = NULL; |
111 } |
111 } |
112 |
112 |
113 if( iParents ) |
113 if( iParents ) |
114 { |
114 { |
115 delete iParents; |
115 delete iParents; |
116 iParents = NULL; |
116 iParents = NULL; |
117 } |
117 } |
118 |
118 |
119 if( iNoContents ) |
119 if( iNoContents ) |
120 { |
120 { |
121 delete iNoContents; |
121 delete iNoContents; |
122 iNoContents = NULL; |
122 iNoContents = NULL; |
123 } |
123 } |
124 }; |
124 }; |
125 |
125 |
126 // ----------------------------------------------------------------------------- |
126 // ----------------------------------------------------------------------------- |
127 // CDRMObsoleteFinder::ExecuteCleanupLD |
127 // CDRMObsoleteFinder::ExecuteCleanupLD |
128 // ----------------------------------------------------------------------------- |
128 // ----------------------------------------------------------------------------- |
129 // |
129 // |
130 void CDRMObsoleteFinder::ExecuteFinderLD() |
130 void CDRMObsoleteFinder::ExecuteFinderLD() |
131 { |
131 { |
132 TRequestStatus* status = 0; |
132 TRequestStatus* status = 0; |
133 |
133 |
134 if( !IsAdded() ) |
134 if( !IsAdded() ) |
135 { |
135 { |
136 CActiveScheduler::Add(this); |
136 CActiveScheduler::Add(this); |
137 } |
137 } |
138 if ( !IsActive() ) |
138 if ( !IsActive() ) |
139 { |
139 { |
140 SetActive(); |
140 SetActive(); |
141 } |
141 } |
142 |
142 |
143 iOperationStatus = KRequestPending; |
143 iOperationStatus = KRequestPending; |
144 status = &iStatus; |
144 status = &iStatus; |
145 User::RequestComplete(status,KErrNone); |
145 User::RequestComplete(status,KErrNone); |
146 }; |
146 }; |
147 |
147 |
148 // ----------------------------------------------------------------------------- |
148 // ----------------------------------------------------------------------------- |
149 // Default Constructor - First phase. |
149 // Default Constructor - First phase. |
150 // ----------------------------------------------------------------------------- |
150 // ----------------------------------------------------------------------------- |
151 // |
151 // |
152 CDRMObsoleteFinder::CDRMObsoleteFinder( RFs& aFs, |
152 CDRMObsoleteFinder::CDRMObsoleteFinder( RFs& aFs, |
153 CDRMRightsDB* aDatabase, |
153 CDRMRightsDB* aDatabase, |
160 iIndex( -1 ), |
160 iIndex( -1 ), |
161 iFileServer( aFs ), |
161 iFileServer( aFs ), |
162 iStream( aStream ), |
162 iStream( aStream ), |
163 iRightsDb( aDatabase ), |
163 iRightsDb( aDatabase ), |
164 iOperationStatus( aStatus ), |
164 iOperationStatus( aStatus ), |
165 iState( KScanFileSystem ) |
165 iState( KScanFileSystem ) |
166 { |
166 { |
167 |
167 |
168 }; |
168 }; |
169 |
169 |
170 |
170 |
171 // ----------------------------------------------------------------------------- |
171 // ----------------------------------------------------------------------------- |
172 // CDRMObsoleteFinder::ConstructL |
172 // CDRMObsoleteFinder::ConstructL |
173 // ----------------------------------------------------------------------------- |
173 // ----------------------------------------------------------------------------- |
174 // |
174 // |
175 void CDRMObsoleteFinder::ConstructL( const TBool aPerformScan ) |
175 void CDRMObsoleteFinder::ConstructL( const TBool aPerformScan ) |
176 { |
176 { |
177 // if the scan needs to be done, the initial state is different: |
177 // if the scan needs to be done, the initial state is different: |
178 if( aPerformScan ) |
178 if( aPerformScan ) |
179 { |
179 { |
180 iState = KScanFileSystem; |
180 iState = KScanFileSystem; |
181 } |
181 } |
182 else |
182 else |
183 { |
183 { |
184 iState = KScanContents; |
184 iState = KScanContents; |
185 } |
185 } |
186 |
186 |
187 // connect to dcf repository |
187 // connect to dcf repository |
188 iDcfClient = CDcfRep::NewL(); |
188 iDcfClient = CDcfRep::NewL(); |
189 |
189 |
190 // Create a new list |
190 // Create a new list |
191 iContents = CDRMPointerArray<HBufC8>::NewL(); |
191 iContents = CDRMPointerArray<HBufC8>::NewL(); |
192 |
192 |
193 // Create a new list |
193 // Create a new list |
194 iParents = CDRMPointerArray<HBufC8>::NewL(); |
194 iParents = CDRMPointerArray<HBufC8>::NewL(); |
195 |
195 |
196 // Create a new list |
196 // Create a new list |
197 iNoContents = CDRMPointerArray<HBufC8>::NewL(); |
197 iNoContents = CDRMPointerArray<HBufC8>::NewL(); |
198 |
198 |
199 }; |
199 }; |
200 |
200 |
201 // ----------------------------------------------------------------------------- |
201 // ----------------------------------------------------------------------------- |
202 // CDRMObsoleteFinder::RunError |
202 // CDRMObsoleteFinder::RunError |
203 // ----------------------------------------------------------------------------- |
203 // ----------------------------------------------------------------------------- |
204 // |
204 // |
205 TInt CDRMObsoleteFinder::RunError(TInt aError) |
205 TInt CDRMObsoleteFinder::RunError(TInt aError) |
206 { |
206 { |
207 TRequestStatus* status = 0; |
207 TRequestStatus* status = 0; |
208 |
208 |
209 if( aError != KErrNone ) |
209 if( aError != KErrNone ) |
210 { |
210 { |
211 status = &iOperationStatus; |
211 status = &iOperationStatus; |
212 User::RequestComplete( status, aError ); |
212 User::RequestComplete( status, aError ); |
213 delete this; |
213 delete this; |
214 } |
214 } |
215 return KErrNone; |
215 return KErrNone; |
216 }; |
216 }; |
217 |
217 |
218 // ----------------------------------------------------------------------------- |
218 // ----------------------------------------------------------------------------- |
219 // CDRMObsoleteFinder::RunL |
219 // CDRMObsoleteFinder::RunL |
220 // ----------------------------------------------------------------------------- |
220 // ----------------------------------------------------------------------------- |
221 // |
221 // |
222 void CDRMObsoleteFinder::RunL() |
222 void CDRMObsoleteFinder::RunL() |
223 { |
223 { |
224 TRequestStatus* status = 0; |
224 TRequestStatus* status = 0; |
225 TInt error = KErrNone; |
225 TInt error = KErrNone; |
226 HBufC8* buffer = NULL; |
226 HBufC8* buffer = NULL; |
227 |
227 |
228 // If the status of the cleaning is other than KErrNone |
228 // If the status of the cleaning is other than KErrNone |
229 User::LeaveIfError( iStatus.Int() ); |
229 User::LeaveIfError( iStatus.Int() ); |
230 |
230 |
231 switch( iState ) |
231 switch( iState ) |
232 { |
232 { |
233 case KScanFileSystem: |
233 case KScanFileSystem: |
234 iState = KScanContents; |
234 iState = KScanContents; |
235 iDcfClient->RefreshDcf( iStatus ); |
235 iDcfClient->RefreshDcf( iStatus ); |
236 SetActive(); |
236 SetActive(); |
237 break; |
237 break; |
238 case KScanContents: |
238 case KScanContents: |
239 if( iIndex == -1 ) |
239 if( iIndex == -1 ) |
240 { |
240 { |
241 // Get the contents |
241 // Get the contents |
242 iRightsDb->GetContentIDListL( *iContents ); |
242 iRightsDb->GetContentIDListL( *iContents ); |
243 // Reset the index |
243 // Reset the index |
244 iIndex = 0; |
244 iIndex = 0; |
245 } |
245 } |
246 else |
246 else |
247 { |
247 { |
248 iIndex++; |
248 iIndex++; |
249 } |
249 } |
250 |
250 |
251 if( iIndex >= iContents->Count() ) |
251 if( iIndex >= iContents->Count() ) |
252 { |
252 { |
253 iState = KRemoveUsedParents; |
253 iState = KRemoveUsedParents; |
254 iIndex = -1; |
254 iIndex = -1; |
255 } |
255 } |
256 else |
256 else |
257 { |
257 { |
258 // Check if there is content |
258 // Check if there is content |
259 TRAP( error, iDcfClient->OrderListL( *(*iContents)[iIndex] )); |
259 TRAP( error, iDcfClient->OrderListL( *(*iContents)[iIndex] )); |
260 |
260 |
261 // If an error occurs, leave if it's ok, continue |
261 // If an error occurs, leave if it's ok, continue |
262 if( error != KErrNotFound ) |
262 if( error != KErrNotFound ) |
263 { |
263 { |
264 User::LeaveIfError( error ); |
264 User::LeaveIfError( error ); |
265 |
265 |
266 // Get all the parents |
266 // Get all the parents |
267 if( !error ) |
267 if( !error ) |
268 { |
268 { |
269 GetParentsL( *(*iContents)[iIndex], *iParents ); |
269 GetParentsL( *(*iContents)[iIndex], *iParents ); |
270 } |
270 } |
271 } |
271 } |
272 // If the error is not found, add to the no content list |
272 // If the error is not found, add to the no content list |
273 else |
273 else |
274 { |
274 { |
275 buffer = (*iContents)[iIndex]->AllocLC(); |
275 buffer = (*iContents)[iIndex]->AllocLC(); |
276 iNoContents->AppendL( buffer ); |
276 iNoContents->AppendL( buffer ); |
277 CleanupStack::Pop(); |
277 CleanupStack::Pop(); |
278 } |
278 } |
279 } |
279 } |
280 SetActive(); |
280 SetActive(); |
281 status = &iStatus; |
281 status = &iStatus; |
282 User::RequestComplete(status,KErrNone); |
282 User::RequestComplete(status,KErrNone); |
283 break; |
283 break; |
284 case KRemoveUsedParents: |
284 case KRemoveUsedParents: |
285 if( iIndex == -1 ) |
285 if( iIndex == -1 ) |
286 { |
286 { |
287 iIndex = 0; |
287 iIndex = 0; |
288 } |
288 } |
289 else |
289 else |
290 { |
290 { |
291 iIndex++; |
291 iIndex++; |
292 } |
292 } |
293 |
293 |
294 if( iIndex >= iParents->Count() ) |
294 if( iIndex >= iParents->Count() ) |
295 { |
295 { |
296 iState = KWriteTempFile; |
296 iState = KWriteTempFile; |
297 iIndex = -1; |
297 iIndex = -1; |
298 } |
298 } |
299 else |
299 else |
300 { |
300 { |
301 // Find the parent |
301 // Find the parent |
302 error = iNoContents->FindInOrder( (*iParents)[iIndex], |
302 error = iNoContents->FindInOrder( (*iParents)[iIndex], |
303 TLinearOrder<HBufC8>(CompareHBufC8)); |
303 TLinearOrder<HBufC8>(CompareHBufC8)); |
304 |
304 |
305 if( error != KErrNotFound ) |
305 if( error != KErrNotFound ) |
306 { |
306 { |
307 buffer = (*iNoContents)[error]; |
307 buffer = (*iNoContents)[error]; |
308 iNoContents->Remove( error ); |
308 iNoContents->Remove( error ); |
309 delete buffer; |
309 delete buffer; |
310 buffer = 0; |
310 buffer = 0; |
311 } |
311 } |
312 } |
312 } |
313 SetActive(); |
313 SetActive(); |
314 status = &iStatus; |
314 status = &iStatus; |
315 User::RequestComplete(status,KErrNone); |
315 User::RequestComplete(status,KErrNone); |
316 break; |
316 break; |
317 case KWriteTempFile: |
317 case KWriteTempFile: |
318 ObsoleteToStreamL(); |
318 ObsoleteToStreamL(); |
319 // we are complete: |
319 // we are complete: |
320 status = &iOperationStatus; |
320 status = &iOperationStatus; |
321 User::RequestComplete( status, KErrNone ); |
321 User::RequestComplete( status, KErrNone ); |
322 delete this; |
322 delete this; |
323 return; |
323 return; |
324 default: |
324 default: |
325 // illegal status, return error and delete object |
325 // illegal status, return error and delete object |
326 status = &iOperationStatus; |
326 status = &iOperationStatus; |
327 User::RequestComplete( status, KErrGeneral ); |
327 User::RequestComplete( status, KErrGeneral ); |
328 delete this; |
328 delete this; |
329 return; |
329 return; |
330 } |
330 } |
331 }; |
331 }; |
332 |
332 |
333 |
333 |
334 // ---------------------------------------------------------------------------- |
334 // ---------------------------------------------------------------------------- |
335 // CDRMObsoleteFinder::GetParentsL |
335 // CDRMObsoleteFinder::GetParentsL |
336 // ---------------------------------------------------------------------------- |
336 // ---------------------------------------------------------------------------- |
338 void CDRMObsoleteFinder::GetParentsL( const TDesC8& aContentId, |
338 void CDRMObsoleteFinder::GetParentsL( const TDesC8& aContentId, |
339 RPointerArray<HBufC8>& aParents ) |
339 RPointerArray<HBufC8>& aParents ) |
340 { |
340 { |
341 HBufC8* parentId = NULL; |
341 HBufC8* parentId = NULL; |
342 TInt error = KErrNone; |
342 TInt error = KErrNone; |
343 CDRMPointerArray<CDRMPermission>* permissions = |
343 CDRMPointerArray<CDRMPermission>* permissions = |
344 CDRMPointerArray<CDRMPermission>::NewLC(); |
344 CDRMPointerArray<CDRMPermission>::NewLC(); |
345 permissions->SetAutoCleanup( ETrue ); |
345 permissions->SetAutoCleanup( ETrue ); |
346 CDRMPointerArray<CDRMPermission>& perm = *permissions; |
346 CDRMPointerArray<CDRMPermission>& perm = *permissions; |
347 |
347 |
348 TRAP( error, iRightsDb->GetDBEntryByContentIDL( aContentId, *permissions ) ); |
348 TRAP( error, iRightsDb->GetDBEntryByContentIDL( aContentId, *permissions ) ); |
349 |
349 |
350 // If there are no keys it means that there is encryption key and such, but |
350 // If there are no keys it means that there is encryption key and such, but |
351 // no available permissions |
351 // no available permissions |
352 if( error == KErrCANoRights ) |
352 if( error == KErrCANoRights ) |
353 { |
353 { |
354 CleanupStack::PopAndDestroy(); // permissions |
354 CleanupStack::PopAndDestroy(); // permissions |
355 return; |
355 return; |
356 } |
356 } |
357 else |
357 else |
358 { |
358 { |
359 User::LeaveIfError(error); |
359 User::LeaveIfError(error); |
360 } |
360 } |
361 |
361 |
362 for( TInt i = 0; i < permissions->Count(); i++, error = KErrNone ) |
362 for( TInt i = 0; i < permissions->Count(); i++, error = KErrNone ) |
363 { |
363 { |
364 // Check if the permission has a parent |
364 // Check if the permission has a parent |
365 if( perm[i]->iParentUID ) |
365 if( perm[i]->iParentUID ) |
366 { |
366 { |
367 // if it does, insert it to the aParents array |
367 // if it does, insert it to the aParents array |
368 error = aParents.FindInOrder( perm[i]->iParentUID, |
368 error = aParents.FindInOrder( perm[i]->iParentUID, |
369 TLinearOrder<HBufC8>(CompareHBufC8)); |
369 TLinearOrder<HBufC8>(CompareHBufC8)); |
370 if( error == KErrNotFound ) |
370 if( error == KErrNotFound ) |
371 { |
371 { |
372 parentId = perm[i]->iParentUID->AllocLC(); |
372 parentId = perm[i]->iParentUID->AllocLC(); |
373 User::LeaveIfError( aParents.InsertInOrder(parentId, |
373 User::LeaveIfError( aParents.InsertInOrder(parentId, |
374 TLinearOrder<HBufC8>(CompareHBufC8)) ); |
374 TLinearOrder<HBufC8>(CompareHBufC8)) ); |
375 CleanupStack::Pop(); |
375 CleanupStack::Pop(); |
376 } |
376 } |
377 } |
377 } |
378 } |
378 } |
379 |
379 |
380 CleanupStack::PopAndDestroy(); // permissions |
380 CleanupStack::PopAndDestroy(); // permissions |
381 }; |
381 }; |
382 |
382 |
383 |
383 |
384 // ----------------------------------------------------------------------------- |
384 // ----------------------------------------------------------------------------- |
385 // CDRMObsoleteFinder::ObsoleteToStreamL |
385 // CDRMObsoleteFinder::ObsoleteToStreamL |
386 // ----------------------------------------------------------------------------- |
386 // ----------------------------------------------------------------------------- |
400 // Reset count variable: |
400 // Reset count variable: |
401 count = 0; |
401 count = 0; |
402 |
402 |
403 #ifndef RD_MULTIPLE_DRIVE |
403 #ifndef RD_MULTIPLE_DRIVE |
404 |
404 |
405 if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFileServer, |
405 if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFileServer, |
406 size, |
406 size, |
407 EDriveC ) ) |
407 EDriveC ) ) |
408 |
408 |
409 #else //RD_MULTIPLE_DRIVE |
409 #else //RD_MULTIPLE_DRIVE |
410 |
410 |
411 TInt driveNumber( -1 ); |
411 TInt driveNumber( -1 ); |
412 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
412 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
413 |
413 |
414 if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFileServer, |
414 if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFileServer, |
415 size, |
415 size, |
416 driveNumber ) ) |
416 driveNumber ) ) |
417 |
417 |
418 #endif |
418 #endif |
419 |
419 |
420 { |
420 { |
421 DRMLOG( _L( "CDRMDbSession::UriListToFileL: KErrDiskFull" ) ); |
421 DRMLOG( _L( "CDRMDbSession::UriListToFileL: KErrDiskFull" ) ); |
422 User::Leave( KErrDiskFull ); |
422 User::Leave( KErrDiskFull ); |
423 } |
423 } |
424 // Write the whole stuff into the file. |
424 // Write the whole stuff into the file. |
425 while( count < iNoContents->Count() ) |
425 while( count < iNoContents->Count() ) |
426 { |
426 { |
427 iStream.WriteUint16L( (*iNoContents)[count]->Length() ); |
427 iStream.WriteUint16L( (*iNoContents)[count]->Length() ); |
428 iStream.WriteL( *(*iNoContents)[count] ); |
428 iStream.WriteL( *(*iNoContents)[count] ); |
429 ++count; |
429 ++count; |
430 } |
430 } |
431 // Finish with a 0 |
431 // Finish with a 0 |
432 iStream.WriteUint16L( 0 ); |
432 iStream.WriteUint16L( 0 ); |
433 |
433 |
434 iStream.CommitL(); |
434 iStream.CommitL(); |
435 } |
435 } |
436 |
436 |
437 // ----------------------------------------------------------------------------- |
437 // ----------------------------------------------------------------------------- |
438 // CDRMObsoleteFinder::DoCancel |
438 // CDRMObsoleteFinder::DoCancel |
439 // ----------------------------------------------------------------------------- |
439 // ----------------------------------------------------------------------------- |
440 // |
440 // |
441 void CDRMObsoleteFinder::DoCancel() |
441 void CDRMObsoleteFinder::DoCancel() |
442 { |
442 { |
443 }; |
443 }; |
444 |
444 |
445 // ----------------------------------------------------------------------------- |
445 // ----------------------------------------------------------------------------- |
446 // CDRMObsoleteFinder::DoCleanup |
446 // CDRMObsoleteFinder::DoCleanup |
447 // ----------------------------------------------------------------------------- |
447 // ----------------------------------------------------------------------------- |
448 // |
448 // |
449 void CDRMObsoleteFinder::DoCleanup() |
449 void CDRMObsoleteFinder::DoCleanup() |
450 { |
450 { |
451 TRequestStatus* status = 0; |
451 TRequestStatus* status = 0; |
452 if( iCancel <= 0 ) |
452 if( iCancel <= 0 ) |
453 { |
453 { |
454 iCancel = 1; |
454 iCancel = 1; |
455 status = &iStatus; |
455 status = &iStatus; |
456 User::RequestComplete(status, KErrCancel); |
456 User::RequestComplete(status, KErrCancel); |
457 } |
457 } |
458 }; |
458 }; |
459 |
459 |
460 |
460 |
461 |
461 |
462 |
462 |
463 |
463 |
464 |
464 |
465 |
465 |
466 |
466 |