|
1 /* |
|
2 * Copyright (c) 2004 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: Datatype for the Common Rights Database Data |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <s32strm.h> |
|
22 #include "DRMCommonData.h" |
|
23 |
|
24 // EXTERNAL DATA STRUCTURES |
|
25 |
|
26 // EXTERNAL FUNCTION PROTOTYPES |
|
27 |
|
28 // CONSTANTS |
|
29 |
|
30 // MACROS |
|
31 |
|
32 // LOCAL CONSTANTS AND MACROS |
|
33 _LIT8( KOwnNullDesC8, "" ); |
|
34 _LIT( KOwnNullDesC, "" ); |
|
35 |
|
36 // MODULE DATA STRUCTURES |
|
37 |
|
38 // LOCAL FUNCTION PROTOTYPES |
|
39 |
|
40 // FORWARD DECLARATIONS |
|
41 |
|
42 // ============================= LOCAL FUNCTIONS =============================== |
|
43 // ============================ MEMBER FUNCTIONS =============================== |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CDRMCommonData::NewLC |
|
47 // Two-phased constructor. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CDRMCommonData* CDRMCommonData::NewLC( const TDesC8& aContentID, |
|
51 const TDesC8& aContentHash, |
|
52 const TDesC8& aRightsIssuer, |
|
53 const TDesC& aContentName, |
|
54 const TDesC8& aAuthenticationSeed ) |
|
55 { |
|
56 CDRMCommonData* self = new( ELeave ) CDRMCommonData(); |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL( aContentID, aContentHash, |
|
59 aRightsIssuer, aContentName, |
|
60 aAuthenticationSeed ); |
|
61 |
|
62 return self; |
|
63 }; |
|
64 |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CDRMCommonData::NewL |
|
68 // Two-phased constructor. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 CDRMCommonData* CDRMCommonData::NewL( const TDesC8& aContentID, |
|
72 const TDesC8& aContentHash, |
|
73 const TDesC8& aRightsIssuer, |
|
74 const TDesC& aContentName, |
|
75 const TDesC8& aAuthenticationSeed ) |
|
76 { |
|
77 CDRMCommonData* self = NewLC( aContentID, aContentHash, |
|
78 aRightsIssuer, aContentName, |
|
79 aAuthenticationSeed ); |
|
80 CleanupStack::Pop(); |
|
81 |
|
82 return self; |
|
83 }; |
|
84 |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CDRMCommonData::NewLC |
|
88 // Two-phased constructor. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CDRMCommonData* CDRMCommonData::NewLC() |
|
92 { |
|
93 CDRMCommonData* self = new( ELeave ) CDRMCommonData(); |
|
94 CleanupStack::PushL( self ); |
|
95 |
|
96 return self; |
|
97 }; |
|
98 |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CDRMCommonData::NewL |
|
102 // Two-phased constructor. |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 CDRMCommonData* CDRMCommonData::NewL() |
|
106 { |
|
107 CDRMCommonData* self = NewLC(); |
|
108 CleanupStack::Pop(); |
|
109 |
|
110 return self; |
|
111 }; |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // Default Constructor - First phase. |
|
115 // Can be used by itself to generate an empty object |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 CDRMCommonData::CDRMCommonData() |
|
119 { |
|
120 |
|
121 }; |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // Destructor |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 CDRMCommonData::~CDRMCommonData() |
|
128 { |
|
129 if( iContentID ) |
|
130 { |
|
131 delete iContentID; |
|
132 iContentID = NULL; |
|
133 } |
|
134 |
|
135 if( iContentHash ) |
|
136 { |
|
137 delete iContentHash; |
|
138 iContentHash = NULL; |
|
139 } |
|
140 |
|
141 if( iRightsIssuer ) |
|
142 { |
|
143 delete iRightsIssuer; |
|
144 iRightsIssuer = NULL; |
|
145 } |
|
146 |
|
147 if( iContentName ) |
|
148 { |
|
149 delete iContentName; |
|
150 iContentName = NULL; |
|
151 } |
|
152 |
|
153 if( iAuthenticationSeed ) |
|
154 { |
|
155 delete iAuthenticationSeed; |
|
156 iAuthenticationSeed = NULL; |
|
157 } |
|
158 }; |
|
159 |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CDRMCommonData::ContentID |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 const TDesC8& CDRMCommonData::ContentID() const |
|
166 { |
|
167 if ( iContentID ) |
|
168 { |
|
169 return *iContentID; |
|
170 } |
|
171 return KOwnNullDesC8; |
|
172 }; |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CDRMCommonData::ContentHash |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 const TDesC8& CDRMCommonData::ContentHash() const |
|
179 { |
|
180 if ( iContentHash ) |
|
181 { |
|
182 return *iContentHash; |
|
183 } |
|
184 |
|
185 return KOwnNullDesC8; |
|
186 }; |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CDRMCommonData::RightsIssuer |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 const TDesC8& CDRMCommonData::RightsIssuer() const |
|
193 { |
|
194 if ( iRightsIssuer ) |
|
195 { |
|
196 return *iRightsIssuer; |
|
197 } |
|
198 return KOwnNullDesC8; |
|
199 }; |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CDRMCommonData::ContentName |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 const TDesC& CDRMCommonData::ContentName() const |
|
206 { |
|
207 if ( iContentName ) |
|
208 { |
|
209 return *iContentName; |
|
210 } |
|
211 |
|
212 return KOwnNullDesC; |
|
213 }; |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CDRMCommonData::AuthenticationSeed |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 const TDesC8& CDRMCommonData::AuthenticationSeed() const |
|
220 { |
|
221 if ( iAuthenticationSeed ) |
|
222 { |
|
223 return *iAuthenticationSeed; |
|
224 } |
|
225 return KOwnNullDesC8; |
|
226 }; |
|
227 |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CDRMCommonData::SetContentIDL |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 void CDRMCommonData::SetContentIDL( const TDesC8& aContentID ) |
|
234 { |
|
235 HBufC8* newContentID = aContentID.AllocL(); |
|
236 |
|
237 if( iContentID ) |
|
238 { |
|
239 delete iContentID; |
|
240 iContentID = NULL; |
|
241 } |
|
242 iContentID = newContentID; |
|
243 }; |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CDRMCommonData::SetContentHashL |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 void CDRMCommonData::SetContentHashL( const TDesC8& aContentHash ) |
|
250 { |
|
251 HBufC8* newContentHash = aContentHash.AllocL(); |
|
252 |
|
253 if( iContentHash ) |
|
254 { |
|
255 delete iContentHash; |
|
256 iContentHash = NULL; |
|
257 } |
|
258 iContentHash = newContentHash; |
|
259 }; |
|
260 |
|
261 // ----------------------------------------------------------------------------- |
|
262 // CDRMCommonData::SetRightsIssuerL |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 void CDRMCommonData::SetRightsIssuerL( const TDesC8& aRightsIssuer ) |
|
266 { |
|
267 HBufC8* newRightsIssuer = aRightsIssuer.AllocL(); |
|
268 |
|
269 if( iRightsIssuer ) |
|
270 { |
|
271 delete iRightsIssuer; |
|
272 iRightsIssuer = NULL; |
|
273 } |
|
274 iRightsIssuer = newRightsIssuer; |
|
275 }; |
|
276 |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // CDRMCommonData::SetContentNameL |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 void CDRMCommonData::SetContentNameL( const TDesC& aContentName ) |
|
283 { |
|
284 HBufC* newContentName = NULL; |
|
285 |
|
286 // If the content name you want to give is empty, just delete the existing |
|
287 // one and not do anything else; |
|
288 if( aContentName.Length() == 0 ) |
|
289 { |
|
290 if( iContentName ) |
|
291 { |
|
292 delete iContentName; |
|
293 iContentName = NULL; |
|
294 } |
|
295 return; |
|
296 } |
|
297 |
|
298 newContentName = aContentName.AllocL(); |
|
299 |
|
300 if( iContentName ) |
|
301 { |
|
302 delete iContentName; |
|
303 iContentName = NULL; |
|
304 } |
|
305 iContentName = newContentName; |
|
306 }; |
|
307 |
|
308 |
|
309 // ----------------------------------------------------------------------------- |
|
310 // CDRMCommonData::SetAuthenticationSeedL |
|
311 // ----------------------------------------------------------------------------- |
|
312 // |
|
313 void CDRMCommonData::SetAuthenticationSeedL( const TDesC8& aAuthenticationSeed ) |
|
314 { |
|
315 HBufC8* newAuthenticationSeed = aAuthenticationSeed.AllocL(); |
|
316 |
|
317 if( iAuthenticationSeed ) |
|
318 { |
|
319 delete iAuthenticationSeed; |
|
320 iAuthenticationSeed= NULL; |
|
321 } |
|
322 iAuthenticationSeed = newAuthenticationSeed; |
|
323 }; |
|
324 |
|
325 |
|
326 // ----------------------------------------------------------------------------- |
|
327 // CDRMCommonData::ExternalizeL |
|
328 // ----------------------------------------------------------------------------- |
|
329 // |
|
330 void CDRMCommonData::ExternalizeL( RWriteStream& aStream ) const |
|
331 { |
|
332 TInt dataLength = 0; |
|
333 |
|
334 // Write the ContentID |
|
335 if( iContentID ) |
|
336 { |
|
337 dataLength = iContentID->Length(); |
|
338 } |
|
339 aStream.WriteInt32L( dataLength ); |
|
340 |
|
341 if( dataLength ) |
|
342 { |
|
343 aStream.WriteL( iContentID->Des() ); |
|
344 } |
|
345 |
|
346 // Write the ContentHash |
|
347 dataLength = 0; |
|
348 if( iContentHash ) |
|
349 { |
|
350 dataLength = iContentHash->Length(); |
|
351 } |
|
352 aStream.WriteInt32L( dataLength ); |
|
353 |
|
354 if( dataLength ) |
|
355 { |
|
356 aStream.WriteL( iContentHash->Des() ); |
|
357 } |
|
358 |
|
359 // Write the Rights Issuer |
|
360 dataLength = 0; |
|
361 if( iRightsIssuer ) |
|
362 { |
|
363 dataLength = iRightsIssuer->Length(); |
|
364 } |
|
365 aStream.WriteInt32L( dataLength ); |
|
366 |
|
367 if( dataLength ) |
|
368 { |
|
369 aStream.WriteL( iRightsIssuer->Des() ); |
|
370 } |
|
371 |
|
372 // Write the ContentName |
|
373 dataLength = 0; |
|
374 if( iContentName ) |
|
375 { |
|
376 dataLength = iContentName->Length(); |
|
377 } |
|
378 aStream.WriteInt32L( dataLength ); |
|
379 |
|
380 if( dataLength ) |
|
381 { |
|
382 aStream.WriteL( iContentName->Des() ); |
|
383 } |
|
384 |
|
385 // Write the Rights Issuer |
|
386 dataLength = 0; |
|
387 if( iAuthenticationSeed ) |
|
388 { |
|
389 dataLength = iAuthenticationSeed->Length(); |
|
390 } |
|
391 aStream.WriteInt32L( dataLength ); |
|
392 |
|
393 if( dataLength ) |
|
394 { |
|
395 aStream.WriteL( iAuthenticationSeed->Des() ); |
|
396 } |
|
397 |
|
398 }; |
|
399 |
|
400 // ----------------------------------------------------------------------------- |
|
401 // CDRMCommonData::InternalizeL |
|
402 // ----------------------------------------------------------------------------- |
|
403 // |
|
404 void CDRMCommonData::InternalizeL( RReadStream& aStream ) |
|
405 { |
|
406 TInt dataLength = 0; |
|
407 HBufC8* dataPart = 0; |
|
408 TPtr8 dataBuffer(NULL,0,0); |
|
409 |
|
410 // Read the ContentID |
|
411 dataLength = aStream.ReadInt32L(); |
|
412 |
|
413 if( dataLength ) |
|
414 { |
|
415 // Reserve a new buffer: |
|
416 dataPart = HBufC8::NewMaxLC( dataLength ); |
|
417 |
|
418 // Set the read buffer: |
|
419 dataBuffer.Set(const_cast<TUint8*>(dataPart->Ptr()), 0, dataLength); |
|
420 |
|
421 // Read the data: |
|
422 aStream.ReadL( dataBuffer ); |
|
423 |
|
424 // Pop the buffer |
|
425 CleanupStack::Pop(); // dataPart |
|
426 |
|
427 // If an old content identifier exists delete it |
|
428 if( iContentID ) |
|
429 { |
|
430 delete iContentID; |
|
431 iContentID = NULL; |
|
432 } |
|
433 |
|
434 // assign the new content id |
|
435 iContentID = dataPart; |
|
436 } |
|
437 else |
|
438 { |
|
439 // If an old content identifier exists delete it |
|
440 if( iContentID ) |
|
441 { |
|
442 delete iContentID; |
|
443 iContentID = NULL; |
|
444 } |
|
445 } |
|
446 |
|
447 // Read the Content Hash |
|
448 dataLength = aStream.ReadInt32L(); |
|
449 |
|
450 if( dataLength ) |
|
451 { |
|
452 // Reserve a new buffer: |
|
453 dataPart = HBufC8::NewMaxLC( dataLength ); |
|
454 |
|
455 // Set the read buffer: |
|
456 dataBuffer.Set(const_cast<TUint8*>(dataPart->Ptr()), 0, dataLength); |
|
457 |
|
458 // Read the data: |
|
459 aStream.ReadL( dataBuffer ); |
|
460 |
|
461 // Pop the buffer |
|
462 CleanupStack::Pop(); // dataPart |
|
463 |
|
464 // If an old content identifier exists delete it |
|
465 if( iContentHash ) |
|
466 { |
|
467 delete iContentHash; |
|
468 iContentHash = NULL; |
|
469 } |
|
470 |
|
471 // assign the new content id |
|
472 iContentHash = dataPart; |
|
473 } |
|
474 else |
|
475 { |
|
476 // If an old content identifier exists delete it |
|
477 if( iContentHash ) |
|
478 { |
|
479 delete iContentHash; |
|
480 iContentHash = NULL; |
|
481 } |
|
482 } |
|
483 |
|
484 // Read the rights issuer |
|
485 dataLength = aStream.ReadInt32L(); |
|
486 |
|
487 if( dataLength ) |
|
488 { |
|
489 // Reserve a new buffer: |
|
490 dataPart = HBufC8::NewMaxLC( dataLength ); |
|
491 |
|
492 // Set the read buffer: |
|
493 dataBuffer.Set(const_cast<TUint8*>(dataPart->Ptr()), 0, dataLength); |
|
494 |
|
495 // Read the data: |
|
496 aStream.ReadL( dataBuffer ); |
|
497 |
|
498 // Pop the buffer |
|
499 CleanupStack::Pop(); // dataPart |
|
500 |
|
501 // If an old content identifier exists delete it |
|
502 if( iRightsIssuer ) |
|
503 { |
|
504 delete iRightsIssuer; |
|
505 iRightsIssuer = NULL; |
|
506 } |
|
507 |
|
508 // assign the new content id |
|
509 iRightsIssuer = dataPart; |
|
510 } |
|
511 else |
|
512 { |
|
513 // If an old content identifier exists delete it |
|
514 if( iRightsIssuer ) |
|
515 { |
|
516 delete iRightsIssuer; |
|
517 iRightsIssuer = NULL; |
|
518 } |
|
519 } |
|
520 |
|
521 // Read the rights issuer |
|
522 dataLength = aStream.ReadInt32L(); |
|
523 |
|
524 if( dataLength ) |
|
525 { |
|
526 HBufC16* dataPart2 = 0; |
|
527 TPtr16 dataBuffer2(NULL,0,0); |
|
528 |
|
529 // Reserve a new buffer: |
|
530 dataPart2 = HBufC::NewMaxLC( dataLength ); |
|
531 |
|
532 // Set the read buffer: |
|
533 dataBuffer2.Set(const_cast<TUint16*>(dataPart2->Ptr()), 0, dataLength); |
|
534 |
|
535 // Read the data: |
|
536 aStream.ReadL( dataBuffer2 ); |
|
537 |
|
538 // Pop the buffer |
|
539 CleanupStack::Pop(); // dataPart |
|
540 |
|
541 // If an old content identifier exists delete it |
|
542 if( iContentName ) |
|
543 { |
|
544 delete iContentName; |
|
545 iContentName = NULL; |
|
546 } |
|
547 |
|
548 // assign the new content id |
|
549 iContentName = dataPart2; |
|
550 } |
|
551 else |
|
552 { |
|
553 // If an old content identifier exists delete it |
|
554 if( iContentName ) |
|
555 { |
|
556 delete iContentName; |
|
557 iContentName = NULL; |
|
558 } |
|
559 } |
|
560 |
|
561 // Read the iAuthenticationSeed |
|
562 dataLength = aStream.ReadInt32L(); |
|
563 |
|
564 if( dataLength ) |
|
565 { |
|
566 // Reserve a new buffer: |
|
567 dataPart = HBufC8::NewMaxLC( dataLength ); |
|
568 |
|
569 // Set the read buffer: |
|
570 dataBuffer.Set(const_cast<TUint8*>(dataPart->Ptr()), 0, dataLength); |
|
571 |
|
572 // Read the data: |
|
573 aStream.ReadL( dataBuffer ); |
|
574 |
|
575 // Pop the buffer |
|
576 CleanupStack::Pop(); // dataPart |
|
577 |
|
578 // If an old content identifier exists delete it |
|
579 if( iAuthenticationSeed ) |
|
580 { |
|
581 delete iAuthenticationSeed; |
|
582 iAuthenticationSeed = NULL; |
|
583 } |
|
584 |
|
585 // assign the new content id |
|
586 iAuthenticationSeed = dataPart; |
|
587 } |
|
588 else |
|
589 { |
|
590 // If an old content identifier exists delete it |
|
591 if( iAuthenticationSeed ) |
|
592 { |
|
593 delete iAuthenticationSeed; |
|
594 iAuthenticationSeed = NULL; |
|
595 } |
|
596 } |
|
597 |
|
598 }; |
|
599 |
|
600 // ----------------------------------------------------------------------------- |
|
601 // CDRMCommonData::Size |
|
602 // ----------------------------------------------------------------------------- |
|
603 // |
|
604 TInt CDRMCommonData::Size() const |
|
605 { |
|
606 TInt size = 0; |
|
607 |
|
608 // Content identifier of the content |
|
609 size += sizeof(TInt32); |
|
610 |
|
611 if( iContentID ) |
|
612 { |
|
613 size += iContentID->Size(); |
|
614 } |
|
615 |
|
616 // Hash of the content DCF |
|
617 size += sizeof(TInt32); |
|
618 |
|
619 if( iContentHash ) |
|
620 { |
|
621 size += iContentHash->Size(); |
|
622 } |
|
623 |
|
624 // Issuer of the rights |
|
625 size += sizeof(TInt32); |
|
626 |
|
627 if( iRightsIssuer) |
|
628 { |
|
629 size += iRightsIssuer->Size(); |
|
630 } |
|
631 |
|
632 // Content name |
|
633 size += sizeof(TInt32); |
|
634 |
|
635 if( iContentName ) |
|
636 { |
|
637 size += iContentName->Size(); |
|
638 } |
|
639 |
|
640 // Authentication seed |
|
641 size += sizeof(TInt32); |
|
642 |
|
643 if( iAuthenticationSeed ) |
|
644 { |
|
645 size += iAuthenticationSeed->Size(); |
|
646 } |
|
647 return size; |
|
648 }; |
|
649 |
|
650 // ----------------------------------------------------------------------------- |
|
651 // CDRMCommonData::ConstrutL |
|
652 // Second phase constructor |
|
653 // ----------------------------------------------------------------------------- |
|
654 // |
|
655 void CDRMCommonData::ConstructL( const TDesC8& aContentID, |
|
656 const TDesC8& aContentHash, |
|
657 const TDesC8& aRightsIssuer, |
|
658 const TDesC& aContentName, |
|
659 const TDesC8& aAuthenticationSeed ) |
|
660 { |
|
661 iContentID = aContentID.AllocL(); |
|
662 iContentHash = aContentHash.AllocL(); |
|
663 iRightsIssuer = aRightsIssuer.AllocL(); |
|
664 iContentName = aContentName.AllocL(); |
|
665 iAuthenticationSeed = aAuthenticationSeed.AllocL(); |
|
666 }; |
|
667 |
|
668 // End of File |