1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/contentmgmt/contentaccessfwfordrm/source/f32agent/f32agentdata.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,384 @@
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 <caf/caf.h>
1.23 +#include "f32agentdata.h"
1.24 +#include "f32defaultattributes.h"
1.25 +#include <caf/virtualpath.h>
1.26 +#include <caf/f32agentui.h>
1.27 +#include <e32def.h>
1.28 +
1.29 +using namespace ContentAccess;
1.30 +
1.31 +CF32AgentData* CF32AgentData::NewL(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode)
1.32 + {
1.33 + CF32AgentData* self = new (ELeave) CF32AgentData;
1.34 + CleanupStack::PushL(self);
1.35 + self->ConstructL(aVirtualPath, aShareMode);
1.36 + CleanupStack::Pop(self);
1.37 + return self;
1.38 + }
1.39 +
1.40 +CF32AgentData* CF32AgentData::NewL(RFile& aFile, const TDesC& aUniqueId)
1.41 + {
1.42 + CF32AgentData* self = new (ELeave) CF32AgentData;
1.43 + CleanupStack::PushL(self);
1.44 + self->ConstructL(aFile, aUniqueId);
1.45 + CleanupStack::Pop(self);
1.46 + return self;
1.47 + }
1.48 +
1.49 +#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1.50 +
1.51 +CF32AgentData* CF32AgentData::NewL(const TDesC8& aHeaderData)
1.52 + {
1.53 + CF32AgentData* self = new (ELeave) CF32AgentData;
1.54 + CleanupStack::PushL(self);
1.55 + self->ConstructL(aHeaderData);
1.56 + CleanupStack::Pop(self);
1.57 + return self;
1.58 + }
1.59 +
1.60 +void CF32AgentData::ConstructL(const TDesC8& aHeaderData)
1.61 + {
1.62 + if(aHeaderData.Length() > 0)
1.63 + iHeaderData = aHeaderData.AllocL();
1.64 + else
1.65 + User::Leave(KErrMissingWmdrmHeaderData);
1.66 + }
1.67 +
1.68 +#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1.69 +
1.70 +CF32AgentData::CF32AgentData()
1.71 + {
1.72 + }
1.73 +
1.74 +CF32AgentData::~CF32AgentData()
1.75 + {
1.76 + // Tidy up RFile and RFs
1.77 + iFile.Close();
1.78 + if(iVirtualPath) // opened by name
1.79 + {
1.80 + iFs.Close();
1.81 + }
1.82 +
1.83 + delete iVirtualPath;
1.84 +
1.85 +#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1.86 + delete iHeaderData;
1.87 +#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1.88 + }
1.89 +
1.90 +void CF32AgentData::ConstructL(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode)
1.91 + {
1.92 + iVirtualPath = CVirtualPath::NewL(aVirtualPath);
1.93 +
1.94 + // Check that the client hasn't specified some incorrect UniqueId
1.95 + User::LeaveIfError(TF32DefaultAttributes::CheckUniqueId(aVirtualPath.UniqueId()));
1.96 +
1.97 + TUint mode = TF32DefaultAttributes::GetFileMode(aShareMode);
1.98 + User::LeaveIfError(iFs.Connect());
1.99 +
1.100 + // Make the file session shareable
1.101 + User::LeaveIfError(iFs.ShareAuto());
1.102 +
1.103 + User::LeaveIfError(iFile.Open(iFs, aVirtualPath.URI(), mode));
1.104 + }
1.105 +
1.106 +void CF32AgentData::ConstructL(RFile& aFile, const TDesC& aUniqueId)
1.107 + {
1.108 +#ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1.109 + TInt64 pos = 0;
1.110 +#else
1.111 + TInt pos = 0;
1.112 +#endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1.113 +
1.114 + // Check that the client hasn't specified some incorrect UniqueId
1.115 + User::LeaveIfError(TF32DefaultAttributes::CheckUniqueId(aUniqueId));
1.116 +
1.117 + // When creating a CData from a file handle we must duplicate the file handle
1.118 + // before doing anything
1.119 + User::LeaveIfError(iFile.Duplicate(aFile));
1.120 + User::LeaveIfError(iFile.Seek(ESeekStart, pos)); // reset to start of file
1.121 + }
1.122 +
1.123 +void CF32AgentData::DataSizeL(TInt &aSize)
1.124 + {
1.125 +#ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1.126 + TInt64 size;
1.127 + User::LeaveIfError(iFile.Size(size));
1.128 + aSize=size;
1.129 +#else
1.130 + User::LeaveIfError(iFile.Size(aSize));
1.131 +#endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1.132 + }
1.133 +
1.134 +#ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1.135 +void CF32AgentData::DataSize64L(TInt64 &aSize)
1.136 + {
1.137 + User::LeaveIfError(iFile.Size(aSize));
1.138 + }
1.139 +#endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1.140 +
1.141 +TInt CF32AgentData::EvaluateIntent(TIntent /*aIntent*/)
1.142 + {
1.143 + return KErrNone;
1.144 + }
1.145 +
1.146 +TInt CF32AgentData::ExecuteIntent(TIntent /*aIntent*/)
1.147 + {
1.148 + return KErrNone;
1.149 + }
1.150 +
1.151 +TInt CF32AgentData::Read(TDes8& aDes)
1.152 + {
1.153 + return iFile.Read(aDes);
1.154 + }
1.155 +
1.156 +TInt CF32AgentData::Read(TDes8& aDes,TInt aLength)
1.157 + {
1.158 + return iFile.Read(aDes,aLength);
1.159 + }
1.160 +
1.161 +void CF32AgentData::Read(TDes8& aDes,TRequestStatus& aStatus)
1.162 + {
1.163 + iFile.Read(aDes, aStatus);
1.164 + }
1.165 +
1.166 +void CF32AgentData::Read(TDes8& aDes,
1.167 + TInt aLength,
1.168 + TRequestStatus& aStatus)
1.169 + {
1.170 + iFile.Read(aDes, aLength, aStatus);
1.171 + }
1.172 +
1.173 +TInt CF32AgentData::Read(TInt aPos, TDes8& aDes,
1.174 + TInt aLength,
1.175 + TRequestStatus& aStatus)
1.176 + {
1.177 + iFile.Read(aPos, aDes, aLength, aStatus);
1.178 + return KErrNone;
1.179 + }
1.180 +
1.181 +#ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1.182 +TInt CF32AgentData::Read64(TInt64 aPos, TDes8& aDes,
1.183 + TInt aLength,
1.184 + TRequestStatus& aStatus)
1.185 + {
1.186 + iFile.Read(aPos, aDes, aLength, aStatus);
1.187 + return KErrNone;
1.188 + }
1.189 +#endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1.190 +
1.191 +void CF32AgentData::ReadCancel(TRequestStatus& aStatus)
1.192 + {
1.193 + iFile.ReadCancel(aStatus);
1.194 + }
1.195 +
1.196 +TInt CF32AgentData::Seek(TSeek aMode, TInt& aPos)
1.197 + {
1.198 +#ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1.199 + TInt64 pos = aPos;
1.200 + TInt offset = iFile.Seek(aMode, pos);
1.201 + aPos = I64INT(pos);
1.202 +#else
1.203 + TInt offset = iFile.Seek(aMode, aPos);
1.204 +#endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1.205 + return offset;
1.206 + }
1.207 +
1.208 +#ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1.209 +TInt CF32AgentData::Seek64(TSeek aMode, TInt64& aPos)
1.210 + {
1.211 + return iFile.Seek(aMode, aPos);
1.212 + }
1.213 +#endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1.214 +
1.215 +
1.216 +TInt CF32AgentData::SetProperty(TAgentProperty aProperty, TInt aValue)
1.217 + {
1.218 +
1.219 + if(aProperty==EAgentPropertyAgentUI)
1.220 + // should only pass type EAgentPropertyAgentUI
1.221 + {
1.222 + CF32AgentUi* ui = NULL;
1.223 +
1.224 + // get a pointer to the UI
1.225 + TRAPD(err, ui = &AgentUiL());
1.226 + if(err)
1.227 + {
1.228 + return err;
1.229 + }
1.230 + return ui->SetProperty(aProperty, aValue);
1.231 + }
1.232 + else
1.233 + {
1.234 + return KErrCANotSupported;
1.235 + }
1.236 + }
1.237 +
1.238 +TInt CF32AgentData::GetAttribute(TInt aAttribute, TInt& aValue)
1.239 + {
1.240 +#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1.241 + if(iHeaderData)
1.242 + {
1.243 + return TF32DefaultAttributes::GetAttribute(*iHeaderData, aAttribute, aValue);
1.244 + }
1.245 +
1.246 + else if(iVirtualPath)
1.247 + {
1.248 + return TF32DefaultAttributes::GetAttribute(aAttribute, aValue, iVirtualPath->URI());
1.249 + }
1.250 +
1.251 + else
1.252 + {
1.253 + return TF32DefaultAttributes::GetAttribute(aAttribute, aValue, iFile);
1.254 + }
1.255 +#else
1.256 + if(iVirtualPath)
1.257 + {
1.258 + return TF32DefaultAttributes::GetAttribute(aAttribute, aValue, iVirtualPath->URI());
1.259 + }
1.260 + else
1.261 + {
1.262 + return TF32DefaultAttributes::GetAttribute(aAttribute, aValue, iFile);
1.263 + }
1.264 +#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1.265 + }
1.266 +
1.267 +TInt CF32AgentData::GetAttributeSet(RAttributeSet& aAttributeSet)
1.268 + {
1.269 +#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1.270 + if(iHeaderData)
1.271 + {
1.272 + return TF32DefaultAttributes::GetAttributeSet(*iHeaderData, aAttributeSet);
1.273 + }
1.274 +
1.275 + else if(iVirtualPath)
1.276 + {
1.277 + return TF32DefaultAttributes::GetAttributeSet(aAttributeSet, iVirtualPath->URI());
1.278 + }
1.279 +
1.280 + else
1.281 + {
1.282 + return TF32DefaultAttributes::GetAttributeSet(aAttributeSet, iFile);
1.283 + }
1.284 +#else
1.285 + if(iVirtualPath)
1.286 + {
1.287 + return TF32DefaultAttributes::GetAttributeSet(aAttributeSet, iVirtualPath->URI());
1.288 + }
1.289 + else
1.290 + {
1.291 + return TF32DefaultAttributes::GetAttributeSet(aAttributeSet, iFile);
1.292 + }
1.293 +#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1.294 + }
1.295 +
1.296 +TInt CF32AgentData::GetStringAttribute(TInt aAttribute, TDes& aValue)
1.297 + {
1.298 +#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1.299 + if(iHeaderData)
1.300 + {
1.301 + return TF32DefaultAttributes::GetStringAttribute(*iHeaderData, aAttribute, aValue);
1.302 + }
1.303 +
1.304 + else if(iVirtualPath)
1.305 + {
1.306 + return TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, iVirtualPath->URI());
1.307 + }
1.308 + else
1.309 + {
1.310 + return TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, iFile);
1.311 + }
1.312 +#else
1.313 + if(iVirtualPath)
1.314 + {
1.315 + return TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, iVirtualPath->URI());
1.316 + }
1.317 + else
1.318 + {
1.319 + return TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, iFile);
1.320 + }
1.321 +#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1.322 + }
1.323 +
1.324 +TInt CF32AgentData::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet)
1.325 + {
1.326 +#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1.327 + if(iHeaderData)
1.328 + {
1.329 + return TF32DefaultAttributes::GetStringAttributeSet(*iHeaderData, aStringAttributeSet);
1.330 + }
1.331 +
1.332 + else if(iVirtualPath)
1.333 + {
1.334 + return TF32DefaultAttributes::GetStringAttributeSet(aStringAttributeSet, iVirtualPath->URI());
1.335 + }
1.336 + else
1.337 + {
1.338 + return TF32DefaultAttributes::GetStringAttributeSet(aStringAttributeSet, iFile);
1.339 + }
1.340 +#else
1.341 + if(iVirtualPath)
1.342 + {
1.343 + return TF32DefaultAttributes::GetStringAttributeSet(aStringAttributeSet, iVirtualPath->URI());
1.344 + }
1.345 + else
1.346 + {
1.347 + return TF32DefaultAttributes::GetStringAttributeSet(aStringAttributeSet, iFile);
1.348 + }
1.349 +#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1.350 + }
1.351 +
1.352 +CF32AgentUi& CF32AgentData::AgentUiL()
1.353 + {
1.354 + if(!iAgentUi)
1.355 + {
1.356 + // load agent UI from f32AgentUi.dll
1.357 + iAgentUi = TF32AgentUiFactory::CreateF32AgentUiL();
1.358 + }
1.359 + return *iAgentUi;
1.360 + }
1.361 +
1.362 +#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1.363 +
1.364 +TInt CF32AgentData::Read(const TDesC8& aEncryptedInputDataPacket, TDes8& aDecryptedOutputDataPacket)
1.365 + {
1.366 + if(aEncryptedInputDataPacket.Length() <= 0)
1.367 + {
1.368 + return KErrInsufficientDataPacketLength;
1.369 + }
1.370 +
1.371 + aDecryptedOutputDataPacket = aEncryptedInputDataPacket;
1.372 + return KErrNone;
1.373 + }
1.374 +
1.375 +void CF32AgentData::Read(const TDesC8& aEncryptedInputDataPacket, TDes8& aDecryptedOutputDataPacket, TRequestStatus& aStatus)
1.376 + {
1.377 + TRequestStatus* status = &aStatus;
1.378 + if(aEncryptedInputDataPacket.Length() <= 0)
1.379 + {
1.380 + User::RequestComplete(status, KErrInsufficientDataPacketLength);
1.381 + }
1.382 +
1.383 + aDecryptedOutputDataPacket = aEncryptedInputDataPacket;
1.384 + User::RequestComplete(status, KErrNone);
1.385 + }
1.386 +
1.387 +#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT