sipplugins/sippsipsettingsui/src/gssipprofileutil.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2003 - 2005 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:  Utility class for manipulating profiles and their attributes
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <escapeutils.h>
       
    21 #include    <delimitedpathsegment8.h> 
       
    22 #include    <sipmanagedprofile.h>
       
    23 #include    <StringLoader.h>
       
    24 #include 	<uriutils.h>
       
    25 #include    <sipstrings.h>
       
    26 #include    <sipaddress.h>
       
    27 #include    <gssipsettingspluginrsc.rsg> //GUI Resource
       
    28 #include	<e32const.h>
       
    29 #include    "gssipprofileutil.h"
       
    30 #include    "tgssipserverdata.h"
       
    31 #include    "tsipsettingsdata.h"
       
    32 #include    "gssippluginlogger.h"
       
    33 
       
    34 const TUint32 KDefaultSNAPIdentifier = KMaxTUint32;
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // GSSIPProfileUtil::GSSIPProfileUtil
       
    40 // C++ default constructor can NOT contain any code, that
       
    41 // might leave.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 GSSIPProfileUtil::GSSIPProfileUtil()
       
    45     {
       
    46     __GSLOGSTRING("GSSIPProfileUtil::GSSIPProfileUtil" )
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // GSSIPProfileUtil::CopyProfileAttributesL
       
    51 // Copies profile attributes from temp data structure to profile
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 void GSSIPProfileUtil::CopyProfileAttributesL( 
       
    55     CSIPManagedProfile* aProfile, 
       
    56     const TSIPSettingsData& aProfileData )
       
    57     {
       
    58     __GSLOGSTRING("GSSIPProfileUtil::CopyProfileAttributesL Start" )
       
    59     // Service provider name
       
    60     HBufC8* providerName = 
       
    61         EscapeUtils::ConvertFromUnicodeToUtf8L( aProfileData.iProviderName );
       
    62     CleanupStack::PushL( providerName );
       
    63     User::LeaveIfError( 
       
    64     	aProfile->SetParameter( KSIPProviderName, providerName->Des() ) );
       
    65     CleanupStack::PopAndDestroy( providerName ) ;
       
    66     
       
    67     // Service profile
       
    68     aProfile->SetType( aProfileData.iServiceProfile );      
       
    69     
       
    70     if ( aProfileData.iSNAPIndex != KDefaultSNAP )
       
    71         {
       
    72         // SNAP index
       
    73         User::LeaveIfError( aProfile->SetParameter( 
       
    74         KSIPSnapId, (TUint32)aProfileData.iSNAPIndex ) );
       
    75         }
       
    76     else
       
    77         {
       
    78         // AP index
       
    79         User::LeaveIfError( aProfile->SetParameter( 
       
    80             KSIPAccessPointId, (TUint32)aProfileData.iAPIndex ) );
       
    81         }
       
    82     
       
    83     // Publib username / address of record
       
    84     if ( aProfileData.iUsername.Length() )
       
    85         {
       
    86         TBool protocolFound( EFalse );
       
    87         
       
    88         TBuf<KSIPProtocolHeaderLength + 1> sipHeader( KSIPProtocolHeader );
       
    89         sipHeader.Append( KSIPColonSeparator );
       
    90         TBuf<KSIPSProtocolHeaderLength + 1> sipsHeader( KSIPSProtocolHeader );
       
    91         sipsHeader.Append( KSIPColonSeparator );
       
    92         
       
    93         EscapeUtils::TEscapeMode mode = EscapeUtils::EEscapeNormal;
       
    94         HBufC8* conv = 
       
    95             EscapeUtils::ConvertFromUnicodeToUtf8L( aProfileData.iUsername );
       
    96         CleanupStack::PushL( conv );
       
    97         HBufC8* enc = EscapeUtils::EscapeEncodeL( conv->Des(), mode );
       
    98         CleanupStack::PushL( enc );
       
    99         
       
   100         // Set public username if "sip:" was found.
       
   101         if ( aProfileData.iUsername.Length() > KSIPProtocolHeaderLength )
       
   102             {
       
   103             TBuf<KSIPProtocolHeaderLength + 1> lowerCase;
       
   104             lowerCase.Copy( aProfileData.iUsername.Left( 
       
   105                 KSIPProtocolHeaderLength + 1 ) );
       
   106             lowerCase.LowerCase();
       
   107             
       
   108             if ( !sipHeader.Compare( lowerCase ) )
       
   109                 {
       
   110                 User::LeaveIfError( 
       
   111                 	aProfile->SetParameter( KSIPUserAor, enc->Des() ) );
       
   112                 protocolFound = ETrue;
       
   113                 }
       
   114             }
       
   115         
       
   116         // Set public username if "sips:" was found.
       
   117         if ( aProfileData.iUsername.Length() > KSIPSProtocolHeaderLength )
       
   118             {
       
   119             TBuf<KSIPSProtocolHeaderLength + 1> lowerCase;
       
   120             lowerCase.Copy( aProfileData.iUsername.Left( 
       
   121                 KSIPSProtocolHeaderLength + 1 ) );
       
   122             lowerCase.LowerCase();
       
   123                 
       
   124             if ( !sipsHeader.Compare( lowerCase ) )
       
   125                 {
       
   126                 User::LeaveIfError( 
       
   127                 	aProfile->SetParameter( KSIPUserAor, enc->Des() ) );
       
   128                 protocolFound = ETrue;
       
   129                 }
       
   130             }
       
   131         
       
   132         // Set scheme and public username
       
   133         if ( !protocolFound )
       
   134             {
       
   135             TInt length = enc->Length() + sipHeader.Length();
       
   136             HBufC8* username = HBufC8::NewLC( length );
       
   137             username->Des().Append( sipHeader );
       
   138             username->Des().Append( enc->Des() );
       
   139                 
       
   140             // Cut some characters if length exceeds max. username length.
       
   141 			if ( length > KMaxUsernameLength )
       
   142             	{
       
   143                 username->Des().Delete( 
       
   144                     KMaxUsernameLength, length - KMaxUsernameLength );
       
   145                 }
       
   146 
       
   147             User::LeaveIfError(
       
   148             	aProfile->SetParameter( KSIPUserAor, username->Des() ) );
       
   149             CleanupStack::PopAndDestroy( username );
       
   150             }
       
   151         
       
   152         CleanupStack::PopAndDestroy( enc );
       
   153         CleanupStack::PopAndDestroy( conv );    
       
   154         }
       
   155     else
       
   156        	{
       
   157        	User::LeaveIfError( 
       
   158                	aProfile->SetParameter( KSIPUserAor, KNullDesC8 ) );
       
   159        	}
       
   160         
       
   161     // Compression setting
       
   162     TBool compression = ( aProfileData.iCompression == EGSComprYes );
       
   163     User::LeaveIfError( aProfile->SetParameter( KSIPSigComp, compression ) );
       
   164     
       
   165     // Registration mode
       
   166     if ( aProfileData.iRegistrationMode == EGSWhenNeeded )
       
   167     	{
       
   168     	User::LeaveIfError( 
       
   169     		aProfile->SetParameter( KSIPAutoRegistration, EFalse ) );
       
   170     	}
       
   171     else
       
   172     	{
       
   173     	User::LeaveIfError( 
       
   174     		aProfile->SetParameter( KSIPAutoRegistration, ETrue ) );
       
   175     	}
       
   176     
       
   177     // Security negotiation
       
   178     TBool security = ( aProfileData.iSecurity == EGSSecurityOn );
       
   179     User::LeaveIfError( 
       
   180     	aProfile->SetParameter( KSIPSecurityNegotiation, security ) );
       
   181     __GSLOGSTRING("GSSIPProfileUtil::CopyProfileAttributesL End" )
       
   182     }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // GSSIPProfileUtil::CopyServerAttributesL
       
   186 // Copies server attributes from temp data structure to profile
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 void GSSIPProfileUtil::CopyServerAttributesL(
       
   190     CSIPManagedProfile* aProfile,
       
   191     TUint32 aServer,
       
   192     const TGSSIPServerData& aProfileData )
       
   193     {
       
   194     __GSLOGSTRING("GSSIPProfileUtil::CopyServerAttributesL Start" )
       
   195     TInt err( KErrNone );
       
   196     EscapeUtils::TEscapeMode mode = EscapeUtils::EEscapeNormal;
       
   197     
       
   198     // Digest realm
       
   199     HBufC8* realm =
       
   200         EscapeUtils::ConvertFromUnicodeToUtf8L( aProfileData.iRealm );
       
   201     CleanupStack::PushL( realm );
       
   202     HBufC8* encRealm = EscapeUtils::EscapeEncodeL( realm->Des(), mode ); 
       
   203     ReplaceEscapedSpace( encRealm );
       
   204     err = aProfile->SetParameter( 
       
   205         aServer, KSIPDigestRealm, encRealm->Des() );
       
   206     delete encRealm;
       
   207     CleanupStack::PopAndDestroy( realm );
       
   208     User::LeaveIfError( err );
       
   209 
       
   210     // Username        
       
   211     HBufC8* uname =
       
   212         EscapeUtils::ConvertFromUnicodeToUtf8L( aProfileData.iUsername ); 
       
   213     CleanupStack::PushL( uname );
       
   214     HBufC8* encUname = EscapeUtils::EscapeEncodeL( uname->Des(), mode );    
       
   215     err = aProfile->SetParameter( 
       
   216         aServer, KSIPDigestUserName, encUname->Des() );
       
   217     delete encUname;
       
   218     CleanupStack::PopAndDestroy( uname );
       
   219     User::LeaveIfError( err );
       
   220     
       
   221     // Password
       
   222     if ( aProfileData.iPasswordChanged )
       
   223 	    {
       
   224 	    HBufC8* passw =
       
   225 	        EscapeUtils::ConvertFromUnicodeToUtf8L( aProfileData.iPassword );
       
   226 	    CleanupStack::PushL( passw );    
       
   227 	    err = aProfile->SetParameter( 
       
   228 	        aServer, KSIPDigestPassword, passw->Des() );    
       
   229 	    CleanupStack::PopAndDestroy( passw );
       
   230 	    User::LeaveIfError( err );	    	
       
   231 	    }
       
   232     
       
   233     // Address
       
   234     GSSIPProfileUtil::CopyServerURIL( aProfile, aServer, aProfileData );
       
   235     __GSLOGSTRING("GSSIPProfileUtil::CopyServerAttributesL End" )
       
   236     }
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // GSSIPProfileUtil::CopyToTempStructL
       
   240 // Copies profile attributes from profile to temp data struct
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 void GSSIPProfileUtil::CopyToTempStructL(
       
   244     CSIPManagedProfile* aProfile,
       
   245     TSIPSettingsData& aProfileData )
       
   246     {
       
   247     __GSLOGSTRING("GSSIPProfileUtil::CopyToTempStructL Start" )
       
   248     // Profile ID
       
   249     TUint32 id( KErrNone );
       
   250     aProfile->GetParameter( KSIPProfileId, id );
       
   251     aProfileData.iID = id;
       
   252     
       
   253     // Service provider name
       
   254     const TDesC8* providerName;
       
   255     aProfile->GetParameter( KSIPProviderName, providerName );
       
   256     HBufC* providerName16 = 
       
   257         EscapeUtils::ConvertToUnicodeFromUtf8L( *providerName );    
       
   258     aProfileData.iProviderName.Copy( 
       
   259     	providerName16->Des().LeftTPtr( KMaxSIPProviderNameLength ) );
       
   260     delete providerName16;
       
   261     
       
   262     // Profile type    
       
   263     aProfileData.iServiceProfile = aProfile->Type();
       
   264     
       
   265     // Access Point ID
       
   266     aProfile->GetParameter( KSIPAccessPointId, id );
       
   267     aProfileData.iAPIndex = id;
       
   268     
       
   269     // Destination ID
       
   270     TInt err( KErrNone );
       
   271     err = aProfile->GetParameter( KSIPSnapId, id );
       
   272     if ( !err && ( static_cast<TInt>(id) != KErrNotFound) )
       
   273         {
       
   274         aProfileData.iSNAPIndex = id;
       
   275         }
       
   276     else
       
   277     	{
       
   278         aProfileData.iSNAPIndex = KDefaultSNAP;
       
   279     	}
       
   280     
       
   281     // Public username / address of record
       
   282     const TDesC8* userName;
       
   283     aProfile->GetParameter( KSIPUserAor, userName );
       
   284     HBufC8* decodedUsername = EscapeUtils::EscapeDecodeL( *userName );
       
   285     CleanupStack::PushL( decodedUsername );
       
   286     HBufC* userName16 =
       
   287         EscapeUtils::ConvertToUnicodeFromUtf8L( decodedUsername->Des() );
       
   288     aProfileData.iUsername.Copy( 
       
   289     	userName16->Des().LeftTPtr( KMaxUsernameLength ) );    
       
   290     delete userName16;
       
   291     CleanupStack::PopAndDestroy( decodedUsername );
       
   292     
       
   293      // Registration mode
       
   294     TBool mode;
       
   295     aProfile->GetParameter( KSIPAutoRegistration, mode );
       
   296     if ( mode )
       
   297         {
       
   298         aProfileData.iRegistrationMode = EGSAlwaysOn;
       
   299         }
       
   300     else
       
   301         {
       
   302         aProfileData.iRegistrationMode = EGSWhenNeeded;
       
   303         }
       
   304 
       
   305     // Signal compression
       
   306     TBool compression;
       
   307     aProfile->GetParameter( KSIPSigComp, compression );
       
   308     if( compression )
       
   309         {
       
   310         aProfileData.iCompression = EGSComprYes;
       
   311         }
       
   312     else
       
   313         {
       
   314         aProfileData.iCompression = EGSComprNo;
       
   315         }
       
   316     
       
   317     // Security negotiation
       
   318     TBool negotiation;
       
   319     aProfile->GetParameter( KSIPSecurityNegotiation,negotiation );
       
   320     if( negotiation )
       
   321         {
       
   322         aProfileData.iSecurity = EGSSecurityOn;
       
   323         }
       
   324     else
       
   325         {   
       
   326         aProfileData.iSecurity = EGSSecurityOff;
       
   327         }
       
   328     
       
   329     // Private user identity
       
   330     const TDesC8* privateIdentity;
       
   331     aProfile->GetParameter( KSIPPrivateIdentity, privateIdentity );
       
   332     HBufC8* decodedIdentity = EscapeUtils::EscapeDecodeL( *privateIdentity );
       
   333     CleanupStack::PushL( decodedIdentity );
       
   334     HBufC* privateIdentity16 =
       
   335         EscapeUtils::ConvertToUnicodeFromUtf8L( decodedIdentity->Des() );
       
   336     aProfileData.iRegistrar.iPrivateIdentity.Copy( 
       
   337     	privateIdentity16->Des().LeftTPtr( KMaxServerPrivateIdentityLength ) );
       
   338     delete privateIdentity16;
       
   339     CleanupStack::PopAndDestroy( decodedIdentity );
       
   340     __GSLOGSTRING("GSSIPProfileUtil::CopyToTempStructL End" )
       
   341     }
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // GSSIPProfileUtil::CopyServerSettingsToTempStructL
       
   345 // Copies server attributes from profile to temp data struct
       
   346 // -----------------------------------------------------------------------------
       
   347 //
       
   348 void GSSIPProfileUtil::CopyServerSettingsToTempStructL(
       
   349     CSIPManagedProfile* aProfile,
       
   350     TUint32 aServer,
       
   351     TGSSIPServerData& aProfileData )
       
   352     {
       
   353     __GSLOGSTRING("GSSIPProfileUtil::CopyServerSettingsToTempStructL Start" )
       
   354     SIPStrings::OpenL();
       
   355 
       
   356     // Digest realm
       
   357     const TDesC8* realm;
       
   358     TInt err = aProfile->GetParameter( aServer, KSIPDigestRealm, realm );
       
   359     User::LeaveIfError( err );
       
   360     
       
   361     HBufC8* decodedRealm = EscapeUtils::EscapeDecodeL( *realm );
       
   362     CleanupStack::PushL( decodedRealm );
       
   363     HBufC* realm16 =
       
   364         EscapeUtils::ConvertToUnicodeFromUtf8L( decodedRealm->Des() );
       
   365     aProfileData.iRealm.Copy( realm16->Des().LeftTPtr( KMaxRealmLength ) );
       
   366     delete realm16;
       
   367     CleanupStack::PopAndDestroy( decodedRealm );
       
   368     
       
   369     // Username
       
   370     const TDesC8* uName;
       
   371     err = aProfile->GetParameter( aServer, KSIPDigestUserName, uName );
       
   372     User::LeaveIfError( err );
       
   373     
       
   374     HBufC8* decodedUname = EscapeUtils::EscapeDecodeL( *uName );
       
   375     CleanupStack::PushL( decodedUname );
       
   376     HBufC* uName16 =
       
   377             EscapeUtils::ConvertToUnicodeFromUtf8L( decodedUname->Des() );
       
   378     aProfileData.iUsername.Copy( 
       
   379     	uName16->Des().LeftTPtr( KMaxServerUsernameLength ) );
       
   380     delete uName16;
       
   381     CleanupStack::PopAndDestroy( decodedUname );
       
   382     
       
   383     // Server address and other params
       
   384     const TDesC8* uri;
       
   385     err = aProfile->GetParameter( aServer, KSIPServerAddress, uri );
       
   386     User::LeaveIfError( err );
       
   387     
       
   388     if ( !uri->Length() )
       
   389         {
       
   390         // Set default settings if URI is empty.
       
   391         aProfileData.iAddress.Zero();
       
   392         aProfileData.iPortNumber = KDefaultPortNumber;
       
   393         aProfileData.iTransportProtocol = EGSTranspProtocolAuto;
       
   394         if ( aServer == KSIPOutboundProxy )
       
   395             {
       
   396             aProfileData.iLooseRouting = EGSLooseRoutingOn;
       
   397             }
       
   398         }
       
   399     else
       
   400         {
       
   401         // Parse uri
       
   402         TUriParser8 parser;
       
   403         User::LeaveIfError( parser.Parse( *uri ) );
       
   404         aProfileData.iAddress.Zero();
       
   405         
       
   406         // Scheme
       
   407         if ( parser.IsPresent( EUriScheme ) )
       
   408             {
       
   409             const TDesC8& scheme = parser.Extract( EUriScheme );
       
   410             HBufC* scheme16 = EscapeUtils::ConvertToUnicodeFromUtf8L(scheme);
       
   411             TPtr trimmedScheme ( scheme16->Des().LeftTPtr(
       
   412             	KMaxProxyLength-aProfileData.iAddress.Length() ) );
       
   413             aProfileData.iAddress.Append( trimmedScheme );
       
   414             aProfileData.iAddress.Append( KSIPColonSeparator );
       
   415             delete scheme16;
       
   416             }
       
   417         else
       
   418             {
       
   419             aProfileData.iAddress.Append( KSIPProtocolHeader );
       
   420             aProfileData.iAddress.Append( KSIPColonSeparator );
       
   421             }
       
   422         
       
   423         // Host
       
   424         if ( parser.IsPresent( EUriHost ) )
       
   425             {
       
   426             const TDesC8& host = parser.Extract( EUriHost );
       
   427             UriUtils::TUriHostType type = UriUtils::HostType( host );
       
   428             if ( type == UriUtils::EIPv6Host )
       
   429                 {
       
   430                 HBufC8* ipv6Host8 = HBufC8::NewLC( host.Length() + 2 );
       
   431                 ipv6Host8->Des().Copy( host );
       
   432                 GSSIPProfileUtil::AddBrackets( ipv6Host8->Des() );
       
   433                 HBufC* ipv6Host16 = 
       
   434                     EscapeUtils::ConvertToUnicodeFromUtf8L( *ipv6Host8 );
       
   435 	            TPtr trimmedHost ( ipv6Host16->Des().LeftTPtr(
       
   436 	            	KMaxProxyLength-aProfileData.iAddress.Length() ) );
       
   437                 aProfileData.iAddress.Append( trimmedHost );
       
   438                 delete ipv6Host16;
       
   439                 CleanupStack::PopAndDestroy( ipv6Host8 );
       
   440                 }
       
   441             else
       
   442                 {
       
   443                 HBufC* ipv4Host16 = 
       
   444                     EscapeUtils::ConvertToUnicodeFromUtf8L( host );
       
   445 	            TPtr trimmedHost ( ipv4Host16->Des().LeftTPtr(
       
   446 	            	KMaxProxyLength-aProfileData.iAddress.Length() ) );
       
   447                 aProfileData.iAddress.Append( trimmedHost );
       
   448                 delete ipv4Host16;
       
   449                 }    
       
   450             }
       
   451         
       
   452         // Port
       
   453         if ( parser.IsPresent( EUriPort ) )
       
   454             {
       
   455             const TDesC8& port = parser.Extract( EUriPort );
       
   456             TLex8 lex( port );
       
   457             lex.Val( aProfileData.iPortNumber );
       
   458             
       
   459             if ( aProfileData.iPortNumber < 0 )
       
   460 	            {
       
   461 				aProfileData.iPortNumber = KDefaultPortNumber;	            	
       
   462 	            }
       
   463             }
       
   464         else
       
   465             {
       
   466             aProfileData.iPortNumber = KDefaultPortNumber;
       
   467             }
       
   468         
       
   469         // Loose routing and transport
       
   470         if ( parser.IsPresent( EUriPath ) )
       
   471             {
       
   472             const TDesC8& path = parser.Extract( EUriPath );
       
   473         
       
   474             TDelimitedPathSegmentParser8 pathSegmentParser; 
       
   475             pathSegmentParser.Parse( path ); 
       
   476             TPtrC8 segment; 
       
   477         
       
   478             // Set temporary values for loose routing and transport.
       
   479             aProfileData.iLooseRouting = EGSLooseRoutingOff;
       
   480             aProfileData.iTransportProtocol = EGSTranspProtocolAuto;
       
   481         
       
   482             while( pathSegmentParser.GetNext( segment ) == KErrNone ) 
       
   483                 {   
       
   484                 TBuf<KMaxSegmentLength> seg;
       
   485                 seg.Copy( segment );
       
   486                 seg.LowerCase();
       
   487                 // Loose routing
       
   488                 if ( !seg.Compare( KLooseRoutingParam ) )
       
   489                     {
       
   490                     aProfileData.iLooseRouting = EGSLooseRoutingOn;
       
   491                     }
       
   492                 // Transport
       
   493                 if ( !seg.Find( KTransportParamPrefix ) )
       
   494                     {
       
   495                     seg.UpperCase();
       
   496                     if ( !seg.Right( KTCP().Length() ).Compare( KTCP ) )
       
   497                         {
       
   498                         aProfileData.iTransportProtocol = EGSTranspProtocolTCP;
       
   499                         }
       
   500                     if ( !seg.Right( KUDP().Length() ).Compare( KUDP ) )
       
   501                         {
       
   502                         aProfileData.iTransportProtocol = EGSTranspProtocolUDP;
       
   503                         }
       
   504                     }
       
   505                 }    
       
   506             }
       
   507         }
       
   508         
       
   509     SIPStrings::Close();    
       
   510     __GSLOGSTRING("GSSIPProfileUtil::CopyServerSettingsToTempStructL End" )
       
   511     }
       
   512 
       
   513 // -----------------------------------------------------------------------------
       
   514 // GSSIPProfileUtil::ProfileModificationsL
       
   515 // Compares profile attributes with the ones on the temporary structure
       
   516 // -----------------------------------------------------------------------------
       
   517 //
       
   518 TBool GSSIPProfileUtil::ProfileModificationsL(
       
   519     CSIPManagedProfile* aProfile,
       
   520     const TSIPSettingsData& aProfileData )
       
   521     {
       
   522     __GSLOGSTRING("GSSIPProfileUtil::ProfileModificationsL Start" )
       
   523     TInt err( KErrNone );
       
   524     TBool modifs = EFalse;
       
   525     
       
   526     // Service provider name
       
   527     const TDesC8* pName;
       
   528     HBufC8* providerName = 
       
   529         EscapeUtils::ConvertFromUnicodeToUtf8L( aProfileData.iProviderName );
       
   530     CleanupStack::PushL( providerName );    
       
   531     aProfile->GetParameter( KSIPProviderName, pName );
       
   532     User::LeaveIfError( err );
       
   533     TBool nameComp = providerName->Des().Compare( *pName ) != 0;
       
   534     CleanupStack::PopAndDestroy( providerName );
       
   535 
       
   536     // Public username / address of record
       
   537     const TDesC8* aor;
       
   538     HBufC8* userName = 
       
   539         EscapeUtils::ConvertFromUnicodeToUtf8L( aProfileData.iUsername );
       
   540     CleanupStack::PushL( userName );
       
   541     err = aProfile->GetParameter( KSIPUserAor, aor );
       
   542     User::LeaveIfError( err );
       
   543     HBufC8* decodedAor = EscapeUtils::EscapeDecodeL( *aor );
       
   544     TBool uNameComp = userName->Des().Compare( decodedAor->Des() ) != 0;
       
   545     delete decodedAor;
       
   546     CleanupStack::PopAndDestroy( userName );
       
   547     
       
   548     // Destination 
       
   549     TUint32 snapid;    
       
   550     TBool snapComp = EFalse;
       
   551     TBool snapUsed = EFalse;
       
   552     
       
   553     err = aProfile->GetParameter( KSIPSnapId, snapid );
       
   554     if ( err == KErrNotFound )
       
   555         {
       
   556         if ( aProfileData.iSNAPIndex != KDefaultSNAP )
       
   557 	        {
       
   558 	        snapComp = ETrue;	        	
       
   559 	        }
       
   560         }
       
   561     else 
       
   562         {
       
   563 		if(snapid == KDefaultSNAPIdentifier && aProfileData.iSNAPIndex == KDefaultSNAP)
       
   564 			{
       
   565 			snapUsed=EFalse;
       
   566 			snapComp=EFalse;
       
   567 			}
       
   568 		else
       
   569 			{
       
   570 	        User::LeaveIfError( err );  
       
   571     	    snapUsed = ETrue;
       
   572         	snapComp = TUint( aProfileData.iSNAPIndex ) != snapid;
       
   573 			}
       
   574         }
       
   575 
       
   576     // Access Point 
       
   577     TUint32 apid;    
       
   578     err = aProfile->GetParameter( KSIPAccessPointId, apid );
       
   579     User::LeaveIfError( err );  
       
   580 
       
   581 	TBool iapComp (EFalse);
       
   582     if ( !snapUsed )
       
   583     	{
       
   584 	    iapComp = TUint( aProfileData.iAPIndex ) != apid;	
       
   585     	}
       
   586         
       
   587     // Signaling compression
       
   588     TBool sigcomp;
       
   589     err = aProfile->GetParameter( KSIPSigComp, sigcomp );
       
   590     User::LeaveIfError( err );
       
   591     TBool comprComp = 
       
   592         aProfileData.iCompression == (TInt)sigcomp ? EFalse : ETrue;
       
   593     
       
   594     // Registration method
       
   595     TBool registration;
       
   596     TBool registrationComp = EFalse;
       
   597     err = aProfile->GetParameter( KSIPAutoRegistration, registration );
       
   598     User::LeaveIfError( err );
       
   599     if ( aProfileData.iRegistrationMode == EGSWhenNeeded )
       
   600     	{
       
   601     	if ( registration )
       
   602     		{
       
   603     		registrationComp = ETrue;
       
   604     		}
       
   605     	}
       
   606     else if ( aProfileData.iRegistrationMode == EGSAlwaysOn )
       
   607     	{
       
   608     	if ( !registration )
       
   609     		{ // was WhenNeeded or 'only on home network'
       
   610     		registrationComp = ETrue;
       
   611     		}
       
   612     	}
       
   613    
       
   614     // Security negotiation        
       
   615     TBool negation;
       
   616     err = aProfile->GetParameter( KSIPSecurityNegotiation, negation );
       
   617     User::LeaveIfError( err );
       
   618     TBool securityComp = 
       
   619         aProfileData.iSecurity == (TInt)negation ? EFalse : ETrue;
       
   620  
       
   621     TBool serviceComp = ( aProfileData.iServiceProfile.iSIPProfileName !=
       
   622                           aProfile->Type().iSIPProfileName ) ||
       
   623                         ( aProfileData.iServiceProfile.iSIPProfileClass !=
       
   624                           aProfile->Type().iSIPProfileClass );
       
   625 
       
   626     if ( nameComp || iapComp || snapComp || comprComp || registrationComp ||
       
   627          securityComp || uNameComp || serviceComp )
       
   628         {        
       
   629         modifs = ETrue;
       
   630         }   
       
   631     __GSLOGSTRING("GSSIPProfileUtil::ProfileModificationsL End" ) 
       
   632     return modifs;
       
   633     }
       
   634 
       
   635 // -----------------------------------------------------------------------------
       
   636 // GSSIPProfileUtil::ServerModifciationsL
       
   637 // Compares server attributes with the ones on the temporary structure
       
   638 // -----------------------------------------------------------------------------
       
   639 //
       
   640 TBool GSSIPProfileUtil::ServerModificationsL(
       
   641     CSIPManagedProfile* aProfile,
       
   642     TUint32 aServer,
       
   643     const TGSSIPServerData& aData )
       
   644     {
       
   645     __GSLOGSTRING("GSSIPProfileUtil::ServerModificationsL" )
       
   646     TGSSIPServerData serverData;
       
   647 
       
   648     GSSIPProfileUtil::CopyServerSettingsToTempStructL( 
       
   649         aProfile, aServer, serverData );
       
   650 
       
   651     TBool addrComp  = serverData.iAddress != aData.iAddress;
       
   652     TBool lrComp    = ( serverData.iLooseRouting != aData.iLooseRouting && 
       
   653                         aServer != KSIPRegistrar );
       
   654     TBool realmComp = serverData.iRealm != aData.iRealm;
       
   655     TBool uNameComp = serverData.iUsername != aData.iUsername;
       
   656 
       
   657     TBool tpComp    = serverData.iTransportProtocol != aData.iTransportProtocol;
       
   658     TBool portComp  = serverData.iPortNumber != aData.iPortNumber;
       
   659 
       
   660     return ( addrComp || lrComp || realmComp || uNameComp || aData.iPasswordChanged ||
       
   661              tpComp || portComp );
       
   662     }
       
   663 
       
   664 // -----------------------------------------------------------------------------
       
   665 // GSSIPProfileUtil::CopyProfileL
       
   666 // Copies profile attributes from one profile to another
       
   667 // -----------------------------------------------------------------------------
       
   668 //
       
   669 void GSSIPProfileUtil::CopyProfileL(
       
   670     CSIPManagedProfile* aOrigProfile,
       
   671     CSIPManagedProfile* aCopiedProfile )
       
   672     {
       
   673     __GSLOGSTRING("GSSIPProfileUtil::CopyProfileL Start" )
       
   674     TInt err( KErrNone );
       
   675     // Copy profile settings
       
   676     aCopiedProfile->SetType( aOrigProfile->Type() );
       
   677     
       
   678     TUint32 apid;
       
   679     err = aOrigProfile->GetParameter( KSIPAccessPointId, apid );
       
   680     User::LeaveIfError( err );
       
   681     err = aCopiedProfile->SetParameter( KSIPAccessPointId, apid );    
       
   682     User::LeaveIfError( err );
       
   683     	
       
   684     const TDesC8* aor; 
       
   685     err = aOrigProfile->GetParameter( KSIPUserAor, aor );
       
   686     User::LeaveIfError( err );
       
   687     err = aCopiedProfile->SetParameter( KSIPUserAor, *aor ); 
       
   688 	User::LeaveIfError( err );
       
   689 	
       
   690 	const TDesC8* identity; 
       
   691 	err = aOrigProfile->GetParameter(KSIPPrivateIdentity, identity );
       
   692     User::LeaveIfError( err );
       
   693     err = aCopiedProfile->SetParameter( KSIPPrivateIdentity, *identity );
       
   694 	User::LeaveIfError( err );
       
   695 	
       
   696 	const TDesC8* provider;
       
   697 	err = aOrigProfile->GetParameter( KSIPProviderName, provider );
       
   698 	User::LeaveIfError( err );
       
   699 	err = aCopiedProfile->SetParameter(KSIPProviderName, *provider );
       
   700 	User::LeaveIfError( err );
       
   701 	
       
   702 	TBool sigcomp;
       
   703 	err = aOrigProfile->GetParameter( KSIPSigComp,sigcomp );
       
   704 	User::LeaveIfError( err );
       
   705 	err = aCopiedProfile->SetParameter( KSIPSigComp,sigcomp );
       
   706 	User::LeaveIfError( err );
       
   707 	
       
   708 	TBool autoregistration;
       
   709 	err = aOrigProfile->GetParameter( KSIPAutoRegistration,autoregistration );
       
   710 	User::LeaveIfError( err );
       
   711 	err = aCopiedProfile->SetParameter( KSIPAutoRegistration,autoregistration );
       
   712 	User::LeaveIfError( err );
       
   713 	
       
   714 	TBool negation;
       
   715 	err = aOrigProfile->GetParameter( KSIPSecurityNegotiation, negation );
       
   716 	User::LeaveIfError( err );
       
   717 	err = aCopiedProfile->SetParameter( KSIPSecurityNegotiation, negation );
       
   718 	User::LeaveIfError( err );
       
   719 		
       
   720     TBool defaultValue;
       
   721     err = aOrigProfile->GetParameter( KSIPDefaultProfile, defaultValue );
       
   722     User::LeaveIfError( err );
       
   723     if ( defaultValue )
       
   724         {
       
   725         err = aCopiedProfile->SetParameter( KSIPDefaultProfile, defaultValue );
       
   726         User::LeaveIfError( err );
       
   727         }
       
   728 
       
   729     // Copy Proxy settings
       
   730     const TDesC8* address;
       
   731     err = aOrigProfile->GetParameter( KSIPOutboundProxy, KSIPServerAddress, address );
       
   732     User::LeaveIfError( err );
       
   733     err = aCopiedProfile->SetParameter( KSIPOutboundProxy, KSIPServerAddress, *address );
       
   734     User::LeaveIfError( err );
       
   735     
       
   736     const TDesC8* realm;
       
   737     err = aOrigProfile->GetParameter( KSIPOutboundProxy, KSIPDigestRealm, realm );
       
   738     User::LeaveIfError( err );
       
   739     err = aCopiedProfile->SetParameter( KSIPOutboundProxy, KSIPDigestRealm, *realm );    
       
   740     User::LeaveIfError( err );
       
   741     
       
   742     const TDesC8* user;
       
   743     err = aOrigProfile->GetParameter( KSIPOutboundProxy, KSIPDigestUserName, user );
       
   744     User::LeaveIfError( err );
       
   745     err = aCopiedProfile->SetParameter( KSIPOutboundProxy, KSIPDigestUserName, *user ); 
       
   746     User::LeaveIfError( err );
       
   747  
       
   748     // Copy Registrar server settings
       
   749     err = aOrigProfile->GetParameter( KSIPRegistrar, KSIPServerAddress, address );
       
   750     User::LeaveIfError( err );
       
   751     err = aCopiedProfile->SetParameter( KSIPRegistrar, KSIPServerAddress, *address );
       
   752     User::LeaveIfError( err );
       
   753     
       
   754     err = aOrigProfile->GetParameter( KSIPRegistrar, KSIPDigestRealm, realm );
       
   755     User::LeaveIfError( err );
       
   756     err = aCopiedProfile->SetParameter( KSIPRegistrar, KSIPDigestRealm, *realm );    
       
   757     User::LeaveIfError( err );
       
   758 
       
   759     err = aOrigProfile->GetParameter( KSIPRegistrar, KSIPDigestUserName, user );
       
   760     User::LeaveIfError( err );
       
   761     err = aCopiedProfile->SetParameter( KSIPRegistrar, KSIPDigestUserName, *user ); 
       
   762     User::LeaveIfError( err );
       
   763     __GSLOGSTRING("GSSIPProfileUtil::CopyProfileL End" )
       
   764     }
       
   765 
       
   766 // -----------------------------------------------------------------------------
       
   767 // GSSIPProfileUtil::CopyServerURIL
       
   768 // Copies server URI to the profile
       
   769 // -----------------------------------------------------------------------------
       
   770 //
       
   771 void GSSIPProfileUtil::CopyServerURIL(
       
   772     CSIPManagedProfile* aProfile,
       
   773     TUint32 aServer,
       
   774     const TGSSIPServerData& aProfileData )
       
   775     {
       
   776     __GSLOGSTRING("GSSIPProfileUtil::CopyServerURIL Start" )
       
   777     SIPStrings::OpenL();
       
   778     
       
   779     // Set settings to KSIPServerAddress param.
       
   780     if ( aProfileData.iAddress.Length() > 0 )
       
   781         {
       
   782         HBufC8* finalAddress = HBufC8::NewLC( KMaxProxyLength * 2 );
       
   783         
       
   784         // Convert address to 8-bit descriptor format.
       
   785         TPtrC addr = aProfileData.iAddress;
       
   786         HBufC8* conv = EscapeUtils::ConvertFromUnicodeToUtf8L( addr );
       
   787         CleanupStack::PushL( conv );    
       
   788         
       
   789         // Parse address.
       
   790         TUriParser8 parser;
       
   791         User::LeaveIfError( parser.Parse( conv->Des() ) );
       
   792         // Append scheme to final address if needed.
       
   793         if ( !parser.IsPresent( EUriScheme ) )
       
   794             {
       
   795             finalAddress->Des().Append( KSIPProtocolHeader );
       
   796             finalAddress->Des().Append( KSIPColonSeparator );
       
   797             }
       
   798         // Append proxy/registrar address to final address.
       
   799         finalAddress->Des().Append( conv->Des() );
       
   800         // Check host type. Add brackets for ipv6 type of address.
       
   801         TUriParser8 parser2;
       
   802         User::LeaveIfError( parser2.Parse( finalAddress->Des() ) );
       
   803         if ( parser2.IsPresent( EUriHost ) )
       
   804             {
       
   805             const TDesC8& scheme = parser2.Extract( EUriScheme );
       
   806             const TDesC8& host = parser2.Extract( EUriHost );
       
   807             UriUtils::TUriHostType type = UriUtils::HostType( host );
       
   808             if ( type == UriUtils::EIPv6Host )
       
   809                 {
       
   810                 HBufC8* ipv6Address = HBufC8::NewL( KMaxProxyLength );
       
   811                 ipv6Address->Des().Append( host );
       
   812                 GSSIPProfileUtil::AddBrackets( ipv6Address->Des() );
       
   813                 TBuf8<1> colon ( KNullDesC8 );
       
   814                 colon.Copy( KSIPColonSeparator );
       
   815                 ipv6Address->Des().Insert( 0, colon );
       
   816                 ipv6Address->Des().Insert( 0, scheme );
       
   817                 finalAddress->Des().Copy( ipv6Address->Des() ); 
       
   818                 delete ipv6Address;
       
   819                 }
       
   820             }
       
   821         CleanupStack::PopAndDestroy( conv );
       
   822 
       
   823         // Set used port if it's not default one.
       
   824         if ( aProfileData.iPortNumber != KDefaultPortNumber )
       
   825             {     
       
   826             TBuf8<KMaxLengthForPort> port;
       
   827             port.Num( aProfileData.iPortNumber );
       
   828             finalAddress->Des().Append( KSIPColonSeparator );
       
   829             finalAddress->Des().Append( port );
       
   830             }
       
   831 
       
   832         // Set uri path part if there is something to be added.
       
   833         HBufC8* finalPath = HBufC8::NewLC( KMaxLengthForPath ); 
       
   834         ParseUriPathL( aProfile, aServer, aProfileData, finalPath );
       
   835         finalAddress->Des().Append( finalPath->Des() );
       
   836         CleanupStack::PopAndDestroy( finalPath );
       
   837 
       
   838         // Set final address to profile.   
       
   839         TInt err = aProfile->SetParameter( 
       
   840             aServer, KSIPServerAddress, finalAddress->Des() );
       
   841         User::LeaveIfError( err );
       
   842 
       
   843         CleanupStack::PopAndDestroy( finalAddress );
       
   844         }
       
   845 	// If host is set to empty, empty KSIPServerAddress param.
       
   846     else
       
   847         {
       
   848         TInt err = aProfile->SetParameter( 
       
   849             aServer, KSIPServerAddress, KNullDesC8 );
       
   850         User::LeaveIfError( err );
       
   851         }
       
   852 
       
   853     SIPStrings::Close();
       
   854     __GSLOGSTRING("GSSIPProfileUtil::CopyServerURIL End" )
       
   855     }
       
   856 
       
   857 // -----------------------------------------------------------------------------
       
   858 // GSSIPProfileUtil::ParseUriPathL
       
   859 // Parses uri path.
       
   860 // -----------------------------------------------------------------------------
       
   861 //    
       
   862 void GSSIPProfileUtil::ParseUriPathL(
       
   863     CSIPManagedProfile* aProfile,
       
   864     TUint32 aServer,
       
   865     const TGSSIPServerData& aProfileData,
       
   866     HBufC8* aFinalPath )
       
   867     {
       
   868     __GSLOGSTRING("GSSIPProfileUtil::ParseUriPathL Start" )
       
   869     TInt err( KErrNone );
       
   870    
       
   871     // Add Loose routing param. (if needed)    
       
   872     if ( aServer != KSIPRegistrar && 
       
   873         aProfileData.iLooseRouting == EGSLooseRoutingOn ) 
       
   874         {
       
   875         aFinalPath->Des().Append( KSegmentSeparator );
       
   876         aFinalPath->Des().Append( KLooseRoutingParam );
       
   877         }
       
   878         
       
   879     // Add Transport param TCP. (if needed)
       
   880     if ( aProfileData.iTransportProtocol == EGSTranspProtocolTCP )
       
   881         {             
       
   882         aFinalPath->Des().Append( KSegmentSeparator );
       
   883         aFinalPath->Des().Append( KTransportParamPrefix );
       
   884         aFinalPath->Des().Append( KTCP );
       
   885         }
       
   886     
       
   887     // Add Transport param UDP. (if needed)
       
   888     if ( aProfileData.iTransportProtocol == EGSTranspProtocolUDP )
       
   889         {            
       
   890         aFinalPath->Des().Append( KSegmentSeparator );
       
   891         aFinalPath->Des().Append( KTransportParamPrefix );
       
   892         aFinalPath->Des().Append( KUDP );
       
   893         }
       
   894     
       
   895     // Get path data from saved profile.
       
   896     const TDesC8* serverTxt;
       
   897     err = aProfile->GetParameter( aServer, KSIPServerAddress, serverTxt );
       
   898     User::LeaveIfError( err );
       
   899     
       
   900     if ( serverTxt->Length() )
       
   901         {
       
   902         // Parse address.
       
   903         TUriParser8 parser;
       
   904         User::LeaveIfError( parser.Parse( *serverTxt ) );
       
   905         if ( parser.IsPresent( EUriPath ) )
       
   906             {
       
   907             const TDesC8& path = parser.Extract( EUriPath );
       
   908         
       
   909             // Put any other params than lr and transport back to string.            
       
   910             TDelimitedPathSegmentParser8 pathSegmentParser; 
       
   911             pathSegmentParser.Parse( path ); 
       
   912             TPtrC8 segment; 
       
   913             while( pathSegmentParser.GetNext( segment ) == KErrNone ) 
       
   914                 {   
       
   915                 TBuf<KMaxSegmentLength> seg;
       
   916                 seg.Copy( segment );
       
   917                 seg.LowerCase();
       
   918             
       
   919                 if ( seg.Compare( KLooseRoutingParam ) &&
       
   920                     seg.Find( KTransportParamPrefix ) )
       
   921                     {
       
   922                     aFinalPath->Des().Append( KSegmentSeparator );
       
   923                     aFinalPath->Des().Append( seg );
       
   924                     }
       
   925                 }
       
   926             }
       
   927         }
       
   928     __GSLOGSTRING("GSSIPProfileUtil::ParseUriPathL End" )
       
   929     }
       
   930     
       
   931 // -----------------------------------------------------------------------------
       
   932 // GSSIPProfileUtil::SchemeIncluded
       
   933 // Checks if sip or sips scheme included.
       
   934 // -----------------------------------------------------------------------------
       
   935 //    
       
   936 TInt GSSIPProfileUtil::SchemeIncluded( const TDesC8& aAddr, 
       
   937 										TBool aHostBrackets )
       
   938 	{
       
   939 	__GSLOGSTRING("GSSIPProfileUtil::SchemeIncluded" )
       
   940 	TLex8 lex( aAddr );
       
   941     lex.Mark();
       
   942     TUint chrCount = 0;
       
   943     TChar chr = lex.Get();
       
   944     while ( chr != 0 && chr != ':' )
       
   945     	{
       
   946         chrCount++;
       
   947         chr = lex.Get();
       
   948         }
       
   949 
       
   950     TBool sipSchemeIncluded( EFalse );
       
   951     if ( chr != 0 )
       
   952     	{
       
   953         chrCount++; //include ':' too
       
   954         TPtrC8 remainder = lex.RemainderFromMark();
       
   955         _LIT8(KSIPScheme, "sip:");
       
   956 		_LIT8(KSIPSScheme, "sips:");
       
   957 		
       
   958 		// set scheme to lovercase because of comparing
       
   959 		HBufC8* scheme = HBufC8::New( chrCount );
       
   960         scheme->Des().Copy( remainder.Left( chrCount ) );
       
   961         scheme->Des().LowerCase();
       
   962         
       
   963         if ( !scheme->Compare( KSIPScheme ) ||
       
   964         	!scheme->Compare( KSIPSScheme ) )
       
   965         	{
       
   966         	sipSchemeIncluded = ETrue;
       
   967         	}
       
   968         
       
   969         delete scheme;
       
   970         
       
   971         if ( aHostBrackets )
       
   972         	{ // check host brackets 
       
   973         	if ( sipSchemeIncluded )
       
   974         		{ // scheme separated from uri, check host
       
   975         		if( GSSIPProfileUtil::BracketsIncluded( 
       
   976         			remainder.Right( aAddr.Length() - chrCount ) ) == -1 )
       
   977         			{
       
   978         			sipSchemeIncluded = -1;
       
   979         			}
       
   980         		}
       
   981         	else
       
   982         		{ // scheme not included, check host == aAddr
       
   983         		if( GSSIPProfileUtil::BracketsIncluded( aAddr ) == -1)
       
   984         			{
       
   985         			sipSchemeIncluded = -1;
       
   986         			}
       
   987         		}
       
   988         	}
       
   989         }
       
   990     
       
   991 	return sipSchemeIncluded;
       
   992 	}
       
   993 	
       
   994 // -----------------------------------------------------------------------------
       
   995 // GSSIPProfileUtil::BracketsIncluded
       
   996 // Check if brackets included correctly in IPv6 reference.
       
   997 // -----------------------------------------------------------------------------
       
   998 //    
       
   999 TInt GSSIPProfileUtil::BracketsIncluded( TPtrC8 aHost )
       
  1000 	{
       
  1001 	__GSLOGSTRING("GSSIPProfileUtil::BracketsIncluded" )
       
  1002 	TBool ret ( ETrue );
       
  1003 	UriUtils::TUriHostType type = UriUtils::HostType( aHost );
       
  1004 	if ( type == UriUtils::EIPv6Host )
       
  1005 		{
       
  1006 		TLex8 lex( aHost );
       
  1007 	    lex.Mark();
       
  1008 	    TUint chrCount = 0;
       
  1009 	    TChar chr = lex.Get();
       
  1010 	    TInt lBracket( KErrNotFound );
       
  1011 	    TInt rBracket( KErrNotFound );
       
  1012 	    TInt separator( KErrNotFound );
       
  1013     
       
  1014     	while ( chr != 0 )
       
  1015 	    	{
       
  1016 	        if ( chr == '[' )
       
  1017 	        	{
       
  1018 	        	lBracket = chrCount;
       
  1019 	        	}
       
  1020 	        else if ( chr == ']' )
       
  1021 	        	{
       
  1022 	        	rBracket = chrCount;
       
  1023 	        	}
       
  1024 	        else if ( chr == '@' )
       
  1025 	        	{
       
  1026 	        	separator = chrCount;
       
  1027 	        	}
       
  1028 	        else
       
  1029 	        	{
       
  1030 	        	}
       
  1031 	        chrCount++;
       
  1032 	        chr = lex.Get();
       
  1033 	        }
       
  1034 	    chrCount--; // the last character 
       
  1035 	        
       
  1036 	    if ( lBracket == KErrNotFound && rBracket == KErrNotFound )
       
  1037     		{ //bracets not included, add them
       
  1038 			ret = EFalse;
       
  1039 	    	}
       
  1040 	    else if ( ( lBracket == KErrNotFound && rBracket != KErrNotFound) ||
       
  1041 	    	( lBracket != KErrNotFound && rBracket == KErrNotFound ) )
       
  1042 	    	{ // both brackets not found
       
  1043 	    	ret = KErrNotFound;
       
  1044 	    	}
       
  1045 	    else if ( lBracket != KErrNotFound && rBracket != KErrNotFound )
       
  1046 	    	{ //brackets are found
       
  1047 	    	if ( !( lBracket == 0 && rBracket == chrCount ) &&
       
  1048 	    		!( separator > 0 && lBracket ==  separator + 1 
       
  1049 	    			&& rBracket == chrCount ) )
       
  1050 	    		{ // brackets are placed incorrectly
       
  1051 	    		ret = KErrNotFound;
       
  1052 	    		}
       
  1053 	    	}
       
  1054 	    else
       
  1055 	    	{
       
  1056 	    	}
       
  1057 		}
       
  1058     return ret;
       
  1059 	
       
  1060 	}
       
  1061 	
       
  1062 // -----------------------------------------------------------------------------
       
  1063 // GSSIPProfileUtil::AddBrackets
       
  1064 // Adds brackets into IPv6 reference.
       
  1065 // -----------------------------------------------------------------------------
       
  1066 //    
       
  1067 void GSSIPProfileUtil::AddBrackets( TPtr8 aHost )
       
  1068 	{
       
  1069 	__GSLOGSTRING("GSSIPProfileUtil::AddBrackets" )
       
  1070 	_LIT8( KLBracket, "[" );
       
  1071     _LIT8( KRBracket, "]" );
       
  1072     
       
  1073     aHost.Insert( 0, KLBracket );
       
  1074     aHost.Append( KRBracket );
       
  1075     }
       
  1076     
       
  1077 // -----------------------------------------------------------------------------
       
  1078 // GSSIPProfileUtil::RemoveBrackets
       
  1079 // Remove brackets from IPv6 reference.
       
  1080 // -----------------------------------------------------------------------------
       
  1081 //    
       
  1082 void GSSIPProfileUtil::RemoveBrackets( TPtr8 aHost )
       
  1083 	{
       
  1084 	__GSLOGSTRING("GSSIPProfileUtil::RemoveBrackets" )
       
  1085 	TInt index;
       
  1086 	
       
  1087 	index = aHost.Locate( '[' );
       
  1088 	if ( index != KErrNotFound )
       
  1089 		{
       
  1090 		aHost.Delete( index, 1 );
       
  1091 		}
       
  1092 		
       
  1093 	index = aHost.Locate( ']' );
       
  1094 	if ( index != KErrNotFound )
       
  1095 		{
       
  1096 		aHost.Delete( index, 1 );
       
  1097 		}
       
  1098 	}
       
  1099 	
       
  1100 // -----------------------------------------------------------------------------
       
  1101 // GSSIPProfileUtil::URIValid
       
  1102 // Checks if reference is valid URI.
       
  1103 // -----------------------------------------------------------------------------
       
  1104 //    
       
  1105 TInt GSSIPProfileUtil::URIValid( const TDesC8& aValue )
       
  1106 	{
       
  1107 	__GSLOGSTRING("GSSIPProfileUtil::URIValid" )
       
  1108 	TUriParser8 parser;
       
  1109 	return parser.Parse(aValue);
       
  1110 	}
       
  1111 	
       
  1112 // -----------------------------------------------------------------------------
       
  1113 // GSSIPProfileUtil::ReplaceEscapedSpace
       
  1114 // Replace %20 to ' '.
       
  1115 // -----------------------------------------------------------------------------
       
  1116 //    
       
  1117 void GSSIPProfileUtil::ReplaceEscapedSpace( HBufC8* aValue )
       
  1118 	{
       
  1119 	__GSLOGSTRING("GSSIPProfileUtil::ReplaceEscapedSpace" )
       
  1120 	_LIT8( KEscapedSpace, "%20" );
       
  1121 	_LIT8( KSpace, " " );
       
  1122 	TInt pos = KErrNone;
       
  1123 	while ( pos != KErrNotFound )
       
  1124 		{
       
  1125 		pos = aValue->Des().Find( KEscapedSpace );
       
  1126 		if ( pos != KErrNotFound )
       
  1127 			{
       
  1128 			aValue->Des().Replace( pos, 3, KSpace );
       
  1129 			}
       
  1130 		}
       
  1131 	}
       
  1132 
       
  1133 // End of File