imstutils/xmppadapter/src/xmppadapter.cpp
branchRCL_3
changeset 22 3104fc151679
parent 21 2b7283837edb
child 23 9a48e301e94b
equal deleted inserted replaced
21:2b7283837edb 22:3104fc151679
     1 /*
       
     2 * Copyright (c) 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:  Handles XMPPAdapter settings in OMA provisioning.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <f32file.h>
       
    21 #include    <CWPCharacteristic.h>
       
    22 #include    <CWPParameter.h>
       
    23 #include    <pdpcontextmanagerinternalcrkeys.h>
       
    24 #include    <centralrepository.h>
       
    25 
       
    26 #include    "imconnectionprovideruids.hrh"
       
    27 
       
    28 #include    "WPAdapterUtil.h"
       
    29 #include    "xmppadapter.h"
       
    30 
       
    31 #include "xmppservicesettingsapi.h"
       
    32 #include "xmppparams.h"
       
    33 
       
    34 #include <spentry.h>
       
    35 #include <spsettings.h>
       
    36 #include <spproperty.h>
       
    37 #include <spdefinitions.h>
       
    38 #include <cvimpstsettingsstore.h> // application specific settings writer
       
    39 
       
    40 #include "xmppadapterlogger.h"
       
    41 #include <e32base.h>
       
    42 #include <StringLoader.h>
       
    43 #include <wpgeneralxmppsettingsadapter.rsg>
       
    44 #include <bautils.h>
       
    45 #include <f32file.h>
       
    46 #include <WPAdapterUtil.h> // Adapter utils
       
    47 #include <barsc.h>
       
    48 // CONSTANTS
       
    49 _LIT( KMecoImAppID,       "wXMPP" );  
       
    50 //_LIT( KXMPPProtocol,       "APROTOCOL" );   
       
    51 //_LIT( KXMPPServerAddr,       "AADDR" );  
       
    52 _LIT(KSsl,"SSL");
       
    53 _LIT(KPortNbr, "APORTNBR"); 
       
    54 _LIT(KBrandId, "BRANDID");
       
    55 const TInt KGranularity = 4;
       
    56 
       
    57 _LIT( KResorcePathFolder, "\\resource\\");
       
    58 _LIT( KResorcePathFile, "WPGeneralXMPPSettingsAdapter.rsc");
       
    59 
       
    60 
       
    61 // ======== LOCAL FUNCTIONS ========
       
    62 
       
    63 // ======== MEMBER FUNCTIONS ========
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CXMPPAdapter::CXMPPAdapter
       
    67 // C++ default constructor can NOT contain any code, that
       
    68 // might leave.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CXMPPAdapter::CXMPPAdapter() : iIsAppIdOk(EFalse)
       
    72     {
       
    73     LOGGER ( TXT ( "CXMPPAdapter::CXMPPAdapter() Start" ) );
       
    74     LOGGER ( TXT ( "CXMPPAdapter::CXMPPAdapter() Start" ) );
       
    75 
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CXMPPAdapter::ConstructL
       
    80 // Symbian 2nd phase constructor can leave.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CXMPPAdapter::ConstructL()
       
    84     {
       
    85     LOGGER ( TXT ( "CXMPPAdapter::ConstructL() Start" ) );
       
    86     iSnapId = 11;
       
    87     iAppref = NULL;
       
    88     iAppName = NULL;
       
    89     RFs fs;
       
    90     
       
    91     TFileName resFilePath;
       
    92     resFilePath.Zero();
       
    93     resFilePath.Append( KResorcePathFolder() );
       
    94     resFilePath.Append( KResorcePathFile() );
       
    95 
       
    96     LOGGER ( TXT ( "CXMPPAdapter::ConstructL() End1" ) );
       
    97     TFileName path;
       
    98     Dll::FileName( path );
       
    99     
       
   100     User::LeaveIfError( fs.Connect() );
       
   101    
       
   102     TDriveName drive( TParsePtrC( path ).Drive() );
       
   103     
       
   104     HBufC* resourceFilePath = HBufC::NewLC( KMaxFileName );
       
   105     TPtr ptr( resourceFilePath->Des() );
       
   106     
       
   107     
       
   108     ptr.Append( resFilePath );
       
   109     ptr.Insert( 0, drive );
       
   110     
       
   111     path.Zero();
       
   112     path.Append( *resourceFilePath );
       
   113 
       
   114     
       
   115     BaflUtils::NearestLanguageFile( fs, path );
       
   116     iResFile.OpenL( fs, path );
       
   117     //To decide on whether default name is needed or not
       
   118     iDefaultName = ReadResourceL( R_QTN_IPCOMM_MSG_TEXT );
       
   119     iTitle = ReadResourceL( R_QTN_IPCOMM_MSG_TITLE );
       
   120     
       
   121     CleanupStack::PopAndDestroy(); //resourceFilePath
       
   122     iResFile.Close();
       
   123     
       
   124     LOGGER ( TXT ( "CXMPPAdapter::ConstructL() End" ) );
       
   125 
       
   126     
       
   127     fs.Close();
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CXMPPAdapter::NewL
       
   132 // Two-phased constructor.
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 CXMPPAdapter* CXMPPAdapter::NewL()
       
   136     {
       
   137     LOGGER ( TXT ( "CXMPPAdapter::NewL() Start" ) );
       
   138     CXMPPAdapter* self = new( ELeave ) CXMPPAdapter;
       
   139     CleanupStack::PushL( self );
       
   140     self->ConstructL();
       
   141     CleanupStack::Pop( self );
       
   142     LOGGER ( TXT ( "CXMPPAdapter::NewL() End" ) );
       
   143     return self;
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CXMPPAdapter::~CXMPPAdapter
       
   148 // Destructor
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 CXMPPAdapter::~CXMPPAdapter()
       
   152     { 
       
   153     LOGGER ( TXT ( "CXMPPAdapter::~CXMPPAdapter Start" ) );   
       
   154     delete iUserName;
       
   155     delete iPassword;
       
   156     delete iProviderId;
       
   157     delete iXmppServerAddress;
       
   158     delete iProtocol;
       
   159     delete iAppId;
       
   160     delete iDomainName;
       
   161     delete iBrandId;
       
   162     delete iAppref;
       
   163     
       
   164     if ( iAppName )
       
   165     delete iAppName;
       
   166     
       
   167     delete iDefaultName;
       
   168     delete iTitle;
       
   169     LOGGER ( TXT ( "CXMPPAdapter::~CXMPPAdapter End" ) );      
       
   170     }
       
   171 // -----------------------------------------------------------------------------
       
   172 // CXMPPAdapter::ReadResourceLC Reads the resource without having to use a CCoeEnv
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 HBufC* CXMPPAdapter::ReadResourceL( TInt aId )
       
   176     {
       
   177     LOGGER ( TXT ( "CXMPPAdapter::ReadResourceL() " ) );
       
   178     iResFile.ConfirmSignatureL( aId );
       
   179     HBufC8* readBuffer = iResFile.AllocReadLC( aId );
       
   180     TResourceReader theReader;
       
   181     theReader.SetBuffer( readBuffer );
       
   182     TPtrC textData = theReader.ReadTPtrC();
       
   183     
       
   184     HBufC* textBuffer = HBufC::NewL( textData.Length() );
       
   185     *textBuffer = textData;
       
   186     
       
   187     CleanupStack::PopAndDestroy( readBuffer );
       
   188     LOGGER ( TXT ( "CXMPPAdapter::ReadResourceL() " ) );
       
   189     return textBuffer;
       
   190 
       
   191     }
       
   192 // -----------------------------------------------------------------------------
       
   193 // CXMPPAdapter::ItemCount
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 TInt CXMPPAdapter::ItemCount() const
       
   197     {
       
   198     LOGGER ( TXT ( "CXMPPAdapter::ItemCount() " ) );
       
   199     // SummaryTitle(), SummaryText(), SaveL(), SetAsDefaultL() and
       
   200     // CanSetAsDefault() are called ItemCount() times
       
   201     return (iUserName && iPassword && iProviderId && iXmppServerAddress && iDomainName && iProtocol) ? 1 : 0;
       
   202     }
       
   203 
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CXMPPAdapter::DetailsL
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 TInt CXMPPAdapter::DetailsL( TInt /*aItem*/, MWPPairVisitor& /*aVisitor*/ )
       
   210     {
       
   211     LOGGER ( TXT ( "CXMPPAdapter::DetailsL() " ) );
       
   212     // Detail view is a feature for later release.
       
   213     return KErrNotSupported;
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // CXMPPAdapter::SaveL
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 void CXMPPAdapter::SaveL( TInt /*aItem*/ )
       
   221     {
       
   222     LOGGER ( TXT ( "CXMPPAdapter::CanSetAsDefault() Start" ) );
       
   223     
       
   224     __ASSERT_DEBUG( (iUserName && iPassword && iProviderId  && iXmppServerAddress && iDomainName && iProtocol), User::Leave( KErrCorrupt ) );
       
   225 
       
   226 	CreateSettingsRecordL();   
       
   227     LOGGER ( TXT ( "CXMPPAdapter::CanSetAsDefault() End" ) );
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CXMPPAdapter::CanSetAsDefault
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 TBool CXMPPAdapter::CanSetAsDefault( TInt /*aItem*/ ) const
       
   235     {
       
   236     LOGGER ( TXT ( "CXMPPAdapter::CanSetAsDefault() t" ) );
       
   237     return EFalse;
       
   238     }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CXMPPAdapter::SetAsDefault
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 void CXMPPAdapter::SetAsDefaultL( TInt /*aItem*/ )
       
   245     {
       
   246     LOGGER ( TXT ( "CXMPPAdapter::SetAsDefaultL () Start" ) );
       
   247     // This shouldn't be called because CanSetAsDefault
       
   248     // always returns EFalse.
       
   249     LOGGER ( TXT ( "CXMPPAdapter::SetAsDefaultL() End" ) );
       
   250     }
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CXMPPAdapter::VisitL
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 void CXMPPAdapter::VisitL( CWPCharacteristic& aCharacteristic )
       
   257     {
       
   258     LOGGER ( TXT ( "CXMPPAdapter::VisitL( CWPCharacteristic& aCharacteristic ) Start" ) );
       
   259     switch( aCharacteristic.Type() )
       
   260         {
       
   261         case KWPApplication:
       
   262             {
       
   263             
       
   264             aCharacteristic.AcceptL( *this );
       
   265             iIsAppIdOk = ETrue;
       
   266             break;            
       
   267             }
       
   268         case KWPResource:
       
   269         	{
       
   270         	if ( 0 == iAppIdPtr.Compare( KMecoImAppID() ) )
       
   271 	        	{	       
       
   272 	        	aCharacteristic.AcceptL( *this );
       
   273 	        	}            
       
   274 	        break;            	
       
   275         	}
       
   276         case KWPAppAddr:
       
   277             {
       
   278             
       
   279             if ( 0 == iAppIdPtr.Compare( KMecoImAppID() ) )
       
   280 	        	{
       
   281 	        	aCharacteristic.AcceptL( *this );
       
   282 	        	}
       
   283             break;            
       
   284             }
       
   285         default:
       
   286         	{
       
   287             break;
       
   288         	}
       
   289         }
       
   290     LOGGER ( TXT ( "CXMPPAdapter::VisitL( CWPCharacteristic& aCharacteristic ) End" ) );
       
   291     }
       
   292 
       
   293 // -----------------------------------------------------------------------------
       
   294 // CXMPPAdapter::VisitL
       
   295 //
       
   296 //   Used to parse, the following always-on related provisioning settings
       
   297 //
       
   298 //   <characteristic type="VENDORCONFIG">
       
   299 //          <parm name="NAME" value="MRBLOBBY"/>
       
   300 //          <parm name="AWON-PDPC" value="11"/>
       
   301 //          <parm name="T-RETRY" value="100"/>
       
   302 //      </characteristic>
       
   303 //   </characteristic>
       
   304 // -----------------------------------------------------------------------------
       
   305 //
       
   306 void CXMPPAdapter::VisitL( CWPParameter& aParameter )
       
   307     {
       
   308     LOGGER ( TXT ( "CXMPPAdapter::VisitL( CWPParameter& aParameter ) Start" ) );
       
   309     switch( aParameter.ID() )
       
   310         {
       
   311         case EWPNamedParameter:
       
   312         	{
       
   313         	if ( 0 == iAppIdPtr.Compare( KMecoImAppID() ) )
       
   314 	        	{
       
   315 	        	if(aParameter.Name().Compare(KSsl) == 0)
       
   316 	        		{
       
   317 	        	    ParseIntegerL(aParameter.Value(),iSSL);
       
   318 	        		}
       
   319 	        	if(aParameter.Name().Compare(KPortNbr) == 0)
       
   320 	        		{
       
   321 	        		ParseIntegerL(aParameter.Value(),iPortNbr);
       
   322 	        		}
       
   323 	        	if(aParameter.Name().Compare(KBrandId) == 0)
       
   324 	        	    {
       
   325 	        	    if (iBrandId)
       
   326 	                    {
       
   327 	                    delete iBrandId;
       
   328 	                    iBrandId = NULL;  
       
   329 	                    }
       
   330 	        	    iBrandId = aParameter.Value().AllocL();
       
   331 	        	    }
       
   332 	        	}
       
   333             break;
       
   334         	}
       
   335         case EWPParameterName:  
       
   336         	{
       
   337         	if ( iAppName )
       
   338         	    {
       
   339         	    delete iAppName;
       
   340         	    iAppName = NULL;
       
   341         	    }
       
   342         	iAppName = aParameter.Value().AllocL();
       
   343 	         break; 
       
   344         	}          
       
   345            
       
   346         case EWPParameterAppID:
       
   347             {
       
   348         	if (iAppId)
       
   349 	        	{
       
   350 	        	delete iAppId;
       
   351 	        	iAppId = NULL;	
       
   352 	        	}
       
   353 	        iAppId = aParameter.Value().AllocL();
       
   354             iAppIdPtr.Set(iAppId->Des());
       
   355             break;
       
   356             }    
       
   357         
       
   358         case EWPParameterAProtocol:
       
   359         	{
       
   360         	if ( 0 == iAppIdPtr.Compare( KMecoImAppID() ) )
       
   361 	        	{
       
   362          		if (iProtocol)
       
   363 		        	{
       
   364 		        	delete iProtocol;
       
   365 		        	iProtocol = NULL;	
       
   366 		        	}
       
   367         		iProtocol = aParameter.Value().AllocL();
       
   368 	        	}
       
   369         	break;	
       
   370         	}
       
   371         case EWPParameterAddr:
       
   372         	{
       
   373         	if ( 0 == iAppIdPtr.Compare( KMecoImAppID() ) )
       
   374 	        	{
       
   375         		if (iXmppServerAddress)
       
   376 		        	{
       
   377 		        	delete iXmppServerAddress;
       
   378 		        	iXmppServerAddress = NULL;	
       
   379 		        	}
       
   380         		iXmppServerAddress = aParameter.Value().AllocL();
       
   381 	        	}
       
   382         	break;	
       
   383         	}
       
   384         case EWPParameterAAuthName:
       
   385         	{
       
   386         	if ( 0 == iAppIdPtr.Compare( KMecoImAppID() ) )
       
   387 	        	{     		
       
   388 	        	
       
   389 	        	if (iUserName)
       
   390 		        	{
       
   391 		        	delete iUserName;
       
   392 		        	iUserName = NULL;	
       
   393 		        	}
       
   394 	        	iUserName = aParameter.Value().AllocL();
       
   395 	        	}
       
   396         	break;	
       
   397         	}
       
   398         case EWPParameterAAuthSecret:
       
   399         	{
       
   400         	if ( 0 == iAppIdPtr.Compare( KMecoImAppID() ) )
       
   401 	        	{       	
       
   402 				if (iPassword)
       
   403 					{
       
   404 					delete iPassword;
       
   405 					iPassword = NULL;	
       
   406 					}
       
   407 
       
   408 	        	iPassword = aParameter.Value().AllocL();
       
   409 	        	}
       
   410         	break;	
       
   411         	}
       
   412         
       
   413         case EWPParameterProviderID:
       
   414         	{
       
   415 			if ( 0 == iAppIdPtr.Compare( KMecoImAppID() ) )
       
   416 				{
       
   417 	        	if (iProviderId)
       
   418 					{
       
   419 					delete iProviderId;
       
   420 					iProviderId = NULL;	
       
   421 					}
       
   422 
       
   423 	        	iProviderId = aParameter.Value().AllocL();
       
   424 				}
       
   425         	break;	
       
   426         	}
       
   427         case EWPParameterDomain :
       
   428             {
       
   429             if ( 0 == iAppIdPtr.Compare( KMecoImAppID() ) )
       
   430             {           
       
   431             if (iDomainName)
       
   432                 {
       
   433                 delete iDomainName;
       
   434                 iDomainName = NULL;   
       
   435                 }
       
   436         
       
   437             iDomainName = aParameter.Value().AllocL();
       
   438             }
       
   439             break;  
       
   440             }
       
   441         case EWPParameterAppRef:
       
   442         		{
       
   443 				if ( 0 == iAppIdPtr.Compare( KMecoImAppID() ) )
       
   444 					{
       
   445 		        	if (iAppref)
       
   446 						{
       
   447 						delete iAppref;
       
   448 						iAppref = NULL;	
       
   449 						}
       
   450 		        	iAppref= aParameter.Value().AllocL();
       
   451 					}
       
   452 				break;	
       
   453 			      }
       
   454         default:
       
   455             break;
       
   456         }
       
   457     LOGGER ( TXT ( "CXMPPAdapter::VisitL( CWPParameter& aParameter ) End" ) );
       
   458     }
       
   459 
       
   460 
       
   461 // ---------------------------------------------------------------------------
       
   462 // From class CWPAdapter.
       
   463 // CWPGeneralVoIPSettingsAdapter::SummaryTitle
       
   464 // Returns the summary title of general XMPP settings item.
       
   465 // ---------------------------------------------------------------------------
       
   466 //
       
   467 const TDesC16& CXMPPAdapter::SummaryTitle( 
       
   468     TInt /*aIndex*/ ) const
       
   469     {
       
   470     LOGGER ( TXT ( "CXMPPAdapter::SummaryText() " ) );
       
   471     if ( iIsAppIdOk )
       
   472         {
       
   473         LOGGER ( TXT ( "returning CXMPPAdapter::SummaryText() " ) );
       
   474         //LOGGER ( TXT ( "CXMPPAdapter::ConstructL() Title in SummaryText is %s" ), *iTitle );
       
   475         return *iTitle;
       
   476         }
       
   477     return KNullDesC16;
       
   478     }
       
   479 
       
   480 // ---------------------------------------------------------------------------
       
   481 // CWPGeneralVoIPSettingsAdapter::SummaryText
       
   482 // From class CWPAdapter.
       
   483 // Returns the summary text of general XMPP settings.
       
   484 // ---------------------------------------------------------------------------
       
   485 //
       
   486 const TDesC16& CXMPPAdapter::SummaryText( 
       
   487     TInt /*aIndex*/ ) const
       
   488     {
       
   489     LOGGER ( TXT ( "CXMPPAdapter::SummaryText() " ) );
       
   490     if ( iIsAppIdOk )
       
   491         {
       
   492         LOGGER ( TXT ( " returnign CXMPPAdapter::SummaryText() " ) );
       
   493         if ( NULL == iAppName )
       
   494             {
       
   495             return *iDefaultName;
       
   496             }
       
   497         return *iAppName;
       
   498         }
       
   499     LOGGER ( TXT ( "CXMPPAdapter::SummaryText() " ) );
       
   500     return KNullDesC16;
       
   501     }
       
   502 
       
   503 
       
   504 // -----------------------------------------------------------------------------
       
   505 // CXMPPAdapter::VisitLinkL
       
   506 // -----------------------------------------------------------------------------
       
   507 //
       
   508 void CXMPPAdapter::VisitLinkL( CWPCharacteristic& /*aCharacteristic*/ )
       
   509     {
       
   510     LOGGER ( TXT ( "CXMPPAdapter::VisitLinkL() " ) );
       
   511     }
       
   512 
       
   513 // -----------------------------------------------------------------------------
       
   514 // CXMPPAdapter::ParseIntegerL
       
   515 // -----------------------------------------------------------------------------
       
   516 //
       
   517 void CXMPPAdapter::ParseIntegerL( const TDesC& aPtr, TInt& aInt )
       
   518     {
       
   519     LOGGER ( TXT ( "CXMPPAdapter::ParseIntegerL " ) );
       
   520     TLex lex( aPtr );
       
   521     User::LeaveIfError( lex.Val( aInt ) );
       
   522     }
       
   523 // -----------------------------------------------------------------------------
       
   524 // CXMPPAdapter::CheckforXmppserviceL
       
   525 // This function will check for the IM Subservice in sp settings table
       
   526 // if it exists in any of the service it will return ETrue else it will return EFalse
       
   527 // -----------------------------------------------------------------------------
       
   528 //
       
   529 TBool CXMPPAdapter::CheckforXmppserviceL()
       
   530     {
       
   531     // get the existing services from sp settings table
       
   532     CSPSettings* serviceSettings = CSPSettings::NewLC(); 
       
   533     RIdArray serviceIds;
       
   534     User::LeaveIfError( serviceSettings->FindServiceIdsL( serviceIds ) );
       
   535     TBool xmppexists = EFalse;
       
   536     TInt servicecount = serviceIds.Count();
       
   537     for ( TInt i( 0 ); i < servicecount; i++ )
       
   538         {
       
   539         CSPProperty* property = CSPProperty::NewLC();
       
   540         TInt err = serviceSettings->FindPropertyL( serviceIds[ i ],EPropertyIMSubServicePluginId,
       
   541                 *property );
       
   542         CleanupStack::PopAndDestroy( property ); 
       
   543         if(!err)
       
   544             {
       
   545             xmppexists = ETrue;
       
   546             break; // just to break the loop
       
   547             }
       
   548         } 
       
   549     CleanupStack::PopAndDestroy( serviceSettings ); 
       
   550     return xmppexists;
       
   551 
       
   552     }
       
   553 //------------------------------------------------------------------------
       
   554 //CXMPPAdapter::::CreateSettingsRecordL()
       
   555 //------------------------------------------------------------------------
       
   556 void CXMPPAdapter::CreateSettingsRecordL()
       
   557     {
       
   558     LOGGER ( TXT ( "CXMPPAdapter::CreateSettingsRecordL() Start" ) );
       
   559     CXmppSettingsApi* sapi = CXmppSettingsApi::NewLC();
       
   560     iSettingsRecordId=0;
       
   561     TRAPD(err,sapi->DefaultSettingsRecordL(iSettingsRecordId));
       
   562     if( err == KErrNone && iSettingsRecordId > 0)
       
   563         {
       
   564         if(CheckforXmppserviceL())
       
   565             {
       
   566             CleanupStack::PopAndDestroy( sapi );
       
   567             User::Leave(KErrNotSupported);
       
   568             }
       
   569         } 
       
   570     sapi->CreateSettingsRecordL( iSettingsRecordId );
       
   571     
       
   572     sapi->SetParamL( iSettingsRecordId,XmppParams::KXmppParamServerPort(),/*5223 443*/ iPortNbr); 
       
   573     
       
   574     sapi->SetParamL( iSettingsRecordId, XmppParams::KXmppParamHttpsProxyServerPort(),8080 );
       
   575 
       
   576     sapi->SetParamL( iSettingsRecordId,XmppParams::KXmppParamSnapId(),5 );
       
   577     
       
   578     sapi->SetParamL( iSettingsRecordId, XmppParams:: KXmppParamXmppServerAddress(),
       
   579                                               *iXmppServerAddress );
       
   580                                                                                         
       
   581     sapi->SetParamL( iSettingsRecordId,XmppParams::KXmppParamUsername(),*iUserName );
       
   582     
       
   583     sapi->SetParamL( iSettingsRecordId,XmppParams::KXmppParamPassword(),*iPassword );
       
   584     
       
   585     sapi->SetParamL( iSettingsRecordId,XmppParams::KXmppParamResource(),
       
   586                                               _L("gtalk_resource") );
       
   587 
       
   588     sapi->SetParamL( iSettingsRecordId,XmppParams::KXmppParamHttpsProxyServerAddress(),
       
   589                                               _L("172.16.42.135") );
       
   590 
       
   591     sapi->SetParamL( iSettingsRecordId,XmppParams::KXmppParamAlais(), _L("") );
       
   592 
       
   593     sapi->SetParamL( iSettingsRecordId,XmppParams::KXmppParamOldSSLRequired(),/*ETrue  EFalse */ iSSL );
       
   594     sapi->SetParamL( iSettingsRecordId, XmppParams::KXmppParamRegisterRequired(),EFalse );
       
   595                                               
       
   596     sapi->SetParamL( iSettingsRecordId,
       
   597                                   XmppParams::KXmppParamConnMgrBus(),
       
   598                     _L("org.freedesktop.Telepathy.ConnectionManager.gabble" ) );
       
   599                           		  
       
   600     sapi->SetParamL( iSettingsRecordId,
       
   601 								  XmppParams::KXmppParamConnMgrPath(),
       
   602 					_L("/org/freedesktop/Telepathy/ConnectionManager/gabble" ) );
       
   603 								  
       
   604     sapi->SetParamL( iSettingsRecordId,XmppParams::KXmppParamProtocol(),*iProtocol );
       
   605     
       
   606     sapi->SetParamL( iSettingsRecordId, XmppParams::KXmppParamPresenceStatusFreeTextOnline(),
       
   607                                               _L("") );
       
   608 
       
   609     sapi->SetParamL( iSettingsRecordId, XmppParams::KXmppParamPresenceStatusFreeTextAway(),
       
   610                                               _L(""));
       
   611 
       
   612     sapi->SetParamL( iSettingsRecordId, XmppParams::KXmppParamPresenceStatusFreeTextBusy(),
       
   613                                               _L(""));                                              
       
   614 
       
   615     sapi->SetParamL( iSettingsRecordId, XmppParams::KXmppParamPresenceStatusFreeTextOffline(),
       
   616                                               _L(""));  
       
   617     
       
   618     sapi->SetParamL( iSettingsRecordId, XmppParams::KXmppParamPresenceStatusFreeTextInvisible(),
       
   619                                               _L(""));  
       
   620     
       
   621     sapi->SetParamL( iSettingsRecordId, XmppParams::KXmppParamLastLoggedInUserName(),
       
   622                                                   _L(""));    
       
   623 
       
   624     sapi->SetParamL( iSettingsRecordId,XmppParams::KXmppParamPresenceStatus(),0 );
       
   625                                               
       
   626     sapi->SetParamL( iSettingsRecordId,XmppParams::KXmppParamAutoAcceptBuddyReq(),EFalse );
       
   627     
       
   628     sapi->SetParamL( iSettingsRecordId,XmppParams::KXmppParamDomain(),*iDomainName );
       
   629     UpdateServiceSettingsL();                                          
       
   630 
       
   631     WriteAppSettingsL();
       
   632     CleanupStack::PopAndDestroy( sapi );
       
   633     LOGGER ( TXT ( "CXMPPAdapter::CreateSettingsRecordL() End" ) );
       
   634     }
       
   635     
       
   636 // ---------------------------------------------------------------------------
       
   637 //CXMPPAdapter::UpdateServiceSettingsL
       
   638 // ---------------------------------------------------------------------------
       
   639 //
       
   640 void CXMPPAdapter::UpdateServiceSettingsL()
       
   641     {
       
   642     LOGGER ( TXT ( "CXMPPAdapter::UpdateServiceSettingsL() Start" ) );
       
   643     CSPSettings* serviceSettings = CSPSettings::NewLC();   
       
   644     RIdArray serviceIds;
       
   645 
       
   646     User::LeaveIfError( serviceSettings->FindServiceIdsL( serviceIds ) );
       
   647     
       
   648     
       
   649 
       
   650     if( serviceIds.Count() )
       
   651         {
       
   652         CDesCArrayFlat* serviceNames = new( ELeave ) CDesCArrayFlat( KGranularity );
       
   653         CleanupStack::PushL( serviceNames );
       
   654 
       
   655         User::LeaveIfError( serviceSettings->FindServiceNamesL( serviceIds,
       
   656                                                                 *serviceNames) );
       
   657 
       
   658         for ( TInt i=0; i < serviceNames->MdcaCount(); i++ )
       
   659             {
       
   660             if ( ( serviceNames->MdcaPoint(i)).Compare( *iProviderId )  == 0 )
       
   661                 {
       
   662                 
       
   663                 iServiceProviderId = serviceIds[i];
       
   664                 break;
       
   665                 }
       
   666             }
       
   667         CleanupStack::PopAndDestroy( serviceNames );
       
   668         }
       
   669     
       
   670     if ( 0 >= iServiceProviderId )
       
   671         {
       
   672         
       
   673         CSPEntry* entry = CSPEntry::NewLC();
       
   674         entry->SetServiceName( *iProviderId );
       
   675         TInt entryRetvalue = serviceSettings->AddEntryL( *entry );
       
   676         User::LeaveIfError( entryRetvalue );
       
   677         iServiceProviderId = entry->GetServiceId();
       
   678         CleanupStack::PopAndDestroy( entry );
       
   679         }
       
   680 	      
       
   681 
       
   682     // Add/Update properties
       
   683     CSPProperty* property = CSPProperty::NewLC(); 
       
   684     
       
   685     
       
   686     property->SetName( ESubPropertyIMLaunchUid );
       
   687     property->SetValue( 0x200255D0 );
       
   688 
       
   689     User::LeaveIfError( serviceSettings->AddOrUpdatePropertyL( iServiceProviderId,
       
   690                                                                *property ) );
       
   691 	
       
   692 		
       
   693     property->SetName( EPropertyContactViewPluginId );
       
   694     property->SetValue( 0x20012423 ); // plugin view id  
       
   695 
       
   696     User::LeaveIfError( serviceSettings->AddOrUpdatePropertyL( iServiceProviderId,
       
   697                                                                *property ) );
       
   698 	
       
   699     
       
   700     property->SetName( ESubPropertyIMSettingsId );
       
   701     property->SetValue( iSettingsRecordId );
       
   702 
       
   703     User::LeaveIfError( serviceSettings->AddOrUpdatePropertyL( iServiceProviderId,
       
   704                                                                *property ) );
       
   705     
       
   706     
       
   707     
       
   708     property->SetName( EPropertyIMSubServicePluginId );
       
   709     property->SetValue( KIMConnectivityPluginImplUid );
       
   710 
       
   711     User::LeaveIfError( serviceSettings->AddOrUpdatePropertyL( iServiceProviderId,
       
   712                                                                *property ) );
       
   713     
       
   714     
       
   715     property->SetName( ESubPropertyIMPreferredIAPId );
       
   716     property->SetValue( iSnapId );
       
   717 
       
   718     User::LeaveIfError( serviceSettings->AddOrUpdatePropertyL( iServiceProviderId,
       
   719                                                                *property ) );
       
   720     
       
   721     
       
   722     
       
   723     property->SetName( ESubPropertyIMPreferredSNAPId );
       
   724     property->SetValue( iSnapId );
       
   725 
       
   726     User::LeaveIfError( serviceSettings->AddOrUpdatePropertyL( iServiceProviderId,
       
   727                                                                *property ) );
       
   728     
       
   729     
       
   730     property->SetName( ESubPropertyIMEnabled );
       
   731     property->SetValue( EOff );
       
   732 
       
   733     User::LeaveIfError( serviceSettings->AddOrUpdatePropertyL( iServiceProviderId,
       
   734                                                                *property ) );
       
   735     
       
   736     RBuf brandId;
       
   737     if( iBrandId )
       
   738         {
       
   739         brandId.CreateL(*iBrandId );
       
   740         }
       
   741     else
       
   742         {
       
   743         brandId.CreateL(KNullDesC);
       
   744         }
       
   745     CleanupClosePushL( brandId );
       
   746     property->SetName( EPropertyBrandId );
       
   747     property->SetValue( brandId );
       
   748 
       
   749     User::LeaveIfError( serviceSettings->AddOrUpdatePropertyL( iServiceProviderId,
       
   750                                                                *property ) );
       
   751     CleanupStack::PopAndDestroy( &brandId );
       
   752     
       
   753     
       
   754     property->SetName( EPropertyBrandLanguage );
       
   755     
       
   756     // ELangInternationalEnglish is selected as Default Brand Language Id. 
       
   757     property->SetValue( ELangInternationalEnglish );       
       
   758 
       
   759     User::LeaveIfError( serviceSettings->AddOrUpdatePropertyL( iServiceProviderId,
       
   760                                                                *property ) );
       
   761     
       
   762     
       
   763 	RBuf contactDB;
       
   764 	TBuf <50> string;
       
   765 	// The store name should be service specific, and not hardcoded, hence we use iServiceProviderId to form uniqueness.
       
   766 	string.Format(_L("cntdb://c:vimpststore%d.cdb"), iServiceProviderId);
       
   767 	contactDB.CreateL (string); 
       
   768     CleanupClosePushL( contactDB );
       
   769     property->SetName( EPropertyContactStoreId );
       
   770     property->SetValue( contactDB );
       
   771 
       
   772     User::LeaveIfError( serviceSettings->AddOrUpdatePropertyL( iServiceProviderId,
       
   773                                                                *property ) );
       
   774     CleanupStack::PopAndDestroy( &contactDB );
       
   775     
       
   776 	/*PresenceSubservice*/
       
   777 	property->SetName( ESubPropertyPresenceSettingsId );
       
   778 	property->SetValue( iSettingsRecordId );
       
   779 
       
   780 	User::LeaveIfError( serviceSettings->AddOrUpdatePropertyL( iServiceProviderId,
       
   781 	                                               *property ) );
       
   782 
       
   783 
       
   784 
       
   785 	property->SetName( EPropertyPresenceSubServicePluginId );
       
   786 	property->SetValue( KIMConnectivityPluginImplUid );
       
   787 
       
   788 	User::LeaveIfError( serviceSettings->AddOrUpdatePropertyL( iServiceProviderId,
       
   789 	                                               *property ) );
       
   790 
       
   791 
       
   792 	property->SetName( ESubPropertyPresencePreferredIAPId );
       
   793 	property->SetValue( iSnapId );
       
   794 
       
   795 	User::LeaveIfError( serviceSettings->AddOrUpdatePropertyL( iServiceProviderId,
       
   796 	                                               *property ) );
       
   797 
       
   798 
       
   799 
       
   800 	property->SetName( ESubPropertyPresencePreferredSNAPId );
       
   801 	property->SetValue( iSnapId );
       
   802 
       
   803 	User::LeaveIfError( serviceSettings->AddOrUpdatePropertyL( iServiceProviderId,
       
   804 	                                               *property ) );
       
   805 
       
   806 
       
   807 	property->SetName( ESubPropertyPresenceEnabled );
       
   808 	property->SetValue( EOff );
       
   809 
       
   810 	User::LeaveIfError( serviceSettings->AddOrUpdatePropertyL( iServiceProviderId,
       
   811 	                                               *property ) );
       
   812 
       
   813 
       
   814 
       
   815 	property->SetName( EPropertyPCSPluginId );
       
   816 	property->SetValue( 0x101FB3E7 ); 
       
   817 
       
   818 	User::LeaveIfError( serviceSettings->AddOrUpdatePropertyL( iServiceProviderId,
       
   819 	                                                               *property ) ); 
       
   820 
       
   821 	property->SetName( ESubPropertyPresenceAddrScheme );
       
   822 	property->SetValue( *iDomainName ); 
       
   823 	   
       
   824 	User::LeaveIfError( serviceSettings->AddOrUpdatePropertyL( iServiceProviderId,
       
   825 	                                                                   *property ) ); 
       
   826 
       
   827 	//End of Presence Subservice
       
   828 
       
   829 	CleanupStack::PopAndDestroy( property );
       
   830     CleanupStack::PopAndDestroy( serviceSettings );
       
   831     LOGGER ( TXT ( "CXMPPAdapter::UpdateServiceSettingsL() End" ) );
       
   832     }
       
   833 
       
   834 // ---------------------------------------------------------------------------
       
   835 //CXMPPAdapter::WriteAppSettingsL
       
   836 // ---------------------------------------------------------------------------
       
   837 //
       
   838 void CXMPPAdapter::WriteAppSettingsL()
       
   839     {
       
   840     MVIMPSTSettingsStore*  settingsStore = CVIMPSTSettingsStore::NewLC();
       
   841     // write cancel login not supported : since xmpp doesnot have the support
       
   842     settingsStore->SetL( iServiceProviderId , EServiceCancelLoginNotSupported , 1 );
       
   843     // write change connection not supported : since xmpp doesnot have the support
       
   844     settingsStore->SetL( iServiceProviderId , EServiceChangeConnectionNotSupported , 1 );
       
   845     CleanupStack::PopAndDestroy();//settingStore
       
   846     }
       
   847 //  End of File