os/kernelhwsrv/baseapitest/basesvs/common/src/FileserverUtil.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 "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 #include "FileserverUtil.h"
    20 
    21 /**
    22  * @enum Constant Literals used.
    23  */
    24  
    25 /*@{*/
    26 
    27 // Parameters
    28 _LIT( KExpectedName,					"expectedName" );
    29 _LIT( KExpectedSize,					"expectedSize" );
    30 _LIT( KExpectedTime,					"expectedTime" );
    31 _LIT( KExpectedUid1,					"expectedUid1" );
    32 _LIT( KExpectedUid2,					"expectedUid2" );
    33 _LIT( KExpectedUid3,					"expectedUid3" );
    34 _LIT( KVolumeLabel,						"volume_label" );
    35 _LIT( KVolumeSize,						"volume_size");
    36 _LIT( KVolumeFreeSpace,					"volume_free_space" );
    37 _LIT( KVolumeUniqueID,					"volume_unique_id");
    38 _LIT( KExpectedMostDerivedUid,			"expectedMostDerivedUid" );
    39 _LIT( KVolumeFileCacheFlags,			"volume_File_Cache_Flags" );
    40 _LIT( KFileCacheReadEnabled,			"EFileCacheReadEnabled" );
    41 _LIT( KFileCacheReadOn,					"EFileCacheReadOn");
    42 _LIT( KFileCacheReadAheadEnabled,		"EFileCacheReadAheadEnabled" );
    43 _LIT( KFileCacheReadAheadOn,			"EFileCacheReadAheadOn" );
    44 _LIT( KFileCacheWriteEnabled,			"EFileCacheWriteEnabled" );
    45 _LIT( KFileCacheWriteOn,				"EFileCacheWriteOn" );
    46 
    47 // Attributes
    48 _LIT(KEntryAttNormalStr, 				"KEntryAttNormal");
    49 _LIT(KEntryAttReadOnlyStr, 				"KEntryAttReadOnly");
    50 _LIT(KEntryAttHiddenStr, 				"KEntryAttHidden");
    51 _LIT(KEntryAttSystemStr, 				"KEntryAttSystem");
    52 _LIT(KEntryAttVolumeStr,				"KEntryAttVolume");
    53 _LIT(KEntryAttDirStr, 					"KEntryAttDir");
    54 _LIT(KEntryAttArchiveStr, 				"KEntryAttArchive");
    55 _LIT(KEntryAttXIPStr, 					"KEntryAttXIP");
    56 #if (!defined(__Symbian_OS_v9_1__))
    57 _LIT(KEntryAttRemoteStr, 				"KEntryAttRemote");
    58 _LIT(KEntryAttMaskFileSystemSpecificStr,"KEntryAttMaskFileSystemSpecific");
    59 #endif
    60 _LIT(KEntryAttMatchMaskStr,				"KEntryAttMatchMask");
    61 _LIT(KEntryAttMaskSupportedStr,			"KEntryAttMaskSupported");
    62 _LIT(KEntryAttMatchExclusiveStr,		"KEntryAttMatchExclusive");
    63 _LIT(KEntryAttMatchExcludeStr,			"KEntryAttMatchExclude");
    64 _LIT(KEntryAttAllowUidStr,				"KEntryAttAllowUid");
    65 
    66 // constants
    67 const TInt KUid1Index 					= 0;
    68 const TInt KUid2Index 					= 1;
    69 const TInt KUid3Index 					= 2;
    70 
    71 const TInt KTimeFormatSize 				= 30;
    72 _LIT( KTimeFormat,						"%D%M%Y%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B" );
    73 
    74 /*@}*/
    75 
    76 
    77 
    78 TBool FileserverUtil::VerifyTEntryDataFromIniL(CDataWrapper& aDataWrapper, const TDesC& aSection, TEntry& aEntry)
    79 	{
    80 	TBool ret = ETrue; 
    81 
    82 	aDataWrapper.INFO_PRINTF2(_L("Entry name = %S"), &aEntry.iName );				
    83 		
    84 	TPtrC expectedStr;
    85 	if ( aDataWrapper.GetStringFromConfig(aSection, KExpectedName(), expectedStr) )
    86 		{
    87 		if (aEntry.iName.CompareC(expectedStr, 0, NULL) != 0)
    88 			{
    89 			aDataWrapper.ERR_PRINTF3(_L("%S != %S"), &aEntry.iName, &expectedStr);
    90 			ret = EFalse;
    91 			}
    92 		else
    93 			{
    94 			aDataWrapper.INFO_PRINTF3(_L("%S == %S"), &aEntry.iName, &expectedStr);
    95 			}
    96 		}
    97 			
    98 	TInt expectedInt = 0;
    99 	if ( aDataWrapper.GetIntFromConfig(aSection, KExpectedSize(), expectedInt) )
   100 		{
   101 		aDataWrapper.INFO_PRINTF2(_L("Entry size = %d"), aEntry.iSize );
   102 		if (aEntry.iSize != expectedInt)
   103 			{
   104 			aDataWrapper.ERR_PRINTF3(_L("Size from ini file not equal with size returned from function (%d != %d)"), expectedInt, aEntry.iSize);
   105 			ret = EFalse;
   106 			}
   107 		}
   108 	
   109 	if ( aDataWrapper.GetStringFromConfig(aSection, KExpectedTime(), expectedStr) )
   110 		{			
   111 		TBuf<KTimeFormatSize>	dateString;
   112 		aEntry.iModified.FormatL(dateString, KTimeFormat);
   113 		aDataWrapper.INFO_PRINTF2(_L("Entry modified %S"), &dateString);
   114 		
   115 		TTime	modificationTime;
   116 		User::LeaveIfError(modificationTime.Set(expectedStr));
   117 		
   118 		if (aEntry.iModified != modificationTime)
   119 			{
   120 			aDataWrapper.ERR_PRINTF1(_L("Time from ini file not equal with time returned from function."));
   121 			ret = EFalse;
   122 			}
   123 		}
   124 	
   125 	if ( aDataWrapper.GetIntFromConfig(aSection, KExpectedUid1(), expectedInt) )
   126 		{
   127 		TInt uid1 = aEntry.iType[KUid1Index].iUid;	
   128 		aDataWrapper.INFO_PRINTF2(_L("Entry UID1 = %d"), uid1 );
   129 
   130 		if ( uid1 != expectedInt )
   131 			{
   132 			aDataWrapper.ERR_PRINTF3(_L("Entry UID1 %d  !=  ini UID1 %d)"), uid1, expectedInt);
   133 			ret = EFalse;
   134 			}
   135 		}
   136 		
   137 	if ( aDataWrapper.GetIntFromConfig(aSection, KExpectedUid2(), expectedInt) )
   138 		{
   139 		TInt uid2 = aEntry.iType[KUid2Index].iUid;
   140 		aDataWrapper.INFO_PRINTF2(_L("Entry UID2 = %d"), uid2 );
   141 
   142 		if ( uid2 != expectedInt )
   143 			{
   144 			aDataWrapper.ERR_PRINTF3(_L("Entry UID2 %d  !=  ini UID1 %d)"), uid2, expectedInt);
   145 			ret = EFalse;
   146 			}
   147 		}
   148 		
   149 	if ( aDataWrapper.GetIntFromConfig(aSection, KExpectedUid3(), expectedInt) )
   150 		{
   151 		TInt uid3 = aEntry.iType[KUid3Index].iUid;
   152 		aDataWrapper.INFO_PRINTF2(_L("Entry UID3 = %d"), uid3 );
   153 		
   154 		if ( uid3 != expectedInt )
   155 			{
   156 			aDataWrapper.ERR_PRINTF3(_L("Entry UID3 %d  !=  ini UID3 %d)"), uid3, expectedInt);
   157 			ret = EFalse;
   158 			}
   159 		}
   160 		
   161 	if ( aDataWrapper.GetIntFromConfig(aSection, KExpectedMostDerivedUid(), expectedInt) )
   162 		{
   163 		TInt mostDerivedUid = aEntry.MostDerivedUid().iUid;
   164 		aDataWrapper.INFO_PRINTF2(_L("MostDerivedUid = %d"), mostDerivedUid);
   165 
   166 		if ( mostDerivedUid != expectedInt )
   167 			{
   168 			aDataWrapper.ERR_PRINTF3(_L("Entry MostDerivedUid %d  !=  ini MostDerivedUid %d)"), mostDerivedUid, expectedInt);
   169 			ret = EFalse;
   170 			}
   171 		}
   172 	
   173 
   174 	return ret;
   175 	}
   176 
   177 
   178 
   179 TBool FileserverUtil::VerifyTVolumeInfoDataFromIniL(CDataWrapper& aDataWrapper, const TDesC& aSection, TVolumeInfo& aVolumeInfo)
   180 	{
   181 	TBool ret = ETrue; 
   182 
   183 	//Get volume name from config.
   184 	TPtrC	volumeLabel;
   185 	if (aDataWrapper.GetStringFromConfig(aSection, KVolumeLabel(), volumeLabel))
   186 		{
   187 		//Checking that name of volume is equal to passed through config file.
   188 		if (aVolumeInfo.iName.CompareC(volumeLabel, 0, NULL) != 0)
   189 			{
   190 			aDataWrapper.ERR_PRINTF1(_L("Volume name from ini file not equal with volume name returned from function"));
   191 			ret = EFalse;
   192 			}
   193 		}
   194 	
   195 	TInt	tmp;
   196 	if (aDataWrapper.GetIntFromConfig(aSection, KVolumeSize(), tmp))
   197 		{
   198 		TInt64	volumeSize;
   199 		volumeSize = tmp;
   200 		//Checking that size of volume is equal to passed through config file.
   201 		if (volumeSize != aVolumeInfo.iSize)
   202 			{
   203 			aDataWrapper.ERR_PRINTF1(_L("Volume size from ini file not equal with volume size returned from function"));
   204 			ret = EFalse;
   205 			}
   206 		}
   207 
   208 	if (aDataWrapper.GetIntFromConfig(aSection, KVolumeFreeSpace(), tmp))
   209 		{
   210 		TInt64	freeSpace;
   211 		freeSpace = tmp;
   212 		//Checking that free space of volume is equal to passed through config file.
   213 		if (freeSpace != aVolumeInfo.iFree)
   214 			{
   215 			aDataWrapper.ERR_PRINTF1(_L("Volume free space amount from ini file not equal with volume free space amount returned from function"));
   216 			ret = EFalse;
   217 			}
   218 		}
   219 
   220 	if (aDataWrapper.GetIntFromConfig(aSection, KVolumeUniqueID(), tmp))
   221 		{
   222 		if(tmp<0)
   223 			{
   224 			aDataWrapper.ERR_PRINTF1(_L("ID in config should be not less than 0 "));
   225 			ret = EFalse;
   226 			}
   227 		else
   228 			{
   229 			TUint	volumeUniqueID;
   230 			volumeUniqueID = (TUint)tmp;
   231 			//Checking that Unique ID of volume is equal to passed through config file.
   232 			if (volumeUniqueID != aVolumeInfo.iUniqueID)
   233 				{
   234 				aDataWrapper.ERR_PRINTF1(_L("Volume unique ID from ini file not equal with volume unique ID returned from function"));
   235 				ret = EFalse;
   236 				}
   237 			}
   238 		}
   239 
   240 	TPtrC volumeFileCacheFlags;		
   241 	if (aDataWrapper.GetStringFromConfig(aSection, KVolumeFileCacheFlags(), volumeFileCacheFlags))
   242 		{
   243 		TFileCacheFlags tmpFileCacheFlags;
   244 		if(volumeFileCacheFlags == KFileCacheReadEnabled())
   245 			{
   246 			tmpFileCacheFlags = EFileCacheReadEnabled;
   247 			}
   248 		else if(volumeFileCacheFlags == KFileCacheReadOn())
   249 			{
   250 			tmpFileCacheFlags = EFileCacheReadOn;
   251 			}
   252 		else if(volumeFileCacheFlags == KFileCacheReadAheadEnabled())
   253 			{
   254 			tmpFileCacheFlags = EFileCacheReadAheadEnabled;
   255 			}
   256 		else if(volumeFileCacheFlags == KFileCacheReadAheadOn())
   257 			{
   258 			tmpFileCacheFlags = EFileCacheReadAheadOn;
   259 			}
   260 		else if(volumeFileCacheFlags == KFileCacheWriteEnabled())
   261 			{
   262 			tmpFileCacheFlags = EFileCacheWriteEnabled;
   263 			}
   264 		else if(volumeFileCacheFlags == KFileCacheWriteOn())
   265 			{
   266 			tmpFileCacheFlags = EFileCacheWriteOn;
   267 			}
   268 		else
   269 			{
   270 			aDataWrapper.ERR_PRINTF1(_L("Volume file cache flags from ini file not equal with volume file cache flags returned from function"));
   271 			ret = EFalse;
   272 			}
   273 			
   274 		if(ret && (aVolumeInfo.iFileCacheFlags != tmpFileCacheFlags))
   275 			{
   276 			aDataWrapper.ERR_PRINTF1(_L("Volume file cache flags from ini file not equal with volume file cache flags returned from function"));
   277 			ret = EFalse;
   278 			}
   279 		}
   280 	return ret;
   281 	}
   282 	
   283 	
   284 	
   285 TBool FileserverUtil::GetAttMask(CDataWrapper& aDataWrapper, const TDesC& aSection, const TDesC& aParameterName, TUint& aAttMask)
   286 	{
   287 	TPtrC	iniAttMaskStr;
   288 	TBool	ret = aDataWrapper.GetStringFromConfig(aSection, aParameterName, iniAttMaskStr);
   289 	if ( ret )
   290 		{
   291 		if ( !ConvertToAttMask(iniAttMaskStr, aAttMask) )
   292 			{
   293 			TInt	intTemp;
   294 			ret = aDataWrapper.GetIntFromConfig(aSection, aParameterName, intTemp);
   295 			if ( ret )
   296 				{
   297 				aAttMask = intTemp;
   298 				}
   299 			}
   300 		}
   301 
   302 	return ret;
   303 	}
   304 
   305 
   306 
   307 TBool FileserverUtil::ConvertToAttMask(const TDesC& aAttMaskStr, TUint& aAttMask)
   308 	{
   309 	TBool ret = ETrue;
   310 
   311 	if (aAttMaskStr == KEntryAttNormalStr)
   312 		{
   313 		aAttMask = KEntryAttNormal;
   314 		}
   315 	else if (aAttMaskStr == KEntryAttReadOnlyStr)
   316 		{
   317 		aAttMask = KEntryAttReadOnly;
   318 		}
   319 	else if (aAttMaskStr == KEntryAttHiddenStr)
   320 		{
   321 		aAttMask = KEntryAttHidden;
   322 		}
   323 	else if (aAttMaskStr == KEntryAttSystemStr)
   324 		{
   325 		aAttMask = KEntryAttSystem;
   326 		}
   327 	else if (aAttMaskStr == KEntryAttVolumeStr)
   328 		{
   329 		aAttMask = KEntryAttVolume;
   330 		}
   331 	else if (aAttMaskStr == KEntryAttDirStr)
   332 		{
   333 		aAttMask = KEntryAttDir;
   334 		}
   335 	else if (aAttMaskStr == KEntryAttArchiveStr)
   336 		{
   337 		aAttMask = KEntryAttArchive;
   338 		}
   339 	else if (aAttMaskStr == KEntryAttXIPStr)
   340 		{
   341 		aAttMask = KEntryAttXIP;
   342 		}
   343 #if (!defined(__Symbian_OS_v9_1__))
   344 	else if (aAttMaskStr == KEntryAttRemoteStr)
   345 		{
   346 		aAttMask = KEntryAttRemote;
   347 		}
   348 	else if (aAttMaskStr == KEntryAttMaskFileSystemSpecificStr)
   349 		{
   350 		aAttMask = KEntryAttMaskFileSystemSpecific;
   351 		}
   352 #endif
   353 	else if (aAttMaskStr == KEntryAttMatchMaskStr)
   354 		{
   355 		aAttMask = KEntryAttMatchMask;
   356 		}
   357 	else if (aAttMaskStr == KEntryAttMaskSupportedStr)
   358 		{
   359 		aAttMask = KEntryAttMaskSupported;
   360 		}
   361 	else if (aAttMaskStr == KEntryAttMatchExclusiveStr)
   362 		{
   363 		aAttMask = KEntryAttMatchExclusive;
   364 		}
   365 	else if (aAttMaskStr == KEntryAttMatchExcludeStr)
   366 		{
   367 		aAttMask = KEntryAttMatchExclude;
   368 		}
   369 	else if (aAttMaskStr == KEntryAttAllowUidStr)
   370 		{
   371 		aAttMask = KEntryAttAllowUid;
   372 		}
   373 	else if (aAttMaskStr.Match((_L("*|*"))) != KErrNotFound)
   374 		{
   375 		TUint	tmpAttMask;
   376 
   377 		TInt	location = aAttMaskStr.Match(_L("*|*"));
   378 		//Converting Left part of the data
   379 		TPtrC	left = aAttMaskStr.Left(location);
   380 		if (ConvertToAttMask(left, tmpAttMask))
   381 			{
   382 			aAttMask = tmpAttMask;
   383 			}
   384 		else
   385 			{
   386 			ret = EFalse;
   387 			}
   388 
   389 		//Converting right data can be with another "|"
   390 		TPtrC	right = aAttMaskStr.Mid(location + 1);
   391 		if (ConvertToAttMask(right, tmpAttMask))
   392 			{
   393 			aAttMask = aAttMask | tmpAttMask;
   394 			}
   395 		else
   396 			{
   397 			ret = EFalse;
   398 			}
   399 		}
   400 	else
   401 		{
   402 		ret = EFalse;
   403 		}
   404 
   405 	return ret;
   406 	}
   407