|
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 the License "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: |
|
15 * Handles white list settings in provisioning. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 // User includes |
|
23 #include "PushInitiator.h" |
|
24 #include "PushInitiatorList.h" |
|
25 #include "PushMtmSettings.h" |
|
26 #include "WhiteListAdapter.h" |
|
27 #include "WhiteListAdapterDef.h" |
|
28 #include "WhiteListAdapterItem.h" |
|
29 #include "WhiteListAdapterLogger.h" |
|
30 #include "WhiteListAdapterPanic.h" |
|
31 #include "WhiteListAdapterUids.h" |
|
32 // System includes |
|
33 #include <CWPCharacteristic.h> |
|
34 #include <CWPParameter.h> |
|
35 |
|
36 // CONSTANTS |
|
37 |
|
38 // 'Push enabled' flag settings |
|
39 const TInt KPushEnabledFlagLength = 1; |
|
40 const TUint16 KPushEnabledFlagTrue = '1'; |
|
41 const TUint16 KPushEnabledFlagFalse = '0'; |
|
42 |
|
43 // Granularity value for dynamic arrays |
|
44 const TInt KDynamicArrayGranularity = 3; |
|
45 |
|
46 // ================= MEMBER FUNCTIONS ====================== |
|
47 |
|
48 // --------------------------------------------------------- |
|
49 // CWhiteListAdapter::CWhiteListAdapter |
|
50 // --------------------------------------------------------- |
|
51 // |
|
52 CWhiteListAdapter::CWhiteListAdapter() : CWPAdapter(), |
|
53 iItems( KDynamicArrayGranularity ), |
|
54 iItemsToBeAdded( KDynamicArrayGranularity ), |
|
55 iLogicalProxyPushSupport( EPushDontCare ), iPhysicalProxyIsVisited( EFalse ) |
|
56 { |
|
57 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
58 _L( "WhiteListAdapter c'tor" ) ) ); |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------- |
|
62 // CWhiteListAdapter::ConstructL |
|
63 // --------------------------------------------------------- |
|
64 // |
|
65 void CWhiteListAdapter::ConstructL() |
|
66 { |
|
67 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
68 _L( "-> WhiteListAdapter::ConstructL" ) ) ); |
|
69 |
|
70 iMsvSession = CMsvSession::OpenSyncL( *this ); |
|
71 iPushMtmSettings = CPushMtmSettings::NewL(); |
|
72 |
|
73 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
74 _L( "<- WhiteListAdapter::ConstructL" ) ) ); |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------- |
|
78 // CWhiteListAdapter::NewL |
|
79 // --------------------------------------------------------- |
|
80 // |
|
81 CWhiteListAdapter* CWhiteListAdapter::NewL() |
|
82 { |
|
83 CWhiteListAdapter* self = new (ELeave) CWhiteListAdapter; |
|
84 |
|
85 CleanupStack::PushL( self ); |
|
86 |
|
87 self->ConstructL(); |
|
88 |
|
89 CleanupStack::Pop(); // self |
|
90 |
|
91 return self; |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------- |
|
95 // CWhiteListAdapter::~CWhiteListAdapter |
|
96 // --------------------------------------------------------- |
|
97 // |
|
98 CWhiteListAdapter::~CWhiteListAdapter() |
|
99 { |
|
100 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
101 _L( "-> WhiteListAdapter d'tor" ) ) ); |
|
102 |
|
103 delete iCurrentItem; |
|
104 |
|
105 delete iPushMtmSettings; // It has to be deleted before iMsvSession, |
|
106 // because it uses iMsvSession->FileSession(). |
|
107 delete iMsvSession; |
|
108 |
|
109 CLOG( ( ELogDetailed, WHITELISTADAPTER_LOG_LEVEL, |
|
110 _L( "WhiteListAdapter d'tor, iItemsToBeAdded.Count:%d" ), |
|
111 iItemsToBeAdded.Count() ) ); |
|
112 iItemsToBeAdded.ResetAndDestroy(); |
|
113 iItemsToBeAdded.Close(); |
|
114 |
|
115 CLOG( ( ELogDetailed, WHITELISTADAPTER_LOG_LEVEL, |
|
116 _L( "WhiteListAdapter d'tor, iItems.Count:%d" ), iItems.Count() ) ); |
|
117 iItems.ResetAndDestroy(); |
|
118 iItems.Close(); |
|
119 |
|
120 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
121 _L( "<- WhiteListAdapter d'tor" ) ) ); |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------- |
|
125 // CWhiteListAdapter::ItemCount |
|
126 // --------------------------------------------------------- |
|
127 // |
|
128 TInt CWhiteListAdapter::ItemCount() const |
|
129 { |
|
130 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
131 _L( "WhiteListAdapter::ItemCount %d" ), iItems.Count() ) ); |
|
132 |
|
133 return iItems.Count(); |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------- |
|
137 // CWhiteListAdapter::SummaryTitle |
|
138 // --------------------------------------------------------- |
|
139 // |
|
140 const TDesC16& CWhiteListAdapter::SummaryTitle( TInt /*aIndex*/ ) const |
|
141 { |
|
142 // As WL text will never be shown, we simply return an empty string here. |
|
143 return KNullDesC16(); |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------- |
|
147 // CWhiteListAdapter::SummaryText |
|
148 // --------------------------------------------------------- |
|
149 // |
|
150 const TDesC16& CWhiteListAdapter::SummaryText( TInt /*aIndex*/ ) const |
|
151 { |
|
152 // As WL text will never be shown, we simply return an empty string here. |
|
153 return KNullDesC16(); |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------- |
|
157 // CWhiteListAdapter::SaveL |
|
158 // --------------------------------------------------------- |
|
159 // |
|
160 void CWhiteListAdapter::SaveL( TInt aItem ) |
|
161 { |
|
162 __ASSERT_DEBUG( 0 <= aItem && aItem < iItems.Count(), |
|
163 Panic( EArrayIndexOutOfBounds ) ); |
|
164 |
|
165 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
166 _L( "-> WhiteListAdapter::SaveL %d" ), aItem ) ); |
|
167 |
|
168 CPushInitiator* pi = new (ELeave) CPushInitiator; |
|
169 CleanupStack::PushL( pi ); |
|
170 pi->SetAddressL( iItems[aItem]->Address(), |
|
171 iItems[aItem]->AddressType() ); |
|
172 |
|
173 TUint32 entryId = iPushMtmSettings->PushInitiatorList().AddL( pi ); |
|
174 CleanupStack::Pop( pi ); // pi, ownership taken over |
|
175 // Save the ID of the added entry: |
|
176 iItems[aItem]->SetId( entryId ); |
|
177 |
|
178 iPushMtmSettings->SaveL(); |
|
179 |
|
180 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
181 _L( "<- WhiteListAdapter::SaveL" ) ) ); |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------- |
|
185 // CWhiteListAdapter::CanSetAsDefault |
|
186 // --------------------------------------------------------- |
|
187 // |
|
188 TBool CWhiteListAdapter::CanSetAsDefault( TInt /*aItem*/ ) const |
|
189 { |
|
190 return EFalse; |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------- |
|
194 // CWhiteListAdapter::SetAsDefaultL |
|
195 // --------------------------------------------------------- |
|
196 // |
|
197 void CWhiteListAdapter::SetAsDefaultL( TInt /*aItem*/ ) |
|
198 { |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------- |
|
202 // CWhiteListAdapter::DetailsL |
|
203 // --------------------------------------------------------- |
|
204 // |
|
205 TInt CWhiteListAdapter::DetailsL( TInt /*aItem*/, |
|
206 MWPPairVisitor& /*aVisitor*/ ) |
|
207 { |
|
208 return KErrNotSupported; |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------- |
|
212 // CWhiteListAdapter::ContextExtension |
|
213 // --------------------------------------------------------- |
|
214 // |
|
215 TInt CWhiteListAdapter::ContextExtension( MWPContextExtension*& aExtension ) |
|
216 { |
|
217 aExtension = this; |
|
218 return KErrNone; |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------- |
|
222 // CWhiteListAdapter::VisitL |
|
223 // --------------------------------------------------------- |
|
224 // |
|
225 void CWhiteListAdapter::VisitL( CWPCharacteristic& aCharacteristic ) |
|
226 { |
|
227 if ( aCharacteristic.Type() == KWPPxLogical ) |
|
228 { |
|
229 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
230 _L( "-> WhiteListAdapter::VisitL PXLOGICAL" ) ) ); |
|
231 |
|
232 aCharacteristic.AcceptL( *this ); |
|
233 |
|
234 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
235 _L( "WhiteListAdapter::VisitL PXLOGICAL visited, push support is %d" ), |
|
236 iLogicalProxyPushSupport ) ); |
|
237 |
|
238 // iItemsToBeAdded contains physical proxies whose push support |
|
239 // is either PushEnabled or PushDontCare (i.e. PushDisabled proxies |
|
240 // are not present in this array). |
|
241 if ( iLogicalProxyPushSupport == EPushEnabled ) |
|
242 { |
|
243 // Knowing that the logical proxy's push support is PushEnabled, |
|
244 // we have to add each element of the above-mentioned array. |
|
245 for ( TInt i = 0; i < iItemsToBeAdded.Count(); i++ ) |
|
246 { |
|
247 // If addition fails, then we delete the item. Otherwise, |
|
248 // the ownership has been taken over by iItems array. |
|
249 if ( iItems.Append( iItemsToBeAdded[i] ) != KErrNone ) |
|
250 { |
|
251 delete iItemsToBeAdded[i]; |
|
252 } |
|
253 } |
|
254 } |
|
255 else |
|
256 { |
|
257 // We're here : logical proxy's push support is either PushDontCare |
|
258 // or PushDisabled. In this case we have to add only those elements |
|
259 // in the array whose push support is PushEnabled. This is because |
|
260 // physical proxy's push support definition is stronger than the |
|
261 // logical proxy's definition. |
|
262 for ( TInt i = 0; i < iItemsToBeAdded.Count(); i++ ) |
|
263 { |
|
264 TWhiteListAdapterItem* item = iItemsToBeAdded[i]; |
|
265 if ( item->PushSupport() == EPushEnabled ) |
|
266 { |
|
267 // If addition fails, then we delete the item. Otherwise, |
|
268 // the ownership has been taken over by iItems array. |
|
269 if ( iItems.Append( item ) != KErrNone ) |
|
270 { |
|
271 delete item; |
|
272 } |
|
273 } |
|
274 else |
|
275 { |
|
276 delete item; |
|
277 } |
|
278 } |
|
279 } |
|
280 |
|
281 // There is only one thing we need to do here : reset the array. |
|
282 // At this point, each element in the array is invalid : if the |
|
283 // element happened to be valid, then the other array (iItems) |
|
284 // took over the ownership. Otherwise (i.e. the element was |
|
285 // invalid), the element got deleted manually. |
|
286 // Thus, we can safely reset the array. |
|
287 iItemsToBeAdded.Reset(); |
|
288 |
|
289 iLogicalProxyPushSupport = EPushDontCare; |
|
290 |
|
291 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
292 _L( "<- WhiteListAdapter::VisitL PXLOGICAL" ) ) ); |
|
293 } |
|
294 else if ( aCharacteristic.Type() == KWPPxPhysical ) |
|
295 { |
|
296 // This deletion is for safety's sake : if one of the leaving methods |
|
297 // in this section (below) has left, then it may happen that this |
|
298 // method is called again and iCurrentItem is not NULL. If it is the |
|
299 // case, we can avoid having an orphaned memory area by deleting the |
|
300 // current item before allocating a new one. |
|
301 // However, in most cases iCurrentItem will be NULL. |
|
302 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
303 _L( "-> WhiteListAdapter::VisitL PXPHYSICAL" ) ) ); |
|
304 |
|
305 delete iCurrentItem; |
|
306 iCurrentItem = NULL; |
|
307 iCurrentItem = new (ELeave) TWhiteListAdapterItem(); |
|
308 |
|
309 iPhysicalProxyIsVisited = ETrue; |
|
310 |
|
311 aCharacteristic.AcceptL( *this ); |
|
312 |
|
313 iPhysicalProxyIsVisited = EFalse; |
|
314 |
|
315 if ( iCurrentItem->Valid() ) |
|
316 { |
|
317 User::LeaveIfError( iItemsToBeAdded.Append( iCurrentItem ) ); |
|
318 iCurrentItem = NULL; // Ownership transferred. |
|
319 |
|
320 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
321 _L( "WhiteListAdapter::VisitL PXPHYSICAL valid & added" ) ) ); |
|
322 } |
|
323 else |
|
324 { |
|
325 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
326 _L( "WhiteListAdapter::VisitL PXPHYSICAL invalid" ) ) ); |
|
327 // invalid physical proxy (at least from our point of view) |
|
328 delete iCurrentItem; |
|
329 iCurrentItem = NULL; |
|
330 } |
|
331 |
|
332 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
333 _L( "<- WhiteListAdapter::VisitL PXPHYSICAL" ) ) ); |
|
334 } |
|
335 } |
|
336 |
|
337 // --------------------------------------------------------- |
|
338 // CWhiteListAdapter::VisitL |
|
339 // --------------------------------------------------------- |
|
340 // |
|
341 void CWhiteListAdapter::VisitL( CWPParameter& aParameter ) |
|
342 { |
|
343 switch ( aParameter.ID() ) |
|
344 { |
|
345 case EWPParameterPhysicalProxyID : |
|
346 { |
|
347 __ASSERT_DEBUG( iCurrentItem, Panic( ENullProxy ) ); |
|
348 |
|
349 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
350 _L( "WhiteListAdapter::VisitL PhysicalProxyID" ) ) ); |
|
351 |
|
352 if ( iCurrentItem ) |
|
353 { |
|
354 iCurrentItem->SetProxyId( aParameter.Value() ); |
|
355 } |
|
356 |
|
357 break; |
|
358 } |
|
359 case EWPParameterPxAddr : |
|
360 { |
|
361 __ASSERT_DEBUG( iCurrentItem, Panic( ENullProxy ) ); |
|
362 |
|
363 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
364 _L( "WhiteListAdapter::VisitL PxAddr" ) ) ); |
|
365 |
|
366 if ( iCurrentItem ) |
|
367 { |
|
368 iCurrentItem->SetAddress( aParameter.Value() ); |
|
369 } |
|
370 |
|
371 break; |
|
372 } |
|
373 case EWPParameterPxAddrType : |
|
374 { |
|
375 __ASSERT_DEBUG( iCurrentItem, Panic( ENullProxy ) ); |
|
376 |
|
377 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
378 _L( "WhiteListAdapter::VisitL PxAddrType" ) ) ); |
|
379 |
|
380 if ( iCurrentItem ) |
|
381 { |
|
382 iCurrentItem->SetAddressType( aParameter.Value() ); |
|
383 } |
|
384 |
|
385 break; |
|
386 } |
|
387 case EWPParameterPushEnabled : |
|
388 { |
|
389 if ( iCurrentItem ) |
|
390 { |
|
391 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
392 _L( "WhiteListAdapter::VisitL Physical PushEnabled" ) ) ); |
|
393 |
|
394 // it is a physical proxy |
|
395 iCurrentItem->SetPushSupport |
|
396 ( ResolvePushSupport( aParameter.Value() ) ); |
|
397 } |
|
398 else |
|
399 { |
|
400 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
401 _L( "WhiteListAdapter::VisitL Logical PushEnabled" ) ) ); |
|
402 |
|
403 // it is a logical proxy |
|
404 iLogicalProxyPushSupport = |
|
405 ResolvePushSupport( aParameter.Value() ); |
|
406 } |
|
407 |
|
408 break; |
|
409 } |
|
410 default : |
|
411 break; |
|
412 } |
|
413 } |
|
414 |
|
415 // --------------------------------------------------------- |
|
416 // CWhiteListAdapter::VisitLinkL |
|
417 // --------------------------------------------------------- |
|
418 // |
|
419 void CWhiteListAdapter::VisitLinkL( CWPCharacteristic& /*aCharacteristic*/ ) |
|
420 { |
|
421 } |
|
422 |
|
423 // --------------------------------------------------------- |
|
424 // CWhiteListAdapter::HandleSessionEventL |
|
425 // --------------------------------------------------------- |
|
426 // |
|
427 void CWhiteListAdapter::HandleSessionEventL( TMsvSessionEvent /*aEvent*/, |
|
428 TAny* /*aArg1*/, |
|
429 TAny* /*aArg2*/, |
|
430 TAny* /*aArg3*/ ) |
|
431 { |
|
432 } |
|
433 |
|
434 // --------------------------------------------------------- |
|
435 // CWhiteListAdapter::ResolvePushSupport |
|
436 // --------------------------------------------------------- |
|
437 // |
|
438 TPushSupport CWhiteListAdapter::ResolvePushSupport( const TDesC& aPushSupport ) |
|
439 { |
|
440 TPushSupport support = EPushDontCare; |
|
441 |
|
442 if ( aPushSupport.Length() == KPushEnabledFlagLength ) |
|
443 { |
|
444 if ( aPushSupport[0] == KPushEnabledFlagTrue ) |
|
445 { |
|
446 support = EPushEnabled; |
|
447 } |
|
448 else if ( aPushSupport[0] == KPushEnabledFlagFalse ) |
|
449 { |
|
450 support = EPushDisabled; |
|
451 } |
|
452 } |
|
453 |
|
454 return support; |
|
455 } |
|
456 |
|
457 // --------------------------------------------------------- |
|
458 // CWhiteListAdapter::SaveDataL |
|
459 // --------------------------------------------------------- |
|
460 // |
|
461 const TDesC8& CWhiteListAdapter::SaveDataL( TInt aIndex ) const |
|
462 { |
|
463 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
464 _L( "WhiteListAdapter::SaveDataL %d %d %d" ), |
|
465 iItems.Count(), aIndex, iItems[aIndex]->Id() ) ); |
|
466 return ( iItems[aIndex]->IdBuf() ); |
|
467 } |
|
468 |
|
469 // --------------------------------------------------------- |
|
470 // CWhiteListAdapter::DeleteL |
|
471 // --------------------------------------------------------- |
|
472 // |
|
473 void CWhiteListAdapter::DeleteL( const TDesC8& aSaveData ) |
|
474 { |
|
475 // Copy source into a package buffer: |
|
476 TPckgBuf<TUint32> entryIdBuf; |
|
477 entryIdBuf.Copy( aSaveData ); |
|
478 // Extract the entry ID: |
|
479 TUint32 entryId( entryIdBuf() ); |
|
480 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
481 _L( "WhiteListAdapter::DeleteL ID %d" ), entryId ) ); |
|
482 |
|
483 // Now entryId holds the ID - we can remove it from WL: |
|
484 CPushInitiatorList& whiteList = iPushMtmSettings->PushInitiatorList(); |
|
485 // Find the index of the Initiator with the given ID. |
|
486 TInt index( KErrNotFound ); |
|
487 // As the entries are unique in WL by the ID, it's enough |
|
488 // to continue the loop until first hit. |
|
489 const TInt count( whiteList.Count() ); |
|
490 for ( TInt i = 0; i < count; ++i ) |
|
491 { |
|
492 const CPushInitiator& initiator = whiteList.At(i); |
|
493 if ( initiator.EntryID() == entryId ) |
|
494 { |
|
495 index = i; |
|
496 // Found: |
|
497 break; |
|
498 } |
|
499 } |
|
500 |
|
501 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
502 _L( "WhiteListAdapter::DeleteL index %d" ), index ) ); |
|
503 if ( index != KErrNotFound ) |
|
504 { |
|
505 whiteList.Delete( index ); |
|
506 // Commit changes. |
|
507 iPushMtmSettings->SaveL(); |
|
508 CLOG( ( ELogBasic, WHITELISTADAPTER_LOG_LEVEL, |
|
509 _L( "WhiteListAdapter::DeleteL Saved..." ) ) ); |
|
510 } |
|
511 } |
|
512 |
|
513 // --------------------------------------------------------- |
|
514 // CWhiteListAdapter::Uid |
|
515 // --------------------------------------------------------- |
|
516 // |
|
517 TUint32 CWhiteListAdapter::Uid() const |
|
518 { |
|
519 return (TUint32)KWhiteListAdapterImplementationUid; |
|
520 } |
|
521 |
|
522 // End of file |