|
1 /* |
|
2 * Copyright (c) 2002 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: Root of Provisioning document |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <s32file.h> |
|
21 #include <badesca.h> |
|
22 #include "CWPRoot.h" |
|
23 #include "CWPCharacteristic.h" |
|
24 #include "CWPParameter.h" |
|
25 #include "WPElementFactory.h" |
|
26 #include "ProvisioningDebug.h" |
|
27 |
|
28 // CONSTANTS |
|
29 const TInt KElementsGranularity = 5; |
|
30 const TInt KIDArrayGranularity = 6; |
|
31 _LIT( KInternet, "INTERNET" ); |
|
32 |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CWPRoot::CWPRoot |
|
38 // C++ default constructor can NOT contain any code, that |
|
39 // might leave. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CWPRoot::CWPRoot() |
|
43 { |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CWPRoot::ConstructL |
|
48 // Symbian 2nd phase constructor can leave. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 void CWPRoot::ConstructL() |
|
52 { |
|
53 iContents = new(ELeave) |
|
54 CArrayPtrFlat<CWPCharacteristic>( KElementsGranularity ); |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CWPRoot::NewL |
|
59 // Two-phased constructor. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CWPRoot* CWPRoot::NewL() |
|
63 { |
|
64 CWPRoot* self = NewLC(); |
|
65 CleanupStack::Pop(); |
|
66 |
|
67 return self; |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CWPRoot::NewLC |
|
72 // Two-phased constructor. |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 CWPRoot* CWPRoot::NewLC() |
|
76 { |
|
77 CWPRoot* self = new( ELeave ) CWPRoot; |
|
78 |
|
79 CleanupStack::PushL( self ); |
|
80 self->ConstructL(); |
|
81 |
|
82 return self; |
|
83 } |
|
84 // ----------------------------------------------------------------------------- |
|
85 // Destructor |
|
86 // ----------------------------------------------------------------------------- |
|
87 CWPRoot::~CWPRoot() |
|
88 { |
|
89 if( iContents ) |
|
90 { |
|
91 iContents->ResetAndDestroy(); |
|
92 delete iContents; |
|
93 } |
|
94 |
|
95 iNeeders.Close(); |
|
96 iProviders.Close(); |
|
97 delete iNeededIDs; |
|
98 delete iProviderIDs; |
|
99 iStack.Close(); |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CWPRoot::AcceptL |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void CWPRoot::AcceptL( MWPVisitor& aVisitor ) |
|
107 { |
|
108 FLOG( _L( "[Provisioning] CWPRoot::AcceptL:" ) ); |
|
109 |
|
110 for( TInt i( 0 ); i < iContents->Count(); i++ ) |
|
111 { |
|
112 iContents->At( i )->CallVisitorL( aVisitor ); |
|
113 } |
|
114 |
|
115 FLOG( _L( "[Provisioning] CWPRoot::AcceptL: Done" ) ); |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CWPRoot::InternalizeL |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 void CWPRoot::InternalizeL(RReadStream& aStream) |
|
123 { |
|
124 TInt count( aStream.ReadInt32L() ); |
|
125 |
|
126 iContents->ResetAndDestroy(); |
|
127 for( TInt i( 0 ); i < count; i++ ) |
|
128 { |
|
129 TInt type( aStream.ReadInt32L() ); |
|
130 CWPCharacteristic* current = |
|
131 WPElementFactory::CreateCharacteristicLC( type ); |
|
132 current->InternalizeL( aStream ); |
|
133 iContents->AppendL( current ); |
|
134 CleanupStack::Pop(); // current |
|
135 } |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CWPRoot::ExternalizeL |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 void CWPRoot::ExternalizeL(RWriteStream& aStream) const |
|
143 { |
|
144 aStream.WriteInt32L( iContents->Count() ); |
|
145 |
|
146 for( TInt i( 0 ); i < iContents->Count(); i++ ) |
|
147 { |
|
148 CWPCharacteristic* current = iContents->At( i ); |
|
149 aStream.WriteInt32L( current->Type() ); |
|
150 current->ExternalizeL( aStream ); |
|
151 } |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CWPRoot::InsertL |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 void CWPRoot::InsertL( CWPCharacteristic* aCharacteristic ) |
|
159 { |
|
160 iContents->AppendL( aCharacteristic ); |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CWPRoot::StartCharacteristicL |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 void CWPRoot::StartCharacteristicL( TInt aType ) |
|
168 { |
|
169 FTRACE(RDebug::Print(_L("[Provisioning] CWPRoot::StartCharacteristicL: aType (%d)"), aType)); |
|
170 |
|
171 CWPCharacteristic* newChar = |
|
172 WPElementFactory::CreateCharacteristicLC( aType ); |
|
173 if( iStack.Count() == 0 ) |
|
174 { |
|
175 // Assumes ownership if doesn't leave |
|
176 InsertL( newChar ); |
|
177 } |
|
178 else |
|
179 { |
|
180 CWPCharacteristic* latest = iStack[ iStack.Count()-1 ]; |
|
181 // Assumes ownership if doesn't leave |
|
182 latest->InsertL( newChar ); |
|
183 } |
|
184 CleanupStack::Pop(); // newChar |
|
185 |
|
186 User::LeaveIfError( iStack.Append( newChar ) ); |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CWPRoot::StartCharacteristicL |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 void CWPRoot::StartCharacteristicL( const TDesC& aName ) |
|
194 { |
|
195 FLOG( _L( "[Provisioning] CWPRoot::StartCharacteristicL:" ) ); |
|
196 |
|
197 CWPCharacteristic* newChar = |
|
198 WPElementFactory::CreateCharacteristicLC( aName ); |
|
199 if( iStack.Count() == 0 ) |
|
200 { |
|
201 // Assumes ownership if doesn't leave |
|
202 InsertL( newChar ); |
|
203 } |
|
204 else |
|
205 { |
|
206 CWPCharacteristic* latest = iStack[ iStack.Count()-1 ]; |
|
207 // Assumes ownership if doesn't leave |
|
208 latest->InsertL( newChar ); |
|
209 } |
|
210 CleanupStack::Pop(); // newChar |
|
211 |
|
212 User::LeaveIfError( iStack.Append( newChar ) ); |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CWPRoot::EndCharacteristicL |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 void CWPRoot::EndCharacteristicL() |
|
220 { |
|
221 FLOG( _L( "[Provisioning] CWPRoot::EndCharacteristicL:" ) ); |
|
222 |
|
223 if( iStack.Count() > 0 ) |
|
224 { |
|
225 iStack.Remove( iStack.Count()-1 ); |
|
226 } |
|
227 else |
|
228 { |
|
229 User::Leave( KErrCorrupt ); |
|
230 } |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CWPRoot::ParameterL |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 void CWPRoot::ParameterL( TInt aID, const TDesC& aValue ) |
|
238 { |
|
239 TPtrC ptr( aValue ); |
|
240 |
|
241 FTRACE(RDebug::Print(_L("[Provisioning] CWPRoot::ParameterL: id: %d: value: %S"), aID, &ptr)); |
|
242 |
|
243 if( iStack.Count() > 0 ) |
|
244 { |
|
245 CWPParameter* param = WPElementFactory::CreateParameterLC( aID, ptr ); |
|
246 iStack[ iStack.Count()-1 ]->InsertL( param ); |
|
247 CleanupStack::Pop(); // param |
|
248 } |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // CWPRoot::ParameterL |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 void CWPRoot::ParameterL( const TDesC& aName, const TDesC& aValue ) |
|
256 { |
|
257 TPtrC name( aName ); |
|
258 TPtrC value( aValue ); |
|
259 |
|
260 FTRACE(RDebug::Print(_L("[Provisioning] CWPRoot::ParameterL: %S: %S"), &name, &value)); |
|
261 |
|
262 if( iStack.Count() > 0 ) |
|
263 { |
|
264 CWPParameter* param = |
|
265 WPElementFactory::CreateParameterLC( name, value ); |
|
266 iStack[ iStack.Count()-1 ]->InsertL( param ); |
|
267 CleanupStack::Pop(); // param |
|
268 } |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // CWPRoot::CreateLinksL |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 void CWPRoot::CreateLinksL() |
|
276 { |
|
277 FLOG( _L( "[Provisioning] CWPRoot::ParameterL2:" ) ); |
|
278 |
|
279 iNeeders.Reset(); |
|
280 delete iNeededIDs; |
|
281 iNeededIDs = NULL; |
|
282 iNeededIDs = new(ELeave) CDesCArrayFlat( KIDArrayGranularity ); |
|
283 delete iProviderIDs; |
|
284 iProviderIDs = NULL; |
|
285 iProviderIDs = new(ELeave) CDesCArrayFlat( KIDArrayGranularity ); |
|
286 |
|
287 AcceptL( *this ); |
|
288 |
|
289 // We now have arrays of links and targets of links. Put them together. |
|
290 for( TInt i( 0 ); i < iNeeders.Count(); i++ ) |
|
291 { |
|
292 CWPCharacteristic* needer = iNeeders[i]; |
|
293 TPtrC neededID( iNeededIDs->MdcaPoint( i ) ); |
|
294 |
|
295 TBool foundProvider( EFalse ); |
|
296 for( TInt j( 0 ); j < iProviders.Count() && !foundProvider; j++ ) |
|
297 { |
|
298 CWPCharacteristic* needed = iProviders[j]; |
|
299 TPtrC providerID( iProviderIDs->MdcaPoint( j ) ); |
|
300 |
|
301 if( providerID == neededID ) |
|
302 { |
|
303 if ( needer->Type() == KWPPxPhysical && needed->Type() != KWPNapDef) |
|
304 { |
|
305 // incorrect link found. do nothing. |
|
306 } |
|
307 else |
|
308 { |
|
309 #ifndef __SYNCML_DM_OTA |
|
310 FLOG ( _L( "[Provisioning] CWPRoot::CreateLinksL*********** __SYNCML_DM_OTA ***********" ) ); |
|
311 if (KWPApplication == needer->Type()) |
|
312 { |
|
313 _LIT( KNSmlDMProvisioningDMAppIdVal, "w7" ); |
|
314 FLOG (_L( "[Provisioning] CWPRoot::CreateLinksL:Needer is Application" ) ); |
|
315 |
|
316 CArrayFix<TPtrC>* name = new(ELeave) CArrayFixFlat<TPtrC>(1); |
|
317 CleanupStack::PushL(name); |
|
318 |
|
319 needer->ParameterL(EWPParameterAppID, name); |
|
320 |
|
321 if ((name->Count() > 0) |
|
322 && |
|
323 0 == name->At(0).Compare(KNSmlDMProvisioningDMAppIdVal) ) |
|
324 { |
|
325 CleanupStack::PopAndDestroy(); // name |
|
326 continue; |
|
327 } |
|
328 |
|
329 |
|
330 CleanupStack::PopAndDestroy(); // name |
|
331 } |
|
332 FLOG ( _L( "[Provisioning] CWPRoot::CreateLinksL:*********** __SYNCML_DM_OTA ***********" ) ); |
|
333 #endif |
|
334 |
|
335 needer->InsertLinkL( *needed ); |
|
336 foundProvider = ETrue; |
|
337 } |
|
338 } |
|
339 } |
|
340 } |
|
341 |
|
342 // Free the temporary memory |
|
343 iNeeders.Reset(); |
|
344 iProviders.Reset(); |
|
345 delete iNeededIDs; |
|
346 iNeededIDs = NULL; |
|
347 delete iProviderIDs; |
|
348 iProviderIDs = NULL; |
|
349 } |
|
350 |
|
351 // ----------------------------------------------------------------------------- |
|
352 // CWPRoot::Visit |
|
353 // ----------------------------------------------------------------------------- |
|
354 // |
|
355 void CWPRoot::VisitL( CWPParameter& aParameter ) |
|
356 { |
|
357 FLOG( _L( "[Provisioning] CWPRoot::VisitL Parameter:" ) ); |
|
358 |
|
359 if( iCharStack ) |
|
360 { |
|
361 TInt charType( iCharStack->Type() ); |
|
362 TInt paramID( aParameter.ID() ); |
|
363 |
|
364 // If the current characteristic is a logical proxy or access point, |
|
365 // add it to the list of potential targets of a link |
|
366 if( (charType == KWPPxLogical && paramID == EWPParameterProxyID ) |
|
367 || (charType == KWPNapDef && paramID == EWPParameterNapID) ) |
|
368 { |
|
369 iProviderIDs->AppendL( aParameter.Value() ); |
|
370 } |
|
371 // Handle internet-capable NAPDEF here |
|
372 else if( charType == KWPNapDef && paramID == EWPParameterInternet ) |
|
373 { |
|
374 User::LeaveIfError( iProviders.Append( iCharStack ) ); |
|
375 iProviderIDs->AppendL( KInternet ); |
|
376 } |
|
377 // If the parameter can link, append to the list of sources of links |
|
378 else if( paramID == EWPParameterToNapID |
|
379 || paramID == EWPParameterToProxy |
|
380 || (charType == KWPBootstrap && paramID == EWPParameterProxyID) ) |
|
381 { |
|
382 iNeededIDs->AppendL( aParameter.Value() ); |
|
383 User::LeaveIfError( iNeeders.Append( iCharStack ) ); |
|
384 } |
|
385 } |
|
386 } |
|
387 |
|
388 // ----------------------------------------------------------------------------- |
|
389 // CWPRoot::Visit |
|
390 // ----------------------------------------------------------------------------- |
|
391 // |
|
392 void CWPRoot::VisitL( CWPCharacteristic& aCharacteristic ) |
|
393 { |
|
394 FLOG( _L( "[Provisioning] CWPRoot::VisitL Char:" ) ); |
|
395 |
|
396 TInt charType( aCharacteristic.Type() ); |
|
397 |
|
398 // Add the characteristic to the stack as current |
|
399 CWPCharacteristic* charStack = iCharStack; |
|
400 iCharStack = &aCharacteristic; |
|
401 |
|
402 // Logical proxy and access points as treated as potential targets of links |
|
403 if( charType == KWPPxLogical || charType == KWPNapDef ) |
|
404 { |
|
405 // First get the characteristic and then use a visitor to find out the |
|
406 // id |
|
407 aCharacteristic.AcceptL( *this ); |
|
408 |
|
409 // If no id was found, there's something wrong with the document |
|
410 if( iProviders.Count() == iProviderIDs->Count()-1 ) |
|
411 { |
|
412 User::LeaveIfError( iProviders.Append( &aCharacteristic ) ); |
|
413 } |
|
414 } |
|
415 else |
|
416 { |
|
417 // Just enter other characteristics |
|
418 aCharacteristic.AcceptL( *this ); |
|
419 } |
|
420 |
|
421 // Remove the current from stack |
|
422 iCharStack = charStack; |
|
423 } |
|
424 |
|
425 // ----------------------------------------------------------------------------- |
|
426 // CWPRoot::VisitLink |
|
427 // ----------------------------------------------------------------------------- |
|
428 // |
|
429 void CWPRoot::VisitLinkL( CWPCharacteristic& /*aLink*/ ) |
|
430 { |
|
431 // Links have not yet been created |
|
432 } |
|
433 |
|
434 // End of File |