sipplugins/sippsipadapter/src/CWPSIPItem.cpp
changeset 0 307788aac0a8
child 37 0295359a7673
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2002-2008 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:  Settings item for SIP settings, handles also the saving of
       
    15 *                settings item. 
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <wpsipadapter.rsg>
       
    22 #include <charconv.h>
       
    23 #include <sipprofile.h>
       
    24 #include <sipprofiletypeinfo.h>
       
    25 #include <sipmanagedprofileregistry.h>
       
    26 #include <sipprofileregistry.h>
       
    27 #include <sipmanagedprofile.h>
       
    28 #include <in_sock.h>                // TInetAddr, TSockAddr
       
    29 #include <sip.h>
       
    30 #include <WPAdapterUtil.h>
       
    31 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    32 
       
    33 #include "CWPSIPItem.h"
       
    34 #include "CSIPProfileRegistryObserver.h"
       
    35 #include "CWPSIPAdapter.h"
       
    36 #include "wpsipadapterdebug.h"
       
    37 
       
    38 #include <cmmanagerext.h>
       
    39 #include <cmdestinationext.h>
       
    40 #include <cmmanagerdef.h>
       
    41 #include <escapeutils.h>
       
    42 
       
    43 // CONSTANTS
       
    44 const TInt KMaxCharsInTUint32     = 10;
       
    45 const TInt KMaxProviderNameLength = 100;
       
    46 _LIT8( KPTypeIMS,           "IMS" ); // w9010.txt
       
    47 _LIT8( KImsPlugInName,      "ims" ); // SIP Profile Plugin name
       
    48 _LIT8( KPTypeNokiapreR5Ims, "NokiapreR5Ims" ); // for backward compatibility
       
    49 _LIT8( KPTypeIETF,          "IETF" ); // w9010.txt
       
    50 _LIT8( KColon,              ":" );
       
    51 _LIT8( KTransport,          ";transport=" ); // IETF RFC 3261
       
    52 _LIT8( KSip,                "sip:" ); // IETF RFC 3261
       
    53 _LIT8( KLr,                 ";lr" ); // IETF RFC 3261
       
    54 _LIT8( KOpenParenthesis,    "(" );
       
    55 _LIT8( KClosedParenthesis,  ")" );
       
    56 _LIT8( KSips,               "sips:" ); // IETF RFC 3261
       
    57 _LIT8( KEscaped,            "%" );
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CWPSIPItem::NewL
       
    61 //
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 CWPSIPItem* CWPSIPItem::NewL()
       
    65     {
       
    66     CWPSIPItem* self = new ( ELeave ) CWPSIPItem();
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69     CleanupStack::Pop( self );
       
    70     return self;
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CWPSIPItem::CWPSIPItem
       
    75 //
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 CWPSIPItem::CWPSIPItem()
       
    79     {
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CWPSIPItem::~CWPSIPItem
       
    84 //
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 CWPSIPItem::~CWPSIPItem()
       
    88     {
       
    89     DBG_PRINT( "CWPSIPItem::~CWPSIPItem - begin" );
       
    90     delete iProviderId;
       
    91     delete iName;
       
    92     delete iAppRef;
       
    93     delete iAOR;
       
    94     delete iProtocolForOutboundConnection;
       
    95     delete iNapDefName;
       
    96     delete iOutboundAddr;
       
    97     delete iPortNumberForOutboundConnection;
       
    98     delete iAuthenticationTypeForOutbound;
       
    99     delete iUsernameForOutbound;
       
   100     delete iPasswordForOutbound;
       
   101     delete iRealmForOutbound;
       
   102     delete iRegistrarAddr;
       
   103     delete iAuthenticationTypeForRegistrar;
       
   104     delete iUsernameForRegistrar;
       
   105     delete iPasswordForRegistrar;
       
   106     delete iRealmForRegistrar;
       
   107     delete iSavedProfileId;
       
   108     delete iToAppRef;
       
   109     delete iNetwork;
       
   110     DBG_PRINT( "CWPSIPItem::~CWPSIPItem - end" );
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // CWPSIPSAPItem::ConstructL
       
   115 //
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 void CWPSIPItem::ConstructL()
       
   119     { 
       
   120     DBG_PRINT( "CWPSIPItem::ConstructL - begin" );
       
   121     iProviderId                               = HBufC8::NewL( 0 );
       
   122     iName                                     = HBufC::NewL( 0 );
       
   123     iAppRef                                   = HBufC8::NewL( 0 );
       
   124     iAOR                                      = HBufC8::NewL( 0 );
       
   125     iProtocolForOutboundConnection            = HBufC8::NewL( 0 );
       
   126     iNapDefName                               = HBufC8::NewL( 0 );
       
   127     iSignalCompressionEnabled                 = EFalse;
       
   128     iSecurityNegotiationEnabled               = EFalse;
       
   129     iLooseRoutingForOutboundConnectionEnabled = EFalse;
       
   130     iOutboundAddr                             = HBufC8::NewL( 0 );
       
   131     iPortNumberForOutboundConnection          = HBufC8::NewL( 0 );
       
   132     iAuthenticationTypeForOutbound            = HBufC8::NewL( 0 );
       
   133     iUsernameForOutbound                      = HBufC8::NewL( 0 );
       
   134     iPasswordForOutbound                      = HBufC8::NewL( 0 );
       
   135     iRealmForOutbound                         = HBufC8::NewL( 0 );
       
   136     iRegistrarAddr                            = HBufC8::NewL( 0 );
       
   137     iAuthenticationTypeForRegistrar           = HBufC8::NewL( 0 );
       
   138     iUsernameForRegistrar                     = HBufC8::NewL( 0 );
       
   139     iPasswordForRegistrar                     = HBufC8::NewL( 0 );
       
   140     iRealmForRegistrar                        = HBufC8::NewL( 0 );
       
   141     iNapDef                                   = NULL;
       
   142     iSetAsDefault                             = EFalse;
       
   143     iSavedProfileId                           = HBufC8::NewL( 0 );
       
   144     iProfileId                                = 0;
       
   145     iProfileLockEnabled                       = EFalse;
       
   146     iToAppRef                                 = HBufC8::NewL( 0 );
       
   147     iNetwork                                  = HBufC::NewL( 0 );
       
   148     iSnapId                                   = KErrNotFound;
       
   149     SetSigQos( 40 );
       
   150     DBG_PRINT( "CWPSIPItem::ConstructL - end" );
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // CWPSIPItem::SetProfileTypeL
       
   155 //
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 void CWPSIPItem::SetProfileTypeL( const TDesC8& aPTYPE )
       
   159     {
       
   160     HBufC8* tmpProfileType = aPTYPE.AllocL();
       
   161     CleanupStack::PushL( tmpProfileType ); // CS:1
       
   162     // Map the profile type name used in message to SIP stack internal type.
       
   163     if ( ( ( tmpProfileType->Compare( KPTypeIMS() ) ) == 0 ) ||
       
   164         ( tmpProfileType->Compare( KPTypeNokiapreR5Ims ) == 0 ) )
       
   165         {
       
   166         iSIPProfileTypeInfo.iSIPProfileClass = TSIPProfileTypeInfo::EIms;
       
   167         iSIPProfileTypeInfo.iSIPProfileName.Insert( 0, KImsPlugInName() );
       
   168         }
       
   169     else if ( ( tmpProfileType->Compare( KPTypeIETF() ) ) == 0 )
       
   170         {
       
   171         iSIPProfileTypeInfo.iSIPProfileClass = TSIPProfileTypeInfo::EInternet;
       
   172         iSIPProfileTypeInfo.iSIPProfileName.Insert( 0,tmpProfileType->Des() );
       
   173         }
       
   174     else
       
   175         {
       
   176         iSIPProfileTypeInfo.iSIPProfileClass = TSIPProfileTypeInfo::EOther;
       
   177         iSIPProfileTypeInfo.iSIPProfileName.Insert( 0,tmpProfileType->Des() );
       
   178         }
       
   179     CleanupStack::PopAndDestroy( tmpProfileType ); // CS:0
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // CWPSIPItem::SetAppRefL
       
   184 //
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 void CWPSIPItem::SetAppRefL( const TDesC8& aAPPREF )
       
   188     {
       
   189     HBufC8* temp = aAPPREF.AllocL();
       
   190     delete iAppRef;
       
   191     iAppRef = NULL;
       
   192     iAppRef = temp;
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // CWPSIPItem::SetAORL
       
   197 //
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 void CWPSIPItem::SetAORL( const TDesC8& aPUID )
       
   201     {
       
   202     HBufC8* temp( NULL );
       
   203     
       
   204     if ( KErrNotFound == aPUID.Find( KEscaped() ) )
       
   205         {
       
   206         temp = EscapeUtils::EscapeEncodeL( aPUID,
       
   207             EscapeUtils::EEscapeNormal );
       
   208         }
       
   209     else
       
   210         {
       
   211         temp = aPUID.AllocL();
       
   212         }
       
   213     
       
   214     delete iAOR;
       
   215     iAOR = NULL;
       
   216     
       
   217     // If the PUID starts with sip: or sips:
       
   218     if ( KErrNone == temp->Find( KSip() ) ||
       
   219          KErrNone == temp->Find( KSips() ) )
       
   220         {
       
   221         iAOR = temp;
       
   222         }
       
   223     else
       
   224         {
       
   225         CleanupStack::PushL( temp ); // CS: 1
       
   226         
       
   227         iAOR = HBufC8::NewL( KSip().Length() + temp->Length() );
       
   228         iAOR->Des().Copy( KSip() );
       
   229         iAOR->Des().Append( *temp );
       
   230         
       
   231         CleanupStack::PopAndDestroy( temp );  // CS: 0
       
   232         }
       
   233     }
       
   234 
       
   235 // ---------------------------------------------------------------------------
       
   236 // CWPSIPItem::SetNameL
       
   237 //
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 void CWPSIPItem::SetNameL( const TDesC& aNAME )
       
   241     {
       
   242     HBufC* temp = aNAME.AllocL();
       
   243     delete iName;
       
   244     iName = NULL;
       
   245     iName = temp;
       
   246     }
       
   247 
       
   248 // ---------------------------------------------------------------------------
       
   249 // CWPSIPItem::SetProviderIdL
       
   250 //
       
   251 // ---------------------------------------------------------------------------
       
   252 //
       
   253 void CWPSIPItem::SetProviderIdL( const TDesC8& aPROVIDERID )
       
   254     {
       
   255     HBufC8* temp = aPROVIDERID.AllocL();
       
   256     delete iProviderId;
       
   257     iProviderId = NULL;
       
   258     iProviderId = temp;
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // CWPSIPItem::SetProtocolForOutboundConnectionL
       
   263 //
       
   264 // ---------------------------------------------------------------------------
       
   265 //
       
   266 void CWPSIPItem::SetProtocolForOutboundConnectionL( const TDesC8& aAPROTOCOL )
       
   267     {
       
   268     HBufC8* temp = aAPROTOCOL.AllocL();
       
   269     delete iProtocolForOutboundConnection;
       
   270     iProtocolForOutboundConnection = NULL;
       
   271     iProtocolForOutboundConnection = temp;
       
   272     }
       
   273 
       
   274 // ---------------------------------------------------------------------------
       
   275 // CWPSIPItem::SetNapDefNameL
       
   276 //
       
   277 // ---------------------------------------------------------------------------
       
   278 //
       
   279 void CWPSIPItem::SetNapDefNameL( const TDesC8& aTONAPID )
       
   280     {
       
   281     HBufC8* temp = aTONAPID.AllocL();
       
   282     delete iNapDefName;
       
   283     iNapDefName = NULL;
       
   284     iNapDefName = temp;
       
   285     }
       
   286 
       
   287 // ---------------------------------------------------------------------------
       
   288 // CWPSIPItem::SetSignalCompressionEnabled
       
   289 //
       
   290 // ---------------------------------------------------------------------------
       
   291 //
       
   292 void CWPSIPItem::SetSignalCompressionEnabled( TBool aEnabled )
       
   293     {
       
   294     iSignalCompressionEnabled = aEnabled;
       
   295     }
       
   296 
       
   297 // ---------------------------------------------------------------------------
       
   298 // CWPSIPItem::SetSecurityNegotiationEnabled
       
   299 //
       
   300 // ---------------------------------------------------------------------------
       
   301 //
       
   302 void CWPSIPItem::SetSecurityNegotiationEnabled( TBool aEnabled )
       
   303     {
       
   304     iSecurityNegotiationEnabled = aEnabled;
       
   305     }
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 // CWPSIPItem::SetLooseRoutingForOutboundConnectionEnabled
       
   309 //
       
   310 // ---------------------------------------------------------------------------
       
   311 //
       
   312 void CWPSIPItem::SetLooseRoutingForOutboundConnectionEnabled( TBool aEnabled )
       
   313     {
       
   314     iLooseRoutingForOutboundConnectionEnabled = aEnabled;
       
   315     }
       
   316     
       
   317 // ---------------------------------------------------------------------------
       
   318 // CWPSIPItem::SetProfileLockEnabled
       
   319 //
       
   320 // ---------------------------------------------------------------------------
       
   321 //
       
   322 void CWPSIPItem::SetProfileLockEnabled( TBool aEnabled )
       
   323     {
       
   324     iProfileLockEnabled = aEnabled;
       
   325     }
       
   326 
       
   327 // ---------------------------------------------------------------------------
       
   328 // CWPSIPItem::SetOutboundAddrL
       
   329 //
       
   330 // ---------------------------------------------------------------------------
       
   331 //
       
   332 void CWPSIPItem::SetOutboundAddrL( const TDesC8& aOutboundAddr )
       
   333     {
       
   334     // If the parameter is empty, do not add prefix.
       
   335     if ( !aOutboundAddr.Length() )
       
   336         {
       
   337         return;
       
   338         }
       
   339 
       
   340     delete iOutboundAddr;
       
   341     iOutboundAddr = NULL;
       
   342     // Check if the address starts with sip: or sips:
       
   343     if ( KErrNone == aOutboundAddr.Find( KSip() ) ||
       
   344          KErrNone == aOutboundAddr.Find( KSips() ) )
       
   345         {
       
   346         iOutboundAddr = aOutboundAddr.AllocL();
       
   347         }
       
   348     else
       
   349         {
       
   350         iOutboundAddr = HBufC8::NewL( KSip().Length() + 
       
   351             aOutboundAddr.Length() );
       
   352         iOutboundAddr->Des().Copy( KSip() );
       
   353         iOutboundAddr->Des().Append( aOutboundAddr );
       
   354         }
       
   355     }
       
   356 
       
   357 // ---------------------------------------------------------------------------
       
   358 // CWPSIPItem::SetPortNumberForOutboundConnectionL
       
   359 //
       
   360 // ---------------------------------------------------------------------------
       
   361 //
       
   362 void CWPSIPItem::SetPortNumberForOutboundConnectionL( const TDesC8& aPORT )
       
   363     {
       
   364     HBufC8* temp = aPORT.AllocL();
       
   365     delete iPortNumberForOutboundConnection;
       
   366     iPortNumberForOutboundConnection = NULL;
       
   367     iPortNumberForOutboundConnection = temp;
       
   368     }
       
   369 
       
   370 // ---------------------------------------------------------------------------
       
   371 // CWPSIPItem::SetAuthenticationTypeForOutboundL
       
   372 //
       
   373 // ---------------------------------------------------------------------------
       
   374 //
       
   375 void CWPSIPItem::SetAuthenticationTypeForOutboundL( const TDesC8& aAAUTHTYPE )
       
   376     {
       
   377     HBufC8* temp = aAAUTHTYPE.AllocL();
       
   378     delete iAuthenticationTypeForOutbound;
       
   379     iAuthenticationTypeForOutbound = NULL;
       
   380     iAuthenticationTypeForOutbound = temp;
       
   381     }
       
   382 
       
   383 // ---------------------------------------------------------------------------
       
   384 // CWPSIPItem::SetUsernameForOutboundL
       
   385 //
       
   386 // ---------------------------------------------------------------------------
       
   387 //
       
   388 void CWPSIPItem::SetUsernameForOutboundL( const TDesC8& aAAUTHNAME )
       
   389     {
       
   390     HBufC8* temp( NULL );
       
   391     
       
   392     if ( KErrNotFound == aAAUTHNAME.Find( KEscaped() ) )
       
   393         {
       
   394         temp = EscapeUtils::EscapeEncodeL( aAAUTHNAME,
       
   395             EscapeUtils::EEscapeNormal );
       
   396         }
       
   397     else
       
   398         {
       
   399         temp = aAAUTHNAME.AllocL();
       
   400         }
       
   401     
       
   402     delete iUsernameForOutbound;
       
   403     iUsernameForOutbound = NULL;
       
   404     iUsernameForOutbound = temp;
       
   405     }
       
   406 
       
   407 // ---------------------------------------------------------------------------
       
   408 // CWPSIPItem::SetPasswordForOutboundL
       
   409 //
       
   410 // ---------------------------------------------------------------------------
       
   411 //
       
   412 void CWPSIPItem::SetPasswordForOutboundL( const TDesC8& aAAUTHSECRET )
       
   413     {
       
   414     HBufC8* temp = aAAUTHSECRET.AllocL();
       
   415     delete iPasswordForOutbound;
       
   416     iPasswordForOutbound = NULL;
       
   417     iPasswordForOutbound = temp;
       
   418     }
       
   419 
       
   420 // ---------------------------------------------------------------------------
       
   421 // CWPSIPItem::SetRealmForOutboundL
       
   422 //
       
   423 // ---------------------------------------------------------------------------
       
   424 //
       
   425 void CWPSIPItem::SetRealmForOutboundL( const TDesC8& aAAUTHDATA )
       
   426     {
       
   427     HBufC8* temp = aAAUTHDATA.AllocL();
       
   428     delete iRealmForOutbound;
       
   429     iRealmForOutbound = NULL;
       
   430     iRealmForOutbound = temp;
       
   431     }
       
   432 
       
   433 // ---------------------------------------------------------------------------
       
   434 // CWPSIPItem::SetRegistrarAddrL
       
   435 //
       
   436 // ---------------------------------------------------------------------------
       
   437 //
       
   438 void CWPSIPItem::SetRegistrarAddrL( const TDesC8& aRegistrarAddr )
       
   439     {
       
   440     // If the paremeter is empty, do not add prefix.
       
   441     if ( !aRegistrarAddr.Length() )
       
   442         {
       
   443         return;
       
   444         }
       
   445 
       
   446     delete iRegistrarAddr;
       
   447     iRegistrarAddr = NULL;
       
   448     // Check if the address starts with sip: or sips:
       
   449     if ( KErrNone == aRegistrarAddr.Find( KSip() ) ||
       
   450          KErrNone == aRegistrarAddr.Find( KSips() ) )
       
   451         {
       
   452         iRegistrarAddr = aRegistrarAddr.AllocL();
       
   453         }
       
   454     else
       
   455         {
       
   456         iRegistrarAddr = HBufC8::NewL( KSip().Length() + 
       
   457             aRegistrarAddr.Length() );
       
   458         iRegistrarAddr->Des().Copy( KSip() );
       
   459         iRegistrarAddr->Des().Append( aRegistrarAddr );
       
   460         }
       
   461     }
       
   462 
       
   463 // ---------------------------------------------------------------------------
       
   464 // CWPSIPItem::SetAuthenticationTypeForRegistrarL
       
   465 //
       
   466 // ---------------------------------------------------------------------------
       
   467 //
       
   468 void CWPSIPItem::SetAuthenticationTypeForRegistrarL( const TDesC8& 
       
   469     aAAUTHTYPE )
       
   470     {
       
   471     HBufC8* temp = aAAUTHTYPE.AllocL();
       
   472     delete iAuthenticationTypeForRegistrar;
       
   473     iAuthenticationTypeForRegistrar = NULL;
       
   474     iAuthenticationTypeForRegistrar = temp;
       
   475     }
       
   476 
       
   477 // ---------------------------------------------------------------------------
       
   478 // CWPSIPItem::SetUsernameForRegistrarL
       
   479 //
       
   480 // ---------------------------------------------------------------------------
       
   481 //
       
   482 void CWPSIPItem::SetUsernameForRegistrarL( const TDesC8& aAAUTHNAME )
       
   483     {
       
   484     HBufC8* temp( NULL );
       
   485     
       
   486     if ( KErrNotFound == aAAUTHNAME.Find( KEscaped() ) )
       
   487         {
       
   488         temp = EscapeUtils::EscapeEncodeL( aAAUTHNAME,
       
   489             EscapeUtils::EEscapeNormal );
       
   490         }
       
   491     else
       
   492         {
       
   493         temp = aAAUTHNAME.AllocL();
       
   494         }
       
   495     
       
   496     delete iUsernameForRegistrar;
       
   497     iUsernameForRegistrar = NULL;
       
   498     iUsernameForRegistrar = temp;
       
   499     }
       
   500 
       
   501 // ---------------------------------------------------------------------------
       
   502 // CWPSIPItem::SetPasswordForRegistrarL
       
   503 //
       
   504 // ---------------------------------------------------------------------------
       
   505 //
       
   506 void CWPSIPItem::SetPasswordForRegistrarL( const TDesC8& aAAUTHSECRET )
       
   507     {
       
   508     HBufC8* temp = aAAUTHSECRET.AllocL();
       
   509     delete iPasswordForRegistrar;
       
   510     iPasswordForRegistrar = NULL;
       
   511     iPasswordForRegistrar = temp;
       
   512     }
       
   513 
       
   514 // ---------------------------------------------------------------------------
       
   515 // CWPSIPItem::SetRealmForRegistrarL
       
   516 //
       
   517 // ---------------------------------------------------------------------------
       
   518 //
       
   519 void CWPSIPItem::SetRealmForRegistrarL( const TDesC8& aAAUTHDATA )
       
   520     {
       
   521     HBufC8* temp = aAAUTHDATA.AllocL();
       
   522     delete iRealmForRegistrar;
       
   523     iRealmForRegistrar = NULL;
       
   524     iRealmForRegistrar = temp;
       
   525     }
       
   526 
       
   527 // ---------------------------------------------------------------------------
       
   528 // CWPSIPItem::SetNapDef
       
   529 //
       
   530 // ---------------------------------------------------------------------------
       
   531 //
       
   532 void CWPSIPItem::SetNapDef( CWPCharacteristic* aNapDef )
       
   533     {
       
   534     iNapDef = aNapDef;
       
   535     }
       
   536 
       
   537 // ---------------------------------------------------------------------------
       
   538 // CWPSIPItem::SetAsDefaultL
       
   539 //
       
   540 // ---------------------------------------------------------------------------
       
   541 //
       
   542 void CWPSIPItem::SetAsDefaultL()
       
   543     {
       
   544     iSetAsDefault = ETrue;
       
   545     }
       
   546 
       
   547 // ---------------------------------------------------------------------------
       
   548 // CWPSIPSAPItem::SetIAPId
       
   549 //
       
   550 // ---------------------------------------------------------------------------
       
   551 //
       
   552 void CWPSIPItem::SetIAPId( TUint32 aUid )
       
   553     {
       
   554     iIAPId = aUid;
       
   555     }
       
   556 
       
   557 // ---------------------------------------------------------------------------
       
   558 // CWPSIPSAPItem::SetAutomaticRegistrationEnabled
       
   559 //
       
   560 // ---------------------------------------------------------------------------
       
   561 //
       
   562 void CWPSIPItem::SetAutomaticRegistrationEnabled( 
       
   563     TBool aAutomaticRegistrationEnabled )
       
   564     {
       
   565     iAutomaticRegistrationEnabled = aAutomaticRegistrationEnabled;
       
   566     }
       
   567 
       
   568 // ---------------------------------------------------------------------------
       
   569 // CWPSIPItem::GetAOR
       
   570 //
       
   571 // ---------------------------------------------------------------------------
       
   572 //
       
   573 TDesC8& CWPSIPItem::GetAOR()
       
   574     {
       
   575     return *iAOR;
       
   576     }
       
   577 
       
   578 // ---------------------------------------------------------------------------
       
   579 // CWPSIPItem::GetProviderId
       
   580 //
       
   581 // ---------------------------------------------------------------------------
       
   582 //
       
   583 TDesC8& CWPSIPItem::GetProviderId()
       
   584     {
       
   585     return *iProviderId;
       
   586     }
       
   587 
       
   588 // ---------------------------------------------------------------------------
       
   589 // CWPSIPItem::GetName
       
   590 //
       
   591 // ---------------------------------------------------------------------------
       
   592 //
       
   593 TDesC& CWPSIPItem::GetName()
       
   594     {
       
   595     return *iName;
       
   596     }
       
   597 
       
   598 // ---------------------------------------------------------------------------
       
   599 // CWPSIPItem::GetProtocolForOutboundConnection
       
   600 //
       
   601 // ---------------------------------------------------------------------------
       
   602 //
       
   603 TDesC8& CWPSIPItem::GetProtocolForOutboundConnection()
       
   604     {
       
   605     return *iProtocolForOutboundConnection;
       
   606     }
       
   607 
       
   608 // ---------------------------------------------------------------------------
       
   609 // CWPSIPItem::GetNapDefName
       
   610 //
       
   611 // ---------------------------------------------------------------------------
       
   612 //
       
   613 TDesC8& CWPSIPItem::GetNapDefName()
       
   614     {
       
   615     return *iNapDefName;
       
   616     }
       
   617 
       
   618 // ---------------------------------------------------------------------------
       
   619 // CWPSIPItem::GetSignalCompressionEnabled
       
   620 //
       
   621 // ---------------------------------------------------------------------------
       
   622 //
       
   623 TBool CWPSIPItem::GetSignalCompressionEnabled()
       
   624     {
       
   625     return iSignalCompressionEnabled;
       
   626     }
       
   627 
       
   628 // ---------------------------------------------------------------------------
       
   629 // CWPSIPItem::GetSecurityNegotiationEnabled
       
   630 //
       
   631 // ---------------------------------------------------------------------------
       
   632 //
       
   633 TBool CWPSIPItem::GetSecurityNegotiationEnabled()
       
   634     {
       
   635     return iSecurityNegotiationEnabled;
       
   636     }
       
   637 
       
   638 // ---------------------------------------------------------------------------
       
   639 // CWPSIPItem::GetLooseRoutingForOutboundConnectionEnabled
       
   640 //
       
   641 // ---------------------------------------------------------------------------
       
   642 //
       
   643 TBool CWPSIPItem::GetLooseRoutingForOutboundConnectionEnabled()
       
   644     {
       
   645     return iLooseRoutingForOutboundConnectionEnabled;
       
   646     }
       
   647     
       
   648 // ---------------------------------------------------------------------------
       
   649 // CWPSIPItem::GetAutomaticRegistrationEnabled
       
   650 //
       
   651 // ---------------------------------------------------------------------------
       
   652 //
       
   653 TBool CWPSIPItem::GetAutomaticRegistrationEnabled()
       
   654     {
       
   655     return iAutomaticRegistrationEnabled;
       
   656     }
       
   657 
       
   658 // ---------------------------------------------------------------------------
       
   659 // CWPSIPItem::GetProfileLockEnabled
       
   660 //
       
   661 // ---------------------------------------------------------------------------
       
   662 //
       
   663 TBool CWPSIPItem::GetProfileLockEnabled()
       
   664     {
       
   665     return iProfileLockEnabled;
       
   666     }
       
   667 
       
   668 // ---------------------------------------------------------------------------
       
   669 // CWPSIPItem::GetOutboundAddr
       
   670 //
       
   671 // ---------------------------------------------------------------------------
       
   672 //
       
   673 TDesC8& CWPSIPItem::GetOutboundAddr()
       
   674     {
       
   675     return *iOutboundAddr;
       
   676     }
       
   677 
       
   678 // ---------------------------------------------------------------------------
       
   679 // CWPSIPItem::GetPortNumberForOutboundConnection
       
   680 //
       
   681 // ---------------------------------------------------------------------------
       
   682 //
       
   683 TDesC8& CWPSIPItem::GetPortNumberForOutboundConnection()
       
   684     {
       
   685     return *iPortNumberForOutboundConnection;
       
   686     }
       
   687 
       
   688 // ---------------------------------------------------------------------------
       
   689 // CWPSIPItem::GetAuthenticationTypeForOutbound
       
   690 //
       
   691 // ---------------------------------------------------------------------------
       
   692 //
       
   693 TDesC8& CWPSIPItem::GetAuthenticationTypeForOutbound()
       
   694     {
       
   695     return *iAuthenticationTypeForOutbound;
       
   696     }
       
   697 
       
   698 // ---------------------------------------------------------------------------
       
   699 // CWPSIPItem::GetUsernameForOutbound
       
   700 //
       
   701 // ---------------------------------------------------------------------------
       
   702 //
       
   703 TDesC8& CWPSIPItem::GetUsernameForOutbound()
       
   704     {
       
   705     return *iUsernameForOutbound;
       
   706     }
       
   707 
       
   708 // ---------------------------------------------------------------------------
       
   709 // CWPSIPItem::GetPasswordForOutbound
       
   710 //
       
   711 // ---------------------------------------------------------------------------
       
   712 //
       
   713 TDesC8& CWPSIPItem::GetPasswordForOutbound()
       
   714     {
       
   715     return *iPasswordForOutbound;
       
   716     }
       
   717 
       
   718 // ---------------------------------------------------------------------------
       
   719 // CWPSIPItem::GetRealmForOutbound
       
   720 //
       
   721 // ---------------------------------------------------------------------------
       
   722 //
       
   723 TDesC8& CWPSIPItem::GetRealmForOutbound()
       
   724     {
       
   725     return *iRealmForOutbound;
       
   726     }
       
   727 
       
   728 // ---------------------------------------------------------------------------
       
   729 // CWPSIPItem::GetRegistrarAddr
       
   730 //
       
   731 // ---------------------------------------------------------------------------
       
   732 //
       
   733 TDesC8& CWPSIPItem::GetRegistrarAddr()
       
   734     {
       
   735     return *iRegistrarAddr;
       
   736     }
       
   737 
       
   738 // ---------------------------------------------------------------------------
       
   739 // CWPSIPItem::GetAuthenticationTypeForRegistrar
       
   740 //
       
   741 // ---------------------------------------------------------------------------
       
   742 //
       
   743 TDesC8& CWPSIPItem::GetAuthenticationTypeForRegistrar()
       
   744     {
       
   745     return *iAuthenticationTypeForRegistrar;
       
   746     }
       
   747 
       
   748 // ---------------------------------------------------------------------------
       
   749 // CWPSIPItem::GetUsernameForRegistrar
       
   750 //
       
   751 // ---------------------------------------------------------------------------
       
   752 //
       
   753 TDesC8& CWPSIPItem::GetUsernameForRegistrar()
       
   754     {
       
   755     return *iUsernameForRegistrar;
       
   756     }
       
   757 
       
   758 // ---------------------------------------------------------------------------
       
   759 // CWPSIPItem::GetPasswordForRegistrar
       
   760 //
       
   761 // ---------------------------------------------------------------------------
       
   762 //
       
   763 TDesC8& CWPSIPItem::GetPasswordForRegistrar()
       
   764     {
       
   765     return *iPasswordForRegistrar;
       
   766     }
       
   767 
       
   768 // ---------------------------------------------------------------------------
       
   769 // CWPSIPItem::GetRealmForRegistrar
       
   770 //
       
   771 // ---------------------------------------------------------------------------
       
   772 //
       
   773 TDesC8& CWPSIPItem::GetRealmForRegistrar()
       
   774     {
       
   775     return *iRealmForRegistrar;
       
   776     }
       
   777 
       
   778 // ---------------------------------------------------------------------------
       
   779 // CWPSIPItem::GetNapDef
       
   780 //
       
   781 // ---------------------------------------------------------------------------
       
   782 //
       
   783 CWPCharacteristic* CWPSIPItem::GetNapDef()
       
   784     {
       
   785     return iNapDef;
       
   786     }
       
   787 
       
   788 // ---------------------------------------------------------------------------
       
   789 // CWPSIPItem::GetProfileId
       
   790 //
       
   791 // ---------------------------------------------------------------------------
       
   792 //
       
   793 TUint32 CWPSIPItem::GetProfileId()
       
   794     {
       
   795     return iProfileId;
       
   796     }
       
   797 
       
   798 // ---------------------------------------------------------------------------
       
   799 // CWPSIPItem::GetRefId
       
   800 //
       
   801 // ---------------------------------------------------------------------------
       
   802 //
       
   803 TDesC8& CWPSIPItem::GetAppRef()
       
   804     {
       
   805     return *iAppRef;
       
   806     }
       
   807     
       
   808 // ---------------------------------------------------------------------------
       
   809 // CWPSIPSAPItem::GetIAPId
       
   810 //
       
   811 // ---------------------------------------------------------------------------
       
   812 //
       
   813 TUint32 CWPSIPItem::GetIAPId()
       
   814     {
       
   815     return iIAPId;
       
   816     }
       
   817 
       
   818 // ---------------------------------------------------------------------------
       
   819 // CWPSIPItem::StoreL()
       
   820 // Saves the SIP settings by using SIP Profile API and SIP API. 
       
   821 // ---------------------------------------------------------------------------
       
   822 //
       
   823 TUint32 CWPSIPItem::StoreL()
       
   824     {
       
   825     // __UHEAP_MARK; // For testing.
       
   826     DBG_PRINT( "CWPSIPItem::StoreL - begin" );
       
   827 
       
   828     CSIPProfile* tmpProfile = NULL;
       
   829     CSIPProfileRegistryObserver* cSIPProfileRegistryObserver = 
       
   830         CSIPProfileRegistryObserver::NewLC(); // CS:1
       
   831     CSIPManagedProfileRegistry* cSIPManagedProfileRegistry = 
       
   832         CSIPManagedProfileRegistry::NewLC( *cSIPProfileRegistryObserver );
       
   833         // CS:2
       
   834 
       
   835     // Preparing persistent managed profile for saving the SIP settings of the
       
   836     CSIPManagedProfile* cSIPManagedProfile = cSIPManagedProfileRegistry->
       
   837         CreateL( iSIPProfileTypeInfo ); 
       
   838            
       
   839     // Load existing profile if we are trying to set as default    
       
   840     if ( iProfileId && iSetAsDefault )
       
   841         {
       
   842         // Delete current profilecontent and load already saved profile.
       
   843         delete cSIPManagedProfile;
       
   844         tmpProfile = cSIPManagedProfileRegistry->ProfileL( iProfileId );
       
   845         cSIPManagedProfile = static_cast<CSIPManagedProfile*> ( tmpProfile );
       
   846         }
       
   847     CleanupStack::PushL( cSIPManagedProfile );// CS:3 
       
   848 
       
   849     // Skip setting providername if we are setting profile as default,
       
   850     // no need to check duplicate providers again.
       
   851     if ( !iSetAsDefault )
       
   852         {
       
   853         // Provider.
       
   854         cSIPManagedProfile->SetParameter( KSIPProviderName, 
       
   855             iProviderId->Des() );
       
   856 
       
   857         // For adding numbering to providername shown in settings UI.
       
   858         CheckDuplicateNameL( *cSIPManagedProfile, KErrNotFound );
       
   859         }
       
   860 
       
   861     if ( iNetwork->Des().Length() )
       
   862         {
       
   863         iSnapId = NetworkIdL( iNetwork->Des() );
       
   864         if ( KErrNotFound < iSnapId )
       
   865             {
       
   866             // Set SNAP ID.
       
   867             TInt err = cSIPManagedProfile->SetParameter( 
       
   868                 KSIPSnapId, (TUint32)iSnapId );
       
   869             }
       
   870         else
       
   871             {
       
   872             // Set IAP ID.
       
   873             cSIPManagedProfile->SetParameter( KSIPAccessPointId, iIAPId );
       
   874             }
       
   875         }
       
   876     else
       
   877         {
       
   878         if ( KErrNotFound < iSnapId )
       
   879             {
       
   880             // Set SNAP ID.
       
   881             TInt err = cSIPManagedProfile->SetParameter( KSIPSnapId, 
       
   882                 (TUint32)iSnapId );
       
   883             }
       
   884         else
       
   885             {
       
   886             // Set IAP ID.
       
   887             cSIPManagedProfile->SetParameter( KSIPAccessPointId, iIAPId );
       
   888             }
       
   889         }
       
   890 
       
   891     // Setting SIP Address-Of-Record/Public User Identity. There is only one 
       
   892     // AOR via OMA Client Provisioning.
       
   893     cSIPManagedProfile->SetParameter( KSIPUserAor, iAOR->Des() );
       
   894 
       
   895     // Set outbound proxy URI only if address part is present.
       
   896     if ( iOutboundAddr->Length() )
       
   897         {
       
   898         // Outbound proxy SIP-URI. The size of the final SIP-URI is calculated
       
   899         // with the maximum possible size. sip:host:port;transport
       
   900         HBufC8* bufURI = HBufC8::NewLC( 
       
   901             iOutboundAddr->Length()                    +
       
   902             KColon().Length()                          +
       
   903             iPortNumberForOutboundConnection->Length() +
       
   904             KTransport().Length()                      +
       
   905             iProtocolForOutboundConnection->Length()   +
       
   906             KLr().Length()
       
   907             ); // CS:4
       
   908 
       
   909         TPtr8 ptrBufURI( bufURI->Des() );
       
   910 
       
   911         // Outbound/P-CSCF proxy address;domain name or IP address.
       
   912         ptrBufURI.Copy( iOutboundAddr->Des() ); 
       
   913         // If the port number was received,
       
   914         // it is appended into the Request-URI.
       
   915         if ( iPortNumberForOutboundConnection->Length() > 0 ) // :port
       
   916             {
       
   917             ptrBufURI.Append( KColon );
       
   918             ptrBufURI.Append( iPortNumberForOutboundConnection->Des() );
       
   919             }
       
   920         // If the transport protocol was received, it is appended into the 
       
   921         // Request-URI.
       
   922         if ( iProtocolForOutboundConnection->Length() > 0 )
       
   923             {
       
   924             ptrBufURI.Append( KTransport );
       
   925             ptrBufURI.Append( iProtocolForOutboundConnection->Des() );
       
   926             }
       
   927 
       
   928         // Check if the loose routing parameter ";lr" should be
       
   929         // placed into the Request-URI.
       
   930         if ( iLooseRoutingForOutboundConnectionEnabled )
       
   931             {
       
   932             ptrBufURI.Append( KLr );
       
   933             }
       
   934         // Set outbound proxy/P-CSCF address.
       
   935         cSIPManagedProfile->SetParameter( 
       
   936             KSIPOutboundProxy, KSIPServerAddress, bufURI->Des() );
       
   937         CleanupStack::PopAndDestroy( bufURI ); // CS:3
       
   938         bufURI = NULL;
       
   939         }
       
   940 
       
   941     // Set signal compression enabled value.
       
   942     cSIPManagedProfile->SetParameter( KSIPSigComp, 
       
   943         iSignalCompressionEnabled );
       
   944 
       
   945     // Set security negotiation enabled value.
       
   946     cSIPManagedProfile->SetParameter( KSIPSecurityNegotiation,
       
   947         iSecurityNegotiationEnabled );
       
   948  
       
   949      if ( iSIPProfileTypeInfo.iSIPProfileClass == TSIPProfileTypeInfo::EOther
       
   950         || iSIPProfileTypeInfo.iSIPProfileClass == TSIPProfileTypeInfo::EIms )
       
   951         {
       
   952         cSIPManagedProfile->SetParameter( KSIPPrivateIdentity, 
       
   953             iUsernameForOutbound->Des() );
       
   954         }
       
   955     else
       
   956         {
       
   957         // Set outbound proxy username. Digest username.
       
   958         cSIPManagedProfile->SetParameter( KSIPOutboundProxy, 
       
   959             KSIPDigestUserName, iUsernameForOutbound->Des() );
       
   960         }
       
   961 
       
   962     // Set outbound proxy password. Digest password.
       
   963     cSIPManagedProfile->SetParameter( KSIPOutboundProxy, KSIPDigestPassword,
       
   964         iPasswordForOutbound->Des() );
       
   965  
       
   966     // Set realm for outbound.
       
   967     cSIPManagedProfile->SetParameter( KSIPOutboundProxy, KSIPDigestRealm,
       
   968         iRealmForOutbound->Des() );
       
   969 
       
   970     // Registrar SIP-URI.
       
   971     cSIPManagedProfile->SetParameter( KSIPRegistrar, KSIPServerAddress, 
       
   972         iRegistrarAddr->Des() );
       
   973 
       
   974     if ( iSIPProfileTypeInfo.iSIPProfileClass == TSIPProfileTypeInfo::EOther
       
   975         || iSIPProfileTypeInfo.iSIPProfileClass == TSIPProfileTypeInfo::EIms )
       
   976         {
       
   977         cSIPManagedProfile->SetParameter( KSIPPrivateIdentity, 
       
   978             iUsernameForRegistrar->Des() );
       
   979         }
       
   980     else
       
   981         {
       
   982         // Set registrar username. Digest username.
       
   983         cSIPManagedProfile->SetParameter( KSIPRegistrar, KSIPDigestUserName,
       
   984             iUsernameForRegistrar->Des() );
       
   985         }
       
   986 
       
   987     // Set registrar password. Digest password.
       
   988     cSIPManagedProfile->SetParameter( KSIPRegistrar, KSIPDigestPassword,
       
   989         iPasswordForRegistrar->Des() );
       
   990 
       
   991     // Set realm for registrar.
       
   992     cSIPManagedProfile->SetParameter( KSIPRegistrar, KSIPDigestRealm,
       
   993         iRealmForRegistrar->Des() );
       
   994 
       
   995     // Default parameter
       
   996     if ( iSetAsDefault )   
       
   997         {
       
   998         cSIPManagedProfile->SetParameter( KSIPDefaultProfile, ETrue );
       
   999         cSIPManagedProfile->SetParameter( KSIPProfileId, iProfileId );
       
  1000         }
       
  1001 
       
  1002     // Profile lock parameter
       
  1003     if ( iProfileLockEnabled )
       
  1004         {
       
  1005         cSIPManagedProfile->SetParameter( KSIPProfileLocked, ETrue );
       
  1006         }
       
  1007 
       
  1008     // Signalling QoS parameter.
       
  1009     cSIPManagedProfile->SetParameter( KSIPSoIpTOS, iSigQos );
       
  1010 
       
  1011     // Stores SIP profile to permanent storage
       
  1012     cSIPManagedProfileRegistry->SaveL( *cSIPManagedProfile );
       
  1013 
       
  1014     // get saved profile id
       
  1015     cSIPManagedProfile->GetParameter( KSIPProfileId, iProfileId );
       
  1016     CleanupStack::PopAndDestroy( cSIPManagedProfile );    
       
  1017     CleanupStack::PopAndDestroy( cSIPManagedProfileRegistry );
       
  1018     CleanupStack::PopAndDestroy( cSIPProfileRegistryObserver );
       
  1019     cSIPManagedProfile = NULL;
       
  1020 
       
  1021     // for testing
       
  1022     //__UHEAP_MARKEND;
       
  1023 
       
  1024     HBufC8* tmpId = HBufC8::NewL( KMaxCharsInTUint32 );
       
  1025     _LIT8( KFormatTxt,"%u" );
       
  1026     tmpId->Des().Format( KFormatTxt, iProfileId );
       
  1027     delete iSavedProfileId;
       
  1028     iSavedProfileId = NULL;
       
  1029     iSetAsDefault = EFalse;
       
  1030     iSavedProfileId = tmpId;
       
  1031     tmpId = NULL;
       
  1032     DBG_PRINT( "CWPSIPItem::StoreL - end" );
       
  1033     return iProfileId;
       
  1034     }
       
  1035 
       
  1036 // ---------------------------------------------------------------------------
       
  1037 // CWPSIPItem::SaveData
       
  1038 //
       
  1039 // ---------------------------------------------------------------------------
       
  1040 //
       
  1041 const TDesC8& CWPSIPItem::SaveData()
       
  1042     {
       
  1043     return *iSavedProfileId;
       
  1044     }
       
  1045 
       
  1046 // ---------------------------------------------------------------------------
       
  1047 // CWPSIPItem::CheckDuplicateNameL
       
  1048 // Checks if duplicate named sip profiles. Renames if same.
       
  1049 // ---------------------------------------------------------------------------
       
  1050 //
       
  1051 void CWPSIPItem::CheckDuplicateNameL( CSIPManagedProfile& aProfile, 
       
  1052     const TInt& aProfileId )
       
  1053     {
       
  1054     // Array of pointers to all loaded SIP profiles.
       
  1055     CArrayPtrFlat<CSIPManagedProfile>* profiles;
       
  1056     CSIPProfileRegistryObserver* cSIPProfileRegistryObserver = 
       
  1057         CSIPProfileRegistryObserver::NewLC(); // CS:1
       
  1058     CSIPManagedProfileRegistry*  cSIPManagedProfileRegistry = 
       
  1059         CSIPManagedProfileRegistry::NewLC( *cSIPProfileRegistryObserver );
       
  1060         // CS:2
       
  1061 
       
  1062     RArray<TSIPProfileTypeInfo> profileTypes;
       
  1063     CleanupClosePushL( profileTypes ); // CS:3
       
  1064 
       
  1065      // Get the supported profile types.
       
  1066     cSIPManagedProfileRegistry->SupportedProfileTypesL( profileTypes );
       
  1067 
       
  1068     // Create profile pointer array.
       
  1069     profiles = new ( ELeave ) CArrayPtrFlat<CSIPManagedProfile>( 5 );
       
  1070     TCleanupItem cleanupItem( CWPSIPItem::CleanupArrayItem, profiles );
       
  1071     CleanupStack::PushL( cleanupItem ); // CS:4
       
  1072 
       
  1073     RPointerArray<CSIPProfile> profilePointerArray;
       
  1074     CleanupResetAndDestroyPushL( profilePointerArray ); // CS:5
       
  1075 
       
  1076     // Get all profiles based on profile types.
       
  1077     const TInt profileTypeCount = profileTypes.Count();
       
  1078     for ( TInt i = 0; i < profileTypeCount; i++ )
       
  1079         {        
       
  1080         cSIPManagedProfileRegistry->ProfilesL( profileTypes[i], 
       
  1081             profilePointerArray );
       
  1082         const TInt profileCount = profilePointerArray.Count();
       
  1083         for ( TInt j = 0; j < profileCount; j++ )
       
  1084             {
       
  1085             CSIPManagedProfile* profile = 
       
  1086                 static_cast<CSIPManagedProfile*>( profilePointerArray[j] );
       
  1087             profiles->AppendL( profile );
       
  1088             }                    
       
  1089         profilePointerArray.Reset();
       
  1090         }
       
  1091     CleanupStack::PopAndDestroy( &profilePointerArray ); // CS:4
       
  1092 
       
  1093     // Go through loaded profiles and check for name duplicates.
       
  1094     const TDesC8* name;
       
  1095     aProfile.GetParameter( KSIPProviderName, name );
       
  1096     HBufC8* newName = HBufC8::NewLC( KMaxProviderNameLength ); // CS:5
       
  1097     newName->Des().Copy( *name );
       
  1098     const TInt count( profiles->Count() );
       
  1099     for ( TInt n = 0; n < count; n++ )
       
  1100         {
       
  1101         // Skip profile currently being checked.
       
  1102         if ( aProfileId != n )
       
  1103             {
       
  1104             const TDesC8* existingName;
       
  1105             profiles->At( n )->GetParameter( KSIPProviderName, existingName );
       
  1106             if ( existingName->Compare( *name )  == 0 )
       
  1107                 {
       
  1108                 TBool isUnique( EFalse );
       
  1109                 for ( TInt i = 1; !isUnique; i++ )
       
  1110                     {
       
  1111                     TBool found( EFalse );
       
  1112                     newName->Des().Zero();
       
  1113                     newName->Des().Append( *name );
       
  1114                     newName->Des().Append( KOpenParenthesis() );
       
  1115                     newName->Des().AppendNum( i );
       
  1116                     newName->Des().Append( KClosedParenthesis() );
       
  1117                     for ( TInt m = 0; m < count; m++ )
       
  1118                         {
       
  1119                         profiles->At( m )->GetParameter( KSIPProviderName, 
       
  1120                             existingName );
       
  1121                         if ( existingName->Compare( newName->Des() ) == 0 )
       
  1122                             {
       
  1123                             found = ETrue;
       
  1124                             }
       
  1125                         }
       
  1126                     if ( !found )
       
  1127                         {
       
  1128                         isUnique = ETrue;
       
  1129                         }
       
  1130                     }
       
  1131                 }
       
  1132             }
       
  1133         }
       
  1134     aProfile.SetParameter( KSIPProviderName, newName->Des() );
       
  1135     // newName, profiles, &profileTypes, cSIPManagedProfileRegistry
       
  1136     CleanupStack::PopAndDestroy( 5, cSIPProfileRegistryObserver ); // CS:0
       
  1137     }
       
  1138 
       
  1139 // ---------------------------------------------------------------------------
       
  1140 // CWPSIPItem::CleanupArrayItem
       
  1141 // Cleans up an array.
       
  1142 // ---------------------------------------------------------------------------
       
  1143 //
       
  1144 void CWPSIPItem::CleanupArrayItem( TAny* aArray )
       
  1145     {
       
  1146     CArrayPtrFlat<CSIPManagedProfile>* tempArray = 
       
  1147         static_cast<CArrayPtrFlat<CSIPManagedProfile>*>( aArray );
       
  1148     if ( tempArray )
       
  1149         {
       
  1150         tempArray->ResetAndDestroy();
       
  1151         }
       
  1152     delete tempArray;
       
  1153     }
       
  1154 
       
  1155 // ---------------------------------------------------------------------------
       
  1156 // CWPSIPItem::SetToAppRefL
       
  1157 //
       
  1158 // ---------------------------------------------------------------------------
       
  1159 //
       
  1160 void CWPSIPItem::SetToAppRefL( const TDesC8& aToAppRef )
       
  1161     {
       
  1162     delete iToAppRef;
       
  1163     iToAppRef = NULL;
       
  1164     iToAppRef = aToAppRef.AllocL();
       
  1165     }
       
  1166 
       
  1167 // ---------------------------------------------------------------------------
       
  1168 // CWPSIPItem::ToAppRef
       
  1169 //
       
  1170 // ---------------------------------------------------------------------------
       
  1171 //
       
  1172 const TDesC8& CWPSIPItem::ToAppRef() const
       
  1173     {
       
  1174     return *iToAppRef;
       
  1175     }
       
  1176 
       
  1177 // ---------------------------------------------------------------------------
       
  1178 // CWPSIPItem::SetNetworkL
       
  1179 //
       
  1180 // ---------------------------------------------------------------------------
       
  1181 //
       
  1182 void CWPSIPItem::SetNetworkL( const TDesC& aNetwork )
       
  1183     {
       
  1184     delete iNetwork;
       
  1185     iNetwork = NULL;
       
  1186     iNetwork = aNetwork.AllocL();
       
  1187     }
       
  1188 
       
  1189 // ---------------------------------------------------------------------------
       
  1190 // CWPSIPItem::Network
       
  1191 //
       
  1192 // ---------------------------------------------------------------------------
       
  1193 //
       
  1194 const TDesC& CWPSIPItem::Network() const
       
  1195     {
       
  1196     return *iNetwork;
       
  1197     }
       
  1198 
       
  1199 // ---------------------------------------------------------------------------
       
  1200 // CWPSIPItem::SetSnapId
       
  1201 //
       
  1202 // ---------------------------------------------------------------------------
       
  1203 //
       
  1204 void CWPSIPItem::SetSnapId( TInt aSnapId )
       
  1205     {
       
  1206     iSnapId = aSnapId;
       
  1207     }
       
  1208 
       
  1209 // ---------------------------------------------------------------------------
       
  1210 // CWPSIPItem::NetworkIdL
       
  1211 //
       
  1212 // ---------------------------------------------------------------------------
       
  1213 //
       
  1214 TInt CWPSIPItem::NetworkIdL( const TDesC& aName )
       
  1215     {
       
  1216     DBG_PRINT( "CWPSIPItem::NetworkIdL - begin" );
       
  1217     TInt networkId( KErrNotFound );
       
  1218     RCmManagerExt cmManager;
       
  1219     cmManager.OpenL();
       
  1220     CleanupClosePushL( cmManager ); // CS:1
       
  1221     RArray<TUint32> destinations;
       
  1222     CleanupClosePushL( destinations ); // CS:2
       
  1223     cmManager.AllDestinationsL( destinations );
       
  1224     const TInt destCount = destinations.Count();
       
  1225     for ( TInt counter = 0; counter < destCount; counter++ )
       
  1226         {
       
  1227         RCmDestinationExt destination = cmManager.DestinationL( 
       
  1228             destinations[counter] );
       
  1229         CleanupClosePushL( destination ); // CS:3
       
  1230         HBufC* destName = destination.NameLC(); // CS:4
       
  1231         if ( 0 == aName.Compare( destName->Des() ) )
       
  1232             {
       
  1233             networkId = destinations[counter];
       
  1234             CleanupStack::PopAndDestroy( 2, &destination ); // CS:2
       
  1235             break;
       
  1236             }
       
  1237         CleanupStack::PopAndDestroy( 2, &destination ); // CS:2
       
  1238         }
       
  1239     CleanupStack::PopAndDestroy( 2, &cmManager ); // CS:0
       
  1240     destinations.Close();
       
  1241     DBG_PRINT( "CWPSIPItem::NetworkIdL - end" );
       
  1242     return networkId;
       
  1243     }
       
  1244 
       
  1245 // ---------------------------------------------------------------------------
       
  1246 // CWPSIPItem::SetSigQos
       
  1247 //
       
  1248 // ---------------------------------------------------------------------------
       
  1249 //
       
  1250 void CWPSIPItem::SetSigQos( TUint32 aSigQos )
       
  1251     {
       
  1252     // We need to do bitshifting on the IP TOS, because it's the upper 6 bits
       
  1253     // that are set and settings provide us the IP TOS as the lower 6 bits.
       
  1254     // The lower 2 bits are reserver for explicit congestion notification.
       
  1255     // See also more from:
       
  1256     // Symbian Developer Library / in_sock.h Global variables / KSoIpTOS
       
  1257     const TInt ipTosShift( 2 );
       
  1258     const TUint32 tosBits( aSigQos << ipTosShift );
       
  1259     iSigQos = tosBits;
       
  1260     }
       
  1261 
       
  1262 // End of file.