sipplugins/sippsipadapter/src/CWPSIPAdapter.cpp
changeset 0 307788aac0a8
child 1 dd3853b8dc3f
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2004-2007 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 SIP settings in provisioning.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <CWPAdapter.h>
       
    22 #include <cwpcharacteristic.h>
       
    23 #include <cwpparameter.h>
       
    24 #include <wpsipadapter.rsg>
       
    25 #include <utf.h>           // Unicode conversion
       
    26 #include <wpadapterutil.h>
       
    27 #include <sipmanagedprofileregistry.h>
       
    28 #include <sipmanagedprofile.h>
       
    29 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    30 
       
    31 #include <cmmanagerext.h>
       
    32 #include <cmdestinationext.h>
       
    33 #include <cmconnectionmethoddef.h>
       
    34 
       
    35 #include "CSIPProfileRegistryObserver.h"
       
    36 #include "CWPSIPAdapter.h"      // own header
       
    37 #include "CWPSIPItem.h"
       
    38 #include "wpsipadapterdebug.h"
       
    39 
       
    40 // CONSTANTS
       
    41 _LIT( KSIPAdapterName,      "WPSIPAdapter" );
       
    42 _LIT( KSIPAppID,            "w9010" );
       
    43 _LIT8( KSIPAppID8,          "w9010" );
       
    44 _LIT8( KDestinationNwAppId, "w904C" ); // Destination Network settings APPID
       
    45 
       
    46 // SIP profile parameters, see w9010.txt
       
    47 _LIT( KParmPTYPE,      "PTYPE");
       
    48 _LIT( KParmPUID,       "PUID");
       
    49 _LIT( KParmSIGNALCMPR, "SIGNALCMPR" );
       
    50 _LIT( KParmSECNEG,     "SECNEG" );
       
    51 _LIT( KParmLR,         "LR" );
       
    52 _LIT( KParmLOCK,       "LOCK" );
       
    53 _LIT( KParmAUTOREG,    "AUTOREG" );
       
    54 _LIT( KParmSIGQOS,     "SIGQOS" );
       
    55 
       
    56 // For other purposes.
       
    57 const TUint32 KNotSet = 0xffffffff;
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CWPSIPAdapter::CWPSIPAdapter
       
    61 // 
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 CWPSIPAdapter::CWPSIPAdapter() : CWPAdapter()
       
    65     {
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CWPSIPAdapter::ConstructL
       
    70 // 
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 void CWPSIPAdapter::ConstructL()
       
    74     {
       
    75     DBG_PRINT( "CWPSIPAdapter::ConstructL - begin" );
       
    76     TFileName fileName;
       
    77     Dll::FileName( fileName );
       
    78     iDefaultName = WPAdapterUtil::ReadHBufCL( fileName, KSIPAdapterName, 
       
    79         R_QTN_SM_DEFAULT_NAME_SIP );
       
    80     iTitle = WPAdapterUtil::ReadHBufCL( fileName, KSIPAdapterName, 
       
    81         R_QTN_SM_HEAD_SIP );
       
    82     iProviderIdDefault = WPAdapterUtil::ReadHBufCL( fileName, KSIPAdapterName,
       
    83         R_QTN_SM_PROVIDER );
       
    84     iSIPIdForDefault = KNotSet;
       
    85     DBG_PRINT( "CWPSIPAdapter::ConstructL - end" );
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // CWPSIPAdapter::NewL
       
    90 // 
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 CWPSIPAdapter* CWPSIPAdapter::NewL()
       
    94     {
       
    95     CWPSIPAdapter* self = new( ELeave ) CWPSIPAdapter; 
       
    96     CleanupStack::PushL( self );
       
    97     self->ConstructL();
       
    98     CleanupStack::Pop( self );
       
    99     return self;
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CWPSIPAdapter::~CWPSIPAdapter
       
   104 // 
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 CWPSIPAdapter::~CWPSIPAdapter()
       
   108     {
       
   109     DBG_PRINT( "CWPSIPAdapter::~CWPSIPAdapter - begin" );
       
   110     delete iTitle;
       
   111     delete iProviderIdDefault;
       
   112     delete iDefaultName;
       
   113     delete iCurrentSIPItem;
       
   114     iDatas.ResetAndDestroy();
       
   115     iDatas.Close();
       
   116     iSIPIdArray.Reset();
       
   117     iSIPIdArray.Close();
       
   118     DBG_PRINT( "CWPSIPAdapter::~CWPSIPAdapter - end" );
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // CWPSIPAdapter::ContextExtension
       
   123 //
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 TInt CWPSIPAdapter::ContextExtension( MWPContextExtension*& aExtension )
       
   127     {
       
   128     aExtension = this;
       
   129     return KErrNone;
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // CWPSIPAdapter::SaveDataL
       
   134 //
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 const TDesC8& CWPSIPAdapter::SaveDataL( TInt aIndex ) const
       
   138     {
       
   139     return iDatas[aIndex]->SaveData();
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CWPSIPAdapter::DeleteL
       
   144 //
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 void CWPSIPAdapter::DeleteL( const TDesC8& aSaveData )
       
   148     {
       
   149     TUint tId;
       
   150     TLex8 lex( aSaveData );
       
   151     TInt err( KErrNone );            
       
   152     err = lex.Val( tId );
       
   153     if ( KErrNone == err )
       
   154         {
       
   155         CSIPProfileRegistryObserver* cSIPProfileRegistryObserver = 
       
   156             CSIPProfileRegistryObserver::NewLC();
       
   157         CSIPManagedProfileRegistry*  cSIPManagedProfileRegistry  = 
       
   158             CSIPManagedProfileRegistry::NewLC( *cSIPProfileRegistryObserver );
       
   159         CSIPProfile* cProfile = NULL;
       
   160         cProfile = cSIPManagedProfileRegistry->ProfileL( tId );
       
   161         CleanupStack::PushL( cProfile );
       
   162         cSIPManagedProfileRegistry->DestroyL( *cProfile );
       
   163         CleanupStack::PopAndDestroy( cProfile );
       
   164         cProfile = NULL;
       
   165         CleanupStack::PopAndDestroy( cSIPManagedProfileRegistry );
       
   166         CleanupStack::PopAndDestroy( cSIPProfileRegistryObserver );
       
   167         }// if
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // CWPSIPAdapter::Uid
       
   172 //
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 TUint32 CWPSIPAdapter::Uid() const
       
   176     {
       
   177     return iDtor_ID_Key.iUid; 
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // CWPSIPAdapter::DetailsL
       
   182 //
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 TInt CWPSIPAdapter::DetailsL( TInt /*aItem*/, MWPPairVisitor& /*aVisitor */ )
       
   186     {
       
   187     return KErrNotSupported;
       
   188     }  
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CWPSIPAdapter::SummaryCount
       
   192 //
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 TInt CWPSIPAdapter::ItemCount() const
       
   196     {
       
   197     return iDatas.Count();
       
   198     }
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // CWPSIPAdapter::SummaryTitle
       
   202 //
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 const TDesC16& CWPSIPAdapter::SummaryTitle( TInt /*aIndex*/ ) const
       
   206     {
       
   207     return *iTitle;
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // CWPSIPAdapter::SummaryText
       
   212 //
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 const TDesC16& CWPSIPAdapter::SummaryText( TInt aIndex ) const
       
   216     {
       
   217     // If there is no value for NAME parameter the default value is set here.
       
   218     if ( iDatas[aIndex]->GetName().Length() == 0 )
       
   219         {
       
   220         TRAP_IGNORE( iDatas[aIndex]->SetNameL( iDefaultName->Des() ) );
       
   221         }
       
   222     return iDatas[aIndex]->GetName();
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // CWPSIPAdapter::SaveL
       
   227 //
       
   228 // ---------------------------------------------------------------------------
       
   229 //
       
   230 void CWPSIPAdapter::SaveL( TInt aIndex )
       
   231     {
       
   232     DBG_PRINT( "CWPSIPAdapter::SaveL - begin" );
       
   233     // Getting the SIP item (SIP profile data) at given index.
       
   234     CWPSIPItem* sipItem = iDatas[aIndex];
       
   235 
       
   236     if ( sipItem->GetNapDef() )
       
   237         {
       
   238         // Get WAP ID.
       
   239         TPckgBuf<TUint32> uid;
       
   240         uid.Copy( sipItem->GetNapDef()->Data( 0 ) );
       
   241         
       
   242         TUint32 wapId( uid() );
       
   243         // Get corresponding IAP ID.
       
   244         TUint32 iapId = IapIdFromWapIdL( wapId );
       
   245         sipItem->SetIAPId( iapId );
       
   246         }
       
   247 
       
   248     // If the PROVIDER-ID was not received the default value is set.
       
   249     if ( sipItem->GetProviderId().Length() == 0 )
       
   250         {
       
   251         HBufC8* tmpProviderId8 = HBufC8::NewLC( 
       
   252             iProviderIdDefault->Length() ); // CS:1
       
   253         TPtr8   ptrProviderId( tmpProviderId8->Des() );
       
   254         ptrProviderId.Copy( iProviderIdDefault->Des() );
       
   255         sipItem->SetProviderIdL( tmpProviderId8->Des() );
       
   256         CleanupStack::PopAndDestroy( tmpProviderId8 ); // CS:0
       
   257         }
       
   258 
       
   259     sipItem->StoreL();
       
   260 
       
   261     // Set WLAN availability state. Setting WLAN availability is done in
       
   262     // SavingFinalizedL().
       
   263     if ( sipItem->GetAutomaticRegistrationEnabled() )
       
   264         {
       
   265         iSIPIdArray.AppendL( sipItem->GetProfileId() );
       
   266         }
       
   267     DBG_PRINT( "CWPSIPAdapter::SaveL - end" );
       
   268     }
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // CWPSIPAdapter::CanSetAsDefault
       
   272 //
       
   273 // ---------------------------------------------------------------------------
       
   274 //
       
   275 TBool CWPSIPAdapter::CanSetAsDefault( TInt /* aIndex */ ) const
       
   276     {
       
   277     TBool canSetAsDefault( 0 );
       
   278     TRAP_IGNORE( canSetAsDefault = CheckSettingAsDefaultL() );
       
   279     return canSetAsDefault;
       
   280     }
       
   281 
       
   282 // ---------------------------------------------------------------------------
       
   283 // CWPSIPAdapter::CheckSettingAsDefaultL
       
   284 //
       
   285 // ---------------------------------------------------------------------------
       
   286 //
       
   287 TBool CWPSIPAdapter::CheckSettingAsDefaultL() const
       
   288     {
       
   289     // Array of pointers to all loaded SIP profiles.
       
   290     CArrayPtrFlat<CSIPManagedProfile>* profiles;
       
   291 
       
   292     CSIPProfileRegistryObserver* cSIPProfileRegistryObserver = 
       
   293         CSIPProfileRegistryObserver::NewLC(); // CS:1
       
   294     CSIPManagedProfileRegistry*  cSIPManagedProfileRegistry = 
       
   295         CSIPManagedProfileRegistry::NewLC( *cSIPProfileRegistryObserver );
       
   296         // CS:2
       
   297     RArray<TSIPProfileTypeInfo> profileTypes;
       
   298     CleanupClosePushL( profileTypes ); // CS:3
       
   299 
       
   300      // Get the supported profile types.
       
   301     cSIPManagedProfileRegistry->SupportedProfileTypesL( profileTypes );
       
   302 
       
   303     // Create the profile pointer array.
       
   304     profiles = new ( ELeave ) CArrayPtrFlat<CSIPManagedProfile>( 5 );    
       
   305     TCleanupItem cleanupItem( CWPSIPItem::CleanupArrayItem, profiles );
       
   306     CleanupStack::PushL( cleanupItem ); // CS:4
       
   307 
       
   308     TInt i( 0 );
       
   309     RPointerArray<CSIPProfile> profilePointerArray;
       
   310     CleanupResetAndDestroyPushL( profilePointerArray ); // CS:5
       
   311 
       
   312     // Get all profiles based on profile types
       
   313     for ( i = 0; i < profileTypes.Count(); i++ )
       
   314         {        
       
   315         cSIPManagedProfileRegistry->ProfilesL( profileTypes[i], 
       
   316             profilePointerArray );
       
   317         TInt j( 0 );
       
   318         for ( j = 0; j < profilePointerArray.Count(); j++ )
       
   319             {
       
   320             CSIPManagedProfile* profile = 
       
   321                 static_cast<CSIPManagedProfile*>( profilePointerArray[j] );
       
   322             profiles->AppendL( profile ); 
       
   323             }                    
       
   324         profilePointerArray.Reset();
       
   325         }
       
   326     TInt profileCount = profiles->Count();   
       
   327 
       
   328     // &profilePointerArray, profiles, &profileTypes,
       
   329     // cSIPManagedProfileRegistry, cSIPProfileRegistryObserver
       
   330     CleanupStack::PopAndDestroy( 5, cSIPProfileRegistryObserver ); // CS:0
       
   331 
       
   332     if ( profileCount > 1 )
       
   333         {
       
   334         // Adapter supports setting profile as default when there are at least
       
   335         // one profile stored before.
       
   336         return ETrue;
       
   337         }
       
   338     else
       
   339         {
       
   340         // First profile always gets default, no need to ask question in UI.
       
   341         return EFalse;
       
   342         }
       
   343     }
       
   344 
       
   345 // ---------------------------------------------------------------------------
       
   346 // CWPSIPAdapter::SetAsDefaultL
       
   347 //
       
   348 // ---------------------------------------------------------------------------
       
   349 //
       
   350 void CWPSIPAdapter::SetAsDefaultL( TInt /* aIndex */ )
       
   351     {
       
   352     // Set messages first profile as default
       
   353     iDatas[0]->SetAsDefaultL();
       
   354     iDatas[0]->StoreL();
       
   355     }
       
   356 
       
   357 // ---------------------------------------------------------------------------
       
   358 // CWPSIPAdapter::VisitL
       
   359 //
       
   360 // ---------------------------------------------------------------------------
       
   361 //
       
   362 void CWPSIPAdapter::VisitL( CWPCharacteristic& aCharacteristic )
       
   363     {
       
   364     switch( aCharacteristic.Type() )
       
   365         {
       
   366         case KWPApplication:
       
   367             iCurrentCharacteristic = KWPApplication;
       
   368             iCurrentSIPItem = CWPSIPItem::NewL();
       
   369             aCharacteristic.AcceptL( *this );
       
   370 
       
   371             if ( iAppID == KSIPAppID )
       
   372                 {
       
   373                 User::LeaveIfError( iDatas.Append( iCurrentSIPItem ) );
       
   374                 }
       
   375             else
       
   376                 {
       
   377                 delete iCurrentSIPItem;
       
   378                 }
       
   379             iCurrentSIPItem = NULL;
       
   380             break;
       
   381 
       
   382         case KWPResource:
       
   383             iCurrentCharacteristic = KWPResource;
       
   384 			if ( iCurrentSIPItem )
       
   385                 {                
       
   386                 aCharacteristic.AcceptL( *this );
       
   387                 }
       
   388             break;
       
   389 
       
   390         case KWPNapDef:
       
   391             iCurrentCharacteristic = KWPNapDef;
       
   392 			if ( iCurrentSIPItem )
       
   393                 {                
       
   394                 aCharacteristic.AcceptL( *this );
       
   395                 }
       
   396             break;
       
   397 
       
   398         case KWPAppAddr:
       
   399             iCurrentCharacteristic = KWPAppAddr;
       
   400             if ( iCurrentSIPItem )
       
   401                 {                
       
   402                 aCharacteristic.AcceptL( *this );
       
   403                 }
       
   404             break;
       
   405 
       
   406         case KWPPort:
       
   407             iCurrentCharacteristic = KWPPort;
       
   408             if ( iCurrentSIPItem )
       
   409                 {                
       
   410                 aCharacteristic.AcceptL( *this );
       
   411                 }
       
   412             break;
       
   413 
       
   414         case KWPAppAuth:
       
   415             iCurrentCharacteristic = KWPAppAuth;
       
   416 			if ( iCurrentSIPItem )
       
   417                 {                
       
   418                 aCharacteristic.AcceptL( *this );
       
   419                 }
       
   420             break;
       
   421 
       
   422         default:
       
   423             break;
       
   424         }
       
   425     }
       
   426 
       
   427 // ---------------------------------------------------------------------------
       
   428 // CWPSIPAdapter::VisitL
       
   429 //
       
   430 // ---------------------------------------------------------------------------
       
   431 //
       
   432 void CWPSIPAdapter::VisitL( CWPParameter& aParameter )
       
   433     {
       
   434     DBG_PRINT("CWPSIPAdapter::VisitL( parameter ) - begin");
       
   435 
       
   436     if ( !iCurrentSIPItem )
       
   437         {
       
   438         User::Leave( KErrGeneral );
       
   439         }
       
   440     // tmpValue is created for holding value converted from Unicode to UTF8.
       
   441     HBufC8* tmpValue;
       
   442     tmpValue = HBufC8::NewL( aParameter.Value().Length() );
       
   443     CleanupStack::PushL( tmpValue ); // CS:1
       
   444     TPtr8 ptrTmpValue( tmpValue->Des() );
       
   445     ptrTmpValue.Copy( aParameter.Value() );
       
   446 
       
   447     switch ( aParameter.ID() )
       
   448         {
       
   449         case EWPParameterAppID:
       
   450             {
       
   451 		    iAppID.Set( aParameter.Value() );
       
   452             break;
       
   453             }
       
   454         // Here case 0 are handled the SIP parameters that are extensions to 
       
   455         // OMA Client Provisioning parameter set.
       
   456         case 0:
       
   457             {
       
   458             if ( aParameter.Name() == KParmPTYPE )
       
   459                 {
       
   460                 iCurrentSIPItem->SetProfileTypeL( tmpValue->Des() );
       
   461                 }
       
   462             else if ( aParameter.Name() == KParmPUID && 
       
   463                 iCurrentSIPItem->GetAOR().Length() == 0 )
       
   464                 {
       
   465                 iCurrentSIPItem->SetAORL( tmpValue->Des() );
       
   466                 }
       
   467             else if ( aParameter.Name() == KParmSIGNALCMPR && 
       
   468                 iCurrentSIPItem->GetSignalCompressionEnabled() == EFalse )
       
   469                 {
       
   470                 iCurrentSIPItem->SetSignalCompressionEnabled( ETrue );
       
   471                 }
       
   472             else if ( aParameter.Name() == KParmSECNEG && 
       
   473                 iCurrentSIPItem->GetSecurityNegotiationEnabled() == EFalse )
       
   474                 {
       
   475                 iCurrentSIPItem->SetSecurityNegotiationEnabled( ETrue );
       
   476                 }
       
   477             // Extensions to OMA parameters in APPDDR characteristics    
       
   478             else if ( aParameter.Name() == KParmLR && iCurrentSIPItem->
       
   479                 GetLooseRoutingForOutboundConnectionEnabled() == EFalse ) 
       
   480                 {
       
   481                 iCurrentSIPItem->SetLooseRoutingForOutboundConnectionEnabled( 
       
   482                     ETrue );
       
   483                 }
       
   484             else if ( aParameter.Name() == KParmLOCK ) 
       
   485                 {
       
   486                 iCurrentSIPItem->SetProfileLockEnabled( ETrue );
       
   487                 }
       
   488             else if ( aParameter.Name() == KParmAUTOREG && iCurrentSIPItem->
       
   489                 GetAutomaticRegistrationEnabled() == EFalse ) 
       
   490                 {
       
   491                 iCurrentSIPItem->SetAutomaticRegistrationEnabled( ETrue );
       
   492                 }
       
   493             else if ( aParameter.Name() == KParmSIGQOS )
       
   494                 {
       
   495                 TUint32 parmVal;
       
   496                 TLex8 lex( tmpValue->Des() );
       
   497                 TInt err( KErrNone );
       
   498                 err = lex.Val( parmVal, EDecimal );
       
   499                 if ( KErrNone == err )
       
   500                     {
       
   501                     iCurrentSIPItem->SetSigQos( parmVal );
       
   502                     }
       
   503                 }
       
   504             break;
       
   505             }
       
   506         case EWPParameterAppRef:
       
   507             {
       
   508             if ( iCurrentSIPItem->GetAppRef().Length() == 0 )
       
   509                 {
       
   510                 iCurrentSIPItem->SetAppRefL( tmpValue->Des() );
       
   511                 }// if
       
   512             break;
       
   513             }
       
   514         case EWPParameterURI:
       
   515             {
       
   516             if ( iCurrentCharacteristic == KWPResource && 
       
   517                 iCurrentSIPItem->GetRegistrarAddr().Length() == 0 )
       
   518                 {
       
   519                 iCurrentSIPItem->SetRegistrarAddrL( tmpValue->Des() );
       
   520                 }// if
       
   521             break;
       
   522             }
       
   523 
       
   524         case EWPParameterToNapID:
       
   525             {
       
   526             if ( iCurrentCharacteristic == KWPApplication && 
       
   527                 iCurrentSIPItem->GetNapDefName().Length() == 0 )
       
   528                 {
       
   529                 iCurrentSIPItem->SetNapDefNameL( tmpValue->Des() );
       
   530                 }// if
       
   531             break;
       
   532             }
       
   533         case EWPParameterName:
       
   534             {
       
   535             if ( iCurrentSIPItem->GetName().Length() == 0 )
       
   536                 {
       
   537                 iCurrentSIPItem->SetNameL( aParameter.Value() );
       
   538                 }
       
   539             break;
       
   540             }
       
   541 
       
   542         case EWPParameterProviderID:
       
   543             {
       
   544             if ( iCurrentSIPItem->GetProviderId().Length() == 0 )
       
   545                 {
       
   546                 iCurrentSIPItem->SetProviderIdL( tmpValue->Des() );
       
   547                 }
       
   548         break;
       
   549             }
       
   550 
       
   551         case EWPParameterAProtocol:
       
   552             {
       
   553             if ( iCurrentSIPItem->GetProtocolForOutboundConnection().Length()
       
   554                 == 0 )
       
   555                 {
       
   556                 iCurrentSIPItem->SetProtocolForOutboundConnectionL( 
       
   557                     tmpValue->Des() );
       
   558                 }
       
   559  			break;
       
   560             }
       
   561 
       
   562         case EWPParameterAddr:
       
   563             {
       
   564             if ( iCurrentCharacteristic == KWPAppAddr && 
       
   565                 iCurrentSIPItem->GetOutboundAddr().Length() == 0 )
       
   566                 {
       
   567                 iCurrentSIPItem->SetOutboundAddrL( tmpValue->Des() );
       
   568                 }
       
   569 			break;
       
   570             }
       
   571 
       
   572         case EWPParameterPortNbr:
       
   573             {
       
   574             if ( iCurrentCharacteristic == KWPPort && iCurrentSIPItem->
       
   575                 GetPortNumberForOutboundConnection().Length() == 0 )
       
   576                 {
       
   577                 iCurrentSIPItem->SetPortNumberForOutboundConnectionL(
       
   578                     tmpValue->Des() );
       
   579                 }
       
   580           break;
       
   581             }
       
   582 
       
   583         case EWPParameterAAuthType:
       
   584             {
       
   585             if ( iCurrentCharacteristic == KWPAppAuth && iCurrentSIPItem->
       
   586                 GetAuthenticationTypeForOutbound().Length() == 0 )
       
   587                 {
       
   588                 iCurrentSIPItem->SetAuthenticationTypeForOutboundL( 
       
   589                     tmpValue->Des() );
       
   590                 }
       
   591             else if ( iCurrentCharacteristic == KWPResource && 
       
   592                 iCurrentSIPItem->GetAuthenticationTypeForRegistrar().Length()
       
   593                 == 0 )
       
   594                 {
       
   595                 iCurrentSIPItem->SetAuthenticationTypeForRegistrarL( 
       
   596                     tmpValue->Des() );
       
   597                 }
       
   598             break;
       
   599             }
       
   600 
       
   601         case EWPParameterAAuthName:
       
   602             {
       
   603             if ( iCurrentCharacteristic == KWPAppAuth &&
       
   604                 iCurrentSIPItem->GetUsernameForOutbound().Length() == 0 )
       
   605                 {
       
   606                 iCurrentSIPItem->SetUsernameForOutboundL( tmpValue->Des() );
       
   607                 }
       
   608             else if ( iCurrentCharacteristic == KWPResource && 
       
   609                 iCurrentSIPItem->GetUsernameForRegistrar().Length() == 0 )
       
   610                 {
       
   611                 iCurrentSIPItem->SetUsernameForRegistrarL( tmpValue->Des() );
       
   612                 }
       
   613             break;
       
   614             }
       
   615 
       
   616         case EWPParameterAAuthSecret:
       
   617             {
       
   618             if ( iCurrentCharacteristic == KWPAppAuth &&
       
   619                 iCurrentSIPItem->GetPasswordForOutbound().Length() == 0 )
       
   620                 {
       
   621                 iCurrentSIPItem->SetPasswordForOutboundL(tmpValue->Des());
       
   622                 }
       
   623             else if ( iCurrentCharacteristic == KWPResource && 
       
   624                 iCurrentSIPItem->GetPasswordForRegistrar().Length() == 0 )
       
   625                 {
       
   626                 iCurrentSIPItem->SetPasswordForRegistrarL( tmpValue->Des() );
       
   627                 }
       
   628             break;
       
   629             }
       
   630 
       
   631         case EWPParameterAAuthData:
       
   632             {
       
   633             if ( iCurrentCharacteristic == KWPAppAuth && 
       
   634                 iCurrentSIPItem->GetRealmForOutbound().Length() == 0 )
       
   635                 {
       
   636                 iCurrentSIPItem->SetRealmForOutboundL(tmpValue->Des());
       
   637                 }
       
   638             else if ( iCurrentCharacteristic == KWPResource && 
       
   639                 iCurrentSIPItem->GetRealmForRegistrar().Length() == 0 )
       
   640                 {
       
   641                 iCurrentSIPItem->SetRealmForRegistrarL( tmpValue->Des() );
       
   642                 }
       
   643             break;
       
   644             }
       
   645 
       
   646         case EWPParameterToAppRef:
       
   647             {
       
   648             if ( !iCurrentSIPItem->ToAppRef().Length() )
       
   649                 {
       
   650                 iCurrentSIPItem->SetToAppRefL( tmpValue->Des() );
       
   651                 }
       
   652             break;
       
   653             }
       
   654 
       
   655         case EWPParameterNetwork:
       
   656             {
       
   657             if ( !iCurrentSIPItem->Network().Length() )
       
   658                 {
       
   659                 iCurrentSIPItem->SetNetworkL( aParameter.Value() );
       
   660                 }
       
   661             break;
       
   662             }
       
   663 
       
   664         default:
       
   665             break;
       
   666         }
       
   667     CleanupStack::PopAndDestroy( tmpValue );  // CS:0
       
   668     DBG_PRINT("CWPSIPAdapter::VisitL( parameter ) - end");
       
   669     }
       
   670 
       
   671 // ---------------------------------------------------------------------------
       
   672 // CWPSIPAdapter::VisitLinkL
       
   673 //
       
   674 // ---------------------------------------------------------------------------
       
   675 //
       
   676 void CWPSIPAdapter::VisitLinkL( CWPCharacteristic& aLink )
       
   677     {
       
   678     DBG_PRINT("CWPSIPAdapter::VisitLinkL - begin");
       
   679     switch( aLink.Type() )
       
   680         {
       
   681         case KWPNapDef:
       
   682             {            
       
   683             if ( !iCurrentSIPItem->GetNapDef() )
       
   684                 {
       
   685                 iCurrentSIPItem->SetNapDef( &aLink );
       
   686                 }
       
   687             break;
       
   688             }
       
   689         default:
       
   690             break;
       
   691         }
       
   692     DBG_PRINT("CWPSIPAdapter::VisitLinkL - end");
       
   693     }
       
   694 
       
   695 // ---------------------------------------------------------------------------
       
   696 // CWPSIPAdapter::GetSavingInfoL
       
   697 //
       
   698 // ---------------------------------------------------------------------------
       
   699 //
       
   700 void CWPSIPAdapter::GetSavingInfoL( TInt aIndex, 
       
   701                                     RPointerArray<HBufC8>& aSavingInfo )
       
   702     {
       
   703     // APPID into place [0].
       
   704     aSavingInfo.AppendL( KSIPAppID8().AllocL() );
       
   705     // APPREF into place [1].
       
   706     aSavingInfo.AppendL( iDatas[aIndex]->GetAppRef().AllocL() );
       
   707     // SIP Profile id into place [2].
       
   708     aSavingInfo.AppendL( iDatas[aIndex]->SaveData().AllocL() );
       
   709     }
       
   710 
       
   711 // ---------------------------------------------------------------------------
       
   712 // CWPSIPAdapter::SavingFinalizedL()
       
   713 //
       
   714 // ---------------------------------------------------------------------------
       
   715 //
       
   716 void CWPSIPAdapter::SavingFinalizedL()
       
   717     {
       
   718     DBG_PRINT( "CWPSIPAdapter::SavingFinalizedL - begin" );
       
   719     CSIPProfileRegistryObserver* cSIPProfileRegistryObserver = 
       
   720         CSIPProfileRegistryObserver::NewLC();
       
   721     CSIPManagedProfileRegistry* cSIPManagedProfileRegistry  = 
       
   722         CSIPManagedProfileRegistry::NewLC( *cSIPProfileRegistryObserver );
       
   723 
       
   724     // Go through SIP profiles and set autoregistration if needed.
       
   725     // Autoregistrable profile IDs are in iSIPIdArray.
       
   726     for ( TInt sipIdCounter = 0; sipIdCounter < iSIPIdArray.Count(); 
       
   727         sipIdCounter++ )
       
   728         {
       
   729         CSIPProfile* cProfile = NULL;
       
   730         cProfile = cSIPManagedProfileRegistry->ProfileL( 
       
   731             iSIPIdArray[sipIdCounter] );
       
   732         CSIPManagedProfile* cSIPManagedProfile = 
       
   733             static_cast<CSIPManagedProfile*>( cProfile );
       
   734         cSIPManagedProfile->SetParameter( KSIPAutoRegistration, ETrue );
       
   735         cSIPManagedProfileRegistry->SaveL( *cSIPManagedProfile );
       
   736         }
       
   737     iSIPIdArray.Reset(); 
       
   738     CleanupStack::PopAndDestroy( cSIPManagedProfileRegistry );
       
   739     CleanupStack::PopAndDestroy( cSIPProfileRegistryObserver );
       
   740     DBG_PRINT( "CWPSIPAdapter::SavingFinalizedL - end" );
       
   741     }
       
   742 
       
   743 // ---------------------------------------------------------------------------
       
   744 // CWPSIPAdapter::IapIdFromWapIdL
       
   745 // Returns IAP ID from WAP ID.
       
   746 // ---------------------------------------------------------------------------
       
   747 //
       
   748 TUint32 CWPSIPAdapter::IapIdFromWapIdL( TUint32 aWapId )
       
   749     {
       
   750     DBG_PRINT( "CWPSIPAdapter::IapIdFromWapIdL - begin" );
       
   751     RCmManagerExt cmManager;
       
   752     cmManager.OpenLC(); // CS:1
       
   753     RArray<TUint32> iapIds;
       
   754 
       
   755     TUint32 iapId( 0 );
       
   756 
       
   757     // First get all free IAP ID's.
       
   758     cmManager.ConnectionMethodL( iapIds );
       
   759     CleanupClosePushL( iapIds );  // CS:2
       
   760 
       
   761     // Then get IAP ID's from all destinations.
       
   762     RArray<TUint32> destIds;
       
   763     cmManager.AllDestinationsL( destIds );
       
   764     CleanupClosePushL( destIds );  // CS:3
       
   765     
       
   766     TInt destCount = destIds.Count();
       
   767     
       
   768     for ( TInt destIndex = 0; destIndex < destCount; destIndex++ )
       
   769         {
       
   770         RCmDestinationExt dest = cmManager.DestinationL( 
       
   771             destIds[destIndex] );
       
   772         
       
   773         CleanupClosePushL( dest ); // CS:4
       
   774         TInt cmCount = dest.ConnectionMethodCount();
       
   775         for ( TInt cmIndex = 0; cmIndex < cmCount; cmIndex++ )
       
   776             {
       
   777             TUint32 apId = dest.ConnectionMethodL( 
       
   778                 cmIndex ).GetIntAttributeL( CMManager::ECmIapId );
       
   779             iapIds.AppendL( apId );
       
   780             }
       
   781         CleanupStack::PopAndDestroy( &dest ); // CS:3
       
   782         }
       
   783     // Finally, go through all connection methods and find correct IAP ID.
       
   784     const TInt cmCount = iapIds.Count();
       
   785     for ( TInt counter = 0; counter < cmCount; counter++ )
       
   786         {
       
   787         TUint32 id = cmManager.GetConnectionMethodInfoIntL( 
       
   788             iapIds[counter], CMManager::ECmWapId );
       
   789 
       
   790         if ( id == aWapId )
       
   791             {
       
   792             iapId = iapIds[counter];
       
   793             // No need to go through rest of IAPs.
       
   794             break;
       
   795             }
       
   796         }
       
   797     
       
   798     // PopAndDestroy destIds, iapIds, cmManager.
       
   799     CleanupStack::PopAndDestroy( 3, &cmManager ); // CS:0
       
   800 
       
   801     DBG_PRINT( "CWPSIPAdapter::IapIdFromWapIdL - end" );
       
   802     return iapId;
       
   803     }
       
   804 
       
   805 // ---------------------------------------------------------------------------
       
   806 // CWPSIPAdapter::SettingsSavedL
       
   807 //
       
   808 // ---------------------------------------------------------------------------
       
   809 //
       
   810 void CWPSIPAdapter::SettingsSavedL( const TDesC8& aAppIdOfSavingItem,
       
   811     const TDesC8& aAppRef, const TDesC8& aStorageIdValue )
       
   812     {
       
   813     DBG_PRINT( "CWPSIPAdapter::SettingsSavedL - begin" );
       
   814     if ( 0 == aAppIdOfSavingItem.Compare( KDestinationNwAppId() ) )
       
   815         {
       
   816         TInt snapId;
       
   817         TLex8 lex( aStorageIdValue );
       
   818         User::LeaveIfError( lex.Val( snapId ) );
       
   819         for ( TInt counter = 0; counter < iDatas.Count(); counter++ )
       
   820             {
       
   821             if ( 0 == iDatas[counter]->ToAppRef().Compare( aAppRef ) )
       
   822                 {
       
   823                 // If SIP settings are already saved, i.e. profile ID exists,
       
   824                 // set SNAP ID to existing profile.
       
   825                 if ( iDatas[counter]->GetProfileId() )
       
   826                     {
       
   827                     CSIPProfileRegistryObserver* observer = 
       
   828                         CSIPProfileRegistryObserver::NewLC(); // CS:1
       
   829                     CSIPManagedProfileRegistry* registry  = 
       
   830                         CSIPManagedProfileRegistry::NewLC( *observer );// CS:2
       
   831                     CSIPProfile* profile = NULL;
       
   832                     profile = registry->ProfileL( 
       
   833                         iDatas[counter]->GetProfileId() );
       
   834                     CSIPManagedProfile* managedProfile = 
       
   835                         static_cast<CSIPManagedProfile*>( profile );
       
   836                     managedProfile->SetParameter( 
       
   837                         KSIPSnapId, (TUint32)snapId );
       
   838                     registry->SaveL( *managedProfile );
       
   839                     CleanupStack::PopAndDestroy( 2, observer ); // CS:0
       
   840                     }
       
   841                 else
       
   842                     {
       
   843                     iDatas[counter]->SetSnapId( snapId );
       
   844                     }
       
   845                 }
       
   846             }
       
   847         }
       
   848     DBG_PRINT( "CWPSIPAdapter::SettingsSavedL - end" );
       
   849     }
       
   850 
       
   851 //  End of File