os/security/contentmgmt/contentaccessfwfordrm/source/f32agent/f32defaultattributes.cpp
First public contribution.
2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
22 #include <caf/attributeset.h>
23 #include <caf/stringattributeset.h>
24 #include <caf/virtualpath.h>
25 #include <caf/caferr.h>
26 #include "f32defaultattributes.h"
29 using namespace ContentAccess;
31 TInt TF32DefaultAttributes::GetAttribute(TInt aAttribute, TInt& aValue, const TDesC& )
34 // All files handled by the F32 agent are unprotected and have the same
35 // standard set of attributes
49 case ECanAutomaticConsume:
52 case EIsMediaPlayerOnly:
53 case EIsAutomatedUseOnly:
55 case EPreviewAvailable:
59 case EContentCDataInUse:
62 err = KErrCANotSupported;
68 TInt TF32DefaultAttributes::GetAttributeSet(RAttributeSet& aAttributeSet, const TDesC& aUri)
74 TInt numAttributes = aAttributeSet.Count();
76 // loop through all the attriutes in the set and find their values
77 for(i = 0; i < numAttributes; i++)
79 attribute = aAttributeSet[i];
80 err = GetAttribute(attribute, value, aUri);
81 aAttributeSet.SetValue(attribute, value, err);
86 TInt TF32DefaultAttributes::GetStringAttribute(TInt aAttribute, TDes& aValue, const TDesC& aUri)
89 TBuf8 <KMaxDataTypeLength> mimeType;
94 TRAP(err, GetMimeTypeL(aUri, mimeType));
97 aValue.Copy(mimeType);
101 err = KErrCANotSupported;
107 TInt TF32DefaultAttributes::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, const TDesC& aUri)
112 TBuf <KMaxDataTypeLength> buf;
114 TInt numAttributes = aStringAttributeSet.Count();
116 // loop through all the attriutes in the set and find their values
117 for(i = 0; i < numAttributes; i++)
120 attribute = aStringAttributeSet[i];
121 err = GetStringAttribute(attribute, buf, aUri);
122 err = aStringAttributeSet.SetValue(attribute,buf, err);
131 void TF32DefaultAttributes::GetMimeTypeL(const TDesC& aURI, TDes8& aMimeType)
133 TUid appUid(KNullUid);
135 RApaLsSession apparcSession;
138 User::LeaveIfError(apparcSession.Connect());
139 CleanupClosePushL(apparcSession);
141 User::LeaveIfError(apparcSession.AppForDocument(aURI, appUid, dataType));
143 if(dataType.Des8().Length() == 0)
145 User::Leave(KErrNotFound);
148 aMimeType.Append(dataType.Des8());
149 CleanupStack::PopAndDestroy(&apparcSession);
153 TInt TF32DefaultAttributes::GetAttribute(TInt aAttribute, TInt& aValue, RFile& /*aFile*/)
155 return GetAttribute(aAttribute, aValue, KNullDesC);
158 TInt TF32DefaultAttributes::GetAttributeSet(RAttributeSet& aAttributeSet, RFile& aFile)
164 TInt numAttributes = aAttributeSet.Count();
166 // loop through all the attributes in the set and find their values
167 for(i = 0; i < numAttributes; i++)
169 attribute = aAttributeSet[i];
170 err = GetAttribute(attribute, value, aFile);
171 aAttributeSet.SetValue(attribute, value, err);
176 TInt TF32DefaultAttributes::GetStringAttribute(TInt aAttribute, TDes& aValue, RFile& aFile)
179 TBuf8 <KMaxDataTypeLength> mimeType;
184 TRAP(err, GetMimeTypeL(aFile, mimeType));
187 aValue.Copy(mimeType);
191 err = KErrCANotSupported;
197 TInt TF32DefaultAttributes::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, RFile& aFile)
202 TBuf <KMaxDataTypeLength> buf;
204 TInt numAttributes = aStringAttributeSet.Count();
206 // loop through all the attriutes in the set and find their values
207 for(i = 0; i < numAttributes; i++)
210 attribute = aStringAttributeSet[i];
211 err = GetStringAttribute(attribute, buf, aFile);
212 err = aStringAttributeSet.SetValue(attribute,buf, err);
221 void TF32DefaultAttributes::GetMimeTypeL(RFile& aFile, TDes8& aMimeType)
223 TUid appUid(KNullUid);
225 RApaLsSession apparcSession;
228 User::LeaveIfError(apparcSession.Connect());
229 CleanupClosePushL(apparcSession);
231 User::LeaveIfError(apparcSession.AppForDocument(aFile, appUid, dataType));
233 if(dataType.Des8().Length() == 0)
235 User::Leave(KErrNotFound);
238 aMimeType.Append(dataType.Des8());
239 CleanupStack::PopAndDestroy(&apparcSession);
242 TInt TF32DefaultAttributes::CheckUniqueId(const TDesC& aUniqueId)
244 // The only UniqueId values that make sense for the F32 agent are
245 // a zero length descriptor (indicating the application is referring to the entire file
246 // or KDefaultContentObject which is also the entire file in the case of the F32 agent
247 if(aUniqueId.Length() == 0 || aUniqueId == KDefaultContentObject())
257 TInt TF32DefaultAttributes::CheckVirtualPath(const TVirtualPathPtr& aVirtualPath)
259 // check the Unique Id
260 TInt err = CheckUniqueId(aVirtualPath.UniqueId());
262 // check if the file exists
268 TUint TF32DefaultAttributes::GetFileMode(TContentShareMode aMode)
271 TUint fileMode = EFileStream | EFileRead;
273 if(aMode == EContentShareReadWrite)
275 fileMode |= EFileShareReadersOrWriters;
277 else if(aMode == EContentShareExclusive)
279 fileMode |= EFileShareExclusive;
283 fileMode |= EFileShareReadersOnly;
289 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
291 TInt TF32DefaultAttributes::GetAttribute(const TDesC8& /*aHeaderData*/, TInt aAttribute, TInt& aValue)
293 return GetAttribute(aAttribute, aValue, KNullDesC);
296 TInt TF32DefaultAttributes::GetAttributeSet(const TDesC8& aHeaderData, RAttributeSet& aAttributeSet)
302 TInt numAttributes = aAttributeSet.Count();
304 // loop through all the attriutes in the set and find their values
305 for(i = 0; i < numAttributes; i++)
307 attribute = aAttributeSet[i];
308 err = GetAttribute(aHeaderData, attribute, value);
309 aAttributeSet.SetValue(attribute, value, err);
314 TInt TF32DefaultAttributes::GetStringAttribute(const TDesC8& /*aHeaderData*/, TInt aAttribute, TDes& aValue)
317 TBuf8 <KMaxDataTypeLength> mimeType;
322 aValue.Copy(KNullDesC());
325 aValue.Copy(KDefaultContentObject());
328 err = KErrCANotSupported;
334 TInt TF32DefaultAttributes::GetStringAttributeSet(const TDesC8& aHeaderData, RStringAttributeSet& aStringAttributeSet)
339 TBuf <KMaxDataTypeLength> buf;
341 TInt numAttributes = aStringAttributeSet.Count();
343 // loop through all the attriutes in the set and find their values
344 for(i = 0; i < numAttributes; i++)
347 attribute = aStringAttributeSet[i];
348 err = GetStringAttribute(aHeaderData, attribute, buf);
349 err = aStringAttributeSet.SetValue(attribute, buf, err);
358 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT