|
1 /* |
|
2 * Copyright (c) 2007 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: Part of the Implementation of the DRM Rights Database |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <s32strm.h> |
|
22 #include <s32mem.h> |
|
23 #include <caf/caf.h> |
|
24 #include "DRMPermission.h" |
|
25 #include "DRMConstraint.h" |
|
26 #include "drmlog.h" |
|
27 #include "OMA2Agent.h" |
|
28 |
|
29 // EXTERNAL DATA STRUCTURES |
|
30 |
|
31 // EXTERNAL FUNCTION PROTOTYPES |
|
32 |
|
33 // CONSTANTS |
|
34 |
|
35 // Synchronizing marker in the beginning of the stream in order to synchronize |
|
36 // to externalized Permission object having the new structure. |
|
37 const TInt32 KSyncMark = 0xAFCE; |
|
38 |
|
39 // Old and new version number of the Permission object |
|
40 const TInt8 KVersion3_2_0 = 0; |
|
41 const TInt8 KVersion3_2_1 = 1; |
|
42 |
|
43 |
|
44 const TInt KSanityDataLengthLow = 0; |
|
45 const TInt KSanityDataLengthHigh = 32768; |
|
46 |
|
47 // MACROS |
|
48 |
|
49 // LOCAL CONSTANTS AND MACROS |
|
50 |
|
51 // MODULE DATA STRUCTURES |
|
52 |
|
53 // LOCAL FUNCTION PROTOTYPES |
|
54 |
|
55 // FORWARD DECLARATIONS |
|
56 |
|
57 // ============================= LOCAL FUNCTIONS =============================== |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // SanitizeL |
|
61 // Performs a sanity check on length parameters |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 LOCAL_C void SanitizeL( TInt aParam ) |
|
65 { |
|
66 if( aParam < KSanityDataLengthLow || aParam > KSanityDataLengthHigh ) |
|
67 { |
|
68 User::Leave(KErrArgument); |
|
69 } |
|
70 } |
|
71 |
|
72 // ============================ MEMBER FUNCTIONS =============================== |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CDRMPermission::NewLC |
|
79 // Two-phased constructor. |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 EXPORT_C CDRMPermission* CDRMPermission::NewLC() |
|
83 { |
|
84 CDRMPermission* self = new( ELeave ) CDRMPermission(); |
|
85 CleanupStack::PushL( self ); |
|
86 self->ConstructL(); |
|
87 |
|
88 return self; |
|
89 }; |
|
90 |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CDRMPermission::NewL |
|
94 // Two-phased constructor. |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 EXPORT_C CDRMPermission* CDRMPermission::NewL() |
|
98 { |
|
99 CDRMPermission* self = NewLC(); |
|
100 CleanupStack::Pop(); |
|
101 |
|
102 return self; |
|
103 }; |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // Default constructor |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 CDRMPermission::CDRMPermission() : |
|
110 iSyncMark( KSyncMark ), |
|
111 iVersion( KVersion3_2_1 ), // Version number for differentiation in |
|
112 // InternalizeL. |
|
113 iUniqueID( 0 ), |
|
114 iOriginalInsertTime( Time::NullTTime() ), |
|
115 iTopLevel( NULL ), |
|
116 iPlay( NULL ), |
|
117 iDisplay( NULL ), |
|
118 iExecute(NULL ), |
|
119 iPrint( NULL ), |
|
120 iExportMode( ECopy ), |
|
121 iParentUID( NULL ), |
|
122 iRoID( NULL ), |
|
123 iDomainID( NULL ), |
|
124 iAvailableRights( 0 ), |
|
125 iInfoBits( 0 ), |
|
126 iOnExpiredUrl( NULL ) |
|
127 { |
|
128 iRiId.SetLength( KRiIdSize ); |
|
129 iRiId.Fill( 0 ); |
|
130 }; |
|
131 |
|
132 |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // Destructor |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 EXPORT_C CDRMPermission::~CDRMPermission() |
|
139 { |
|
140 if( iTopLevel ) |
|
141 { |
|
142 delete iTopLevel; |
|
143 iTopLevel = NULL; |
|
144 } |
|
145 |
|
146 if( iPlay ) |
|
147 { |
|
148 delete iPlay; |
|
149 iPlay = NULL; |
|
150 } |
|
151 |
|
152 if( iDisplay ) |
|
153 { |
|
154 delete iDisplay; |
|
155 iDisplay = NULL; |
|
156 } |
|
157 |
|
158 if( iExecute ) |
|
159 { |
|
160 delete iExecute; |
|
161 iExecute = NULL; |
|
162 } |
|
163 |
|
164 if( iExport ) |
|
165 { |
|
166 delete iExport; |
|
167 iExport = NULL; |
|
168 } |
|
169 |
|
170 if( iPrint ) |
|
171 { |
|
172 delete iPrint; |
|
173 iPrint = NULL; |
|
174 } |
|
175 |
|
176 if( iParentUID ) |
|
177 { |
|
178 delete iParentUID; |
|
179 iParentUID = NULL; |
|
180 } |
|
181 |
|
182 if( iRoID ) |
|
183 { |
|
184 delete iRoID; |
|
185 iRoID = NULL; |
|
186 } |
|
187 |
|
188 if( iDomainID ) |
|
189 { |
|
190 delete iDomainID; |
|
191 iDomainID = NULL; |
|
192 } |
|
193 |
|
194 if( iOnExpiredUrl ) |
|
195 { |
|
196 delete iOnExpiredUrl; |
|
197 iOnExpiredUrl = NULL; |
|
198 } |
|
199 }; |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CDRMPermission::ExternalizeL |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 EXPORT_C void CDRMPermission::ExternalizeL( RWriteStream& aStream ) const |
|
206 { |
|
207 |
|
208 // used for the buffers |
|
209 TInt dataLength = 0; |
|
210 |
|
211 // Used for mode |
|
212 TUint8 exportMode = 0; |
|
213 |
|
214 // Write the synchronizing marker |
|
215 aStream.WriteInt32L( iSyncMark ); |
|
216 |
|
217 // Write the version number |
|
218 aStream.WriteInt32L( iVersion ); |
|
219 |
|
220 // Unique ID of the permission |
|
221 aStream.WriteUint32L( iUniqueID ); |
|
222 |
|
223 // The original insertion time |
|
224 WriteInt64L( iOriginalInsertTime.Int64(), aStream ); |
|
225 |
|
226 // Top level constraint |
|
227 if( !iTopLevel ) |
|
228 { |
|
229 User::Leave( KErrNotReady ); |
|
230 } |
|
231 iTopLevel->ExternalizeL( aStream ); |
|
232 |
|
233 // Play constraint |
|
234 if( !iPlay ) |
|
235 { |
|
236 User::Leave( KErrNotReady ); |
|
237 } |
|
238 iPlay->ExternalizeL( aStream ); |
|
239 |
|
240 // Display constraint |
|
241 if( !iDisplay ) |
|
242 { |
|
243 User::Leave( KErrNotReady ); |
|
244 } |
|
245 iDisplay->ExternalizeL( aStream ); |
|
246 |
|
247 // Execute constraint |
|
248 if( !iExecute ) |
|
249 { |
|
250 User::Leave( KErrNotReady ); |
|
251 } |
|
252 iExecute->ExternalizeL( aStream ); |
|
253 |
|
254 // Print constraint |
|
255 if( !iPrint ) |
|
256 { |
|
257 User::Leave( KErrNotReady ); |
|
258 } |
|
259 iPrint->ExternalizeL( aStream ); |
|
260 |
|
261 // Export constraint |
|
262 if( !iExport ) |
|
263 { |
|
264 User::Leave( KErrNotReady ); |
|
265 } |
|
266 iExport->ExternalizeL( aStream ); |
|
267 |
|
268 // Export mode |
|
269 exportMode = iExportMode; |
|
270 aStream.WriteUint8L( exportMode ); |
|
271 |
|
272 // Content id of the parent rights object |
|
273 dataLength = 0; |
|
274 if( iParentUID ) |
|
275 { |
|
276 dataLength = iParentUID->Length(); |
|
277 } |
|
278 aStream.WriteInt32L( dataLength ); |
|
279 |
|
280 if( dataLength ) |
|
281 { |
|
282 aStream.WriteL( iParentUID->Des() ); |
|
283 } |
|
284 |
|
285 // Rights Object if of the rights delivery container |
|
286 dataLength = 0; |
|
287 if( iRoID ) |
|
288 { |
|
289 dataLength = iRoID->Length(); |
|
290 } |
|
291 aStream.WriteInt32L( dataLength ); |
|
292 |
|
293 if( dataLength ) |
|
294 { |
|
295 aStream.WriteL( iRoID->Des() ); |
|
296 } |
|
297 |
|
298 // Domain identifier |
|
299 dataLength = 0; |
|
300 if( iDomainID ) |
|
301 { |
|
302 dataLength = iDomainID->Length(); |
|
303 } |
|
304 aStream.WriteInt32L( dataLength ); |
|
305 |
|
306 if( dataLength ) |
|
307 { |
|
308 aStream.WriteL( iDomainID->Des() ); |
|
309 } |
|
310 |
|
311 // Available rights |
|
312 aStream.WriteUint16L( iAvailableRights ); |
|
313 |
|
314 // Version number of the rights object |
|
315 aStream.WriteUint16L( iRightsObjectVersion.iVersionMain ); |
|
316 aStream.WriteUint16L( iRightsObjectVersion.iVersionSub ); |
|
317 |
|
318 // Info bits |
|
319 aStream.WriteInt32L( iInfoBits ); |
|
320 |
|
321 aStream.WriteL( iRiId ); |
|
322 |
|
323 // OnExpiredUrl |
|
324 dataLength = 0; |
|
325 if ( iOnExpiredUrl ) |
|
326 { |
|
327 dataLength = iOnExpiredUrl->Length(); |
|
328 } |
|
329 aStream.WriteInt32L( dataLength ); |
|
330 |
|
331 if ( dataLength ) |
|
332 { |
|
333 aStream.WriteL( iOnExpiredUrl->Des() ); |
|
334 } |
|
335 |
|
336 // For future use |
|
337 aStream.WriteInt32L( 0 ); |
|
338 |
|
339 }; |
|
340 |
|
341 // ----------------------------------------------------------------------------- |
|
342 // CDRMPermission::InternalizeL |
|
343 // ----------------------------------------------------------------------------- |
|
344 // |
|
345 EXPORT_C void CDRMPermission::InternalizeL( RReadStream& aStream ) |
|
346 { |
|
347 |
|
348 TInt64 timeData = 0; |
|
349 |
|
350 // used for the buffers |
|
351 TInt dataLength = 0; |
|
352 TPtr8 dataBuffer(NULL,0,0); |
|
353 HBufC8* dataPart = NULL; |
|
354 |
|
355 // (Possible) synchronizing marker |
|
356 iSyncMark = aStream.ReadInt32L(); |
|
357 |
|
358 if ( iSyncMark == KSyncMark ) |
|
359 { |
|
360 |
|
361 // The internalized Permission object has the new structure if the |
|
362 // synchronizing marker is found in the beginning of the stream. In that |
|
363 // case read version number and Unique ID. |
|
364 iVersion = aStream.ReadInt32L(); |
|
365 |
|
366 // Unique ID of the permission |
|
367 iUniqueID = aStream.ReadUint32L(); |
|
368 |
|
369 } |
|
370 else |
|
371 { |
|
372 |
|
373 // The internalized Permission object has the old structure. The |
|
374 // stream information that was read to iSyncMark is actually the |
|
375 // Unique ID. |
|
376 iUniqueID = (TDRMUniqueID)iSyncMark; |
|
377 iVersion = KVersion3_2_0; // Old version, needed for differentation |
|
378 |
|
379 } |
|
380 |
|
381 // The original insertion time |
|
382 ReadInt64L( timeData, aStream ); |
|
383 iOriginalInsertTime = timeData; |
|
384 |
|
385 // Top level constraint |
|
386 if( !iTopLevel ) |
|
387 { |
|
388 iTopLevel = CDRMConstraint::NewL(); |
|
389 } |
|
390 |
|
391 iTopLevel->InternalizeL( aStream ); |
|
392 |
|
393 // Play constraint |
|
394 if( !iPlay ) |
|
395 { |
|
396 iPlay = CDRMConstraint::NewL(); |
|
397 } |
|
398 |
|
399 iPlay->InternalizeL( aStream ); |
|
400 |
|
401 // Display constraint |
|
402 if( !iDisplay ) |
|
403 { |
|
404 iDisplay = CDRMConstraint::NewL(); |
|
405 } |
|
406 |
|
407 iDisplay->InternalizeL( aStream ); |
|
408 |
|
409 // Execute constraint |
|
410 if( !iExecute ) |
|
411 { |
|
412 iExecute = CDRMConstraint::NewL(); |
|
413 } |
|
414 |
|
415 iExecute->InternalizeL( aStream ); |
|
416 |
|
417 // Print constraint |
|
418 if( !iPrint) |
|
419 { |
|
420 iPrint = CDRMConstraint::NewL(); |
|
421 } |
|
422 |
|
423 iPrint->InternalizeL( aStream ); |
|
424 |
|
425 // Export constraint |
|
426 |
|
427 iExport->InternalizeL( aStream ); |
|
428 |
|
429 // Export mode |
|
430 iExportMode = static_cast<TExportMode>(aStream.ReadUint8L()); |
|
431 |
|
432 // Content id of the parent rights object |
|
433 dataLength = aStream.ReadInt32L(); |
|
434 |
|
435 SanitizeL( dataLength ); |
|
436 |
|
437 if( dataLength > 0 ) |
|
438 { |
|
439 // Reserve a new buffer: |
|
440 dataPart = HBufC8::NewMaxLC( dataLength ); |
|
441 |
|
442 // Set the read buffer: |
|
443 dataBuffer.Set(const_cast<TUint8*>(dataPart->Ptr()), 0, dataLength); |
|
444 |
|
445 // Read the data: |
|
446 aStream.ReadL( dataBuffer ); |
|
447 |
|
448 // Pop the buffer |
|
449 CleanupStack::Pop(); // dataPart |
|
450 |
|
451 // If an old content identifier exists delete it |
|
452 if( iParentUID ) |
|
453 { |
|
454 delete iParentUID; |
|
455 iParentUID = NULL; |
|
456 } |
|
457 |
|
458 // assign the new content id |
|
459 iParentUID = dataPart; |
|
460 } |
|
461 else |
|
462 { |
|
463 // If an old individual exists delete it |
|
464 if( iParentUID ) |
|
465 { |
|
466 delete iParentUID; |
|
467 iParentUID = NULL; |
|
468 } |
|
469 } |
|
470 |
|
471 |
|
472 // Rights Object if of the rights delivery container |
|
473 // Read the individual |
|
474 dataLength = aStream.ReadInt32L(); |
|
475 |
|
476 SanitizeL( dataLength ); |
|
477 |
|
478 if( dataLength > 0 ) |
|
479 { |
|
480 // Reserve a new buffer: |
|
481 dataPart = HBufC8::NewMaxLC( dataLength ); |
|
482 |
|
483 // Set the read buffer: |
|
484 dataBuffer.Set(const_cast<TUint8*>(dataPart->Ptr()), 0, dataLength); |
|
485 |
|
486 // Read the data: |
|
487 aStream.ReadL( dataBuffer ); |
|
488 |
|
489 // Pop the buffer |
|
490 CleanupStack::Pop(); // dataPart |
|
491 |
|
492 // If an old content identifier exists delete it |
|
493 if( iRoID ) |
|
494 { |
|
495 delete iRoID; |
|
496 iRoID = NULL; |
|
497 } |
|
498 |
|
499 // assign the new content id |
|
500 iRoID = dataPart; |
|
501 } |
|
502 else |
|
503 { |
|
504 // If an old individual exists delete it |
|
505 if( iRoID ) |
|
506 { |
|
507 delete iRoID; |
|
508 iRoID = NULL; |
|
509 } |
|
510 } |
|
511 |
|
512 // Domain identifier |
|
513 dataLength = aStream.ReadInt32L(); |
|
514 |
|
515 SanitizeL( dataLength ); |
|
516 |
|
517 if( dataLength > 0 ) |
|
518 { |
|
519 // Reserve a new buffer: |
|
520 dataPart = HBufC8::NewMaxLC( dataLength ); |
|
521 |
|
522 // Set the read buffer: |
|
523 dataBuffer.Set(const_cast<TUint8*>(dataPart->Ptr()), 0, dataLength); |
|
524 |
|
525 // Read the data: |
|
526 aStream.ReadL( dataBuffer ); |
|
527 |
|
528 // Pop the buffer |
|
529 CleanupStack::Pop(); // dataPart |
|
530 |
|
531 // If an old content identifier exists delete it |
|
532 if( iDomainID ) |
|
533 { |
|
534 delete iDomainID; |
|
535 iDomainID = NULL; |
|
536 } |
|
537 |
|
538 // assign the new content id |
|
539 iDomainID = dataPart; |
|
540 } |
|
541 else |
|
542 { |
|
543 // If an old individual exists delete it |
|
544 if( iDomainID ) |
|
545 { |
|
546 delete iDomainID; |
|
547 iDomainID = NULL; |
|
548 } |
|
549 } |
|
550 |
|
551 |
|
552 // Available rights |
|
553 iAvailableRights = aStream.ReadUint16L(); |
|
554 |
|
555 // Version number of the rights object |
|
556 iRightsObjectVersion.iVersionMain = aStream.ReadUint16L(); |
|
557 iRightsObjectVersion.iVersionSub = aStream.ReadUint16L(); |
|
558 |
|
559 // Information bits |
|
560 iInfoBits = aStream.ReadInt32L(); |
|
561 |
|
562 aStream.ReadL( iRiId ); |
|
563 |
|
564 // New structure of Permission object |
|
565 if ( iVersion == KVersion3_2_1 ) |
|
566 { |
|
567 |
|
568 // OnExpiredUrl |
|
569 dataLength = aStream.ReadInt32L(); |
|
570 |
|
571 SanitizeL( dataLength ); |
|
572 |
|
573 if( dataLength > 0 ) |
|
574 { |
|
575 |
|
576 // Reserve a new buffer: |
|
577 dataPart = HBufC8::NewMaxLC( dataLength ); |
|
578 |
|
579 // Set the read buffer: |
|
580 dataBuffer.Set(const_cast<TUint8*>(dataPart->Ptr()), 0, |
|
581 dataLength); |
|
582 |
|
583 // Read the data: |
|
584 aStream.ReadL( dataBuffer ); |
|
585 |
|
586 // Pop the buffer |
|
587 CleanupStack::Pop(); // dataPart |
|
588 |
|
589 // If an old OnExpiredUrl exists delete it |
|
590 if( iOnExpiredUrl ) |
|
591 { |
|
592 delete iOnExpiredUrl; |
|
593 iOnExpiredUrl = NULL; |
|
594 } |
|
595 |
|
596 // assign the new OnExpiredUrl |
|
597 iOnExpiredUrl = dataPart; |
|
598 } |
|
599 else |
|
600 { |
|
601 // If an old OnExpiredUrl exists delete it |
|
602 if( iOnExpiredUrl ) |
|
603 { |
|
604 delete iOnExpiredUrl; |
|
605 iOnExpiredUrl = NULL; |
|
606 } |
|
607 } |
|
608 |
|
609 // For future use or development, reads the data at the end of the stream |
|
610 dataLength = aStream.ReadInt32L(); |
|
611 |
|
612 SanitizeL( dataLength ); |
|
613 |
|
614 if ( dataLength > 0 ) |
|
615 { |
|
616 // Reserve a new buffer: |
|
617 dataPart = HBufC8::NewMaxLC( dataLength ); |
|
618 |
|
619 // Set the read buffer: |
|
620 dataBuffer.Set(const_cast<TUint8*>(dataPart->Ptr()), 0, dataLength); |
|
621 |
|
622 // Read the data: |
|
623 aStream.ReadL( dataBuffer ); |
|
624 |
|
625 // Delete the buffer |
|
626 CleanupStack::PopAndDestroy( dataPart ); |
|
627 } |
|
628 } |
|
629 |
|
630 // Permission can be considered to have the new structure after |
|
631 // internalization. |
|
632 if ( iVersion == KVersion3_2_0 ) |
|
633 { |
|
634 iSyncMark = KSyncMark; |
|
635 iVersion = KVersion3_2_1; |
|
636 } |
|
637 |
|
638 }; |
|
639 |
|
640 // ----------------------------------------------------------------------------- |
|
641 // CDRMPermission::Stateful |
|
642 // ----------------------------------------------------------------------------- |
|
643 // |
|
644 EXPORT_C TBool CDRMPermission::Stateful() const |
|
645 { |
|
646 if( ( (iAvailableRights & ERightsTopLevel) && iTopLevel->Stateful() ) ) |
|
647 { |
|
648 return ETrue; |
|
649 } |
|
650 else if( (iAvailableRights & ERightsPlay) && iPlay->Stateful() ) |
|
651 { |
|
652 return ETrue; |
|
653 } |
|
654 else if( (iAvailableRights & ERightsDisplay) && iDisplay->Stateful() ) |
|
655 { |
|
656 return ETrue; |
|
657 } |
|
658 else if( (iAvailableRights & ERightsExecute) && iExecute->Stateful() ) |
|
659 { |
|
660 return ETrue; |
|
661 } |
|
662 else if( (iAvailableRights & ERightsPrint) && iPrint->Stateful() ) |
|
663 { |
|
664 return ETrue; |
|
665 } |
|
666 return EFalse; |
|
667 }; |
|
668 |
|
669 // ----------------------------------------------------------------------------- |
|
670 // CDRMPermission::SoftwareConstrained |
|
671 // ----------------------------------------------------------------------------- |
|
672 // |
|
673 EXPORT_C TBool CDRMPermission::SoftwareConstrained() const |
|
674 { |
|
675 if ( (iAvailableRights & ERightsTopLevel) && |
|
676 iTopLevel->iActiveConstraints & ( EConstraintVendor | EConstraintSoftware ) ) |
|
677 { |
|
678 return ETrue; |
|
679 } |
|
680 else if ( (iAvailableRights & ERightsPlay) && |
|
681 iPlay->iActiveConstraints & ( EConstraintVendor | EConstraintSoftware ) ) |
|
682 { |
|
683 return ETrue; |
|
684 } |
|
685 else if ( (iAvailableRights & ERightsDisplay) && |
|
686 iDisplay->iActiveConstraints & ( EConstraintVendor | EConstraintSoftware ) ) |
|
687 { |
|
688 return ETrue; |
|
689 } |
|
690 else if ( (iAvailableRights & ERightsExecute) && |
|
691 iExecute->iActiveConstraints & ( EConstraintVendor | EConstraintSoftware ) ) |
|
692 { |
|
693 return ETrue; |
|
694 } |
|
695 else if ( (iAvailableRights & ERightsPrint) && |
|
696 iPrint->iActiveConstraints & ( EConstraintVendor | EConstraintSoftware ) ) |
|
697 { |
|
698 return ETrue; |
|
699 } |
|
700 return EFalse; |
|
701 }; |
|
702 |
|
703 // ----------------------------------------------------------------------------- |
|
704 // CDRMPermission::Child |
|
705 // ----------------------------------------------------------------------------- |
|
706 // |
|
707 EXPORT_C TBool CDRMPermission::Child() const |
|
708 { |
|
709 return iParentUID ? ETrue : EFalse; |
|
710 }; |
|
711 |
|
712 // ----------------------------------------------------------------------------- |
|
713 // CDRMPermission::Size |
|
714 // ----------------------------------------------------------------------------- |
|
715 // |
|
716 EXPORT_C TInt CDRMPermission::Size() const |
|
717 { |
|
718 TInt size = 0; |
|
719 |
|
720 // synchronizing marker |
|
721 size += sizeof(TInt32); |
|
722 |
|
723 // Version number |
|
724 size += sizeof(TInt32); |
|
725 |
|
726 // Unique ID of the permission |
|
727 size += sizeof(TDRMUniqueID); |
|
728 |
|
729 // The original insertion time |
|
730 size += sizeof(TTime); |
|
731 |
|
732 // Top level constraint |
|
733 size += iTopLevel->Size(); |
|
734 |
|
735 // Play constraint |
|
736 size += iPlay->Size(); |
|
737 |
|
738 // Display constraint |
|
739 size += iDisplay->Size(); |
|
740 |
|
741 // Execute constraint |
|
742 size += iExecute->Size(); |
|
743 |
|
744 // Print constraint |
|
745 size += iPrint->Size(); |
|
746 |
|
747 // Export constraint |
|
748 size += iExport->Size(); |
|
749 |
|
750 // Export mode |
|
751 size += sizeof(TUint8); |
|
752 |
|
753 // Content id of the parent rights object |
|
754 size += sizeof(TInt32); |
|
755 |
|
756 if( iParentUID ) |
|
757 { |
|
758 size += iParentUID->Size(); |
|
759 } |
|
760 |
|
761 // Rights Object if of the rights delivery container |
|
762 size += sizeof(TInt32); |
|
763 |
|
764 if( iRoID ) |
|
765 { |
|
766 size += iRoID->Size(); |
|
767 } |
|
768 |
|
769 // Domain identifier |
|
770 size += sizeof(TInt32); |
|
771 |
|
772 if( iDomainID ) |
|
773 { |
|
774 size += iDomainID->Size(); |
|
775 } |
|
776 |
|
777 // Available rights |
|
778 size += sizeof(TUint16); |
|
779 |
|
780 // Version number of the rights object |
|
781 size += sizeof(TUint16); |
|
782 size += sizeof(TUint16); |
|
783 |
|
784 // infobits |
|
785 size += sizeof(TInt32); |
|
786 |
|
787 // RI ID |
|
788 size += KRiIdSize; |
|
789 |
|
790 // OnExpiredUrl |
|
791 size += sizeof(TInt32); |
|
792 |
|
793 if ( iOnExpiredUrl ) |
|
794 { |
|
795 size += iOnExpiredUrl->Size(); |
|
796 } |
|
797 |
|
798 // For future use |
|
799 size += sizeof(TInt32); |
|
800 |
|
801 return size; |
|
802 |
|
803 }; |
|
804 |
|
805 // ----------------------------------------------------------------------------- |
|
806 // CDRMPermission::ConstraintForIntent |
|
807 // ----------------------------------------------------------------------------- |
|
808 // |
|
809 EXPORT_C CDRMConstraint* CDRMPermission::ConstraintForIntent( |
|
810 const ContentAccess::TIntent aIntent ) |
|
811 { |
|
812 CDRMConstraint* r = NULL; |
|
813 |
|
814 switch ( aIntent ) |
|
815 { |
|
816 case ContentAccess::EPlay: |
|
817 if ( iAvailableRights & ERightsPlay ) |
|
818 { |
|
819 r = iPlay; |
|
820 } |
|
821 break; |
|
822 case ContentAccess::EView: |
|
823 if ( iAvailableRights & ERightsDisplay ) |
|
824 { |
|
825 r = iDisplay; |
|
826 } |
|
827 break; |
|
828 case ContentAccess::EExecute: |
|
829 if ( iAvailableRights & ERightsExecute ) |
|
830 { |
|
831 r = iExecute; |
|
832 } |
|
833 break; |
|
834 case ContentAccess::EPrint: |
|
835 if ( iAvailableRights & ERightsPrint ) |
|
836 { |
|
837 r = iPrint; |
|
838 } |
|
839 break; |
|
840 } |
|
841 |
|
842 return r; |
|
843 } |
|
844 |
|
845 // ----------------------------------------------------------------------------- |
|
846 // CDRMPermission::ConstraintForIntent |
|
847 // ----------------------------------------------------------------------------- |
|
848 // |
|
849 EXPORT_C CDRMConstraint* CDRMPermission::TopLevelConstraint() |
|
850 { |
|
851 if ( iAvailableRights & ERightsTopLevel ) |
|
852 { |
|
853 return iTopLevel; |
|
854 } |
|
855 else |
|
856 { |
|
857 return NULL; |
|
858 } |
|
859 } |
|
860 |
|
861 // ----------------------------------------------------------------------------- |
|
862 // CDRMPermission::ConsumeRights |
|
863 // ----------------------------------------------------------------------------- |
|
864 // |
|
865 EXPORT_C void CDRMPermission::ConsumeRights( const TIntent aIntent, const TTime& aCurrentTime ) |
|
866 { |
|
867 //__ASSERT_DEBUG( !( aIntent == ERightsTopLevel ), User::Leave( KErrArgument ) ); |
|
868 |
|
869 CDRMConstraint* constraint( TopLevelConstraint() ); |
|
870 |
|
871 if ( constraint ) |
|
872 { |
|
873 constraint->Consume( aCurrentTime ); |
|
874 } |
|
875 |
|
876 constraint = ConstraintForIntent( aIntent ); |
|
877 if ( constraint ) |
|
878 { |
|
879 constraint->Consume( aCurrentTime ); |
|
880 } |
|
881 } |
|
882 |
|
883 // ----------------------------------------------------------------------------- |
|
884 // CDRMPermission::ImportL |
|
885 // ----------------------------------------------------------------------------- |
|
886 // |
|
887 EXPORT_C void CDRMPermission::ImportL( const TDesC8& aBuffer ) |
|
888 { |
|
889 TInt size = aBuffer.Size(); |
|
890 RMemReadStream stream( (TAny*)( aBuffer.Ptr() ), size ); |
|
891 CleanupClosePushL( stream ); |
|
892 |
|
893 InternalizeL( stream ); |
|
894 |
|
895 CleanupStack::PopAndDestroy(); // Stream |
|
896 }; |
|
897 |
|
898 |
|
899 // ----------------------------------------------------------------------------- |
|
900 // CDRMPermission::ExportL |
|
901 // ----------------------------------------------------------------------------- |
|
902 // |
|
903 EXPORT_C HBufC8* CDRMPermission::ExportL() const |
|
904 { |
|
905 TInt size = Size(); |
|
906 HBufC8* data = HBufC8::NewMaxLC( size ); |
|
907 |
|
908 RMemWriteStream stream( (TAny*)( data->Ptr() ), size ); |
|
909 CleanupClosePushL( stream ); |
|
910 |
|
911 ExternalizeL( stream ); |
|
912 |
|
913 CleanupStack::PopAndDestroy(); // Stream |
|
914 CleanupStack::Pop(); |
|
915 return data; |
|
916 }; |
|
917 |
|
918 // ----------------------------------------------------------------------------- |
|
919 // CDRMPermission::DuplicateL |
|
920 // ----------------------------------------------------------------------------- |
|
921 // |
|
922 EXPORT_C void CDRMPermission::DuplicateL( const CDRMPermission& aPermission ) |
|
923 { |
|
924 |
|
925 // Synchronizing marker |
|
926 iSyncMark = aPermission.iSyncMark; |
|
927 |
|
928 // Version number |
|
929 iVersion = aPermission.iVersion; |
|
930 |
|
931 // Unique ID of the permission |
|
932 iUniqueID = aPermission.iUniqueID; |
|
933 |
|
934 // The original insertion time |
|
935 iOriginalInsertTime = aPermission.iOriginalInsertTime; |
|
936 |
|
937 // Top level constraint |
|
938 if( !iTopLevel ) |
|
939 { |
|
940 iTopLevel = CDRMConstraint::NewL(); |
|
941 } |
|
942 iTopLevel->DuplicateL( *(aPermission.iTopLevel ) ); |
|
943 |
|
944 // Play constraint |
|
945 if( !iPlay ) |
|
946 { |
|
947 iPlay = CDRMConstraint::NewL(); |
|
948 } |
|
949 iPlay->DuplicateL( *(aPermission.iPlay ) ); |
|
950 |
|
951 // Display constraint |
|
952 if( !iDisplay ) |
|
953 { |
|
954 iDisplay = CDRMConstraint::NewL(); |
|
955 } |
|
956 iDisplay->DuplicateL( *(aPermission.iDisplay ) ); |
|
957 |
|
958 // Execute constraint |
|
959 if( !iExecute ) |
|
960 { |
|
961 iExecute = CDRMConstraint::NewL(); |
|
962 } |
|
963 iExecute->DuplicateL( *(aPermission.iExecute ) ); |
|
964 |
|
965 // Print constraint |
|
966 if( !iPrint ) |
|
967 { |
|
968 iPrint = CDRMConstraint::NewL(); |
|
969 } |
|
970 iPrint->DuplicateL( *(aPermission.iPrint ) ); |
|
971 |
|
972 // Export constraint |
|
973 if( !iExport ) |
|
974 { |
|
975 iExport = CDRMConstraint::NewL(); |
|
976 } |
|
977 iExport->DuplicateL( *(aPermission.iExport ) ); |
|
978 |
|
979 // Export mode |
|
980 iExportMode = aPermission.iExportMode; |
|
981 |
|
982 // Content id of the parent rights object |
|
983 if( iParentUID ) |
|
984 { |
|
985 delete iParentUID; |
|
986 iParentUID = NULL; |
|
987 } |
|
988 |
|
989 if( aPermission.iParentUID ) |
|
990 { |
|
991 iParentUID = aPermission.iParentUID->AllocL(); |
|
992 } |
|
993 |
|
994 // Rights Object if of the rights delivery container |
|
995 if( iRoID ) |
|
996 { |
|
997 delete iRoID; |
|
998 iRoID = NULL; |
|
999 } |
|
1000 |
|
1001 if( aPermission.iRoID ) |
|
1002 { |
|
1003 iRoID = aPermission.iRoID->AllocL(); |
|
1004 } |
|
1005 |
|
1006 // Domain identifier |
|
1007 if( iDomainID ) |
|
1008 { |
|
1009 delete iDomainID; |
|
1010 iDomainID = NULL; |
|
1011 } |
|
1012 |
|
1013 if( aPermission.iDomainID ) |
|
1014 { |
|
1015 iDomainID = aPermission.iDomainID->AllocL(); |
|
1016 } |
|
1017 // Available rights |
|
1018 iAvailableRights = aPermission.iAvailableRights; // Bitmask |
|
1019 |
|
1020 // Version number of the rights object |
|
1021 iRightsObjectVersion.iVersionMain = aPermission.iRightsObjectVersion.iVersionMain; |
|
1022 iRightsObjectVersion.iVersionSub = aPermission.iRightsObjectVersion.iVersionSub; |
|
1023 |
|
1024 // info bits |
|
1025 iInfoBits = aPermission.iInfoBits; |
|
1026 |
|
1027 // OnExpiredUrl |
|
1028 if ( iOnExpiredUrl ) |
|
1029 { |
|
1030 delete iOnExpiredUrl; |
|
1031 iOnExpiredUrl = NULL; |
|
1032 } |
|
1033 |
|
1034 if ( aPermission.iOnExpiredUrl ) |
|
1035 { |
|
1036 iOnExpiredUrl = aPermission.iOnExpiredUrl->AllocL(); |
|
1037 } |
|
1038 |
|
1039 }; |
|
1040 |
|
1041 |
|
1042 // ----------------------------------------------------------------------------- |
|
1043 // CDRMPermission::Expired |
|
1044 // ----------------------------------------------------------------------------- |
|
1045 // |
|
1046 EXPORT_C TBool CDRMPermission::Expired( const TTime& aTime ) |
|
1047 { |
|
1048 if( iTopLevel && iAvailableRights & ERightsTopLevel ) |
|
1049 { |
|
1050 if( iTopLevel->Expired( aTime ) ) |
|
1051 { |
|
1052 return ETrue; |
|
1053 } |
|
1054 } |
|
1055 |
|
1056 if( iPlay && iAvailableRights & ERightsPlay) |
|
1057 { |
|
1058 if( !iPlay->Expired( aTime ) ) |
|
1059 { |
|
1060 return EFalse; |
|
1061 } |
|
1062 } |
|
1063 |
|
1064 if( iDisplay && iAvailableRights & ERightsDisplay ) |
|
1065 { |
|
1066 if( !iDisplay->Expired( aTime ) ) |
|
1067 { |
|
1068 return EFalse; |
|
1069 } |
|
1070 } |
|
1071 |
|
1072 if( iExecute && iAvailableRights & ERightsExecute ) |
|
1073 { |
|
1074 if( !iExecute->Expired( aTime ) ) |
|
1075 { |
|
1076 return EFalse; |
|
1077 } |
|
1078 } |
|
1079 |
|
1080 if( iPrint && iAvailableRights & ERightsPrint ) |
|
1081 { |
|
1082 if( !iPrint->Expired( aTime ) ) |
|
1083 { |
|
1084 return EFalse; |
|
1085 } |
|
1086 } |
|
1087 |
|
1088 if( iExport && iAvailableRights & ERightsExport ) |
|
1089 { |
|
1090 if( !iExport->Expired( aTime ) ) |
|
1091 { |
|
1092 return EFalse; |
|
1093 } |
|
1094 } |
|
1095 |
|
1096 return ETrue; |
|
1097 }; |
|
1098 |
|
1099 |
|
1100 // ----------------------------------------------------------------------------- |
|
1101 // CDRMPermission::Expired |
|
1102 // ----------------------------------------------------------------------------- |
|
1103 // |
|
1104 EXPORT_C TBool CDRMPermission::Valid( const TTime& aTime, |
|
1105 const RPointerArray<HBufC8>& aIndividual, |
|
1106 TUint32& aRejection, |
|
1107 const TRightsType aType ) const |
|
1108 { |
|
1109 // Always check that if the top level rights are present |
|
1110 // that they are valid |
|
1111 if( iTopLevel && !iTopLevel->Valid( aTime, aIndividual, aRejection ) ) |
|
1112 { |
|
1113 aRejection |= aRejection; |
|
1114 return EFalse; |
|
1115 } |
|
1116 |
|
1117 switch( aType ) |
|
1118 { |
|
1119 case ERightsTopLevel: |
|
1120 if( !iTopLevel ) |
|
1121 { |
|
1122 return EFalse; |
|
1123 } |
|
1124 break; |
|
1125 case ERightsPlay: |
|
1126 if( !iPlay ) |
|
1127 { |
|
1128 return EFalse; |
|
1129 } |
|
1130 else if( iPlay && !iPlay->Valid( aTime, aIndividual, aRejection ) ) |
|
1131 { |
|
1132 return EFalse; |
|
1133 } |
|
1134 break; |
|
1135 case ERightsDisplay: |
|
1136 if( !iDisplay ) |
|
1137 { |
|
1138 return EFalse; |
|
1139 } |
|
1140 else if( iDisplay && !iDisplay->Valid( aTime, aIndividual, aRejection ) ) |
|
1141 { |
|
1142 return EFalse; |
|
1143 } |
|
1144 break; |
|
1145 case ERightsExecute: |
|
1146 if( !iExecute ) |
|
1147 { |
|
1148 return EFalse; |
|
1149 } |
|
1150 else if( iExecute && !iExecute->Valid( aTime, aIndividual, aRejection ) ) |
|
1151 { |
|
1152 return EFalse; |
|
1153 } |
|
1154 break; |
|
1155 case ERightsPrint: |
|
1156 if( !iPrint ) |
|
1157 { |
|
1158 return EFalse; |
|
1159 } |
|
1160 else if( iPrint && !iPrint->Valid( aTime, aIndividual, aRejection ) ) |
|
1161 { |
|
1162 return EFalse; |
|
1163 } |
|
1164 break; |
|
1165 case ERightsExport: |
|
1166 if( !iExport ) |
|
1167 { |
|
1168 return EFalse; |
|
1169 } |
|
1170 else if( iExport && !iExport->Valid( aTime, aIndividual, aRejection ) ) |
|
1171 { |
|
1172 return EFalse; |
|
1173 } |
|
1174 break; |
|
1175 default: |
|
1176 // No constraints are defined, top level doesn't work |
|
1177 // on it's own, the permission is invalid |
|
1178 if( !iPrint && !iDisplay && !iExecute && !iPrint ) |
|
1179 { |
|
1180 return EFalse; |
|
1181 } |
|
1182 else if( iPlay && !iPlay->Valid( aTime, aIndividual, aRejection ) ) |
|
1183 { |
|
1184 return EFalse; |
|
1185 } |
|
1186 else if( iDisplay && !iDisplay->Valid( aTime, aIndividual, aRejection ) ) |
|
1187 { |
|
1188 return EFalse; |
|
1189 } |
|
1190 else if( iPrint && !iPrint->Valid( aTime, aIndividual, aRejection ) ) |
|
1191 { |
|
1192 return EFalse; |
|
1193 } |
|
1194 else if( iExecute && !iExecute->Valid( aTime, aIndividual, aRejection ) ) |
|
1195 { |
|
1196 return EFalse; |
|
1197 } |
|
1198 else if( iExport && !iExport->Valid( aTime, aIndividual, aRejection ) ) |
|
1199 { |
|
1200 return EFalse; |
|
1201 } |
|
1202 break; |
|
1203 } |
|
1204 return ETrue; |
|
1205 }; |
|
1206 |
|
1207 |
|
1208 |
|
1209 // ----------------------------------------------------------------------------- |
|
1210 // CDRMPermission::ConstructL |
|
1211 // 2nd phase constructor |
|
1212 // ----------------------------------------------------------------------------- |
|
1213 // |
|
1214 void CDRMPermission::ConstructL() |
|
1215 { |
|
1216 iTopLevel = CDRMConstraint::NewL(); |
|
1217 iPlay = CDRMConstraint::NewL(); |
|
1218 iDisplay = CDRMConstraint::NewL(); |
|
1219 iExecute = CDRMConstraint::NewL(); |
|
1220 iPrint = CDRMConstraint::NewL(); |
|
1221 iExport = CDRMConstraint::NewL(); |
|
1222 |
|
1223 iRightsObjectVersion.iVersionMain = EOma1Rights; |
|
1224 iRightsObjectVersion.iVersionSub = 0; |
|
1225 }; |
|
1226 |
|
1227 |
|
1228 // ----------------------------------------------------------------------------- |
|
1229 // CDRMPermission::WriteInt64L |
|
1230 // ----------------------------------------------------------------------------- |
|
1231 // |
|
1232 void CDRMPermission::WriteInt64L( const TInt64& aWrite, RWriteStream& aStream ) const |
|
1233 { |
|
1234 TPtr8 output( reinterpret_cast<TUint8*>(const_cast<TInt64*>(&aWrite)), |
|
1235 sizeof(TInt64), sizeof(TInt64) ); |
|
1236 |
|
1237 aStream.WriteL( output, sizeof(TInt64) ); |
|
1238 } |
|
1239 |
|
1240 // ----------------------------------------------------------------------------- |
|
1241 // CDRMPermission::ReadInt64L |
|
1242 // ----------------------------------------------------------------------------- |
|
1243 // |
|
1244 void CDRMPermission::ReadInt64L( TInt64& aRead, RReadStream& aStream ) |
|
1245 { |
|
1246 TPtr8 input( reinterpret_cast<TUint8*>(&aRead), 0, sizeof(TInt64) ); |
|
1247 |
|
1248 aStream.ReadL( input, sizeof(TInt64) ); |
|
1249 }; |
|
1250 |
|
1251 |
|
1252 // ----------------------------------------------------------------------------- |
|
1253 // CDRMPermission::Merge |
|
1254 // ----------------------------------------------------------------------------- |
|
1255 // |
|
1256 EXPORT_C void CDRMPermission::Merge( const CDRMPermission& aPermission ) |
|
1257 { |
|
1258 iTopLevel->Merge( *( aPermission.iTopLevel ) ); |
|
1259 iPlay->Merge( *( aPermission.iPlay ) ); |
|
1260 iDisplay->Merge( *( aPermission.iDisplay ) ); |
|
1261 iExecute->Merge( *( aPermission.iExecute ) ); |
|
1262 iPrint->Merge( *( aPermission.iPrint ) ); |
|
1263 iExport->Merge( *( aPermission.iExport ) ); |
|
1264 iAvailableRights |= aPermission.iAvailableRights; |
|
1265 iInfoBits |= aPermission.iInfoBits; |
|
1266 } |
|
1267 |
|
1268 // End of File |