sl@0: /* sl@0: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: #include "filecertstorenibbler.h" sl@0: #include sl@0: sl@0: _LIT(KFileCertstorePath, "\\system\\data\\cacerts.dat"); sl@0: sl@0: /*static*/ CFileCertstoreNibbler* CFileCertstoreNibbler::NewL(TTimeIntervalMicroSeconds32 aInterval) sl@0: { sl@0: CFileCertstoreNibbler* me = new (ELeave) CFileCertstoreNibbler(aInterval); sl@0: CleanupStack::PushL(me); sl@0: me->ConstructL(); sl@0: CleanupStack::Pop(me); sl@0: return (me); sl@0: } sl@0: sl@0: CFileCertstoreNibbler::CFileCertstoreNibbler(TTimeIntervalMicroSeconds32 aInterval) sl@0: : CTimer(EPriorityHigh), iNibbleInterval(aInterval) sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: CFileCertstoreNibbler::~CFileCertstoreNibbler() sl@0: { sl@0: Cancel(); sl@0: iFs.Close(); sl@0: } sl@0: sl@0: void CFileCertstoreNibbler::StartTimer() sl@0: { sl@0: After(iNibbleInterval); sl@0: } sl@0: sl@0: void CFileCertstoreNibbler::ConstructL() sl@0: { sl@0: User::LeaveIfError(iFs.Connect()); sl@0: sl@0: RFile file; sl@0: TDriveUnit sysDrive (RFs::GetSystemDrive()); sl@0: TBuf<128> fileCertstorePath (sysDrive.Name()); sl@0: fileCertstorePath.Append(KFileCertstorePath); sl@0: User::LeaveIfError(file.Open(iFs, fileCertstorePath, EFileWrite|EFileRead|EFileShareExclusive)); sl@0: CleanupClosePushL(file); sl@0: CPermanentFileStore* store = CPermanentFileStore::FromLC(file); sl@0: sl@0: RStoreWriteStream stream; sl@0: iNibbleStreamId = stream.CreateLC(*store); // stream for cert sl@0: sl@0: // Write to stream sl@0: _LIT(KNibble, "wool"); sl@0: stream << KNibble; sl@0: sl@0: stream.CommitL(); sl@0: CleanupStack::PopAndDestroy(); // stream sl@0: store->CommitL(); sl@0: CleanupStack::PopAndDestroy(store); sl@0: CleanupStack::Pop(); // file cleanup sl@0: sl@0: CTimer::ConstructL(); sl@0: StartTimer(); sl@0: } sl@0: sl@0: void CFileCertstoreNibbler::RunL() sl@0: { sl@0: NibbleFileL(); sl@0: StartTimer(); sl@0: } sl@0: sl@0: // Writes to the filecertstore file (\system\data\cacerts.dat on system drive) to test sl@0: // concurrency access. Writes to a separate stream so will have no effect sl@0: // on certs data. This doesn't test integrity of certstore in any way, is sl@0: // simply a quick check that the file can be opened and written to whilst sl@0: // other tests proceed. sl@0: void CFileCertstoreNibbler::NibbleFileL() sl@0: { sl@0: RFile file; sl@0: TDriveUnit sysDrive (RFs::GetSystemDrive()); sl@0: TBuf<128> fileCertstorePath (sysDrive.Name()); sl@0: fileCertstorePath.Append(KFileCertstorePath); sl@0: User::LeaveIfError(file.Open(iFs, fileCertstorePath, EFileWrite|EFileRead|EFileShareExclusive)); sl@0: CleanupClosePushL(file); sl@0: CPermanentFileStore* store = CPermanentFileStore::FromLC(file); sl@0: sl@0: RStoreWriteStream stream; sl@0: stream.ReplaceLC(*store, iNibbleStreamId); sl@0: sl@0: // Write to stream sl@0: _LIT(KNibble, "clanger"); sl@0: stream << KNibble; sl@0: sl@0: stream.CommitL(); sl@0: CleanupStack::PopAndDestroy(); // stream sl@0: store->CommitL(); sl@0: CleanupStack::PopAndDestroy(store); sl@0: CleanupStack::Pop(); // file cleanup sl@0: } sl@0: sl@0: TInt CFileCertstoreNibbler::RunError(TInt /*anError*/) sl@0: { sl@0: // _LIT(KNibblerError, "CFileCertstoreNibbler::RunError"); sl@0: // User::Panic(KNibblerError, anError); sl@0: return (KErrNone); sl@0: } sl@0: