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 "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: #include "FileserverUtil.h" sl@0: sl@0: /** sl@0: * @enum Constant Literals used. sl@0: */ sl@0: sl@0: /*@{*/ sl@0: sl@0: // Parameters sl@0: _LIT( KExpectedName, "expectedName" ); sl@0: _LIT( KExpectedSize, "expectedSize" ); sl@0: _LIT( KExpectedTime, "expectedTime" ); sl@0: _LIT( KExpectedUid1, "expectedUid1" ); sl@0: _LIT( KExpectedUid2, "expectedUid2" ); sl@0: _LIT( KExpectedUid3, "expectedUid3" ); sl@0: _LIT( KVolumeLabel, "volume_label" ); sl@0: _LIT( KVolumeSize, "volume_size"); sl@0: _LIT( KVolumeFreeSpace, "volume_free_space" ); sl@0: _LIT( KVolumeUniqueID, "volume_unique_id"); sl@0: _LIT( KExpectedMostDerivedUid, "expectedMostDerivedUid" ); sl@0: _LIT( KVolumeFileCacheFlags, "volume_File_Cache_Flags" ); sl@0: _LIT( KFileCacheReadEnabled, "EFileCacheReadEnabled" ); sl@0: _LIT( KFileCacheReadOn, "EFileCacheReadOn"); sl@0: _LIT( KFileCacheReadAheadEnabled, "EFileCacheReadAheadEnabled" ); sl@0: _LIT( KFileCacheReadAheadOn, "EFileCacheReadAheadOn" ); sl@0: _LIT( KFileCacheWriteEnabled, "EFileCacheWriteEnabled" ); sl@0: _LIT( KFileCacheWriteOn, "EFileCacheWriteOn" ); sl@0: sl@0: // Attributes sl@0: _LIT(KEntryAttNormalStr, "KEntryAttNormal"); sl@0: _LIT(KEntryAttReadOnlyStr, "KEntryAttReadOnly"); sl@0: _LIT(KEntryAttHiddenStr, "KEntryAttHidden"); sl@0: _LIT(KEntryAttSystemStr, "KEntryAttSystem"); sl@0: _LIT(KEntryAttVolumeStr, "KEntryAttVolume"); sl@0: _LIT(KEntryAttDirStr, "KEntryAttDir"); sl@0: _LIT(KEntryAttArchiveStr, "KEntryAttArchive"); sl@0: _LIT(KEntryAttXIPStr, "KEntryAttXIP"); sl@0: #if (!defined(__Symbian_OS_v9_1__)) sl@0: _LIT(KEntryAttRemoteStr, "KEntryAttRemote"); sl@0: _LIT(KEntryAttMaskFileSystemSpecificStr,"KEntryAttMaskFileSystemSpecific"); sl@0: #endif sl@0: _LIT(KEntryAttMatchMaskStr, "KEntryAttMatchMask"); sl@0: _LIT(KEntryAttMaskSupportedStr, "KEntryAttMaskSupported"); sl@0: _LIT(KEntryAttMatchExclusiveStr, "KEntryAttMatchExclusive"); sl@0: _LIT(KEntryAttMatchExcludeStr, "KEntryAttMatchExclude"); sl@0: _LIT(KEntryAttAllowUidStr, "KEntryAttAllowUid"); sl@0: sl@0: // constants sl@0: const TInt KUid1Index = 0; sl@0: const TInt KUid2Index = 1; sl@0: const TInt KUid3Index = 2; sl@0: sl@0: const TInt KTimeFormatSize = 30; sl@0: _LIT( KTimeFormat, "%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B" ); sl@0: sl@0: /*@}*/ sl@0: sl@0: sl@0: sl@0: TBool FileserverUtil::VerifyTEntryDataFromIniL(CDataWrapper& aDataWrapper, const TDesC& aSection, TEntry& aEntry) sl@0: { sl@0: TBool ret = ETrue; sl@0: sl@0: aDataWrapper.INFO_PRINTF2(_L("Entry name = %S"), &aEntry.iName ); sl@0: sl@0: TPtrC expectedStr; sl@0: if ( aDataWrapper.GetStringFromConfig(aSection, KExpectedName(), expectedStr) ) sl@0: { sl@0: if (aEntry.iName.CompareC(expectedStr, 0, NULL) != 0) sl@0: { sl@0: aDataWrapper.ERR_PRINTF3(_L("%S != %S"), &aEntry.iName, &expectedStr); sl@0: ret = EFalse; sl@0: } sl@0: else sl@0: { sl@0: aDataWrapper.INFO_PRINTF3(_L("%S == %S"), &aEntry.iName, &expectedStr); sl@0: } sl@0: } sl@0: sl@0: TInt expectedInt = 0; sl@0: if ( aDataWrapper.GetIntFromConfig(aSection, KExpectedSize(), expectedInt) ) sl@0: { sl@0: aDataWrapper.INFO_PRINTF2(_L("Entry size = %d"), aEntry.iSize ); sl@0: if (aEntry.iSize != expectedInt) sl@0: { sl@0: aDataWrapper.ERR_PRINTF3(_L("Size from ini file not equal with size returned from function (%d != %d)"), expectedInt, aEntry.iSize); sl@0: ret = EFalse; sl@0: } sl@0: } sl@0: sl@0: if ( aDataWrapper.GetStringFromConfig(aSection, KExpectedTime(), expectedStr) ) sl@0: { sl@0: TBuf dateString; sl@0: aEntry.iModified.FormatL(dateString, KTimeFormat); sl@0: aDataWrapper.INFO_PRINTF2(_L("Entry modified %S"), &dateString); sl@0: sl@0: TTime modificationTime; sl@0: User::LeaveIfError(modificationTime.Set(expectedStr)); sl@0: sl@0: if (aEntry.iModified != modificationTime) sl@0: { sl@0: aDataWrapper.ERR_PRINTF1(_L("Time from ini file not equal with time returned from function.")); sl@0: ret = EFalse; sl@0: } sl@0: } sl@0: sl@0: if ( aDataWrapper.GetIntFromConfig(aSection, KExpectedUid1(), expectedInt) ) sl@0: { sl@0: TInt uid1 = aEntry.iType[KUid1Index].iUid; sl@0: aDataWrapper.INFO_PRINTF2(_L("Entry UID1 = %d"), uid1 ); sl@0: sl@0: if ( uid1 != expectedInt ) sl@0: { sl@0: aDataWrapper.ERR_PRINTF3(_L("Entry UID1 %d != ini UID1 %d)"), uid1, expectedInt); sl@0: ret = EFalse; sl@0: } sl@0: } sl@0: sl@0: if ( aDataWrapper.GetIntFromConfig(aSection, KExpectedUid2(), expectedInt) ) sl@0: { sl@0: TInt uid2 = aEntry.iType[KUid2Index].iUid; sl@0: aDataWrapper.INFO_PRINTF2(_L("Entry UID2 = %d"), uid2 ); sl@0: sl@0: if ( uid2 != expectedInt ) sl@0: { sl@0: aDataWrapper.ERR_PRINTF3(_L("Entry UID2 %d != ini UID1 %d)"), uid2, expectedInt); sl@0: ret = EFalse; sl@0: } sl@0: } sl@0: sl@0: if ( aDataWrapper.GetIntFromConfig(aSection, KExpectedUid3(), expectedInt) ) sl@0: { sl@0: TInt uid3 = aEntry.iType[KUid3Index].iUid; sl@0: aDataWrapper.INFO_PRINTF2(_L("Entry UID3 = %d"), uid3 ); sl@0: sl@0: if ( uid3 != expectedInt ) sl@0: { sl@0: aDataWrapper.ERR_PRINTF3(_L("Entry UID3 %d != ini UID3 %d)"), uid3, expectedInt); sl@0: ret = EFalse; sl@0: } sl@0: } sl@0: sl@0: if ( aDataWrapper.GetIntFromConfig(aSection, KExpectedMostDerivedUid(), expectedInt) ) sl@0: { sl@0: TInt mostDerivedUid = aEntry.MostDerivedUid().iUid; sl@0: aDataWrapper.INFO_PRINTF2(_L("MostDerivedUid = %d"), mostDerivedUid); sl@0: sl@0: if ( mostDerivedUid != expectedInt ) sl@0: { sl@0: aDataWrapper.ERR_PRINTF3(_L("Entry MostDerivedUid %d != ini MostDerivedUid %d)"), mostDerivedUid, expectedInt); sl@0: ret = EFalse; sl@0: } sl@0: } sl@0: sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: sl@0: TBool FileserverUtil::VerifyTVolumeInfoDataFromIniL(CDataWrapper& aDataWrapper, const TDesC& aSection, TVolumeInfo& aVolumeInfo) sl@0: { sl@0: TBool ret = ETrue; sl@0: sl@0: //Get volume name from config. sl@0: TPtrC volumeLabel; sl@0: if (aDataWrapper.GetStringFromConfig(aSection, KVolumeLabel(), volumeLabel)) sl@0: { sl@0: //Checking that name of volume is equal to passed through config file. sl@0: if (aVolumeInfo.iName.CompareC(volumeLabel, 0, NULL) != 0) sl@0: { sl@0: aDataWrapper.ERR_PRINTF1(_L("Volume name from ini file not equal with volume name returned from function")); sl@0: ret = EFalse; sl@0: } sl@0: } sl@0: sl@0: TInt tmp; sl@0: if (aDataWrapper.GetIntFromConfig(aSection, KVolumeSize(), tmp)) sl@0: { sl@0: TInt64 volumeSize; sl@0: volumeSize = tmp; sl@0: //Checking that size of volume is equal to passed through config file. sl@0: if (volumeSize != aVolumeInfo.iSize) sl@0: { sl@0: aDataWrapper.ERR_PRINTF1(_L("Volume size from ini file not equal with volume size returned from function")); sl@0: ret = EFalse; sl@0: } sl@0: } sl@0: sl@0: if (aDataWrapper.GetIntFromConfig(aSection, KVolumeFreeSpace(), tmp)) sl@0: { sl@0: TInt64 freeSpace; sl@0: freeSpace = tmp; sl@0: //Checking that free space of volume is equal to passed through config file. sl@0: if (freeSpace != aVolumeInfo.iFree) sl@0: { sl@0: aDataWrapper.ERR_PRINTF1(_L("Volume free space amount from ini file not equal with volume free space amount returned from function")); sl@0: ret = EFalse; sl@0: } sl@0: } sl@0: sl@0: if (aDataWrapper.GetIntFromConfig(aSection, KVolumeUniqueID(), tmp)) sl@0: { sl@0: if(tmp<0) sl@0: { sl@0: aDataWrapper.ERR_PRINTF1(_L("ID in config should be not less than 0 ")); sl@0: ret = EFalse; sl@0: } sl@0: else sl@0: { sl@0: TUint volumeUniqueID; sl@0: volumeUniqueID = (TUint)tmp; sl@0: //Checking that Unique ID of volume is equal to passed through config file. sl@0: if (volumeUniqueID != aVolumeInfo.iUniqueID) sl@0: { sl@0: aDataWrapper.ERR_PRINTF1(_L("Volume unique ID from ini file not equal with volume unique ID returned from function")); sl@0: ret = EFalse; sl@0: } sl@0: } sl@0: } sl@0: sl@0: TPtrC volumeFileCacheFlags; sl@0: if (aDataWrapper.GetStringFromConfig(aSection, KVolumeFileCacheFlags(), volumeFileCacheFlags)) sl@0: { sl@0: TFileCacheFlags tmpFileCacheFlags; sl@0: if(volumeFileCacheFlags == KFileCacheReadEnabled()) sl@0: { sl@0: tmpFileCacheFlags = EFileCacheReadEnabled; sl@0: } sl@0: else if(volumeFileCacheFlags == KFileCacheReadOn()) sl@0: { sl@0: tmpFileCacheFlags = EFileCacheReadOn; sl@0: } sl@0: else if(volumeFileCacheFlags == KFileCacheReadAheadEnabled()) sl@0: { sl@0: tmpFileCacheFlags = EFileCacheReadAheadEnabled; sl@0: } sl@0: else if(volumeFileCacheFlags == KFileCacheReadAheadOn()) sl@0: { sl@0: tmpFileCacheFlags = EFileCacheReadAheadOn; sl@0: } sl@0: else if(volumeFileCacheFlags == KFileCacheWriteEnabled()) sl@0: { sl@0: tmpFileCacheFlags = EFileCacheWriteEnabled; sl@0: } sl@0: else if(volumeFileCacheFlags == KFileCacheWriteOn()) sl@0: { sl@0: tmpFileCacheFlags = EFileCacheWriteOn; sl@0: } sl@0: else sl@0: { sl@0: aDataWrapper.ERR_PRINTF1(_L("Volume file cache flags from ini file not equal with volume file cache flags returned from function")); sl@0: ret = EFalse; sl@0: } sl@0: sl@0: if(ret && (aVolumeInfo.iFileCacheFlags != tmpFileCacheFlags)) sl@0: { sl@0: aDataWrapper.ERR_PRINTF1(_L("Volume file cache flags from ini file not equal with volume file cache flags returned from function")); sl@0: ret = EFalse; sl@0: } sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: sl@0: TBool FileserverUtil::GetAttMask(CDataWrapper& aDataWrapper, const TDesC& aSection, const TDesC& aParameterName, TUint& aAttMask) sl@0: { sl@0: TPtrC iniAttMaskStr; sl@0: TBool ret = aDataWrapper.GetStringFromConfig(aSection, aParameterName, iniAttMaskStr); sl@0: if ( ret ) sl@0: { sl@0: if ( !ConvertToAttMask(iniAttMaskStr, aAttMask) ) sl@0: { sl@0: TInt intTemp; sl@0: ret = aDataWrapper.GetIntFromConfig(aSection, aParameterName, intTemp); sl@0: if ( ret ) sl@0: { sl@0: aAttMask = intTemp; sl@0: } sl@0: } sl@0: } sl@0: sl@0: return ret; sl@0: } sl@0: sl@0: sl@0: sl@0: TBool FileserverUtil::ConvertToAttMask(const TDesC& aAttMaskStr, TUint& aAttMask) sl@0: { sl@0: TBool ret = ETrue; sl@0: sl@0: if (aAttMaskStr == KEntryAttNormalStr) sl@0: { sl@0: aAttMask = KEntryAttNormal; sl@0: } sl@0: else if (aAttMaskStr == KEntryAttReadOnlyStr) sl@0: { sl@0: aAttMask = KEntryAttReadOnly; sl@0: } sl@0: else if (aAttMaskStr == KEntryAttHiddenStr) sl@0: { sl@0: aAttMask = KEntryAttHidden; sl@0: } sl@0: else if (aAttMaskStr == KEntryAttSystemStr) sl@0: { sl@0: aAttMask = KEntryAttSystem; sl@0: } sl@0: else if (aAttMaskStr == KEntryAttVolumeStr) sl@0: { sl@0: aAttMask = KEntryAttVolume; sl@0: } sl@0: else if (aAttMaskStr == KEntryAttDirStr) sl@0: { sl@0: aAttMask = KEntryAttDir; sl@0: } sl@0: else if (aAttMaskStr == KEntryAttArchiveStr) sl@0: { sl@0: aAttMask = KEntryAttArchive; sl@0: } sl@0: else if (aAttMaskStr == KEntryAttXIPStr) sl@0: { sl@0: aAttMask = KEntryAttXIP; sl@0: } sl@0: #if (!defined(__Symbian_OS_v9_1__)) sl@0: else if (aAttMaskStr == KEntryAttRemoteStr) sl@0: { sl@0: aAttMask = KEntryAttRemote; sl@0: } sl@0: else if (aAttMaskStr == KEntryAttMaskFileSystemSpecificStr) sl@0: { sl@0: aAttMask = KEntryAttMaskFileSystemSpecific; sl@0: } sl@0: #endif sl@0: else if (aAttMaskStr == KEntryAttMatchMaskStr) sl@0: { sl@0: aAttMask = KEntryAttMatchMask; sl@0: } sl@0: else if (aAttMaskStr == KEntryAttMaskSupportedStr) sl@0: { sl@0: aAttMask = KEntryAttMaskSupported; sl@0: } sl@0: else if (aAttMaskStr == KEntryAttMatchExclusiveStr) sl@0: { sl@0: aAttMask = KEntryAttMatchExclusive; sl@0: } sl@0: else if (aAttMaskStr == KEntryAttMatchExcludeStr) sl@0: { sl@0: aAttMask = KEntryAttMatchExclude; sl@0: } sl@0: else if (aAttMaskStr == KEntryAttAllowUidStr) sl@0: { sl@0: aAttMask = KEntryAttAllowUid; sl@0: } sl@0: else if (aAttMaskStr.Match((_L("*|*"))) != KErrNotFound) sl@0: { sl@0: TUint tmpAttMask; sl@0: sl@0: TInt location = aAttMaskStr.Match(_L("*|*")); sl@0: //Converting Left part of the data sl@0: TPtrC left = aAttMaskStr.Left(location); sl@0: if (ConvertToAttMask(left, tmpAttMask)) sl@0: { sl@0: aAttMask = tmpAttMask; sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: sl@0: //Converting right data can be with another "|" sl@0: TPtrC right = aAttMaskStr.Mid(location + 1); sl@0: if (ConvertToAttMask(right, tmpAttMask)) sl@0: { sl@0: aAttMask = aAttMask | tmpAttMask; sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ret = EFalse; sl@0: } sl@0: sl@0: return ret; sl@0: } sl@0: