realtimenetprots/sipfw/SampleApp/gameUI_techview/Src/Profileutil.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name        : ProfileUtil.cpp
       
    15 // Part of     : SIP Profile Client / Settings User Interface
       
    16 // Utility class for manipulating profiles and their attributes
       
    17 // Version     : 1.0
       
    18 //
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDE FILES
       
    24 #include    <e32std.h>
       
    25 #include    <e32base.h>
       
    26 #include    <eikenv.h>
       
    27 #include 	<badesca.h>
       
    28 #include    "ProfileUtil.h"
       
    29 #include    "TSIPServerData.h"
       
    30 #include    "TSIPProfileData.h"
       
    31 #include    "sipmanagedprofile.h"
       
    32 #include    "siphostport.h"
       
    33 #include    "sipuri.h"
       
    34 #include 	"sipstrings.h"
       
    35 #include    "sipstrconsts.h"
       
    36 #include    <sipex.rsg>
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // ProfileUtil::ProfileUtil
       
    42 // C++ default constructor can NOT contain any code, that
       
    43 // might leave.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 ProfileUtil::ProfileUtil()
       
    47     {
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // ProfileUtil::CopyProfileAttributesL
       
    52 // Copies profile attributes from temp data structure to profile
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 void ProfileUtil::CopyProfileAttributesL( 
       
    56     CSIPManagedProfile* aProfile, 
       
    57     const TSIPProfileData& aProfileData )
       
    58     {
       
    59     // Service provider name
       
    60     HBufC8* providerName = HBufC8::NewLC( KMaxProviderNameLength );
       
    61     providerName->Des().Copy( aProfileData.iProviderName );
       
    62     TInt err = aProfile->SetParameter(KSIPProviderName ,providerName->Des());
       
    63     User::LeaveIfError(err);    
       
    64     CleanupStack::PopAndDestroy();  // providerName
       
    65 
       
    66     // AP index
       
    67     err=aProfile->SetParameter(KSIPAccessPointId,(TUint32)aProfileData.iAPIndex);
       
    68     User::LeaveIfError(err);    
       
    69 
       
    70     // Compression setting
       
    71     TBool compression = ( aProfileData.iCompression == EComprYes );
       
    72     err=aProfile->SetParameter(KSIPSigComp,compression);
       
    73     User::LeaveIfError(err);
       
    74     
       
    75     // Registration mode
       
    76     TBool autoReg = ( aProfileData.iRegistrationMode == EAlwaysOn );
       
    77     err=aProfile->SetParameter(KSIPAutoRegistration,autoReg);
       
    78     User::LeaveIfError(err);    
       
    79 
       
    80     // Security negotiation
       
    81     TBool security = ( aProfileData.iSecurity == ESecurityOn );
       
    82     err=aProfile->SetParameter(KSIPSecurityNegotiation,security);
       
    83     User::LeaveIfError(err);
       
    84     
       
    85     // Username
       
    86     if ( aProfileData.iUsername != KEmptyString )
       
    87         {
       
    88       
       
    89         HBufC8* uName = HBufC8::NewLC( KMaxUsernameLength + 
       
    90                                        KSIPProtocolHeader().Length() );       
       
    91         uName->Des().Copy( KSIPProtocolHeader );
       
    92         uName->Des().Append( aProfileData.iUsername );
       
    93      
       
    94         err=aProfile->SetParameter(KSIPUserAor,*uName );
       
    95         User::LeaveIfError(err);
       
    96         
       
    97         CleanupStack::PopAndDestroy( 1 );  // uName
       
    98         }
       
    99     
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // ProfileUtil::CopyServerAttributesL
       
   104 // Copies server attributes from temp data structure to profile
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void ProfileUtil::CopyServerAttributesL(
       
   108     CSIPManagedProfile* aProfile,
       
   109     const TUint32 aServer,
       
   110     const TSIPServerData& aProfileData )
       
   111     {
       
   112     // Digest realm
       
   113     TInt err(KErrNone);
       
   114     if ( aProfileData.iRealm != KEmptyString )
       
   115         {
       
   116         HBufC8* realm = HBufC8::NewLC( aProfileData.iRealm.Length() );
       
   117         realm->Des().Copy( aProfileData.iRealm );        
       
   118 		err=aProfile->SetParameter( 
       
   119 		         aServer,KSIPDigestRealm, *realm );
       
   120 		User::LeaveIfError(err);
       
   121         CleanupStack::PopAndDestroy();  // realm
       
   122         }
       
   123 
       
   124     // Username        
       
   125     if ( aProfileData.iUsername != KEmptyString )
       
   126         {
       
   127         HBufC8* uName = HBufC8::NewLC( aProfileData.iUsername.Length() );
       
   128         uName->Des().Copy( aProfileData.iUsername );
       
   129         err=aProfile->SetParameter( 
       
   130 		         aServer,KSIPDigestUserName,*uName );
       
   131 		User::LeaveIfError(err);
       
   132         CleanupStack::PopAndDestroy();  // uName    
       
   133         }
       
   134 
       
   135     // Password
       
   136     if ( aProfileData.iPassword != KEmptyString )
       
   137         {
       
   138         HBufC8* passw = HBufC8::NewLC( aProfileData.iPassword.Length() );
       
   139         passw->Des().Copy( aProfileData.iPassword );        
       
   140         err=aProfile->SetParameter( 
       
   141 		         aServer,KSIPDigestPassword,*passw );
       
   142 		User::LeaveIfError(err);
       
   143         CleanupStack::PopAndDestroy();  // passw
       
   144         }
       
   145     
       
   146     HBufC* defBuf = CEikonEnv::Static()->AllocReadResourceLC(
       
   147         R_SIP_EX_DEF_SERVER_ADDRESS );
       
   148     
       
   149     // If there are default values set, then the URI string
       
   150     // will be empty. Otherwise the changed values are copied
       
   151     if ( aProfileData.iTransportProtocol != ETranspProtocolUDP ||
       
   152          ( aServer == KSIPOutboundProxy &&
       
   153            aProfileData.iLooseRouting != ELooseRoutingOn ) ||
       
   154          aProfileData.iPortNumber != KDefaultPortNumber ||
       
   155          (aProfileData.iAddress != defBuf->Des() &&
       
   156          aProfileData.iAddress.Length() > 0
       
   157          ))
       
   158         {
       
   159         // Don't need defBuf no more
       
   160         CleanupStack::PopAndDestroy();  // defBuf
       
   161         
       
   162         // Creates, formats and saves URI to profile
       
   163         ProfileUtil::CopyServerURIL( aProfile, aServer, aProfileData );
       
   164         }
       
   165     else
       
   166         {
       
   167         // Don't need defBuf no more
       
   168         CleanupStack::PopAndDestroy();  // defBuf
       
   169 
       
   170         // Empty string  . New API will leave if empty sting has set 
       
   171         // So there is no point of setting this .
       
   172         /*
       
   173         err=aProfile->SetParameter(KSIPOutboundProxy,KEmptyString8 );
       
   174         User::LeaveIfError(err);
       
   175         */
       
   176         }
       
   177     }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // ProfileUtil::CopyToTempStruct
       
   181 // Copies profile attributes from profile to temp data struct
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 void ProfileUtil::CopyToTempStruct(
       
   185     CSIPManagedProfile* aProfile,
       
   186     TSIPProfileData& aProfileData )
       
   187     {
       
   188     // Profile ID
       
   189     TInt err=  aProfile->GetParameter(KSIPProfileId,(TUint32 &)aProfileData.iID);
       
   190     if(err)	
       
   191     	{
       
   192     	// don't know what to do     	
       
   193     	}    
       
   194     // Access Point index
       
   195     err=  aProfile->GetParameter(KSIPAccessPointId ,(TUint32 &)aProfileData.iAPIndex);
       
   196     if(err)	
       
   197     	{
       
   198     	// don't know what to do     	
       
   199     	}    
       
   200     
       
   201     // Service provider name
       
   202     
       
   203     const TDesC8 * tmpProviderName = 0;
       
   204     err=  aProfile->GetParameter(KSIPProviderName,tmpProviderName);
       
   205     if(err)	
       
   206     	{
       
   207     	// don't know what to do     	
       
   208     	}    
       
   209     else
       
   210     	{
       
   211     	aProfileData.iProviderName.Copy( *tmpProviderName );	
       
   212     //	delete tmpProviderName;
       
   213     	}    
       
   214 
       
   215     // Registration mode
       
   216     TBool bResult(EFalse);
       
   217     err=  aProfile->GetParameter(KSIPAutoRegistration,bResult);
       
   218     if(err)
       
   219     	{
       
   220     		// don't know what to do 
       
   221     	}    
       
   222     if (bResult)
       
   223         {
       
   224         aProfileData.iRegistrationMode = EAlwaysOn;
       
   225         }
       
   226     else
       
   227         {
       
   228         aProfileData.iRegistrationMode = EWhenNeeded;
       
   229         }
       
   230 	//reset the value to EFalse since we are not caring err .
       
   231 	bResult = EFalse;
       
   232 	err=  aProfile->GetParameter(KSIPSigComp,bResult);
       
   233     if(err)
       
   234     	{
       
   235     		// don't know what to do 
       
   236     	}    
       
   237     if ( bResult)
       
   238         {
       
   239         aProfileData.iCompression = EComprYes;
       
   240         }
       
   241     else
       
   242         {
       
   243         aProfileData.iCompression = EComprNo;
       
   244         }
       
   245     
       
   246     //reset the value to EFalse since we are not caring err .
       
   247     // Security negotiation
       
   248     bResult = EFalse;
       
   249 	err=  aProfile->GetParameter(KSIPSecurityNegotiation ,bResult);
       
   250     if(err)
       
   251     	{
       
   252     		// don't know what to do 
       
   253     	}
       
   254     	   
       
   255     if (bResult)
       
   256         {
       
   257         aProfileData.iSecurity = ESecurityOn;
       
   258         }
       
   259     else
       
   260         {   
       
   261         aProfileData.iSecurity = ESecurityOff;
       
   262         }
       
   263 
       
   264     // Profile type    
       
   265     aProfileData.iServiceProfile = aProfile->Type();
       
   266 
       
   267     // Username
       
   268     const TDesC8 * userName = 0;
       
   269     err=  aProfile->GetParameter(KSIPUserAor ,userName);
       
   270     if(err)
       
   271     	{
       
   272     		// don't know what to do 
       
   273     	}
       
   274     if (userName && 
       
   275          (userName->Length() > 
       
   276            KSIPProtocolHeader().Length() ) )
       
   277         {
       
   278         TPtrC8 ptr( *userName);
       
   279         aProfileData.iUsername.Copy( 
       
   280             ptr.Right( ptr.Length() - KSIPProtocolHeader().Length() ) );
       
   281         }    
       
   282     else
       
   283         {
       
   284         aProfileData.iUsername.Zero();
       
   285         }   
       
   286     }
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // ProfileUtil::CopyServerSettingsToTempStructL
       
   290 // Copies server attributes from profile to temp data struct
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 void ProfileUtil::CopyServerSettingsToTempStructL(
       
   294     CSIPManagedProfile* aProfile,
       
   295     const TUint32 aServer,
       
   296     TSIPServerData& aProfileData )
       
   297     {
       
   298     CEikonEnv* env = CEikonEnv::Static();
       
   299 	TInt err(KErrNone);    
       
   300     const TDesC8 * uri = 0;    
       
   301     err= aProfile->GetParameter(aServer,KSIPServerAddress,uri);
       
   302     User::LeaveIfError(err);    	     
       
   303 	const TDesC8 * realm =0;	
       
   304 	err=aProfile->GetParameter(aServer,KSIPDigestRealm,realm);
       
   305 	User::LeaveIfError(err);	    
       
   306 	const TDesC8 * uName = 0;	
       
   307 	err=aProfile->GetParameter(aServer,KSIPDigestUserName,uName);
       
   308 	User::LeaveIfError(err);	
       
   309 	// Can't be retrived according to new api
       
   310     //const TDesC8& passw = aProfile->ServerExtensionParameter( 
       
   311     //    aServer, KLabelPassword );
       
   312     
       
   313     aProfileData.iRealm.Copy( *realm );
       
   314     aProfileData.iUsername.Copy( *uName );
       
   315     aProfileData.iPassword.Copy( KNullDesC);
       
   316 
       
   317     if ( *uri == KEmptyString8 )
       
   318         {
       
   319         // Set default settings if URI is empty
       
   320         aProfileData.iAddress =         
       
   321             env->AllocReadResourceLC( R_SIP_EX_DEF_SERVER_ADDRESS )->Des();
       
   322         CleanupStack::PopAndDestroy();  // addr                           
       
   323         aProfileData.iPortNumber = KDefaultPortNumber;
       
   324         aProfileData.iTransportProtocol = ETranspProtocolUDP;
       
   325         if ( aServer == KSIPOutboundProxy)
       
   326             {
       
   327             aProfileData.iLooseRouting = ELooseRoutingOn;
       
   328             }
       
   329         else
       
   330             {
       
   331             aProfileData.iLooseRouting = ELooseRoutingOff;
       
   332             }
       
   333         }
       
   334     else
       
   335         {
       
   336         CSIPURI* sipURI = CSIPURI::DecodeL( *uri );
       
   337         CleanupStack::PushL( sipURI );
       
   338         // Get proxy/registrar address
       
   339         if ( sipURI->HostPort().Host().Length() )        
       
   340             {
       
   341             aProfileData.iAddress.Copy( sipURI->HostPort().Host() );            
       
   342             }
       
   343         else
       
   344             {       
       
   345             aProfileData.iAddress =         
       
   346                 env->AllocReadResourceLC( R_SIP_EX_DEF_SERVER_ADDRESS )->Des();
       
   347             CleanupStack::PopAndDestroy();  // addr                           
       
   348             }
       
   349 
       
   350         // Get lr parameter
       
   351         RStringF lr = SIPStrings::Pool().StringF(SipStrConsts::ELr,SIPStrings::Table());
       
   352         aProfileData.iLooseRouting = sipURI->HasParam(lr);       
       
   353         // Get the port 
       
   354         if (! sipURI->HostPort().HasPort())
       
   355             {
       
   356             aProfileData.iPortNumber = KDefaultPortNumber;
       
   357             }
       
   358         else
       
   359             {
       
   360             aProfileData.iPortNumber = sipURI->HostPort().Port();
       
   361             }
       
   362     
       
   363         // Read transport protocol parameter
       
   364 /*        HBufC* transpParamTCP;
       
   365         HBufC8* transpParamTCP8;
       
   366         transpParamTCP = env->AllocReadResourceLC( R_SIP_EX_TCP_PARAM );
       
   367         transpParamTCP8 = HBufC8::NewLC( transpParamTCP->Length() );
       
   368         transpParamTCP8->Des().Copy( transpParamTCP->Des() );        
       
   369 		RStringF transportParam = SIPStrings::Pool().StringF(SipStrConsts::ETransport,SIPStrings::Table());
       
   370         if ( (*transpParamTCP8).Compare( sipURI->ParamValue(transportParam).DesC() ) == 0 )
       
   371             {
       
   372             aProfileData.iTransportProtocol = ETranspProtocolTCP;
       
   373             }
       
   374         else
       
   375             {
       
   376             // UDP is default transport parameter
       
   377   */          aProfileData.iTransportProtocol = ETranspProtocolUDP;
       
   378    /*         }
       
   379      */   
       
   380         CleanupStack::PopAndDestroy( 2 );      // transpParamTCP, transpParamTCP8
       
   381 
       
   382         CleanupStack::PopAndDestroy();   // sipURI
       
   383         }    
       
   384     }
       
   385 
       
   386 // -----------------------------------------------------------------------------
       
   387 // ProfileUtil::ProfileModificationsL
       
   388 // Compares profile attributes with the ones on the temporary structure
       
   389 // -----------------------------------------------------------------------------
       
   390 //
       
   391 TBool ProfileUtil::ProfileModificationsL(
       
   392     CSIPManagedProfile* aProfile,
       
   393     const TSIPProfileData& aProfileData )
       
   394     {
       
   395     TBool modifs = EFalse;
       
   396     
       
   397     // Service provider name
       
   398     HBufC8* providerName = HBufC8::NewLC( KMaxProviderNameLength );
       
   399     providerName->Des().Copy( aProfileData.iProviderName );
       
   400 
       
   401     HBufC8* userName = HBufC8::NewLC( KMaxUsernameLength );
       
   402     userName->Des().Copy( aProfileData.iUsername );   
       
   403 
       
   404 	const TDesC8 * tmpProviderName = 0;
       
   405 	TInt err(KErrNone);
       
   406     err=  aProfile->GetParameter(KSIPProviderName,tmpProviderName);
       
   407     User::LeaveIfError(err);
       
   408        
       
   409     TBool nameComp = providerName->Des().Compare( *tmpProviderName ) != 0;
       
   410     
       
   411     TUint32 iapId(0);
       
   412     err=  aProfile->GetParameter(KSIPAccessPointId,iapId);
       
   413     User::LeaveIfError(err);    
       
   414     TBool iapComp = TUint( aProfileData.iAPIndex ) != iapId;
       
   415     
       
   416     // error 514: (Warning -- Unusual use of a Boolean expression)
       
   417     // PC-Lint refuses to understand XOR operation
       
   418     TBool bSigComp(EFalse);
       
   419     err=  aProfile->GetParameter(KSIPSigComp,bSigComp);
       
   420     User::LeaveIfError(err)	;
       
   421     
       
   422     TBool comprComp = ( aProfileData.iCompression == EComprYes ) ^ 
       
   423                       bSigComp; //lint !e514
       
   424                       
       
   425     // error 514: (Warning -- Unusual use of a Boolean expression)
       
   426     // PC-Lint refuses to understand XOR operation
       
   427     
       
   428     TBool bAutoReg(EFalse);
       
   429     err=  aProfile->GetParameter(KSIPAutoRegistration,bAutoReg);
       
   430     User::LeaveIfError(err);
       
   431          
       
   432     TBool registrationComp = ( aProfileData.iRegistrationMode == EAlwaysOn ) ^
       
   433                     			bAutoReg; //lint !e514
       
   434     
       
   435     // error 514: (Warning -- Unusual use of a Boolean expression)
       
   436     // PC-Lint refuses to understand XOR operation
       
   437     
       
   438     TBool bSecurityNeg(EFalse);
       
   439     err=  aProfile->GetParameter(KSIPSecurityNegotiation,bSecurityNeg);
       
   440     User::LeaveIfError(err);
       
   441          
       
   442     TBool securityComp = ( aProfileData.iSecurity == ESecurityOn ) ^
       
   443             				bSecurityNeg; //lint !e514
       
   444 	const TDesC8 * aor = 0;
       
   445     err=  aProfile->GetParameter(KSIPUserAor,aor);    
       
   446     User::LeaveIfError(err);
       
   447     
       
   448     TPtrC8 ptr(*aor);
       
   449     // Username comparison
       
   450     TBool uNameComp = 
       
   451         userName->Des().Compare(
       
   452             ptr.Right( ptr.Length() - KSIPProtocolHeader().Length() )  ) != 0;
       
   453 
       
   454     TBool serviceComp = ( aProfileData.iServiceProfile.iSIPProfileName !=
       
   455                           aProfile->Type().iSIPProfileName ) ||
       
   456                         ( aProfileData.iServiceProfile.iSIPProfileClass !=
       
   457                           aProfile->Type().iSIPProfileClass );
       
   458 
       
   459     if ( nameComp || iapComp || comprComp || registrationComp ||
       
   460          securityComp || uNameComp || serviceComp )
       
   461         {        
       
   462         modifs = ETrue;
       
   463         }   
       
   464         
       
   465     CleanupStack::PopAndDestroy( 2 );  // providerName, userName
       
   466 
       
   467     return modifs;
       
   468     }
       
   469 
       
   470 // -----------------------------------------------------------------------------
       
   471 // ProfileUtil::ServerModifciationsL
       
   472 // Compares server attributes with the ones on the temporary structure
       
   473 // -----------------------------------------------------------------------------
       
   474 //
       
   475 TBool ProfileUtil::ServerModificationsL(
       
   476     CSIPManagedProfile* aProfile,
       
   477     const TUint32 aServer,
       
   478     const TSIPServerData& aData )
       
   479     {
       
   480     TSIPServerData serverData;
       
   481 
       
   482     ProfileUtil::CopyServerSettingsToTempStructL( 
       
   483         aProfile, aServer, serverData );
       
   484 
       
   485     TBool addrComp = serverData.iAddress != aData.iAddress;
       
   486     TBool lrComp = serverData.iLooseRouting != aData.iLooseRouting;
       
   487     TBool realmComp = serverData.iRealm != aData.iRealm;
       
   488     TBool uNameComp = serverData.iUsername != aData.iUsername;
       
   489     TBool passwComp = serverData.iPassword != aData.iPassword;
       
   490     TBool transpComp = 
       
   491         serverData.iTransportProtocol != aData.iTransportProtocol;
       
   492     TBool portComp = serverData.iPortNumber != aData.iPortNumber;
       
   493 
       
   494     return ( addrComp || lrComp || realmComp || uNameComp || passwComp ||
       
   495              transpComp || portComp );
       
   496     }
       
   497 
       
   498 // -----------------------------------------------------------------------------
       
   499 // ProfileUtil::CopyProfileL
       
   500 // Copies profile attributes from one profile to another
       
   501 // -----------------------------------------------------------------------------
       
   502 //
       
   503 void ProfileUtil::CopyProfileL(
       
   504     CSIPManagedProfile* aOrigProfile,
       
   505     CSIPManagedProfile* aCopiedProfile )
       
   506     {
       
   507     // Copy profile settings    
       
   508 	TInt err(KErrNone);    
       
   509     aCopiedProfile->SetType( aOrigProfile->Type() );
       
   510     TUint32 iapId(0);
       
   511     err=  aOrigProfile->GetParameter(KSIPAccessPointId,iapId);    
       
   512     User::LeaveIfError(err);
       
   513     
       
   514 	err=aCopiedProfile->SetParameter(KSIPAccessPointId,iapId);	
       
   515 	User::LeaveIfError(err);	
       
   516 	
       
   517 	const MDesC8Array * aors = 0;
       
   518     err=  aOrigProfile->GetParameter(KSIPRegisteredAors,aors);    
       
   519     User::LeaveIfError(err);
       
   520     
       
   521     
       
   522 	err=aCopiedProfile->SetParameter(KSIPRegisteredAors,*aors);	
       
   523 	User::LeaveIfError(err);
       
   524 	
       
   525     const TDesC8 * pIdentiy = 0;
       
   526     err=  aOrigProfile->GetParameter(KSIPPrivateIdentity,pIdentiy);    
       
   527     User::LeaveIfError(err);    
       
   528 	err=aCopiedProfile->SetParameter(KSIPPrivateIdentity,*pIdentiy);	
       
   529 	User::LeaveIfError(err);
       
   530     
       
   531     
       
   532 	const TDesC8 * providerName = 0;
       
   533     err=  aOrigProfile->GetParameter(KSIPProviderName,providerName);    
       
   534     User::LeaveIfError(err);    
       
   535 	err=aCopiedProfile->SetParameter(KSIPProviderName,*providerName);	
       
   536 	User::LeaveIfError(err);
       
   537 	
       
   538 	TBool bSigcomp(EFalse);
       
   539     err=  aOrigProfile->GetParameter(KSIPSigComp,bSigcomp);    
       
   540     User::LeaveIfError(err);    
       
   541 	err=aCopiedProfile->SetParameter(KSIPSigComp,bSigcomp);	
       
   542 	User::LeaveIfError(err);
       
   543 	
       
   544 	TBool bAutoReg(EFalse);
       
   545     err=  aOrigProfile->GetParameter(KSIPAutoRegistration,bAutoReg);    
       
   546     User::LeaveIfError(err);
       
   547     err=aCopiedProfile->SetParameter(KSIPAutoRegistration,bAutoReg);	
       
   548 	User::LeaveIfError(err);
       
   549 	
       
   550 
       
   551 	TBool bSecurityNeg(EFalse);
       
   552     err=  aOrigProfile->GetParameter(KSIPNegotiatedSecurityMechanism ,bSecurityNeg);    
       
   553     User::LeaveIfError(err);
       
   554     err=aCopiedProfile->SetParameter(KSIPNegotiatedSecurityMechanism ,bSecurityNeg);	
       
   555 	User::LeaveIfError(err);
       
   556 	
       
   557 	TBool bDefault(EFalse);
       
   558     err=  aOrigProfile->GetParameter(KSIPDefaultProfile ,bDefault);    
       
   559     User::LeaveIfError(err);
       
   560         
       
   561     if(bDefault)
       
   562         {
       
   563         err=aCopiedProfile->SetParameter(KSIPDefaultProfile,bDefault);
       
   564 		User::LeaveIfError(err);
       
   565         }
       
   566 
       
   567 	const TDesC8 * outboundProxy = 0;
       
   568     err=  aOrigProfile->GetParameter(KSIPOutboundProxy,KSIPServerAddress,outboundProxy );    
       
   569     User::LeaveIfError(err);
       
   570     err=aCopiedProfile->SetParameter(KSIPOutboundProxy ,KSIPServerAddress,*outboundProxy);	
       
   571 	User::LeaveIfError(err);
       
   572 		
       
   573 	const TDesC8 * realm = 0;
       
   574     err=  aOrigProfile->GetParameter(KSIPOutboundProxy,KSIPDigestRealm,realm );    
       
   575     User::LeaveIfError(err);
       
   576     err=aCopiedProfile->SetParameter(KSIPOutboundProxy ,KSIPDigestRealm ,*realm);
       
   577 	User::LeaveIfError(err);
       
   578     
       
   579     const TDesC8 * uName = 0;
       
   580     err=  aOrigProfile->GetParameter(KSIPOutboundProxy,KSIPDigestUserName,uName );
       
   581     User::LeaveIfError(err);
       
   582     err=aCopiedProfile->SetParameter(KSIPOutboundProxy,KSIPDigestUserName,*uName);
       
   583 	User::LeaveIfError(err);    
       
   584  
       
   585     err=  aOrigProfile->GetParameter(KSIPRegistrar,KSIPDigestRealm,realm );    
       
   586     User::LeaveIfError(err);
       
   587     err=aCopiedProfile->SetParameter(KSIPRegistrar ,KSIPDigestRealm,*realm);	
       
   588 	User::LeaveIfError(err);
       
   589        
       
   590     err=  aOrigProfile->GetParameter(KSIPRegistrar,KSIPDigestUserName,uName );    
       
   591     User::LeaveIfError(err);
       
   592     err=aCopiedProfile->SetParameter(KSIPRegistrar,KSIPDigestUserName,*uName);	
       
   593 	User::LeaveIfError(err);
       
   594 	
       
   595 // TODO : This can't be done according to new API .            
       
   596 /*	aCopiedProfile->SetServerExtensionParameterL( 
       
   597         CSIPProfile::ERegistrar, 
       
   598         KLabelPassword,
       
   599 		aOrigProfile->ServerExtensionParameter( 
       
   600             CSIPProfile::ERegistrar, 
       
   601             KLabelPassword ) );
       
   602 */            
       
   603     }
       
   604 
       
   605 // -----------------------------------------------------------------------------
       
   606 // ProfileUtil::CopyServerURIL
       
   607 // Copies server URI to the profile
       
   608 // -----------------------------------------------------------------------------
       
   609 //
       
   610 void ProfileUtil::CopyServerURIL(
       
   611     CSIPManagedProfile* aProfile,
       
   612     const TUint32 aServer,
       
   613     const TSIPServerData& aProfileData )
       
   614     {    
       
   615     CEikonEnv* env = CEikonEnv::Static();
       
   616 
       
   617     // Check if the default values are used in port 
       
   618     // and transport protocol.
       
   619     TBool defaultValues = EFalse;
       
   620     if( aProfileData.iPortNumber == KDefaultPortNumber &&
       
   621         aProfileData.iTransportProtocol == KDefaultTranspProtocol )
       
   622         {
       
   623         defaultValues = ETrue;
       
   624         }
       
   625 
       
   626     // Set URI (contains proxy address, port and 
       
   627     // loose routing & transport parameters)     
       
   628     HBufC8* host = HBufC8::NewLC( aProfileData.iAddress.Length() );
       
   629     host->Des().Copy( aProfileData.iAddress );
       
   630 
       
   631     // If default values are used, the port is not added to URI.
       
   632     CSIPHostPort* port = NULL;    
       
   633     if( defaultValues )
       
   634         {
       
   635         port = CSIPHostPort::DecodeL( host->Des() );            
       
   636         }
       
   637     else
       
   638         {
       
   639         port = CSIPHostPort::DecodeL(host->Des());
       
   640         port->SetPort(aProfileData.iPortNumber );            
       
   641         }
       
   642     CleanupStack::PushL(port);    
       
   643     HBufC8* uriString;    
       
   644     // String is of format "sip:[public username]"
       
   645     uriString = HBufC8::NewLC( host->Length() + 
       
   646                                KSIPProtocolHeader().Length() );
       
   647     uriString->Des().Copy( KSIPProtocolHeader );
       
   648     uriString->Des().Append( host->Des() );
       
   649     CSIPURI* uri = CSIPURI::DecodeL(*uriString);    
       
   650     CleanupStack::PopAndDestroy(1);    // uriString      
       
   651     uri->SetHostPortL(port);
       
   652     CleanupStack::Pop(port);
       
   653     CleanupStack::PopAndDestroy(1);    // host
       
   654     CleanupStack::PushL( uri ); // Ownership of port is transferred
       
   655     // Loose routing param
       
   656     if ( aProfileData.iLooseRouting == ELooseRoutingOn &&
       
   657          aServer != KSIPRegistrar )
       
   658         {
       
   659         RStringF lr = SIPStrings::Pool().StringF(SipStrConsts::ELr,SIPStrings::Table());
       
   660         uri->SetParamL(lr);
       
   661         }
       
   662 
       
   663     // If default values are used, the transport protocol is not added to URI.
       
   664     if( !defaultValues )
       
   665         {
       
   666        	RStringF transportParam = SIPStrings::Pool().StringF(SipStrConsts::ETransport,SIPStrings::Table());
       
   667        	if ( aProfileData.iTransportProtocol == ETranspProtocolUDP )
       
   668        		{
       
   669        		RStringF udp = SIPStrings::Pool().StringF(SipStrConsts::EUdp,SIPStrings::Table());
       
   670        		uri->SetParamL(transportParam,udp );	
       
   671        		}
       
   672        	else if (aProfileData.iTransportProtocol == ETranspProtocolTCP)
       
   673        		{
       
   674        		RStringF tcp = SIPStrings::Pool().StringF(SipStrConsts::ETcp,SIPStrings::Table());
       
   675        		uri->SetParamL(transportParam,tcp );	       	
       
   676        		}
       
   677        	else
       
   678        		{
       
   679        		User::Leave( KErrNotFound );
       
   680        		} 
       
   681         }
       
   682     
       
   683     HBufC8* txt = uri->ToTextL();
       
   684     CleanupStack::PushL( txt );    
       
   685     TInt err= aProfile->SetParameter( aServer,KSIPServerAddress,*txt );
       
   686     User::LeaveIfError(err);
       
   687     CleanupStack::PopAndDestroy( 2 );   // uri, txt               
       
   688     }