|
1 /* |
|
2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Implementation of the DRM Rights Database |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include <e32std.h> // RPointerArray |
|
23 #include <e32def.h> // Type definitions |
|
24 |
|
25 #include <caf/caf.h> |
|
26 #include "DRMCommon.h" // DRM Error messages |
|
27 #include "DRMRightsCleaner.h" |
|
28 #include "DRMRightsDB.h" |
|
29 #include "drmlog.h" |
|
30 |
|
31 |
|
32 // EXTERNAL DATA STRUCTURES |
|
33 |
|
34 // EXTERNAL FUNCTION PROTOTYPES |
|
35 |
|
36 // CONSTANTS |
|
37 |
|
38 // MACROS |
|
39 |
|
40 // LOCAL CONSTANTS AND MACROS |
|
41 |
|
42 const TInt KMaxDirs = 16; |
|
43 |
|
44 // MODULE DATA STRUCTURES |
|
45 |
|
46 // LOCAL FUNCTION PROTOTYPES |
|
47 |
|
48 // FORWARD DECLARATIONS |
|
49 |
|
50 // ============================= LOCAL FUNCTIONS =============================== |
|
51 // ============================ MEMBER FUNCTIONS =============================== |
|
52 |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CDRMRightsCleaner::NewL |
|
56 // Two-phased constructor. |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CDRMRightsCleaner* CDRMRightsCleaner::NewL( RFs& aFs, |
|
60 CDRMRightsDB* aDatabase, |
|
61 TRequestStatus& aStatus, |
|
62 const TDesC& aDatabasePath, |
|
63 const TTime& aTime ) |
|
64 { |
|
65 CDRMRightsCleaner* self = new( ELeave ) CDRMRightsCleaner( aFs, |
|
66 aDatabase, aStatus, |
|
67 aDatabasePath, aTime ); |
|
68 CleanupStack::PushL( self ); |
|
69 self->ConstructL(); |
|
70 CleanupStack::Pop(); |
|
71 |
|
72 return self; |
|
73 } |
|
74 |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // Destructor |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CDRMRightsCleaner::~CDRMRightsCleaner() |
|
81 { |
|
82 // just in case |
|
83 Deque(); |
|
84 |
|
85 if( iCurrentDirectory ) |
|
86 { |
|
87 delete iCurrentDirectory; |
|
88 iCurrentDirectory = NULL; |
|
89 } |
|
90 }; |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CDRMRightsCleaner::ExecuteCleanupLD |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 void CDRMRightsCleaner::ExecuteCleanupLD() |
|
97 { |
|
98 TRequestStatus* status = 0; |
|
99 |
|
100 if( !IsAdded() ) |
|
101 { |
|
102 CActiveScheduler::Add(this); |
|
103 } |
|
104 if ( !IsActive() ) |
|
105 { |
|
106 SetActive(); |
|
107 } |
|
108 |
|
109 iOperationStatus = KRequestPending; |
|
110 status = &iStatus; |
|
111 User::RequestComplete(status,KErrNone); |
|
112 }; |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // Default Constructor - First phase. |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 CDRMRightsCleaner::CDRMRightsCleaner( RFs& aFs, |
|
119 CDRMRightsDB* aDatabase, |
|
120 TRequestStatus& aStatus, |
|
121 const TDesC& aDatabasePath, |
|
122 const TTime& aTime ) : |
|
123 CActive( EPriorityLow ), |
|
124 iFileServer( aFs ), |
|
125 iRightsDb( aDatabase ), |
|
126 iOperationStatus( aStatus ), |
|
127 iDatabasePath( aDatabasePath ), |
|
128 iExpirationTime( aTime ), |
|
129 iCurrentDirectory( NULL ), |
|
130 iDirIndex( 0 ), |
|
131 iCurrentFile( 0 ) |
|
132 { |
|
133 |
|
134 }; |
|
135 |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CDRMRightsCleaner::ConstructL |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 void CDRMRightsCleaner::ConstructL() |
|
142 { |
|
143 }; |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CDRMRightsCleaner::RunError |
|
147 // More or less just ignore all errors and call RunL again |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 TInt CDRMRightsCleaner::RunError(TInt aError) |
|
151 { |
|
152 TRequestStatus* status = 0; |
|
153 |
|
154 if( aError == KErrCancel ) |
|
155 { |
|
156 // we are complete: |
|
157 status = &iOperationStatus; |
|
158 User::RequestComplete( status, KErrNone ); |
|
159 delete this; |
|
160 return KErrNone; |
|
161 } |
|
162 |
|
163 SetActive(); |
|
164 status = &iStatus; |
|
165 User::RequestComplete(status,KErrNone); |
|
166 |
|
167 return KErrNone; |
|
168 }; |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CDRMRightsCleaner::RunL |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 void CDRMRightsCleaner::RunL() |
|
175 { |
|
176 TRequestStatus* status = 0; |
|
177 TInt error = KErrNone; |
|
178 TFileName path; |
|
179 TInt modIndex = 0; |
|
180 TInt removeFile = EFalse; |
|
181 |
|
182 // If the status of the cleaning is other than KErrNone |
|
183 User::LeaveIfError( iStatus.Int() ); |
|
184 |
|
185 if( !iCurrentDirectory || |
|
186 iCurrentFile >= iCurrentDirectory->Count() ) |
|
187 { |
|
188 |
|
189 if( iDirIndex >= KMaxDirs ) |
|
190 { |
|
191 // we are complete: |
|
192 status = &iOperationStatus; |
|
193 User::RequestComplete( status, KErrNone ); |
|
194 delete this; |
|
195 return; |
|
196 } |
|
197 |
|
198 // if it exists, delete it |
|
199 if( iCurrentDirectory ) |
|
200 { |
|
201 delete iCurrentDirectory; |
|
202 iCurrentDirectory = 0; |
|
203 } |
|
204 |
|
205 TFileName path = iDatabasePath; |
|
206 |
|
207 |
|
208 path.Append(iDirIndex < 10 ? iDirIndex + '0' : iDirIndex + 'a' - 10); |
|
209 path.Append('\\'); |
|
210 |
|
211 |
|
212 error = iFileServer.GetDir(path, KEntryAttDir, ESortNone, iCurrentDirectory); |
|
213 |
|
214 DRMLOG(_L("Entering directory:")); |
|
215 DRMLOG( path ); |
|
216 |
|
217 // increase the dir counter |
|
218 iDirIndex++; |
|
219 iCurrentFile = 0; |
|
220 } |
|
221 |
|
222 if( !error && iCurrentDirectory->Count() ) |
|
223 { |
|
224 modIndex = iDirIndex-1; |
|
225 |
|
226 path = iDatabasePath; |
|
227 path.Append(modIndex < 10 ? modIndex + '0' : modIndex + 'a' - 10); |
|
228 path.Append('\\'); |
|
229 |
|
230 path.Append((*iCurrentDirectory)[iCurrentFile].iName); |
|
231 |
|
232 DRMLOG(_L("Checking file:")); |
|
233 DRMLOG( path ); |
|
234 |
|
235 // increase the file counter |
|
236 iCurrentFile++; |
|
237 |
|
238 TRAP( error, removeFile = iRightsDb->DeleteExpiredL( path, iExpirationTime ) ); |
|
239 if( error != KErrNone ) |
|
240 { |
|
241 DRMLOG2( _L( "CDRMRightsCleaner: error %d cleaning:" ), error ); |
|
242 DRMLOG( path ); |
|
243 } |
|
244 else |
|
245 { |
|
246 if ( removeFile ) |
|
247 { |
|
248 DRMLOG(_L("Deleting file:")); |
|
249 DRMLOG( path ); |
|
250 iFileServer.Delete( path ); |
|
251 } |
|
252 } |
|
253 } |
|
254 |
|
255 SetActive(); |
|
256 status = &iStatus; |
|
257 User::RequestComplete(status, KErrNone); |
|
258 }; |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // CDRMRightsCleaner::DoCancel |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 void CDRMRightsCleaner::DoCancel() |
|
265 { |
|
266 }; |
|
267 |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // CDRMRightsCleaner::DoCleanup |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 void CDRMRightsCleaner::DoCleanup() |
|
274 { |
|
275 TRequestStatus* status = 0; |
|
276 if( iCancel <= 0 ) |
|
277 { |
|
278 Cancel(); |
|
279 iCancel = 1; |
|
280 SetActive(); |
|
281 status = &iStatus; |
|
282 User::RequestComplete(status, KErrCancel); |
|
283 } |
|
284 }; |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |