os/security/contentmgmt/contentaccessfwfordrm/source/caf/resolver.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/contentmgmt/contentaccessfwfordrm/source/caf/resolver.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,667 @@
     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 <e32debug.h>
    1.23 +#include <ecom/ecom.h>
    1.24 +
    1.25 +#include "resolver.h"
    1.26 +#include <caf/agentfactory.h>
    1.27 +#include <caf/agentinterface.h>
    1.28 +#include "agentinfo.h"
    1.29 +#include <caf/agent.h>
    1.30 +#include <caf/cafpanic.h>
    1.31 +#include <caf/caferr.h>
    1.32 +#include <caf/patchdata.h>
    1.33 +
    1.34 +
    1.35 +using namespace ContentAccess;
    1.36 +
    1.37 +// Constants for the F32 agent
    1.38 +_LIT(KF32Agent,"F32 CA Agent");
    1.39 +
    1.40 +
    1.41 +_LIT(KParentDir, "..\\");
    1.42 +_LIT(KPrivateDir, "\\private\\");
    1.43 +const TInt KPrivateDirLength = 9;   // "\\private\\"
    1.44 +const TInt KPrivateDirAndDriveLength = 11;   // "x:\\private\\"
    1.45 +const TInt KPrivateDirOffset = 2; // "x:\\"
    1.46 +
    1.47 +
    1.48 +EXPORT_C CAgentResolver* CAgentResolver::NewLC(const TBool aDynamicAgentUpdate)
    1.49 +	{
    1.50 +	CAgentResolver* self = new (ELeave) CAgentResolver(aDynamicAgentUpdate);
    1.51 +	CleanupStack::PushL(self);
    1.52 +	self->ConstructL();
    1.53 +	return self;
    1.54 +	}
    1.55 +
    1.56 +EXPORT_C CAgentResolver* CAgentResolver::NewL(const TBool aDynamicAgentUpdate)
    1.57 +	{
    1.58 +	CAgentResolver* self = CAgentResolver::NewLC(aDynamicAgentUpdate);
    1.59 +	CleanupStack::Pop(self);
    1.60 +	return self;
    1.61 +	}
    1.62 +
    1.63 +CAgentResolver::CAgentResolver(const TBool aDynamicAgentUpdate) : CActive(EPriorityStandard), iDynamicAgentUpdate(aDynamicAgentUpdate)
    1.64 +	{
    1.65 +	}
    1.66 +
    1.67 +CAgentResolver::~CAgentResolver()
    1.68 +	{
    1.69 +	// remove ourselves from the ActiveScheduler
    1.70 +	if(IsAdded())
    1.71 +		{
    1.72 +		Deque();
    1.73 +		}
    1.74 +	
    1.75 +	// Unload all the agents
    1.76 +	DestroyListOfAgents();
    1.77 +	
    1.78 +	// Close our ECOM session
    1.79 +	if(iEcomSession)
    1.80 +		{
    1.81 +		if(iDynamicAgentUpdate)
    1.82 +			{
    1.83 +			iEcomSession->CancelNotifyOnChange(iStatus);
    1.84 +			}
    1.85 +		iEcomSession->Close();
    1.86 +		REComSession::FinalClose();
    1.87 +		}
    1.88 +
    1.89 +	iSupplierMimeTypes.Close();
    1.90 +	iConsumerMimeTypes.Close();
    1.91 +	iAgentInfos.Close();
    1.92 +	}
    1.93 +
    1.94 +void CAgentResolver::ConstructL()
    1.95 +	{
    1.96 +	if(iDynamicAgentUpdate)
    1.97 +		{
    1.98 +		// Add ourselves to the current active scheduler so we can get dynamic 
    1.99 +		// updates when agents are removed or new agents are added
   1.100 +		CActiveScheduler::Add(this);
   1.101 +		}
   1.102 +
   1.103 +	iEcomSession = &REComSession::OpenL();
   1.104 +	
   1.105 +	// find all the agents
   1.106 +	BuildListOfAgentsL();
   1.107 +
   1.108 +	if(iDynamicAgentUpdate)
   1.109 +		{
   1.110 +		// register for ECOM update notifications in case a new agent appears
   1.111 +		SetActive();
   1.112 +		iEcomSession->NotifyOnChange(iStatus);
   1.113 +		}
   1.114 +	}
   1.115 +
   1.116 +void CAgentResolver::BuildListOfAgentsL()
   1.117 +	{
   1.118 +	TInt err = KErrNone;
   1.119 +
   1.120 +	// Get all plugins which implement the agent interface
   1.121 +	RImplInfoPtrArray implArray;
   1.122 +	CleanupStack::PushL(TCleanupItem(CleanImplArray, &implArray));
   1.123 +	REComSession::ListImplementationsL(KCAAgentInterfaceUid, implArray);
   1.124 +
   1.125 +	for (TInt i = 0; i < implArray.Count(); ++i)
   1.126 +		{
   1.127 +#ifdef __EPOC32__
   1.128 +		// On hardware - to load agents from sources other than ROM the patch 
   1.129 +		// data KCafLoadPostProductionAgents must be set to True (non-zero).
   1.130 +		// Default SymbianOS behavior is to only load agents from ROM
   1.131 +		if ((KCafLoadPostProductionAgents == 0) &&
   1.132 +            !implArray[i]->RomBased())
   1.133 +			{
   1.134 +			// If the agent is not in ROM, don't load it because it might
   1.135 +			// be a security risk.
   1.136 +			continue;
   1.137 +			}
   1.138 +#endif
   1.139 +
   1.140 +		// Construct all the agent infos from these implementations
   1.141 +		TRAP(err, AddAgentL(*implArray[i]));
   1.142 +
   1.143 +		// If we ran out of memory proagate the leave to the caller
   1.144 +		// otherwise don't let a dodgy agent affect the construction of the other
   1.145 +		// agents
   1.146 +		if(err == KErrNoMemory)
   1.147 +			{
   1.148 +			User::Leave(KErrNoMemory);
   1.149 +			}
   1.150 +		}
   1.151 +	CleanupStack::PopAndDestroy(&implArray);  
   1.152 +
   1.153 +
   1.154 +	if (!iDefaultAgent)
   1.155 +		{
   1.156 +		// If we didn't find a default agent, we have a big problem so panic
   1.157 +		User::Panic(KCafPanicString, ECafPanicNoF32Agent);
   1.158 +		}
   1.159 +	}
   1.160 +
   1.161 +void CAgentResolver::AddAgentL(const CImplementationInformation& aImplInfo)
   1.162 +	{
   1.163 +	// Create a CAgentInfo instance
   1.164 +	CAgentInfo* agentInfo = CAgentInfo::NewLC(aImplInfo);
   1.165 +
   1.166 +
   1.167 +	if(IsF32Agent(*agentInfo))
   1.168 +		{
   1.169 +		// It's the F32 Agent
   1.170 +		if(iDefaultAgent)
   1.171 +			{
   1.172 +			// If we already have a default agent something is seriously wrong
   1.173 +			User::Panic(KCafPanicString, ECafPanicDuplicateF32Agent);
   1.174 +			}
   1.175 +
   1.176 +		// Note that the default agent is NOT stored in the agents list, it is a special case
   1.177 +		iDefaultAgent = agentInfo;
   1.178 +		CleanupStack::Pop(agentInfo);
   1.179 +		}
   1.180 +	else
   1.181 +		{
   1.182 +		// All other agents go in the agent list
   1.183 +		User::LeaveIfError(iAgentInfos.Append(agentInfo));
   1.184 +		CleanupStack::Pop(agentInfo);
   1.185 +
   1.186 +		TInt mimeIndex=0;
   1.187 +
   1.188 +		// Update our list of all supplier mime types supported by CAF
   1.189 +		for(mimeIndex=0;mimeIndex < agentInfo->SupplierMimeTypes().Count(); mimeIndex++) 
   1.190 +			{
   1.191 +			User::LeaveIfError(iSupplierMimeTypes.Append(*agentInfo->SupplierMimeTypes()[mimeIndex]));
   1.192 +			}
   1.193 +
   1.194 +		// Update our list of all consumer mime types supported by CAF
   1.195 +		for(mimeIndex=0;mimeIndex < agentInfo->ConsumerMimeTypes().Count(); mimeIndex++) 
   1.196 +			{
   1.197 +			User::LeaveIfError(iConsumerMimeTypes.Append(*agentInfo->ConsumerMimeTypes()[mimeIndex]));
   1.198 +			}
   1.199 +		}
   1.200 +	}
   1.201 +
   1.202 +void CAgentResolver::DestroyListOfAgents()
   1.203 +	{
   1.204 +	iSupplierMimeTypes.Reset();
   1.205 +	iConsumerMimeTypes.Reset();
   1.206 +
   1.207 +	// cant forget to delete the default agent
   1.208 +	delete iDefaultAgent;
   1.209 +	iDefaultAgent = NULL;
   1.210 +
   1.211 +	// Free memory assocated with the iAgentInfos array 
   1.212 +	iAgentInfos.ResetAndDestroy();
   1.213 +	}
   1.214 +
   1.215 +void CAgentResolver::DoCancel()
   1.216 +	{
   1.217 +	// Abort any update notification 
   1.218 +	iEcomSession->CancelNotifyOnChange(iStatus);
   1.219 +	}
   1.220 +
   1.221 +void CAgentResolver::RunL()
   1.222 +	{
   1.223 +	// Called by the ECOM framework if a new agent appears
   1.224 +
   1.225 +	// remove the existing list of agents and build a new one
   1.226 +	DestroyListOfAgents();
   1.227 +	BuildListOfAgentsL();
   1.228 +
   1.229 +	// request notification of any further changes
   1.230 +	iEcomSession->NotifyOnChange(iStatus);
   1.231 +	SetActive();
   1.232 +	}	
   1.233 +
   1.234 +TBool CAgentResolver::IsF32Agent(CAgentInfo& aAgentInfo)
   1.235 +	{
   1.236 +	// Check if the agent has no consumer or supplier mime types
   1.237 +	// and that it has the correct name and Uid
   1.238 +	if (aAgentInfo.Agent().ImplementationUid() == KF32AgentImplUid
   1.239 +		&& aAgentInfo.Agent().Name().Compare(KF32Agent()) == 0 
   1.240 +		&& aAgentInfo.ConsumerMimeTypes().Count() == 0 
   1.241 +		&& aAgentInfo.SupplierMimeTypes().Count() == 0)
   1.242 +		{
   1.243 +		return ETrue;
   1.244 +		}
   1.245 +	else
   1.246 +		{
   1.247 +		return EFalse;
   1.248 +		}
   1.249 +	}
   1.250 +
   1.251 +CAgentInfo& CAgentResolver::ResolveSupplierMimeL(const TDesC8& aMimeType) const
   1.252 +	{
   1.253 +	// Go through all the agents and return the one which supports the
   1.254 +	// required supplier mime type
   1.255 +	CAgentInfo* retVal=NULL;
   1.256 +
   1.257 +	for (TInt i = 0; i < iAgentInfos.Count(); ++i)
   1.258 +		{
   1.259 +		if (iAgentInfos[i]->IsSupportedSupplier(aMimeType))
   1.260 +			{
   1.261 +			retVal = iAgentInfos[i];
   1.262 +			break;
   1.263 +			}
   1.264 +		}
   1.265 +	
   1.266 +	if (!retVal)
   1.267 +		{
   1.268 +		User::Leave(KErrCANoAgent);
   1.269 +		}
   1.270 +	return *retVal;
   1.271 +	}
   1.272 +
   1.273 +CAgentInfo& CAgentResolver::ResolveConsumerMime(const TDesC8& aMimeType) const
   1.274 +	{
   1.275 +	// By default, set the return value to be the default agent. If we find
   1.276 +	// anything better, then we change it
   1.277 +	CAgentInfo* retVal = iDefaultAgent;
   1.278 +
   1.279 +	for (TInt i = 0; i < iAgentInfos.Count(); ++i)
   1.280 +		{
   1.281 +		if (iAgentInfos[i]->IsSupportedConsumer(aMimeType))
   1.282 +			{
   1.283 +			retVal = iAgentInfos[i];
   1.284 +			break;
   1.285 +			}
   1.286 +		}
   1.287 +
   1.288 +	ASSERT(retVal);
   1.289 +	return *retVal;
   1.290 +	}
   1.291 +
   1.292 +CAgentInfo& CAgentResolver::ResolveFileL(const TDesC& aURI, TDes& aActualUri, TContentShareMode aShareMode) const
   1.293 +	{
   1.294 +	// Go through all the agents and return the one which supports the file at the given URI	
   1.295 +	TBool thePrivateDir = EFalse;	
   1.296 +	TUid agentUid = ResolveDirectory(aURI, aActualUri, thePrivateDir);
   1.297 +	
   1.298 +	if(agentUid != iDefaultAgent->Agent().ImplementationUid())
   1.299 +		{
   1.300 +		// this file must be living in a private server directory
   1.301 +		// return the agent who owns the directory
   1.302 +		return AgentInfoL(agentUid);
   1.303 +		}
   1.304 +	else
   1.305 +		{
   1.306 +		TInt agentsCount(iAgentInfos.Count());
   1.307 +		CAgentManager* agentManager = NULL;
   1.308 +		for (TInt i = 0; i < agentsCount; ++i)
   1.309 +			{
   1.310 +			TRAPD(result, agentManager = &iAgentInfos[i]->AgentManagerL());
   1.311 +			if(result != KErrNone)
   1.312 +				{
   1.313 +				if(KErrNoMemory == result)
   1.314 +					{
   1.315 +					User::Leave(result);
   1.316 +					}
   1.317 +				else
   1.318 +					{
   1.319 +					continue;	
   1.320 +					}
   1.321 +				}
   1.322 +			if (agentManager->IsRecognizedL(aURI, aShareMode))
   1.323 +				{
   1.324 +				return *iAgentInfos[i];
   1.325 +				}
   1.326 +			}
   1.327 +		}
   1.328 +	return *iDefaultAgent;
   1.329 +	}
   1.330 +
   1.331 +CAgentInfo& CAgentResolver::ResolveFileL(RFile& aFile) const
   1.332 +	{
   1.333 +	// Go through all the agents and return the one which supports the file
   1.334 +
   1.335 +	TInt agentsCount(iAgentInfos.Count());
   1.336 +	CAgentManager* agentManager = NULL;
   1.337 +	for (TInt i = 0; i < agentsCount; ++i)
   1.338 +		{
   1.339 +		TRAPD(result, agentManager = &iAgentInfos[i]->AgentManagerL());
   1.340 +		if(result != KErrNone)
   1.341 +			{
   1.342 +			if(KErrNoMemory == result)
   1.343 +				{
   1.344 +				User::Leave(result);
   1.345 +				}
   1.346 +			else
   1.347 +				{
   1.348 +				continue;	
   1.349 +				}
   1.350 +			}
   1.351 +		if (agentManager->IsRecognizedL(aFile))
   1.352 +			{
   1.353 +			return *iAgentInfos[i];
   1.354 +			}
   1.355 +		}
   1.356 +	return *iDefaultAgent;
   1.357 +	}
   1.358 +
   1.359 +#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   1.360 +
   1.361 +CAgentInfo& CAgentResolver::ResolveFileL(const TDesC8& aHeaderData)
   1.362 +	{
   1.363 +	// Go through all the agents and return the one which supports the given WMDRM content.
   1.364 +	
   1.365 +	TInt agentsCount(iAgentInfos.Count());
   1.366 +	CAgentManager* agentManager = NULL;
   1.367 +	
   1.368 +	for (TInt i = 0; i < agentsCount; ++i)
   1.369 +		{
   1.370 +		TRAPD(result, agentManager = &iAgentInfos[i]->AgentManagerL());
   1.371 +		if(result != KErrNone)
   1.372 +			{
   1.373 +			if(KErrNoMemory == result)
   1.374 +				{
   1.375 +				User::Leave(result);
   1.376 +				}
   1.377 +			else
   1.378 +				{
   1.379 +				continue;	
   1.380 +				}
   1.381 +			}
   1.382 +			
   1.383 +		if (agentManager->IsRecognizedL(aHeaderData))
   1.384 +			{
   1.385 +			return *iAgentInfos[i];
   1.386 +			}
   1.387 +		}
   1.388 +		
   1.389 +    // will never reach here	
   1.390 +	return *iDefaultAgent;
   1.391 +	}
   1.392 +	
   1.393 +	
   1.394 +EXPORT_C TBool CAgentResolver::DoRecognizeL(const TDesC8& aHeader, TDes8& aFileMimeType, TDes8& aContentMimeType)
   1.395 +	{
   1.396 +	// Go through all the agents and return the one which supports the given WMDRM content.
   1.397 +	TInt agentsCount(iAgentInfos.Count());
   1.398 +	CAgentManager* agentManager = NULL;
   1.399 +	for (TInt i = 0; i < agentsCount; ++i)
   1.400 +		{
   1.401 +		TRAPD(result, agentManager = &iAgentInfos[i]->AgentManagerL());
   1.402 +		if(result != KErrNone)
   1.403 +			{
   1.404 +			if(KErrNoMemory == result)
   1.405 +				{
   1.406 +				User::Leave(result);
   1.407 +				}
   1.408 +			else
   1.409 +				{
   1.410 +				continue;	
   1.411 +				}
   1.412 +			}
   1.413 +			
   1.414 +		if (agentManager->RecognizeContentL(aHeader, aFileMimeType, aContentMimeType))
   1.415 +			{
   1.416 +			// force to lower case to ensure that chosen lower case scheme for mime types is maintained
   1.417 +			aFileMimeType.LowerCase();
   1.418 +			aContentMimeType.LowerCase();			
   1.419 +			return ETrue;
   1.420 +			}
   1.421 +		}
   1.422 +		
   1.423 +	return EFalse;
   1.424 +	}
   1.425 +	
   1.426 +#endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   1.427 +	
   1.428 +TUid CAgentResolver::ResolveDirectory(const TDesC& aPath, TDes& aActualPath, TBool& aThePrivateDir) const
   1.429 +	{
   1.430 +	TInt i = 0;
   1.431 +	TInt pathLength = 0;
   1.432 +	TBuf <KPrivateDirAndDriveLength> pathLowerCase;
   1.433 +	
   1.434 +	// Assume it's a publicly accessable path
   1.435 +	aThePrivateDir = EFalse;
   1.436 +	
   1.437 +	// Find the length of the path and private directory
   1.438 +	pathLength = aPath.Length();
   1.439 +
   1.440 +	// Check that the path is long enough to be within a private directory
   1.441 +	// and does not include "..\\".The  "..\\" sequence could be a security risk
   1.442 +	if(aPath.Find(KParentDir()) == KErrNotFound && pathLength >= KPrivateDirAndDriveLength)
   1.443 +		{
   1.444 +		// Create a lower case copy of the left hand side of the path
   1.445 +		TPtrC lowerCasePtr = aPath.Mid(KPrivateDirOffset, KPrivateDirLength);
   1.446 +		pathLowerCase.Copy(lowerCasePtr);
   1.447 +		pathLowerCase.LowerCase();
   1.448 +	
   1.449 +		// Compare the first directory in the path to \\private\\ 
   1.450 +		if(KPrivateDir() == pathLowerCase)
   1.451 +			{
   1.452 +			// It is a private directory of some sort
   1.453 +			if(pathLength > KPrivateDirAndDriveLength)
   1.454 +				{
   1.455 +				// It must be a server private directory data cage
   1.456 +				TPtrC serverDirectoryPath = aPath.Right(pathLength - KPrivateDirAndDriveLength);
   1.457 +				for(i = 0; i < AgentInfoCount(); i++)
   1.458 +					{
   1.459 +					// See if the part after \\private\\ matches the agent name
   1.460 +					TPtrC privateDirectoryName = AgentInfo(i).PrivateDirectoryName();
   1.461 +					TPtrC agentName = AgentInfo(i).Agent().Name();
   1.462 +					if(privateDirectoryName.Length() && agentName.Length() && agentName == serverDirectoryPath.Left(agentName.Length()))
   1.463 +						{
   1.464 +						// It must be this agent's private directory
   1.465 +						// Convert \\private\\agentName\\... to \\private\\SID\\...
   1.466 +						aActualPath.Copy(aPath.Left(KPrivateDirAndDriveLength));
   1.467 +						aActualPath.Append(privateDirectoryName);
   1.468 +						aActualPath.Append(aPath.Right(pathLength - KPrivateDirAndDriveLength - agentName.Length()));
   1.469 +						return AgentInfo(i).Agent().ImplementationUid();
   1.470 +						}
   1.471 +					}
   1.472 +				}
   1.473 +			else
   1.474 +				{
   1.475 +				// It's just the c:\\private\\ directory
   1.476 +				// Use the default agent, any calls will just fail
   1.477 +				aThePrivateDir = ETrue;
   1.478 +				}
   1.479 +			}
   1.480 +		}
   1.481 +	
   1.482 +	// Not an agent private directory so just return the default agent
   1.483 +	aActualPath.Copy(aPath);
   1.484 +	return iDefaultAgent->Agent().ImplementationUid();
   1.485 +	}
   1.486 +
   1.487 +HBufC* CAgentResolver::ConvertAgentFileNameL(const TDesC& aFileName) const
   1.488 +	{
   1.489 +	TInt i = 0;
   1.490 +	TInt fileNameLength = 0;
   1.491 +	TBuf <KPrivateDirAndDriveLength> pathLowerCase;
   1.492 +	
   1.493 +	fileNameLength = aFileName.Length();
   1.494 +	
   1.495 +	// If the path is shorter than the x:\\private\\ it must be a F32 file
   1.496 +	if(fileNameLength  > KPrivateDirAndDriveLength)
   1.497 +		{
   1.498 +		// Create a lower case copy of the left hand side of the path
   1.499 +		TPtrC lowerCasePtr = aFileName.Mid(KPrivateDirOffset, KPrivateDirLength);
   1.500 +		pathLowerCase.Copy(lowerCasePtr);
   1.501 +		pathLowerCase.LowerCase();
   1.502 +	
   1.503 +		// Compare the first directory in the path to \\private\\ 
   1.504 +		if(KPrivateDir() == pathLowerCase)
   1.505 +			{
   1.506 +			// It is a private directory of some sort
   1.507 +			if(fileNameLength > KPrivateDirAndDriveLength)
   1.508 +				{
   1.509 +				// It must be a server private directory data cage
   1.510 +				TPtrC serverDirectoryPath = aFileName.Right(fileNameLength - KPrivateDirAndDriveLength);
   1.511 +				for(i = 0; i < AgentInfoCount(); i++)
   1.512 +					{
   1.513 +					// See if the part after \\private\\ matches the agent name
   1.514 +					TPtrC privateDirectoryName = AgentInfo(i).PrivateDirectoryName();
   1.515 +					TPtrC agentName = AgentInfo(i).Agent().Name();
   1.516 +					if(privateDirectoryName.Length() && agentName.Length() && privateDirectoryName == serverDirectoryPath.Left(privateDirectoryName.Length()))
   1.517 +						{
   1.518 +						// It is this agent's private directory
   1.519 +						// Convert \\private\\SID\\... \\private\\agentName\\... 
   1.520 +						HBufC* buffer = HBufC::NewL(fileNameLength - privateDirectoryName.Length() + agentName.Length());
   1.521 +						TPtr ptr = buffer->Des();
   1.522 +						ptr.Copy(aFileName.Left(KPrivateDirAndDriveLength));
   1.523 +						ptr.Append(agentName);
   1.524 +						ptr.Append(aFileName.Right(fileNameLength - KPrivateDirAndDriveLength - privateDirectoryName.Length()));
   1.525 +						return buffer;
   1.526 +						}
   1.527 +					}
   1.528 +				}
   1.529 +			}
   1.530 +		}
   1.531 +	return aFileName.AllocL();
   1.532 +	}
   1.533 +
   1.534 +EXPORT_C TBool CAgentResolver::DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer, TDes8& aFileMimeType, TDes8& aContentMimeType)
   1.535 +	{
   1.536 +
   1.537 +	// Given the filename and buffer from apparc, ask the agents in turn if they recognize the file
   1.538 +	// Note this will not call the DefaultAgent (F32) because it won't be able to recognize anything
   1.539 +
   1.540 +	TInt agentsCount(iAgentInfos.Count());
   1.541 +	CAgentManager* agentManager = NULL;
   1.542 +	for (TInt i = 0; i < agentsCount; ++i)
   1.543 +		{
   1.544 +		TRAPD(result, agentManager = &iAgentInfos[i]->AgentManagerL());
   1.545 +		if(result != KErrNone)
   1.546 +			{
   1.547 +			if(KErrNoMemory == result)
   1.548 +				{
   1.549 +				User::Leave(result);
   1.550 +				}
   1.551 +			else
   1.552 +				{
   1.553 +				continue;	
   1.554 +				}
   1.555 +			}
   1.556 +		if (agentManager->RecognizeFileL(aName, aBuffer, aFileMimeType, aContentMimeType))
   1.557 +			{
   1.558 +			// force to lower case to ensure that chosen lower case scheme for mime types is maintained
   1.559 +			aFileMimeType.LowerCase();
   1.560 +			aContentMimeType.LowerCase();			
   1.561 +			return ETrue;
   1.562 +			}
   1.563 +		}
   1.564 +	return EFalse;
   1.565 +	}
   1.566 +	
   1.567 +
   1.568 +void CAgentResolver::CleanImplArray(TAny* aArray)
   1.569 +	{
   1.570 +	static_cast<RImplInfoPtrArray*>(aArray)->ResetAndDestroy();
   1.571 +	}
   1.572 +
   1.573 +EXPORT_C TInt CAgentResolver::PreferredBufferSize()
   1.574 +	{
   1.575 +	TInt size=0;
   1.576 +
   1.577 +	if(iDefaultAgent != NULL)
   1.578 +		{
   1.579 +		size = iDefaultAgent->PreferredBufferSize();
   1.580 +		}
   1.581 +
   1.582 +	// Find out the maximum buffer requested by any agent
   1.583 +	for (TInt i = 0; i < iAgentInfos.Count(); ++i)
   1.584 +			{
   1.585 +			if(iAgentInfos[i]->PreferredBufferSize() > size)
   1.586 +				{
   1.587 +				size = iAgentInfos[i]->PreferredBufferSize();
   1.588 +				}
   1.589 +			}
   1.590 +	return size;
   1.591 +	}
   1.592 +
   1.593 +
   1.594 +EXPORT_C const RArray<TPtrC8>& CAgentResolver::ConsumerMimeTypes() const
   1.595 +	{
   1.596 +	return iConsumerMimeTypes;
   1.597 +	}
   1.598 +
   1.599 +
   1.600 +EXPORT_C const RArray<TPtrC8>& CAgentResolver::SupplierMimeTypes() const
   1.601 +	{
   1.602 +	return iSupplierMimeTypes;
   1.603 +	}
   1.604 +
   1.605 +
   1.606 +CAgentInfo& CAgentResolver::AgentInfoL(const TDesC& aAgentName) const
   1.607 +	{
   1.608 +	TBool found = EFalse;
   1.609 +	TInt i = 0;
   1.610 +	for(i = 0; i < iAgentInfos.Count(); i++)
   1.611 +		{
   1.612 +		if(iAgentInfos[i]->Agent().Name() == aAgentName)
   1.613 +			{
   1.614 +			found = ETrue;
   1.615 +			break;
   1.616 +			}
   1.617 +		}
   1.618 +	
   1.619 +	if(!found)
   1.620 +		{
   1.621 +		// Can't find the agent so leave
   1.622 +		User::Leave(KErrNotFound);
   1.623 +		}
   1.624 +	
   1.625 +	return *iAgentInfos[i];
   1.626 +	}
   1.627 +
   1.628 +CAgentInfo& CAgentResolver::AgentInfoL(const TUid& aUid) const
   1.629 +	{
   1.630 +	TInt i = 0;
   1.631 +	TBool found = EFalse;
   1.632 +	
   1.633 +	// See if it's the F32 agent
   1.634 +	if(aUid == DefaultAgentUid())
   1.635 +		{
   1.636 +		return *iDefaultAgent;
   1.637 +		}
   1.638 +	
   1.639 +	for(i = 0; i < iAgentInfos.Count(); i++)
   1.640 +		{
   1.641 +		if(iAgentInfos[i]->Agent().ImplementationUid() == aUid)
   1.642 +			{
   1.643 +			found = ETrue;
   1.644 +			break;			
   1.645 +			}
   1.646 +		}
   1.647 +	
   1.648 +	if(!found)
   1.649 +		{
   1.650 +		// couldn't find the agent so leave
   1.651 +		User::Leave(KErrNotFound);
   1.652 +		}
   1.653 +	
   1.654 +	return *iAgentInfos[i];
   1.655 +	}
   1.656 +
   1.657 +CAgentInfo& CAgentResolver::AgentInfo(TInt aIndex) const
   1.658 +		{
   1.659 +		return *iAgentInfos[aIndex];		
   1.660 +		}
   1.661 +
   1.662 +TInt CAgentResolver::AgentInfoCount() const
   1.663 +	{
   1.664 +	return iAgentInfos.Count();	
   1.665 +	}
   1.666 +
   1.667 +TUid CAgentResolver::DefaultAgentUid() const
   1.668 +	{
   1.669 +	return iDefaultAgent->Agent().ImplementationUid();
   1.670 +	}