os/security/contentmgmt/contentaccessfwfordrm/source/caf/manager.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2003-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 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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include <caf/manager.h>
    20 #include <caf/agentinterface.h>
    21 #include <caf/agent.h>
    22 #include "agentinfo.h"
    23 #include <caf/agentfactory.h>
    24 #include <caf/attributeset.h>
    25 #include <caf/caftypes.h>
    26 #include <caf/caferr.h>
    27 #include <caf/virtualpath.h>
    28 #include <caf/dirstreamable.h>
    29 #include <caf/rightsmanager.h>
    30 #include <caf/cafpanic.h>
    31 #include "resolver.h"
    32 
    33 using namespace ContentAccess;
    34 
    35 EXPORT_C CManager* CManager::NewL()
    36 	{
    37 	CManager* self = CManager::NewLC();
    38 	CleanupStack::Pop(self);
    39 	return self;
    40 	}
    41 	
    42 EXPORT_C CManager* CManager::NewLC()
    43 	{
    44 	CManager* self = new (ELeave) CManager;
    45 	CleanupStack::PushL(self);
    46 	self->ConstructL();
    47 	return self;
    48 	}
    49 
    50 CManager::CManager()
    51 	{
    52 	}
    53 
    54 CManager::~CManager()
    55 	{
    56 	delete iResolver;
    57 	}
    58 
    59 void CManager::ConstructL()
    60 	{
    61 	iResolver = CAgentResolver::NewL(EFalse);
    62 	}
    63 
    64 EXPORT_C TInt CManager::DeleteFile(const TDesC &aFileName) const
    65 	{
    66 	TRAPD(err, DoDeleteFileL(aFileName));
    67 	return err;
    68 	}
    69 	
    70 void CManager::DoDeleteFileL(const TDesC &aFileName) const
    71 	{
    72 	TFileName actualFileName;
    73 	
    74 	// initalise a pointer to the relevant CAgentManager object
    75 	// iResolver retains ownership of the pointer
    76 	CAgentInfo& agentInfo = iResolver->ResolveFileL(aFileName, actualFileName, EContentShareReadOnly);
    77 
    78 	User::LeaveIfError(agentInfo.AgentManagerL().DeleteFile(actualFileName));
    79 	}
    80 
    81 EXPORT_C TInt CManager::CopyFile(RFile& aSourceFile, const TDesC &aDestination) const
    82 	{
    83 	TRAPD(err, DoCopyFileL(aSourceFile, aDestination));
    84 	return err;
    85 	}
    86 
    87 void CManager::DoCopyFileL(RFile& aSourceFile, const TDesC &aDestination) const
    88 	{
    89 	TFileName actualDestination;
    90 	TBool thePrivateDir = EFalse;
    91 	TUid agentUid = KNullUid;
    92 
    93 	// Find out which agent owns the directory where the destination file lives
    94 	TUid destinationAgentUid = iResolver->ResolveDirectory(aDestination, actualDestination, thePrivateDir);
    95 	
    96 	if(destinationAgentUid != iResolver->DefaultAgentUid())
    97 		{
    98 		// Destination file is in an agent private directory
    99 		// Use destination agent to copy
   100 		agentUid = destinationAgentUid;
   101 		}
   102 	else
   103 		{
   104 		// Use RFile version of ResolveFileL to find the Agent Uid
   105 		agentUid = iResolver->ResolveFileL(aSourceFile).Agent().ImplementationUid();
   106 		}
   107 		
   108 	// If creating the appropriate CAgentManager succeeded ask the agent to copy the file
   109 	User::LeaveIfError(iResolver->AgentInfoL(agentUid).AgentManagerL().CopyFile(aSourceFile, actualDestination));
   110 	}
   111 
   112 EXPORT_C TInt CManager::CopyFile(const TDesC &aSource, const TDesC &aDestination) const
   113 	{
   114 	TRAPD(err, DoCopyFileL(aSource, aDestination));
   115 	return err;
   116 	}
   117 
   118 void CManager::DoCopyFileL(const TDesC &aSource, const TDesC &aDestination) const
   119 	{
   120 	TFileName actualSource;
   121 	TFileName actualDestination;
   122 	TBool thePrivateDir = EFalse;
   123 	TUid agentUid = KNullUid;
   124 	
   125 	// Find out which agent owns the directory where the source file lives
   126 	TUid sourceAgentUid = iResolver->ResolveDirectory(aSource, actualSource, thePrivateDir);
   127 
   128 	// Find out which agent owns the directory where the destination file lives
   129 	TUid destinationAgentUid = iResolver->ResolveDirectory(aDestination, actualDestination, thePrivateDir);
   130 	
   131 	if(sourceAgentUid != iResolver->DefaultAgentUid())
   132 		{
   133 		// Source file is in an agent private directory
   134 		// Use source agent to copy
   135 		agentUid = sourceAgentUid;
   136 		}
   137 	else if(destinationAgentUid != iResolver->DefaultAgentUid())
   138 		{
   139 		// Destination file is in an agent private directory
   140 		// Use destination agent to copy
   141 		agentUid = destinationAgentUid;
   142 		}
   143 	else
   144 		{
   145 		// Source and destination are in publicly accessable directories
   146 		agentUid = iResolver->ResolveFileL(aSource, actualSource, EContentShareReadOnly).Agent().ImplementationUid();
   147 		}
   148 		
   149 	// If creating the appropriate CAgentManager succeeded ask the agent to copy the file
   150 	User::LeaveIfError(iResolver->AgentInfoL(agentUid).AgentManagerL().CopyFile(actualSource, actualDestination));
   151 	}
   152 
   153 EXPORT_C TInt CManager::RenameFile(const TDesC& aSource, const TDesC& aDestination) const
   154 	{
   155 	TRAPD(err, DoRenameFileL(aSource, aDestination));
   156 	return err;
   157 	}
   158 
   159 void CManager::DoRenameFileL(const TDesC& aSource, const TDesC& aDestination) const
   160 	{
   161 	TFileName actualSource;
   162 	TFileName actualDestination;
   163 	TBool thePrivateDir = EFalse;
   164 	TUid agentUid = KNullUid;
   165 
   166 	// Find out which agent owns the directory where the source file lives
   167 	TUid sourceAgentUid = iResolver->ResolveDirectory(aSource, actualSource, thePrivateDir);
   168 
   169 	// Find out which agent owns the directory where the destination file lives
   170 	TUid destinationAgentUid = iResolver->ResolveDirectory(aDestination, actualDestination, thePrivateDir);
   171 	
   172 	if(sourceAgentUid != iResolver->DefaultAgentUid())
   173 		{
   174 		// Source file is in an agent private directory
   175 		// Use source agent to copy
   176 		agentUid = sourceAgentUid;
   177 		}
   178 	else if(destinationAgentUid != iResolver->DefaultAgentUid())
   179 		{
   180 		// Destination file is in an agent private directory
   181 		// Use destination agent to copy
   182 		agentUid = destinationAgentUid;
   183 		}
   184 	else
   185 		{
   186 		// Source and destination are in publicly accessable directories
   187 		agentUid = iResolver->ResolveFileL(aSource, actualSource, EContentShareReadOnly).Agent().ImplementationUid();
   188 		}
   189 		
   190 	// Ask the agent to move or rename the file
   191 	User::LeaveIfError(iResolver->AgentInfoL(agentUid).AgentManagerL().RenameFile(actualSource, actualDestination));
   192 	}
   193 
   194 EXPORT_C TInt CManager::MkDir(const TDesC &aPath) const
   195 	{
   196 	TRAPD(err, DoMkDirL(aPath));
   197 		
   198 	return err;	
   199 	}
   200 
   201 void CManager::DoMkDirL(const TDesC &aPath) const
   202 	{
   203 	TBool isThePrivateDir = EFalse;
   204 	TFileName actualPath;
   205 	
   206 	// Figure out which agent handles the directory
   207 	TUid uid = iResolver->ResolveDirectory(aPath, actualPath, isThePrivateDir);
   208 
   209 	User::LeaveIfError(iResolver->AgentInfoL(uid).AgentManagerL().MkDir(actualPath));
   210 	}
   211 
   212 EXPORT_C TInt CManager::MkDirAll (const TDesC &aPath) const
   213 	{
   214 	TRAPD(err, DoMkDirAllL(aPath));
   215 	return err;	
   216 	}
   217 
   218 void CManager::DoMkDirAllL(const TDesC &aPath) const
   219 	{
   220 	TBool isThePrivateDir = EFalse;
   221 	TFileName actualPath;
   222 	
   223 	// Figure out which agent handles the directory
   224 	TUid uid = iResolver->ResolveDirectory(aPath, actualPath, isThePrivateDir);
   225 	
   226 	User::LeaveIfError(iResolver->AgentInfoL(uid).AgentManagerL().MkDirAll(actualPath));
   227 	}
   228 
   229 EXPORT_C TInt CManager::RmDir(const TDesC &aPath) const
   230 	{
   231 	TRAPD(err, DoRmDirL(aPath));
   232 	return err;	
   233 	}
   234 
   235 void CManager::DoRmDirL(const TDesC &aPath) const
   236 	{
   237 	TBool isThePrivateDir = EFalse;
   238 	TFileName actualPath;
   239 	
   240 	// Figure out which agent handles the directory
   241 	TUid uid = iResolver->ResolveDirectory(aPath, actualPath, isThePrivateDir);
   242 
   243 	if(isThePrivateDir)
   244 		{
   245 		User::Leave(KErrAccessDenied);	
   246 		}
   247 	else
   248 		{
   249 		User::LeaveIfError(iResolver->AgentInfoL(uid).AgentManagerL().RmDir(actualPath));
   250 		}
   251 	}
   252 
   253 EXPORT_C TInt CManager::RenameDir(const TDesC& aOldName, const TDesC& aNewName) const
   254 		{
   255 		TRAPD(err, DoRenameDirL(aOldName, aNewName));
   256 		return err;
   257 		}
   258 
   259 void CManager::DoRenameDirL(const TDesC &aOldName, const TDesC& aNewName) const
   260 	{
   261 	TPath actualSource;
   262 	TPath actualDestination;
   263 	TBool thePrivateDir = EFalse;
   264 	TUid agentUid = iResolver->DefaultAgentUid();
   265 
   266 	// Find out which agent owns the directory where the source file lives
   267 	TUid sourceAgentUid = iResolver->ResolveDirectory(aOldName, actualSource, thePrivateDir);
   268 
   269 	// Find out which agent owns the directory where the destination file lives
   270 	TUid destinationAgentUid = iResolver->ResolveDirectory(aNewName, actualDestination, thePrivateDir);
   271 	
   272 	if(sourceAgentUid != iResolver->DefaultAgentUid())
   273 		{
   274 		// Source file is in an agent private directory
   275 		// Use source agent to copy
   276 		agentUid = sourceAgentUid;
   277 		}
   278 	else if(destinationAgentUid != iResolver->DefaultAgentUid())
   279 		{
   280 		// Destination file is in an agent private directory
   281 		// Use destination agent to copy
   282 		agentUid = destinationAgentUid;
   283 		}
   284 		
   285 	// Ask the agent to move or rename the file
   286 	User::LeaveIfError(iResolver->AgentInfoL(agentUid).AgentManagerL().RenameDir(actualSource, actualDestination));
   287 	}
   288 
   289 
   290 EXPORT_C TInt CManager::GetDir(const TDesC &aName, TUint aEntryAttMask, TUint aEntrySortKey, CDir *&aEntryList) const 
   291 	{
   292 	TRAPD(err, DoGetDirL(aName, aEntryAttMask, aEntrySortKey, aEntryList));
   293 	return err;
   294 	}
   295 	
   296 void CManager::DoGetDirL(const TDesC &aName, TUint aEntryAttMask, TUint aEntrySortKey, CDir *&aEntryList) const 	
   297 	{
   298 	TBool isThePrivateDir = EFalse;
   299 	TFileName actualPath;
   300 	
   301 	// Figure out which agent handles the directory
   302 	TUid uid = iResolver->ResolveDirectory(aName, actualPath, isThePrivateDir);
   303 
   304 	if(isThePrivateDir)
   305 		{
   306 		// If we are doing GetDir of C:\\private\\ just create an empty CDirStreamable
   307 		aEntryList = CDirStreamable::NewL();
   308 		}
   309 	else
   310 		{
   311 		User::LeaveIfError(iResolver->AgentInfoL(uid).AgentManagerL().GetDir(actualPath, aEntryAttMask, aEntrySortKey, aEntryList));
   312 		}
   313 	}
   314 
   315 EXPORT_C TInt CManager::GetDir(const TDesC &aName, TUint aEntryAttMask, TUint aEntrySortKey, CDir *&aEntryList, CDir *&aDirList) const 
   316 	{
   317 	TRAPD(err, DoGetDirL(aName, aEntryAttMask, aEntrySortKey, aEntryList, aDirList));
   318 	return err;
   319 	}
   320 
   321 void CManager::DoGetDirL(const TDesC &aName, TUint aEntryAttMask, TUint aEntrySortKey, CDir *&aEntryList, CDir *&aDirList) const 
   322 	{
   323 	TBool isThePrivateDir = EFalse;
   324 	TFileName actualPath;
   325 	CDir* emptyDirList;
   326 	
   327 	// Figure out which agent handles the directory
   328 	TUid uid = iResolver->ResolveDirectory(aName, actualPath, isThePrivateDir);
   329 
   330 	if(isThePrivateDir)
   331 		{
   332 		// If we are doing GetDir of C:\\private\\ just create an empty entryList
   333 		emptyDirList = CDirStreamable::NewL();
   334 		CleanupStack::PushL(emptyDirList);
   335 
   336 		GetListOfAgentPrivateDirectoriesL(aDirList);
   337 
   338 		CleanupStack::Pop(emptyDirList);
   339 		aEntryList = emptyDirList;		
   340 		}
   341 	else
   342 		{
   343 		User::LeaveIfError(iResolver->AgentInfoL(uid).AgentManagerL().GetDir(actualPath, aEntryAttMask, aEntrySortKey, aEntryList, aDirList));
   344 		}
   345 	}
   346 
   347 EXPORT_C TInt CManager::GetDir(const TDesC &aName, const TUidType &aEntryUid, TUint aEntrySortKey, CDir *&aFileList) const 
   348 	{
   349 	TRAPD(err, DoGetDirL(aName, aEntryUid, aEntrySortKey, aFileList));
   350 	return err;
   351 	}
   352 
   353 void CManager::DoGetDirL(const TDesC &aName, const TUidType &aEntryUid, TUint aEntrySortKey, CDir *&aFileList) const 
   354 	{
   355 	TBool isThePrivateDir = EFalse;
   356 	TFileName actualPath;
   357 	
   358 	// Figure out which agent handles the directory
   359 	TUid uid = iResolver->ResolveDirectory(aName, actualPath, isThePrivateDir);
   360 
   361 	if(isThePrivateDir)
   362 		{
   363 		// We've been asked to look at C:\\private\\ just return an empty CDirStreamable
   364 		aFileList = CDirStreamable::NewL();
   365 		}
   366 	else
   367 		{
   368 		User::LeaveIfError(iResolver->AgentInfoL(uid).AgentManagerL().GetDir(actualPath, aEntryUid, aEntrySortKey, aFileList));
   369 		}
   370 	}
   371 
   372 EXPORT_C TInt CManager::GetAttribute(TInt aAttribute, TInt& aValue, const TVirtualPathPtr& aVirtualPath) const
   373 	{
   374 	TRAPD(err, DoGetAttributeL(aAttribute, aValue, aVirtualPath));
   375 	return err;
   376 	}
   377 
   378 void CManager::DoGetAttributeL(TInt aAttribute, TInt& aValue, const TVirtualPathPtr& aVirtualPath) const
   379 	{
   380 	HBufC* uriBuffer = HBufC::NewLC(aVirtualPath.URI().Length() + KMaxSIDLength);
   381 	TPtr uri = uriBuffer->Des();
   382 
   383 	// Find the agent who handles the file 
   384 	CAgentInfo& agentInfo = iResolver->ResolveFileL(aVirtualPath.URI(),uri, EContentShareReadOnly);
   385 	User::LeaveIfError(agentInfo.AgentManagerL().GetAttribute(aAttribute, aValue, TVirtualPathPtr(uri, aVirtualPath.UniqueId())));
   386 	CleanupStack::PopAndDestroy(uriBuffer);
   387 	}
   388 	
   389 EXPORT_C TInt CManager::GetAttribute(TInt aAttribute, TInt& aValue, RFile& aFile, const TDesC& aUniqueId) 
   390 	{
   391 	TRAPD(err, DoGetAttributeL(aAttribute, aValue, aFile, aUniqueId));
   392 	return err;
   393 	}
   394 
   395 void CManager::DoGetAttributeL(TInt aAttribute, TInt& aValue, RFile& aFile, const TDesC& aUniqueId) const
   396 	{
   397 	// Find the agent who handles the file 
   398 	CAgentInfo& agentInfo = iResolver->ResolveFileL(aFile);
   399 	User::LeaveIfError(agentInfo.AgentManagerL().GetAttribute(aAttribute, aValue, aFile, aUniqueId));
   400 	}
   401 	
   402 
   403 EXPORT_C TInt CManager::GetStringAttribute(TInt aAttribute, TDes& aValue, const TVirtualPathPtr& aVirtualPath) const
   404 	{
   405 	TRAPD(err, DoGetStringAttributeL(aAttribute, aValue, aVirtualPath));
   406 	return err;
   407 	}
   408 	
   409 void CManager::DoGetStringAttributeL(TInt aAttribute, TDes& aValue, const TVirtualPathPtr& aVirtualPath) const
   410 	{
   411 	HBufC* uriBuffer = HBufC::NewLC(aVirtualPath.URI().Length() + KMaxSIDLength);
   412 	TPtr uri = uriBuffer->Des();
   413 
   414 
   415 	// Find the agent who handles the file 
   416 	CAgentInfo& agentInfo = iResolver->ResolveFileL(aVirtualPath.URI(), uri, EContentShareReadOnly);
   417 	
   418 	// find out the attribute
   419 	User::LeaveIfError(agentInfo.AgentManagerL().GetStringAttribute(aAttribute, aValue, TVirtualPathPtr(uri,aVirtualPath.UniqueId())));
   420 	CleanupStack::PopAndDestroy(uriBuffer);
   421 	}
   422 	
   423 EXPORT_C TInt CManager::GetStringAttribute (TInt aAttribute, TDes& aValue, RFile& aFile, const TDesC& aUniqueId)	
   424 	{
   425 	TRAPD(err, DoGetStringAttributeL(aAttribute, aValue, aFile, aUniqueId));
   426 	return err;
   427 	}
   428 	
   429 void CManager::DoGetStringAttributeL(TInt aAttribute, TDes& aValue, RFile& aFile, const TDesC& aUniqueId) const
   430 	{
   431 	// Find the agent who handles the file 
   432 	CAgentInfo& agentInfo = iResolver->ResolveFileL(aFile);	
   433 	// find out the attribute
   434 	User::LeaveIfError(agentInfo.AgentManagerL().GetStringAttribute(aAttribute, aValue, aFile, aUniqueId));
   435 	}
   436 
   437 EXPORT_C TInt CManager::GetAttributeSet(RAttributeSet& aAttributeSet, const TVirtualPathPtr& aVirtualPath) const
   438 	{
   439 	TRAPD(err, DoGetAttributeSetL(aAttributeSet, aVirtualPath));
   440 	return err;
   441 	}
   442 
   443 void CManager::DoGetAttributeSetL(RAttributeSet& aAttributeSet, const TVirtualPathPtr& aVirtualPath) const	
   444 	{
   445 	HBufC* uriBuffer = HBufC::NewLC(aVirtualPath.URI().Length() + KMaxSIDLength);
   446 	TPtr uri = uriBuffer->Des();
   447 	
   448 	// Find the agent who handles the file 
   449 	CAgentInfo& agentInfo = iResolver->ResolveFileL(aVirtualPath.URI(), uri, EContentShareReadOnly);
   450 	
   451 	User::LeaveIfError(agentInfo.AgentManagerL().GetAttributeSet(aAttributeSet, TVirtualPathPtr(uri, aVirtualPath.UniqueId())));
   452 	CleanupStack::PopAndDestroy(uriBuffer);
   453 	}
   454 
   455 EXPORT_C TInt CManager::GetAttributeSet (RAttributeSet& aAttributeSet, RFile& aFile, const TDesC& aUniqueId)
   456 	{
   457 	TRAPD(err, DoGetAttributeSetL(aAttributeSet, aFile, aUniqueId));
   458 	return err;
   459 	}
   460 
   461 void CManager::DoGetAttributeSetL(RAttributeSet& aAttributeSet, RFile& aFile, const TDesC& aUniqueId) const	
   462 	{
   463 	// Find the agent who handles the file 
   464 	CAgentInfo& agentInfo = iResolver->ResolveFileL(aFile);
   465 	User::LeaveIfError(agentInfo.AgentManagerL().GetAttributeSet(aAttributeSet, aFile, aUniqueId));
   466 	}	
   467 
   468 EXPORT_C TInt CManager::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, const TVirtualPathPtr& aVirtualPath) const
   469 	{
   470 	TRAPD(err, DoGetStringAttributeSetL(aStringAttributeSet, aVirtualPath));
   471 	return err;
   472 	}
   473 
   474 void CManager::DoGetStringAttributeSetL(RStringAttributeSet& aStringAttributeSet, const TVirtualPathPtr& aVirtualPath) const
   475 	{
   476 	HBufC* uriBuffer = HBufC::NewLC(aVirtualPath.URI().Length() + KMaxSIDLength);
   477 	TPtr uri = uriBuffer->Des();
   478 	
   479 	// Find the agent who handles the file 
   480 	CAgentInfo& agentInfo = iResolver->ResolveFileL(aVirtualPath.URI(),uri, EContentShareReadOnly);
   481 
   482 	// find out the array of attributes
   483 	User::LeaveIfError(agentInfo.AgentManagerL().GetStringAttributeSet(aStringAttributeSet, TVirtualPathPtr(uri, aVirtualPath.UniqueId())));
   484 	CleanupStack::PopAndDestroy(uriBuffer);
   485 	}
   486 
   487 EXPORT_C TInt CManager::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, RFile& aFile, const TDesC& aUniqueId)
   488 	{
   489 	TRAPD(err, DoGetStringAttributeSetL(aStringAttributeSet, aFile, aUniqueId));
   490 	return err;
   491 	}
   492 
   493 void CManager::DoGetStringAttributeSetL(RStringAttributeSet& aStringAttributeSet, RFile& aFile, const TDesC& aUniqueId) const
   494 	{
   495 	// Find the agent who handles the file 
   496 	CAgentInfo& agentInfo = iResolver->ResolveFileL(aFile);
   497 	// find out the array of attributes
   498 	User::LeaveIfError(agentInfo.AgentManagerL().GetStringAttributeSet(aStringAttributeSet, aFile, aUniqueId));
   499 	}
   500 
   501 EXPORT_C void CManager::NotifyStatusChange(const TDesC &aURI, TEventMask aMask, TRequestStatus &aStatus) 
   502 	{
   503 	TRAPD(err, DoNotifyStatusChangeL(aURI, aMask, aStatus));
   504 	if(err != KErrNone)
   505 		{
   506 		// Must have failed before asking the agent for status
   507 		TRequestStatus* status = &aStatus;
   508 		User::RequestComplete(status, err);
   509 		}
   510 	}
   511 
   512 void CManager::DoNotifyStatusChangeL(const TDesC &aURI, TEventMask aMask, TRequestStatus &aStatus) 
   513 	{
   514 	HBufC* uriBuffer = HBufC::NewLC(aURI.Length() + KMaxSIDLength);
   515 	TPtr uri = uriBuffer->Des();
   516 	
   517 	// Find the agent who handles the file 
   518 	CAgentInfo& agentInfo = iResolver->ResolveFileL(aURI, uri, EContentShareReadOnly);
   519 	
   520 	// Ask the agent to notifiy the client when the status of the given file changes
   521 	agentInfo.AgentManagerL().NotifyStatusChange(uri, aMask, aStatus);
   522 	CleanupStack::PopAndDestroy(uriBuffer);
   523 	}
   524 
   525 EXPORT_C TInt CManager::CancelNotifyStatusChange (const TDesC &aURI, TRequestStatus &aStatus) 
   526 	{
   527 	TRAPD(err, DoCancelNotifyStatusChangeL(aURI, aStatus));
   528 	return err;
   529 	}
   530 
   531 void CManager::DoCancelNotifyStatusChangeL(const TDesC &aURI, TRequestStatus &aStatus) 
   532 	{
   533 	HBufC* uriBuffer = HBufC::NewLC(aURI.Length() + KMaxSIDLength);
   534 	TPtr uri = uriBuffer->Des();
   535 	
   536 	// Find the agent who handles the file 
   537 	CAgentInfo& agentInfo = iResolver->ResolveFileL(aURI, uri, EContentShareReadOnly);
   538 	
   539 	// cancel the notification request
   540 	User::LeaveIfError(agentInfo.AgentManagerL().CancelNotifyStatusChange(uri, aStatus));
   541 	CleanupStack::PopAndDestroy(uriBuffer);
   542 	}
   543 
   544 EXPORT_C TInt CManager::SetProperty(TAgentProperty aProperty, TInt aValue)
   545 	{
   546 	TRAPD(err, DoSetPropertyL(aProperty, aValue));
   547 	return err;
   548 	}
   549 
   550 void CManager::DoSetPropertyL(TAgentProperty aProperty, TInt aValue)
   551 	{
   552 	TInt err = KErrNone;
   553 	TInt rVal = KErrNone;
   554 	TInt i = 0;
   555 	TInt count = iResolver->AgentInfoCount();
   556 	
   557 	CAgentInfo &defaultAgentInfo = iResolver->AgentInfoL(iResolver->DefaultAgentUid());
   558 	err = defaultAgentInfo.AgentManagerL().SetProperty(aProperty, aValue);
   559 	if(err == KErrNoMemory)
   560 		{
   561 		User::Leave(KErrNoMemory);
   562 		}
   563 	
   564 	// Ignore F32 agent return code unless it's KErrNoMemory
   565 	err= KErrNone;
   566 	
   567 	// Set the property in all the other agents
   568 	for( i = 0; i < count; i++)
   569 		{
   570 		CAgentInfo& agentInfo = iResolver->AgentInfo(i);
   571 		err = agentInfo.AgentManagerL().SetProperty(aProperty, aValue);
   572 		if(err == KErrNoMemory)
   573 			{
   574 			User::Leave(KErrNoMemory);
   575 			}
   576 			
   577 		// If an error occurred and no previous error has occured
   578 		if(err != KErrNone && rVal == KErrNone)
   579 			{
   580 			rVal = err;
   581 			}
   582 		}
   583 	
   584 	// leave if an error occurred in any agent
   585 	User::LeaveIfError(rVal);
   586 	}
   587 
   588 EXPORT_C void CManager::DisplayInfoL(TDisplayInfo aInfo, const TVirtualPathPtr& aVirtualPath)
   589 	{
   590 	HBufC* uriBuffer = HBufC::NewLC(aVirtualPath.URI().Length() + KMaxSIDLength);
   591 	TPtr uri = uriBuffer->Des();
   592 
   593 	// Find the agent who handles the file 
   594 	CAgentInfo& agentInfo = iResolver->ResolveFileL(aVirtualPath.URI(), uri, EContentShareReadOnly);
   595 	
   596 	// find out the attribute
   597 	agentInfo.AgentManagerL().DisplayInfoL(aInfo, TVirtualPathPtr(uri, aVirtualPath.UniqueId()));
   598 	CleanupStack::PopAndDestroy(uriBuffer);
   599 	}
   600 
   601 EXPORT_C void CManager::DisplayInfoL(TDisplayInfo aInfo, RFile& aFile, const TDesC& aUniqueId) 
   602 	{
   603 	// Find the agent who handles the file 
   604 	CAgentInfo& agentInfo = iResolver->ResolveFileL(aFile);
   605 	// find out the attribute
   606 	agentInfo.AgentManagerL().DisplayInfoL(aInfo, aFile, aUniqueId);
   607 	}
   608 
   609 EXPORT_C void CManager::ListAgentsL (RArray <TAgent>& aAgents) 
   610 	{
   611 	TInt i = 0;
   612 	TBuf <KMaxAgentNameLength> agentName;
   613 	TInt count = iResolver->AgentInfoCount();
   614 	
   615 	// build the array of pointers from CAgentResolver
   616 	for(i = 0; i < count; i++)
   617 		{
   618 		TAgent agent = iResolver->AgentInfo(i).Agent();
   619 		User::LeaveIfError(aAgents.Append(agent));
   620 		}
   621 	}
   622 
   623 EXPORT_C TInt CManager::AgentSpecificCommand (TAgent &aAgent, TInt aCommand, const TDesC8 &aInputBuffer, TDes8 &aOutputBuffer) 
   624 	{
   625 	CAgentManager* manager = NULL;
   626 	TInt err = KErrNone;
   627 	TRAP(err, manager = &iResolver->AgentInfoL(aAgent.ImplementationUid()).AgentManagerL());
   628 	if(err == KErrNone)
   629 		{
   630 		err = manager->AgentSpecificCommand (aCommand, aInputBuffer, aOutputBuffer);
   631 		}
   632 	return err;
   633 	}
   634 
   635 EXPORT_C void CManager::AgentSpecificCommand (TAgent &aAgent, TInt aCommand, const TDesC8 &aInputBuffer, TDes8 &aOutputBuffer, TRequestStatus &aStatus) 
   636 	{
   637 	CAgentManager* manager = NULL;
   638 	
   639 	TRAPD(err, manager = &iResolver->AgentInfoL(aAgent.ImplementationUid()).AgentManagerL());
   640 	if(err == KErrNone)
   641 		{
   642 		manager->AgentSpecificCommand (aCommand, aInputBuffer, aOutputBuffer, aStatus);
   643 		}
   644 	else
   645 		{
   646 		TRequestStatus* status = &aStatus;
   647 		User::RequestComplete(status, err);
   648 		}
   649 	}
   650 
   651 EXPORT_C void CManager::DisplayManagementInfoL(TAgent& aAgent)
   652 	{
   653 	CAgentInfo& agentInfo = iResolver->AgentInfoL(aAgent.ImplementationUid());
   654 
   655 	// Ask agent to display management info
   656 	agentInfo.AgentManagerL().DisplayManagementInfoL();
   657 	}
   658 
   659 EXPORT_C CRightsManager* CManager::CreateRightsManagerL(TAgent& aAgent) const
   660 	{
   661 	// Create a rights manager
   662 	return CRightsManager::NewL(aAgent.ImplementationUid());
   663 	}
   664 
   665 void CManager::GetListOfAgentPrivateDirectoriesL(CDir *&aDir) const
   666 	{
   667 	CDirStreamable *ptr = NULL;
   668 	// fill in the agent directories under the \\private\\ directory 
   669 	TInt i = 0;
   670 	TInt count = iResolver->AgentInfoCount();
   671 	
   672 	TBuf <KMaxAgentNameLength> agentName;
   673 	TPath privateDirectory;
   674 	
   675 	// Create CDirStreamable object
   676 	ptr = CDirStreamable::NewL();
   677 	CleanupStack::PushL(ptr);
   678 	
   679 	// set aDir to point to the CDirStreamable we just created
   680 	for(i = 0; i < count; i++)
   681 		{
   682 		// only fill in the agents that have a private directory that is not blank
   683 		if(iResolver->AgentInfo(i).PrivateDirectoryName().Length() != 0)
   684 			{
   685 			TEntry aEntry;
   686 			aEntry.iName = iResolver->AgentInfo(i).Agent().Name();
   687 			aEntry.iAtt = KEntryAttDir;
   688 			aEntry.iType = TUidType();
   689 			aEntry.iSize = 0;
   690 			ptr->AddL(aEntry);
   691 			}
   692 		}
   693 	CleanupStack::Pop(ptr);
   694 	aDir = ptr;
   695 	}
   696 
   697 #ifndef REMOVE_CAF1
   698 EXPORT_C void CManager::DeleteFileL(const TDesC &aFileName)
   699 	{
   700 	CManager *m = CManager::NewLC();
   701 	User::LeaveIfError(m->DeleteFile(aFileName));
   702 	CleanupStack::PopAndDestroy(m);
   703 	}
   704 #endif // REMOVE_CAF1
   705 
   706 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   707 
   708 EXPORT_C TInt CManager::GetAttribute(const TDesC8& aHeaderData, TInt aAttribute, TInt& aValue) const
   709 	{
   710 	TRAPD(err, DoGetAttributeL(aHeaderData, aAttribute, aValue));
   711 	return err;
   712 	}
   713 
   714 void CManager::DoGetAttributeL(const TDesC8& aHeaderData, TInt aAttribute, TInt& aValue) const
   715 	{
   716 	// Find the agent who handles the file 
   717 	CAgentInfo& agentInfo = iResolver->ResolveFileL(aHeaderData);
   718 	User::LeaveIfError(agentInfo.AgentManagerL().GetAttribute(aHeaderData, aAttribute, aValue));
   719 	}
   720 	
   721 EXPORT_C TInt CManager::GetAttributeSet(const TDesC8& aHeaderData, RAttributeSet& aAttributeSet) const
   722 	{
   723 	TRAPD(err, DoGetAttributeSetL(aHeaderData, aAttributeSet));
   724 	return err;
   725 	}
   726 
   727 void CManager::DoGetAttributeSetL(const TDesC8& aHeaderData, RAttributeSet& aAttributeSet) const	
   728 	{
   729 	// Find the agent who handles the file 
   730 	CAgentInfo& agentInfo = iResolver->ResolveFileL(aHeaderData);
   731 	
   732 	User::LeaveIfError(agentInfo.AgentManagerL().GetAttributeSet(aHeaderData, aAttributeSet));
   733 	}
   734 	
   735 EXPORT_C TInt CManager::GetStringAttribute(const TDesC8& aHeaderData, TInt aAttribute, TDes& aValue) const
   736 	{
   737 	TRAPD(err, DoGetStringAttributeL(aHeaderData, aAttribute, aValue));
   738 	return err;
   739 	}
   740 	
   741 void CManager::DoGetStringAttributeL(const TDesC8& aHeaderData, TInt aAttribute, TDes& aValue) const
   742 	{
   743 	// Find the agent who handles the file 
   744 	CAgentInfo& agentInfo = iResolver->ResolveFileL(aHeaderData);
   745 	
   746 	// find out the attribute
   747 	User::LeaveIfError(agentInfo.AgentManagerL().GetStringAttribute(aHeaderData, aAttribute, aValue));
   748 	}
   749 	
   750 EXPORT_C TInt CManager::GetStringAttributeSet(const TDesC8& aHeaderData, RStringAttributeSet& aStringAttributeSet) const
   751 	{
   752 	TRAPD(err, DoGetStringAttributeSetL(aHeaderData, aStringAttributeSet));
   753 	return err;
   754 	}
   755 
   756 void CManager::DoGetStringAttributeSetL(const TDesC8& aHeaderData, RStringAttributeSet& aStringAttributeSet) const
   757 	{
   758 	// Find the agent who handles the file 
   759 	CAgentInfo& agentInfo = iResolver->ResolveFileL(aHeaderData);
   760 
   761 	// find out the array of attributes
   762 	User::LeaveIfError(agentInfo.AgentManagerL().GetStringAttributeSet(aHeaderData, aStringAttributeSet));
   763 	}
   764 	
   765 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT