|
1 /* |
|
2 * Copyright (c) 2002-2009 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 CAF rights manager |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <caf/caf.h> |
|
22 #include <utf.h> |
|
23 #include "drmrights.h" |
|
24 #include "oma2agentrightsmanager.h" |
|
25 #include "drmrightsclient.h" |
|
26 #include "dcfrep.h" |
|
27 #include "dcfentry.h" |
|
28 |
|
29 using namespace ContentAccess; |
|
30 |
|
31 // ============================= LOCAL FUNCTIONS =============================== |
|
32 |
|
33 void DoDeleteAllRightsObjectsL( const TVirtualPathPtr& aVirtualPath ) |
|
34 { |
|
35 RDRMRightsClient client; |
|
36 CDcfCommon* dcf = NULL; |
|
37 RFs fs; |
|
38 |
|
39 User::LeaveIfError(client.Connect()); |
|
40 CleanupClosePushL(client); |
|
41 User::LeaveIfError(fs.Connect()); |
|
42 User::LeaveIfError(fs.ShareAuto()); |
|
43 CleanupClosePushL(fs); |
|
44 dcf = CDcfCommon::NewL(aVirtualPath.URI(), &fs); |
|
45 CleanupStack::PushL(dcf); |
|
46 User::LeaveIfError( dcf->OpenPart(aVirtualPath.UniqueId())); |
|
47 User::LeaveIfError( client.DeleteDbEntry(*dcf->iContentID)); |
|
48 CleanupStack::PopAndDestroy(3); // dcf, fs, client |
|
49 } |
|
50 |
|
51 void DoDeleteAllRightsObjects( const TVirtualPathPtr& aVirtualPath ) |
|
52 { |
|
53 TRAP_IGNORE( DoDeleteAllRightsObjectsL( aVirtualPath ) ); |
|
54 } |
|
55 |
|
56 void DoDeleteRightsObjectL( |
|
57 const CRightsInfo& aRightsInfo) |
|
58 { |
|
59 RDRMRightsClient client; |
|
60 TInt uniqueId; |
|
61 HBufC8* contentId = NULL; |
|
62 TInt n; |
|
63 |
|
64 User::LeaveIfError(client.Connect()); |
|
65 CleanupClosePushL(client); |
|
66 n = aRightsInfo.UniqueId().Locate(0); |
|
67 if (n == KErrNotFound) |
|
68 { |
|
69 contentId = CnvUtfConverter::ConvertFromUnicodeToUtf8L( |
|
70 aRightsInfo.UniqueId()); |
|
71 CleanupStack::PushL(contentId); |
|
72 User::LeaveIfError( client.DeleteDbEntry(*contentId) ); |
|
73 } |
|
74 else |
|
75 { |
|
76 contentId = CnvUtfConverter::ConvertFromUnicodeToUtf8L( |
|
77 aRightsInfo.UniqueId().Left(n)); |
|
78 CleanupStack::PushL(contentId); |
|
79 TLex lex(aRightsInfo.UniqueId().Right( |
|
80 aRightsInfo.UniqueId().Length() - n - 1)); |
|
81 User::LeaveIfError( lex.Val(uniqueId) ); |
|
82 User::LeaveIfError( client.DeleteDbEntry(*contentId, uniqueId) ); |
|
83 } |
|
84 CleanupStack::PopAndDestroy(2); // contentId, client |
|
85 } |
|
86 |
|
87 void DoDeleteRightsObject( |
|
88 const CRightsInfo& aRightsInfo) |
|
89 { |
|
90 TRAP_IGNORE( DoDeleteRightsObjectL( aRightsInfo ) ); |
|
91 } |
|
92 |
|
93 |
|
94 template<class S> |
|
95 void PointerArrayResetDestroyAndClose(TAny* aPtr) |
|
96 { |
|
97 (reinterpret_cast<RPointerArray<S>*>(aPtr))->ResetAndDestroy(); |
|
98 (reinterpret_cast<RPointerArray<S>*>(aPtr))->Close(); |
|
99 } |
|
100 |
|
101 TBool IsValid( |
|
102 CDRMPermission* aPermission, |
|
103 TIntent aIntent, |
|
104 TTime aTime) |
|
105 { |
|
106 TBool r = EFalse; |
|
107 CDRMConstraint* constraint; |
|
108 |
|
109 constraint = aPermission->ConstraintForIntent(aIntent); |
|
110 if (constraint != NULL && !constraint->Expired(aTime)) |
|
111 { |
|
112 r = ETrue; |
|
113 } |
|
114 return r; |
|
115 } |
|
116 |
|
117 TRightsStatus PermissionStatus( |
|
118 CDRMPermission* aPermission) |
|
119 { |
|
120 TRightsStatus r = ERightsStatusNone; |
|
121 TTime time; |
|
122 |
|
123 time.HomeTime(); |
|
124 if ((!(aPermission->iAvailableRights & ERightsTopLevel) || |
|
125 !aPermission->iTopLevel->Expired(time)) |
|
126 |
|
127 && |
|
128 |
|
129 (IsValid(aPermission, EPlay, time) || |
|
130 IsValid(aPermission, EView, time) || |
|
131 IsValid(aPermission, EPrint, time) || |
|
132 IsValid(aPermission, EExecute, time))) |
|
133 { |
|
134 r = ERightsStatusValid; |
|
135 } |
|
136 return r; |
|
137 } |
|
138 |
|
139 CRightsInfo* ConvertToRightsInfoL( |
|
140 CDRMPermission* aPermission, |
|
141 const TDesC8& aContentId) |
|
142 { |
|
143 TRightsTypeMask type; |
|
144 TPtr ptr(NULL, 0); |
|
145 HBufC* id = NULL; |
|
146 CRightsInfo* r = NULL; |
|
147 |
|
148 id = HBufC::NewLC(aContentId.Length() + 20); |
|
149 ptr.Set(id->Des()); |
|
150 ptr.Copy(aContentId); |
|
151 ptr.SetLength(aContentId.Length()); |
|
152 ptr.Append(0); |
|
153 ptr.AppendNum(aPermission->iUniqueID); |
|
154 if (aPermission->Stateful()) |
|
155 { |
|
156 type = ERightsTypeConsumable; |
|
157 } |
|
158 else |
|
159 { |
|
160 type = ERightsTypeStateless; |
|
161 } |
|
162 r = CRightsInfo::NewL(KNullDesC, *id, type, PermissionStatus(aPermission)); |
|
163 CleanupStack::PopAndDestroy(); // id |
|
164 return r; |
|
165 } |
|
166 |
|
167 // ============================ MEMBER FUNCTIONS =============================== |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // COma2AgentRightsManager::COma2AgentRightsManager |
|
171 // C++ default constructor can NOT contain any code, that |
|
172 // might leave. |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 COma2AgentRightsManager::COma2AgentRightsManager() |
|
176 { |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // COma2AgentRightsManager::ConstructL |
|
181 // Symbian 2nd phase constructor can leave. |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 void COma2AgentRightsManager::ConstructL() |
|
185 { |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // COma2AgentRightsManager::NewL |
|
190 // Two-phased constructor. |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 COma2AgentRightsManager* COma2AgentRightsManager::NewL() |
|
194 { |
|
195 COma2AgentRightsManager* self = new( ELeave ) COma2AgentRightsManager; |
|
196 |
|
197 CleanupStack::PushL( self ); |
|
198 self->ConstructL(); |
|
199 CleanupStack::Pop(); |
|
200 |
|
201 return self; |
|
202 } |
|
203 |
|
204 |
|
205 // Destructor |
|
206 COma2AgentRightsManager::~COma2AgentRightsManager() |
|
207 { |
|
208 } |
|
209 |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // COma2AgentRightsManager::?member_function |
|
213 // ?implementation_description |
|
214 // (other items were commented in a header). |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 void COma2AgentRightsManager::ListAllRightsL( |
|
218 RStreamablePtrArray<CRightsInfo>& aArray) const |
|
219 { |
|
220 RDRMRightsClient client; |
|
221 RPointerArray<CDRMPermission> permissions; |
|
222 RPointerArray<HBufC8> idList; |
|
223 TCleanupItem permCleanup(PointerArrayResetDestroyAndClose<CDRMPermission>, |
|
224 &permissions); |
|
225 TCleanupItem idCleanup(PointerArrayResetDestroyAndClose<HBufC8>, |
|
226 &idList); |
|
227 TInt i; |
|
228 TInt j; |
|
229 |
|
230 User::LeaveIfError(client.Connect()); |
|
231 CleanupClosePushL(client); |
|
232 User::LeaveIfError(client.ExportContentIDList(idList)); |
|
233 CleanupStack::PushL(idCleanup); |
|
234 |
|
235 for (j = 0; j < idList.Count(); j++) |
|
236 { |
|
237 client.GetDBEntriesL(*idList[j], permissions); |
|
238 CleanupStack::PushL(permCleanup); |
|
239 for (i = 0; i < permissions.Count(); i++) |
|
240 { |
|
241 aArray.AppendL(ConvertToRightsInfoL(permissions[i], *idList[j])); |
|
242 } |
|
243 |
|
244 CleanupStack::PopAndDestroy(1); // permCleanup |
|
245 } |
|
246 CleanupStack::PopAndDestroy(2); // idCleanup, client |
|
247 } |
|
248 |
|
249 void COma2AgentRightsManager::ListRightsL( |
|
250 RStreamablePtrArray<CRightsInfo>& aArray, |
|
251 const TDesC& aUri) const |
|
252 { |
|
253 TVirtualPathPtr ptr(aUri, KDefaultContentObject); |
|
254 ListRightsL(aArray, ptr); |
|
255 } |
|
256 |
|
257 void COma2AgentRightsManager::ListRightsL( |
|
258 RStreamablePtrArray<CRightsInfo>& aArray, |
|
259 TVirtualPathPtr& aVirtualPath) const |
|
260 { |
|
261 RPointerArray<CDRMPermission> permissions; |
|
262 RDRMRightsClient client; |
|
263 TCleanupItem listCleanup(PointerArrayResetDestroyAndClose<CDRMPermission>, |
|
264 &permissions); |
|
265 CDcfCommon* dcf = NULL; |
|
266 CDRMPermission* permission = NULL; |
|
267 RFs fs; |
|
268 TInt i; |
|
269 TInt error; |
|
270 TUint32 reason = 0; |
|
271 |
|
272 User::LeaveIfError(client.Connect()); |
|
273 CleanupClosePushL(client); |
|
274 User::LeaveIfError(fs.Connect()); |
|
275 User::LeaveIfError(fs.ShareAuto()); |
|
276 CleanupClosePushL(fs); |
|
277 dcf = CDcfCommon::NewL(aVirtualPath.URI(), &fs); |
|
278 if (dcf == NULL) |
|
279 { |
|
280 User::Leave(KErrArgument); |
|
281 } |
|
282 CleanupStack::PushL(dcf); |
|
283 User::LeaveIfError(dcf->OpenPart(aVirtualPath.UniqueId())); |
|
284 |
|
285 TRAP(error, permission = client.GetActiveRightsL(EUnknown, *dcf->iContentID, reason)); |
|
286 if (permission != NULL) |
|
287 { |
|
288 CleanupStack::PushL(permission); |
|
289 aArray.AppendL(ConvertToRightsInfoL(permission, *dcf->iContentID)); |
|
290 CleanupStack::PopAndDestroy(); // permission |
|
291 } |
|
292 |
|
293 TRAP(error, client.GetDBEntriesL(*dcf->iContentID, permissions)); |
|
294 CleanupStack::PushL(listCleanup); |
|
295 |
|
296 for (i = 0; i < permissions.Count(); i++) |
|
297 { |
|
298 aArray.AppendL(ConvertToRightsInfoL(permissions[i], *dcf->iContentID)); |
|
299 } |
|
300 |
|
301 CleanupStack::PopAndDestroy(4); // listCleanup, dcf, fs, client |
|
302 } |
|
303 |
|
304 void COma2AgentRightsManager::ListContentL( |
|
305 RStreamablePtrArray<CVirtualPath>& aArray, |
|
306 CRightsInfo& aRightsInfo) const |
|
307 { |
|
308 RDRMRightsClient client; |
|
309 HBufC8* contentId = NULL; |
|
310 CDcfRep* rep = NULL; |
|
311 CDcfEntry* entry = NULL; |
|
312 CVirtualPath* path = NULL; |
|
313 TInt n; |
|
314 |
|
315 User::LeaveIfError(client.Connect()); |
|
316 CleanupClosePushL(client); |
|
317 n = aRightsInfo.UniqueId().Locate(0); |
|
318 if (n == KErrNotFound) |
|
319 { |
|
320 n = aRightsInfo.UniqueId().Length(); |
|
321 } |
|
322 contentId = CnvUtfConverter::ConvertFromUnicodeToUtf8L( |
|
323 aRightsInfo.UniqueId().Left(n)); |
|
324 CleanupStack::PushL(contentId); |
|
325 rep = CDcfRep::NewL(); |
|
326 CleanupStack::PushL(rep); |
|
327 rep->OrderListL(); |
|
328 entry = rep->NextL(); |
|
329 while (entry != NULL) |
|
330 { |
|
331 CleanupStack::PushL(entry); |
|
332 path = CVirtualPath::NewL(TVirtualPathPtr(entry->FileName(), |
|
333 KDefaultContentObject)); |
|
334 aArray.AppendL(path); |
|
335 CleanupStack::PopAndDestroy(); // entry |
|
336 entry = rep->NextL(); |
|
337 } |
|
338 |
|
339 CleanupStack::PopAndDestroy(3); // rep, contentId, client |
|
340 } |
|
341 |
|
342 MAgentRightsBase* COma2AgentRightsManager::GetRightsDataL( |
|
343 const CRightsInfo& aRightsInfo) const |
|
344 { |
|
345 RDRMRightsClient client; |
|
346 CDRMPermission* permission = NULL; |
|
347 TInt uniqueId; |
|
348 HBufC8* contentId = NULL; |
|
349 CDRMRights* rights = NULL; |
|
350 CDRMAsset* asset = NULL; |
|
351 TInt n; |
|
352 |
|
353 User::LeaveIfError(client.Connect()); |
|
354 CleanupClosePushL(client); |
|
355 rights = CDRMRights::NewL(); |
|
356 CleanupStack::PushL(rights); |
|
357 n = aRightsInfo.UniqueId().Locate(0); |
|
358 contentId = CnvUtfConverter::ConvertFromUnicodeToUtf8L( |
|
359 aRightsInfo.UniqueId().Left(n)); |
|
360 CleanupStack::PushL(contentId); |
|
361 TLex lex(aRightsInfo.UniqueId().Right( |
|
362 aRightsInfo.UniqueId().Length() - n - 1)); |
|
363 User::LeaveIfError(lex.Val(uniqueId)); |
|
364 permission = client.GetDbEntryL(*contentId, uniqueId); |
|
365 if (permission != NULL) |
|
366 { |
|
367 CleanupStack::PushL(permission); |
|
368 asset = CDRMAsset::NewL(); |
|
369 CleanupStack::PushL(asset); |
|
370 asset->iUid = contentId->AllocL(); |
|
371 if (permission->iParentUID) |
|
372 { |
|
373 asset->iParentRights = permission->iParentUID->AllocL(); |
|
374 } |
|
375 rights->SetPermissionL(*permission); |
|
376 rights->SetAssetL(*asset); |
|
377 CleanupStack::PopAndDestroy(2); // asset, permission |
|
378 } |
|
379 CleanupStack::Pop(); // rights |
|
380 CleanupStack::PopAndDestroy(2); // contentId, client |
|
381 |
|
382 return rights; |
|
383 } |
|
384 |
|
385 TInt COma2AgentRightsManager::DeleteRightsObject( |
|
386 const CRightsInfo& aRightsInfo) |
|
387 { |
|
388 TInt error = KErrNone; |
|
389 TRAP( error, DoDeleteRightsObject(aRightsInfo)); |
|
390 return error; |
|
391 } |
|
392 |
|
393 TInt COma2AgentRightsManager::DeleteAllRightsObjects( |
|
394 const TVirtualPathPtr& aVirtualPath) |
|
395 { |
|
396 TInt error = KErrNone; |
|
397 TRAP( error, DoDeleteAllRightsObjectsL(aVirtualPath)); |
|
398 return error; |
|
399 } |
|
400 |
|
401 TInt COma2AgentRightsManager::SetProperty( |
|
402 TAgentProperty /*aProperty*/, |
|
403 TInt /*aValue*/) |
|
404 { |
|
405 return KErrCANotSupported; |
|
406 } |
|
407 |
|
408 |
|
409 |