|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 #include <f32file.h> |
|
16 #include <f32file64.h> |
|
17 #include "SqlSrvConfig.h" |
|
18 #include "SqlSrvUtil.h" |
|
19 |
|
20 /** |
|
21 Initializes TSqlSrvConfigParams data members with their default values. |
|
22 */ |
|
23 TSqlSrvConfigParams::TSqlSrvConfigParams() : |
|
24 iCacheSize(TSqlSrvConfigParams::KConfigPrmValueNotSet), |
|
25 iPageSize(TSqlSrvConfigParams::KConfigPrmValueNotSet), |
|
26 iDbEncoding(TSqlSrvConfigParams::EEncNotSet), |
|
27 iSoftHeapLimitKb(TSqlSrvConfigParams::KConfigPrmValueNotSet), |
|
28 iCompactionMode(ESqlCompactionNotSet), |
|
29 iFreePageThresholdKb(TSqlSrvConfigParams::KConfigPrmValueNotSet) |
|
30 { |
|
31 } |
|
32 |
|
33 /** |
|
34 "Object initialization" method. |
|
35 Opens and reads the SQL server configuration file (if it exists). |
|
36 Initializes TSqlSrvConfig data members using the data from the config file. |
|
37 If the configuration file does not exist, TSqlSrvConfig data members stay unchanged, |
|
38 except: |
|
39 - the soft heap limit, which default value is TSqlSrvConfigParams::KDefaultSoftHeapLimit; |
|
40 - the free pages threshold, which default value is KSqlCompactFreePageThreshold; |
|
41 |
|
42 @param aFs File session |
|
43 @param aFileName Config file name |
|
44 @leave KErrEof No valid config string found in the configuration file; |
|
45 Note that the function may also leave with some other system-wide error codes. |
|
46 */ |
|
47 void TSqlSrvConfig::InitL(RFs& aFs, const TDesC& aFileName) |
|
48 { |
|
49 if(::FileExists(aFs, aFileName)) |
|
50 { |
|
51 TBuf8<KSqlSrvMaxConfigStrLen> configFileStr; |
|
52 //Step 1: get the config string from the config file and store the string in configFileStr |
|
53 TSqlSrvConfig::GetConfigStringFromFileL(aFs, aFileName, configFileStr); |
|
54 //Step 2: extract config file parameters from the string (configFileStr) and store them in iConfigFileParams |
|
55 TSqlSrvConfig::ExtractConfigParamsFromStringL(configFileStr, iConfigFileParams); |
|
56 } |
|
57 //If the soft heap limit is not set from the file or the file does not exist - then set the soft heap limit with the default value |
|
58 if(iConfigFileParams.iSoftHeapLimitKb == TSqlSrvConfigParams::KConfigPrmValueNotSet) |
|
59 { |
|
60 iConfigFileParams.iSoftHeapLimitKb = TSqlSrvConfigParams::KDefaultSoftHeapLimitKb; |
|
61 } |
|
62 //If the free page threshold is not set from the file or the file does not exist - then set the free page threshold with the default value |
|
63 if(iConfigFileParams.iFreePageThresholdKb == TSqlSrvConfigParams::KConfigPrmValueNotSet) |
|
64 { |
|
65 iConfigFileParams.iFreePageThresholdKb = KSqlCompactFreePageThresholdKb; |
|
66 } |
|
67 } |
|
68 |
|
69 /** |
|
70 Parses the config string parameter (aConfigStr), extracts configuration parameters values and |
|
71 and initialises with them aConfigParams data members. |
|
72 The config string format is: "PARAM1=VALUE1;PARAM2=VALUE2;..." |
|
73 If there is unknown parameter "name=value" pair in the config string, it will be skipped - not reported as an error. |
|
74 In a case of a leave, the old content of aConfigStr is preserved. |
|
75 The rules for TSqlSrvConfigParams data members initialization are described in TSqlSrvConfig class' comments. |
|
76 |
|
77 @see TSqlSrvConfig |
|
78 @param aConfigStr the config descriptor |
|
79 @param aConfigParams Output argument, config parameters will be stored there. |
|
80 @leave KErrArgument if the config is not good or the config string contains "soft heap limit" parameter/value pair. |
|
81 @leave KErrArgument if the config is not good or the config string contains "free page threshold" parameter/value pair. |
|
82 */ |
|
83 void TSqlSrvConfig::GetConfigParamsL(const TDesC8& aConfigStr, TSqlSrvConfigParams& aConfigParams) const |
|
84 { |
|
85 TSqlSrvConfigParams tmpConfigParams; |
|
86 //Step 1: extract configuration parameters from aConfigStr, store them in tmpConfigParams. |
|
87 TSqlSrvConfig::ExtractConfigParamsFromStringL(aConfigStr, tmpConfigParams); |
|
88 if(tmpConfigParams.iSoftHeapLimitKb != TSqlSrvConfigParams::KConfigPrmValueNotSet || |
|
89 tmpConfigParams.iFreePageThresholdKb != TSqlSrvConfigParams::KConfigPrmValueNotSet) |
|
90 {//It is not allowed the soft heap limit to be set from a config string, only from the SQL server config file. |
|
91 //It is not allowed the free page threshold to be set from a config string, only from the SQL server config file. |
|
92 __SQLLEAVE(KErrArgument); |
|
93 } |
|
94 //Step 2: store tmpConfigParams in aConfigParams. |
|
95 aConfigParams = tmpConfigParams; |
|
96 //Step 3: replace each "not set" parameter in aConfigParams with the related parameter value from iConfigFileParams (the config file). |
|
97 if(aConfigParams.iPageSize == TSqlSrvConfigParams::KConfigPrmValueNotSet) |
|
98 { |
|
99 aConfigParams.iPageSize = iConfigFileParams.iPageSize; |
|
100 } |
|
101 if(aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncNotSet) |
|
102 { |
|
103 aConfigParams.iDbEncoding = iConfigFileParams.iDbEncoding; |
|
104 } |
|
105 if(aConfigParams.iCompactionMode == ESqlCompactionNotSet) |
|
106 { |
|
107 aConfigParams.iCompactionMode = iConfigFileParams.iCompactionMode; |
|
108 } |
|
109 //Step 4: set the soft heap limit. |
|
110 aConfigParams.iSoftHeapLimitKb = iConfigFileParams.iSoftHeapLimitKb; |
|
111 //Step 5: set the free page threshold. |
|
112 aConfigParams.iFreePageThresholdKb = iConfigFileParams.iFreePageThresholdKb; |
|
113 //Step 6: assert the parameter values. |
|
114 __SQLASSERT(aConfigParams.iPageSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iPageSize >= 0, ESqlPanicInternalError); |
|
115 __SQLASSERT(aConfigParams.iCacheSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iCacheSize >= 0, ESqlPanicInternalError); |
|
116 __SQLASSERT(aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncNotSet || |
|
117 aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncUtf8 || |
|
118 aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncUtf16, ESqlPanicInternalError); |
|
119 __SQLASSERT(aConfigParams.iSoftHeapLimitKb == TSqlSrvConfigParams::KConfigPrmValueNotSet || |
|
120 (aConfigParams.iSoftHeapLimitKb >= TSqlSrvConfigParams::KMinSoftHeapLimitKb && |
|
121 aConfigParams.iSoftHeapLimitKb <= TSqlSrvConfigParams::KMaxSoftHeapLimitKb), ESqlPanicInternalError); |
|
122 __SQLASSERT(aConfigParams.iCompactionMode == ESqlCompactionNotSet || aConfigParams.iCompactionMode == ESqlCompactionManual || |
|
123 aConfigParams.iCompactionMode == ESqlCompactionBackground || aConfigParams.iCompactionMode == ESqlCompactionAuto, ESqlPanicInternalError); |
|
124 __SQLASSERT(aConfigParams.iFreePageThresholdKb == TSqlSrvConfigParams::KConfigPrmValueNotSet || |
|
125 aConfigParams.iFreePageThresholdKb >= 0, ESqlPanicInternalError); |
|
126 } |
|
127 |
|
128 //The function opeans the aFileName config file and reads the config string, storring it in aConfigStr argument. |
|
129 //Preconditions: |
|
130 // - The config file does exist; |
|
131 // - It is a file, containing 16-bit strings; |
|
132 // - aConfigStr max size is at least KSqlSrvMaxConfigStrLen bytes; |
|
133 //The function may leave if some of the file I/O operations (open file, read file) fails. |
|
134 void TSqlSrvConfig::GetConfigStringFromFileL(RFs& aFs, const TDesC& aFileName, TDes8& aConfigStr) |
|
135 { |
|
136 __SQLASSERT(aConfigStr.MaxLength() >= KSqlSrvMaxConfigStrLen, ESqlPanicBadArgument); |
|
137 RFile64 cfgFile; |
|
138 CleanupClosePushL(cfgFile); |
|
139 __SQLLEAVE_IF_ERROR(cfgFile.Open(aFs, aFileName, EFileRead)); |
|
140 TFileText cfgFileReader; |
|
141 cfgFileReader.Set(cfgFile); |
|
142 TBuf<KSqlSrvMaxConfigStrLen> buf; |
|
143 TBool cfgLineFound = EFalse; |
|
144 TInt err = KErrNone; |
|
145 //Read the configuration file line by line until get the first "non-comment" line. |
|
146 while((err = cfgFileReader.Read(buf)) == KErrNone) |
|
147 { |
|
148 buf.TrimAll(); |
|
149 if(buf.Length() == 0 || buf.Locate('#') == 0) //'#' means - this line is a comment |
|
150 { |
|
151 continue; |
|
152 } |
|
153 cfgLineFound = ETrue; |
|
154 break; |
|
155 } |
|
156 CleanupStack::PopAndDestroy(&cfgFile); |
|
157 if(err != KErrEof) |
|
158 {//The "read configuration file" operation has failed with "err" (if err != KErrNone) |
|
159 __SQLLEAVE_IF_ERROR(err); |
|
160 } |
|
161 if(!cfgLineFound) |
|
162 {//End of config file reached - no valid configuration line found. |
|
163 __SQLLEAVE(KErrEof); |
|
164 } |
|
165 __SQLASSERT(err == KErrNone || err == KErrEof, ESqlPanicInternalError); |
|
166 aConfigStr.Copy(buf); |
|
167 } |
|
168 |
|
169 //Parses the config string parameter (aConfigStr) and stores the extracted configuration parameter values in the aConfigParams argument. |
|
170 //The config string format is: "PARAM1=VALUE1;PARAM2=VALUE2;..." |
|
171 //If there is unknown parameter name in the config string, it will be skipped - not reported as an error. |
|
172 //The function will leave with KErrArgument in a case of a bad config string (bad parameter values). |
|
173 void TSqlSrvConfig::ExtractConfigParamsFromStringL(const TDesC8& aConfigStr, TSqlSrvConfigParams& aConfigParams) |
|
174 { |
|
175 //Search iteratively the config string for "PARAM=VALUE;" pairs. If such pair is found, extract the parameter name and |
|
176 //parameter value. Adjust the string start ptr to point to the rest of the string. |
|
177 for(TPtrC8 ptr(aConfigStr);ptr.Length()>0;) |
|
178 { |
|
179 TPtrC8 prmName(KNullDesC8); |
|
180 TPtrC8 prmValue(KNullDesC8); |
|
181 if(TSqlSrvConfig::ExtractParamValuePairL(ptr, prmName, prmValue)) |
|
182 { |
|
183 TSqlSrvConfig::ExtractParamValueL(prmName, prmValue, aConfigParams); |
|
184 } |
|
185 } |
|
186 //Assert the extracted parameter values. |
|
187 __SQLASSERT(aConfigParams.iPageSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iPageSize >= 0, ESqlPanicInternalError); |
|
188 __SQLASSERT(aConfigParams.iCacheSize == TSqlSrvConfigParams::KConfigPrmValueNotSet || aConfigParams.iCacheSize >= 0, ESqlPanicInternalError); |
|
189 __SQLASSERT(aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncNotSet || |
|
190 aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncUtf8 || |
|
191 aConfigParams.iDbEncoding == TSqlSrvConfigParams::EEncUtf16, ESqlPanicInternalError); |
|
192 __SQLASSERT(aConfigParams.iSoftHeapLimitKb == TSqlSrvConfigParams::KConfigPrmValueNotSet || |
|
193 (aConfigParams.iSoftHeapLimitKb >= TSqlSrvConfigParams::KMinSoftHeapLimitKb && |
|
194 aConfigParams.iSoftHeapLimitKb <= TSqlSrvConfigParams::KMaxSoftHeapLimitKb), ESqlPanicInternalError); |
|
195 __SQLASSERT(aConfigParams.iCompactionMode == ESqlCompactionNotSet || aConfigParams.iCompactionMode == ESqlCompactionManual || |
|
196 aConfigParams.iCompactionMode == ESqlCompactionBackground || aConfigParams.iCompactionMode == ESqlCompactionAuto, ESqlPanicInternalError); |
|
197 __SQLASSERT(aConfigParams.iFreePageThresholdKb == TSqlSrvConfigParams::KConfigPrmValueNotSet || |
|
198 aConfigParams.iFreePageThresholdKb >= 0, ESqlPanicInternalError); |
|
199 } |
|
200 |
|
201 //The function searches aConfigStr arguments for "PARAM=VALUE;" pair. If such pair is found, then |
|
202 //aParamName is set to point to the parameter name, aParamValue is set to point to the parameter value, |
|
203 //aConfigStr is set to point to the rest of the config string (skipping the just found "param=value;" pair). |
|
204 //The function leaves with KErrArgument in case of a bad config string. |
|
205 //The function returns false if a ";" string is found instead of a "param=value;" pair. |
|
206 //When the function returns true, it means that aParamName and aParamValue arguments are set to point to the |
|
207 //parameter name and parameter value. |
|
208 TBool TSqlSrvConfig::ExtractParamValuePairL(TPtrC8& aConfigStr, TPtrC8& aParamName, TPtrC8& aParamValue) |
|
209 { |
|
210 const TChar KSemiColon(';'); |
|
211 const TChar KAssignment('='); |
|
212 TInt pos = aConfigStr.Locate(KSemiColon); |
|
213 TPtrC8 prmText(KNullDesC8); |
|
214 if(pos < 0) |
|
215 { |
|
216 pos = aConfigStr.Length() - 1; |
|
217 prmText.Set(TSqlSrvConfig::TrimAndConstructPtr(aConfigStr.Ptr(), aConfigStr.Length())); |
|
218 } |
|
219 else |
|
220 { |
|
221 prmText.Set(TSqlSrvConfig::TrimAndConstructPtr(aConfigStr.Ptr(), pos)); |
|
222 } |
|
223 //Set aConfigStr to the "point" right after the last found ';' |
|
224 if(pos == aConfigStr.Length() - 1) |
|
225 { |
|
226 aConfigStr.Set(NULL, 0); |
|
227 } |
|
228 else |
|
229 { |
|
230 aConfigStr.Set(aConfigStr.Ptr() + pos + 1, aConfigStr.Length() - (pos + 1)); |
|
231 } |
|
232 if(prmText.Length() == 0) |
|
233 {//Empty ";" |
|
234 return EFalse; |
|
235 } |
|
236 //Find the parameter name and parameter value |
|
237 pos = prmText.Locate(KAssignment); |
|
238 if(pos < 0 || pos >= (prmText.Length() - 1)) |
|
239 { |
|
240 __SQLLEAVE(KErrArgument); |
|
241 } |
|
242 //we've got now prmText pointing to a " PARAM = VALUE " string. |
|
243 aParamName.Set(TSqlSrvConfig::TrimAndConstructPtr(prmText.Ptr(), pos)); |
|
244 aParamValue.Set(TSqlSrvConfig::TrimAndConstructPtr(prmText.Ptr() + pos + 1, prmText.Length() - (pos + 1))); |
|
245 return ETrue; |
|
246 } |
|
247 |
|
248 //The function compares aParamName argument against a set of predefined parameter names and if one of them is matched, |
|
249 //then the function converts aParamValue argument to a numerical value and assigns it to the corresponding aConfigParams data member. |
|
250 //The function may leave with KErrArgument, if the parameter value is invalid. |
|
251 void TSqlSrvConfig::ExtractParamValueL(const TDesC8& aParamName, const TDesC8& aParamValue, TSqlSrvConfigParams& aConfigParams) |
|
252 { |
|
253 if(aParamName.CompareF(KCacheSize) == 0) |
|
254 { |
|
255 aConfigParams.iCacheSize = TSqlSrvConfig::GetCacheSizeL(aParamValue); |
|
256 } |
|
257 else if(aParamName.CompareF(KPageSize) == 0) |
|
258 { |
|
259 aConfigParams.iPageSize = TSqlSrvConfig::GetPageSizeL(aParamValue); |
|
260 } |
|
261 else if(aParamName.CompareF(KEncoding) == 0) |
|
262 { |
|
263 aConfigParams.iDbEncoding = TSqlSrvConfig::GetEncoding(aParamValue); |
|
264 } |
|
265 else if(aParamName.CompareF(KSoftHeapLimitKb) == 0) |
|
266 { |
|
267 aConfigParams.iSoftHeapLimitKb = TSqlSrvConfig::GetSoftHeapLimitL(aParamValue); |
|
268 } |
|
269 else if(aParamName.CompareF(KCompactionMode) == 0) |
|
270 { |
|
271 aConfigParams.iCompactionMode = TSqlSrvConfig::GetCompactionModeL(aParamValue); |
|
272 } |
|
273 else if(aParamName.CompareF(KFreePageThresholdKb) == 0) |
|
274 { |
|
275 aConfigParams.iFreePageThresholdKb = TSqlSrvConfig::GetFreePageThresholdL(aParamValue); |
|
276 } |
|
277 //else |
|
278 // { |
|
279 // Unrecognized parameter/value pair - no problem, skip it. |
|
280 // } |
|
281 } |
|
282 |
|
283 //The function converts aParamValue to a numerical value (the cache size in pages) and returns it. |
|
284 //If the converted numerical value is less than 0, the function leaves with KErrArgument. |
|
285 TInt TSqlSrvConfig::GetCacheSizeL(const TDesC8& aParamValue) |
|
286 { |
|
287 TLex8 lex(aParamValue); |
|
288 TInt cacheSize = TSqlSrvConfigParams::KConfigPrmValueNotSet; |
|
289 TInt err = lex.Val(cacheSize); |
|
290 if(err != KErrNone || cacheSize < 0) //The correct check is for "<=0", but it has to be backward |
|
291 { //compatible with the previous implementation |
|
292 __SQLLEAVE(KErrArgument); |
|
293 } |
|
294 return cacheSize; |
|
295 } |
|
296 |
|
297 //The function converts aParamValue to a numerical value (the page size in bytes) and returns it. |
|
298 //If the converted numerical value is less than 0, the function leaves with KErrArgument. |
|
299 TInt TSqlSrvConfig::GetPageSizeL(const TDesC8& aParamValue) |
|
300 { |
|
301 TLex8 lex(aParamValue); |
|
302 TInt pageSize = TSqlSrvConfigParams::KConfigPrmValueNotSet; |
|
303 TInt err = lex.Val(pageSize); |
|
304 if(err != KErrNone || pageSize < 0) //The correct check is for "<0", "power of 2", "between 512 and 32768", |
|
305 { //but it has to be backward compatible with the previous implementation |
|
306 __SQLLEAVE(KErrArgument); |
|
307 } |
|
308 return pageSize; |
|
309 } |
|
310 |
|
311 //The function converts aParamValue to a numerical value (the database encoding) and returns it. |
|
312 TSqlSrvConfigParams::TDbEncoding TSqlSrvConfig::GetEncoding(const TDesC8& aParamValue) |
|
313 { |
|
314 TSqlSrvConfigParams::TDbEncoding encoding = TSqlSrvConfigParams::EEncNotSet; |
|
315 if(aParamValue.CompareF(KUTF8) == 0 || aParamValue.CompareF(KUTF8Q) == 0) |
|
316 { |
|
317 encoding = TSqlSrvConfigParams::EEncUtf8; |
|
318 } |
|
319 else if(aParamValue.CompareF(KUTF16) == 0 || aParamValue.CompareF(KUTF16Q) == 0) |
|
320 { |
|
321 encoding = TSqlSrvConfigParams::EEncUtf16; |
|
322 } |
|
323 //else |
|
324 // { |
|
325 // Invalid encoding - bypass it in order to be compatible with the previous implementation |
|
326 // } |
|
327 return encoding; |
|
328 } |
|
329 |
|
330 //The function converts aParamValue to a numerical value (the soft heap limit in Kb) and returns it. |
|
331 TInt TSqlSrvConfig::GetSoftHeapLimitL(const TDesC8& aParamValue) |
|
332 { |
|
333 TLex8 lex(aParamValue); |
|
334 TInt softHeapLimitKb = TSqlSrvConfigParams::KConfigPrmValueNotSet; |
|
335 TInt err = lex.Val(softHeapLimitKb); |
|
336 if(err != KErrNone || softHeapLimitKb < 0 || |
|
337 (softHeapLimitKb < TSqlSrvConfigParams::KMinSoftHeapLimitKb || softHeapLimitKb > TSqlSrvConfigParams::KMaxSoftHeapLimitKb)) |
|
338 { |
|
339 __SQLLEAVE(KErrArgument); |
|
340 } |
|
341 return softHeapLimitKb; |
|
342 } |
|
343 |
|
344 //The function converts aParamValue to a numerical value (the database compaction mode) and returns it. |
|
345 TSqlCompactionMode TSqlSrvConfig::GetCompactionModeL(const TDesC8& aParamValue) |
|
346 { |
|
347 TSqlCompactionMode compactionMode = ESqlCompactionNotSet; |
|
348 if(aParamValue.CompareF(KManual) == 0) |
|
349 { |
|
350 compactionMode = ESqlCompactionManual; |
|
351 } |
|
352 else if(aParamValue.CompareF(KBackground) == 0) |
|
353 { |
|
354 compactionMode = ESqlCompactionBackground; |
|
355 } |
|
356 else if(aParamValue.CompareF(KAuto) == 0 || aParamValue.CompareF(KSynchronous) == 0) |
|
357 { |
|
358 compactionMode = ESqlCompactionAuto; |
|
359 } |
|
360 //else |
|
361 // { |
|
362 // Invalid compaction mode |
|
363 // } |
|
364 return compactionMode; |
|
365 } |
|
366 |
|
367 //The function converts aParamValue to a numerical value (the free page threshold in pages) and returns it. |
|
368 TInt TSqlSrvConfig::GetFreePageThresholdL(const TDesC8& aParamValue) |
|
369 { |
|
370 TLex8 lex(aParamValue); |
|
371 TInt freePageThreshold = 0; |
|
372 TInt err = lex.Val(freePageThreshold); |
|
373 if(err != KErrNone || freePageThreshold < 0) |
|
374 { |
|
375 __SQLLEAVE(KErrArgument); |
|
376 } |
|
377 return freePageThreshold; |
|
378 } |
|
379 |
|
380 |
|
381 //The function searches aStr for leading and trailing whitespace |
|
382 //characters, then creates and returns TPtrC object which points to the |
|
383 //aStr content without leading and trailing whitespace characters. |
|
384 TPtrC8 TSqlSrvConfig::TrimAndConstructPtr(const TUint8* aStr, TInt aLength) |
|
385 { |
|
386 __SQLASSERT(aStr != NULL, ESqlPanicBadArgument); |
|
387 __SQLASSERT(aLength >= 0, ESqlPanicBadArgument); |
|
388 //Trim left |
|
389 for(;aLength>0;--aLength,++aStr) |
|
390 { |
|
391 if(!TChar(*aStr).IsSpace()) |
|
392 { |
|
393 break; |
|
394 } |
|
395 } |
|
396 //Trim right |
|
397 for(const TUint8* p=aStr+aLength-1;aLength>0;--aLength,--p) |
|
398 { |
|
399 if(!TChar(*p).IsSpace()) |
|
400 { |
|
401 break; |
|
402 } |
|
403 } |
|
404 return TPtrC8(aStr, aLength); |
|
405 } |
|
406 |
|
407 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
408 |
|
409 CDbConfigFiles* CDbConfigFiles::NewL(const CDir& aDirEntries) |
|
410 { |
|
411 CDbConfigFiles* self = new(ELeave) CDbConfigFiles(); |
|
412 CleanupStack::PushL(self); |
|
413 self->ConstructL(aDirEntries); |
|
414 CleanupStack::Pop(); |
|
415 return self; |
|
416 } |
|
417 |
|
418 CDbConfigFiles::CDbConfigFiles() |
|
419 { |
|
420 } |
|
421 |
|
422 void CDbConfigFiles::ConstructL(const CDir& aDirEntries) |
|
423 { |
|
424 StoreFileNamesL(aDirEntries); |
|
425 } |
|
426 |
|
427 CDbConfigFiles::~CDbConfigFiles() |
|
428 { |
|
429 iConfigFileNames.ResetAndDestroy(); |
|
430 } |
|
431 |
|
432 //Stores the names of the given database configuration files. |
|
433 //These files were found in the server's private data cage on |
|
434 //the Z: drive and begin with the prefix 'cfg' |
|
435 void CDbConfigFiles::StoreFileNamesL(const CDir& aDirEntries) |
|
436 { |
|
437 //Store the file names in reverse alphabetical order so that |
|
438 //in FindConfigFile() if there is more than one version of the same |
|
439 //config file (which there shouldn't be) then the highest version |
|
440 //will be returned |
|
441 for(TInt i = aDirEntries.Count() - 1; i >= 0; --i) |
|
442 { |
|
443 const TEntry& entry = aDirEntries[i]; |
|
444 if(!entry.IsDir()) |
|
445 { |
|
446 HBufC* filename = entry.iName.AllocLC(); |
|
447 iConfigFileNames.AppendL(filename); |
|
448 CleanupStack::Pop(); // filename |
|
449 } |
|
450 } |
|
451 } |
|
452 |
|
453 //Finds the configuration file corresponding to the given database, if one exists. |
|
454 //The database filename including the extension is passed as a parameter - for example, |
|
455 //[12345678]a.db. Note that if more than one version of a configuration file exists |
|
456 //for the given database (which shouldn't happen) - for example, cfg[12345678]a.db.01 |
|
457 //and cfg[12345678]a.db.02 - then the highest version will be returned |
|
458 HBufC* CDbConfigFiles::FindConfigFile(const TDesC& aDbFilename) const |
|
459 { |
|
460 TInt count = iConfigFileNames.Count(); |
|
461 for(TInt i = 0; i < count; ++i) |
|
462 { |
|
463 TInt offset = iConfigFileNames[i]->Des().FindF(aDbFilename); |
|
464 if(KErrNotFound != offset) |
|
465 { |
|
466 return iConfigFileNames[i]; |
|
467 } |
|
468 } |
|
469 return NULL; |
|
470 } |