|
1 /* |
|
2 * Copyright (c) 2007 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: Definition of CNcdTestConfig |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdtestconfig.h" |
|
20 #include "ncdpanics.h" |
|
21 #include "catalogsdebug.h" |
|
22 #include "catalogsutils.h" |
|
23 |
|
24 |
|
25 _LIT( KCurrentMnc, "currentmnc" ); |
|
26 _LIT( KCurrentMcc, "currentmcc" ); |
|
27 |
|
28 _LIT( KHomeMnc, "homemnc" ); |
|
29 _LIT( KHomeMcc, "homemcc" ); |
|
30 |
|
31 _LIT( KImsi, "imsi" ); |
|
32 |
|
33 // ======== MEMBER FUNCTIONS ======== |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // Constructor. |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 CNcdTestConfig* CNcdTestConfig::NewL( |
|
40 RFs& aFs, const TDesC& aConfigFile ) |
|
41 { |
|
42 CNcdTestConfig* self = new (ELeave) CNcdTestConfig; |
|
43 CleanupStack::PushL( self ); |
|
44 self->ConstructL( aFs, aConfigFile ); |
|
45 CleanupStack::Pop( self ); |
|
46 return self; |
|
47 } |
|
48 |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // Destructor |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 CNcdTestConfig::~CNcdTestConfig() |
|
55 { |
|
56 DLTRACEIN(("")); |
|
57 |
|
58 iConfigStrings.ResetAndDestroy(); |
|
59 |
|
60 } |
|
61 |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // IsSet |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 TBool CNcdTestConfig::IsSet( TConfigValue aValue ) const |
|
68 { |
|
69 DLTRACEIN(("aValue: %d", aValue)); |
|
70 |
|
71 return GetString( aValue ) != NULL; |
|
72 } |
|
73 |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // Value getter |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 const TDesC& CNcdTestConfig::Value( TConfigValue aValue ) const |
|
80 { |
|
81 DLTRACEIN(("aValue: %d", aValue)); |
|
82 HBufC* value = GetString( aValue ); |
|
83 NCD_ASSERT_ALWAYS( value, ENcdPanicNoData ); |
|
84 DLTRACEOUT(( _L("Value: %S"), value )); |
|
85 return *value; |
|
86 } |
|
87 |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 CNcdTestConfig::CNcdTestConfig() |
|
94 { |
|
95 } |
|
96 |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 void CNcdTestConfig::ConstructL( RFs& aFs, const TDesC& aConfigFile ) |
|
103 { |
|
104 DLTRACEIN(( _L("file: %S"), &aConfigFile )); |
|
105 |
|
106 // Fill the array with null pointers |
|
107 for ( TInt i = 0; i < EConfigInternal; ++i ) |
|
108 { |
|
109 iConfigStrings.AppendL( NULL ); |
|
110 } |
|
111 |
|
112 // Read & parse the configuration file |
|
113 HBufC8* data8 = ReadFileL( aFs, aConfigFile ); |
|
114 |
|
115 CleanupStack::PushL( data8 ); |
|
116 HBufC16* data16 = ConvertUtf8ToUnicodeL( *data8 ); |
|
117 CleanupStack::PopAndDestroy( data8 ); |
|
118 |
|
119 CleanupStack::PushL( data16 ); |
|
120 ParseL( *data16 ); |
|
121 CleanupStack::PopAndDestroy( data16 ); |
|
122 } |
|
123 |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 void CNcdTestConfig::ParseL( const TDesC& aData ) |
|
130 { |
|
131 DLTRACEIN(("")); |
|
132 |
|
133 TLex lex( aData ); |
|
134 lex.Mark(); |
|
135 for ( ;; ) |
|
136 { |
|
137 if ( lex.Eos() || |
|
138 lex.Peek() == 0x0d || |
|
139 lex.Peek() == 0x0a ) |
|
140 { |
|
141 TPtrC data( lex.MarkedToken() ); |
|
142 |
|
143 // basically if-else-if |
|
144 TBool doStuff = ( |
|
145 ParseEntityL( data, KCurrentMnc, EConfigCurrentMnc ) || |
|
146 ParseEntityL( data, KCurrentMcc, EConfigCurrentMcc ) || |
|
147 ParseEntityL( data, KHomeMnc, EConfigHomeMnc ) || |
|
148 ParseEntityL( data, KHomeMcc, EConfigHomeMcc ) || |
|
149 ParseEntityL( data, KImsi, EConfigImsi) ); |
|
150 |
|
151 if ( lex.Eos() ) |
|
152 { |
|
153 break; |
|
154 } |
|
155 else |
|
156 { |
|
157 lex.SkipAndMark( 1 ); |
|
158 } |
|
159 } |
|
160 else |
|
161 { |
|
162 lex.Inc(); |
|
163 } |
|
164 } |
|
165 |
|
166 /* |
|
167 // Check that at least one of the attributes was set |
|
168 if ( !( iCurrentMnc || |
|
169 iCurrentMcc || |
|
170 iHomeMnc || |
|
171 iHomeMcc || |
|
172 iImsi ) ) |
|
173 { |
|
174 DLERROR(("No attribute had been set, leaving with KErrArgument")); |
|
175 User::Leave( KErrArgument ); |
|
176 } |
|
177 */ |
|
178 } |
|
179 |
|
180 |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 TBool CNcdTestConfig::ParseEntityL( |
|
187 const TDesC& aData, const TDesC& aEntityName, TConfigValue aTarget ) |
|
188 { |
|
189 DLTRACEIN(("")); |
|
190 if ( aData.FindF( aEntityName ) == 0 ) |
|
191 { |
|
192 // current mcd |
|
193 TInt offset = aData.LocateF( '=' ); |
|
194 if ( offset != KErrNotFound ) |
|
195 { |
|
196 delete iConfigStrings[aTarget]; |
|
197 |
|
198 iConfigStrings[aTarget] = NULL; |
|
199 |
|
200 // Decode all possible encoded characters |
|
201 iConfigStrings[aTarget] = aData.Mid( offset + 1 ).AllocL(); |
|
202 |
|
203 // Remove trailing white space |
|
204 iConfigStrings[aTarget]->Des().TrimRight(); |
|
205 return ETrue; |
|
206 } |
|
207 else |
|
208 { |
|
209 User::Leave( KErrCorrupt ); |
|
210 } |
|
211 } |
|
212 return EFalse; |
|
213 } |
|
214 |
|
215 |
|
216 // --------------------------------------------------------------------------- |
|
217 // GetValue |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 HBufC* CNcdTestConfig::GetString( TConfigValue aValue ) const |
|
221 { |
|
222 DLTRACEIN(("aValue: %d", aValue)); |
|
223 NCD_ASSERT_ALWAYS( aValue < EConfigInternal, ENcdPanicIndexOutOfRange ); |
|
224 return iConfigStrings[aValue]; |
|
225 } |
|
226 |