|
1 /* |
|
2 * Copyright (c) 2006-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: Access to content and data attributes |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Includes |
|
20 #include <apgcli.h> |
|
21 #include <f32file.h> |
|
22 #include <charconv.h> |
|
23 |
|
24 #include <caf.h> |
|
25 #include <caf/attributeset.h> |
|
26 #include <caf/stringattributeset.h> |
|
27 #include <caf/virtualpath.h> |
|
28 #include <caf/caferr.h> |
|
29 #include <caf/caftypes.h> |
|
30 #include <utf.h> |
|
31 #include <drmagents.h> |
|
32 #include <oma2agent.h> |
|
33 #include <wmdrmagent.h> |
|
34 #include "wmdrmagentattributes.h" |
|
35 #include "asf.h" |
|
36 #include "logfn.h" |
|
37 |
|
38 using namespace ContentAccess; |
|
39 |
|
40 // ============================ MEMBER FUNCTIONS =============================== |
|
41 |
|
42 // PointerArrayResetDestroyAndClose |
|
43 // Template method used to push RPointerArrays to the cleanup stack. Takes |
|
44 // care of deleting all pointers in the array. |
|
45 // ----------------------------------------------------------------------------- |
|
46 |
|
47 template<class S> |
|
48 void PointerArrayResetDestroyAndClose(TAny* aPtr) |
|
49 { |
|
50 (reinterpret_cast<RPointerArray<S>*>(aPtr))->ResetAndDestroy(); |
|
51 (reinterpret_cast<RPointerArray<S>*>(aPtr))->Close(); |
|
52 } |
|
53 |
|
54 // ============================ MEMBER FUNCTIONS =============================== |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 TInt TWmDrmAgentAttributes::GetAttributeL( |
|
58 CAsf* /*aAsfFile*/, |
|
59 TInt aAttribute, |
|
60 TInt& aValue, |
|
61 const TVirtualPathPtr& /*aVirtualPath*/, |
|
62 TBool /*aReusePreviousQuery*/ ) |
|
63 { |
|
64 TInt r = KErrNone; |
|
65 |
|
66 LOGFNR( "TWmDrmAgentAttributes::GetAttributeL", r ); |
|
67 aValue = ETrue; |
|
68 switch ( aAttribute ) |
|
69 { |
|
70 case DRM::EDrmAgentUid: |
|
71 aValue = DRM::EDrmWmAgent; |
|
72 break; |
|
73 case ECanPlay: |
|
74 case ECanView: |
|
75 aValue = EFalse; |
|
76 r = KErrCANotSupported; |
|
77 break; |
|
78 case ERightsStateless: |
|
79 case ERightsConsumable: |
|
80 aValue = EFalse; |
|
81 r = KErrCANotSupported; |
|
82 break; |
|
83 case ECanAutomaticConsume: |
|
84 aValue = EFalse; |
|
85 r = KErrCANotSupported; |
|
86 break; |
|
87 case EIsForwardable: |
|
88 case EIsCopyable: |
|
89 case ECanRewind: |
|
90 case ECopyPaste: |
|
91 case ECanMove: |
|
92 case ECanRename: |
|
93 aValue = ETrue; |
|
94 break; |
|
95 case EIsModifyable: |
|
96 case ECanPrint: |
|
97 case ECanExecute: |
|
98 case EPreviewAvailable: |
|
99 aValue = EFalse; |
|
100 break; |
|
101 case EIsProtected: |
|
102 r = KErrCANotSupported; |
|
103 break; |
|
104 case EContentCDataInUse: |
|
105 aValue = ETrue; |
|
106 break; |
|
107 case EFileType: |
|
108 aValue = EAsf; |
|
109 break; |
|
110 case DRM::EDrmFileType: |
|
111 aValue = DRM::EDrmWMFile; |
|
112 break; |
|
113 case DRM::EDrmAllowedOutputs: |
|
114 aValue = 0; |
|
115 r = KErrCANotSupported; |
|
116 break; |
|
117 default: |
|
118 r = KErrCANotSupported; |
|
119 break; |
|
120 }; |
|
121 LOG3( "Attribute: %d, value: %d", aAttribute, aValue ); |
|
122 return r; |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 TInt TWmDrmAgentAttributes::GetAttributeSetL( |
|
127 CAsf* aAsfFile, |
|
128 RAttributeSet& aAttributeSet, |
|
129 const TVirtualPathPtr& aVirtualPath ) |
|
130 { |
|
131 TInt i = 0; |
|
132 TInt attribute = 0; |
|
133 TInt value=0; |
|
134 TInt err = KErrNone; |
|
135 TInt numAttributes = aAttributeSet.Count(); |
|
136 |
|
137 LOGFN( "TWmDrmAgentAttributes::GetAttributeSetL" ); |
|
138 |
|
139 // loop through all the attriutes in the set and find their values |
|
140 for ( i = 0; i < numAttributes && err == KErrNone; i++ ) |
|
141 { |
|
142 attribute = aAttributeSet[i]; |
|
143 err = GetAttributeL( aAsfFile, attribute, |
|
144 value, aVirtualPath, ETrue ); |
|
145 err = aAttributeSet.SetValue( attribute, value, err ); |
|
146 } |
|
147 return err; |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 TInt TWmDrmAgentAttributes::GetStringAttributeL( |
|
152 CAsf* aAsfFile, |
|
153 TInt aAttribute, |
|
154 TDes& aValue, |
|
155 const TVirtualPathPtr& /*aVirtualPath*/, |
|
156 TBool /*aReusePreviousQuery*/ ) |
|
157 { |
|
158 TInt err = KErrNone; |
|
159 HBufC* b = NULL; |
|
160 HBufC* allocated = NULL; |
|
161 TFileName fileName; |
|
162 |
|
163 LOGFNR( "TWmDrmAgentAttributes::GetStringAttributeL", err ); |
|
164 // Initialise the attribute value to be zero length in case it's not |
|
165 // supported or an error occurs |
|
166 aValue.SetLength( 0 ); |
|
167 |
|
168 switch( aAttribute ) |
|
169 { |
|
170 case EIconURI: |
|
171 case EPreviewURI: |
|
172 case EContentURI: |
|
173 case EInfoURL: |
|
174 case EPendingRightsETA: |
|
175 err = KErrCANotSupported; |
|
176 break; |
|
177 |
|
178 case EMimeType: |
|
179 aValue.Copy( aAsfFile->iMimeType ); |
|
180 break; |
|
181 case EDescription: |
|
182 if (aAsfFile->iDescription) |
|
183 { |
|
184 b = aAsfFile->iDescription; |
|
185 } |
|
186 break; |
|
187 case ETitle: |
|
188 if (aAsfFile->iTitle) |
|
189 { |
|
190 b = aAsfFile->iTitle; |
|
191 } |
|
192 break; |
|
193 case EPerformer: |
|
194 case EAuthor: |
|
195 if (aAsfFile->iAuthor) |
|
196 { |
|
197 b = aAsfFile->iAuthor; |
|
198 } |
|
199 break; |
|
200 case EContentID: |
|
201 if (aAsfFile->iUniqueFileID) |
|
202 { |
|
203 b = aAsfFile->iUniqueFileID; |
|
204 } |
|
205 break; |
|
206 case ECopyright: |
|
207 if (aAsfFile->iCopyright) |
|
208 { |
|
209 b = aAsfFile->iCopyright; |
|
210 } |
|
211 break; |
|
212 case ERating: |
|
213 case DRM::EDrmRatingInfo: |
|
214 if (aAsfFile->iRating) |
|
215 { |
|
216 b = aAsfFile->iRating; |
|
217 } |
|
218 break; |
|
219 case EAlbumTitle: |
|
220 if (aAsfFile->iAlbumTitle) |
|
221 { |
|
222 b = aAsfFile->iAlbumTitle; |
|
223 } |
|
224 break; |
|
225 case EPicture: |
|
226 if (aAsfFile->iPicture) |
|
227 { |
|
228 b = aAsfFile->iPicture; |
|
229 } |
|
230 break; |
|
231 case EText: |
|
232 if (aAsfFile->iText) |
|
233 { |
|
234 b = aAsfFile->iText; |
|
235 } |
|
236 break; |
|
237 case EComposer: |
|
238 if (aAsfFile->iComposer) |
|
239 { |
|
240 b = aAsfFile->iComposer; |
|
241 } |
|
242 break; |
|
243 case EGenre: |
|
244 if (aAsfFile->iGenre) |
|
245 { |
|
246 b = aAsfFile->iGenre; |
|
247 } |
|
248 break; |
|
249 case EYear: |
|
250 case DRM::EDrmRecordingYear: |
|
251 if (aAsfFile->iYear) |
|
252 { |
|
253 b = aAsfFile->iYear; |
|
254 } |
|
255 break; |
|
256 case EOriginalArtist: |
|
257 case DRM::EDrmOriginalArtist: |
|
258 if (aAsfFile->iOriginalArtist) |
|
259 { |
|
260 b = aAsfFile->iOriginalArtist; |
|
261 } |
|
262 break; |
|
263 case EWmTrackNumber: |
|
264 case DRM::EDrmTrackNumber: |
|
265 if (aAsfFile->iTrackNumber) |
|
266 { |
|
267 b = aAsfFile->iTrackNumber; |
|
268 } |
|
269 break; |
|
270 case EAudioFileUrl: |
|
271 if (aAsfFile->iAudioFileUrl) |
|
272 { |
|
273 b = aAsfFile->iAudioFileUrl; |
|
274 } |
|
275 break; |
|
276 case ESharedUserRating: |
|
277 if (aAsfFile->iSharedUserRating) |
|
278 { |
|
279 b = aAsfFile->iSharedUserRating; |
|
280 } |
|
281 break; |
|
282 case EDate: |
|
283 if (aAsfFile->iDate) |
|
284 { |
|
285 b = aAsfFile->iDate; |
|
286 } |
|
287 break; |
|
288 case DRM::EDrmAgentName: |
|
289 allocated = DRM::KDrmWMAgentName().AllocL(); |
|
290 break; |
|
291 case DRM::EDrmFileName: |
|
292 err = aAsfFile->iFile.Name( fileName ); |
|
293 if( aValue.MaxLength() < fileName.Length() ) |
|
294 { |
|
295 return KErrOverflow; |
|
296 } |
|
297 aValue.Copy( fileName ); |
|
298 break; |
|
299 case DRM::EDrmFullName: |
|
300 err = aAsfFile->iFile.FullName( fileName ); |
|
301 if ( aValue.MaxLength() < fileName.Length() ) |
|
302 { |
|
303 return KErrOverflow; |
|
304 } |
|
305 aValue.Copy( fileName ); |
|
306 break; |
|
307 default: |
|
308 err = KErrCANotSupported; |
|
309 break; |
|
310 }; |
|
311 |
|
312 if (b != NULL) |
|
313 { |
|
314 if( b->Length() > aValue.MaxLength() ) |
|
315 { |
|
316 return KErrOverflow; |
|
317 } |
|
318 err = KErrNone; |
|
319 aValue.Copy(*b); |
|
320 } |
|
321 else if( allocated ) |
|
322 { |
|
323 if( allocated->Length() <= aValue.MaxLength() ) |
|
324 { |
|
325 err = KErrNone; |
|
326 aValue.Copy(*allocated); |
|
327 } |
|
328 else |
|
329 { |
|
330 err = KErrOverflow; |
|
331 } |
|
332 delete allocated; |
|
333 allocated = NULL; |
|
334 } |
|
335 |
|
336 LOG2( "Attribute: %d", aAttribute ); |
|
337 return err; |
|
338 } |
|
339 |
|
340 // ----------------------------------------------------------------------------- |
|
341 TInt TWmDrmAgentAttributes::GetStringAttributeSetL( |
|
342 CAsf* aAsfFile, |
|
343 RStringAttributeSet& aStringAttributeSet, |
|
344 const TVirtualPathPtr& aVirtualPath ) |
|
345 { |
|
346 TInt i = 0; |
|
347 TInt attribute = 0; |
|
348 TInt err = KErrNone; |
|
349 TBuf <KMaxDataTypeLength> buf; |
|
350 |
|
351 LOGFN( "TWmDrmAgentAttributes::GetStringAttributeSetL" ); |
|
352 TInt numAttributes = aStringAttributeSet.Count(); |
|
353 |
|
354 // loop through all the attriutes in the set and find their values |
|
355 for ( i = 0; i < numAttributes && err==KErrNone; i++ ) |
|
356 { |
|
357 buf.SetLength( 0 ); |
|
358 attribute = aStringAttributeSet[i]; |
|
359 err = GetStringAttributeL( aAsfFile, attribute, buf, aVirtualPath ); |
|
360 err = aStringAttributeSet.SetValue(attribute,buf, err); |
|
361 } |
|
362 return err; |
|
363 } |
|
364 |
|
365 |
|
366 // End of file |