os/security/contentmgmt/contentaccessfwfordrm/source/caf/agentinfo.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/agentinfo.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,250 @@
     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 <ecom/ecom.h>
    1.23 +#include "agentinfo.h"
    1.24 +#include <caf/agent.h>
    1.25 +#include <caf/agentfactory.h>
    1.26 +#include <caf/agentinterface.h>
    1.27 +
    1.28 +using namespace ContentAccess;
    1.29 +
    1.30 +// Default buffer size of zero
    1.31 +const TInt KCafApparcBufferSize = 0;
    1.32 +
    1.33 +CAgentInfo* CAgentInfo::NewLC(const CImplementationInformation& aImplInfo)
    1.34 +	{
    1.35 +	CAgentInfo* self = new (ELeave) CAgentInfo;
    1.36 +	CleanupStack::PushL(self);
    1.37 +	self->ConstructL(aImplInfo);
    1.38 +	return self;
    1.39 +	}
    1.40 +
    1.41 +CAgentInfo::CAgentInfo()
    1.42 +	{
    1.43 +	}
    1.44 +
    1.45 +CAgentInfo::~CAgentInfo()
    1.46 +	{
    1.47 +	iSupplierMimeTypes.ResetAndDestroy();
    1.48 +	iSupplierMimeTypes.Close();
    1.49 +	iConsumerMimeTypes.ResetAndDestroy();
    1.50 +	iConsumerMimeTypes.Close();
    1.51 +	
    1.52 +	// Delete the agent manager and agent factory, this may unload the agent DLL
    1.53 +	delete iAgentManager;
    1.54 +	delete iAgentFactory;
    1.55 +	}
    1.56 +
    1.57 +
    1.58 +void CAgentInfo::ConstructL(const CImplementationInformation& aImplInfo)
    1.59 +	{
    1.60 +	// Set up the agent member with the name and Uid of the agent
    1.61 +	iAgent.SetValue(aImplInfo.DisplayName(), aImplInfo.ImplementationUid());
    1.62 +
    1.63 +	// get the name of the agents private directory
    1.64 +	TInt length = aImplInfo.OpaqueData().Length();
    1.65 +	if(length > KMaxSIDLength)
    1.66 +		{
    1.67 +		User::Leave(KErrCorrupt);
    1.68 +		}
    1.69 +	else
    1.70 +		{
    1.71 +		iPrivateDirectoryName.Copy(aImplInfo.OpaqueData().Left(KMaxSIDLength));
    1.72 +		}
    1.73 +			
    1.74 +	// Extract from the data field from the info.
    1.75 +	// The data field should be of the form:
    1.76 +	// "<bufferlength>|<supplier1>,<supplier2>,....,<suppliern>:<consumer1>,<consumer2>"
    1.77 +	// bufferlength is the desired length of the buffer passed from apparc to DoRecognize
    1.78 +	TPtrC8 data(aImplInfo.DataType());
    1.79 +	TPtrC8 supplier(KNullDesC8());
    1.80 +	TPtrC8 consumer(KNullDesC8());
    1.81 +
    1.82 +	// Search for the "|" field to delimit buffersize and supplier mime types
    1.83 +	TInt index = data.LocateF('|');
    1.84 +	if(index < 0)
    1.85 +		{
    1.86 +		// No default buffersize, ie. corrupt
    1.87 +		User::Leave(KErrCorrupt);
    1.88 +		}
    1.89 +	else
    1.90 +		{
    1.91 +		TPtrC8 buffersize(data.Left(index));
    1.92 +		TLex8 bufferLex(buffersize);
    1.93 +		bufferLex.Val(iPreferredBufferSize);
    1.94 +
    1.95 +		// Make sure a buffer size was actually specified before the | character
    1.96 +		if(iPreferredBufferSize == 0)
    1.97 +			{
    1.98 +			iPreferredBufferSize = KCafApparcBufferSize;
    1.99 +			}
   1.100 +
   1.101 +		// Make sure '|' is not the last character
   1.102 +		if (index + 1 < data.Length())
   1.103 +			{
   1.104 +			data.Set(aImplInfo.DataType().Mid(index + 1));
   1.105 +			}
   1.106 +		else 
   1.107 +			{
   1.108 +			User::Leave(KErrCorrupt);
   1.109 +			}
   1.110 +		}
   1.111 +
   1.112 +	
   1.113 +	// Search for the ":" field to delimit supplier and consumer
   1.114 +	index = data.LocateF(':');
   1.115 +	
   1.116 +	// If the colon was present, then set the pointers appropriately
   1.117 +	if (index >= 0)
   1.118 +		{
   1.119 +		// Set supplier pointer
   1.120 +		supplier.Set(data.Left(index));
   1.121 +
   1.122 +		// Check that ':' is not the last character before setting consumer pointer
   1.123 +		if (index + 1 < data.Length())
   1.124 +			{
   1.125 +			consumer.Set(data.Mid(index + 1));
   1.126 +			}
   1.127 +		}
   1.128 +	else
   1.129 +		{
   1.130 +		User::Leave(KErrCorrupt);
   1.131 +		}
   1.132 +
   1.133 +	// Now parse the supplier mime types
   1.134 +	ParseMimeTypesL(supplier, iSupplierMimeTypes);
   1.135 +	
   1.136 +	// Do the same for the consumer mime types
   1.137 +	ParseMimeTypesL(consumer, iConsumerMimeTypes);
   1.138 +	}
   1.139 +
   1.140 +CAgentFactory& CAgentInfo::AgentFactoryL()
   1.141 +	{
   1.142 +	// Create the agent factory if it hasn't been done already
   1.143 +	if (!iAgentFactory)
   1.144 +		{
   1.145 +		iAgentFactory = CAgentFactory::NewL(iAgent.ImplementationUid());
   1.146 +		}
   1.147 +	return *iAgentFactory;
   1.148 +	}
   1.149 +
   1.150 +CAgentManager& CAgentInfo::AgentManagerL()
   1.151 +	{
   1.152 +	// Create the agent manager
   1.153 +	if (!iAgentManager)
   1.154 +		{
   1.155 +		iAgentManager = AgentFactoryL().CreateManagerL();
   1.156 +		}
   1.157 +	return *iAgentManager;
   1.158 +	}	
   1.159 +
   1.160 +TBool CAgentInfo::IsSupportedSupplier(const TDesC8& aSupplierMime) const
   1.161 +	{
   1.162 +	for (TInt i = 0; i < iSupplierMimeTypes.Count(); ++i)
   1.163 +		{
   1.164 +		if (aSupplierMime == *iSupplierMimeTypes[i])
   1.165 +			{
   1.166 +			return ETrue;
   1.167 +			}
   1.168 +		}
   1.169 +	return EFalse;
   1.170 +	}
   1.171 +
   1.172 +TBool CAgentInfo::IsSupportedConsumer(const TDesC8& aConsumerMime) const
   1.173 +	{
   1.174 +
   1.175 +	for (TInt i = 0; i < iConsumerMimeTypes.Count(); ++i)
   1.176 +		{
   1.177 +		if (aConsumerMime == *iConsumerMimeTypes[i])
   1.178 +			{
   1.179 +			return ETrue;
   1.180 +			}
   1.181 +		}
   1.182 +	return EFalse;
   1.183 +	}
   1.184 +		
   1.185 +const RPointerArray<HBufC8>& CAgentInfo::SupplierMimeTypes() const
   1.186 +	{
   1.187 +	return iSupplierMimeTypes;
   1.188 +	}
   1.189 +
   1.190 +const RPointerArray<HBufC8>& CAgentInfo::ConsumerMimeTypes() const
   1.191 +	{
   1.192 +	return iConsumerMimeTypes;
   1.193 +	}
   1.194 +
   1.195 +void CAgentInfo::AddToArrayL(const TDesC8& aElement, 
   1.196 +							 RPointerArray<HBufC8>& aArray)
   1.197 +	{
   1.198 +	// Don't bother adding empty elements
   1.199 +	if (aElement.Length())
   1.200 +		{
   1.201 +		HBufC8* newElem = aElement.AllocLC();
   1.202 +		TPtr8 lowerCasePtr = newElem->Des();
   1.203 +		lowerCasePtr.LowerCase();
   1.204 +		User::LeaveIfError(aArray.Append(newElem));
   1.205 +		CleanupStack::Pop(newElem);
   1.206 +		}
   1.207 +	}
   1.208 +
   1.209 +void CAgentInfo::ParseMimeTypesL(const TDesC8& aBuf, 
   1.210 +								 RPointerArray<HBufC8>& aMimeTypes)
   1.211 +	{
   1.212 +	TPtrC8 ptr(aBuf);
   1.213 +	TInt pos = 0;
   1.214 +	while ((pos = ptr.LocateF(',')) >= 0)
   1.215 +		{
   1.216 +		// Take into account possibility of ,,
   1.217 +		if (pos > 0)
   1.218 +			{
   1.219 +			AddToArrayL(ptr.Left(pos), aMimeTypes);
   1.220 +			}
   1.221 +
   1.222 +		// Now, move the pointer to the position after the ','. BUT if the
   1.223 +		// ',' is the last position, then we are done, so return (a bit
   1.224 +		// dirty, but makes things easier
   1.225 +		if (pos + 1 < ptr.Length())
   1.226 +			{
   1.227 +			ptr.Set(ptr.Mid(pos + 1));
   1.228 +			}
   1.229 +		else
   1.230 +			{
   1.231 +			// The ',' is the last character, so quit
   1.232 +			return;
   1.233 +			}
   1.234 +		}
   1.235 +
   1.236 +	// Now extract the last mime type.
   1.237 +	AddToArrayL(ptr, aMimeTypes);
   1.238 +	}
   1.239 +
   1.240 +TInt CAgentInfo::PreferredBufferSize() const
   1.241 +	{
   1.242 +	return iPreferredBufferSize;
   1.243 +	}
   1.244 +
   1.245 +const TDesC& CAgentInfo::PrivateDirectoryName() const
   1.246 +	{
   1.247 +	return iPrivateDirectoryName;
   1.248 +	}
   1.249 +	
   1.250 +TAgent& CAgentInfo::Agent()
   1.251 +	{
   1.252 +	return iAgent;
   1.253 +	}