|
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 CProcessorDN |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include "cdcprocessordn.h" |
|
24 #include "cdclogger.h" |
|
25 #include "cdctagcontainer.h" |
|
26 |
|
27 using namespace CMManager; |
|
28 |
|
29 // CONSTANTS |
|
30 |
|
31 _LIT16( KDefaultDestinationName, "Default destination" ); |
|
32 //_LIT16( KMetadataUserDefined, "UserDefined" ); |
|
33 //_LIT16( KMetadataInternet, "Internet" ); |
|
34 |
|
35 // constants for TSnapPurpose |
|
36 _LIT16( KPurposeUnknown, "UserDefined" ); |
|
37 _LIT16( KPurposeInternet, "Internet" ); |
|
38 _LIT16( KPurposeOperator, "Operator" ); |
|
39 _LIT16( KPurposeMMS, "MMS" ); |
|
40 _LIT16( KPurposeIntranet, "Intranet" ); |
|
41 |
|
42 |
|
43 // ================= MEMBER FUNCTIONS ======================= |
|
44 |
|
45 // --------------------------------------------------------- |
|
46 // CProcessorDN::NewL |
|
47 // --------------------------------------------------------- |
|
48 // |
|
49 CProcessorDN* CProcessorDN::NewL( CReaderBase* aFileReader, |
|
50 RCmManagerExt& aCmManager, |
|
51 RPointerArray< RCmConnectionMethodExt >& aPluginArray, |
|
52 RPointerArray< HBufC >& aPluginNames, |
|
53 RPointerArray< RCmDestinationExt >& aDestArray, |
|
54 RPointerArray< HBufC >& aDestNames, |
|
55 RArray<TBool>& aCmInDest, |
|
56 TBool aIsFirstRound ) |
|
57 { |
|
58 CProcessorDN* self = new ( ELeave ) CProcessorDN( aFileReader, |
|
59 aCmManager, |
|
60 aPluginArray, |
|
61 aPluginNames, |
|
62 aDestArray, |
|
63 aDestNames, |
|
64 aCmInDest, |
|
65 aIsFirstRound ); |
|
66 CleanupStack::PushL( self ); |
|
67 |
|
68 // From base class |
|
69 self->ConstructL(); |
|
70 CleanupStack::Pop( self ); // self |
|
71 return self; |
|
72 } |
|
73 |
|
74 |
|
75 // --------------------------------------------------------- |
|
76 // CProcessorDN::~CProcessorDN |
|
77 // --------------------------------------------------------- |
|
78 // |
|
79 CProcessorDN::~CProcessorDN() |
|
80 { |
|
81 iDestination.Close(); |
|
82 } |
|
83 |
|
84 |
|
85 // --------------------------------------------------------- |
|
86 // CProcessorDN::ConstructL |
|
87 // --------------------------------------------------------- |
|
88 // |
|
89 void CProcessorDN::ConstructL() |
|
90 { |
|
91 } |
|
92 |
|
93 |
|
94 // --------------------------------------------------------- |
|
95 // CProcessorDN::CProcessorDN |
|
96 // --------------------------------------------------------- |
|
97 // |
|
98 CProcessorDN::CProcessorDN( CReaderBase* aFileReader, |
|
99 RCmManagerExt& aCmManager, |
|
100 RPointerArray< RCmConnectionMethodExt >& aPluginArray, |
|
101 RPointerArray< HBufC >& aPluginNames, |
|
102 RPointerArray< RCmDestinationExt >& aDestArray, |
|
103 RPointerArray< HBufC >& aDestNames, |
|
104 RArray< TBool >& aCmInDest, |
|
105 TBool aIsFirstRound ) : |
|
106 CProcessorBase( aFileReader, |
|
107 aCmManager, |
|
108 aPluginArray, |
|
109 aPluginNames, |
|
110 aDestArray, |
|
111 aDestNames ), |
|
112 iProtectionLevel( EProtLevel0 ), |
|
113 iIsFirstRound( aIsFirstRound ) |
|
114 { |
|
115 iCmInDest = &aCmInDest; |
|
116 } |
|
117 |
|
118 |
|
119 // --------------------------------------------------------- |
|
120 // CProcessorDN::ProcessTagL |
|
121 // --------------------------------------------------------- |
|
122 // |
|
123 void CProcessorDN::ProcessTagL( TBool /*aFieldIDPresent*/ ) |
|
124 { |
|
125 |
|
126 iDestinationDropped = EFalse; |
|
127 |
|
128 iProtectionLevel = EProtLevel0; |
|
129 |
|
130 if( iIsFirstRound ) |
|
131 { |
|
132 TInt dnId = -1; |
|
133 for ( TInt idx(0); idx < TagContainer().Count(); idx++) |
|
134 { |
|
135 if ( TagContainer().FieldId( idx ) == EDN_Id ) |
|
136 { |
|
137 HBufC16* ptrTag = TagContainer().Tag(idx); |
|
138 TLex16 lex(ptrTag->Des()); |
|
139 TInt err = lex.Val(dnId); |
|
140 if (err != KErrNone) |
|
141 { |
|
142 CLOG_WRITE( "The destinaton Id field is bad."); |
|
143 User::Leave(err); |
|
144 } |
|
145 break; |
|
146 } |
|
147 } |
|
148 if (dnId == -1) |
|
149 { |
|
150 iDestination = iCmManager->CreateDestinationL( KDefaultDestinationName ); |
|
151 CLOG_WRITE( "Destinaton created without dnId."); |
|
152 } |
|
153 else |
|
154 { |
|
155 iDestination = iCmManager->CreateDestinationL( KDefaultDestinationName, dnId); |
|
156 CLOG_WRITE_FORMAT( "Destinaton created. dnId:%d", dnId); |
|
157 } |
|
158 } |
|
159 |
|
160 HBufC *destName( NULL ); |
|
161 TInt priority = 0; |
|
162 RPointerArray<HBufC> names; |
|
163 |
|
164 for (TInt idx(0); idx < TagContainer().Count(); idx++) |
|
165 { |
|
166 HBufC16* ptrTag = TagContainer().Tag(idx); |
|
167 TInt field = TagContainer().FieldId( idx ); |
|
168 |
|
169 if( iIsFirstRound && !iDestinationDropped ) |
|
170 { |
|
171 switch ( field ) |
|
172 { |
|
173 case EDN_Name: |
|
174 { |
|
175 // If more destinations exist with same name then one is kept |
|
176 TRAPD( err, iDestination.SetNameL( *ptrTag ) ); |
|
177 if( KErrAlreadyExists == err ) |
|
178 { |
|
179 CLOG_WRITE_FORMAT( |
|
180 "Error: Destination exist: %S. It is dropped!", ptrTag ) |
|
181 CLOG_WRITE( "\t \r\n" ) |
|
182 iDestinationDropped = ETrue; |
|
183 } |
|
184 else |
|
185 { |
|
186 destName = ptrTag->AllocLC(); |
|
187 } |
|
188 } |
|
189 break; |
|
190 case EDN_Icon: |
|
191 { |
|
192 TPtrC16 iconPtr = ptrTag->Right( ptrTag->Length() ); |
|
193 TLex16 lex( iconPtr ); |
|
194 TUint32 icon( 0 ); |
|
195 if ( lex.Val( icon, EDecimal ) == KErrNone ) |
|
196 { |
|
197 iDestination.SetIconL( icon ); |
|
198 } |
|
199 } |
|
200 break; |
|
201 case EDN_Metadata: |
|
202 { |
|
203 if( !ptrTag->Compare( KPurposeUnknown ) ) |
|
204 { |
|
205 iDestination.SetMetadataL( ESnapMetadataPurpose, |
|
206 ESnapPurposeUnknown ); |
|
207 } |
|
208 else if( !ptrTag->Compare( KPurposeInternet ) ) |
|
209 { |
|
210 iDestination.SetMetadataL( |
|
211 ESnapMetadataPurpose, |
|
212 ESnapPurposeInternet ); |
|
213 } |
|
214 else if( !ptrTag->Compare( KPurposeOperator ) ) |
|
215 { |
|
216 iDestination.SetMetadataL( |
|
217 ESnapMetadataPurpose, |
|
218 ESnapPurposeOperator ); |
|
219 } |
|
220 else if( !ptrTag->Compare( KPurposeMMS ) ) |
|
221 { |
|
222 iDestination.SetMetadataL( |
|
223 ESnapMetadataPurpose, |
|
224 ESnapPurposeMMS ); |
|
225 } |
|
226 else if( !ptrTag->Compare( KPurposeIntranet ) ) |
|
227 { |
|
228 iDestination.SetMetadataL( |
|
229 ESnapMetadataPurpose, |
|
230 ESnapPurposeIntranet ); |
|
231 } |
|
232 else |
|
233 { |
|
234 //no valid data is given - use default value |
|
235 iDestination.SetMetadataL( ESnapMetadataPurpose, |
|
236 ESnapPurposeUnknown ); |
|
237 CLOG_WRITE( "! Error : Invalid Metadata. Default:User Defined"); |
|
238 } |
|
239 } |
|
240 break; |
|
241 case EDN_Protection: |
|
242 { |
|
243 TPtrC16 protPtr = ptrTag->Right( ptrTag->Length() ); |
|
244 TLex16 lex( protPtr ); |
|
245 TUint32 prot( 0 ); |
|
246 if ( lex.Val( prot, EDecimal ) == KErrNone ) |
|
247 { |
|
248 if( prot <= EProtLevel3 ) // prot is unsigned so no need |
|
249 // to check lower boundary |
|
250 { |
|
251 iProtectionLevel = TProtectionLevel( prot ); |
|
252 } |
|
253 else |
|
254 { |
|
255 //no valid data is given - use default value |
|
256 iProtectionLevel = EProtLevel0; |
|
257 CLOG_WRITE( "! Error : Invalid Protection level. Default:Level0"); |
|
258 } |
|
259 } |
|
260 } |
|
261 break; |
|
262 case EDN_Hidden: |
|
263 { |
|
264 if( !ptrTag->Compare( KStrYes ) ) |
|
265 { |
|
266 iDestination.SetHiddenL( ETrue ); |
|
267 } |
|
268 else if( !ptrTag->Compare( KStrNo ) ) |
|
269 { |
|
270 iDestination.SetHiddenL( EFalse ); |
|
271 } |
|
272 else |
|
273 { |
|
274 //no valid data is given - use default value |
|
275 iDestination.SetHiddenL( EFalse ); |
|
276 CLOG_WRITE( "! Error : Invalid Hidden. Default:No"); |
|
277 } |
|
278 } |
|
279 break; |
|
280 case EDN_HiddenAgent: |
|
281 { |
|
282 if( !ptrTag->Compare( KStrYes ) ) |
|
283 { |
|
284 iDestination.SetMetadataL( ESnapMetadataHiddenAgent, ETrue ); |
|
285 } |
|
286 else if( !ptrTag->Compare( KStrNo ) ) |
|
287 { |
|
288 iDestination.SetMetadataL( ESnapMetadataHiddenAgent, EFalse ); |
|
289 } |
|
290 else |
|
291 { |
|
292 iDestination.SetMetadataL( ESnapMetadataHiddenAgent, EFalse ); |
|
293 //no valid data is given - use default value |
|
294 CLOG_WRITE( "! Error : Invalid HiddenAgent. Default:No"); |
|
295 } |
|
296 } |
|
297 break; |
|
298 case EDN_Highlighted: |
|
299 { |
|
300 if( !ptrTag->Compare( KStrYes ) ) |
|
301 { |
|
302 iDestination.SetMetadataL( ESnapMetadataHighlight, ETrue ); |
|
303 } |
|
304 else if( !ptrTag->Compare( KStrNo ) ) |
|
305 { |
|
306 iDestination.SetMetadataL( ESnapMetadataHighlight, EFalse ); |
|
307 } |
|
308 else |
|
309 { |
|
310 iDestination.SetMetadataL( ESnapMetadataHighlight, EFalse ); |
|
311 //no valid data is given - use default value |
|
312 CLOG_WRITE( "! Error : Invalid Highlighted. Default:No"); |
|
313 } |
|
314 } |
|
315 break; |
|
316 } // switch |
|
317 } // if |
|
318 else if( !iIsFirstRound && !iDestinationDropped ) |
|
319 { |
|
320 switch ( field ) |
|
321 { |
|
322 case EDN_Name: |
|
323 { |
|
324 iDest = FindDestinationL( ptrTag ); |
|
325 if( iDest == NULL ) |
|
326 { |
|
327 CLOG_WRITE_FORMAT( "Error: Destination not found: %S ", ptrTag ) |
|
328 iDestinationDropped = ETrue; |
|
329 } |
|
330 else |
|
331 { |
|
332 CLOG_WRITE_FORMAT( "\t Destination name: %S ", ptrTag ) |
|
333 } |
|
334 } |
|
335 break; |
|
336 case EDN_IAPName: |
|
337 { |
|
338 TInt pos; |
|
339 RCmConnectionMethodExt* plugin = FindPluginL( ptrTag, pos ); |
|
340 if( plugin ) |
|
341 { |
|
342 TRAPD( err, iDest->AddConnectionMethodL( *plugin ) ); |
|
343 // Set the priority according to the order in which the IAPs are in the XML |
|
344 TRAPD( err2 ,iDest->ModifyPriorityL( *plugin, priority )); |
|
345 if ( err2 != KErrNone ) |
|
346 { |
|
347 err2 = KErrNone; // to remove the compiler warnings |
|
348 } |
|
349 |
|
350 iDest->UpdateL(); |
|
351 priority++; |
|
352 |
|
353 if( err == KErrNone ) |
|
354 { |
|
355 CLOG_WRITE_FORMAT( "\t Added connection method: %S ", ptrTag ) |
|
356 (*iCmInDest)[ pos ] = ETrue; |
|
357 } |
|
358 else |
|
359 { |
|
360 CLOG_WRITE_FORMAT( |
|
361 "Warning connection method could not added: %S ", ptrTag ) |
|
362 } |
|
363 } |
|
364 else |
|
365 { |
|
366 CLOG_WRITE_FORMAT( |
|
367 "Warning: plugin could not added: %S ", ptrTag ) |
|
368 } |
|
369 } |
|
370 break; |
|
371 case EDN_EmbeddedDNName: |
|
372 { |
|
373 const RCmDestinationExt* embDestination = FindDestinationL( ptrTag ); |
|
374 if( embDestination ) |
|
375 { |
|
376 |
|
377 TRAPD( err, iDest->AddEmbeddedDestinationL( *embDestination ) ); |
|
378 |
|
379 if( err == KErrNone ) |
|
380 { |
|
381 CLOG_WRITE_FORMAT( "\t Added embedded destination: %S ", ptrTag ) |
|
382 } |
|
383 else |
|
384 { |
|
385 CLOG_WRITE_FORMAT( |
|
386 "Warning embedded destination could not added: %S ", ptrTag ) |
|
387 } |
|
388 } |
|
389 else |
|
390 { |
|
391 CLOG_WRITE_FORMAT( |
|
392 "Warning embedded destination could not added: %S ", ptrTag ) |
|
393 } |
|
394 |
|
395 } |
|
396 break; |
|
397 default: |
|
398 { |
|
399 break; |
|
400 } |
|
401 } // switch |
|
402 |
|
403 } // if |
|
404 |
|
405 }//for |
|
406 |
|
407 if( iIsFirstRound && !iDestinationDropped ) |
|
408 { |
|
409 RCmDestinationExt* newItem = new (ELeave) |
|
410 RCmDestinationExt( iDestination ); |
|
411 |
|
412 iDest = newItem; |
|
413 |
|
414 iDestArray->Append( newItem ); |
|
415 iDestName->Append( destName ); |
|
416 CleanupStack::Pop( destName ); |
|
417 } |
|
418 } |
|
419 |
|
420 |
|
421 // --------------------------------------------------------- |
|
422 // CProcessorDN::ProcessAPL |
|
423 // --------------------------------------------------------- |
|
424 // |
|
425 void CProcessorDN::ProcessAPL() |
|
426 { |
|
427 if( !iDestinationDropped ) |
|
428 { |
|
429 if( iDest ) |
|
430 { |
|
431 if( iIsFirstRound ) |
|
432 { |
|
433 iDest->SetProtectionL( iProtectionLevel ); |
|
434 } |
|
435 iDest->UpdateL(); |
|
436 |
|
437 if( iIsFirstRound ) |
|
438 { |
|
439 DoLogL(); |
|
440 } |
|
441 else |
|
442 { |
|
443 CLOG_WRITE( "\t \r\n" ) |
|
444 } |
|
445 } |
|
446 } |
|
447 } |
|
448 |
|
449 |
|
450 // --------------------------------------------------------- |
|
451 // CProcessorDN::DoLogL |
|
452 // --------------------------------------------------------- |
|
453 // |
|
454 void CProcessorDN::DoLogL() |
|
455 { |
|
456 HBufC16* tmp; |
|
457 |
|
458 tmp = iDestination.NameLC(); |
|
459 |
|
460 // Writes some data of the destination network into the log file. |
|
461 CLOG_WRITE( "Destination Network created:" ) |
|
462 CLOG_WRITE_FORMAT( "\t Destination name: %S ", tmp ) |
|
463 TUint32 uid = iDest->Id(); |
|
464 CLOG_WRITE_FORMAT( "\t Destination ID: %d", uid ); |
|
465 |
|
466 CLOG_WRITE( "\t \r\n" ) |
|
467 |
|
468 CleanupStack::PopAndDestroy( tmp ); // Removes tmp. |
|
469 } |
|
470 |
|
471 // End of File. |