|
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: Main class for handling provisioning accesspoint data |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include "CWPAPAdapter.h" // Own header |
|
23 |
|
24 #include <CWPCharacteristic.h> |
|
25 #include <commdb.h> |
|
26 #include <WPAPAdapterResource.rsg> |
|
27 #include <featmgr.h> // Feature manager |
|
28 #include "WPAPUtil.h" |
|
29 #include "CWPAPAccesspointItem.h" |
|
30 #include "CWPAPNapdef.h" |
|
31 #include "CWPAPLogicalProxy.h" |
|
32 #include "WPAPAdapter.pan" |
|
33 #include "CWPLog.h" |
|
34 #include "ProvisioningDebug.h" |
|
35 #include "WPAPDefs.h" |
|
36 #include <cmmanagerext.h> |
|
37 #include <cmconnectionmethodext.h> |
|
38 #include <WPAdapterUtil.h> |
|
39 |
|
40 // ============================ MEMBER FUNCTIONS =============================== |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CWPAPAdapter::CWPAPAdapter |
|
44 // C++ default constructor can NOT contain any code, that |
|
45 // might leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CWPAPAdapter::CWPAPAdapter() : CWPAdapter(), |
|
49 iLinks( KInitialArraySize ), |
|
50 iDataItems( KInitialArraySize ), |
|
51 iSaveItems( KInitialArraySize ) |
|
52 { |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CWPAPAdapter::ConstructL |
|
57 // Symbian 2nd phase constructor can leave. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 void CWPAPAdapter::ConstructL() |
|
61 { |
|
62 FLOG( _L( "[AccesspointAdapter] CWPAPAdapter::ConstructL:" ) ); |
|
63 |
|
64 iTitle = WPAPUtil::ReadHBufCL( R_QTN_SM_WML_ACCESSPOINTS ); |
|
65 iDefaultName = WPAPUtil::ReadHBufCL( R_QTN_SM_WAPAP_NAME ); |
|
66 |
|
67 FeatureManager::InitializeLibL(); |
|
68 |
|
69 iCmManager = new RCmManagerExt; |
|
70 iCmManager->OpenL(); |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CWPAPAdapter::NewL |
|
75 // Two-phased constructor. |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 CWPAPAdapter* CWPAPAdapter::NewL() |
|
79 { |
|
80 CWPAPAdapter* self = new(ELeave) CWPAPAdapter; |
|
81 CleanupStack::PushL(self); |
|
82 self->ConstructL(); |
|
83 CleanupStack::Pop(self); |
|
84 return self; |
|
85 } |
|
86 // ----------------------------------------------------------------------------- |
|
87 // Destructor |
|
88 // ----------------------------------------------------------------------------- |
|
89 CWPAPAdapter::~CWPAPAdapter() |
|
90 { |
|
91 // Contents of iLinks array are not owned |
|
92 iLinks.Close(); |
|
93 |
|
94 iDataItems.ResetAndDestroy(); |
|
95 iDataItems.Close(); |
|
96 |
|
97 iSaveItems.ResetAndDestroy(); |
|
98 iSaveItems.Close(); |
|
99 iAPValue.Reset(); |
|
100 |
|
101 delete iTitle; |
|
102 delete iDefaultName; |
|
103 delete iCommsDb; |
|
104 |
|
105 if ( iCmManager != NULL ) |
|
106 { |
|
107 iCmManager->Close(); |
|
108 delete iCmManager; |
|
109 } |
|
110 |
|
111 FeatureManager::UnInitializeLib(); |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CWPAPAdapter::ItemCount |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 TInt CWPAPAdapter::ItemCount() const |
|
119 { |
|
120 LOG1("Number of Access points: %d", iSaveItems.Count() ); |
|
121 return iSaveItems.Count(); |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CWPAPAdapter::SummaryTitle |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 const TDesC16& CWPAPAdapter::SummaryTitle(TInt aIndex) const |
|
129 { |
|
130 __ASSERT_DEBUG( aIndex >= 0 && aIndex < iSaveItems.Count(), |
|
131 Panic( EIndexOutOfBounds )); |
|
132 // The title is always the same. |
|
133 return *iTitle; |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CWPAPAdapter::SummaryText |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 const TDesC16& CWPAPAdapter::SummaryText(TInt aIndex) const |
|
141 { |
|
142 __ASSERT_DEBUG( aIndex >= 0 && aIndex < iSaveItems.Count(), |
|
143 Panic( EIndexOutOfBounds )); |
|
144 return iSaveItems[ aIndex ]->Name(); |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CWPAPAdapter::DetailsL |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 TInt CWPAPAdapter::DetailsL( TInt /*aItem*/, MWPPairVisitor& /*aVisitor*/) |
|
152 { |
|
153 // Detail view is a feature for later release. |
|
154 return KErrNotSupported; |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CWPAPAdapter::SaveL |
|
159 // ----------------------------------------------------------------------------- |
|
160 // |
|
161 void CWPAPAdapter::SaveL( TInt aItem ) |
|
162 { |
|
163 FLOG( _L( "[AccesspointAdapter] CWPAPAdapter::SaveL:" ) ); |
|
164 |
|
165 __ASSERT_DEBUG(aItem >= 0 && |
|
166 aItem < iSaveItems.Count(), |
|
167 Panic( EPreConditionFail )); |
|
168 |
|
169 TBool internetparmfound = EFalse; |
|
170 TInt err1; |
|
171 |
|
172 for (TInt i = 0; i < iAPValue.Count(); i++) |
|
173 { |
|
174 if (aItem == iAPValue[i]) |
|
175 { |
|
176 internetparmfound = ETrue; |
|
177 break; |
|
178 } |
|
179 |
|
180 } |
|
181 |
|
182 // Create the commsdb when the save is initiated first time. |
|
183 // This stays alive until the adapter is destroyed. |
|
184 if ( !iCommsDb ) |
|
185 { |
|
186 iCommsDb = CCommsDatabase::NewL( EDatabaseTypeIAP ); |
|
187 } |
|
188 |
|
189 if( iAlreadySavedOnce && aItem == 0 ) |
|
190 { |
|
191 for( TInt i( 0 ); i < iSaveItems.Count(); i++ ) |
|
192 { |
|
193 iSaveItems[i]->DeleteUidData(); |
|
194 } |
|
195 } |
|
196 |
|
197 // ********************************************************************************** // |
|
198 // ***** check that the napdefs with a certain id are only saved once SKSS-79REKH *** // |
|
199 // ********************************************************************************** // |
|
200 TBool found = EFalse; |
|
201 if (iSaveItems[ aItem ]->Characteristic() == KWPNapDef) |
|
202 { |
|
203 |
|
204 // Get the napdef pointer from the saved items and check that it is not NULL |
|
205 CWPAPNapdef* napdef = static_cast<CWPAPNapdef*>(iSaveItems[ aItem ]->NapDef()); |
|
206 |
|
207 if ( napdef ) |
|
208 { |
|
209 // Store the id of the NAP that is being saved now |
|
210 TBufC<KNameMaxLength> napId = napdef->NapId(); |
|
211 |
|
212 // check whether napdef with same id has been already saved. |
|
213 for ( TInt j( 0 ); j < aItem; j++ ) |
|
214 { |
|
215 // If a napdef is not in question we can move to the next item |
|
216 if ( iSaveItems[ j ]->Characteristic() != KWPNapDef) |
|
217 { |
|
218 continue; |
|
219 } |
|
220 |
|
221 // Store the pointer to to comparison napdef and make the nap id check if |
|
222 // the pointer is other than NULL |
|
223 CWPAPNapdef* tmpNap = static_cast<CWPAPNapdef*>(iSaveItems[ j ]->NapDef()); |
|
224 |
|
225 if ( tmpNap != NULL ) |
|
226 { |
|
227 // If the id was found, the napdef with this id is already stored |
|
228 if ( tmpNap->NapId() == napId ) |
|
229 { |
|
230 found = ETrue; |
|
231 break; |
|
232 } |
|
233 } |
|
234 } |
|
235 } |
|
236 } |
|
237 |
|
238 // if access point is not already stored, then we store it |
|
239 if ( !found ) |
|
240 { |
|
241 TUint32 iap = 0; |
|
242 if (internetparmfound) |
|
243 { |
|
244 // Give pointer to cm manager to access point item |
|
245 iSaveItems[ aItem ]->SetCMManager(iCmManager); |
|
246 TRAPD(err,iap = iSaveItems[ aItem ]->SaveL( *iCommsDb)); |
|
247 if(err!=KErrNone) |
|
248 { |
|
249 User::LeaveIfError(err); |
|
250 } |
|
251 |
|
252 TRAP(err1, WPAdapterUtil::SetAPDetailsL(iap)); |
|
253 if (err1 == KErrNone) |
|
254 { |
|
255 iAlreadySavedOnce = ETrue; |
|
256 } |
|
257 } |
|
258 |
|
259 if (!internetparmfound || (internetparmfound && err1 != KErrNone)) |
|
260 { |
|
261 // Give pointer to cm manager to access point item |
|
262 iSaveItems[ aItem ]->SetCMManager(iCmManager); |
|
263 TRAPD(err,iap = iSaveItems[ aItem ]->SaveL( *iCommsDb)); |
|
264 if(err!=KErrNone) |
|
265 { |
|
266 User::LeaveIfError(err); |
|
267 } |
|
268 iAlreadySavedOnce = ETrue; |
|
269 } |
|
270 } |
|
271 FLOG( _L( "[AccesspointAdapter] CWPAPAdapter::SaveL: done" ) ); |
|
272 } |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 // CWPAPAdapter::CanSetAsDefault |
|
276 // ----------------------------------------------------------------------------- |
|
277 // |
|
278 TBool CWPAPAdapter::CanSetAsDefault( TInt /*aItem*/ ) const |
|
279 { |
|
280 return EFalse; |
|
281 } |
|
282 |
|
283 // ----------------------------------------------------------------------------- |
|
284 // CWPAPAdapter::SetAsDefault |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 void CWPAPAdapter::SetAsDefaultL( TInt /*aItem*/ ) |
|
288 { |
|
289 // This shouldn't be called because CanSetAsDefault |
|
290 // always returns EFalse. |
|
291 Panic( EPreConditionFail ); |
|
292 } |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // CWPAPAdapter::VisitL |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 void CWPAPAdapter::VisitL( CWPCharacteristic& aCharacteristic ) |
|
299 { |
|
300 FLOG( _L( "[AccesspointAdapter] CWPAPAdapter::VisitL:" ) ); |
|
301 |
|
302 TInt type = aCharacteristic.Type(); |
|
303 |
|
304 if ( type == KWPApplication ) |
|
305 { |
|
306 FLOG( _L( "[AccesspointAdapter] CWPAPAdapter::VisitL: KWPApplication" ) ); |
|
307 aCharacteristic.AcceptL( *this ); |
|
308 } |
|
309 // Check every NAPDEF characteristic. If it contains INTERNET |
|
310 // parameter then new access point is created from NAPDEF data. |
|
311 else if ( type == KWPNapDef && !IsAlreadyLinked( aCharacteristic ) ) |
|
312 { |
|
313 FLOG( _L( "[AccesspointAdapter] CWPAPAdapter::VisitL: KWPNapDef" ) ); |
|
314 CWPAPNapdef* item = CWPAPNapdef::NewLC( EFalse, |
|
315 *iDefaultName, |
|
316 aCharacteristic, |
|
317 aCharacteristic ); |
|
318 if( item->AddItemsL( iSaveItems, NULL, NULL ) > 0 ) |
|
319 { |
|
320 User::LeaveIfError( iLinks.InsertInAddressOrder( &aCharacteristic ) ); |
|
321 } |
|
322 User::LeaveIfError( iDataItems.Append( item ) ); |
|
323 |
|
324 |
|
325 TInt val = item->GetInternetIndicator(); |
|
326 if (val != -1) |
|
327 { |
|
328 iAPValue.Append(val); |
|
329 } |
|
330 CleanupStack::Pop( item ); |
|
331 } |
|
332 FLOG( _L( "[AccesspointAdapter] CWPAPAdapter::VisitL:done" ) ); |
|
333 |
|
334 } |
|
335 |
|
336 // ----------------------------------------------------------------------------- |
|
337 // CWPAPAdapter::VisitL |
|
338 // ----------------------------------------------------------------------------- |
|
339 // |
|
340 void CWPAPAdapter::VisitL( CWPParameter& /*aParameter*/ ) |
|
341 { |
|
342 } |
|
343 |
|
344 // ----------------------------------------------------------------------------- |
|
345 // CWPAPAdapter::VisitLinkL |
|
346 // ----------------------------------------------------------------------------- |
|
347 // |
|
348 void CWPAPAdapter::VisitLinkL( CWPCharacteristic& aCharacteristic ) |
|
349 { |
|
350 if( !IsAlreadyLinked( aCharacteristic ) ) |
|
351 { |
|
352 switch( aCharacteristic.Type() ) |
|
353 { |
|
354 // This is link in APPLICATION characteristic to certain NAPDEF or LOGICAL proxy |
|
355 case KWPPxLogical: |
|
356 { |
|
357 CWPAPLogicalProxy* item = CWPAPLogicalProxy::NewLC( |
|
358 *iDefaultName, aCharacteristic ); |
|
359 item->AddItemsL( iSaveItems, NULL, NULL ); |
|
360 User::LeaveIfError( iLinks.InsertInAddressOrder( &aCharacteristic ) ); |
|
361 User::LeaveIfError( iDataItems.Append( item ) ); |
|
362 CleanupStack::Pop( item ); |
|
363 break; |
|
364 } |
|
365 case KWPNapDef: |
|
366 { |
|
367 CWPAPNapdef* item = CWPAPNapdef::NewLC( ETrue, |
|
368 *iDefaultName, |
|
369 aCharacteristic, |
|
370 aCharacteristic ); |
|
371 item->AddItemsL( iSaveItems, NULL, NULL ); |
|
372 User::LeaveIfError( iLinks.InsertInAddressOrder( &aCharacteristic ) ); |
|
373 User::LeaveIfError( iDataItems.Append( item ) ); |
|
374 CleanupStack::Pop( item ); |
|
375 break; |
|
376 } |
|
377 } |
|
378 } |
|
379 } |
|
380 |
|
381 // ----------------------------------------------------------------------------- |
|
382 // CWPAPAdapter::ContextExtension |
|
383 // ----------------------------------------------------------------------------- |
|
384 // |
|
385 TInt CWPAPAdapter::ContextExtension( MWPContextExtension*& aContextExtension ) |
|
386 { |
|
387 aContextExtension = this; |
|
388 return KErrNone; |
|
389 } |
|
390 |
|
391 // ----------------------------------------------------------------------------- |
|
392 // CWPAPAdapter::SaveDataL |
|
393 // ----------------------------------------------------------------------------- |
|
394 // |
|
395 const TDesC8& CWPAPAdapter::SaveDataL( TInt aIndex ) const |
|
396 { |
|
397 return iSaveItems[ aIndex ]->Uid(); |
|
398 } |
|
399 |
|
400 // ----------------------------------------------------------------------------- |
|
401 // CWPAPAdapter::DeleteL |
|
402 // ----------------------------------------------------------------------------- |
|
403 // |
|
404 void CWPAPAdapter::DeleteL( const TDesC8& aSaveData ) |
|
405 { |
|
406 if ( !iCommsDb ) |
|
407 { |
|
408 iCommsDb = CCommsDatabase::NewL( EDatabaseTypeIAP ); |
|
409 } |
|
410 |
|
411 TPckgBuf<TUint32> uid; |
|
412 if( aSaveData.Length() == uid.MaxLength() ) |
|
413 { |
|
414 LOG1( "DeleteL: Deleting %08x", uid() ); |
|
415 uid.Copy( aSaveData ); |
|
416 |
|
417 // CMManager |
|
418 TRAPD( err, iCmManager->ConnectionMethodL( uid()).DeleteL() ); |
|
419 |
|
420 LOG1( "DeleteL: Result: %d", err ); |
|
421 if( err == KErrLocked ) |
|
422 { |
|
423 User::Leave( EWPCommsDBLocked ); |
|
424 } |
|
425 else if ( err != KErrNone && err != KErrNotFound ) |
|
426 { |
|
427 User::Leave( err ); |
|
428 } |
|
429 } |
|
430 |
|
431 //CleanupStack::PopAndDestroy( dataHandler ); |
|
432 } |
|
433 |
|
434 // ----------------------------------------------------------------------------- |
|
435 // CWPAPAdapter::Uid |
|
436 // ----------------------------------------------------------------------------- |
|
437 // |
|
438 TUint32 CWPAPAdapter::Uid() const |
|
439 { |
|
440 return iDtor_ID_Key.iUid; |
|
441 } |
|
442 |
|
443 // ----------------------------------------------------------------------------- |
|
444 // CWPAPAdapter::IsAlreadyLinked |
|
445 // ----------------------------------------------------------------------------- |
|
446 // |
|
447 TBool CWPAPAdapter::IsAlreadyLinked( CWPCharacteristic& aCharacteristic ) |
|
448 { |
|
449 return iLinks.FindInAddressOrder( &aCharacteristic ) >= 0; |
|
450 } |
|
451 |
|
452 // End of File |