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