os/security/contentmgmt/contentaccessfwfordrm/source/f32agent/f32agentmanager.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/contentmgmt/contentaccessfwfordrm/source/f32agent/f32agentmanager.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,377 @@
1.4 +/*
1.5 +* Copyright (c) 2003-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/cafpanic.h>
1.23 +#include <caf/virtualpathptr.h>
1.24 +#include <caf/dirstreamable.h>
1.25 +#include "f32agentmanager.h"
1.26 +#include "f32defaultattributes.h"
1.27 +#include <caf/f32agentui.h>
1.28 +
1.29 +using namespace ContentAccess;
1.30 +
1.31 +CF32AgentManager* CF32AgentManager::NewL()
1.32 + {
1.33 + CF32AgentManager* self=new(ELeave) CF32AgentManager();
1.34 + CleanupStack::PushL(self);
1.35 + self->ConstructL();
1.36 + CleanupStack::Pop(self);
1.37 + return self;
1.38 + }
1.39 +
1.40 +CF32AgentManager::CF32AgentManager()
1.41 + {
1.42 + }
1.43 +
1.44 +CF32AgentManager::~CF32AgentManager()
1.45 + {
1.46 + delete iFileMan;
1.47 + iFs.Close();
1.48 + }
1.49 +
1.50 +void CF32AgentManager::ConstructL()
1.51 + {
1.52 + User::LeaveIfError(iFs.Connect());
1.53 + iFileMan = CFileMan::NewL(iFs);
1.54 + }
1.55 +
1.56 +TBool CF32AgentManager::IsRecognizedL(const TDesC&, TContentShareMode) const
1.57 + {
1.58 + // F32 should be the default agent and should never be called here
1.59 + return EFalse;
1.60 + }
1.61 +
1.62 +TBool CF32AgentManager::IsRecognizedL(RFile& ) const
1.63 + {
1.64 + return EFalse;
1.65 + }
1.66 +
1.67 +TBool CF32AgentManager::RecognizeFileL(const TDesC&, const TDesC8&, TDes8&, TDes8&) const
1.68 + {
1.69 + // F32 should be the default agent and should never be called here
1.70 + return EFalse;
1.71 + }
1.72 +
1.73 +TInt CF32AgentManager::DeleteFile(const TDesC &aFileName)
1.74 + {
1.75 + TInt err = KErrNone;
1.76 + CF32AgentUi* ui = NULL;
1.77 + TBool enableDelete = ETrue;
1.78 +
1.79 + // get a pointer to the UI
1.80 + TRAP(err, ui = &AgentUiL());
1.81 + if(err == KErrNone)
1.82 + {
1.83 + // UI confirmation supported, see if user wants to delete
1.84 + TRAP(err, enableDelete = ui->ConfirmDeleteL(aFileName));
1.85 + if(err == KErrNone && enableDelete)
1.86 + {
1.87 + // User agrees to delete
1.88 + err = iFs.Delete(aFileName);
1.89 + }
1.90 + }
1.91 + else if(err == KErrCANotSupported)
1.92 + {
1.93 + // UI is not supported, just delete it
1.94 + err = iFs.Delete(aFileName);
1.95 + }
1.96 + return err;
1.97 + }
1.98 +
1.99 +TInt CF32AgentManager::CopyFile(const TDesC& aSource, const TDesC& aDestination)
1.100 + {
1.101 + return iFileMan->Copy(aSource, aDestination);
1.102 + }
1.103 +
1.104 +TInt CF32AgentManager::CopyFile(RFile& aSource, const TDesC& aDestination)
1.105 + {
1.106 + return iFileMan->Copy(aSource, aDestination);
1.107 + }
1.108 +
1.109 +TInt CF32AgentManager::RenameFile(const TDesC& aSource, const TDesC& aDestination)
1.110 + {
1.111 + TInt result = iFileMan->Rename(aSource, aDestination);
1.112 + // If the files are on a different drive, Rename will fail
1.113 + // Therefore we simulate the Move by doing a Copy, followed by Delete
1.114 + if (result != KErrNone)
1.115 + {
1.116 + result = iFileMan->Copy(aSource,aDestination);
1.117 + if (result == KErrNone)
1.118 + {
1.119 + // If the copy was successful try and delete the original
1.120 + result = iFileMan->Delete(aSource);
1.121 + if (result != KErrNone)
1.122 + {
1.123 + // Delete failed so try to cleanup the destination file as we're going to exit with an error
1.124 + // We can safely ignore any error from this as the previous error is more important to propagate, since this is just cleanup
1.125 + iFileMan->Delete(aDestination);
1.126 + }
1.127 + }
1.128 + }
1.129 + return result;
1.130 + }
1.131 +
1.132 +TInt CF32AgentManager::MkDir(const TDesC& aPath)
1.133 + {
1.134 + return iFs.MkDir(aPath);
1.135 + }
1.136 +
1.137 +TInt CF32AgentManager::MkDirAll(const TDesC& aPath)
1.138 + {
1.139 + return iFs.MkDirAll(aPath);
1.140 + }
1.141 +
1.142 +TInt CF32AgentManager::RmDir(const TDesC& aPath)
1.143 + {
1.144 + return iFs.RmDir(aPath);
1.145 + }
1.146 +
1.147 +TInt CF32AgentManager::RenameDir(const TDesC& aOldName, const TDesC& aNewName)
1.148 + {
1.149 + return iFs.Rename(aOldName, aNewName);
1.150 + }
1.151 +
1.152 +TInt CF32AgentManager::GetDir(const TDesC& aName,TUint aEntryAttMask,TUint aEntrySortKey, CDir*& aEntryList) const
1.153 + {
1.154 + return iFs.GetDir(aName, aEntryAttMask, aEntrySortKey, aEntryList);
1.155 + }
1.156 +
1.157 +TInt CF32AgentManager::GetDir(const TDesC& aName,TUint aEntryAttMask,TUint aEntrySortKey, CDir*& aEntryList,CDir*& aDirList) const
1.158 + {
1.159 + return iFs.GetDir(aName, aEntryAttMask, aEntrySortKey, aEntryList, aDirList);
1.160 + }
1.161 +
1.162 +TInt CF32AgentManager::GetDir(const TDesC& aName,const TUidType& aEntryUid,TUint aEntrySortKey, CDir*& aFileList) const
1.163 + {
1.164 + return iFs.GetDir( aName, aEntryUid, aEntrySortKey, aFileList);
1.165 + }
1.166 +
1.167 +TInt CF32AgentManager::GetAttribute(TInt aAttribute, TInt& aValue, const TVirtualPathPtr& aVirtualPath)
1.168 + {
1.169 + // check that the virtual path exists
1.170 + if(TF32DefaultAttributes::CheckVirtualPath(aVirtualPath) != KErrNone)
1.171 + {
1.172 + return KErrNotFound;
1.173 + }
1.174 +
1.175 + return TF32DefaultAttributes::GetAttribute(aAttribute, aValue, aVirtualPath.URI());
1.176 + }
1.177 +
1.178 +TInt CF32AgentManager::GetAttributeSet(RAttributeSet& aAttributeSet, const TVirtualPathPtr& aVirtualPath)
1.179 + {
1.180 + // check that the virtual path exists
1.181 + if(TF32DefaultAttributes::CheckVirtualPath(aVirtualPath) != KErrNone)
1.182 + {
1.183 + return KErrNotFound;
1.184 + }
1.185 +
1.186 + return TF32DefaultAttributes::GetAttributeSet(aAttributeSet, aVirtualPath.URI());
1.187 + }
1.188 +
1.189 +TInt CF32AgentManager::GetStringAttribute(TInt aAttribute, TDes& aValue, const TVirtualPathPtr& aVirtualPath)
1.190 + {
1.191 + // check that the virtual path exists
1.192 + if(TF32DefaultAttributes::CheckVirtualPath(aVirtualPath) != KErrNone)
1.193 + {
1.194 + return KErrNotFound;
1.195 + }
1.196 +
1.197 + return TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, aVirtualPath.URI());
1.198 + }
1.199 +
1.200 +TInt CF32AgentManager::GetStringAttributeSet(RStringAttributeSet& aAttributeSet, const TVirtualPathPtr& aVirtualPath)
1.201 + {
1.202 + // check that the virtual path exists
1.203 + if(TF32DefaultAttributes::CheckVirtualPath(aVirtualPath) != KErrNone)
1.204 + {
1.205 + return KErrNotFound;
1.206 + }
1.207 +
1.208 + return TF32DefaultAttributes::GetStringAttributeSet(aAttributeSet, aVirtualPath.URI());
1.209 + }
1.210 +
1.211 +TInt CF32AgentManager::GetAttribute(TInt aAttribute, TInt& aValue, RFile& aFile, const TDesC& aUniqueId)
1.212 + {
1.213 + // Check that the client hasn't specified some incorrect UniqueId
1.214 + if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
1.215 + {
1.216 + return KErrNotFound;
1.217 + }
1.218 +
1.219 + return TF32DefaultAttributes::GetAttribute(aAttribute, aValue, aFile);
1.220 + }
1.221 +
1.222 +TInt CF32AgentManager::GetAttributeSet(RAttributeSet& aAttributeSet, RFile& aFile, const TDesC& aUniqueId)
1.223 + {
1.224 + // Check that the client hasn't specified some incorrect UniqueId
1.225 + if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
1.226 + {
1.227 + return KErrNotFound;
1.228 + }
1.229 +
1.230 + return TF32DefaultAttributes::GetAttributeSet(aAttributeSet, aFile);
1.231 + }
1.232 +
1.233 +TInt CF32AgentManager::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, RFile& aFile, const TDesC& aUniqueId)
1.234 + {
1.235 + // Check that the client hasn't specified some incorrect UniqueId
1.236 + if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
1.237 + {
1.238 + return KErrNotFound;
1.239 + }
1.240 +
1.241 + return TF32DefaultAttributes::GetStringAttributeSet(aStringAttributeSet, aFile);
1.242 + }
1.243 +
1.244 +TInt CF32AgentManager::GetStringAttribute(TInt aAttribute, TDes& aValue, RFile& aFile, const TDesC& aUniqueId)
1.245 + {
1.246 + // Check that the client hasn't specified some incorrect UniqueId
1.247 + if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
1.248 + {
1.249 + return KErrNotFound;
1.250 + }
1.251 +
1.252 + return TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, aFile);
1.253 + }
1.254 +
1.255 +
1.256 +void CF32AgentManager::NotifyStatusChange(const TDesC& , TEventMask , TRequestStatus& aStatus)
1.257 + {
1.258 + TRequestStatus* ptr = &aStatus;
1.259 + User::RequestComplete(ptr, KErrCANotSupported);
1.260 + }
1.261 +
1.262 +TInt CF32AgentManager::CancelNotifyStatusChange(const TDesC& , TRequestStatus& )
1.263 + {
1.264 + return KErrCANotSupported;
1.265 + }
1.266 +
1.267 +TInt CF32AgentManager::SetProperty(TAgentProperty aProperty, TInt aValue)
1.268 + {
1.269 + if(aProperty==EAgentPropertyAgentUI)
1.270 + // should only pass type EAgentPropertyAgentUI
1.271 + {
1.272 +
1.273 + CF32AgentUi* ui = NULL;
1.274 + // get a pointer to the UI
1.275 + TRAPD(err, ui = &AgentUiL());
1.276 + if(err)
1.277 + {
1.278 + return err;
1.279 + }
1.280 + return ui->SetProperty(aProperty, aValue);
1.281 + }
1.282 + else
1.283 + {
1.284 + return KErrCANotSupported;
1.285 + }
1.286 + }
1.287 +
1.288 +void CF32AgentManager::DisplayInfoL(TDisplayInfo aInfo, const TVirtualPathPtr& aVirtualPath)
1.289 + {
1.290 +#ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1.291 + RFile64 file;
1.292 +#else
1.293 + RFile file;
1.294 +#endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1.295 +
1.296 + // Check that the client hasn't specified some incorrect UniqueId
1.297 + User::LeaveIfError(TF32DefaultAttributes::CheckUniqueId(aVirtualPath.UniqueId()));
1.298 +
1.299 + // Open the file as read only
1.300 + User::LeaveIfError(file.Open(iFs, aVirtualPath.URI(), EFileShareReadersOnly | EFileStream | EFileRead));
1.301 + CleanupClosePushL(file);
1.302 + AgentUiL().DisplayInfoL(aInfo, file);
1.303 + CleanupStack::PopAndDestroy(&file);
1.304 + }
1.305 +
1.306 +void CF32AgentManager::DisplayInfoL(TDisplayInfo aInfo, RFile& aFile, const TDesC& aUniqueId)
1.307 + {
1.308 + // Check that the client hasn't specified some incorrect UniqueId
1.309 + User::LeaveIfError(TF32DefaultAttributes::CheckUniqueId(aUniqueId));
1.310 +
1.311 + // Open the file as read only
1.312 + AgentUiL().DisplayInfoL(aInfo, aFile);
1.313 + }
1.314 +
1.315 +
1.316 +TInt CF32AgentManager::AgentSpecificCommand(TInt , const TDesC8& , TDes8& )
1.317 + {
1.318 + return KErrCANotSupported;
1.319 + }
1.320 +
1.321 +void CF32AgentManager::AgentSpecificCommand(TInt , const TDesC8& , TDes8& , TRequestStatus& aStatus)
1.322 + {
1.323 + TRequestStatus* ptr = &aStatus;
1.324 + User::RequestComplete(ptr, KErrCANotSupported);
1.325 + }
1.326 +
1.327 +void CF32AgentManager::DisplayManagementInfoL()
1.328 + {
1.329 + User::Panic(KCafPanicString, ECafPanicF32AgentManagementInfoNotSupported);
1.330 + }
1.331 +
1.332 +CF32AgentUi& CF32AgentManager::AgentUiL()
1.333 + {
1.334 + if(!iAgentUi)
1.335 + {
1.336 + iAgentUi = TF32AgentUiFactory::CreateF32AgentUiL();
1.337 + }
1.338 + return *iAgentUi;
1.339 + }
1.340 +
1.341 +void CF32AgentManager::PrepareHTTPRequestHeaders(RStringPool& /*aStringPool*/, RHTTPHeaders& /*aRequestHeaders*/) const
1.342 + {
1.343 + User::Panic(KCafPanicString, ECafPanicF32AgentPrepareHTTPHeadersNotSupported);
1.344 + }
1.345 +
1.346 +#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1.347 +
1.348 +TBool CF32AgentManager::IsRecognizedL(const TDesC8& /*aHeaderData*/) const
1.349 + {
1.350 + // F32 should be the default agent and should never be called here
1.351 + return EFalse;
1.352 + }
1.353 +
1.354 +TBool CF32AgentManager::RecognizeContentL(const TDesC8&, TDes8&, TDes8&) const
1.355 + {
1.356 + // F32 should be the default agent and should never be called here
1.357 + return EFalse;
1.358 + }
1.359 +
1.360 +TInt CF32AgentManager::GetAttribute(const TDesC8& aHeaderData, TInt aAttribute, TInt& aValue)
1.361 + {
1.362 + return TF32DefaultAttributes::GetAttribute(aHeaderData, aAttribute, aValue);
1.363 + }
1.364 +
1.365 +TInt CF32AgentManager::GetAttributeSet(const TDesC8& aHeaderData, RAttributeSet& aAttributeSet)
1.366 + {
1.367 + return TF32DefaultAttributes::GetAttributeSet(aHeaderData, aAttributeSet);
1.368 + }
1.369 +
1.370 +TInt CF32AgentManager::GetStringAttribute(const TDesC8& aHeaderData, TInt aAttribute, TDes& aValue)
1.371 + {
1.372 + return TF32DefaultAttributes::GetStringAttribute(aHeaderData, aAttribute, aValue);
1.373 + }
1.374 +
1.375 +TInt CF32AgentManager::GetStringAttributeSet(const TDesC8& aHeaderData, RStringAttributeSet& aAttributeSet)
1.376 + {
1.377 + return TF32DefaultAttributes::GetStringAttributeSet(aHeaderData, aAttributeSet);
1.378 + }
1.379 +
1.380 +#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT