os/security/contentmgmt/contentaccessfwfordrm/source/f32agent/f32defaultattributes.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/contentmgmt/contentaccessfwfordrm/source/f32agent/f32defaultattributes.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,358 @@
     1.4 +/*
     1.5 +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include <apgcli.h>
    1.23 +#include <f32file.h>
    1.24 +
    1.25 +#include <caf/attributeset.h>
    1.26 +#include <caf/stringattributeset.h>
    1.27 +#include <caf/virtualpath.h>
    1.28 +#include <caf/caferr.h>
    1.29 +#include "f32defaultattributes.h"
    1.30 +
    1.31 +
    1.32 +using namespace ContentAccess;
    1.33 +
    1.34 +TInt TF32DefaultAttributes::GetAttribute(TInt aAttribute, TInt& aValue, const TDesC& )
    1.35 +	{
    1.36 +	TInt err = KErrNone;
    1.37 +	// All files handled by the F32 agent are unprotected and have the same
    1.38 +	// standard set of attributes
    1.39 +	switch(aAttribute)
    1.40 +		{
    1.41 +		case EIsForwardable:
    1.42 +		case EIsModifyable:
    1.43 +		case EIsCopyable:
    1.44 +		case ECanPlay:
    1.45 +		case ECanPrint:
    1.46 +		case ECanExecute:
    1.47 +		case ECanView:
    1.48 +		case ECanRewind:
    1.49 +		case ECopyPaste:
    1.50 +		case ECanMove:
    1.51 +		case ECanRename:
    1.52 +		case ECanAutomaticConsume:
    1.53 +			aValue = ETrue;
    1.54 +			break;
    1.55 +		case EIsMediaPlayerOnly:
    1.56 +		case EIsAutomatedUseOnly:
    1.57 +		case EIsProtected:			
    1.58 +		case EPreviewAvailable:
    1.59 +			aValue = EFalse;
    1.60 +			break;
    1.61 +		case ETrackNumber:
    1.62 +		case EContentCDataInUse:
    1.63 +		case EContentVersion:
    1.64 +		default:
    1.65 +			err = KErrCANotSupported;
    1.66 +			break;
    1.67 +		};
    1.68 +	return err;
    1.69 +	}
    1.70 +
    1.71 +TInt TF32DefaultAttributes::GetAttributeSet(RAttributeSet& aAttributeSet, const TDesC& aUri) 
    1.72 +	{
    1.73 +	TInt i = 0;
    1.74 +	TInt attribute = 0;
    1.75 +	TInt value=0;
    1.76 +	TInt err = KErrNone;
    1.77 +	TInt numAttributes = aAttributeSet.Count();
    1.78 +	
    1.79 +	// loop through all the attriutes in the set and find their values
    1.80 +	for(i = 0; i < numAttributes; i++)
    1.81 +		{
    1.82 +		attribute = aAttributeSet[i];
    1.83 +		err = GetAttribute(attribute, value, aUri);
    1.84 +		aAttributeSet.SetValue(attribute, value, err);
    1.85 +		}	
    1.86 +	return KErrNone;
    1.87 +	}
    1.88 +
    1.89 +TInt TF32DefaultAttributes::GetStringAttribute(TInt aAttribute, TDes& aValue, const TDesC& aUri)
    1.90 +	{
    1.91 +	TInt err = KErrNone;
    1.92 +	TBuf8 <KMaxDataTypeLength> mimeType;
    1.93 +
    1.94 +	switch(aAttribute)
    1.95 +		{
    1.96 +		case EMimeType:
    1.97 +			TRAP(err, GetMimeTypeL(aUri, mimeType));
    1.98 +			if(err == KErrNone)
    1.99 +				{
   1.100 +				aValue.Copy(mimeType);
   1.101 +				}
   1.102 +			break;
   1.103 +		default:
   1.104 +			err = KErrCANotSupported;
   1.105 +			break;
   1.106 +		};
   1.107 +	return err;
   1.108 +	}
   1.109 +
   1.110 +TInt TF32DefaultAttributes::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, const TDesC& aUri)
   1.111 +	{
   1.112 +	TInt i = 0;
   1.113 +	TInt attribute = 0;
   1.114 +	TInt err = KErrNone;
   1.115 +	TBuf <KMaxDataTypeLength> buf;
   1.116 +
   1.117 +	TInt numAttributes = aStringAttributeSet.Count();
   1.118 +
   1.119 +	// loop through all the attriutes in the set and find their values
   1.120 +	for(i = 0; i < numAttributes; i++)
   1.121 +		{
   1.122 +		buf.SetLength(0);
   1.123 +		attribute = aStringAttributeSet[i];
   1.124 +		err = GetStringAttribute(attribute, buf, aUri);
   1.125 +		err = aStringAttributeSet.SetValue(attribute,buf, err);
   1.126 +		if(err != KErrNone)
   1.127 +			{
   1.128 +			return err;
   1.129 +			}
   1.130 +		}	
   1.131 +	return KErrNone;
   1.132 +	}
   1.133 +
   1.134 +void TF32DefaultAttributes::GetMimeTypeL(const TDesC& aURI, TDes8& aMimeType)
   1.135 +	{
   1.136 +	TUid appUid(KNullUid);
   1.137 +	TDataType dataType;
   1.138 +	RApaLsSession apparcSession;
   1.139 +	
   1.140 +	// Connect to Apparc
   1.141 +	User::LeaveIfError(apparcSession.Connect());
   1.142 +	CleanupClosePushL(apparcSession);
   1.143 +
   1.144 +	User::LeaveIfError(apparcSession.AppForDocument(aURI, appUid, dataType));
   1.145 +	
   1.146 +	if(dataType.Des8().Length() == 0)
   1.147 +		{
   1.148 +		User::Leave(KErrNotFound);
   1.149 +		}
   1.150 +
   1.151 +	aMimeType.Append(dataType.Des8());
   1.152 +	CleanupStack::PopAndDestroy(&apparcSession);
   1.153 +	}
   1.154 +
   1.155 +
   1.156 +TInt TF32DefaultAttributes::GetAttribute(TInt aAttribute, TInt& aValue, RFile& /*aFile*/)
   1.157 +	{
   1.158 +	return GetAttribute(aAttribute, aValue, KNullDesC);
   1.159 +	}
   1.160 +	
   1.161 +TInt TF32DefaultAttributes::GetAttributeSet(RAttributeSet& aAttributeSet, RFile& aFile)
   1.162 +	{
   1.163 +	TInt i = 0;
   1.164 +	TInt attribute = 0;
   1.165 +	TInt value = 0;
   1.166 +	TInt err = KErrNone;
   1.167 +	TInt numAttributes = aAttributeSet.Count();
   1.168 +	
   1.169 +	// loop through all the attributes in the set and find their values
   1.170 +	for(i = 0; i < numAttributes; i++)
   1.171 +		{
   1.172 +		attribute = aAttributeSet[i];
   1.173 +		err = GetAttribute(attribute, value, aFile);
   1.174 +		aAttributeSet.SetValue(attribute, value, err);
   1.175 +		}	
   1.176 +	return KErrNone;
   1.177 +	}
   1.178 +	
   1.179 +TInt TF32DefaultAttributes::GetStringAttribute(TInt aAttribute, TDes& aValue, RFile& aFile)
   1.180 +	{
   1.181 +	TInt err = KErrNone;
   1.182 +	TBuf8 <KMaxDataTypeLength> mimeType;
   1.183 +
   1.184 +	switch(aAttribute)
   1.185 +		{
   1.186 +		case EMimeType:
   1.187 +			TRAP(err, GetMimeTypeL(aFile, mimeType));
   1.188 +			if(err == KErrNone)
   1.189 +				{
   1.190 +				aValue.Copy(mimeType);
   1.191 +				}
   1.192 +			break;
   1.193 +		default:
   1.194 +			err = KErrCANotSupported;
   1.195 +			break;
   1.196 +		};
   1.197 +	return err;
   1.198 +	}
   1.199 +	
   1.200 +TInt TF32DefaultAttributes::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, RFile& aFile)
   1.201 +	{
   1.202 +	TInt i = 0;
   1.203 +	TInt attribute = 0;
   1.204 +	TInt err = KErrNone;
   1.205 +	TBuf <KMaxDataTypeLength> buf;
   1.206 +
   1.207 +	TInt numAttributes = aStringAttributeSet.Count();
   1.208 +
   1.209 +	// loop through all the attriutes in the set and find their values
   1.210 +	for(i = 0; i < numAttributes; i++)
   1.211 +		{
   1.212 +		buf.SetLength(0);
   1.213 +		attribute = aStringAttributeSet[i];
   1.214 +		err = GetStringAttribute(attribute, buf, aFile);
   1.215 +		err = aStringAttributeSet.SetValue(attribute,buf, err);
   1.216 +		if(err != KErrNone)
   1.217 +			{
   1.218 +			return err;
   1.219 +			}
   1.220 +		}	
   1.221 +	return KErrNone;
   1.222 +	}
   1.223 +	
   1.224 +void TF32DefaultAttributes::GetMimeTypeL(RFile& aFile, TDes8& aMimeType)
   1.225 +	{
   1.226 +	TUid appUid(KNullUid);
   1.227 +	TDataType dataType;
   1.228 +	RApaLsSession apparcSession;
   1.229 +	
   1.230 +	// Connect to Apparc
   1.231 +	User::LeaveIfError(apparcSession.Connect());
   1.232 +	CleanupClosePushL(apparcSession);
   1.233 +
   1.234 +	User::LeaveIfError(apparcSession.AppForDocument(aFile, appUid, dataType));
   1.235 +	
   1.236 +	if(dataType.Des8().Length() == 0)
   1.237 +		{
   1.238 +		User::Leave(KErrNotFound);
   1.239 +		}
   1.240 +	
   1.241 +	aMimeType.Append(dataType.Des8());
   1.242 +	CleanupStack::PopAndDestroy(&apparcSession);
   1.243 +	}
   1.244 +
   1.245 +TInt TF32DefaultAttributes::CheckUniqueId(const TDesC& aUniqueId)
   1.246 +	{
   1.247 +	// The only UniqueId values that make sense for the F32 agent are
   1.248 +	// a zero length descriptor (indicating the application is referring to the entire file 
   1.249 +	// or KDefaultContentObject which is also the entire file in the case of the F32 agent
   1.250 +	if(aUniqueId.Length() == 0 || aUniqueId == KDefaultContentObject())
   1.251 +		{
   1.252 +		return KErrNone;	
   1.253 +		}
   1.254 +	else 
   1.255 +		{
   1.256 +		return KErrNotFound;	
   1.257 +		}
   1.258 +	}
   1.259 +	
   1.260 +TInt TF32DefaultAttributes::CheckVirtualPath(const TVirtualPathPtr& aVirtualPath)
   1.261 +	{
   1.262 +	// check the Unique Id
   1.263 +	TInt err = CheckUniqueId(aVirtualPath.UniqueId());
   1.264 +	
   1.265 +	// check if the file exists
   1.266 +	
   1.267 +	
   1.268 +	return err;
   1.269 +	}	
   1.270 +	
   1.271 +TUint TF32DefaultAttributes::GetFileMode(TContentShareMode aMode)
   1.272 +	{
   1.273 +	
   1.274 +	TUint fileMode = EFileStream | EFileRead;
   1.275 +
   1.276 +	if(aMode  == EContentShareReadWrite)
   1.277 +		{
   1.278 +		fileMode |= EFileShareReadersOrWriters;
   1.279 +		}
   1.280 +	else if(aMode == EContentShareExclusive)
   1.281 +		{
   1.282 +		fileMode  |= EFileShareExclusive;
   1.283 +		}
   1.284 +	else
   1.285 +		{
   1.286 +		fileMode |= EFileShareReadersOnly;
   1.287 +		}
   1.288 +		
   1.289 +	return fileMode;
   1.290 +	}
   1.291 +
   1.292 +#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   1.293 +	
   1.294 +TInt TF32DefaultAttributes::GetAttribute(const TDesC8& /*aHeaderData*/, TInt aAttribute, TInt& aValue)
   1.295 +	{
   1.296 +	return GetAttribute(aAttribute, aValue, KNullDesC);
   1.297 +	}
   1.298 +	
   1.299 +TInt TF32DefaultAttributes::GetAttributeSet(const TDesC8& aHeaderData, RAttributeSet& aAttributeSet)
   1.300 +	{
   1.301 +	TInt i = 0;
   1.302 +	TInt attribute = 0;
   1.303 +	TInt value = 0;
   1.304 +	TInt err = KErrNone;
   1.305 +	TInt numAttributes = aAttributeSet.Count();
   1.306 +	
   1.307 +	// loop through all the attriutes in the set and find their values
   1.308 +	for(i = 0; i < numAttributes; i++)
   1.309 +		{
   1.310 +		attribute = aAttributeSet[i];
   1.311 +		err = GetAttribute(aHeaderData, attribute, value);
   1.312 +		aAttributeSet.SetValue(attribute, value, err);
   1.313 +		}	
   1.314 +	return KErrNone;
   1.315 +	}
   1.316 +	
   1.317 +TInt TF32DefaultAttributes::GetStringAttribute(const TDesC8& /*aHeaderData*/, TInt aAttribute, TDes& aValue)
   1.318 +	{
   1.319 +	TInt err = KErrNone;
   1.320 +	TBuf8 <KMaxDataTypeLength> mimeType;
   1.321 +
   1.322 +	switch(aAttribute)
   1.323 +		{
   1.324 +		case EMimeType:
   1.325 +			aValue.Copy(KNullDesC());
   1.326 +			break;
   1.327 +		case EContentID:
   1.328 +			aValue.Copy(KDefaultContentObject());
   1.329 +			break;
   1.330 +		default:
   1.331 +			err = KErrCANotSupported;
   1.332 +			break;
   1.333 +		};
   1.334 +	return err;
   1.335 +	}
   1.336 +	
   1.337 +TInt TF32DefaultAttributes::GetStringAttributeSet(const TDesC8& aHeaderData, RStringAttributeSet& aStringAttributeSet)
   1.338 +	{
   1.339 +	TInt i = 0;
   1.340 +	TInt attribute = 0;
   1.341 +	TInt err = KErrNone;
   1.342 +	TBuf <KMaxDataTypeLength> buf;
   1.343 +
   1.344 +	TInt numAttributes = aStringAttributeSet.Count();
   1.345 +
   1.346 +	// loop through all the attriutes in the set and find their values
   1.347 +	for(i = 0; i < numAttributes; i++)
   1.348 +		{
   1.349 +		buf.SetLength(0);
   1.350 +		attribute = aStringAttributeSet[i];
   1.351 +		err = GetStringAttribute(aHeaderData, attribute, buf);
   1.352 +		err = aStringAttributeSet.SetValue(attribute, buf, err);
   1.353 +		if(err != KErrNone)
   1.354 +			{
   1.355 +			return err;
   1.356 +			}
   1.357 +		}	
   1.358 +	return KErrNone;
   1.359 +	}
   1.360 +
   1.361 +#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT