cryptoservices/certificateandkeymgmt/tadditionalstores/tadditionalstoreentries.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2005-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 
       
    20 
       
    21 /**
       
    22  @file
       
    23 */
       
    24 
       
    25 #include "tadditionalstoremapping.h"
       
    26 
       
    27 ////////////////////////////////////////////////////////////////////////////////
       
    28 //CFileCertStoreMapping
       
    29 /////////////////////////////////////////////////////////////////////////////////
       
    30 
       
    31 CFileCertStoreMapping* CFileCertStoreMapping::NewL()
       
    32 	{
       
    33 	CFileCertStoreMapping* self = CFileCertStoreMapping::NewLC();
       
    34 	CleanupStack::Pop(self);
       
    35 	return self;
       
    36 	}
       
    37 
       
    38 CFileCertStoreMapping* CFileCertStoreMapping::NewLC()
       
    39 	{
       
    40 	CFileCertStoreMapping* self = new(ELeave) CFileCertStoreMapping();
       
    41 	CleanupStack::PushL(self);
       
    42 	self->ConstructL();
       
    43 	return self;
       
    44 	}
       
    45 
       
    46 void CFileCertStoreMapping::ConstructL()
       
    47 	{
       
    48 	iCertificateApps = new(ELeave) RArray<TUid>();
       
    49 	}
       
    50 
       
    51 CFileCertStoreMapping::CFileCertStoreMapping()
       
    52 	{	
       
    53 	}
       
    54 
       
    55 CFileCertStoreMapping::~CFileCertStoreMapping()
       
    56 	{
       
    57 	if (iEntry)
       
    58 		{
       
    59 		iEntry->Release();
       
    60 		}
       
    61 	if (iCertificateApps)
       
    62 		{
       
    63 		iCertificateApps->Close();
       
    64 		delete iCertificateApps;
       
    65 		}
       
    66 	}
       
    67 
       
    68 void CFileCertStoreMapping::SetEntry(CCTCertInfo* aCertInfo)
       
    69 	{
       
    70 	if (iEntry)
       
    71 		{
       
    72 		iEntry->Release();
       
    73 		}
       
    74 	iEntry = aCertInfo;
       
    75 	}
       
    76 
       
    77 void CFileCertStoreMapping::SetCertificateApps(RArray<TUid>* aCertificateApps)
       
    78 	{
       
    79 	iCertificateApps->Close();
       
    80 	delete iCertificateApps;
       
    81 	iCertificateApps = aCertificateApps;
       
    82 	}
       
    83 
       
    84 void CFileCertStoreMapping::SetId(TStreamId aId)
       
    85 	{
       
    86 	iId = aId;
       
    87 	}
       
    88 
       
    89 CCTCertInfo* CFileCertStoreMapping::Entry() const
       
    90 	{
       
    91 	return iEntry;
       
    92 	}
       
    93 
       
    94 const RArray<TUid>& CFileCertStoreMapping::CertificateApps() const
       
    95 	{
       
    96 	return *iCertificateApps;
       
    97 	}
       
    98 
       
    99 TBool CFileCertStoreMapping::IsApplicable(const TUid& aApplication) const
       
   100 	{
       
   101 	TInt count = iCertificateApps->Count();
       
   102 	for (TInt i = 0; i < count; i++)
       
   103 		{
       
   104 		TUid app = (*iCertificateApps)[i];
       
   105 		if (app == aApplication)
       
   106 				{
       
   107 				return ETrue;
       
   108 				}
       
   109 		}
       
   110 	return EFalse;
       
   111 	}
       
   112 
       
   113 TBool CFileCertStoreMapping::Trusted() const
       
   114 	{
       
   115 	return iTrusted;
       
   116 	}
       
   117 
       
   118 void CFileCertStoreMapping::SetTrusted(TBool aTrusted)
       
   119 	{
       
   120 	iTrusted = aTrusted;
       
   121 	}
       
   122 
       
   123 TStreamId CFileCertStoreMapping::Id() const
       
   124 	{
       
   125 	return iId;
       
   126 	}
       
   127 
       
   128 void CFileCertStoreMapping::ExternalizeL(RWriteStream& aStream) const
       
   129 	{
       
   130 	if (!iTempRemoved)
       
   131 		{
       
   132 		aStream << *iEntry;
       
   133 		TInt count = iCertificateApps->Count();
       
   134 		aStream.WriteInt32L(count);
       
   135 		for (TInt i = 0; i < count; i++)
       
   136 			{
       
   137 			aStream << (*iCertificateApps)[i];
       
   138 			}
       
   139 		aStream.WriteUint8L(iTrusted);
       
   140 		aStream << iId;			
       
   141 		}
       
   142 	}
       
   143 
       
   144 void CFileCertStoreMapping::SetTempRemoved(TBool aFlag)
       
   145 	{
       
   146 	iTempRemoved=aFlag;
       
   147 	}
       
   148 
       
   149 TBool CFileCertStoreMapping::IsTempRemoved()
       
   150 	{
       
   151 	return iTempRemoved;
       
   152 	}
       
   153 
       
   154 #include "tadditionalstoremappings.h"
       
   155 
       
   156 /////////////////////////////////////////////////////////////////////////////////
       
   157 //CFileCertStoreMappings
       
   158 /////////////////////////////////////////////////////////////////////////////////
       
   159 CFileCertStoreMappings::~CFileCertStoreMappings()
       
   160 	{
       
   161 	if (iMappings)
       
   162 		{
       
   163 		iMappings->ResetAndDestroy();
       
   164 		delete iMappings;
       
   165 		}
       
   166 	}
       
   167 
       
   168 TInt CFileCertStoreMappings::Count()
       
   169 	{
       
   170 	return iMappings->Count();
       
   171 	}
       
   172 
       
   173 void CFileCertStoreMappings::AddL(CFileCertStoreMapping* aEntry)
       
   174 	{
       
   175 	User::LeaveIfError(iMappings->Append(aEntry));
       
   176 	}
       
   177 
       
   178 TInt CFileCertStoreMappings::Remove(const CCTCertInfo& aCertInfo)
       
   179 	{
       
   180 	TInt index = Index(aCertInfo);
       
   181 	if (index == KErrNotFound)
       
   182 		{
       
   183 		return KErrNotFound;
       
   184 		}
       
   185 	CFileCertStoreMapping* mapping = (*iMappings)[index];
       
   186 	iMappings->Remove(index);
       
   187 	delete mapping;
       
   188 	return KErrNone;
       
   189 	}
       
   190 
       
   191 TInt CFileCertStoreMappings::SetTempRemove(const CCTCertInfo& aCertInfo, TBool aFlag)
       
   192 	{
       
   193 	TInt index = Index(aCertInfo);
       
   194 	if (index == KErrNotFound)
       
   195 		{
       
   196 		return KErrNotFound;
       
   197 		}
       
   198 	(*iMappings)[index]->SetTempRemoved(aFlag);
       
   199 	return KErrNone;		
       
   200 	}
       
   201 
       
   202 
       
   203 void CFileCertStoreMappings::ExternalizeL(RWriteStream& aStream) const
       
   204 	{
       
   205 	TInt count = iMappings->Count();
       
   206 	TInt realCount=count;
       
   207 	TInt i=0;
       
   208 	for (i = 0; i < count; i++)
       
   209 		{
       
   210 		if ((*iMappings)[i]->IsTempRemoved())
       
   211 			{
       
   212 			realCount--;
       
   213 			}
       
   214 		}
       
   215 	aStream.WriteInt32L(realCount);
       
   216 	for (i = 0; i < count; i++)
       
   217 		{
       
   218 		aStream << *(*iMappings)[i];
       
   219 		}
       
   220 	}
       
   221 
       
   222 void CFileCertStoreMappings::ReplaceL()
       
   223 	{
       
   224 	RStoreWriteStream stream;
       
   225 	stream.ReplaceLC(iStore, iStreamId);
       
   226 	ExternalizeL(stream);
       
   227 	stream.CommitL();
       
   228 	CleanupStack::PopAndDestroy();
       
   229 	}
       
   230 
       
   231 TInt CFileCertStoreMappings::Index(const CCTCertInfo& aCertInfo)
       
   232 	{
       
   233 	TInt count = iMappings->Count();
       
   234 	TInt ix = KErrNotFound;
       
   235 	for (TInt i = 0; i < count; i++)
       
   236 		{
       
   237 		CFileCertStoreMapping* mapping = (*iMappings)[i];
       
   238 		if (aCertInfo==*(mapping->Entry()))
       
   239 			{
       
   240 			ix = i;
       
   241 			break;
       
   242 			}
       
   243 		}
       
   244 	return ix;
       
   245 	}
       
   246 
       
   247 CFileCertStoreMapping* CFileCertStoreMappings::Mapping(TInt aIndex)
       
   248 	{
       
   249 	return (*iMappings)[aIndex];
       
   250 	}
       
   251 
       
   252 TStreamId CFileCertStoreMappings::StreamId() const
       
   253 	{
       
   254 	return iStreamId;
       
   255 	}
       
   256 
       
   257 CFileCertStoreMappings::CFileCertStoreMappings(TStreamId aStreamId, 
       
   258 													   CPermanentFileStore& aStore)
       
   259 	:iStreamId(aStreamId), iStore(aStore)
       
   260 	{
       
   261 	}
       
   262 
       
   263 /////////////////////////////////////////////////////////////////////////////////
       
   264 //CFileCertStoreMappings
       
   265 /////////////////////////////////////////////////////////////////////////////////
       
   266 CFileCertStoreMappings* CFileCertStoreMappings::NewL(TStreamId aStreamId, 
       
   267 													 CPermanentFileStore& aStore)
       
   268 	{
       
   269 	CFileCertStoreMappings* self = new(ELeave) CFileCertStoreMappings(aStreamId, aStore);
       
   270 	CleanupStack::PushL(self);
       
   271 	self->ConstructL();
       
   272 	CleanupStack::Pop();
       
   273 	return self;
       
   274 	}
       
   275 
       
   276 const CCTCertInfo& CFileCertStoreMappings::Entry(TInt aIndex)
       
   277 	{
       
   278 	CFileCertStoreMapping* mapping = (*iMappings)[aIndex];
       
   279 	return *mapping->Entry();
       
   280 	}
       
   281 
       
   282 const CCTCertInfo& CFileCertStoreMappings::EntryByHandleL(TInt aHandle) const
       
   283 	{
       
   284 	TInt count = iMappings->Count();
       
   285 	for (TInt i = 0; i < count; i++)
       
   286 		{
       
   287 		CFileCertStoreMapping* mapping = (*iMappings)[i];
       
   288 		if (aHandle==mapping->Entry()->Handle().iObjectId)
       
   289 			{
       
   290 			return *mapping->Entry();
       
   291 			}
       
   292 		}
       
   293 	User::Leave(KErrNotFound);
       
   294 	CCTCertInfo* info = NULL; // This is to shut up a compiler warning
       
   295 	return *info;
       
   296 	}
       
   297 
       
   298 TInt CFileCertStoreMappings::NextHandle() const 
       
   299 	{
       
   300 	TInt count = iMappings->Count();
       
   301 	TInt maxHandle = -1;
       
   302 	for (TInt i = 0; i < count; i++)
       
   303 		{
       
   304 		CFileCertStoreMapping* mapping = (*iMappings)[i];
       
   305 		if (mapping->Entry()->Handle().iObjectId > maxHandle)
       
   306 			{
       
   307 			maxHandle = mapping->Entry()->Handle().iObjectId;
       
   308 			}
       
   309 		}
       
   310 	return ++maxHandle;
       
   311 	}
       
   312 
       
   313 void CFileCertStoreMappings::ConstructL()
       
   314 	{
       
   315 	iMappings = new(ELeave) RPointerArray<CFileCertStoreMapping>;
       
   316 	}