omaprovisioning/provisioning/IMAdapter/Src/CWPIMAdapter.cpp
changeset 73 ae69c2e8bc34
parent 71 d2517372cc44
child 77 9f85c58c0592
equal deleted inserted replaced
71:d2517372cc44 73:ae69c2e8bc34
     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:  Handles wireless village settings in provisioning.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CWPIMAdapter.h"   // own header
       
    22 #include <e32base.h>
       
    23 #include <CWPAdapter.h>
       
    24 #include <CWPCharacteristic.h>
       
    25 #include <CWPParameter.h>
       
    26 #include <wpwvadapterresource.rsg>
       
    27 
       
    28 #include <commdb.h>
       
    29 #include "WPAdapterUtil.h"
       
    30 #include "CWPIMSAPItem.h"
       
    31 #include "ProvisioningDebug.h"
       
    32 
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CWPIMAdapter::CWPIMAdapter
       
    38 // C++ default constructor can NOT contain any code, that
       
    39 // might leave.
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CWPIMAdapter::CWPIMAdapter() : CWPAdapter()
       
    43 	{
       
    44 	}
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CWPIMAdapter::ConstructL
       
    48 // Symbian 2nd phase constructor can leave.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 void CWPIMAdapter::ConstructL()
       
    52 	{
       
    53 	FLOG( _L( "[Provisioning] CWPIMAdapter::ConstructL:" ) );
       
    54 	
       
    55     TFileName fileName;
       
    56     Dll::FileName( fileName );
       
    57     iWVTitle = WPAdapterUtil::ReadHBufCL( fileName, KWVAdapterName, R_QTN_OP_HEAD_IMSETTINGS );
       
    58 
       
    59     iSAPIdForDefault = KNotSet;
       
    60 	}
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CWPIMAdapter::NewL
       
    64 // Two-phased constructor.
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CWPIMAdapter* CWPIMAdapter::NewL()
       
    68 	{
       
    69 	CWPIMAdapter* self = new(ELeave) CWPIMAdapter; 
       
    70 	CleanupStack::PushL(self);
       
    71 	self->ConstructL();
       
    72 	CleanupStack::Pop(self);
       
    73 	return self;
       
    74 	}
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // Destructor
       
    78 // -----------------------------------------------------------------------------
       
    79 CWPIMAdapter::~CWPIMAdapter()
       
    80 	{
       
    81 	delete iCurrentData;    
       
    82     delete iWVTitle;
       
    83 	for ( TInt i = 0; i < iDatas.Count(); i++ )
       
    84 		{
       
    85 		delete iDatas[i];
       
    86 		}
       
    87 	iDatas.Close();
       
    88 	}
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CWPIMAdapter::DetailsL
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 TInt CWPIMAdapter::DetailsL( TInt /*aItem*/, MWPPairVisitor& /*aVisitor */ )
       
    95 	{
       
    96 	return KErrNotSupported;
       
    97 	}
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CWPIMAdapter::SummaryCount
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 TInt CWPIMAdapter::ItemCount() const
       
   104 	{
       
   105 	TInt count(0);
       
   106 	for(TInt i=0;i<iDatas.Count();i++)
       
   107 	    {
       
   108 	    if(iDatas[i]->iProvLocation == EIMPSIMAccessGroup)
       
   109 	        {
       
   110 	        count++;
       
   111 	        }
       
   112 	    }
       
   113 	return count;
       
   114 	}
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CWPIMAdapter::SummaryTitle
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 const TDesC16& CWPIMAdapter::SummaryTitle(TInt /*aIndex*/) const
       
   121 	{
       
   122 	return *iWVTitle;
       
   123 	}
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CWPIMAdapter::SummaryText
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 const TDesC16& CWPIMAdapter::SummaryText(TInt aIndex) const
       
   130 	{
       
   131 	return iDatas[aIndex]->iName;
       
   132 	}
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CWPIMAdapter::SaveL
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void CWPIMAdapter::SaveL( TInt aIndex )
       
   139 	{
       
   140 	FLOG( _L( "[Provisioning] CWPIMAdapter::SaveL" ) );
       
   141 	
       
   142 	for(TInt i=0;i<iDatas.Count();i++)
       
   143 	    {
       
   144 	    if(iDatas[i]->iProvLocation != EIMPSIMAccessGroup)
       
   145 	        {
       
   146 	        delete iDatas[i];
       
   147 	        iDatas.Remove(i);
       
   148 	        i--;
       
   149 	        }
       
   150 	    }
       
   151 	if ( ( iDatas.Count() == 0 ) ||  ( aIndex > iDatas.Count() - 1 ) )
       
   152 	    {
       
   153 	    FLOG( _L( "[Provisioning] CWPIMAdapter::SaveL No data" ) );
       
   154 	    return;
       
   155 	    }
       
   156 	
       
   157     if ( iDatas[aIndex]->iProvLocation == EIMPSIMAccessGroup )	
       
   158 	    {
       
   159         //data item at given index
       
   160         TData* data = iDatas[aIndex];
       
   161         // create save item
       
   162         CWPIMSAPItem* sapItem = CWPIMSAPItem::NewLC( EIMPSIMAccessGroup );
       
   163         
       
   164         // set data to save item
       
   165         sapItem->SetUserIDL( data->iUserID );
       
   166         sapItem->SetPasswordL( data->iPassword );
       
   167         sapItem->SetSAPURIL( data->iURL );
       
   168         sapItem->SetSettingsNameL( data->iName );
       
   169 
       
   170     	// Find a proper GPRS access point
       
   171         TUint32 iapId(KMaxTUint32);
       
   172         if(data->iLinks.Count())
       
   173     	    {
       
   174             iapId = WPIMUtil::FindGPRSL( data->iLinks );
       
   175             }
       
   176     	// set the IAP id as part of save item.
       
   177     	sapItem->SetIAPIdL( iapId );
       
   178            
       
   179         // store SAP item
       
   180         TUint32 SAPuid = sapItem->StoreL();
       
   181     	data->iSAPId = SAPuid;
       
   182 
       
   183         // if there is no id for default Service Access Point, set it. 
       
   184         if (iSAPIdForDefault == KNotSet)
       
   185             {
       
   186             iSAPIdForDefault = SAPuid;
       
   187             }
       
   188         
       
   189         CleanupStack::PopAndDestroy( sapItem ); 
       
   190         FLOG( _L( "[Provisioning] CWPIMAdapter::SaveL Done" ) );
       
   191 	    }
       
   192 	}
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CWPIMAdapter::CanSetAsDefault
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 TBool CWPIMAdapter::CanSetAsDefault(TInt aIndex) const
       
   199 	{
       
   200     // the first one is set as default if exists.
       
   201     return ( iSAPIdForDefault && ( aIndex == 0 ) );
       
   202 	}
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // CWPIMAdapter::SetAsDefaultL
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 void CWPIMAdapter::SetAsDefaultL( TInt aIndex )
       
   209 	{
       
   210     if ( aIndex == 0 && iSAPIdForDefault != KNotSet )
       
   211         {
       
   212         // set the first item saved as a default     
       
   213         CWPIMSAPItem::SetAsDefaultL( iSAPIdForDefault, EIMPSIMAccessGroup );
       
   214         }
       
   215 	}
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CWPIMAdapter::VisitL
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 void CWPIMAdapter::VisitL( CWPCharacteristic& aCharacteristic )
       
   222 	{
       
   223 	switch( aCharacteristic.Type() )
       
   224 		{
       
   225 		case KWPApplication:
       
   226 			iCurrentData = new(ELeave) TData;
       
   227             
       
   228             aCharacteristic.AcceptL( *this );
       
   229 
       
   230 			if( (iAppID == KIMAppID1 || 
       
   231 			     iAppID == KIMAppID2 ) && WPIMUtil::IsValid(iCurrentData) )
       
   232 				{
       
   233 				FLOG( _L( "[Provisioning] CWPIMAdapter::VisitL App ID match" ) );
       
   234 				iCurrentData->iProvLocation = EIMPSIMAccessGroup;
       
   235 				User::LeaveIfError( iDatas.Append( iCurrentData ) );
       
   236 				}
       
   237 			else
       
   238 				{
       
   239 				delete iCurrentData;
       
   240 				}
       
   241 
       
   242 			iCurrentData = NULL;
       
   243 			break;
       
   244 		
       
   245 		case KWPAppAddr: // fallthrough
       
   246         case KWPAppAuth:
       
   247 			if( iCurrentData )
       
   248 				{                
       
   249 				aCharacteristic.AcceptL( *this );
       
   250 				}
       
   251 			break;
       
   252                 
       
   253         default:
       
   254 			break;
       
   255 		}
       
   256 	}
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // CWPIMAdapter::VisitL
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 void CWPIMAdapter::VisitL( CWPParameter& aParameter)
       
   263 	{
       
   264     	
       
   265 	switch( aParameter.ID() )
       
   266 		{
       
   267         case EWPParameterAppID:
       
   268 			iAppID.Set( aParameter.Value() );
       
   269 			break;
       
   270 
       
   271 		case EWPParameterName:
       
   272             if (iCurrentData->iName == KNullDesC)
       
   273                 {
       
   274                 iCurrentData->iName.Set( aParameter.Value() );
       
   275                 }
       
   276  			break;
       
   277 
       
   278 		case EWPParameterAddr:
       
   279             if (iCurrentData->iURL == KNullDesC)
       
   280                 {            
       
   281 			    iCurrentData->iURL.Set( aParameter.Value() );
       
   282                 }
       
   283 			break;
       
   284 
       
   285 		case EWPParameterAAuthName:
       
   286             if (iCurrentData->iUserID == KNullDesC)
       
   287                 {            
       
   288 			    iCurrentData->iUserID.Set( aParameter.Value() );
       
   289                 }
       
   290 			break;
       
   291 
       
   292 		case EWPParameterAAuthSecret:
       
   293             if (iCurrentData->iPassword == KNullDesC)
       
   294                 {            
       
   295 			    iCurrentData->iPassword.Set( aParameter.Value() );
       
   296                 }
       
   297 			break;
       
   298         // Here case 0 are handled the IM and Presence parameters that are extensions  
       
   299         // to OMA Client Provisioning parameter set.
       
   300         case 0:
       
   301             {
       
   302             FLOG( _L( "[Provisioning] CWPIMAdapter::VisitL Case 0" ) );
       
   303             TInt val = aParameter.Name().Match( KServicesName );
       
   304             if ( val >= 0 )
       
   305                 {
       
   306                 FLOG( _L( "[Provisioning] CWPIMAdapter::VisitL  Services" ) );
       
   307                 val = aParameter.Value().Match( KIMName );
       
   308                 if ( val >= 0 )
       
   309                     {
       
   310                     FLOG( _L( "[Provisioning] CWPIMAdapter::VisitL  Services IM settings" ) );
       
   311     	            iCurrentData->iProvLocation = EIMPSIMAccessGroup;
       
   312                     }
       
   313                 else 
       
   314                     {
       
   315                     FLOG( _L( "[Provisioning] CWPIMAdapter::VisitL  Services NO IM settings" ) );
       
   316                     // settings not for us...
       
   317                     iCurrentData->iProvLocation = EIMPSNoAccessGroup;
       
   318                     }
       
   319                 }
       
   320             }
       
   321             break;			
       
   322         default:
       
   323             break;
       
   324         }
       
   325 	}
       
   326 
       
   327 // -----------------------------------------------------------------------------
       
   328 // CWPIMAdapter::VisitLinkL
       
   329 // -----------------------------------------------------------------------------
       
   330 //
       
   331 void CWPIMAdapter::VisitLinkL( CWPCharacteristic& aLink )
       
   332 	{
       
   333   	switch( aLink.Type() )
       
   334 		{
       
   335 		case KWPNapDef: // fallthrough
       
   336 		case KWPPxLogical:
       
   337 			{
       
   338 			User::LeaveIfError( iCurrentData->iLinks.Append( &aLink ) );
       
   339    			break;
       
   340 			}
       
   341 		default:
       
   342 			break;
       
   343 		}
       
   344 	}
       
   345 
       
   346 // -----------------------------------------------------------------------------
       
   347 // CWPIMAdapter::ContextExtension
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 TInt CWPIMAdapter::ContextExtension( MWPContextExtension*& aExtension )
       
   351 	{
       
   352     aExtension = this;
       
   353     return KErrNone;
       
   354 	}
       
   355 
       
   356 // -----------------------------------------------------------------------------
       
   357 // CWPIMAdapter::SaveDataL
       
   358 // -----------------------------------------------------------------------------
       
   359 //
       
   360 const TDesC8& CWPIMAdapter::SaveDataL( TInt aIndex ) const
       
   361 	{
       
   362 	return iDatas[aIndex]->iSAPId;
       
   363 	}
       
   364 
       
   365 // -----------------------------------------------------------------------------
       
   366 // CWPIMAdapter::DeleteL
       
   367 // -----------------------------------------------------------------------------
       
   368 //
       
   369 void CWPIMAdapter::DeleteL( const TDesC8& aSaveData )
       
   370 	{
       
   371 	TPckgBuf<TUint32> pckg;
       
   372     pckg.Copy( aSaveData );
       
   373 
       
   374 	CWPIMSAPItem* sapItem = CWPIMSAPItem::NewLC( EIMPSIMAccessGroup );
       
   375 	sapItem->DeleteL( pckg() );
       
   376 	CleanupStack::PopAndDestroy( sapItem );   
       
   377 	}
       
   378 
       
   379 // -----------------------------------------------------------------------------
       
   380 // CWPIMAdapter::Uid
       
   381 // -----------------------------------------------------------------------------
       
   382 //
       
   383 TUint32 CWPIMAdapter::Uid() const
       
   384 	{
       
   385     return iDtor_ID_Key.iUid;
       
   386 	}
       
   387 
       
   388 //  End of File