|
1 /* |
|
2 * Copyright (c) 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 the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "wmdrmcontentparser.h" |
|
20 #include <caf/caferr.h> |
|
21 |
|
22 using namespace ReferenceTestAgent; |
|
23 using namespace ContentAccess; |
|
24 |
|
25 EXPORT_C CWmdrmContentParser* CWmdrmContentParser::NewL(const TDesC8& aHeaderData) |
|
26 { |
|
27 CWmdrmContentParser* self = new (ELeave) CWmdrmContentParser; |
|
28 CleanupStack::PushL(self); |
|
29 self->ConstructL(aHeaderData); |
|
30 CleanupStack::Pop(self); |
|
31 return self; |
|
32 } |
|
33 |
|
34 |
|
35 CWmdrmContentParser::CWmdrmContentParser() |
|
36 { |
|
37 } |
|
38 |
|
39 |
|
40 void CWmdrmContentParser::ConstructL(const TDesC8& aHeaderData) |
|
41 { |
|
42 iHeaderData = aHeaderData.AllocL(); |
|
43 |
|
44 // Initialise default attributes. |
|
45 CreateAttributeSetL(); |
|
46 CreateStringAttributeSetL(); |
|
47 } |
|
48 |
|
49 void CWmdrmContentParser::CreateAttributeSetL() |
|
50 { |
|
51 // Initialise attributes |
|
52 SetAttributeL(EIsProtected, ETrue, KErrNone); |
|
53 SetAttributeL(EIsForwardable, EFalse, KErrNone); |
|
54 SetAttributeL(EIsModifyable, EFalse, KErrNone); |
|
55 SetAttributeL(EIsCopyable, EFalse, KErrNone); |
|
56 SetAttributeL(ECanPlay, EFalse, KErrNone); |
|
57 SetAttributeL(ECanPrint, EFalse, KErrNone); |
|
58 SetAttributeL(ECanExecute, EFalse, KErrNone); |
|
59 SetAttributeL(ECanView, EFalse, KErrNone); |
|
60 SetAttributeL(ERightsNone, ETrue, KErrNone); |
|
61 SetAttributeL(ERightsPending, EFalse, KErrNone); |
|
62 SetAttributeL(ERightsHaveExpired, EFalse, KErrNone); |
|
63 SetAttributeL(EPreviewAvailable, EFalse, KErrNone); |
|
64 SetAttributeL(ECanRewind, EFalse, KErrNone); |
|
65 SetAttributeL(ECopyPaste, EFalse, KErrNone); |
|
66 SetAttributeL(ERightsConsumable, EFalse, KErrNone); |
|
67 SetAttributeL(ERightsStateless, EFalse, KErrNone); |
|
68 SetAttributeL(ECanMove, ETrue, KErrNone); |
|
69 SetAttributeL(ECanRename, ETrue, KErrNone); |
|
70 SetAttributeL(ECanAutomaticConsume, EFalse, KErrNone); |
|
71 } |
|
72 |
|
73 void CWmdrmContentParser::CreateStringAttributeSetL() |
|
74 { |
|
75 // Initialise string attributes. |
|
76 _LIT(KDescription, "WMDRM"); |
|
77 SetStringAttributeL(EDescription , KDescription, KErrNone); |
|
78 |
|
79 _LIT(KMimeType, "application/vnd.drm.asf"); |
|
80 |
|
81 SetStringAttributeL(EMimeType, KMimeType, KErrNone); |
|
82 } |
|
83 |
|
84 void CWmdrmContentParser::SetAttributeL(TInt aAttribute, TInt aValue, TInt aErrorCode) |
|
85 { |
|
86 iAttributeSet.AddL(aAttribute); |
|
87 User::LeaveIfError(iAttributeSet.SetValue(aAttribute, aValue, aErrorCode)); |
|
88 } |
|
89 |
|
90 void CWmdrmContentParser::SetStringAttributeL(TInt aAttribute, const TDesC& aValue, TInt aErrorCode) |
|
91 { |
|
92 iStringAttributeSet.AddL(aAttribute); |
|
93 User::LeaveIfError(iStringAttributeSet.SetValue(aAttribute, aValue, aErrorCode)); |
|
94 } |
|
95 |
|
96 CWmdrmContentParser::~CWmdrmContentParser() |
|
97 { |
|
98 delete iHeaderData; |
|
99 |
|
100 iAttributeSet.Close(); |
|
101 iStringAttributeSet.Close(); |
|
102 } |
|
103 |
|
104 EXPORT_C TInt CWmdrmContentParser::GetAttribute(TInt aAttribute, TInt& aValue) const |
|
105 { |
|
106 return iAttributeSet.GetValue(aAttribute, aValue); |
|
107 } |
|
108 |
|
109 EXPORT_C TInt CWmdrmContentParser::GetStringAttribute(TInt aAttribute, TDes& aValue) const |
|
110 { |
|
111 return iStringAttributeSet.GetValue(aAttribute, aValue); |
|
112 } |
|
113 |
|
114 EXPORT_C TInt CWmdrmContentParser::GetAttributeSet(RAttributeSet &aAttributeSet) const |
|
115 { |
|
116 TInt value = 0; |
|
117 TInt err = KErrNone; |
|
118 for(TInt i = 0; i < aAttributeSet.Count(); i++) |
|
119 { |
|
120 TInt attribute = aAttributeSet[i]; |
|
121 err = GetAttribute(attribute, value); |
|
122 if(err != KErrNone) |
|
123 { |
|
124 break; |
|
125 } |
|
126 |
|
127 aAttributeSet.SetValue(attribute, value, err); |
|
128 } |
|
129 return err; |
|
130 } |
|
131 |
|
132 EXPORT_C TInt CWmdrmContentParser::GetStringAttributeSet(RStringAttributeSet &aStringAttributeSet) const |
|
133 { |
|
134 TInt err = KErrNone; |
|
135 for(TInt i = 0; i < aStringAttributeSet.Count(); i++) |
|
136 { |
|
137 TInt attribute = aStringAttributeSet[i]; |
|
138 HBufC* value = NULL; |
|
139 TRAP(err, value = HBufC::NewL(iStringAttributeSet.GetValueLength(attribute))); |
|
140 CleanupStack::PushL(value); |
|
141 |
|
142 TPtr valuePtr = value->Des(); |
|
143 err = GetStringAttribute(attribute, valuePtr); |
|
144 if(err != KErrNone) |
|
145 { |
|
146 CleanupStack::PopAndDestroy(value); |
|
147 break; |
|
148 } |
|
149 |
|
150 aStringAttributeSet.SetValue(attribute, valuePtr, err); |
|
151 CleanupStack::PopAndDestroy(value); |
|
152 } |
|
153 return err; |
|
154 } |