os/security/cryptoservices/certificateandkeymgmt/certstore/certificateapps.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/certstore/certificateapps.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,180 @@
     1.4 +/*
     1.5 +* Copyright (c) 1998-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 "CFSTokenTypeClient.h"
    1.23 +#include <certificateapps.h>
    1.24 +#include <ct/mcttoken.h>
    1.25 +#include <mctcertapps.h>
    1.26 +#include "mctcertappinterface.h"
    1.27 +
    1.28 +
    1.29 +////////////////////////////////////////////////////////////////
    1.30 +//	CCertificateAppInfoManager
    1.31 +////////////////////////////////////////////////////////////////
    1.32 +
    1.33 +EXPORT_C CCertificateAppInfoManager* CCertificateAppInfoManager::NewLC()
    1.34 +	{
    1.35 +	CCertificateAppInfoManager* self = new(ELeave) CCertificateAppInfoManager();
    1.36 +	CleanupStack::PushL(self);
    1.37 +	self->ConstructL();
    1.38 +	return self;
    1.39 +	}
    1.40 +
    1.41 +EXPORT_C CCertificateAppInfoManager* CCertificateAppInfoManager::NewL()
    1.42 +	{
    1.43 +	CCertificateAppInfoManager* self = NewLC();
    1.44 +	CleanupStack::Pop();
    1.45 +	return self;
    1.46 +	}
    1.47 +
    1.48 +// deprecated
    1.49 +EXPORT_C CCertificateAppInfoManager* CCertificateAppInfoManager::NewLC(RFs& /*aFs*/,
    1.50 +																	   TBool /*aOpenedForWrite*/)
    1.51 +	{
    1.52 +	return NewLC();
    1.53 +	}
    1.54 +
    1.55 +// deprecated
    1.56 +EXPORT_C CCertificateAppInfoManager* CCertificateAppInfoManager::NewL(RFs& /*aFs*/,
    1.57 +																	  TBool /*aOpenedForWrite*/)
    1.58 +	{
    1.59 +	return NewL();
    1.60 +	}
    1.61 +
    1.62 +EXPORT_C CCertificateAppInfoManager::~CCertificateAppInfoManager()
    1.63 +	{
    1.64 +	iClients.Close();
    1.65 +	if (iCertAppsIf)
    1.66 +		{
    1.67 +		iCertAppsIf->Release();
    1.68 +		}
    1.69 +	}
    1.70 +
    1.71 +CCertificateAppInfoManager::CCertificateAppInfoManager()
    1.72 +	{
    1.73 +	}
    1.74 +
    1.75 +void CCertificateAppInfoManager::ConstructL()
    1.76 +	{
    1.77 +	// This method is the second phase of the construction process.
    1.78 +	//
    1.79 +	// It will open the cert apps token type, get the token, and 
    1.80 +	// then get the token interface.
    1.81 +	//
    1.82 +	// This class is not an active object but we can safely
    1.83 +	// wait for requests to complete because the filetokens
    1.84 +	// server completes requests immediately
    1.85 +	MCTTokenType* tokenType = CFSTokenTypeClient::NewL(TUid::Uid(KTokenTypeCertApps));
    1.86 +	CleanupReleasePushL(*tokenType);
    1.87 +
    1.88 +	// Now extract all the tokens this token type contains
    1.89 +	RCPointerArray<HBufC> tokenArray;
    1.90 +	CleanupClosePushL(tokenArray);
    1.91 +
    1.92 +	TRequestStatus stat;
    1.93 +	tokenType->List(tokenArray, stat);
    1.94 +	User::WaitForRequest(stat);
    1.95 +
    1.96 +	// make sure we have at least one token, otherwise leave
    1.97 +	User::LeaveIfError(stat.Int());
    1.98 +	__ASSERT_DEBUG(tokenArray.Count(), User::Panic(_L("CCertificateAppInfoManager"), 1));
    1.99 +
   1.100 +	MCTToken* token = NULL;
   1.101 +
   1.102 +	// We assume the 1st token is the one we want
   1.103 +	tokenType->OpenToken(*tokenArray[0], token, stat);
   1.104 +	User::WaitForRequest(stat);
   1.105 +	User::LeaveIfError(stat.Int());
   1.106 +	CleanupReleasePushL(*token);
   1.107 +
   1.108 +	// Now try and get the appropriate token interface
   1.109 +	MCTTokenInterface* tokenIf = NULL;
   1.110 +	token->GetInterface(TUid::Uid(KInterfaceCertApps), tokenIf, stat);
   1.111 +	User::WaitForRequest(stat);
   1.112 +	User::LeaveIfError(stat.Int());
   1.113 +	__ASSERT_DEBUG(tokenIf, User::Panic(_L("CCertificateAppInfoManager"), 1));
   1.114 +
   1.115 +	// now upcast to a certapps interface. This should be a fairly safe cast
   1.116 +	// since we specifically requested for this interface
   1.117 +	iCertAppsIf = static_cast<MCTCertApps*>(tokenIf);
   1.118 +
   1.119 +	// Now we can release the token and the token type and destroy the token
   1.120 +	// array
   1.121 +	token->Release();
   1.122 +	tokenType->Release();
   1.123 +	tokenArray.Close();
   1.124 +
   1.125 +	// Pop the stuff from the cleanup stack - could have done a
   1.126 +	// PopAndDestroy instead of Release()/Close() but thought I'd be 
   1.127 +	// more explicit
   1.128 +	CleanupStack::Pop(3);
   1.129 +
   1.130 +	// Populate the applications array
   1.131 +	iCertAppsIf->ApplicationsL(iClients);
   1.132 +	}
   1.133 +
   1.134 +EXPORT_C void CCertificateAppInfoManager::AddL(const TCertificateAppInfo& aClient)
   1.135 +	{
   1.136 +	// We have to update our cached applications array, but must keep this in
   1.137 +	// sync with the server in the face of leaves and OOM
   1.138 +	User::LeaveIfError(iClients.Append(aClient));
   1.139 +	TRAPD(err, iCertAppsIf->AddL(aClient));
   1.140 +	if (err != KErrNone)
   1.141 +		{
   1.142 +		iClients.Remove(iClients.Count() - 1);
   1.143 +		User::Leave(err);
   1.144 +		}
   1.145 +	}
   1.146 +
   1.147 +EXPORT_C void CCertificateAppInfoManager::RemoveL(const TUid& aUid)
   1.148 +	{
   1.149 +	// We have to update our cached applications array, but must keep this in
   1.150 +	// sync with the server in the face of leaves and OOM
   1.151 +	iCertAppsIf->RemoveL(aUid);
   1.152 +	
   1.153 +	// Count backwards so we don't have to worry about the size changing
   1.154 +	for (TInt i = iClients.Count() - 1 ; i >= 0 ; --i)
   1.155 +		{
   1.156 +		if (iClients[i].Id() == aUid)
   1.157 +			{
   1.158 +			iClients.Remove(i);
   1.159 +			}
   1.160 +		}
   1.161 +	}
   1.162 +
   1.163 +EXPORT_C const TCertificateAppInfo& CCertificateAppInfoManager::ApplicationL(const TUid& aUid, TInt& aIndex) const
   1.164 +	{
   1.165 +	aIndex = KErrNotFound;
   1.166 +	
   1.167 +	for (TInt i = 0 ; i < iClients.Count() ; ++i)
   1.168 +		{
   1.169 +		if (iClients[i].Id() == aUid)
   1.170 +			{
   1.171 +			aIndex = i;
   1.172 +			break;
   1.173 +			}
   1.174 +		}
   1.175 +	
   1.176 +	User::LeaveIfError(aIndex);
   1.177 +	return iClients[aIndex];
   1.178 +	}
   1.179 +
   1.180 +EXPORT_C const RArray<TCertificateAppInfo>& CCertificateAppInfoManager::Applications() const
   1.181 +	{
   1.182 +	return iClients;
   1.183 +	}