|
1 /* |
|
2 * Copyright (c) 2005 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: Implementation of the class CProcessorCSD |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <wlancontainer.h> |
|
23 #include <cmmanagertablefields.h> |
|
24 #include <datamobilitycommsdattypes.h> |
|
25 #include <f32file.h> |
|
26 #include <featmgr.h> |
|
27 |
|
28 #include "cdcdumptables.h" |
|
29 #include "cdclogger.h" |
|
30 |
|
31 // DEFINES |
|
32 |
|
33 #define QUERY_HBUFC_FIELD( record, fieldId ) *STATIC_CAST(CommsDat::CMDBField<HBufC*>*, record->GetFieldByIdL( fieldId )) |
|
34 #define QUERY_HBUFC8_FIELD( record, fieldId ) *STATIC_CAST(CommsDat::CMDBField<HBufC8*>*, record->GetFieldByIdL( fieldId )) |
|
35 #define QUERY_UINT32_FIELD( record, fieldId ) *STATIC_CAST(CommsDat::CMDBField<TUint32>*, record->GetFieldByIdL( fieldId )) |
|
36 #define QUERY_INT_FIELD( record, fieldId ) *STATIC_CAST(CommsDat::CMDBField<TInt>*, record->GetFieldByIdL( fieldId )) |
|
37 |
|
38 |
|
39 // CONSTANTS |
|
40 |
|
41 // commons for CSV file creatin |
|
42 _LIT16( KComma, "," ); |
|
43 _LIT16( KNewLine, "\n" ); |
|
44 _LIT16( KCRT, "\r" ); |
|
45 _LIT16( KDQuote, "\"" ); |
|
46 |
|
47 // Table names for CSV file creation |
|
48 _LIT16( KCDWlanServiceRecord, "CCDWlanService" ); |
|
49 _LIT16( KCDWlanDeviceSettingsRecord, "CCDWlanDeviceSettings" ); |
|
50 _LIT16( KCDWLANSecSSIDTable, "CCDWLANSecSSIDTable" ); |
|
51 _LIT16( KCDDestNWTable, "CCDDestNWTable" ); |
|
52 _LIT16( KCDVirtualIAPNextLayerRecord,"CCDVirtualIAPNextLayer" ); |
|
53 _LIT16( KCDDataMobilitySelectionPolicyRecord, "CCDDataMobilitySelectionPolicy" ); |
|
54 _LIT16( KCDSNAPMetadataRecord, "CCDSNAPMetadata" ); |
|
55 _LIT16( KCDGlobalBearerTypePriorizationRecord, "CCDGlobalBearerTypePriorization" ); |
|
56 _LIT16( KCDMIPServiceExtRecord, "CCDMIPServiceExt" ); |
|
57 _LIT16( KCDIAPMetadataRecord, "CCDIAPMetadata" ); |
|
58 _LIT16( KCDMIP4Record, "CCDMIP4" ); |
|
59 _LIT16( KCDMIP6Record, "CCDMIP6" ); |
|
60 |
|
61 |
|
62 // Little-endian Unicode file header. |
|
63 const TUint16 KLittleEndianUnicodeHeader = 0xFEFF; |
|
64 // Buffer length for number conversion |
|
65 const TInt KFormatBufLen = 40; |
|
66 |
|
67 |
|
68 // --------------------------------------------------------- |
|
69 // CDumpTables::NewL |
|
70 // --------------------------------------------------------- |
|
71 // |
|
72 CDumpTables* CDumpTables::NewL() |
|
73 { |
|
74 CDumpTables* self = NewLC(); |
|
75 CleanupStack::Pop( self ); // self |
|
76 return self; |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------- |
|
80 // CDumpTables::NewLC |
|
81 // --------------------------------------------------------- |
|
82 // |
|
83 CDumpTables* CDumpTables::NewLC() |
|
84 { |
|
85 CDumpTables* self = new ( ELeave ) CDumpTables(); |
|
86 CleanupStack::PushL( self ); |
|
87 |
|
88 // From base class |
|
89 self->ConstructL(); |
|
90 return self; |
|
91 } |
|
92 |
|
93 |
|
94 // --------------------------------------------------------- |
|
95 // CDumpTables::~CDumpTables |
|
96 // --------------------------------------------------------- |
|
97 // |
|
98 CDumpTables::~CDumpTables() |
|
99 { |
|
100 iRfs.Close(); |
|
101 if (iSession) |
|
102 { |
|
103 iSession->Close(); |
|
104 delete iSession; |
|
105 } |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------- |
|
109 // CDumpTables::ConstructL |
|
110 // --------------------------------------------------------- |
|
111 // |
|
112 void CDumpTables::ConstructL() |
|
113 { |
|
114 iSession = CommsDat::CMDBSession::NewL( |
|
115 CommsDat::CMDBSession::LatestVersion() ); |
|
116 } |
|
117 |
|
118 |
|
119 // --------------------------------------------------------- |
|
120 // CDumpTables::CDumpTables |
|
121 // --------------------------------------------------------- |
|
122 // |
|
123 CDumpTables::CDumpTables() |
|
124 { |
|
125 |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------- |
|
129 // CDumpTables::DoDumpTablesL |
|
130 // --------------------------------------------------------- |
|
131 // |
|
132 void CDumpTables::DoDumpTablesL( const TFileName& aOutFileName ) |
|
133 { |
|
134 |
|
135 User::LeaveIfError( OpenFileL( aOutFileName ) ); |
|
136 |
|
137 |
|
138 //checks if Wlan feature is supported |
|
139 FeatureManager::InitializeLibL(); |
|
140 TBool isWlanS( FeatureManager::FeatureSupported( KFeatureIdProtocolWlan ) ); |
|
141 FeatureManager::UnInitializeLib(); |
|
142 |
|
143 if( isWlanS ) |
|
144 { |
|
145 // Dumps CCDWlanService Table |
|
146 DumpTableL<CCDWlanServiceRecord>( &KCDWlanServiceRecord ); |
|
147 |
|
148 // Dumps CCDWlanDeviceSettings Table |
|
149 DumpTableL<CCDWlanDeviceSettingsRecord>( &KCDWlanDeviceSettingsRecord ); |
|
150 |
|
151 // Dumps CCDWLANSecSSID Table |
|
152 DumpTableL<CCDWLANSecSSIDTable>( &KCDWLANSecSSIDTable ); |
|
153 |
|
154 // Dumps CCDDestNWTable Table |
|
155 DumpTableL<CCDDestNWTable>( &KCDDestNWTable ); |
|
156 } |
|
157 |
|
158 // Dumps CCDVirtualIAPNextLayerRecord Table |
|
159 DumpTableL<CCDVirtualIAPNextLayerRecord>( |
|
160 &KCDVirtualIAPNextLayerRecord ); |
|
161 |
|
162 // Dumps CCDDataMobilitySelectionPolicyRecord Table |
|
163 DumpTableL<CCDDataMobilitySelectionPolicyRecord>( |
|
164 &KCDDataMobilitySelectionPolicyRecord ); |
|
165 |
|
166 // Dumps CCDSNAPMetadataRecord Table |
|
167 DumpTableL<CCDSNAPMetadataRecord>( &KCDSNAPMetadataRecord ); |
|
168 |
|
169 // Dumps CCDGlobalBearerTypePriorizationRecord Table |
|
170 DumpTableL<CCDGlobalBearerTypePriorizationRecord>( |
|
171 &KCDGlobalBearerTypePriorizationRecord ); |
|
172 |
|
173 // Dumps CCDMIPServiceExtRecord Table |
|
174 DumpTableL<CCDMIPServiceExtRecord>( &KCDMIPServiceExtRecord ); |
|
175 |
|
176 // Dumps CCDIAPMetadataRecord Table |
|
177 DumpTableL<CCDIAPMetadataRecord>( &KCDIAPMetadataRecord ); |
|
178 |
|
179 // Dumps CCDMIP4Record Table |
|
180 DumpTableL<CCDMIP4Record>( &KCDMIP4Record ); |
|
181 |
|
182 // Dumps CCDMIP6Record Table |
|
183 DumpTableL<CCDMIP6Record>( &KCDMIP6Record ); |
|
184 |
|
185 iFile.Close(); |
|
186 } |
|
187 |
|
188 |
|
189 // --------------------------------------------------------- |
|
190 // CDumpTables::DumpTableL |
|
191 // --------------------------------------------------------- |
|
192 // |
|
193 template<class T> void CDumpTables::DumpTableL( const TDesC* aTableName ) |
|
194 { |
|
195 |
|
196 CLOG_WRITE_FORMAT( "Dump table: %S \n", aTableName ); |
|
197 |
|
198 iFile.WriteL( *aTableName ); |
|
199 iFile.WriteL( KNewLine ); |
|
200 |
|
201 // Retreives the table the recordset and the recordinfo |
|
202 TMDBElementId tableId = T::TableIdL( *iSession ); |
|
203 |
|
204 T* table = new (ELeave) T( tableId ); |
|
205 |
|
206 const SRecordTypeInfo* aRecordInfo = table->GetRecordInfo(); |
|
207 |
|
208 CommsDat::CMDBRecordSet<T>* aRecordSet = |
|
209 new (ELeave) CommsDat::CMDBRecordSet<T>( tableId ); |
|
210 |
|
211 // Loads the table |
|
212 TRAP_IGNORE( aRecordSet->LoadL( *iSession ) ); |
|
213 |
|
214 //The table has been loaded |
|
215 TInt count = aRecordSet->iRecords.Count(); |
|
216 CLOG_WRITE_FORMAT("Record count: %d", count ); |
|
217 |
|
218 |
|
219 TBuf16<KFormatBufLen> buf; |
|
220 |
|
221 // Goes throught the records |
|
222 for ( TInt i = 0; i < count; i++ ) |
|
223 { |
|
224 // The closing (after last) field in the record has 0 iTypeId |
|
225 // to indicate the end of the record. |
|
226 for ( TInt j = 0; 0 < aRecordInfo[j].iTypeId; j++ ) |
|
227 { |
|
228 // Switch for different data types |
|
229 switch( aRecordInfo[j].iValType ) |
|
230 { |
|
231 case EInt: |
|
232 case EBool: |
|
233 { |
|
234 // Dumping TInt |
|
235 TInt res( QUERY_INT_FIELD( |
|
236 (*aRecordSet)[i], aRecordInfo[j].iTypeId ) ); |
|
237 buf.Format( _L( "%d" ), res ); |
|
238 iFile.WriteL ( buf ); |
|
239 } |
|
240 break; |
|
241 |
|
242 case EUint32: |
|
243 case ELink: |
|
244 { |
|
245 // Dumping TUint32 |
|
246 TUint32 res32( QUERY_UINT32_FIELD( |
|
247 (*aRecordSet)[i], aRecordInfo[j].iTypeId ) ); |
|
248 buf.Format( _L( "%d" ), res32 ); |
|
249 iFile.WriteL ( buf ); |
|
250 } |
|
251 break; |
|
252 |
|
253 case EText: |
|
254 case EMedText: |
|
255 case ELongText: |
|
256 { |
|
257 // Dumping text16 |
|
258 HBufC16* text16 = QUERY_HBUFC_FIELD( |
|
259 (*aRecordSet)[i], aRecordInfo[j].iTypeId ); |
|
260 WriteL ( text16 ); |
|
261 } |
|
262 break; |
|
263 |
|
264 case EDesC8: |
|
265 { |
|
266 // Dumping text8 |
|
267 HBufC8* text8 = QUERY_HBUFC8_FIELD( |
|
268 (*aRecordSet)[i], aRecordInfo[j].iTypeId ); |
|
269 |
|
270 WriteL ( text8 ); |
|
271 } |
|
272 break; |
|
273 |
|
274 default: |
|
275 CLOG_WRITE_FORMAT("! warning: type not supported: %d", |
|
276 aRecordInfo[j].iValType ); |
|
277 break; |
|
278 } |
|
279 iFile.WriteL( KComma ); |
|
280 |
|
281 } |
|
282 iFile.WriteL( KNewLine ); |
|
283 } |
|
284 } |
|
285 |
|
286 // --------------------------------------------------------- |
|
287 // CDumpTables::OpenFileL |
|
288 // --------------------------------------------------------- |
|
289 // |
|
290 TInt CDumpTables::OpenFileL( const TFileName& aFileName ) |
|
291 { |
|
292 ////CLOG_WRITE_FORMAT( "Output file name %S", aFileName ); |
|
293 |
|
294 TInt err = iRfs.Connect(); |
|
295 |
|
296 if( err == KErrNone ) |
|
297 { |
|
298 err = iFile.Replace( iRfs, aFileName, EFileStreamText | EFileWrite ); |
|
299 } |
|
300 |
|
301 if( err == KErrNotFound ) |
|
302 // file does not exist - create it |
|
303 { |
|
304 err=iFile.Create( iRfs, aFileName, EFileStreamText | EFileWrite ); |
|
305 } |
|
306 |
|
307 if( err == KErrNone ) |
|
308 { |
|
309 // Write little-endian Unicode file header. |
|
310 iFile.WriteUint16L( KLittleEndianUnicodeHeader ); |
|
311 } |
|
312 |
|
313 if( err != KErrNone ) |
|
314 { |
|
315 iFile.Close(); |
|
316 ////CLOG_WRITE_FORMAT( "!Error Output file cannot be opened: %S", aFileName ); |
|
317 } |
|
318 |
|
319 return err; |
|
320 } |
|
321 |
|
322 |
|
323 // --------------------------------------------------------- |
|
324 // CDumpTables::WriteL |
|
325 // --------------------------------------------------------- |
|
326 // |
|
327 void CDumpTables::WriteL( HBufC8* aDes ) |
|
328 { |
|
329 |
|
330 if( aDes ) |
|
331 { |
|
332 |
|
333 CleanupStack::PushL( aDes ); |
|
334 |
|
335 HBufC16* text16 = HBufC16::NewL( aDes->Length() ); |
|
336 text16->Des().Copy( aDes->Des() ); |
|
337 |
|
338 WriteL ( text16 ); |
|
339 |
|
340 CleanupStack::PopAndDestroy( aDes ); |
|
341 } |
|
342 |
|
343 } |
|
344 |
|
345 |
|
346 // --------------------------------------------------------- |
|
347 // CDumpTables::WriteL |
|
348 // --------------------------------------------------------- |
|
349 // |
|
350 void CDumpTables::WriteL( HBufC16* aDes ) |
|
351 { |
|
352 |
|
353 if( aDes ) |
|
354 { |
|
355 CleanupStack::PushL( aDes ); |
|
356 |
|
357 TBool res = CheckCSVTransformNeedL( aDes ); |
|
358 |
|
359 // Need conversion |
|
360 if( res ) |
|
361 { |
|
362 HBufC16* cvsFormat = TransformToCSVFormatLC( aDes ); |
|
363 iFile.WriteL ( *cvsFormat ); |
|
364 CleanupStack::PopAndDestroy( cvsFormat ); |
|
365 } |
|
366 else |
|
367 { |
|
368 iFile.WriteL ( *aDes ); |
|
369 } |
|
370 CleanupStack::PopAndDestroy( aDes ); |
|
371 } |
|
372 } |
|
373 |
|
374 |
|
375 // --------------------------------------------------------- |
|
376 // CDumpTables::TransformToCSVFormatLC |
|
377 // --------------------------------------------------------- |
|
378 // |
|
379 HBufC16* CDumpTables::TransformToCSVFormatLC( const HBufC16* aField ) |
|
380 { |
|
381 CLOG_WRITE_FORMAT( "Transform needed: %S", aField ); |
|
382 |
|
383 // Length of the csv format string is calculated. |
|
384 // "2" are the leading and trailing d.qquotes |
|
385 TInt csvLen = aField->Length() + iNumOfDQuotes + 2; |
|
386 HBufC16* csv = HBufC16::NewLC( csvLen ); |
|
387 |
|
388 TPtr16 ptr = csv->Des(); |
|
389 |
|
390 // Heading quote |
|
391 ptr.Append( KDQuote ); |
|
392 ptr.Append( *aField ); |
|
393 |
|
394 // Quotes might be duplicated |
|
395 if( 0 < iNumOfDQuotes ) |
|
396 { |
|
397 // Heading quote step over |
|
398 TInt pos = 1; |
|
399 while( pos < ptr.Length() && pos != KErrNotFound ) |
|
400 { |
|
401 ptr = ptr.Mid( pos ); |
|
402 pos = ptr.Find( KDQuote ); |
|
403 if( pos != KErrNotFound ) |
|
404 { |
|
405 ptr.Insert( pos, KDQuote ); |
|
406 pos+=2; |
|
407 } |
|
408 } |
|
409 } |
|
410 |
|
411 // Tailing quote |
|
412 ptr.Append( KDQuote ); |
|
413 |
|
414 CLOG_WRITE_FORMAT( "Transformed: %S", csv ); |
|
415 |
|
416 return csv; |
|
417 } |
|
418 |
|
419 |
|
420 // --------------------------------------------------------- |
|
421 // CDumpTables::CheckCSVTransformNeedL |
|
422 // --------------------------------------------------------- |
|
423 // |
|
424 TBool CDumpTables::CheckCSVTransformNeedL( HBufC16* aField ) |
|
425 { |
|
426 // Looks for comma, new line or carrige return characters. |
|
427 // Only existance is necessary. If any of them exist the |
|
428 // quoting is necessary |
|
429 TInt cnrPos = aField->Find( KComma ); |
|
430 if( cnrPos == KErrNotFound ) |
|
431 { |
|
432 cnrPos = aField->Find( KNewLine ); |
|
433 if( cnrPos == KErrNotFound ) |
|
434 { |
|
435 cnrPos = aField->Find( KCRT ); |
|
436 } |
|
437 } |
|
438 |
|
439 // Serches for all dquote. Number is usefull for csv text creation |
|
440 iNumOfDQuotes = 0; |
|
441 TPtr16 ptr = aField->Des(); |
|
442 |
|
443 TInt quotePos = ptr.Find( KDQuote ); |
|
444 while( quotePos != KErrNotFound ) |
|
445 { |
|
446 iNumOfDQuotes++; |
|
447 ptr = ptr.Mid( quotePos+1 ); |
|
448 quotePos = ptr.Find( KDQuote ); |
|
449 } |
|
450 |
|
451 // csv file conversion necessary if comma... or quote is in the text. |
|
452 return ( 0 < iNumOfDQuotes || cnrPos != KErrNotFound ); |
|
453 } |