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