omadm/omadmextensions/adapters/syncmlds/src/NSmlDsSettingsAdapter.cpp
changeset 0 3ce708148e4d
child 2 a5fecba4b1e4
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 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:    DS-settings adapter
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "NSmlDSSettingsAdapter.h"
       
    23 #include "nsmldebug.h"
       
    24 #include "nsmlconstants.h"
       
    25 #include "nsmldmconstants.h"
       
    26 #include "nsmldmimpluids.h"
       
    27 #include "nsmldmiapmatcher.h"
       
    28 
       
    29 #include <implementationproxy.h>
       
    30 #include <badesca.h>
       
    31 #include <utf.h>
       
    32 #include <SyncMLTransportProperties.h>
       
    33 
       
    34 #ifndef __WINS__
       
    35 // This lowers the unnecessary compiler warning (armv5) to remark.
       
    36 // "Warning:  #174-D: expression has no effect..." is caused by 
       
    37 // DBG_ARGS8 macro in no-debug builds.
       
    38 #pragma diag_remark 174
       
    39 #endif
       
    40 
       
    41 
       
    42 // ============================ MEMBER FUNCTIONS ===============================
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 //  CNSmlDSSettingsAdapter::NewL
       
    46 //  Two-phased constructor.
       
    47 // -----------------------------------------------------------------------------
       
    48 CNSmlDSSettingsAdapter* CNSmlDSSettingsAdapter::NewL( MSmlDmCallback* aDmCallback )
       
    49 	{
       
    50 	_DBG_FILE("CNSmlDSSettingsAdapter::NewL(): begin");
       
    51 
       
    52 	CNSmlDSSettingsAdapter* self = NewLC( aDmCallback );
       
    53 	CleanupStack::Pop();
       
    54 
       
    55 	_DBG_FILE("CNSmlDSSettingsAdapter::NewL(): end");
       
    56 	return self;
       
    57 	}
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 //  CNSmlDSSettingsAdapter::NewLC
       
    61 // -----------------------------------------------------------------------------
       
    62 CNSmlDSSettingsAdapter* CNSmlDSSettingsAdapter::NewLC(MSmlDmCallback* aDmCallback )
       
    63 	{
       
    64 	_DBG_FILE("CNSmlDSSettingsAdapter::NewLC(): begin");
       
    65 	CNSmlDSSettingsAdapter* self = new ( ELeave ) CNSmlDSSettingsAdapter( aDmCallback );
       
    66 	CleanupStack::PushL( self );
       
    67 	self->iCallBack = aDmCallback;
       
    68 
       
    69 	self->ConstructL();
       
    70 	self->iLeafType = EDSUnset;
       
    71     
       
    72 	_DBG_FILE("CNSmlDSSettingsAdapter::NewLC(): end");
       
    73 	return self;
       
    74 	}
       
    75 
       
    76 //------------------------------------------------------------------------------
       
    77 // CNSmlDSSettingsAdapter::CNSmlDSSettingsAdapter
       
    78 //------------------------------------------------------------------------------
       
    79 CNSmlDSSettingsAdapter::CNSmlDSSettingsAdapter(TAny* aEcomArguments) : CSmlDmAdapter(aEcomArguments)
       
    80 	{
       
    81 	_DBG_FILE("CNSmlDSSettingsAdapter::CNSmlDSSettingsAdapter(): begin");
       
    82 	_DBG_FILE("CNSmlDSSettingsAdapter::CNSmlDSSettingsAdapter(): end");
       
    83 	}
       
    84 
       
    85 //------------------------------------------------------------------------------
       
    86 //  CNSmlDSSettingsAdapter::~CNSmlDSSettingsAdapter()
       
    87 //  Class destructor.
       
    88 //------------------------------------------------------------------------------
       
    89 CNSmlDSSettingsAdapter::~CNSmlDSSettingsAdapter()
       
    90 	{
       
    91 	_DBG_FILE("CNSmlDSSettingsAdapter::~CNSmlDSSettingsAdapter(): begin");
       
    92     delete iPrevURI;
       
    93     delete iField;
       
    94     
       
    95 	// Command buffer cleaning
       
    96 	if ( iBuffer )
       
    97 		{
       
    98 		
       
    99 		for( TInt i=0; i<iBuffer->Count(); i++ )
       
   100 			{
       
   101 			delete iBuffer->At(i).iMappingName;
       
   102 			delete iBuffer->At(i).iName;
       
   103 
       
   104 			for( TInt j=0; j<iBuffer->At(i).iNodeBuf->Count(); j++ )
       
   105 				{
       
   106 				delete iBuffer->At(i).iNodeBuf->At(j).iUri;
       
   107 				if( iBuffer->At(i).iNodeBuf->At(j).iData )
       
   108 					{
       
   109 					delete iBuffer->At(i).iNodeBuf->At(j).iData;
       
   110 					}
       
   111 				}
       
   112 			iBuffer->At(i).iNodeBuf->Reset();
       
   113 			delete iBuffer->At(i).iNodeBuf;
       
   114 			}
       
   115 
       
   116 		iBuffer->Reset();
       
   117 		delete iBuffer;
       
   118 		}
       
   119     
       
   120     iDSProfile.Close();
       
   121     iSyncSession.Close();
       
   122     iSyncSessionOpen = EFalse;
       
   123         
       
   124     delete iPortNbr;
       
   125     delete iPortBuf;
       
   126     delete iRdbDataStore;
       
   127     
       
   128     iBufferExecution = EFalse;
       
   129     
       
   130     iCallBack = 0;
       
   131 
       
   132 	_DBG_FILE("CNSmlDSSettingsAdapter::~CNSmlDSSettingsAdapter(): end");
       
   133 	}
       
   134 
       
   135 //------------------------------------------------------------------------------
       
   136 //		CNSmlDSSettingsAdapter::ConstructL
       
   137 //		Second phase constructor.
       
   138 //------------------------------------------------------------------------------
       
   139 void CNSmlDSSettingsAdapter::ConstructL()
       
   140 	{
       
   141 	iField = HBufC8::NewL( KNSmlMaxURLLength );
       
   142 	iPrevURI = HBufC8::NewL( KNSmlMaxURLLength );
       
   143     iRdbDataStore = HBufC16::NewL( KNSmlMaxRemoteNameLength );
       
   144 //
       
   145 //	Command buffering used for AddNode + AddLeaf
       
   146 //
       
   147 	iBuffer = new ( ELeave ) CArrayFixFlat <TNSmlDSBufferElement> ( KNSmlDSGranularity );
       
   148 
       
   149     iSyncSessionOpen = EFalse;
       
   150 
       
   151     iPortNbr = 0;
       
   152     iBufferExecution = EFalse;
       
   153 	}
       
   154 	
       
   155 //------------------------------------------------------------------------------
       
   156 //  CNSmlDSSettingsAdapter::DDFVersionL
       
   157 //------------------------------------------------------------------------------
       
   158 void CNSmlDSSettingsAdapter::DDFVersionL(CBufBase& aVersion)
       
   159 	{
       
   160 	aVersion.InsertL( 0, KVersion );
       
   161     }
       
   162 
       
   163 //------------------------------------------------------------------------------
       
   164 //  CNSmlDSSettingsAdapter::DDFStructureL
       
   165 //  Fills the DDF structure of the adapter.
       
   166 //------------------------------------------------------------------------------
       
   167 void CNSmlDSSettingsAdapter::DDFStructureL( MSmlDmDDFObject& aDDF )
       
   168 	{
       
   169 	_DBG_FILE("CNSmlDSSettingsAdapter::DDFStructureL(): begin");
       
   170 
       
   171 	TSmlDmAccessTypes *aclTypes = new ( ELeave ) TSmlDmAccessTypes();
       
   172 	CleanupStack::PushL( aclTypes );
       
   173 
       
   174     //  Set Get as acceptable operations
       
   175 	aclTypes->SetGet();
       
   176 
       
   177     MSmlDmDDFObject* ddfRoot = &aDDF;
       
   178     MSmlDmDDFObject& ddf = ddfRoot->AddChildObjectL( KNSmlDdfRoot );
       
   179     FillNodeInfoL( ddf, *aclTypes, MSmlDmDDFObject::EOne, 
       
   180                     MSmlDmDDFObject::EPermanent, MSmlDmDDFObject::ENode, 
       
   181                     KNSmlDdfRootDescription, KNullDesC8, KMimeType );
       
   182     
       
   183     ddf.SetDFTitleL( KDSSettingsTitle );
       
   184 
       
   185 
       
   186 	MSmlDmDDFObject& nDSAcc = ddf.AddChildObjectL( KNSmlDefDSAcc );
       
   187 	nDSAcc.SetOccurenceL( MSmlDmDDFObject::EOne );
       
   188 	nDSAcc.SetDefaultValueL( KNullDesC8 );
       
   189 	nDSAcc.SetScopeL( MSmlDmDDFObject::EPermanent );
       
   190 	nDSAcc.SetAccessTypesL( *aclTypes );
       
   191 	nDSAcc.SetDFFormatL( MSmlDmDDFObject::ENode );
       
   192 //
       
   193 //  Set rest acceptable operations for data itself
       
   194 //
       
   195     aclTypes->SetAdd();
       
   196 	aclTypes->SetReplace();
       
   197 	aclTypes->SetDelete();
       
   198 
       
   199 	TSmlDmAccessTypes aclTypesLimit;
       
   200 	aclTypesLimit.SetGet();
       
   201 	aclTypesLimit.SetAdd();
       
   202 
       
   203 	TSmlDmAccessTypes aclTypesGet;
       
   204 	aclTypesGet.SetGet();
       
   205 
       
   206 	TSmlDmAccessTypes aclTypesNoGet;
       
   207 	aclTypesNoGet.SetReplace();
       
   208 	aclTypesNoGet.SetAdd();
       
   209 	aclTypesNoGet.SetDelete();
       
   210 
       
   211 	TSmlDmAccessTypes aclTypesNoDelete;
       
   212 	aclTypesNoDelete.SetGet();
       
   213 	aclTypesNoDelete.SetAdd();
       
   214 	aclTypesNoDelete.SetReplace();
       
   215 
       
   216 	MSmlDmDDFObject& nProDDF = nDSAcc.AddChildObjectGroupL();
       
   217     FillNodeInfoL( nProDDF, *aclTypes, MSmlDmDDFObject::EZeroOrMore, 
       
   218                     MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::ENode, 
       
   219                     KNullDesC8, KNullDesC8, KMimeType );
       
   220 
       
   221 	MSmlDmDDFObject& nAddrDDF = nProDDF.AddChildObjectL(KNSmlDdfAddr);	// Addr
       
   222 	FillNodeInfoL( nAddrDDF, *aclTypes, MSmlDmDDFObject::EOne, 
       
   223                     MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr, 
       
   224                     KNSmlDdfAddrDescription, KNullDesC8, KMimeType );
       
   225 
       
   226 	MSmlDmDDFObject& nAddrTypeDDF = nProDDF.AddChildObjectL(KNSmlDdfAddrType);	// AddrType
       
   227     FillNodeInfoL( nAddrTypeDDF, *aclTypes, MSmlDmDDFObject::EZeroOrOne, 
       
   228                     MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr, 
       
   229                     KNSmlDdfAddrTypeDescription, KNullDesC8, KMimeType );
       
   230 
       
   231 	MSmlDmDDFObject& nPortNbrDDF = nProDDF.AddChildObjectL(KNSmlDdfPortNbr);// PortNbr
       
   232 	FillNodeInfoL( nPortNbrDDF, *aclTypes, MSmlDmDDFObject::EZeroOrOne, 
       
   233                     MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EInt, 
       
   234                     KNSmlDdfPortNbrDescription, KNullDesC8, KMimeType );
       
   235 
       
   236 	MSmlDmDDFObject& nNameDDF = nProDDF.AddChildObjectL(KNSmlDdfName);	// Name
       
   237 	FillNodeInfoL( nNameDDF, *aclTypes, MSmlDmDDFObject::EZeroOrOne, 
       
   238                     MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr, 
       
   239                     KNSmlDdfNameDescription, KNullDesC8, KMimeType );
       
   240 
       
   241 	MSmlDmDDFObject& nDBrootDDF = nProDDF.AddChildObjectL(KNSmlDdfDB);	// DB
       
   242     FillNodeInfoL( nDBrootDDF, *aclTypes, MSmlDmDDFObject::EZeroOrOne, 
       
   243                     MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::ENode, 
       
   244                     KNSmlDdfDBDescription, KNullDesC8, KMimeType );
       
   245 
       
   246 	MSmlDmDDFObject& nDBDDF = nDBrootDDF.AddChildObjectGroupL(); // DB/<X>
       
   247     FillNodeInfoL( nDBDDF, *aclTypes, MSmlDmDDFObject::EZeroOrMore, 
       
   248                     MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::ENode, 
       
   249                     KNullDesC8, KNullDesC8, KMimeType );
       
   250 
       
   251 	MSmlDmDDFObject& nCTTypeDDF = nDBDDF.AddChildObjectL(KNSmlDdfCTType);	// CTType
       
   252 	FillNodeInfoL( nCTTypeDDF, aclTypesLimit, MSmlDmDDFObject::EOne, 
       
   253                     MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr, 
       
   254                     KNSmlDdfCTTypeDescription, KNullDesC8, KMimeType );
       
   255 
       
   256 	MSmlDmDDFObject& nRDBURIDDF = nDBDDF.AddChildObjectL(KNSmlDdfRDBURI);	// RDBURI
       
   257 	FillNodeInfoL( nRDBURIDDF, aclTypesNoDelete, MSmlDmDDFObject::EOne, 
       
   258                     MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr, 
       
   259                     KNSmlDdfRDBURIDescription, KNullDesC8, KMimeType );
       
   260 
       
   261 	MSmlDmDDFObject& nLDBURIDDF = nDBDDF.AddChildObjectL(KNSmlDdfLDBURI);	// LDBURI
       
   262     FillNodeInfoL( nLDBURIDDF, aclTypesNoDelete, MSmlDmDDFObject::EOne, 
       
   263                     MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr, 
       
   264                     KNSmlDdfLDBURIDescription, KNullDesC8, KMimeType );
       
   265 
       
   266 	MSmlDmDDFObject& nClientUserNameDDF = nProDDF.AddChildObjectL(KNSmlDdfClientUserName);
       
   267     FillNodeInfoL( nClientUserNameDDF, *aclTypes, MSmlDmDDFObject::EZeroOrOne, 
       
   268                     MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr, 
       
   269                     KNSmlDdfClientUserNameDescription, KNullDesC8, KMimeType );
       
   270 
       
   271 	MSmlDmDDFObject& nServerIdDDF = nProDDF.AddChildObjectL(KNSmlDdfServerId);
       
   272     FillNodeInfoL( nServerIdDDF, *aclTypes, MSmlDmDDFObject::EZeroOrOne, 
       
   273                     MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr, 
       
   274                     KNSmlDdfServerIdDescription, KNullDesC8, KMimeType );
       
   275 
       
   276 	MSmlDmDDFObject& nClientPWDDF = nProDDF.AddChildObjectL(KNSmlDdfClientPW);// ClientPW
       
   277 	FillNodeInfoL( nClientPWDDF, aclTypesNoGet, MSmlDmDDFObject::EOne, 
       
   278                     MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr, 
       
   279                     KNSmlDdfClientPWDescription, KNullDesC8, KMimeType );
       
   280 
       
   281 	MSmlDmDDFObject& nToNAPIDDDF = nProDDF.AddChildObjectL(KNSmlDdfToNAPID);// ToNAPID
       
   282     FillNodeInfoL( nToNAPIDDDF, aclTypesNoDelete, MSmlDmDDFObject::EOne, 
       
   283                     MSmlDmDDFObject::EDynamic, MSmlDmDDFObject::EChr, 
       
   284                     KNSmlDdfToNAPIDDescription, KNullDesC8, KMimeType );
       
   285 
       
   286 	CleanupStack::PopAndDestroy(); //aclTypes
       
   287 	_DBG_FILE("CNSmlDSSettingsAdapter::DDFStructureL(): end");
       
   288 	}
       
   289 
       
   290 //------------------------------------------------------------------------------
       
   291 //  CNSmlDSSettingsAdapter::UpdateLeafObjectL
       
   292 //  The function updates the leaf object data.
       
   293 //------------------------------------------------------------------------------
       
   294 void CNSmlDSSettingsAdapter::UpdateLeafObjectL( const TDesC8& aURI, 
       
   295                                                 const TDesC8& aParentLUID, 
       
   296                                                 const TDesC8& aObject, 
       
   297                                                 const TDesC8& /*aType*/, 
       
   298                                                 const TInt aStatusRef )
       
   299 	{
       
   300 	_DBG_FILE("CNSmlDSSettingsAdapter::UpdateLeafObjectL(): begin");
       
   301 //
       
   302 //	Check which field going to be handled
       
   303 //
       
   304 	// Static node feature start
       
   305 		TInt profileLUID = -1;
       
   306 		if(aParentLUID.Length() == 0 )
       
   307 		{
       
   308 			iLUID = -1;
       
   309 			if( IsDSAccUriFormatMatchPredefined(aURI) )
       
   310     	{
       
   311     		iLUID = ConstructTreeL(aURI);
       
   312     		profileLUID = GetProfileIdFromURIL( aURI ); 
       
   313     	}    	
       
   314     	if ((iLUID == 0 ) && (aURI.Match(_L8("SyncML/DSAcc/DSId*/DB/CTId*"))  == KErrNone))
       
   315 			{
       
   316 				_DBG_FILE("CNSmlDSSettingsAdapter::FetchObjectL(): ENotFound end");
       
   317 				iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   318 				return;
       
   319     	}
       
   320     }
       
   321 		// Static node feature end
       
   322 	SetField( aURI );
       
   323     TInt fieldID = GetDSField();
       
   324 	TInt fieldType = GetDSFieldTypeL();
       
   325 	if ( fieldType == EWrong || fieldID < 0 )
       
   326 		{
       
   327 		_DBG_FILE("CNSmlDSSettingsAdapter::UpdateLeafObjectL(): EError end");
       
   328 		iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   329 		return;
       
   330 		}
       
   331 	if(profileLUID == -1)
       
   332     	profileLUID = GetIntObject( aParentLUID );
       
   333 	
       
   334 	if( profileLUID == -1 && fieldType != EParam )
       
   335 		{
       
   336 		_DBG_FILE("CNSmlDSSettingsAdapter::UpdateLeafObjectL( ): ENotFound end");
       
   337 		iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   338 		return;
       
   339 		}	
       
   340     
       
   341     if ( fieldType == EParam )
       
   342 		{
       
   343 		if( GetBufferIndex( aURI ) >= 0 && iBufferExecution == EFalse )
       
   344 			{
       
   345 			AddLeafBufferL( aURI, aParentLUID, aObject, aStatusRef );
       
   346             return;
       
   347 			}
       
   348 		profileLUID = GetProfileIdFromURIL( aURI );
       
   349         if( FindProfileIdL( profileLUID ) == EFalse )
       
   350             {
       
   351             iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   352 			return;
       
   353             }
       
   354         if( iField->Compare( KNSmlDdfCTType ) == 0 )
       
   355             {
       
   356             if( MimeTypeAllreadyExitsL( profileLUID, aObject ) )
       
   357                 {
       
   358                 iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EAlreadyExists );
       
   359                 return;
       
   360                 }
       
   361             if( aObject.Length() == 0 )
       
   362                 {
       
   363                 iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EInvalidObject );
       
   364                 return;
       
   365                 }
       
   366             }
       
   367         }
       
   368 
       
   369 	if( profileLUID != iParentLUID && fieldType != EParam )
       
   370 		{											    
       
   371 		if( FindProfileIdL( profileLUID ) )
       
   372 			{
       
   373 			iParentLUID = profileLUID;
       
   374 			}
       
   375 		else
       
   376 			{
       
   377 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   378 			return;
       
   379 			}
       
   380 		}
       
   381 	if ( fieldType == EStr || fieldType == EInt )
       
   382 		{
       
   383 //
       
   384 //		Check if Object length id valid
       
   385 //
       
   386 		if( NotValidStrLenght( fieldID, aObject ) )
       
   387 			{
       
   388 			_DBG_FILE("CNSmlDSSettingsAdapter::AddLeafObjectL(): KErr length end");
       
   389 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ETooLargeObject );
       
   390 			return;
       
   391 			}
       
   392 		}
       
   393 
       
   394     TInt ret = 0;
       
   395 	if ( fieldType == EStr || fieldType == EInt )
       
   396 		{
       
   397 		if( fieldID == EProfileURL )
       
   398 			{
       
   399 			TInt num=0;
       
   400             ret = ParseUri( aObject, num );
       
   401             if( ret == KErrNone )
       
   402 				{
       
   403 			    ret = SetProfileServerURIL( iParentLUID, aObject );
       
   404                 if( ret != 0 )
       
   405 					{
       
   406 					_DBG_FILE("CNSmlDSSettingsAdapter::AddLeafObjectL(): URI set failed");
       
   407 					iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   408 					return;
       
   409 					}
       
   410 				}
       
   411 			else //if port number not included in URL
       
   412 				{
       
   413                 ret = SetProfileServerURIL( iParentLUID, aObject );
       
   414                 if( ret != 0 )
       
   415 					{
       
   416 					_DBG_FILE("CNSmlDSSettingsAdapter::AddLeafObjectL(): URI set failed");
       
   417 					iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   418 					return;
       
   419 					}
       
   420 				}
       
   421 		    		    
       
   422 			}
       
   423 		else if( fieldID == EProfileURL )
       
   424 			{
       
   425 			ret = SetProfileServerURIL( iParentLUID, aObject );
       
   426             }
       
   427         else if( fieldID == EProfileMediumType )//AddrType
       
   428 			{
       
   429 			if ( iLeafType == EDSDelete )
       
   430 			    {
       
   431                 iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EOk );
       
   432 	            return;            
       
   433 			    }
       
   434             iObject = GetIntObject( aObject );
       
   435             ret = SetProfileAddrTypeL( iParentLUID, iObject );
       
   436 			}
       
   437         else
       
   438 			{
       
   439 			ret = SetProfileStrValueL( iParentLUID, aObject, fieldID );
       
   440 			}
       
   441 		}
       
   442 	else if ( fieldType == EParam )
       
   443 		{
       
   444         TInt sRet = KErrGeneral;
       
   445         if( iField->Compare( KNSmlDdfCTType ) == 0 ) //Task Mime Type
       
   446 			{
       
   447 //			DBG_ARGS8(_S8("NEW: Object <%S>"), &aObject);
       
   448 			TInt dataProviderId(-1);
       
   449 			if(aParentLUID.Length() == 0 )
       
   450 			{
       
   451 				dataProviderId = iLUID ;
       
   452 			}
       
   453 			else
       
   454 			{
       
   455 				dataProviderId = GetIntObject( aParentLUID );
       
   456 			}
       
   457             if( FindTaskIDL( profileLUID, dataProviderId ) == EFalse )
       
   458                 {
       
   459                 sRet = AddNewDataProviderL( profileLUID, aObject, dataProviderId );
       
   460                 }
       
   461             else
       
   462                 {
       
   463                 sRet = KErrAlreadyExists;
       
   464                 }
       
   465             if( sRet == KErrDiskFull )
       
   466 			    {
       
   467 				iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EDiskFull );
       
   468 				}
       
   469 			else if( sRet == KErrNotFound )
       
   470                 {
       
   471                 iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   472                 }
       
   473             else if( sRet == KErrAlreadyExists )
       
   474                 {
       
   475                 iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EAlreadyExists );
       
   476                 }
       
   477             else if( sRet != KErrNone )
       
   478 			    {
       
   479 				iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   480 				}
       
   481             else
       
   482                 {
       
   483                 TPtrC8 addDBURI = RemoveLastURISeg( aURI ); 
       
   484 				TBuf8<16> dataProvider;
       
   485 				dataProvider.Num( dataProviderId );
       
   486 		    	iCallBack->SetMappingL( addDBURI, dataProvider );
       
   487 				SetBufferLUID( aURI,dataProviderId );
       
   488 				iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EOk ); 
       
   489 				
       
   490 				
       
   491                 }                        
       
   492             return;
       
   493             }
       
   494         //
       
   495         // Only database values handled
       
   496         //
       
   497 /*		if( iField->Compare( KNSmlDdfLDBURI ) == 0 )
       
   498 		    {
       
   499 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   500 			return;
       
   501 		    }
       
   502 */
       
   503 		if( !(iField->Compare( KNSmlDdfLDBURI ) == 0) &&
       
   504 		    !(iField->Compare( KNSmlDdfRDBURI ) == 0) )	
       
   505 		    {
       
   506 			_DBG_FILE("CNSmlDSSettingsAdapter::AddLeafObjectL(): Param header end");
       
   507 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EOk );
       
   508 			return;
       
   509 			}
       
   510 
       
   511 
       
   512         TInt dataProviderId(-1);
       
   513 		if(aParentLUID.Length() == 0 )
       
   514 		{
       
   515 			dataProviderId = iLUID ;
       
   516 		}
       
   517 		else
       
   518 		{
       
   519         	dataProviderId = GetIntObject( aParentLUID );
       
   520 		}
       
   521         if( FindTaskIDL( profileLUID, dataProviderId ) )
       
   522             {
       
   523             ret = UpdateDataSourceL( profileLUID, dataProviderId, aObject, *iField);
       
   524             if( ret != KErrNone )
       
   525                 {
       
   526                 ret = KErrGeneral;
       
   527                 }
       
   528             TPtrC8 dbURI = RemoveLastURISeg( aURI ); 
       
   529 		    TBuf8<16> dataProvider;
       
   530 		    dataProvider.Num( dataProviderId );
       
   531 		    iCallBack->SetMappingL( dbURI, dataProvider );
       
   532 			}
       
   533 		else
       
   534 		    {
       
   535 		    ret = KErrNone;
       
   536 		    //ret = KErrNotFound;
       
   537 			}
       
   538         }
       
   539 	
       
   540     if ( ret != KErrNone )
       
   541 		{
       
   542 		if( ret == KErrDiskFull)
       
   543 			{
       
   544 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EDiskFull );
       
   545 			}
       
   546         else if( ret == KErrNotFound )
       
   547             {
       
   548             iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   549             }
       
   550         else if( ret == KErrArgument )
       
   551             {
       
   552             iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EInvalidObject );
       
   553             }
       
   554         else if( ret == KErrOverflow)
       
   555             {
       
   556             iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ETooLargeObject  );
       
   557             }
       
   558 		else
       
   559 			{
       
   560 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   561 			}
       
   562 		}
       
   563 	else if ( fieldID == EProfilePort )
       
   564 	    {
       
   565         // in case port is updated, save status ref to be used in 
       
   566         // CompleteOutstandingCmdsL (i.e. status not set yet)
       
   567         iPortBufStatusRef = aStatusRef;
       
   568 	    }
       
   569 	else
       
   570 	    {
       
   571     	iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EOk );
       
   572 	    }
       
   573 	
       
   574 	_DBG_FILE("CNSmlDSSettingsAdapter::AddLeafObjectL(): end");
       
   575 	return;
       
   576 	}
       
   577 
       
   578 //------------------------------------------------------------------------------
       
   579 //  CNSmlDSSettingsAdapter::DeleteObjectL
       
   580 //  The function Deletes leaf object data or node data content.
       
   581 //------------------------------------------------------------------------------
       
   582 void CNSmlDSSettingsAdapter::DeleteObjectL( const TDesC8& aURI, 
       
   583                                             const TDesC8& aLUID, 
       
   584                                             const TInt aStatusRef )
       
   585 	{
       
   586     _DBG_FILE("CNSmlDSSettingsAdapter::DeleteObjectL( ): begin");
       
   587 	iLUID = IntLUID( aLUID );
       
   588 	if( aLUID.Length() == 0 )
       
   589 		{
       
   590 		_DBG_FILE("CNSmlDSSettingsAdapter DELETE::DeleteObjectL( ): ENotFound end");
       
   591 		iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   592 		return;
       
   593 		}
       
   594 
       
   595 //
       
   596 //	Check which field going to be handled
       
   597 //
       
   598 	SetField( aURI );
       
   599     if ( iField->Compare( KNSmlDdfCTType ) == 0 
       
   600         || iField->Compare( KNSmlDdfRDBURI ) == 0 
       
   601         || iField->Compare( KNSmlDdfLDBURI ) == 0 
       
   602         || iField->Compare( KNSmlDdfToNAPID ) == 0 )
       
   603 		{
       
   604 		_DBG_FILE("CNSmlDSSettingsAdapter DELETE::DeleteObjectL( ): EError end");
       
   605 		iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   606 		return;
       
   607 		}
       
   608 	
       
   609 	TInt last = aURI.LocateReverse( KNSmlDMUriSeparator );
       
   610 	TInt pos  = aURI.Find( KNSmlDefDSAcc );
       
   611 
       
   612 	if(last - 5 == pos )
       
   613 		{
       
   614 		iLUID = IntLUID( aLUID );
       
   615 		if( !FindProfileIdL( iLUID ) )
       
   616 			{
       
   617 			_DBG_FILE("CNSmlDSSettingsAdapter::DeleteObjectL( ): notfound end");
       
   618 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   619 			return;
       
   620 			}
       
   621 		else
       
   622 			{
       
   623 			TInt sRet = DeleteProfileL( iLUID );
       
   624 			if( sRet!=KErrNone )
       
   625 				{
       
   626 				_DBG_FILE("CNSmlDSSettingsAdapter::DeleteObjectL( ): ENotCommitted end");
       
   627 				if( sRet == KErrNotFound )
       
   628 				    {
       
   629                     iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   630 				    }
       
   631 				else if( sRet == KErrInUse )
       
   632 				    {
       
   633                     iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EObjectInUse );
       
   634 				    }
       
   635 				else
       
   636                     {
       
   637                     iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   638                     }
       
   639 				return;
       
   640 				}
       
   641 			else
       
   642 				{
       
   643 				iPrevURI->Des().Format( KNullDesC8 );
       
   644 				iPrevLUID = 0;
       
   645 				_DBG_FILE("CNSmlDSSettingsAdapter::DeleteObjectL( ): EOk end");
       
   646 				iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EOk );
       
   647 				return;
       
   648 				}
       
   649 			}
       
   650 		}
       
   651 	else if( aURI.Match( KDBUri1 ) != KErrNotFound )
       
   652 		{
       
   653 		iLUID = GetProfileIdFromURIL( aURI ); // Get profile Id for DB-level
       
   654 		if (iLUID < 0)
       
   655 			{
       
   656 			_DBG_FILE("CNSmlDSSettingsAdapter::DeleteObjectL( ): EError end");
       
   657 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   658 			return;
       
   659 			}
       
   660 
       
   661 		if( !FindProfileIdL( iLUID ) )
       
   662 			{
       
   663 			_DBG_FILE("CNSmlDSSettingsAdapter::DeleteObjectL( ): ENotFound end");
       
   664 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   665 			return;
       
   666 			}
       
   667 		TInt adapterId = GetIntObject( aLUID );//Get task ID
       
   668         TInt retval =  DeleteTaskByIDL( iLUID, adapterId );
       
   669         if( retval != KErrNone )
       
   670             {
       
   671             if( retval == KErrNotFound )
       
   672                 {
       
   673                 _DBG_FILE("CNSmlDSSettingsAdapter::DeleteObjectL( ): ENotFound end");
       
   674                 iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   675                 }
       
   676             else
       
   677 				{
       
   678 				_DBG_FILE("CNSmlDSSettingsAdapter::DeleteObjectL( ): EError end");
       
   679                 iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   680                	}
       
   681             }
       
   682 		else
       
   683             {
       
   684             _DBG_FILE("CNSmlDSSettingsAdapter::DeleteObjectL( ): EOk end");
       
   685 		    iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EOk );
       
   686             }
       
   687         return;
       
   688 		}
       
   689 
       
   690 	iLUID = IntLUID( aLUID );
       
   691 
       
   692 	if ( iLUID != iParentLUID )
       
   693 		{
       
   694 		if( !FindProfileIdL( iLUID ) )
       
   695 			{
       
   696 			_DBG_FILE("CNSmlDSSettingsAdapter::DeleteObjectL( ): end");
       
   697 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   698 			return;
       
   699 			}
       
   700 		iParentLUID = iLUID;
       
   701 		}
       
   702 
       
   703 	HBufC8* lObject = HBufC8::NewLC( 15 );
       
   704     lObject->Des().Format( KNullDesC8 );
       
   705 	
       
   706 	iLeafType = EDSDelete;
       
   707 	UpdateLeafObjectL( aURI, aLUID, *lObject, KMimeType, aStatusRef );
       
   708 	iLeafType = EDSUnset;
       
   709 
       
   710 	_DBG_FILE("CNSmlDSSettingsAdapter::DeleteObjectL( ): end");
       
   711 	CleanupStack::PopAndDestroy(); //lObject 
       
   712 	return;
       
   713 	}
       
   714 
       
   715 //------------------------------------------------------------------------------
       
   716 //  CNSmlDSSettingsAdapter::FetchLeafObjectL
       
   717 //  The function fetches the leaf object data.
       
   718 //------------------------------------------------------------------------------
       
   719 void CNSmlDSSettingsAdapter::FetchLeafObjectL( const TDesC8& aURI, 
       
   720                                                 const TDesC8& aLUID, 
       
   721                                                 const TDesC8& aType, 
       
   722                                                 const TInt aResultsRef, 
       
   723                                                 const TInt aStatusRef )
       
   724 	{
       
   725 	_DBG_FILE("CNSmlDSSettingsAdapter::FetchLeafObjectL(): begin");
       
   726 	DBG_ARGS(_S16("DS:Fetch aURI    - %S - %S"), &aURI, &aLUID);
       
   727 
       
   728     CBufBase *lObject = CBufFlat::NewL( 128 );
       
   729 	CleanupStack::PushL( lObject );
       
   730 	lObject->Reset();
       
   731     if( FetchObjectL( aURI, aLUID, lObject, aStatusRef ) != KErrNone )
       
   732         {
       
   733         CleanupStack::PopAndDestroy(); //lObject
       
   734         _DBG_FILE("CNSmlDSSettingsAdapter::FetchLeafObjectL() : Error end");
       
   735         return;
       
   736         };
       
   737     iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EOk );
       
   738     iCallBack->SetResultsL( aResultsRef, *lObject, aType );
       
   739 	CleanupStack::PopAndDestroy(); //object    
       
   740     _DBG_FILE("CNSmlDSSettingsAdapter::FetchLeafObjectL() : end");
       
   741     return;
       
   742 	}
       
   743 
       
   744 //------------------------------------------------------------------------------
       
   745 //  CSmlDSSettingsAdapter::ChildURIListL
       
   746 //  Function returns the list of profiles or leafs of the profile 
       
   747 //  acording to aURI.
       
   748 //------------------------------------------------------------------------------
       
   749 void CNSmlDSSettingsAdapter::ChildURIListL( const TDesC8& aURI, 
       
   750                                             const TDesC8& aLUID, 
       
   751                                             const CArrayFix<TSmlDmMappingInfo>& aPreviousURISegmentList, 
       
   752                                             const TInt aResultsRef, const TInt aStatusRef )
       
   753 	{
       
   754     _DBG_FILE("CNSmlDSSettingsAdapter::ChildURIListL(): begin");
       
   755 //	DBG_ARGS(_S16("ChildURIListL URI - <%S>"), &aURI);
       
   756 
       
   757 	CBufBase *currentURISegmentList = CBufFlat::NewL( 128 );
       
   758 	CleanupStack::PushL( currentURISegmentList );
       
   759 
       
   760 	if( aURI.Match( KDSAccMatch ) != KErrNotFound &&
       
   761 	   aURI.Match( KDSAccMatch2 ) == KErrNotFound )
       
   762 		{
       
   763 		//
       
   764 		//	Check if Profile exists
       
   765 		//
       
   766 		TInt checkLUID = GetIntObject( aLUID ); 
       
   767 		if( FindProfileIdL( checkLUID ) )
       
   768 		{
       
   769 			currentURISegmentList->InsertL( currentURISegmentList->Size(), KSegmDSAcc );
       
   770 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EOk );
       
   771 		   	iCallBack->SetResultsL( aResultsRef, *currentURISegmentList, KNullDesC8 );
       
   772         }
       
   773         else
       
   774         {
       
   775 			checkLUID = -1;
       
   776 			if( IsDSAccUriFormatMatchPredefined(aURI) )
       
   777 		    {
       
   778 		    	checkLUID = ConstructTreeL(aURI); 
       
   779     		}    	
       
   780     		if (checkLUID == -1 ) 
       
   781 		    {
       
   782 		    	_DBG_FILE( "CNSmlDMSettingsAdapter::childURI(): ENotFound end" );
       
   783 				iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   784 				CleanupStack::PopAndDestroy(  ); // currentURISegmentList
       
   785         		_DBG_FILE( "CNSmlDMSettingsAdapter::ChildURIListL(): end" );
       
   786 			    return;
       
   787 		   	}
       
   788 		    else
       
   789 		    {
       
   790        		    currentURISegmentList->InsertL( currentURISegmentList->Size(), KSegmDSAcc );
       
   791  				iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EOk );
       
   792 			    iCallBack->SetResultsL( aResultsRef, *currentURISegmentList, KNullDesC8 );
       
   793 		    	}
       
   794     	
       
   795 			// Static node feature start end
       
   796 
       
   797 			_DBG_FILE("CNSmlDSSettingsAdapter::ChildURIListL(): end");
       
   798 			CleanupStack::PopAndDestroy(); //currentURISegmentList 
       
   799 			return;
       
   800 		}
       
   801 		}		
       
   802 	else if( aURI.Match( KDSDBMatch ) != KErrNotFound )
       
   803 		{
       
   804 		//
       
   805 		//	Check if ContenType exists (profileId from adapters)
       
   806 		// 
       
   807 		TInt profileLUID = GetProfileIdFromURIL( aURI ); // ProfileId for DB-level
       
   808         if( OpenSyncSessionAndDSProfileL( profileLUID, ESmlOpenRead ) == KErrNone )
       
   809             {
       
   810             RArray<TSmlTaskId> taskIdArray;
       
   811             CleanupClosePushL( taskIdArray );
       
   812             iDSProfile.ListTasksL( taskIdArray );
       
   813             if( taskIdArray.Count() == 0 )
       
   814                 {
       
   815                 currentURISegmentList->InsertL( currentURISegmentList->Size(), KNullDesC8 );
       
   816                 }
       
   817             else
       
   818                 {
       
   819                 currentURISegmentList->InsertL( currentURISegmentList->Size(), KSegmDSAcc2 );
       
   820                 }
       
   821             CloseDSProfile();
       
   822             CleanupStack::PopAndDestroy();//taskIdArray
       
   823             }
       
   824         else
       
   825             { 
       
   826             iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   827 		    _DBG_FILE("CNSmlDSSettingsAdapter::ChildURIListL(): CT-NOTFOUND end");
       
   828 			CleanupStack::PopAndDestroy();//currentURISegmentList 
       
   829 			return;
       
   830             }
       
   831             
       
   832         iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EOk );
       
   833 		iCallBack->SetResultsL( aResultsRef, *currentURISegmentList, KNullDesC8 );
       
   834 		_DBG_FILE("CNSmlDSSettingsAdapter::ChildURIListL(): end");
       
   835 		CleanupStack::PopAndDestroy(); //currentURISegmentList
       
   836 		return;
       
   837 		}
       
   838 //
       
   839 //	Handle ContentType (DB) request -> TASKS of the profile
       
   840 //
       
   841 	if( aURI.Match( KDSDBMatch2 ) != KErrNotFound )
       
   842 		{
       
   843 		TInt lProfileId = GetIntObject( aLUID ); 
       
   844 		
       
   845 		if( ! FindProfileIdL( lProfileId ) )
       
   846 			{
       
   847 			_DBG_FILE("CNSmlDSSettingsAdapter::ChildURIListL(): NOTFOUND CTTYPE end");
       
   848 			CleanupStack::PopAndDestroy();// currentURISegmentList
       
   849 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   850 			return;
       
   851 			}
       
   852 		
       
   853         TInt ret = CreateURITaskSegmentListL( aURI, lProfileId, currentURISegmentList, 
       
   854                                                 aPreviousURISegmentList );
       
   855 		if( ret != KErrNone && ret != KErrNotFound )
       
   856 			{
       
   857 			_DBG_FILE("CNSmlDSSettingsAdapter::ChildURIListL(): ContentType error end");
       
   858 			CleanupStack::PopAndDestroy();// currentURISegmentList
       
   859 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   860 			return;
       
   861 			}
       
   862 		_DBG_FILE("CNSmlDSSettingsAdapter::ChildURIListL(): CTTYPE-OK end");
       
   863 		iCallBack->SetResultsL( aResultsRef, *currentURISegmentList, KNullDesC8);
       
   864 		iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EOk );	
       
   865 		CleanupStack::PopAndDestroy();// currentURISegmentList
       
   866 		return;
       
   867 		}
       
   868 
       
   869 	
       
   870     TInt ret = CreateURIProfileSegmentListL( currentURISegmentList, aPreviousURISegmentList );
       
   871 
       
   872     if( ret != KErrNone )
       
   873 	    {
       
   874 		_DBG_FILE("CNSmlDSSettingsAdapter::ChildURIListL(): Profile not found end");
       
   875 		CleanupStack::PopAndDestroy();// currentURISegmentList
       
   876 		iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
   877 		return;
       
   878 		}
       
   879    
       
   880 	iCallBack->SetResultsL( aResultsRef, *currentURISegmentList, KNullDesC8 );
       
   881 	CleanupStack::PopAndDestroy(); // currentURISegmentList
       
   882 	iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EOk );
       
   883 	_DBG_FILE("CNSmlDSSettingsAdapter::ChildURIListL(): end");
       
   884 	return;
       
   885     }
       
   886 
       
   887 //------------------------------------------------------------------------------
       
   888 //  CNSmlDSSettingsAdapter::AddNodeObjectL
       
   889 //  The function adds the new node object.
       
   890 //------------------------------------------------------------------------------
       
   891 void CNSmlDSSettingsAdapter::AddNodeObjectL( const TDesC8& aURI, 
       
   892                                                 const TDesC8& aParentLUID, 
       
   893                                                 const TInt aStatusRef )
       
   894 	{
       
   895 	_DBG_FILE("CNSmlDSSettingsAdapter::AddNodeObjectL(): begin");
       
   896 //
       
   897 //	Check if ContentType-add and insert to Buffer
       
   898 //
       
   899     iParentLUID = GetIntObject( aParentLUID );
       
   900     
       
   901 	if( aURI.Match( KDSDBAddMatch )!= KErrNotFound &&
       
   902 		aURI.Match( KDSDBAddMatch2 )== KErrNotFound )
       
   903 		{
       
   904 		if( aParentLUID.Length() > 0 && iParentLUID >= 0 && iBufferExecution == EFalse )
       
   905 			{
       
   906             AddNodeBufferL( aURI, aParentLUID, aStatusRef );
       
   907             }
       
   908 		else if( iParentLUID < 0 )
       
   909 			{
       
   910 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EOk );
       
   911 			_DBG_FILE("CNSmlDSSettingsAdapter::AddNodeObjectL(): end");
       
   912 			}
       
   913 		else
       
   914 			{
       
   915 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   916 			_DBG_FILE("CNSmlDSSettingsAdapter::AddNodeObjectL(): end");
       
   917 			}
       
   918 		return;
       
   919 		}
       
   920     
       
   921 	if( aURI.Match(KDSDBAddMatch3) != KErrNotFound )
       
   922 		{
       
   923 		if( FindProfileIdL( iParentLUID ) ) // Profile on database
       
   924 			{
       
   925 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EOk );
       
   926 			_DBG_FILE("CNSmlDSSettingsAdapter::AddNodeObjectL(): end");
       
   927 			}
       
   928 		else
       
   929 			{
       
   930 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   931 			_DBG_FILE("CNSmlDSSettingsAdapter::AddNodeObjectL(): end");
       
   932 			}
       
   933 		return;
       
   934 		}
       
   935    
       
   936 	if( FindProfileIdL( iParentLUID ) )
       
   937 		{
       
   938 		iCallBack->SetStatusL(aStatusRef,CSmlDmAdapter::EAlreadyExists);
       
   939 		_DBG_FILE("CNSmlDSSettingsAdapter::AddNodeObjectL(): EAlreadyExists end");
       
   940 		return;
       
   941 		}
       
   942 	else
       
   943 		{
       
   944         //
       
   945         //	Create new profile
       
   946         //
       
   947    	    TInt newPID = -1;
       
   948         TInt sRet = CreateNewProfileL( newPID );
       
   949         if( sRet != KErrNone || newPID < 0 )
       
   950 		    {	
       
   951 		    if( sRet == KErrDiskFull )
       
   952 			    {
       
   953 			    iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EDiskFull );
       
   954 			    }
       
   955 		    else if( sRet == KErrInUse )
       
   956 			    {
       
   957 			    iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EObjectInUse );
       
   958 			    }
       
   959 		    else
       
   960 			    {
       
   961 			    iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EError );
       
   962 			    }
       
   963 		    return;
       
   964 		    }
       
   965 		//
       
   966         //	Get new ProfileId from database
       
   967         //
       
   968 	    iLUID = newPID;
       
   969         //
       
   970    	    TBuf8<8> newLUID;
       
   971 	    newLUID.Num( iLUID );
       
   972 	    iCallBack->SetMappingL( aURI, newLUID );
       
   973         newLUID.Delete( 0, newLUID.Size() );
       
   974         }
       
   975 	iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EOk );
       
   976 	_DBG_FILE("CNSmlDSSettingsAdapter::AddNodeObjectL(): end");
       
   977     return;
       
   978 	}
       
   979 
       
   980 //------------------------------------------------------------------------------
       
   981 //  CNSmlDSSettingsAdapter::UpdateLeafObjectL
       
   982 //------------------------------------------------------------------------------
       
   983 void CNSmlDSSettingsAdapter::UpdateLeafObjectL( const TDesC8& /*aURI*/, 
       
   984                                                 const TDesC8& /*aLUID*/, 
       
   985                                                 RWriteStream*& /*aStream*/, 
       
   986                                                 const TDesC8& /*aType*/, 
       
   987                                                 const TInt /*aStatusRef*/ )
       
   988 	{
       
   989 	//Not supported since streaming is not supported by the adapter.
       
   990 	}
       
   991 	
       
   992 //------------------------------------------------------------------------------
       
   993 //  CNSmlDSSettingsAdapter::FetchLeafObjectSizeL
       
   994 //  The function fetches the size of the leaf object data.
       
   995 //------------------------------------------------------------------------------
       
   996 void CNSmlDSSettingsAdapter::FetchLeafObjectSizeL( const TDesC8& aURI, 
       
   997                                                     const TDesC8& aLUID, 
       
   998                                                     const TDesC8& aType, 
       
   999                                                     const TInt aResultsRef, 
       
  1000                                                     const TInt aStatusRef )
       
  1001 	{
       
  1002 	_DBG_FILE("CNSmlDSSettingsAdapter::FetchLeafObjectSizeL() : begin");
       
  1003     CBufBase *lObject = CBufFlat::NewL( 128 );
       
  1004 	CleanupStack::PushL( lObject );
       
  1005 	lObject->Reset();
       
  1006     if( FetchObjectL( aURI, aLUID, lObject, aStatusRef ) != KErrNone )
       
  1007         {
       
  1008         CleanupStack::PopAndDestroy(); //lObject
       
  1009         _DBG_FILE("CNSmlDSSettingsAdapter::FetchLeafObjectSizeL() : Error end");
       
  1010         return;
       
  1011         };
       
  1012     TInt objSizeInBytes = lObject->Size();
       
  1013 	TBuf8<16> stringObjSizeInBytes;
       
  1014 	stringObjSizeInBytes.Num( objSizeInBytes );
       
  1015 	lObject->Reset();
       
  1016     lObject->InsertL( 0, stringObjSizeInBytes );
       
  1017 	
       
  1018 	iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EOk );
       
  1019 	iCallBack->SetResultsL( aResultsRef, *lObject, aType );
       
  1020 	CleanupStack::PopAndDestroy(); //object
       
  1021     _DBG_FILE("CNSmlDSSettingsAdapter::FetchLeafObjectSizeL() : end");
       
  1022     return;
       
  1023     }
       
  1024 
       
  1025 //------------------------------------------------------------------------------
       
  1026 //  CNSmlDSSettingsAdapter::ExecuteCommandL
       
  1027 //------------------------------------------------------------------------------
       
  1028 void CNSmlDSSettingsAdapter::ExecuteCommandL( const TDesC8& /*aURI*/, 
       
  1029                                                 const TDesC8& /*aLUID*/, 
       
  1030                                                 const TDesC8& /*aArgument*/, 
       
  1031                                                 const TDesC8& /*aType*/, 
       
  1032                                                 const TInt /*aStatusRef*/ )
       
  1033 	{
       
  1034 	// Not supported	
       
  1035 	}
       
  1036 
       
  1037 //------------------------------------------------------------------------------
       
  1038 //  CNSmlDSSettingsAdapter::ExecuteCommandL
       
  1039 //------------------------------------------------------------------------------
       
  1040 void CNSmlDSSettingsAdapter::ExecuteCommandL( const TDesC8& /*aURI*/, 
       
  1041                                                 const TDesC8& /*aLUID*/, 
       
  1042                                                 RWriteStream*& /*aStream*/, 
       
  1043                                                 const TDesC8& /*aType*/, 
       
  1044                                                 const TInt /*aStatusRef*/ )
       
  1045 	{
       
  1046 	// Not supported by the adapter.
       
  1047 	}
       
  1048 
       
  1049 //------------------------------------------------------------------------------
       
  1050 //  CNSmlDSSettingsAdapter::CopyCommandL
       
  1051 //------------------------------------------------------------------------------
       
  1052 void CNSmlDSSettingsAdapter::CopyCommandL( const TDesC8& /*aTargetURI*/, 
       
  1053                                             const TDesC8& /*aTargetLUID*/, 
       
  1054                                             const TDesC8& /*aSourceURI*/, 
       
  1055                                             const TDesC8& /*aSourceLUID*/, 
       
  1056                                             const TDesC8& /*aType*/, 
       
  1057                                             TInt /*aStatusRef*/ )
       
  1058 	{
       
  1059 	// Not supported by the adapter.
       
  1060 	}
       
  1061 
       
  1062 //------------------------------------------------------------------------------
       
  1063 //  CNSmlDSSettingsAdapter::StartAtomicL
       
  1064 //------------------------------------------------------------------------------
       
  1065 void CNSmlDSSettingsAdapter::StartAtomicL()
       
  1066 	{
       
  1067 	// Atomic commands not supported by the adapter.
       
  1068 	}
       
  1069 
       
  1070 //------------------------------------------------------------------------------
       
  1071 //  CNSmlDSSettingsAdapter::CommitAtomicL
       
  1072 //------------------------------------------------------------------------------
       
  1073 void CNSmlDSSettingsAdapter::CommitAtomicL()
       
  1074 	{
       
  1075 	// Atomic commands not supported by the adapter.
       
  1076 	}
       
  1077 
       
  1078 //------------------------------------------------------------------------------
       
  1079 //  CNSmlDSSettingsAdapter::RollbackAtomicL
       
  1080 //------------------------------------------------------------------------------
       
  1081 void CNSmlDSSettingsAdapter::RollbackAtomicL()
       
  1082 	{
       
  1083 	// Atomic commands not supported by the adapter.
       
  1084 	}
       
  1085 
       
  1086 //------------------------------------------------------------------------------
       
  1087 //  CNSmlDSSettingsAdapter::StreamingSupport()
       
  1088 //  Indicates if streaming is supported.
       
  1089 //------------------------------------------------------------------------------
       
  1090 TBool CNSmlDSSettingsAdapter::StreamingSupport( TInt& /*aItemSize*/ )
       
  1091 	{
       
  1092 	return EFalse;
       
  1093 	}
       
  1094 
       
  1095 //------------------------------------------------------------------------------
       
  1096 //  CNSmlDSSettingsAdapter::StreamCommittedL
       
  1097 //------------------------------------------------------------------------------
       
  1098 void CNSmlDSSettingsAdapter::StreamCommittedL()
       
  1099 	{
       
  1100 	//  Not supported since streaming not supported by the adapter.
       
  1101 	}
       
  1102 //------------------------------------------------------------------------------
       
  1103 //  CNSmlDSSettingsAdapter::CompleteOutstandingCmdsL
       
  1104 //  The function completes all buffered command from the buffer.
       
  1105 //------------------------------------------------------------------------------
       
  1106 void CNSmlDSSettingsAdapter::CompleteOutstandingCmdsL()
       
  1107 	{
       
  1108     
       
  1109 //
       
  1110 //	Handle unhandled nodes if any
       
  1111 //
       
  1112     TInt count = iBuffer->Count();
       
  1113 	for( TInt h = 0; h < count ; h++ )
       
  1114 		{
       
  1115 		TBuf8<150> commandURI;
       
  1116 		commandURI.Append( iBuffer->At(0).iMappingName->Des() );
       
  1117 		commandURI.Append( KDummyTxt );
       
  1118 		TRAP_IGNORE( ExecuteBufferL( commandURI ) );
       
  1119 		}
       
  1120 	iBuffer->Reset();
       
  1121 	CloseDSProfile();
       
  1122 	
       
  1123 	// if port was updated, set it
       
  1124     if ( iPortBuf )
       
  1125         {
       
  1126         TInt err = SetProfileConnectionPortNrL( iPortBufLUID, *iPortBuf );
       
  1127         
       
  1128         // set status
       
  1129         if ( err != KErrNone )
       
  1130             {
       
  1131             iCallBack->SetStatusL( iPortBufStatusRef, CSmlDmAdapter::EError );
       
  1132             }
       
  1133         else
       
  1134             {
       
  1135             iCallBack->SetStatusL( iPortBufStatusRef, CSmlDmAdapter::EOk );
       
  1136             }
       
  1137 
       
  1138         delete iPortBuf;
       
  1139         iPortBuf = NULL;
       
  1140         }
       
  1141 	}
       
  1142 
       
  1143 //------------------------------------------------------------------------------
       
  1144 //  TBool CNSmlDSSettingsAdapter::AcceptDSField
       
  1145 //  The function checks if leaf to be handled is valid for the adapter.
       
  1146 //------------------------------------------------------------------------------
       
  1147 TBool CNSmlDSSettingsAdapter::AcceptDSField()
       
  1148 	{
       
  1149 	_DBG_FILE("CNSmlDSSettingsAdapter::AcceptDSField(): begin");
       
  1150 
       
  1151 	if ( iField->Compare( KNSmlDdfAddrType ) == 0 )
       
  1152 		{
       
  1153 		return ETrue;
       
  1154 		}
       
  1155 	else if ( iField->Compare( KNSmlDdfAddr ) == 0 )
       
  1156 		{
       
  1157 		return ETrue;
       
  1158 		}
       
  1159 	else if ( iField->Compare( KNSmlDdfPortNbr ) == 0 )
       
  1160 		{
       
  1161 		return ETrue;
       
  1162 		}
       
  1163 	else if ( iField->Compare( KNSmlDdfClientUserName ) == 0 )
       
  1164 		{
       
  1165 		return ETrue;
       
  1166 		}
       
  1167 	else if ( iField->Compare( KNSmlDdfName ) == 0 )
       
  1168 		{
       
  1169 		return ETrue;
       
  1170 		}
       
  1171 	else if ( iField->Compare( KNSmlDdfCTType ) == 0 )
       
  1172 		{
       
  1173 		return ETrue;
       
  1174 		}
       
  1175 	else if ( iField->Compare( KNSmlDdfRDBURI ) == 0 )
       
  1176 		{
       
  1177 		return ETrue;
       
  1178 		}
       
  1179 	else if ( iField->Compare( KNSmlDdfLDBURI ) == 0 )
       
  1180 		{
       
  1181 		return ETrue;
       
  1182 		}
       
  1183 	else if ( iField->Compare( KNSmlDdfClientPW ) == 0 )
       
  1184 		{
       
  1185 		return ETrue;
       
  1186 		}
       
  1187 	else if ( iField->Compare( KNSmlDdfToNAPID ) == 0 )
       
  1188 		{
       
  1189 		return ETrue;
       
  1190 		}
       
  1191 	else if ( iField->Compare( KNSmlDdfHidden ) == 0 )
       
  1192 		{
       
  1193 		return EFalse;
       
  1194 		}
       
  1195 
       
  1196 	_DBG_FILE("CNSmlDSSettingsAdapter::AcceptDSField(): end");
       
  1197 	return EFalse;
       
  1198 	}
       
  1199 
       
  1200 //------------------------------------------------------------------------------
       
  1201 //  CNSmlDSSettingsAdapter::GetDSField
       
  1202 //  The function checks what leaf to handled and returns enum value for the leaf.
       
  1203 //------------------------------------------------------------------------------
       
  1204 TInt CNSmlDSSettingsAdapter::GetDSField() const
       
  1205 	{
       
  1206 	_DBG_FILE("CNSmlDSSettingsAdapter::GetDSField(): begin");
       
  1207 
       
  1208 	if ( iField->Compare( KNSmlDdfAddrType ) == 0 )
       
  1209 		{
       
  1210 		return EProfileMediumType;
       
  1211 		}
       
  1212 	else if ( iField->Compare( KNSmlDdfAddr ) == 0 )
       
  1213 		{
       
  1214 		return EProfileURL;
       
  1215 		}
       
  1216 	else if ( iField->Compare( KNSmlDdfPortNbr ) == 0 )
       
  1217 		{
       
  1218 		return EProfilePort;
       
  1219 		}
       
  1220 	else if ( iField->Compare( KNSmlDdfClientUserName ) == 0 )
       
  1221 		{
       
  1222 		return EProfileSyncServerUsername;
       
  1223 		}
       
  1224 	else if ( iField->Compare( KNSmlDdfServerId ) == 0 )
       
  1225 		{
       
  1226 		return EProfileServerId;
       
  1227 		}
       
  1228 	else if ( iField->Compare( KNSmlDdfClientPW ) == 0 )
       
  1229 		{
       
  1230 		return EProfileSyncServerPassword;
       
  1231 		}
       
  1232 	else if ( iField->Compare( KNSmlDdfName ) == 0 )
       
  1233 		{
       
  1234 		return EProfileName;
       
  1235 		}
       
  1236 	else if ( iField->Compare( KNSmlDdfToNAPID ) == 0 )
       
  1237 		{
       
  1238 		return EProfileIAPId;
       
  1239 		}
       
  1240 	else if ( iField->Compare( KNSmlDdfHidden ) == 0 )
       
  1241 		{
       
  1242 		return EHiddenProfile;
       
  1243 		}
       
  1244     else if ( iField->Compare( KNSmlDdfDB ) == 0 ||
       
  1245             iField->Compare( KNSmlDdfCTType ) == 0 ||
       
  1246             iField->Compare( KNSmlDdfCTVerL ) == 0 ||
       
  1247             iField->Compare( KNSmlDdfRDBURI ) == 0 ||
       
  1248             iField->Compare( KNSmlDdfLDBURI ) == 0 )
       
  1249 		{
       
  1250 		return ESyncAccepted;
       
  1251 		}
       
  1252 	
       
  1253 	_DBG_FILE("CNSmlDSSettingsAdapter::GetDSField(): end");
       
  1254 	return KErrNotFound;
       
  1255 	}
       
  1256 
       
  1257 //------------------------------------------------------------------------------
       
  1258 //  CNSmlDSSettingsAdapter::GetDSFieldTypeL
       
  1259 //  The function return the data type for the leaf.
       
  1260 //------------------------------------------------------------------------------
       
  1261 TInt CNSmlDSSettingsAdapter::GetDSFieldTypeL() const
       
  1262 	{
       
  1263 	_DBG_FILE("CNSmlDSSettingsAdapter::GetDSFieldTypeL(): begin");
       
  1264 
       
  1265 	if ( iField->Compare( KNSmlDdfAddrType ) == 0 ||
       
  1266         iField->Compare( KNSmlDdfPortNbr ) == 0 ||
       
  1267         iField->Compare( KNSmlDdfToNAPID ) == 0 ||
       
  1268         iField->Compare( KNSmlDdfHidden ) == 0 )
       
  1269 		{
       
  1270 		return EInt;
       
  1271 		}
       
  1272 	else if ( iField->Compare( KNSmlDdfAddr ) == 0 ||
       
  1273             iField->Compare( KNSmlDdfClientUserName ) == 0 ||
       
  1274             iField->Compare( KNSmlDdfServerId ) == 0 ||
       
  1275             iField->Compare( KNSmlDdfClientPW ) == 0 ||
       
  1276             iField->Compare( KNSmlDdfName ) == 0 )
       
  1277 		{
       
  1278 		return EStr;
       
  1279 		}
       
  1280 	else if ( iField->Compare( KNSmlDdfDB ) == 0 ||
       
  1281             iField->Compare( KNSmlDdfCTType ) == 0 ||
       
  1282             iField->Compare( KNSmlDdfCTVerL ) == 0 ||
       
  1283             iField->Compare( KNSmlDdfRDBURI ) == 0 ||
       
  1284             iField->Compare( KNSmlDdfLDBURI ) == 0 )
       
  1285 		{
       
  1286 		return EParam;
       
  1287 		}
       
  1288 
       
  1289 	_DBG_FILE("CNSmlDSSettingsAdapter::GetDSFieldTypeL(): end");
       
  1290 	return EWrong;
       
  1291 	}
       
  1292 
       
  1293 //------------------------------------------------------------------------------
       
  1294 //  CNSmlDSSettingsAdapter::IntLUID
       
  1295 //	Returns IntValue for aLUID.
       
  1296 //------------------------------------------------------------------------------
       
  1297 TInt CNSmlDSSettingsAdapter::IntLUID( const TDesC8& aLUID )
       
  1298 	{
       
  1299 
       
  1300 	TLex8 lLex( aLUID );
       
  1301 
       
  1302 	if ( lLex.Val( iLUID ) == KErrNone )
       
  1303 	    {
       
  1304 	    return iLUID;
       
  1305 	    }
       
  1306 	else
       
  1307         {
       
  1308         return 0;
       
  1309         }
       
  1310 	}
       
  1311 
       
  1312 //------------------------------------------------------------------------------
       
  1313 //	CNSmlDSSettingsAdapter::GetIntObject
       
  1314 //	Returns IntValue for a aObject
       
  1315 //------------------------------------------------------------------------------
       
  1316 TInt CNSmlDSSettingsAdapter::GetIntObject( const TDesC8& aObject )
       
  1317 	{
       
  1318 	TLex8 lLex( aObject );
       
  1319 
       
  1320 	TInt value = 0;
       
  1321 
       
  1322 	if ( lLex.Val( value ) == KErrNone )
       
  1323 	    {
       
  1324 	    return value;
       
  1325 	    }
       
  1326 	else
       
  1327         {
       
  1328         return KErrGeneral;
       
  1329         }
       
  1330 	}
       
  1331 
       
  1332 //------------------------------------------------------------------------------
       
  1333 //	CNSmlDSSettingsAdapter::GetIntObject16()
       
  1334 //	Returns IntValue for a 16-bit aObject
       
  1335 //------------------------------------------------------------------------------
       
  1336 TInt CNSmlDSSettingsAdapter::GetIntObject16( const TDesC& aObject )
       
  1337 	{
       
  1338 	TLex lLex( aObject );
       
  1339 
       
  1340 	TInt value = 0;
       
  1341 
       
  1342 	if ( lLex.Val( value ) == KErrNone )
       
  1343 	    {
       
  1344 	    return value;
       
  1345 	    }
       
  1346 	else
       
  1347         {
       
  1348         return KErrGeneral;
       
  1349         }
       
  1350 	}
       
  1351 //------------------------------------------------------------------------------
       
  1352 //	CNSmlDSSettingsAdapter::SetIntObjectLC
       
  1353 //	Converts integer to HBufC8 type buffer and returns reference to it.
       
  1354 //------------------------------------------------------------------------------
       
  1355 TDesC8& CNSmlDSSettingsAdapter::SetIntObjectLC( const TInt& aObject )
       
  1356 	{
       
  1357 	HBufC8* buf = HBufC8::NewLC( 8 );
       
  1358 	TPtr8 ptrBuf = buf->Des();
       
  1359 
       
  1360 	ptrBuf.Num( aObject );
       
  1361 
       
  1362 	return *buf;
       
  1363 	}
       
  1364 
       
  1365 //------------------------------------------------------------------------------
       
  1366 //	CNSmlDSSettingsAdapter::NotValidStrLenght
       
  1367 //	The function checks if data length for a leaf is valid.
       
  1368 //------------------------------------------------------------------------------
       
  1369 
       
  1370 TBool CNSmlDSSettingsAdapter::NotValidStrLenght( const TInt& aProfileItem, 
       
  1371                                                 const TDesC8& aSource )
       
  1372 	{
       
  1373 	TInt lLen = aSource.Length();
       
  1374 	TBool lBool = EFalse;
       
  1375 	
       
  1376 	switch ( aProfileItem )
       
  1377 		{
       
  1378 		case ( EProfileName ) :
       
  1379 			{
       
  1380 			if( lLen > KNSmlMaxProfileNameLength )
       
  1381 				lBool = ETrue;	
       
  1382 			}
       
  1383 		break;
       
  1384 		
       
  1385 		case ( EProfileSyncServerUsername ) :
       
  1386 			{
       
  1387 			if( lLen > KNSmlMaxUsernameLength )
       
  1388 				lBool = ETrue;	
       
  1389 			}
       
  1390 		break;
       
  1391 
       
  1392 		case ( EProfileSyncServerPassword ) :
       
  1393 			{
       
  1394 			if( lLen > KNSmlMaxPasswordLength )
       
  1395 				lBool = ETrue;	
       
  1396 			}
       
  1397 		break;
       
  1398 
       
  1399 		case ( EProfileURL ) :
       
  1400 			{
       
  1401 			if( lLen > KNSmlMaxURLLength )
       
  1402 				lBool = ETrue;	
       
  1403 			}
       
  1404 		break;
       
  1405 
       
  1406 		case ( EProfileIAPId ) :
       
  1407 			{
       
  1408 			if( lLen > KNSmlMaxURLLength )// Value from InternetAdapter for
       
  1409 				lBool = ETrue;			// given URI ./AP/xxx
       
  1410 			}
       
  1411 		break;
       
  1412 
       
  1413 		case ( EProfilePort ) :
       
  1414 		case ( EHiddenProfile ) :
       
  1415 		case ( EProfileMediumType ) :
       
  1416 			{
       
  1417 			if( lLen > 8 )
       
  1418 				lBool = ETrue;	
       
  1419 			}
       
  1420 		break;
       
  1421 
       
  1422 		case ( EProfileServerId ) :
       
  1423 			{
       
  1424 			if( lLen > KNSmlMaxUsernameLength )
       
  1425 				lBool = ETrue;			
       
  1426 			}
       
  1427 		break;
       
  1428 
       
  1429 		default:
       
  1430 			{
       
  1431 			return ETrue;
       
  1432 			}
       
  1433 		}
       
  1434 
       
  1435 	return lBool;
       
  1436 	}
       
  1437 
       
  1438 //------------------------------------------------------------------------------
       
  1439 //	CNSmlDSSettingsAdapter::SetField
       
  1440 //	The function finds out the last element of the URI.
       
  1441 //------------------------------------------------------------------------------
       
  1442 TInt CNSmlDSSettingsAdapter::SetField( const TDesC8& aSource )
       
  1443 	{
       
  1444 	if ( aSource.LocateReverse( KNSmlDMUriSeparator ) == KErrNotFound )
       
  1445 	    {
       
  1446 	    iField->Des().Format( aSource );
       
  1447 	    }
       
  1448 	else
       
  1449         {
       
  1450         iField->Des().Format( aSource.Mid( aSource.LocateReverse( KNSmlDMUriSeparator ) + 1 ) );
       
  1451         }
       
  1452 
       
  1453     return KErrNone;
       
  1454 	}
       
  1455 
       
  1456 //------------------------------------------------------------------------------
       
  1457 //	CNSmlDSSettingsAdapter::ConvertTo8LC
       
  1458 //	Converts 16-bit string value to 8-bit.
       
  1459 //------------------------------------------------------------------------------
       
  1460 TDesC8& CNSmlDSSettingsAdapter::ConvertTo8LC( const TDesC& aSource )
       
  1461 	{
       
  1462 	HBufC8* buf = HBufC8::NewLC( aSource.Length() * 2 );
       
  1463 	TPtr8 bufPtr = buf->Des();
       
  1464 	CnvUtfConverter::ConvertFromUnicodeToUtf8( bufPtr, aSource );
       
  1465     return *buf;
       
  1466 	}
       
  1467 
       
  1468 //------------------------------------------------------------------------------
       
  1469 //	CNSmlDSSettingsAdapter::ConvertTo16LC
       
  1470 //	Converts 8-bit string value to 16-bit.
       
  1471 //------------------------------------------------------------------------------
       
  1472 TDesC16& CNSmlDSSettingsAdapter::ConvertTo16LC( const TDesC8& aSource )
       
  1473 	{
       
  1474 	HBufC16* buf16 = HBufC16::NewLC( aSource.Length() );
       
  1475 	TPtr16 bufPtr16 = buf16->Des();
       
  1476 	CnvUtfConverter::ConvertToUnicodeFromUtf8( bufPtr16, aSource );
       
  1477     return *buf16;
       
  1478 	}
       
  1479 
       
  1480 //------------------------------------------------------------------------------
       
  1481 //	CNSmlDSSettingsAdapter::AddNewDataProviderL
       
  1482 //	Check if data provider exits and required MIME type is supported by the 
       
  1483 //  data provider. If supported new task will be created.
       
  1484 //------------------------------------------------------------------------------
       
  1485 TInt CNSmlDSSettingsAdapter::AddNewDataProviderL( TInt aIntLUID, 
       
  1486                                                     const TDesC8& aMIMEType, 
       
  1487                                                     TInt& aDataProviderId )
       
  1488 	{
       
  1489 	_DBG_FILE("CNSmlDSSettingsAdapter::AddNewDataProviderL(): begin");
       
  1490     
       
  1491     TInt retVal = OpenSyncSessionAndDSProfileL( aIntLUID, ESmlOpenReadWrite );
       
  1492     if( retVal != KErrNone )
       
  1493 		{
       
  1494         CloseDSProfile();
       
  1495         return KErrGeneral;	
       
  1496 		}
       
  1497     if( iRdbDataStore->Size() <= 0 )
       
  1498         {
       
  1499         CloseDSProfile();
       
  1500         return KErrGeneral;
       
  1501         }
       
  1502     RArray<TSmlDataProviderId> dataProviderArray;
       
  1503     CleanupClosePushL( dataProviderArray );
       
  1504     iSyncSession.ListDataProvidersL( dataProviderArray );
       
  1505     TInt dataProviderCount = dataProviderArray.Count();
       
  1506     if( dataProviderCount == 0 )
       
  1507         {
       
  1508         CloseDSProfile();
       
  1509         CleanupStack::PopAndDestroy(); // dataProviderIdArray
       
  1510     	_DBG_FILE("CNSmlDSSettingsAdapter::AddNewDataProviderL(): dataprovirdercount == 0 End");
       
  1511         return KErrNotFound;   
       
  1512         }
       
  1513     HBufC8* object = aMIMEType.AllocLC();
       
  1514     TPtr8 objectPtr = object->Des();
       
  1515 	objectPtr.LowerCase();
       
  1516     RSyncMLDataProvider dataProvider;
       
  1517         
       
  1518     for ( TInt i= 0; i < dataProviderCount; i++ )
       
  1519         {
       
  1520         dataProvider.OpenL( iSyncSession, dataProviderArray[i] );
       
  1521         CleanupClosePushL( dataProvider );   
       
  1522         for ( TInt n = 0; n < dataProvider.MimeTypeCount(); n++ )
       
  1523             {
       
  1524             HBufC* mimeType = dataProvider.MimeType(n).AllocLC();
       
  1525             if( objectPtr.CompareF( ConvertTo8LC( *mimeType ) ) == 0 ) //if MIME match
       
  1526                 {
       
  1527                	_DBG_FILE("CNSmlDSSettingsAdapter::AddNewDataProviderL(): Mimetype found");
       
  1528 
       
  1529                 aDataProviderId = dataProvider.Identifier();
       
  1530                 RSyncMLTask task;
       
  1531                 CleanupClosePushL( task ); 
       
  1532                 if( dataProvider.AllowsMultipleDataStores() )
       
  1533                     {
       
  1534                    	_DBG_FILE("CNSmlDSSettingsAdapter::AddNewDataProviderL(): AllowsMultipleDataStores");
       
  1535                     CDesCArray* dataStoreName = new ( ELeave ) CDesCArrayFlat( 1 );
       
  1536                     CleanupStack::PushL( dataStoreName );
       
  1537                     dataProvider.GetDataStoreNamesL( *dataStoreName );
       
  1538                     if ( dataStoreName->Count() == 0 )
       
  1539                         {
       
  1540                         // Get default if there are no databases
       
  1541                         _DBG_FILE("CNSmlDSSettingsAdapter::AddNewDataProviderL():  no databases -> get default");
       
  1542                         HBufC* localDataStoreName = dataProvider.DefaultDataStoreName().AllocLC();
       
  1543                         task.CreateL( iDSProfile, aDataProviderId, *iRdbDataStore, 
       
  1544                                     *localDataStoreName );
       
  1545 					    task.UpdateL();
       
  1546 						CleanupStack::PopAndDestroy();  //localDataStoreName
       
  1547                         }
       
  1548                     else
       
  1549                         {
       
  1550                         TPtrC16 ptrDataStoreName = dataStoreName->MdcaPoint(0);
       
  1551                         task.CreateL( iDSProfile, aDataProviderId, *iRdbDataStore, 
       
  1552 		                            ptrDataStoreName );
       
  1553 		                task.UpdateL();
       
  1554                         }
       
  1555                     CleanupStack::PopAndDestroy();//dataStoreName
       
  1556                     }
       
  1557                 else
       
  1558                     {
       
  1559                    	_DBG_FILE("CNSmlDSSettingsAdapter::AddNewDataProviderL():  MultipleDataStores not allowed");
       
  1560                     HBufC* localDataStoreName = dataProvider.DefaultDataStoreName().AllocLC();
       
  1561                     task.CreateL( iDSProfile, aDataProviderId, *iRdbDataStore, 
       
  1562                                     *localDataStoreName );
       
  1563                     task.UpdateL();
       
  1564                     CleanupStack::PopAndDestroy();  //localDataStoreName
       
  1565                     }
       
  1566                 iDSProfile.UpdateL();
       
  1567                 CleanupStack::PopAndDestroy( 6 ); //dataProviderArray, dataProvider, 
       
  1568                                                 //object, mimeType, ConvertTo8LC, 
       
  1569                                                 //task
       
  1570                 CloseDSProfile();
       
  1571                 _DBG_FILE("CNSmlDSSettingsAdapter::AddNewDataProviderL(): end KErrNone");
       
  1572                 return KErrNone;
       
  1573                 }
       
  1574             CleanupStack::PopAndDestroy( 2 ); //mimeType, ConvertTo8LC    
       
  1575             }
       
  1576         CleanupStack::PopAndDestroy(  ); //dataProvider
       
  1577         }
       
  1578     
       
  1579     CleanupStack::PopAndDestroy( 2 ); //dataProviderArray, object
       
  1580     CloseDSProfile();
       
  1581     _DBG_FILE("CNSmlDSSettingsAdapter::AddNewDataProviderL(): end KErrNotFound");
       
  1582     return KErrNotFound;
       
  1583 	}
       
  1584 
       
  1585 //------------------------------------------------------------------------------
       
  1586 //  CNSmlDSSettingsAdapter::GetToNAPIDL
       
  1587 //	The function gets URI for given aObject.
       
  1588 //------------------------------------------------------------------------------
       
  1589 TInt CNSmlDSSettingsAdapter::GetToNAPIDL( const TInt aLUID, CBufBase& aObject )
       
  1590 	{
       
  1591 	_DBG_FILE("CNSmlDSSettingsAdapter::GetToNAPIDL() : begin");
       
  1592 		
       
  1593     TInt profIAPid = -1;
       
  1594     TInt apIdResponse = GetProfileIAPIdL(aLUID, profIAPid);
       
  1595     if( profIAPid < 0 || apIdResponse != KErrNone )
       
  1596         {
       
  1597         return KErrNotFound;
       
  1598         }
       
  1599     CNSmlDMIAPMatcher* apmatch = CNSmlDMIAPMatcher::NewL( iCallBack );
       
  1600     CleanupStack::PushL( apmatch );
       
  1601     HBufC8* uri8 = apmatch->URIFromIAPIdL( profIAPid );
       
  1602     if( uri8 )
       
  1603         {
       
  1604         CleanupStack::PushL( uri8 );
       
  1605         aObject.InsertL(aObject.Size(),uri8->Des());
       
  1606         CleanupStack::PopAndDestroy(); // uri8
       
  1607         }
       
  1608     else
       
  1609         {
       
  1610         CleanupStack::PopAndDestroy(); // apMatch
       
  1611         return KErrGeneral;    
       
  1612         }
       
  1613     CleanupStack::PopAndDestroy(); // apMatch
       
  1614 	_DBG_FILE("CNSmlDSSettingsAdapter::GetToNAPIDL() : end");
       
  1615 	return KErrNone;
       
  1616 	}
       
  1617 
       
  1618 //------------------------------------------------------------------------------
       
  1619 //  CNSmlDSSettingsAdapter::SetToNAPIDL
       
  1620 //	The function sets NAPId value according given URI.
       
  1621 //------------------------------------------------------------------------------
       
  1622 TInt CNSmlDSSettingsAdapter::SetToNAPIDL( const TInt aLUID, const TDesC8& aObject )
       
  1623 	{
       
  1624 	_DBG_FILE("CNSmlDSSettingsAdapter::SetToNAPIDL() : begin");
       
  1625     CNSmlDMIAPMatcher* apmatch = CNSmlDMIAPMatcher::NewL( iCallBack );
       
  1626     CleanupStack::PushL( apmatch );
       
  1627     TInt lIAPid = apmatch->IAPIdFromURIL( aObject );
       
  1628     TInt apIdResponse = SetProfileIAPIdL( aLUID, lIAPid );
       
  1629 	CleanupStack::PopAndDestroy(); // apmatch
       
  1630     _DBG_FILE("CNSmlDSSettingsAdapter::SetToNAPIDL() : end");
       
  1631 	return apIdResponse;
       
  1632 	}
       
  1633 
       
  1634 //------------------------------------------------------------------------------
       
  1635 //  CNSmlDSSettingsAdapter::AddNodeBufferL
       
  1636 //	The function sets the new node to buffer.	
       
  1637 //------------------------------------------------------------------------------
       
  1638 void CNSmlDSSettingsAdapter::AddNodeBufferL( const TDesC8& aURI, 
       
  1639                                                 const TDesC8& aParentLUID,
       
  1640                                                 const TInt aStatusRef )
       
  1641 	{
       
  1642 	TNSmlDSBufferElement newNode;
       
  1643 	newNode.iMappingName = aURI.AllocLC();
       
  1644 	newNode.iName = LastURISeg(aURI).AllocLC(); 
       
  1645 	newNode.iNodeBuf = new (ELeave) CArrayFixFlat <TNSmlDSAddElement> ( KNSmlDSGranularity );
       
  1646 	newNode.iExecuted = EFalse;
       
  1647 	newNode.iLuid = GetIntObject( aParentLUID );
       
  1648 	iBuffer->AppendL( newNode );
       
  1649 	CleanupStack::Pop( 2 ); //newNode.iMappingName,newNode.iName
       
  1650 
       
  1651 	TNSmlDSAddElement newCommand;
       
  1652 
       
  1653 	newCommand.iUri = aURI.AllocLC();
       
  1654 	newCommand.iData = 0;
       
  1655 	newCommand.iStatusRef = aStatusRef;
       
  1656 	newCommand.iLeaf = EFalse;
       
  1657 	newCommand.iDone = EFalse;
       
  1658 
       
  1659 	TInt index = iBuffer->Count() - 1;
       
  1660 	iBuffer->At(index).iNodeBuf->AppendL( newCommand );
       
  1661 	CleanupStack::Pop(); //newCommand.iUri
       
  1662 	}
       
  1663 
       
  1664 //------------------------------------------------------------------------------
       
  1665 //  CNSmlDSSettingsAdapter::AddLeafBufferL
       
  1666 //  The function sets the new leaf to buffer.
       
  1667 //------------------------------------------------------------------------------
       
  1668 void CNSmlDSSettingsAdapter::AddLeafBufferL( const TDesC8& aURI, 
       
  1669                                                 const TDesC8& aParentLUID, 
       
  1670                                                 const TDesC8& aObject, 
       
  1671                                                 const TInt aStatusRef )
       
  1672 	{
       
  1673     TInt index = GetBufferIndex( aURI );
       
  1674     if(index<0)
       
  1675 		{
       
  1676 		DBG_ARGS(_S16("DS-adapter:AddLeafBufferL URI - <%S> <%S> NOTFOUND"), &aURI, &aParentLUID );
       
  1677 		iCallBack->SetStatusL(aStatusRef,  CSmlDmAdapter::ENotFound);
       
  1678 		return;
       
  1679         }
       
  1680 
       
  1681 	TNSmlDSAddElement newCommand;
       
  1682 	newCommand.iUri = aURI.AllocLC();
       
  1683 	newCommand.iData = aObject.AllocLC();
       
  1684 	newCommand.iStatusRef = aStatusRef;
       
  1685 	newCommand.iLeaf = ETrue;
       
  1686 	newCommand.iDone = EFalse;
       
  1687     iBuffer->At(index).iNodeBuf->AppendL( newCommand );
       
  1688 	CleanupStack::Pop( 2 ); //newCommand.iUri, newCommand.iData
       
  1689     }
       
  1690 
       
  1691 //------------------------------------------------------------------------------
       
  1692 //  CNSmlDSSettingsAdapter::LastURISeg
       
  1693 //  The function returns only the last uri segment.
       
  1694 //------------------------------------------------------------------------------
       
  1695 TPtrC8 CNSmlDSSettingsAdapter::LastURISeg(const TDesC8& aURI)
       
  1696 	{
       
  1697 	TInt i;
       
  1698 	for( i=aURI.Length() - 1; i >= 0; i-- )
       
  1699 		{
       
  1700 		if( aURI[i] == KNSmlDMUriSeparator )
       
  1701 			{
       
  1702 			break;
       
  1703 			}
       
  1704 		}
       
  1705 	if( i == 0 )
       
  1706 		{
       
  1707 		return aURI;
       
  1708 		}
       
  1709 	else
       
  1710 		{
       
  1711 		return aURI.Mid( i + 1 );
       
  1712 		}
       
  1713 	}
       
  1714 
       
  1715 //------------------------------------------------------------------------------
       
  1716 //  CNSmlDSSettingsAdapter::RemoveLastURISeg
       
  1717 //  The function removes the last URI segment.
       
  1718 //------------------------------------------------------------------------------
       
  1719 TPtrC8 CNSmlDSSettingsAdapter::RemoveLastURISeg( const TDesC8& aURI )
       
  1720 	{
       
  1721 	TInt i;
       
  1722 	for( i = aURI.Length() - 1; i >= 0; i-- )
       
  1723 		{
       
  1724 		if( aURI[i] == KNSmlDMUriSeparator )
       
  1725 			{
       
  1726 			break;
       
  1727 			}
       
  1728 		}
       
  1729 	if( i == 0 )
       
  1730 		{
       
  1731 		return aURI;
       
  1732 		}
       
  1733 	else
       
  1734 		{
       
  1735 		return aURI.Left( i );
       
  1736 		}
       
  1737 	}
       
  1738 
       
  1739 //------------------------------------------------------------------------------
       
  1740 //  CNSmlDSSettingsAdapter::ExecuteBufferL
       
  1741 //  Executes commands which have not been executed.
       
  1742 //------------------------------------------------------------------------------
       
  1743 void CNSmlDSSettingsAdapter::ExecuteBufferL( const TDesC8& aURI )
       
  1744 	{
       
  1745 	TInt index = GetBufferIndex( aURI );
       
  1746 	if( index < 0 )
       
  1747 		{
       
  1748 		return;
       
  1749 		}
       
  1750 	//
       
  1751 	// Execute all commands for Profiles new ContentType
       
  1752 	//
       
  1753     TBool rdburinotfound = ETrue;
       
  1754     TInt newcmd = 1;
       
  1755     
       
  1756     TNSmlDSBufferElement& bufElem = iBuffer->At(index); 
       
  1757     
       
  1758 	for( TInt cmd = bufElem.iNodeBuf->Count() - 1; cmd >= 0; cmd-- )
       
  1759 		{
       
  1760 		TBuf8<16> addLUID;
       
  1761 		
       
  1762 		TNSmlDSAddElement& addElem = bufElem.iNodeBuf->At(cmd); 
       
  1763 			
       
  1764 		if( cmd == 0 )
       
  1765 			{
       
  1766 			if( bufElem.iLuid > 0 )
       
  1767 			    {
       
  1768 			    addLUID.Format( KFormat, -1 ); // Set status for addnode command
       
  1769 			    }
       
  1770 			else
       
  1771                 {
       
  1772                 addLUID.Format( KFormat, 0 );
       
  1773                 }
       
  1774             iBufferExecution = ETrue;
       
  1775             AddNodeObjectL( addElem.iUri->Des(), 
       
  1776                             addLUID, addElem.iStatusRef );
       
  1777 
       
  1778 			bufElem.iExecuted = ETrue;
       
  1779             iBufferExecution = EFalse;
       
  1780             }
       
  1781 		else 
       
  1782 			{
       
  1783             //First RDBURI leaf must be stored
       
  1784             while( rdburinotfound && newcmd < iBuffer->At(index).iNodeBuf->Count() )
       
  1785     			{
       
  1786 	    		if( bufElem.iNodeBuf->At(newcmd).iUri->Des().Find( KNSmlDdfRDBURI ) >= 0 )
       
  1787 				    {
       
  1788                     SetRDBDataStore( bufElem.iNodeBuf->At(newcmd).iData->Des() );
       
  1789 				    rdburinotfound = EFalse;
       
  1790 				    break;
       
  1791 				    }
       
  1792 			    newcmd++;
       
  1793 			    }//while
       
  1794 			addLUID.Format( KFormat, bufElem.iLuid );
       
  1795 			iBufferExecution = ETrue;
       
  1796             UpdateLeafObjectL( addElem.iUri->Des(),
       
  1797 				addLUID,
       
  1798 				addElem.iData->Des(),
       
  1799 				KNullDesC8,
       
  1800 				addElem.iStatusRef );
       
  1801             iBufferExecution = EFalse;
       
  1802 			}
       
  1803 
       
  1804 		addElem.iDone = ETrue;
       
  1805 
       
  1806 		delete addElem.iUri;
       
  1807 		addElem.iUri=NULL;
       
  1808 		if( addElem.iData )
       
  1809 			{
       
  1810 			delete addElem.iData;
       
  1811 			addElem.iData=NULL;
       
  1812 			}
       
  1813 		bufElem.iNodeBuf->Delete(cmd);
       
  1814 		}
       
  1815 //
       
  1816 //	Remove data from handled ContentType-commands
       
  1817 //
       
  1818 	bufElem.iNodeBuf->Reset();
       
  1819 	delete bufElem.iNodeBuf;
       
  1820 
       
  1821 	if( bufElem.iMappingName )
       
  1822 		{
       
  1823 		delete bufElem.iMappingName;
       
  1824 		bufElem.iMappingName=NULL;
       
  1825 		}
       
  1826 
       
  1827 	if( bufElem.iName )
       
  1828 		{
       
  1829 		delete bufElem.iName;
       
  1830 		bufElem.iName=NULL;
       
  1831 		}
       
  1832 
       
  1833 	iBuffer->Delete( index ); 
       
  1834 	iBuffer->Compress();
       
  1835 	}
       
  1836 
       
  1837 
       
  1838 //------------------------------------------------------------------------------
       
  1839 //  CNSmlDSSettingsAdapter::GetProfileIdFromURIL
       
  1840 //	The function gets the Profile Id for given aURI.
       
  1841 //------------------------------------------------------------------------------
       
  1842 TInt CNSmlDSSettingsAdapter::GetProfileIdFromURIL( const TDesC8& aURI )
       
  1843 	{
       
  1844 	HBufC8* apURI = HBufC8::NewLC( aURI.Size() );
       
  1845 //
       
  1846 //  Second slash after SyncML/DSAcc/XXXX/
       
  1847 //
       
  1848 	TInt i = 0;
       
  1849 	
       
  1850 	for( i = aURI.Find( KDSAcc1 ) + 13; i < aURI.Length(); i++ )
       
  1851 		{
       
  1852 		if( aURI[i] == KNSmlDMUriSeparator )
       
  1853 			{
       
  1854 			break;
       
  1855 			}
       
  1856 		}
       
  1857 	if( i > 0 )
       
  1858 		{
       
  1859 		apURI->Des().Format( aURI.Left(i) );
       
  1860 		}
       
  1861 //
       
  1862 //	Same profile as previous
       
  1863 //
       
  1864 	if( iPrevURI->Match( *apURI ) != KErrNotFound )
       
  1865 		{
       
  1866 		CleanupStack::PopAndDestroy(); // apURI
       
  1867 		return iPrevLUID;
       
  1868 		}
       
  1869 //
       
  1870 //	Fetch Profile-id for URI
       
  1871 //
       
  1872 
       
  1873     HBufC8* apLUID = iCallBack->GetLuidAllocL( *apURI );
       
  1874 	CleanupStack::PushL( apLUID );
       
  1875     if( apLUID->Length() == 0 )
       
  1876         {
       
  1877         CleanupStack::PopAndDestroy( 2 );//apURI, apLUID
       
  1878         return KErrGeneral;
       
  1879         }
       
  1880 	TInt resLUID = GetIntObject( *apLUID );
       
  1881 	iPrevURI->Des().Format( *apURI );
       
  1882 	iPrevLUID = resLUID;
       
  1883 	CleanupStack::PopAndDestroy(2); //apURI,apLUID
       
  1884 
       
  1885 	return resLUID;
       
  1886 	}
       
  1887 
       
  1888 //------------------------------------------------------------------------------
       
  1889 //  CNSmlDSSettingsAdapter::GetContentTypeL
       
  1890 //  Get CTType (MimeType) for given adapter.
       
  1891 //------------------------------------------------------------------------------
       
  1892 TInt CNSmlDSSettingsAdapter::GetContentTypeL( const TInt aDataProviderId, 
       
  1893                                               const TInt aProfileLUID, 
       
  1894                                               CBufBase*& aObject )
       
  1895 	{
       
  1896     _DBG_FILE("CNSmlDSSettingsAdapter::GetContentTypeL(): begin");
       
  1897     TInt retVal = OpenSyncSessionAndDSProfileL( aProfileLUID, ESmlOpenRead );
       
  1898     if( retVal != KErrNone )
       
  1899 		{
       
  1900         CloseDSProfile();
       
  1901 		return retVal;
       
  1902 		}
       
  1903 
       
  1904     RArray<TSmlDataProviderId> dataProviderIdArray;
       
  1905     CleanupClosePushL( dataProviderIdArray );
       
  1906     iSyncSession.ListDataProvidersL( dataProviderIdArray );
       
  1907     
       
  1908     TInt dpIndex = dataProviderIdArray.Find( aDataProviderId );
       
  1909     if( dpIndex == KErrNotFound )
       
  1910         {
       
  1911         CloseDSProfile();
       
  1912         CleanupStack::PopAndDestroy( 1 ); // dataProviderIdArray
       
  1913         return KErrNotFound;
       
  1914         }
       
  1915     RSyncMLDataProvider dataProvider;
       
  1916     CleanupClosePushL( dataProvider );
       
  1917     dataProvider.OpenL( iSyncSession, dataProviderIdArray[dpIndex] );
       
  1918     for( TInt i = 0; i < dataProvider.MimeTypeCount(); i++ )
       
  1919         {
       
  1920         //first mime type will be returned now
       
  1921         HBufC* mimeType = dataProvider.MimeType(i).AllocLC();
       
  1922         aObject->InsertL( aObject->Size(), ConvertTo8LC( *mimeType ) );  
       
  1923         CleanupStack::PopAndDestroy( 2 ); //mimeType, ConvertTo8LC
       
  1924         break;
       
  1925         }
       
  1926     CleanupStack::PopAndDestroy( 2 ); // dataProviderIdArray, dataProvider
       
  1927     CloseDSProfile();
       
  1928     _DBG_FILE("CNSmlDSSettingsAdapter::GetContentTypeL(): end");
       
  1929     return KErrNone;
       
  1930 	}
       
  1931 
       
  1932 //------------------------------------------------------------------------------
       
  1933 //  CNSmlDSSettingsAdapter::GetBufferIndex
       
  1934 //  The function resolves buffer index for given URI.
       
  1935 //------------------------------------------------------------------------------
       
  1936 TInt CNSmlDSSettingsAdapter::GetBufferIndex( const TDesC8& aURI )
       
  1937 	{
       
  1938 	TInt index = -1;
       
  1939 	for( TInt i = 0; i<iBuffer->Count(); i++ )
       
  1940 		{
       
  1941 		TPtrC8 parentUri = RemoveLastURISeg( aURI );
       
  1942 		if( iBuffer->At(i).iMappingName->Compare( parentUri ) == 0 )
       
  1943 			{
       
  1944 			index = i;
       
  1945 			break;
       
  1946 			}
       
  1947 		}
       
  1948 	return index;
       
  1949 	}
       
  1950 
       
  1951 //------------------------------------------------------------------------------
       
  1952 //  CNSmlDSSettingsAdapter::SetBufferLUID
       
  1953 //  The function sets the LUID to buffer for given URI.
       
  1954 //------------------------------------------------------------------------------
       
  1955 TInt CNSmlDSSettingsAdapter::SetBufferLUID( const TDesC8& aURI, const TInt aLUID )
       
  1956 	{
       
  1957 	TInt index = GetBufferIndex( aURI );
       
  1958 	if( index < 0 )
       
  1959 		{
       
  1960 		return 0;
       
  1961 		}
       
  1962 	iBuffer->At(index).iLuid = aLUID;
       
  1963 	return 1;
       
  1964 	}
       
  1965 
       
  1966 //------------------------------------------------------------------------------
       
  1967 //  CNSmlDSSettingsAdapter::ParseUri
       
  1968 //  Resolves portnbr (separated with ':') as integer from URI.
       
  1969 //------------------------------------------------------------------------------
       
  1970 TInt CNSmlDSSettingsAdapter::ParseUri( const TDesC8& aRealURI, TInt& aPort )
       
  1971 	{
       
  1972     TInt offset=0;
       
  1973     //http:
       
  1974 	if( aRealURI.Find( KNSmlDSSettingsHTTP )==0 )//http:
       
  1975 		{
       
  1976 		offset = KNSmlDSSettingsHTTP().Length();
       
  1977 		}
       
  1978 	else if( aRealURI.Find( KNSmlDSSettingsHTTPS )==0 )//https:
       
  1979 		{
       
  1980 		offset = KNSmlDSSettingsHTTPS().Length();
       
  1981 		}
       
  1982 
       
  1983 	TBool portFound=EFalse;
       
  1984 	TBool portExtracted = EFalse;
       
  1985     ////123.234.345.456:80/syncml
       
  1986 	for( TInt i = offset; i < aRealURI.Length() && !portExtracted; i++ )
       
  1987 		{
       
  1988 		if( aRealURI[i] == KNSmlDMColon )// ':'
       
  1989 			{
       
  1990 			portFound = ETrue;
       
  1991 			offset=i;
       
  1992 			}
       
  1993 		if( portFound && aRealURI[i] == KNSmlDMUriSeparator )// '/'
       
  1994 			{
       
  1995 			aPort = GetIntObject( aRealURI.Mid( (offset + 1), (i - offset-1) ) );
       
  1996 			portExtracted = ETrue;
       
  1997 			}
       
  1998 		else if ( portFound && i == aRealURI.Length() - 1 ) // last char
       
  1999 		    {
       
  2000 		    // port is from offset to the end
       
  2001 		    aPort = GetIntObject( aRealURI.Right( aRealURI.Length() - offset - 1 ) );
       
  2002 			portExtracted = ETrue;
       
  2003 		    }
       
  2004 		}
       
  2005 	
       
  2006 	if( aPort != 0 )
       
  2007 		{
       
  2008 		return KErrNone;
       
  2009 		}
       
  2010 	else
       
  2011 		{
       
  2012 		return KErrNotFound;
       
  2013 		}
       
  2014 	}
       
  2015 
       
  2016 //------------------------------------------------------------------------------
       
  2017 //  CNSmlDSSettingsAdapter::FindProfileIdL
       
  2018 //  The function checkd if profile can be found.
       
  2019 //------------------------------------------------------------------------------
       
  2020 TBool CNSmlDSSettingsAdapter::FindProfileIdL( const TInt aIntLUID )
       
  2021 	{
       
  2022 	if( iSyncSessionOpen == EFalse )
       
  2023 	    {
       
  2024         iSyncSession.OpenL();
       
  2025         iSyncSessionOpen = ETrue;
       
  2026 	    }
       
  2027     RArray <TSmlProfileId> profileList;
       
  2028     CleanupClosePushL( profileList );
       
  2029 	TSmlUsageType usageType = ESmlDataSync;		
       
  2030 	iSyncSession.ListProfilesL( profileList, usageType );
       
  2031 	if( profileList.Count() == 0 )
       
  2032 	    {
       
  2033         CleanupStack::PopAndDestroy(); //profileList
       
  2034         return EFalse;
       
  2035 	    }
       
  2036     TInt item = profileList.Find( aIntLUID );
       
  2037     CleanupStack::PopAndDestroy(); //profileList
       
  2038     if( item != KErrNotFound )
       
  2039 		{
       
  2040 		return ETrue;
       
  2041 		}
       
  2042 	return EFalse;
       
  2043 	}
       
  2044 
       
  2045 //------------------------------------------------------------------------------
       
  2046 //  CNSmlDSSettingsAdapter::GetProfileIdentifierL
       
  2047 //  The function gets profile Id from Client API.
       
  2048 //------------------------------------------------------------------------------
       
  2049 TInt CNSmlDSSettingsAdapter::GetProfileIdentifierL( const TInt aIntLUID, 
       
  2050                                                     TInt& aProfileID )
       
  2051 	{
       
  2052 	TInt retVal = OpenSyncSessionAndDSProfileL( aIntLUID, ESmlOpenRead );
       
  2053     if( retVal != KErrNone )
       
  2054 		{
       
  2055         CloseDSProfile();
       
  2056 		return retVal;	
       
  2057 		}
       
  2058 	aProfileID = iDSProfile.Identifier();
       
  2059 	CloseDSProfile();
       
  2060     return retVal;
       
  2061 	}
       
  2062 //------------------------------------------------------------------------------
       
  2063 //  CNSmlDSSettingsAdapter::GetDSFieldDataL
       
  2064 //  The function checks what leaf to be handled and fetches the data for a leaf.
       
  2065 //------------------------------------------------------------------------------
       
  2066 TInt CNSmlDSSettingsAdapter::GetDSFieldDataL( const TInt aIntLUID, 
       
  2067                                                 CBufBase*& aObject )
       
  2068 	{
       
  2069 	_DBG_FILE("CNSmlDSSettingsAdapter::GetDSFieldData(): begin");
       
  2070     
       
  2071 	if ( iField->Compare( KNSmlDdfAddrType ) == 0 )
       
  2072 		{
       
  2073         TSmlTransportId connType = -1;
       
  2074 		connType = GetProfileConnectiontypeL( aIntLUID );
       
  2075         if ( connType <= 0 )
       
  2076 			{
       
  2077             return KErrNotFound;
       
  2078 			}
       
  2079 		aObject->InsertL( aObject->Size(), SetIntObjectLC( connType ) );
       
  2080 		CleanupStack::PopAndDestroy();//SetIntObjectLC
       
  2081         return KErrNone;
       
  2082 		}
       
  2083 	else if ( iField->Compare( KNSmlDdfAddr ) == 0 ) //Server URL
       
  2084 		{
       
  2085 		TInt retValue1 = GetProfileServerURLL( aIntLUID, aObject );
       
  2086 		TInt port(0);
       
  2087 		if(ParseUri(aObject->Ptr(0),port)==KErrNone)
       
  2088 		    {
       
  2089 		    HBufC8* addr = aObject->Ptr(0).AllocLC();
       
  2090 		    aObject->Reset();
       
  2091 		    TInt portStart = addr->LocateReverse(KNSmlDMColon);		    
       
  2092 		    aObject->InsertL(aObject->Size(),addr->Left(portStart));
       
  2093 		    
       
  2094 		    TInt portLen=addr->Mid(portStart).Locate(KNSmlDMUriSeparator);
       
  2095 		    if(portLen!=KErrNotFound)
       
  2096 		        {
       
  2097 		        aObject->InsertL(aObject->Size(),addr->Mid(portStart+portLen));
       
  2098 		        }
       
  2099 		    	    			    
       
  2100 		    CleanupStack::PopAndDestroy(); //addr
       
  2101 		    }
       
  2102 
       
  2103         if( retValue1 != KErrNone )
       
  2104 		    {
       
  2105 		    return KErrNotFound;
       
  2106 		    }
       
  2107 		return KErrNone;
       
  2108 		}
       
  2109 	else if ( iField->Compare( KNSmlDdfPortNbr ) == 0 )
       
  2110 		{
       
  2111 		TInt retValue2 = GetProfileServerURLL( aIntLUID, aObject );
       
  2112         if( retValue2 != KErrNone )
       
  2113 		    {
       
  2114 		    return KErrNotFound;
       
  2115             }
       
  2116         if ( aObject->Size() == 0 )
       
  2117             {
       
  2118             return KErrNone;
       
  2119             }
       
  2120         TInt bSize = aObject->Size();
       
  2121         HBufC8* buf = HBufC8::NewLC( bSize );
       
  2122 		TPtr8 bufPtr = buf->Des();
       
  2123 		aObject->Read( 0, bufPtr, aObject->Size() );
       
  2124 		aObject->Reset();
       
  2125 		
       
  2126         TInt pnum = 0;
       
  2127 		//find out the port number
       
  2128         ParseUri( *buf, pnum );
       
  2129         if(pnum)
       
  2130             {
       
  2131     		aObject->InsertL( aObject->Size(), SetIntObjectLC( pnum ) );
       
  2132             CleanupStack::PopAndDestroy(  ); //SetIntObjectLC( pnum )
       
  2133             }
       
  2134         CleanupStack::PopAndDestroy(  ); //buf
       
  2135         return KErrNone;
       
  2136 		}
       
  2137 	else if ( iField->Compare( KNSmlDdfClientUserName ) == 0 )
       
  2138 		{
       
  2139 		if( GetProfileUserNameL( aIntLUID, aObject ) != KErrNone )
       
  2140             {
       
  2141             return KErrGeneral;
       
  2142             }
       
  2143 		return KErrNone;
       
  2144 		}
       
  2145 	else if ( iField->Compare( KNSmlDdfServerId ) == 0 )
       
  2146 		{
       
  2147 		if( GetProfileServerIdL( aIntLUID, aObject ) != KErrNone )
       
  2148             {
       
  2149             return KErrGeneral;
       
  2150             }
       
  2151 		return KErrNone;
       
  2152 		}
       
  2153 	else if ( iField->Compare( KNSmlDdfClientPW ) == 0 ) //Not allowed
       
  2154 		{
       
  2155 		return KErrGeneral;
       
  2156         }
       
  2157 	else if ( iField->Compare( KNSmlDdfName ) == 0 )
       
  2158 		{
       
  2159 		TInt retValue = GetProfileDisplayNameL( aIntLUID, aObject );
       
  2160 		if( retValue != KErrNone )
       
  2161 		    {
       
  2162             return KErrGeneral;
       
  2163 		    }
       
  2164 		return KErrNone;
       
  2165 		}
       
  2166 	else if ( iField->Compare( KNSmlDdfToNAPID ) == 0 )
       
  2167 		{
       
  2168 		TInt retToNaPID = GetToNAPIDL( aIntLUID, *aObject );
       
  2169 		if ( retToNaPID == KErrNone || retToNaPID == KErrNotFound )
       
  2170 			{
       
  2171 			return retToNaPID;
       
  2172 			}
       
  2173 		return KErrGeneral;			
       
  2174 		}
       
  2175 	else if ( iField->Compare( KNSmlDdfHidden ) == 0 )
       
  2176 		{
       
  2177 		//Hidden profile not supported
       
  2178 		return KErrGeneral;
       
  2179 		}
       
  2180     _DBG_FILE("CNSmlDSSettingsAdapter::GetDSFieldData(): end");
       
  2181     return KErrGeneral;
       
  2182 	}
       
  2183 
       
  2184 //------------------------------------------------------------------------------
       
  2185 //  CNSmlDSSettingsAdapter::GetProfileConnectiontypeL()
       
  2186 //  The function what medium type is supported and returns it.
       
  2187 //------------------------------------------------------------------------------
       
  2188 TInt CNSmlDSSettingsAdapter::GetProfileConnectiontypeL( const TInt aIntLUID )
       
  2189 	{
       
  2190 	TInt retVal = OpenSyncSessionAndDSProfileL( aIntLUID, ESmlOpenRead );
       
  2191     if( retVal != KErrNone )
       
  2192 		{
       
  2193         CloseDSProfile();
       
  2194 		return retVal;	
       
  2195 		}
       
  2196 	RArray<TSmlTransportId> transportIdArray;
       
  2197     CleanupClosePushL( transportIdArray );
       
  2198 	iDSProfile.ListConnectionsL( transportIdArray );
       
  2199 	TInt transportItems = transportIdArray.Count();
       
  2200     if( transportItems == 0 )
       
  2201 		{
       
  2202 		//No matching items
       
  2203         CleanupStack::PopAndDestroy(); //transportIdArray	
       
  2204 		CloseDSProfile();
       
  2205 		return KErrGeneral;
       
  2206 		}
       
  2207 	else if( transportItems > 1 )
       
  2208 		{
       
  2209 		//Error case : against specification
       
  2210         CleanupStack::PopAndDestroy(); //transportIdArray	
       
  2211 		CloseDSProfile();
       
  2212 		return KErrGeneral;
       
  2213 		}
       
  2214 	
       
  2215     TInt mediumType = ENone;	
       
  2216     if ( transportIdArray[0] == KUidNSmlMediumTypeInternet.iUid )
       
  2217         {
       
  2218         mediumType = EHttp;
       
  2219         }
       
  2220     else if ( transportIdArray[0] == KUidNSmlMediumTypeBluetooth.iUid ||
       
  2221               transportIdArray[0] == KUidNSmlMediumTypeUSB.iUid ||   
       
  2222               transportIdArray[0] == KUidNSmlMediumTypeIrDA.iUid  )
       
  2223         {
       
  2224         mediumType = EObex;
       
  2225         }
       
  2226     
       
  2227     CleanupStack::PopAndDestroy(); //transportIdArray
       
  2228 	CloseDSProfile();
       
  2229 	return mediumType;
       
  2230 	}
       
  2231 
       
  2232 //------------------------------------------------------------------------------
       
  2233 //  CNSmlDSSettingsAdapter::GetProfileServerURLL
       
  2234 //  The function gets the profile Addr leaf value.
       
  2235 //------------------------------------------------------------------------------
       
  2236 TInt CNSmlDSSettingsAdapter::GetProfileServerURLL( const TInt aIntLUID, 
       
  2237                                                     CBufBase*& aURL )
       
  2238 	{
       
  2239 	TInt retVal = OpenSyncSessionAndDSProfileL( aIntLUID, ESmlOpenRead );
       
  2240     if( retVal != KErrNone )
       
  2241 		{
       
  2242         CloseDSProfile();
       
  2243 		return retVal;	
       
  2244 		}
       
  2245 	RArray<TSmlTransportId> transportIdArray;
       
  2246     CleanupClosePushL( transportIdArray );
       
  2247 	iDSProfile.ListConnectionsL( transportIdArray );
       
  2248     if( transportIdArray.Count() > 0 )
       
  2249         {
       
  2250         RSyncMLConnection profConn;
       
  2251         CleanupClosePushL( profConn );
       
  2252 	    profConn.OpenL( iDSProfile, transportIdArray[0] );
       
  2253 
       
  2254 	    HBufC8* sURI = profConn.ServerURI().AllocL();
       
  2255         CleanupStack::PushL( sURI );
       
  2256         TPtr8 uriPtr = sURI->Des();
       
  2257         if( uriPtr.Length() > 0 )
       
  2258             {
       
  2259             aURL->InsertL( aURL->Size(),uriPtr );
       
  2260             }
       
  2261         else
       
  2262             {
       
  2263             aURL->InsertL( aURL->Size(), KNullDesC8 );
       
  2264             }
       
  2265         CleanupStack::PopAndDestroy( 2 );//profConn, sURI
       
  2266         retVal = KErrNone;
       
  2267         }
       
  2268     else
       
  2269         {
       
  2270         retVal = KErrNotFound;
       
  2271         }
       
  2272     CleanupStack::PopAndDestroy(); //transportIdArray
       
  2273     CloseDSProfile();
       
  2274     return retVal;
       
  2275 	}
       
  2276 //------------------------------------------------------------------------------
       
  2277 //  CNSmlDSSettingsAdapter::GetProfileUserNameL
       
  2278 //  The function gets the ClientUserName leaf value.
       
  2279 //------------------------------------------------------------------------------
       
  2280 TInt CNSmlDSSettingsAdapter::GetProfileUserNameL( const TInt aIntLUID, 
       
  2281                                                     CBufBase*& aUserName )
       
  2282 	{
       
  2283 	TInt retVal = OpenSyncSessionAndDSProfileL( aIntLUID, ESmlOpenRead );
       
  2284     if( retVal != KErrNone )
       
  2285 		{
       
  2286         CloseDSProfile();
       
  2287 		return retVal;	
       
  2288 		}
       
  2289 	HBufC8* userName = iDSProfile.UserName().AllocL();
       
  2290     CleanupStack::PushL( userName );
       
  2291     TPtr8 ptrUserName = userName->Des();
       
  2292     CloseDSProfile();
       
  2293     aUserName->InsertL( aUserName->Size(), ptrUserName );
       
  2294     CleanupStack::PopAndDestroy(); //userName
       
  2295     return KErrNone;
       
  2296 	}
       
  2297 	
       
  2298 //------------------------------------------------------------------------------
       
  2299 //  CNSmlDSSettingsAdapter::GetProfileServerIdL
       
  2300 //  The function gets the ClientUserName leaf value.
       
  2301 //------------------------------------------------------------------------------
       
  2302 TInt CNSmlDSSettingsAdapter::GetProfileServerIdL( const TInt aIntLUID, 
       
  2303                                                     CBufBase*& aUserName )
       
  2304 	{
       
  2305 	TInt retVal = OpenSyncSessionAndDSProfileL( aIntLUID, ESmlOpenRead );
       
  2306     if( retVal != KErrNone )
       
  2307 		{
       
  2308         CloseDSProfile();
       
  2309 		return retVal;	
       
  2310 		}
       
  2311     aUserName->InsertL( aUserName->Size(), iDSProfile.ServerId() );
       
  2312     CloseDSProfile();
       
  2313     return KErrNone;
       
  2314 	}
       
  2315 	
       
  2316 //------------------------------------------------------------------------------
       
  2317 //  CNSmlDSSettingsAdapter::GetProfileIAPIdL
       
  2318 //  The function gets the IAP id value from Client API.
       
  2319 //------------------------------------------------------------------------------
       
  2320 TInt CNSmlDSSettingsAdapter::GetProfileIAPIdL( const TInt aIntLUID, TInt& aIAPid )
       
  2321 	{
       
  2322     aIAPid = -1;
       
  2323     TInt retVal = OpenSyncSessionAndDSProfileL( aIntLUID, ESmlOpenRead );
       
  2324     if( retVal != KErrNone )
       
  2325 		{
       
  2326 		CloseDSProfile();
       
  2327         return retVal;	
       
  2328 		}
       
  2329     RArray<TSmlTransportId> connIdArray;
       
  2330     CleanupClosePushL( connIdArray );
       
  2331     iDSProfile.ListConnectionsL( connIdArray );
       
  2332     if( connIdArray.Count() == 1 )
       
  2333         {
       
  2334         RSyncMLTransport transport;
       
  2335         CleanupClosePushL( transport );
       
  2336 	    transport.OpenL( iSyncSession, connIdArray[0] );
       
  2337 	    const CSyncMLTransportPropertiesArray& props = transport.Properties();
       
  2338 	    TInt index = props.Find( KNSmlIAPId );
       
  2339         if( index > 0 )
       
  2340             {
       
  2341             RSyncMLConnection conn;
       
  2342             CleanupClosePushL( conn );
       
  2343 	        conn.OpenL( iDSProfile, connIdArray[0] );
       
  2344             HBufC8* iapId = conn.GetPropertyL( KNSmlIAPId ).AllocLC();
       
  2345             aIAPid = GetIntObject( *iapId );
       
  2346             CleanupStack::PopAndDestroy( 2 ); //conn, iapId
       
  2347             retVal = KErrNone;
       
  2348             }
       
  2349         else
       
  2350             {
       
  2351             retVal = KErrNotFound;
       
  2352             }
       
  2353         CleanupStack::PopAndDestroy(); //transport
       
  2354         CloseDSProfile();
       
  2355         }
       
  2356     else
       
  2357         {
       
  2358         retVal = KErrNotFound;
       
  2359         }
       
  2360     CleanupStack::PopAndDestroy(); //connIdArray
       
  2361     return retVal;
       
  2362     }
       
  2363 
       
  2364 //------------------------------------------------------------------------------
       
  2365 //  CNSmlDSSettingsAdapter::GetProfileDisplayNameL
       
  2366 //  The function gets the Name leaf value for a profile.
       
  2367 //------------------------------------------------------------------------------
       
  2368 TInt CNSmlDSSettingsAdapter::GetProfileDisplayNameL( const TInt aIntLUID, 
       
  2369                                                         CBufBase*& aDisplayName )
       
  2370 	{
       
  2371 	TInt retVal = OpenSyncSessionAndDSProfileL( aIntLUID, ESmlOpenRead );
       
  2372     if(retVal != KErrNone)
       
  2373 		{
       
  2374 		CloseDSProfile();
       
  2375         return retVal;	
       
  2376 		}
       
  2377 	HBufC* dataBuf = iDSProfile.DisplayName().AllocL();
       
  2378     CleanupStack::PushL( dataBuf );
       
  2379     TPtr16 ptrDisplayName = dataBuf->Des();
       
  2380     aDisplayName->InsertL( aDisplayName->Size(), ConvertTo8LC( ptrDisplayName ) );
       
  2381     CleanupStack::PopAndDestroy( 2 );//dataBuf, ConvertTo8LC
       
  2382     CloseDSProfile();
       
  2383     return KErrNone;
       
  2384 	}
       
  2385 
       
  2386 //------------------------------------------------------------------------------
       
  2387 //  CNSmlDSSettingsAdapter::CreateNewProfileL
       
  2388 //  The function creates new profile through Client API.
       
  2389 //------------------------------------------------------------------------------
       
  2390 TInt CNSmlDSSettingsAdapter::CreateNewProfileL( TInt& aPID )
       
  2391 	{
       
  2392     if( iSyncSessionOpen == EFalse )
       
  2393 	    {
       
  2394         iSyncSession.OpenL();
       
  2395         iSyncSessionOpen = ETrue;
       
  2396 	    }
       
  2397     TRAPD( trapValue1, iDSProfile.CreateL( iSyncSession ) );
       
  2398     if( trapValue1 != KErrNone )
       
  2399         {
       
  2400         return trapValue1;
       
  2401         }
       
  2402     //iDSProfile.SetProtocolVersionL(ESmlVersion1_1_2);
       
  2403     TRAPD( trapValue2, iDSProfile.UpdateL() );
       
  2404     if( trapValue2 != KErrNone )
       
  2405         {
       
  2406         return trapValue2;
       
  2407         }
       
  2408     aPID = iDSProfile.Identifier();
       
  2409    	
       
  2410 
       
  2411     CloseDSProfile();
       
  2412     return KErrNone;
       
  2413     }
       
  2414 
       
  2415 //------------------------------------------------------------------------------
       
  2416 //  CNSmlDSSettingsAdapter::SetProfileServerURIL
       
  2417 //  The function sets the Addr leaf value.
       
  2418 //------------------------------------------------------------------------------
       
  2419 TInt CNSmlDSSettingsAdapter::SetProfileServerURIL( const TInt aPID, 
       
  2420                                                     const TDesC8& aObj )
       
  2421 	{
       
  2422 	TInt retVal = OpenSyncSessionAndDSProfileL( aPID, ESmlOpenReadWrite );
       
  2423     if(retVal != KErrNone)
       
  2424 		{
       
  2425 		CloseDSProfile();
       
  2426         return retVal;	
       
  2427 		}
       
  2428 	RArray<TSmlTransportId> transportIdArray;
       
  2429     CleanupClosePushL( transportIdArray );
       
  2430 	iDSProfile.ListConnectionsL( transportIdArray );
       
  2431 	if( transportIdArray.Count() == 0 )
       
  2432 	    {
       
  2433         CleanupStack::PopAndDestroy();//transportIdArray
       
  2434         CloseDSProfile();
       
  2435         return KErrGeneral;
       
  2436 	    }
       
  2437 	    
       
  2438 	TInt newPort(0);
       
  2439 	
       
  2440 	RSyncMLConnection conn;
       
  2441     CleanupClosePushL( conn );
       
  2442     conn.OpenL( iDSProfile, transportIdArray[0] );
       
  2443     
       
  2444     if( transportIdArray[0] == KUidNSmlMediumTypeInternet.iUid )
       
  2445         {
       
  2446         if(ParseUri(aObj,newPort)==KErrNotFound)
       
  2447             {
       
  2448             TInt port(0);
       
  2449             ParseUri(conn.ServerURI(),port);
       
  2450             if(port==0)
       
  2451             	{
       
  2452             	// set default port
       
  2453             	if( aObj.Find( KNSmlDSSettingsHTTPS ) == 0 ) //https://
       
  2454             		{
       
  2455             		port = KNSmlDSSettingsHTTPSPort;
       
  2456             		}
       
  2457             	else //http://
       
  2458         	        {
       
  2459         	        port = KNSmlDSSettingsHTTPPort;
       
  2460         	        }
       
  2461             	}
       
  2462 
       
  2463            	TBuf8<5> buf;
       
  2464         	buf.Num( port );
       
  2465             	
       
  2466             TInt totalSize = aObj.Length() + buf.Length() + 1;
       
  2467             HBufC8* newServerURI = HBufC8::NewLC( totalSize );
       
  2468             SetPortNrToAddrStr( aObj, newServerURI, buf );
       
  2469 
       
  2470             conn.SetServerURIL( *newServerURI );
       
  2471         	conn.UpdateL();
       
  2472             CleanupStack::PopAndDestroy( newServerURI ); 
       
  2473             
       
  2474             }
       
  2475         else
       
  2476             {
       
  2477             conn.SetServerURIL( aObj );
       
  2478     	    conn.UpdateL();
       
  2479             }
       
  2480         }
       
  2481     else // medium type not internet, no port allowed
       
  2482         {
       
  2483         if(ParseUri(aObj,newPort)==KErrNotFound)
       
  2484             {
       
  2485             conn.SetServerURIL( aObj );
       
  2486     	    conn.UpdateL();
       
  2487             }
       
  2488         else
       
  2489             {
       
  2490             // remove port from uri
       
  2491             HBufC8* newServerURI = HBufC8::NewL( aObj.Length() );
       
  2492             CleanupStack::PushL( newServerURI );
       
  2493             TBuf8<5> buf;
       
  2494         	buf.Num( 0 );
       
  2495             // change iLeafType to EDSDelete -> deleting port
       
  2496             TNSmlDSLeafType	tmpType(iLeafType); // store current value
       
  2497             iLeafType = EDSDelete;
       
  2498             SetPortNrToAddrStr( aObj, newServerURI, buf );
       
  2499             iLeafType = tmpType; // restore original value
       
  2500             
       
  2501             conn.SetServerURIL( *newServerURI );
       
  2502             conn.UpdateL();
       
  2503             CleanupStack::PopAndDestroy( newServerURI );
       
  2504             }
       
  2505         }
       
  2506 
       
  2507      
       
  2508     iDSProfile.UpdateL();
       
  2509     CleanupStack::PopAndDestroy( 2 ); //transportIdArray, conn
       
  2510 	CloseDSProfile();
       
  2511 	return retVal;
       
  2512 	}
       
  2513 
       
  2514 //------------------------------------------------------------------------------
       
  2515 //  CNSmlDSSettingsAdapter::SetProfileDisplayNameL
       
  2516 //  The function sets the Name leaf value for a profile.
       
  2517 //------------------------------------------------------------------------------
       
  2518 TInt CNSmlDSSettingsAdapter::SetProfileDisplayNameL( const TInt aPID, 
       
  2519                                                         const TDesC8& aObj )
       
  2520 	{
       
  2521 	TInt retVal = OpenSyncSessionAndDSProfileL( aPID, ESmlOpenReadWrite );
       
  2522     if( retVal != KErrNone )
       
  2523 		{
       
  2524 		CloseDSProfile();
       
  2525         return retVal;
       
  2526 		}
       
  2527 	iDSProfile.SetDisplayNameL( ConvertTo16LC( aObj ) );
       
  2528 	iDSProfile.UpdateL();
       
  2529     CleanupStack::PopAndDestroy();//ConvertTo16LC
       
  2530 	CloseDSProfile();
       
  2531 	return retVal;
       
  2532 	}
       
  2533 //------------------------------------------------------------------------------
       
  2534 //  CNSmlDSSettingsAdapter::SetProfileUserNameL
       
  2535 //  The function sets the ClientUserName leaf value for a profile.
       
  2536 //------------------------------------------------------------------------------
       
  2537 TInt CNSmlDSSettingsAdapter::SetProfileUserNameL( const TInt aPID,  
       
  2538                                                     const TDesC8& aObj )
       
  2539 	{
       
  2540 	TInt retVal = OpenSyncSessionAndDSProfileL( aPID, ESmlOpenReadWrite );
       
  2541     if( retVal != KErrNone )
       
  2542 		{
       
  2543 		CloseDSProfile();
       
  2544         return retVal;	
       
  2545 		}
       
  2546 	iDSProfile.SetUserNameL( aObj );
       
  2547 	iDSProfile.UpdateL();
       
  2548 	CloseDSProfile();
       
  2549 	return retVal;
       
  2550 	}
       
  2551 //------------------------------------------------------------------------------
       
  2552 //  CNSmlDSSettingsAdapter::SetProfileServerIdL
       
  2553 //  The function sets the ClientUserName leaf value for a profile.
       
  2554 //------------------------------------------------------------------------------
       
  2555 TInt CNSmlDSSettingsAdapter::SetProfileServerIdL( const TInt aPID,  
       
  2556                                                     const TDesC8& aObj )
       
  2557 	{
       
  2558 	TInt retVal = OpenSyncSessionAndDSProfileL( aPID, ESmlOpenReadWrite );
       
  2559     if( retVal != KErrNone )
       
  2560 		{
       
  2561 		CloseDSProfile();
       
  2562         return retVal;	
       
  2563 		}
       
  2564 	iDSProfile.SetServerIdL( aObj );
       
  2565 	if(aObj.Length())
       
  2566 	    {
       
  2567     	iDSProfile.SetProtocolVersionL(ESmlVersion1_2);
       
  2568 	    }
       
  2569 	else
       
  2570 	    {
       
  2571     	iDSProfile.SetProtocolVersionL(ESmlVersion1_1_2);	    
       
  2572 	    }
       
  2573 	iDSProfile.UpdateL();
       
  2574 	CloseDSProfile();
       
  2575 	return retVal;
       
  2576 	}
       
  2577 //------------------------------------------------------------------------------
       
  2578 //  CNSmlDSSettingsAdapter::SetProfilePasswordL
       
  2579 //  The function sets the ClientPW leaf value for a profile.
       
  2580 //------------------------------------------------------------------------------
       
  2581 TInt CNSmlDSSettingsAdapter::SetProfilePasswordL( const TInt aPID, 
       
  2582                                                     const TDesC8& aObj )
       
  2583 	{
       
  2584 	TInt retVal = OpenSyncSessionAndDSProfileL( aPID, ESmlOpenReadWrite );
       
  2585     if( retVal != KErrNone )
       
  2586 		{
       
  2587 		CloseDSProfile();
       
  2588         return retVal;	
       
  2589 		}
       
  2590 	iDSProfile.SetPasswordL( aObj );
       
  2591 	iDSProfile.UpdateL();
       
  2592 	CloseDSProfile();
       
  2593 	return retVal;
       
  2594 	}
       
  2595 //------------------------------------------------------------------------------
       
  2596 //  CNSmlDSSettingsAdapter::SetProfileStrValueL
       
  2597 //  The function checks what leaf to be handles and calls the proper function to
       
  2598 //  set leaf data.
       
  2599 //------------------------------------------------------------------------------
       
  2600 TInt CNSmlDSSettingsAdapter::SetProfileStrValueL( const TInt aPID, 
       
  2601                                                     const TDesC8& aObj, 
       
  2602                                                     const TInt aFieldID )
       
  2603 	{
       
  2604 	TInt ret = 0;
       
  2605 	switch ( aFieldID )
       
  2606 		{
       
  2607 		case ( EProfileName ) :
       
  2608 			{
       
  2609 			ret = SetProfileDisplayNameL( aPID, aObj );
       
  2610 			}
       
  2611 		break;
       
  2612 		
       
  2613 		case ( EProfileSyncServerUsername ) :
       
  2614 			{
       
  2615 			ret = SetProfileUserNameL( aPID, aObj );
       
  2616 			}
       
  2617 		break;
       
  2618 
       
  2619 		case ( EProfileServerId ) :
       
  2620 			{
       
  2621 			ret = SetProfileServerIdL( aPID, aObj );
       
  2622 			}
       
  2623 		break;
       
  2624 
       
  2625 
       
  2626 		case ( EProfileSyncServerPassword ) :
       
  2627 			{
       
  2628 			ret = SetProfilePasswordL( aPID, aObj );
       
  2629 			}
       
  2630 		break;
       
  2631         case ( EProfileIAPId ) :
       
  2632 			{
       
  2633 			ret = SetToNAPIDL( aPID, aObj );
       
  2634 			}
       
  2635 		break;
       
  2636 		case ( EProfilePort ) :
       
  2637             {
       
  2638 			delete iPortBuf;
       
  2639 			iPortBuf = NULL;
       
  2640 			
       
  2641             // check that port is a valid integer
       
  2642             TLex8 lex( aObj );
       
  2643             TInt port = KErrNotFound;
       
  2644             TInt err = lex.Val( port );
       
  2645             
       
  2646             if ( err != KErrNone || !lex.Eos() )
       
  2647                 {
       
  2648                 ret = KErrArgument;
       
  2649                 }
       
  2650             else
       
  2651                 {
       
  2652     			TInt portval = GetIntObject(aObj);
       
  2653 			if(portval<0)
       
  2654 			{
       
  2655 				ret=KErrArgument;
       
  2656 			}
       
  2657 			else if(portval>65535)
       
  2658 			{
       
  2659 			    	ret=KErrOverflow;	
       
  2660 			}
       
  2661 			
       
  2662 			else
       
  2663 			{
       
  2664 			// save information of the port
       
  2665     			iPortBuf = aObj.AllocL();
       
  2666     			iPortBufLUID = aPID;
       
  2667     			SetProfileConnectionPortNrL( iPortBufLUID, *iPortBuf );
       
  2668 			}
       
  2669                 }
       
  2670             }
       
  2671         break;
       
  2672         case ( EProfileURL ) :
       
  2673 		case ( EHiddenProfile ) :
       
  2674 		case ( EProfileMediumType ) :
       
  2675 		default:
       
  2676 			{
       
  2677 			User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound );
       
  2678 			}
       
  2679 		}
       
  2680 	return ret;
       
  2681 	}
       
  2682 //------------------------------------------------------------------------------
       
  2683 //  CNSmlDSSettingsAdapter::DeleteProfileL
       
  2684 //  The function deletes profile data content.
       
  2685 //------------------------------------------------------------------------------
       
  2686 TInt CNSmlDSSettingsAdapter::DeleteProfileL( const TInt aPID )
       
  2687 	{
       
  2688 	TInt retVal = OpenSyncSessionAndDSProfileL( aPID, ESmlOpenReadWrite );
       
  2689     if( retVal != KErrNone )
       
  2690 		{
       
  2691 		CloseDSProfile();
       
  2692         return KErrGeneral;	
       
  2693 		}
       
  2694     RArray<TSmlTaskId> taskIdArray;
       
  2695     CleanupClosePushL( taskIdArray );
       
  2696     iDSProfile.ListTasksL( taskIdArray );
       
  2697     if( taskIdArray.Count() > 0 )
       
  2698         {
       
  2699         for ( TInt i = 0; i < taskIdArray.Count(); i++ )
       
  2700             {
       
  2701             iDSProfile.DeleteTaskL( taskIdArray[i] );
       
  2702             iDSProfile.UpdateL();
       
  2703             }
       
  2704         }
       
  2705     CloseDSProfile();
       
  2706     RArray<TSmlProfileId> profileIdArray;
       
  2707     CleanupClosePushL( profileIdArray );
       
  2708     TSmlUsageType usageType = ESmlDataSync;
       
  2709     iSyncSession.ListProfilesL( profileIdArray, usageType );
       
  2710     TInt index = profileIdArray.Find( aPID );
       
  2711     iSyncSession.DeleteProfileL( profileIdArray[index] );
       
  2712     CleanupStack::PopAndDestroy( 2 ); //profileIdArray, taskIdArray
       
  2713     iSyncSession.Close();
       
  2714     iSyncSessionOpen = EFalse;
       
  2715     return KErrNone;
       
  2716 	}
       
  2717 
       
  2718 //------------------------------------------------------------------------------
       
  2719 //  CNSmlDSSettingsAdapter::CreateURITaskSegmentListL
       
  2720 //  The function creates list of the content types that profile supports.
       
  2721 //------------------------------------------------------------------------------
       
  2722 TInt CNSmlDSSettingsAdapter::CreateURITaskSegmentListL( const TDesC8& aURI, 
       
  2723                                                         const TInt aPID, 
       
  2724                                                         CBufBase*& aCurrentURISegmentList, 
       
  2725                                                         const CArrayFix<TSmlDmMappingInfo>& aPreviousURISegmentList )
       
  2726 	{
       
  2727 	TInt retVal = OpenSyncSessionAndDSProfileL( aPID, ESmlOpenRead );
       
  2728     if( retVal != KErrNone )
       
  2729 		{
       
  2730 		CloseDSProfile();
       
  2731         return KErrGeneral;	
       
  2732 		}
       
  2733     RArray<TSmlTaskId> taskIdArray;
       
  2734     CleanupClosePushL( taskIdArray );
       
  2735     iDSProfile.ListTasksL( taskIdArray );
       
  2736 	if( taskIdArray.Count() == 0 )
       
  2737 		{
       
  2738 		CloseDSProfile();
       
  2739 		CleanupStack::PopAndDestroy();//taskIdArray
       
  2740     	return KErrNotFound;
       
  2741 		}
       
  2742 	
       
  2743 	RSyncMLTask task;
       
  2744     CleanupClosePushL( task );
       
  2745             
       
  2746     for ( TInt i = 0; i < taskIdArray.Count(); i++ )
       
  2747 		{			
       
  2748 		//	
       
  2749 		//	Check if ContentType -> Task ID on list
       
  2750 		//
       
  2751 		TBool notInList( ETrue );
       
  2752 		TInt newline( 0 );
       
  2753 		TInt ddId( 0 );
       
  2754 		task.OpenL( iDSProfile, taskIdArray[i] );
       
  2755         ddId = task.DataProvider();
       
  2756         task.Close();
       
  2757 		while( notInList && newline <aPreviousURISegmentList.Count() )
       
  2758 			{
       
  2759 			TInt ppId = GetIntObject( aPreviousURISegmentList.At(newline).iURISegLUID );
       
  2760 			if( ppId == ddId )
       
  2761 				{
       
  2762 				notInList = EFalse;
       
  2763 				break;
       
  2764 				}
       
  2765 			newline++;
       
  2766 			}//while
       
  2767 
       
  2768 		if( notInList )
       
  2769 			{
       
  2770 			TBuf8<9> addNAME( Kprev );
       
  2771 			//Get Task ID
       
  2772 			addNAME.AppendNumFixedWidth( taskIdArray[i], EDecimal,3 ); 
       
  2773 			aCurrentURISegmentList->InsertL( aCurrentURISegmentList->Size(), addNAME );
       
  2774 			aCurrentURISegmentList->InsertL( aCurrentURISegmentList->Size(), KNSmlDSSlash );
       
  2775 	
       
  2776 			TBuf8<80> addURI;
       
  2777 			
       
  2778 			addURI.Append( aURI );
       
  2779 			addURI.Append( Kprev2 );
       
  2780 			addURI.AppendNumFixedWidth( taskIdArray[i], EDecimal, 3 ); 
       
  2781 
       
  2782 			TBuf8<16> addLUID;
       
  2783 			addLUID.Num( ddId );
       
  2784 				
       
  2785 			iCallBack->SetMappingL( addURI, addLUID );
       
  2786 			}
       
  2787 		else //not a new object
       
  2788 			{
       
  2789 			aCurrentURISegmentList->InsertL( aCurrentURISegmentList->Size(), 
       
  2790                                             aPreviousURISegmentList.At(newline).iURISeg );
       
  2791 
       
  2792 			aCurrentURISegmentList->InsertL( aCurrentURISegmentList->Size(), KNSmlDSSlash );
       
  2793 
       
  2794 //			DBG_ARGS8(_S8("InList: Id = %d Name %S"), newline, 
       
  2795 //                            aPreviousURISegmentList.At(newline).iURISeg);
       
  2796 			}
       
  2797 		} //For
       
  2798 	CloseDSProfile();
       
  2799 	CleanupStack::PopAndDestroy(2);// task, taskIdArray
       
  2800 	return KErrNone;
       
  2801 	}
       
  2802 //------------------------------------------------------------------------------
       
  2803 //  CNSmlDSSettingsAdapter::CreateURIProfileSegmentListL
       
  2804 //  The function creates list of the profiles.
       
  2805 //------------------------------------------------------------------------------
       
  2806 TInt CNSmlDSSettingsAdapter::CreateURIProfileSegmentListL( CBufBase*& aCurrentURISegmentList, 
       
  2807                                                             const CArrayFix<TSmlDmMappingInfo>& aPreviousURISegmentList )
       
  2808 	{
       
  2809 	if( iSyncSessionOpen == EFalse )
       
  2810 	    {
       
  2811         iSyncSession.OpenL();
       
  2812         iSyncSessionOpen = ETrue;
       
  2813 	    }
       
  2814     RArray<TSmlProfileId> profileIdArray;
       
  2815     CleanupClosePushL( profileIdArray );
       
  2816 	TSmlUsageType usageType = ESmlDataSync;
       
  2817 	iSyncSession.ListProfilesL( profileIdArray, usageType );
       
  2818 		
       
  2819     if(profileIdArray.Count() == 0)
       
  2820 		{
       
  2821         CleanupStack::PopAndDestroy();//profileIdArray
       
  2822 		return KErrNotFound;
       
  2823 		}
       
  2824 		
       
  2825 	for(TInt p = 0; p < profileIdArray.Count(); p++ )
       
  2826 		{
       
  2827 		TBool notInList = ETrue;
       
  2828 		TInt newline = 0;
       
  2829 		while( notInList && newline < aPreviousURISegmentList.Count() )
       
  2830 			{
       
  2831 				TInt ddId = profileIdArray[p];
       
  2832 				TInt ppId = GetIntObject( aPreviousURISegmentList.At(newline).iURISegLUID );
       
  2833 				if( ppId == ddId ) 
       
  2834 					{
       
  2835 					notInList = EFalse;
       
  2836 					break;
       
  2837 					}
       
  2838 				newline++;
       
  2839 			}
       
  2840 
       
  2841 		if( notInList )
       
  2842 			{ // Those which not have mapping data
       
  2843 			
       
  2844 			TBuf8<9> addNAME( KDSprev );
       
  2845 			addNAME.AppendNumFixedWidth( profileIdArray[p], EDecimal, 3 ); 
       
  2846 
       
  2847 			aCurrentURISegmentList->InsertL( aCurrentURISegmentList->Size(), addNAME );
       
  2848 			aCurrentURISegmentList->InsertL( aCurrentURISegmentList->Size(), KNSmlDSSlash );
       
  2849             
       
  2850 			// KNSmlDSStart includes start text for URISeg
       
  2851 			TBuf8<20> addURI; // SyncML/DSAcc/DSIdnnn , nnn = profileid
       
  2852 			addURI.Append( KNSmlDSStart );
       
  2853 			addURI.AppendNumFixedWidth( profileIdArray[p], EDecimal, 3 ); 
       
  2854 			
       
  2855 			TBuf8<16> addLUID;
       
  2856 			addLUID.Num( profileIdArray[p] );
       
  2857 			
       
  2858 			iCallBack->SetMappingL( addURI,addLUID );
       
  2859             }
       
  2860 		else
       
  2861 			{ // Add those in PreviousList which are on database
       
  2862 			aCurrentURISegmentList->InsertL( aCurrentURISegmentList->Size(), 
       
  2863                                             aPreviousURISegmentList.At(newline).iURISeg );
       
  2864 
       
  2865 			aCurrentURISegmentList->InsertL( aCurrentURISegmentList->Size(), KNSmlDSSlash );
       
  2866 //			DBG_ARGS8(_S8("InList: Id = %d Name %S"), newline, 
       
  2867 //                           aPreviousURISegmentList.At(newline).iURISeg);
       
  2868 			}
       
  2869 		}
       
  2870     CleanupStack::PopAndDestroy();//profileIdArray
       
  2871 	return KErrNone;
       
  2872 	}
       
  2873 
       
  2874 //------------------------------------------------------------------------------
       
  2875 //  CNSmlDSSettingsAdapter::OpenSyncSessionAndDSProfileL
       
  2876 //  The function opens the server session and DS profile.
       
  2877 //------------------------------------------------------------------------------
       
  2878 TInt CNSmlDSSettingsAdapter::OpenSyncSessionAndDSProfileL( const TInt aIntLUID, 
       
  2879                                                             TSmlOpenMode aMode )
       
  2880     {
       
  2881     if( iSyncSessionOpen == EFalse )
       
  2882         {
       
  2883         iSyncSession.OpenL();
       
  2884         iSyncSessionOpen = ETrue;
       
  2885         }
       
  2886     RArray<TSmlProfileId> profileIdArray;
       
  2887     CleanupClosePushL( profileIdArray );
       
  2888     TSmlUsageType usageType = ESmlDataSync;
       
  2889     iSyncSession.ListProfilesL( profileIdArray, usageType );
       
  2890     TInt index = profileIdArray.Find( aIntLUID );
       
  2891     CleanupStack::PopAndDestroy(); //profileIdArray
       
  2892     if( index == KErrNotFound )
       
  2893         {
       
  2894         return KErrNotFound;
       
  2895         }
       
  2896     TRAPD( rValue, iDSProfile.OpenL( iSyncSession, aIntLUID, aMode ) );
       
  2897     if( rValue != KErrNone )
       
  2898         {
       
  2899         iDSProfile.Close();
       
  2900 		iSyncSession.Close();
       
  2901         iSyncSessionOpen = EFalse;
       
  2902         }
       
  2903     return rValue;
       
  2904     }
       
  2905 //------------------------------------------------------------------------------
       
  2906 //  CNSmlDSSettingsAdapter::CloseDSProfile
       
  2907 //  The function closes the DS profile connection.
       
  2908 //------------------------------------------------------------------------------
       
  2909 void CNSmlDSSettingsAdapter::CloseDSProfile()
       
  2910     {
       
  2911     iDSProfile.Close();
       
  2912     }
       
  2913 
       
  2914 //------------------------------------------------------------------------------
       
  2915 //  CNSmlDSSettingsAdapter::FindTaskIDL
       
  2916 //  The function searches if task can be found from the profile task list.
       
  2917 //------------------------------------------------------------------------------
       
  2918 TBool CNSmlDSSettingsAdapter::FindTaskIDL( const TInt aProfLUID, const TInt aDataProviderId )
       
  2919     {
       
  2920     TInt retVal = OpenSyncSessionAndDSProfileL( aProfLUID, ESmlOpenRead );
       
  2921     if( retVal != KErrNone )
       
  2922 		{
       
  2923 		CloseDSProfile();
       
  2924         return EFalse;	
       
  2925 		}
       
  2926     RArray<TSmlTaskId> taskIdArray;
       
  2927     CleanupClosePushL( taskIdArray );//taskIdArray
       
  2928     iDSProfile.ListTasksL( taskIdArray );
       
  2929     
       
  2930     RSyncMLTask task;
       
  2931     CleanupClosePushL( task );
       
  2932     // find task
       
  2933     for (TInt i=0; i<taskIdArray.Count(); i++)
       
  2934         {
       
  2935         task.OpenL( iDSProfile, taskIdArray[i] );
       
  2936         if (task.DataProvider() == aDataProviderId)
       
  2937             {
       
  2938             CleanupStack::PopAndDestroy(2); //taskIdArray, task
       
  2939             CloseDSProfile();
       
  2940             return ETrue;
       
  2941             }
       
  2942         task.Close();
       
  2943         }
       
  2944     // task not found
       
  2945     CleanupStack::PopAndDestroy(2); //taskIdArray, task
       
  2946     CloseDSProfile();
       
  2947     return EFalse;
       
  2948     }
       
  2949 //------------------------------------------------------------------------------
       
  2950 //  CNSmlDSSettingsAdapter::DeleteTaskByIDL
       
  2951 //  The function deletes the task by given id.
       
  2952 //------------------------------------------------------------------------------
       
  2953 TInt CNSmlDSSettingsAdapter::DeleteTaskByIDL( const TInt aLUID, const TInt aDataProviderId )
       
  2954     {
       
  2955     TInt retVal = OpenSyncSessionAndDSProfileL( aLUID, ESmlOpenReadWrite );
       
  2956     if( retVal != KErrNone )
       
  2957 		{
       
  2958 		CloseDSProfile();
       
  2959         return retVal;	
       
  2960 		}
       
  2961     RArray<TSmlTaskId> taskIdArray;
       
  2962     CleanupClosePushL( taskIdArray );
       
  2963     iDSProfile.ListTasksL( taskIdArray );
       
  2964     
       
  2965     RSyncMLTask task;
       
  2966     CleanupClosePushL( task );
       
  2967     // find task
       
  2968     for (TInt i=0; i<taskIdArray.Count(); i++)
       
  2969         {
       
  2970         task.OpenL( iDSProfile, taskIdArray[i] );
       
  2971         if (task.DataProvider() == aDataProviderId)
       
  2972             {
       
  2973             task.Close();
       
  2974             CleanupStack::PopAndDestroy(); // task
       
  2975             iDSProfile.DeleteTaskL( taskIdArray[i] );
       
  2976             iDSProfile.UpdateL();
       
  2977             CleanupStack::PopAndDestroy(); //taskIdArray
       
  2978             CloseDSProfile();
       
  2979             return KErrNone;
       
  2980             }
       
  2981         task.Close();
       
  2982         }
       
  2983     // task not found
       
  2984     CleanupStack::PopAndDestroy(2); //taskIdArray, task
       
  2985     CloseDSProfile();
       
  2986     return KErrNotFound;
       
  2987     }
       
  2988 //------------------------------------------------------------------------------
       
  2989 //  CNSmlDSSettingsAdapter::GetClientDataSourceL
       
  2990 //  The function gets the local data store (LDBURI).
       
  2991 //------------------------------------------------------------------------------
       
  2992 TInt CNSmlDSSettingsAdapter::GetClientDataSourceL( const TInt aDataProviderId, 
       
  2993                                                     const TInt aProfileLUID, 
       
  2994                                                     CBufBase*& aObject )
       
  2995     {
       
  2996     TInt retVal = OpenSyncSessionAndDSProfileL( aProfileLUID, ESmlOpenRead );
       
  2997     if( retVal != KErrNone )
       
  2998 		{
       
  2999 		CloseDSProfile();
       
  3000         return retVal;	
       
  3001 		}
       
  3002     RArray<TSmlTaskId> taskArray;
       
  3003     CleanupClosePushL( taskArray );
       
  3004     iDSProfile.ListTasksL( taskArray );
       
  3005     
       
  3006     RSyncMLTask task;
       
  3007     CleanupClosePushL( task );
       
  3008     // find task
       
  3009     for (TInt i=0; i<taskArray.Count(); i++)
       
  3010         {
       
  3011         task.OpenL( iDSProfile, taskArray[i] );
       
  3012         if (task.DataProvider() == aDataProviderId)
       
  3013             {
       
  3014             HBufC* localDataStore = task.ClientDataSource().AllocLC();
       
  3015             aObject->InsertL( aObject->Size(), ConvertTo8LC( *localDataStore ) );
       
  3016             CloseDSProfile();
       
  3017             CleanupStack::PopAndDestroy(4); //taskIdArray, task, localDataStore, ConvertTo8LC
       
  3018             
       
  3019             return KErrNone;
       
  3020             }
       
  3021         task.Close();
       
  3022         }
       
  3023     // task not found
       
  3024     CleanupStack::PopAndDestroy(2); //taskArray, task
       
  3025     CloseDSProfile();
       
  3026     return KErrNotFound;
       
  3027     }
       
  3028 //------------------------------------------------------------------------------
       
  3029 //  CNSmlDSSettingsAdapter::GetServerDataSourceL
       
  3030 //  The function gets the remote data store (RDBURI).
       
  3031 //------------------------------------------------------------------------------
       
  3032 TInt CNSmlDSSettingsAdapter::GetServerDataSourceL( const TInt aDataProviderId, 
       
  3033                                                     const TInt aProfileLUID, 
       
  3034                                                     CBufBase*& aObject )
       
  3035     {
       
  3036     TInt retVal = OpenSyncSessionAndDSProfileL( aProfileLUID, ESmlOpenRead );
       
  3037     if( retVal != KErrNone )
       
  3038 		{
       
  3039 		CloseDSProfile();
       
  3040         return retVal;	
       
  3041 		}
       
  3042     RArray<TSmlTaskId> taskArray;
       
  3043     CleanupClosePushL( taskArray );
       
  3044     iDSProfile.ListTasksL( taskArray );
       
  3045     
       
  3046     RSyncMLTask task;
       
  3047     CleanupClosePushL( task );
       
  3048     // find task
       
  3049     for (TInt i=0; i<taskArray.Count(); i++)
       
  3050         {
       
  3051         task.OpenL( iDSProfile, taskArray[i] );
       
  3052         if (task.DataProvider() == aDataProviderId)
       
  3053             {
       
  3054             HBufC* serverDataStore = task.ServerDataSource().AllocLC();
       
  3055             aObject->InsertL( aObject->Size(), ConvertTo8LC( *serverDataStore ) );
       
  3056             CloseDSProfile();
       
  3057             CleanupStack::PopAndDestroy(4); //taskIdArray, task, serverDataStore, ConvertTo8LC
       
  3058             
       
  3059             return KErrNone;
       
  3060             }
       
  3061         task.Close();
       
  3062         }
       
  3063     // task not found
       
  3064     CleanupStack::PopAndDestroy(2); //taskIdArray, task
       
  3065     CloseDSProfile();
       
  3066     return KErrNotFound;
       
  3067     }
       
  3068 //------------------------------------------------------------------------------
       
  3069 //  CNSmlDSSettingsAdapter::UpdateDataSourceL
       
  3070 //  The function updates the LDBURI or RDBURI leaf value.
       
  3071 //------------------------------------------------------------------------------
       
  3072 TInt CNSmlDSSettingsAdapter::UpdateDataSourceL( const TInt aProfileLUID, 
       
  3073                                                 const TInt aDataProviderId, 
       
  3074                                                 const TDesC8& aObject, 
       
  3075                                                 const HBufC8& aField)
       
  3076     {
       
  3077     // check that aField is RemoteDB or LocalDB
       
  3078     if( aField.Compare( KNSmlDdfRDBURI ) != 0 && aField.Compare( KNSmlDdfLDBURI ) != 0)
       
  3079         {
       
  3080         return KErrGeneral;
       
  3081         }
       
  3082     
       
  3083     TInt retVal = OpenSyncSessionAndDSProfileL( aProfileLUID, ESmlOpenReadWrite );
       
  3084     if( retVal != KErrNone )
       
  3085 		{
       
  3086 		CloseDSProfile();
       
  3087         return retVal;	
       
  3088 		}
       
  3089     RArray<TSmlTaskId> taskArray;
       
  3090     CleanupClosePushL( taskArray );
       
  3091     iDSProfile.ListTasksL( taskArray );
       
  3092     
       
  3093     RSyncMLTask task;
       
  3094     CleanupClosePushL( task );
       
  3095     // find correct task
       
  3096     for (TInt i=0; i<taskArray.Count(); i++)
       
  3097         {
       
  3098         task.OpenL( iDSProfile, taskArray[i] );
       
  3099         if (task.DataProvider() == aDataProviderId)
       
  3100             {
       
  3101             // task found, get current localDataStore and remoteDataStore
       
  3102             HBufC* localDataStore = task.ClientDataSource().AllocLC();
       
  3103             HBufC* remoteDataStore = task.ServerDataSource().AllocLC();
       
  3104             task.Close();
       
  3105             
       
  3106             HBufC16* objectBuffer = HBufC16::NewLC( aObject.Size() );
       
  3107             TPtr16 ptrDataObject = objectBuffer->Des();
       
  3108             CnvUtfConverter::ConvertToUnicodeFromUtf8( ptrDataObject, aObject );
       
  3109             iDSProfile.DeleteTaskL( taskArray[i] );
       
  3110             iDSProfile.UpdateL();
       
  3111             
       
  3112             // create new task with new values
       
  3113             RSyncMLTask newTask;
       
  3114             CleanupClosePushL( newTask );
       
  3115             if( aField.Compare( KNSmlDdfRDBURI ) == 0 ) //Remote DB, Mandatory
       
  3116                 {
       
  3117                 newTask.CreateL( iDSProfile, aDataProviderId, ptrDataObject, *localDataStore );
       
  3118                 }
       
  3119             else if( aField.Compare( KNSmlDdfLDBURI ) == 0 )
       
  3120                 {
       
  3121                 newTask.CreateL( iDSProfile, aDataProviderId, *remoteDataStore, ptrDataObject );
       
  3122                 }
       
  3123             newTask.UpdateL();
       
  3124             
       
  3125             CloseDSProfile();
       
  3126             CleanupStack::PopAndDestroy( 6 ); //taskArray, task, localDataStore, 
       
  3127                                             //remoteDataStore, objectBuffer, newTask
       
  3128             return retVal;
       
  3129             }
       
  3130         task.Close();
       
  3131         }
       
  3132     // task not found
       
  3133     CleanupStack::PopAndDestroy(2);//taskArray, task
       
  3134     CloseDSProfile();
       
  3135     return KErrNotFound;
       
  3136     }
       
  3137 //------------------------------------------------------------------------------
       
  3138 //  CNSmlDSSettingsAdapter::FetchObjectL
       
  3139 //  The function fetches the requested leaf object data.
       
  3140 //------------------------------------------------------------------------------
       
  3141 TInt CNSmlDSSettingsAdapter::FetchObjectL( const TDesC8& aURI, const TDesC8& aLUID, 
       
  3142                                             CBufBase*& aObj, const TInt aStatusRef )
       
  3143 	{
       
  3144 	_DBG_FILE("CNSmlDSSettingsAdapter::FetchObjectL(): begin");
       
  3145 //
       
  3146 	DBG_ARGS(_S16("DS:Fetch aURI    - %S - %S"), &aURI, &aLUID);
       
  3147 
       
  3148     TInt retVal = KErrNone;
       
  3149     TInt profileLUID = -1;
       
  3150 
       
  3151 	iLUID = IntLUID( aLUID );
       
  3152 
       
  3153     if ( aLUID.Length() > 0 && 
       
  3154 	   ( aURI.Match( KCTTypeMatch ) != KErrNotFound ||
       
  3155 	    aURI.Match( KRDBUriMatch ) != KErrNotFound ||
       
  3156 	    aURI.Match( KLDBUriMatch ) != KErrNotFound ) )
       
  3157 	   {
       
  3158 		profileLUID = GetProfileIdFromURIL( aURI ); // ProfileId for DB-level
       
  3159         if( FindTaskIDL( profileLUID, iLUID ) == EFalse )
       
  3160             {
       
  3161             _DBG_FILE("CNSmlDSSettingsAdapter::FetchObjectL(): ENotFound end");
       
  3162 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
  3163 			return KErrNotFound;
       
  3164 			}
       
  3165         }
       
  3166 	else if ( aLUID.Length() > 0 ) //Profile
       
  3167 		{
       
  3168 		TInt profileID = -1; 
       
  3169         TInt retValue = GetProfileIdentifierL( iLUID, profileID );
       
  3170 		if( retValue != KErrNone || profileID < 0 )
       
  3171 			{
       
  3172 			_DBG_FILE("CNSmlDSSettingsAdapter::FetchObjectL(): ENotFound end");
       
  3173 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
  3174 			return KErrNotFound;
       
  3175 			}
       
  3176 		iLUID = profileID;
       
  3177 		}
       
  3178 	else
       
  3179 		{
       
  3180 		// Static node feature start
       
  3181 		iLUID = -1;
       
  3182 		if( IsDSAccUriFormatMatchPredefined(aURI) )
       
  3183     	{
       
  3184     		iLUID = ConstructTreeL(aURI);
       
  3185     		profileLUID = GetProfileIdFromURIL( aURI ); 
       
  3186     	}
       
  3187     	
       
  3188     	if ((iLUID == 0 ) && (aURI.Match(_L8("SyncML/DSAcc/DSId*/DB/CTId*"))  == KErrNone))
       
  3189 		{
       
  3190 		_DBG_FILE("CNSmlDSSettingsAdapter::FetchObjectL(): ENotFound end");
       
  3191 		iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
  3192 		return KErrNotFound;
       
  3193     	}
       
  3194 		// Static node feature end
       
  3195 		}
       
  3196 
       
  3197 	SetField( aURI );
       
  3198 //
       
  3199 //	Check if valid field
       
  3200 //
       
  3201 /*	if( !AcceptDSField() )
       
  3202 		{
       
  3203 		_DBG_FILE("CNSmlDSSettingsAdapter::FetchObjectL(): EInvalidObject end");
       
  3204 		iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EInvalidObject );
       
  3205 		return KErrGeneral;
       
  3206 		}
       
  3207 */
       
  3208 //
       
  3209 //	Check which field going to be handled
       
  3210 //
       
  3211     TInt fType = GetDSFieldTypeL();
       
  3212     if ( fType == EInt || fType == EStr )
       
  3213 		{
       
  3214 		retVal = GetDSFieldDataL( iLUID, aObj );
       
  3215         }
       
  3216 	else if ( fType == EParam )
       
  3217 		{ // DB and CTType (dataprovider info / MIME type)
       
  3218 		  // RDBURI + LDBURI (dataprovider data paths)
       
  3219 	    if( iField->Compare( KNSmlDdfCTType ) == 0 )
       
  3220 		    {
       
  3221 		    retVal = GetContentTypeL( iLUID, profileLUID, aObj );
       
  3222 		    }
       
  3223         else if( iField->Compare( KNSmlDdfLDBURI ) == 0 ) // Local database (optional)
       
  3224 			{
       
  3225 			//ClientDataSource
       
  3226             retVal = GetClientDataSourceL( iLUID, profileLUID, aObj );
       
  3227             }
       
  3228 		else if( iField->Compare( KNSmlDdfRDBURI ) == 0 ) // Remote database 
       
  3229 			{
       
  3230             //ServerDataSource
       
  3231 		    retVal = GetServerDataSourceL( iLUID, profileLUID, aObj );
       
  3232             }
       
  3233 		}
       
  3234 	else 
       
  3235 		{
       
  3236 		_DBG_FILE("CNSmlDSSettingsAdapter::FetchObjectL(): Unknown type end");
       
  3237 		iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
  3238 		return KErrNotFound;
       
  3239 		}
       
  3240     if( retVal != KErrNone )
       
  3241         {
       
  3242         if ( retVal == KErrNotFound )
       
  3243             {
       
  3244 			_DBG_FILE("CNSmlDSSettingsAdapter::FetchObjectL(): ENotFound end");
       
  3245 			iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::ENotFound );
       
  3246             }
       
  3247         else
       
  3248             {
       
  3249 			_DBG_FILE("CNSmlDSSettingsAdapter::FetchObjectL(): retVal != KErrNone");
       
  3250             iCallBack->SetStatusL( aStatusRef, CSmlDmAdapter::EError );        
       
  3251             }            
       
  3252         }
       
  3253     return retVal;
       
  3254     
       
  3255 	}
       
  3256 //------------------------------------------------------------------------------
       
  3257 //  CNSmlDSSettingsAdapter::FillNodeInfoL
       
  3258 //  The function fills the node or leaf information.
       
  3259 //------------------------------------------------------------------------------
       
  3260 void CNSmlDSSettingsAdapter::FillNodeInfoL( MSmlDmDDFObject& aNode, 
       
  3261                                             TSmlDmAccessTypes aAccTypes, 
       
  3262                                             MSmlDmDDFObject::TOccurence aOccurrence, 
       
  3263                                             MSmlDmDDFObject::TScope aScope, 
       
  3264                                             MSmlDmDDFObject::TDFFormat aFormat, 
       
  3265                                             const TDesC8& aDescription, 
       
  3266                                             const TDesC8& aDefaultValue, 
       
  3267                                             const TDesC8& aMimeType )
       
  3268     {
       
  3269     aNode.AddDFTypeMimeTypeL( aMimeType );
       
  3270     aNode.SetAccessTypesL( aAccTypes );
       
  3271 	aNode.SetDescriptionL( aDescription );
       
  3272 	aNode.SetOccurenceL( aOccurrence );
       
  3273 	aNode.SetDefaultValueL( aDefaultValue );
       
  3274 	aNode.SetScopeL( aScope );
       
  3275 	aNode.SetDFFormatL( aFormat );
       
  3276     return;
       
  3277     }
       
  3278 //------------------------------------------------------------------------------
       
  3279 //  CNSmlDSSettingsAdapter::SetProfileAddrTypeL
       
  3280 //  The function sets the medium type for a profile.
       
  3281 //------------------------------------------------------------------------------
       
  3282 TInt CNSmlDSSettingsAdapter::SetProfileAddrTypeL( const TInt aLUID, 
       
  3283                                                     const TInt aIntObj )
       
  3284     {
       
  3285     _DBG_FILE("CNSmlDSSettingsAdapter::SetProfileAddrTypeL(): begin");
       
  3286     TInt retVal = OpenSyncSessionAndDSProfileL( aLUID, ESmlOpenReadWrite );
       
  3287     if( retVal != KErrNone )
       
  3288 		{
       
  3289 		CloseDSProfile();
       
  3290         _DBG_FILE("CNSmlDSSettingsAdapter::SetProfileAddrTypeL(): end");
       
  3291         return retVal;	
       
  3292 		}
       
  3293     TSmlTransportId mediumType = ENone;
       
  3294     GetMediumTypeL( aIntObj, mediumType );
       
  3295     if( mediumType == ENone )
       
  3296         {
       
  3297         return KErrGeneral;
       
  3298         }
       
  3299     RArray<TSmlTransportId> transportIdArray;
       
  3300     CleanupClosePushL( transportIdArray );
       
  3301     iDSProfile.ListConnectionsL( transportIdArray );
       
  3302 
       
  3303     RSyncMLConnection conn;
       
  3304     conn.OpenL( iDSProfile, transportIdArray[0] );
       
  3305     CleanupClosePushL( conn );
       
  3306 
       
  3307     HBufC8* sURI = conn.ServerURI().AllocLC();
       
  3308     if(mediumType!=transportIdArray[0])
       
  3309         {
       
  3310         conn.CreateL( iDSProfile, mediumType ); //changes medium type and clears the buffer
       
  3311         }
       
  3312         
       
  3313     if(mediumType!=KUidNSmlMediumTypeInternet.iUid && sURI->Length() > 0)
       
  3314         {
       
  3315         // remove port
       
  3316         HBufC8* newServerURI = HBufC8::NewL( sURI->Size() );
       
  3317         CleanupStack::PushL( newServerURI );
       
  3318         TBuf8<5> buf;
       
  3319     	buf.Num( 0 );
       
  3320         // change iLeafType to EDSDelete -> deleting port
       
  3321         TNSmlDSLeafType	tmpType(iLeafType); // store old value
       
  3322         iLeafType = EDSDelete;
       
  3323         SetPortNrToAddrStr( *sURI, newServerURI, buf );
       
  3324         iLeafType = tmpType; // restore original value
       
  3325         
       
  3326         conn.SetServerURIL( *newServerURI );
       
  3327         conn.UpdateL();
       
  3328         
       
  3329         CleanupStack::PopAndDestroy( newServerURI );
       
  3330         }
       
  3331     else
       
  3332         {
       
  3333         conn.SetServerURIL( *sURI );
       
  3334         conn.UpdateL();
       
  3335         }
       
  3336                       
       
  3337     CleanupStack::PopAndDestroy( 3 );//transportIdArray, conn, sURI
       
  3338     CloseDSProfile();
       
  3339     _DBG_FILE("CNSmlDSSettingsAdapter::SetProfileAddrTypeL(): end");
       
  3340     return KErrNone;
       
  3341     }
       
  3342 //------------------------------------------------------------------------------
       
  3343 //  CNSmlDSSettingsAdapter::SetProfileConnectionPortNrL
       
  3344 //  The function sets the port number (PortNbr) for a profile.
       
  3345 //------------------------------------------------------------------------------
       
  3346 TInt CNSmlDSSettingsAdapter::SetProfileConnectionPortNrL( const TInt aLUID, 
       
  3347                                                             const TDesC8& aPort )
       
  3348     {
       
  3349     _DBG_FILE("CNSmlDSSettingsAdapter::SetProfileConnectionPortNrL(): begin");
       
  3350     TInt retVal = KErrNone;
       
  3351     
       
  3352     if( iPortNbr )
       
  3353         {
       
  3354         delete iPortNbr;
       
  3355         iPortNbr = NULL;
       
  3356         }
       
  3357     iPortNbr = HBufC8::NewL( aPort.Length() );
       
  3358     TPtr8 newPortNbr = iPortNbr->Des();
       
  3359     newPortNbr.Append( aPort );
       
  3360         
       
  3361     retVal = OpenSyncSessionAndDSProfileL( aLUID, ESmlOpenReadWrite );
       
  3362     if( retVal != KErrNone )
       
  3363 		{
       
  3364 		CloseDSProfile();
       
  3365         _DBG_FILE("CNSmlDSSettingsAdapter::SetProfileConnectionPortNrL(): end");
       
  3366         return retVal;	
       
  3367 		}
       
  3368     
       
  3369     RArray<TSmlTransportId> transportIdArray;
       
  3370     CleanupClosePushL( transportIdArray );
       
  3371     iDSProfile.ListConnectionsL( transportIdArray );
       
  3372     
       
  3373     RSyncMLConnection conn;
       
  3374     CleanupClosePushL( conn );
       
  3375     conn.OpenL( iDSProfile, transportIdArray[0] );
       
  3376     
       
  3377     // if medium type is not internet -> do not add port
       
  3378     if( transportIdArray[0] != KUidNSmlMediumTypeInternet.iUid )
       
  3379         {
       
  3380         CloseDSProfile();
       
  3381         CleanupStack::PopAndDestroy( 2 ); //transportIdArray, conn
       
  3382         _DBG_FILE("CNSmlDSSettingsAdapter::SetProfileConnectionPortNrL(): end");
       
  3383         return retVal;
       
  3384         }
       
  3385         
       
  3386     HBufC8* serverURI = conn.ServerURI().AllocLC();
       
  3387     if( serverURI->Length() == 0 )
       
  3388         {
       
  3389         CloseDSProfile();
       
  3390         CleanupStack::PopAndDestroy( 3 ); //transportIdArray, conn, serverURI
       
  3391         _DBG_FILE("CNSmlDSSettingsAdapter::SetProfileConnectionPortNrL(): end");
       
  3392         return retVal;
       
  3393 	    }
       
  3394     TInt totalSize = serverURI->Size() + newPortNbr.Size() + 1;
       
  3395     HBufC8* newServerURI = HBufC8::NewL( totalSize );
       
  3396     CleanupStack::PushL( newServerURI );
       
  3397     SetPortNrToAddrStr( *serverURI, newServerURI, newPortNbr );
       
  3398     
       
  3399     conn.SetServerURIL( *newServerURI );
       
  3400     conn.UpdateL();
       
  3401     
       
  3402     CleanupStack::PopAndDestroy( 4 ); //transportIdArray, conn, serverURI, newServerURI
       
  3403     CloseDSProfile();
       
  3404     _DBG_FILE("CNSmlDSSettingsAdapter::SetProfileConnectionPortNrL(): end");
       
  3405     return KErrNone;	
       
  3406     }
       
  3407 //------------------------------------------------------------------------------
       
  3408 //  CNSmlDSSettingsAdapter::SetPortNrToAddrStr
       
  3409 //  The function sets or replaces a portnbr (separated with ':') to Addr Uri.
       
  3410 //------------------------------------------------------------------------------
       
  3411 void CNSmlDSSettingsAdapter::SetPortNrToAddrStr( const TDesC8& aSrvURI, 
       
  3412                                                     HBufC8* aNewURI, 
       
  3413                                                     const TDesC8& aPort )
       
  3414 	{
       
  3415 	TInt offset=0;
       
  3416     if( aSrvURI.Find( KNSmlDSSettingsHTTP ) == 0 )//http://
       
  3417 		{
       
  3418 		offset = KNSmlDSSettingsHTTP().Length();
       
  3419 		}
       
  3420 	else if( aSrvURI.Find( KNSmlDSSettingsHTTPS ) == 0 )//https://
       
  3421 		{
       
  3422 		offset = KNSmlDSSettingsHTTPS().Length();
       
  3423 		}
       
  3424 	
       
  3425 	TInt portStart = -1;
       
  3426     TInt separatorPos = aSrvURI.Length();
       
  3427     
       
  3428     TInt i = 0;
       
  3429     for( i = offset; i < aSrvURI.Length(); i++ )
       
  3430 		{
       
  3431 		if( aSrvURI[i] == KNSmlDMColon )// ':'
       
  3432 			{
       
  3433 			portStart = i;
       
  3434 			}
       
  3435 		if( aSrvURI[i] == KNSmlDMUriSeparator )// '/'
       
  3436 			{
       
  3437             separatorPos = i;
       
  3438 			break;
       
  3439 			}
       
  3440 		}
       
  3441     
       
  3442     TPtr8 ptrNewSrvURI = aNewURI->Des();
       
  3443     if( portStart < 0 && separatorPos > 0 && iLeafType != EDSDelete )
       
  3444         {
       
  3445         ptrNewSrvURI.Append( aSrvURI.Left( separatorPos ) );//http://123.234.345.456
       
  3446         ptrNewSrvURI.Append( KNSmlDMColon );
       
  3447         ptrNewSrvURI.Append( aPort );
       
  3448         ptrNewSrvURI.Append( aSrvURI.Right( aSrvURI.Length() - separatorPos ) );//123.234.345.456:xx(x)/syncml    
       
  3449         }
       
  3450     else if ( portStart > 0 && separatorPos > 0 && iLeafType != EDSDelete )
       
  3451         {
       
  3452         ptrNewSrvURI.Append( aSrvURI.Left( portStart + 1 ) );//123.234.345.456:
       
  3453         ptrNewSrvURI.Append( aPort );//123.234.345.456:xx(x)
       
  3454         ptrNewSrvURI.Append( aSrvURI.Right( aSrvURI.Length() - separatorPos ) );//123.234.345.456:xx(x)/syncml
       
  3455         }
       
  3456     else if ( portStart > 0 &&  iLeafType == EDSDelete ) //delete port number from uri
       
  3457         {
       
  3458         ptrNewSrvURI.Append( aSrvURI.Left( portStart ) );//123.234.345.456
       
  3459         ptrNewSrvURI.Append( aSrvURI.Right( aSrvURI.Length() - separatorPos ) );//123.234.345.456:xx(x)/syncml
       
  3460         }
       
  3461     else
       
  3462         {
       
  3463         ptrNewSrvURI.Append( aSrvURI );
       
  3464         }
       
  3465     return;
       
  3466 	}
       
  3467 //------------------------------------------------------------------------------
       
  3468 //  CNSmlDSSettingsAdapter::MimeTypeAllreadyExitsL
       
  3469 //  The function checks if mime type allready exits in this profile.
       
  3470 //------------------------------------------------------------------------------
       
  3471 TBool CNSmlDSSettingsAdapter::MimeTypeAllreadyExitsL( const TInt aLuid, 
       
  3472                                                         const TDesC8& aMimeType )
       
  3473     {
       
  3474     TInt retVal = OpenSyncSessionAndDSProfileL( aLuid, ESmlOpenRead );
       
  3475     if( retVal != KErrNone )
       
  3476 		{
       
  3477 		CloseDSProfile();
       
  3478         return EFalse;	
       
  3479 		}
       
  3480     RArray<TSmlDataProviderId> dataProviderArray;
       
  3481     CleanupClosePushL( dataProviderArray );
       
  3482     iSyncSession.ListDataProvidersL( dataProviderArray );
       
  3483     TInt dataProviderCount = dataProviderArray.Count();
       
  3484     if( dataProviderCount == 0 )
       
  3485         {//error case, data provider not found
       
  3486         CloseDSProfile();
       
  3487         CleanupStack::PopAndDestroy();//dataProviderIdArray
       
  3488         return EFalse;   
       
  3489         }
       
  3490 
       
  3491     RSyncMLTask task;
       
  3492     RSyncMLDataProvider dataProvider;
       
  3493     RArray<TSmlTaskId> taskIdArray;
       
  3494     iDSProfile.ListTasksL( taskIdArray );
       
  3495     CleanupClosePushL(taskIdArray);
       
  3496     
       
  3497     HBufC8* object = aMimeType.AllocLC();
       
  3498     TPtr8 objectPtr = object->Des();
       
  3499 	objectPtr.LowerCase();
       
  3500     
       
  3501     for( TInt i = 0; i<taskIdArray.Count(); i++ )
       
  3502         {
       
  3503         task.OpenL( iDSProfile, taskIdArray[i] );
       
  3504         CleanupClosePushL(task);
       
  3505         TInt dataProviderUID = task.DataProvider();
       
  3506         TInt dataProviderIndex = dataProviderArray.Find( dataProviderUID );
       
  3507         if( dataProviderIndex != KErrNotFound )
       
  3508             {
       
  3509             dataProvider.OpenL( iSyncSession, dataProviderArray[dataProviderIndex] );
       
  3510             CleanupClosePushL(dataProvider);
       
  3511             for ( TInt n = 0; n < dataProvider.MimeTypeCount(); n++ )
       
  3512                 {
       
  3513                 HBufC* mimeType = dataProvider.MimeType(n).AllocLC();
       
  3514                 if( objectPtr.Compare( ConvertTo8LC( *mimeType ) ) == 0 ) //if MIME match
       
  3515                     {
       
  3516                     CleanupStack::PopAndDestroy( 7 ); //dataProviderArray, task, dataProvider,
       
  3517                                                     //taskIdArray, object, mimeType, ConvertTo8LC    
       
  3518                     CloseDSProfile();            
       
  3519                     return ETrue;
       
  3520                     }
       
  3521                 CleanupStack::PopAndDestroy( 2 ); //mimeType, ConvertTo8LC
       
  3522                 }
       
  3523             CleanupStack::PopAndDestroy( ); //dataProvider
       
  3524             }
       
  3525         CleanupStack::PopAndDestroy( ); //task
       
  3526         }
       
  3527     CleanupStack::PopAndDestroy( 3 ); //dataProviderArray,taskIdArray, object
       
  3528     CloseDSProfile();
       
  3529     return EFalse;
       
  3530     }
       
  3531 
       
  3532 //------------------------------------------------------------------------------
       
  3533 //  CNSmlDSSettingsAdapter::SetRDBDataStore
       
  3534 //  The function sets the RDMURI to memeber variable.
       
  3535 //------------------------------------------------------------------------------
       
  3536 void CNSmlDSSettingsAdapter::SetRDBDataStore( const TDesC8& aStore )
       
  3537     {
       
  3538 	TPtr16 bufPtr16 = iRdbDataStore->Des();
       
  3539     bufPtr16.Delete(0, bufPtr16.Size());
       
  3540 	CnvUtfConverter::ConvertToUnicodeFromUtf8( bufPtr16, aStore );
       
  3541     }
       
  3542 
       
  3543 //------------------------------------------------------------------------------
       
  3544 //	CNSmlDSSettingsAdapter::SetProfileIAPIdL
       
  3545 //	The function sets the IAPId value to profile connection properties.
       
  3546 //------------------------------------------------------------------------------
       
  3547 TInt CNSmlDSSettingsAdapter::SetProfileIAPIdL( const TInt aLUID, const TInt aIAPid )
       
  3548     {
       
  3549     TInt retVal = OpenSyncSessionAndDSProfileL( aLUID, ESmlOpenReadWrite );
       
  3550     if( retVal != KErrNone )
       
  3551 		{
       
  3552 		CloseDSProfile();
       
  3553         return retVal;	
       
  3554 		}
       
  3555     RArray<TSmlTransportId> connIdArray;
       
  3556     CleanupClosePushL( connIdArray );
       
  3557     iDSProfile.ListConnectionsL( connIdArray );
       
  3558     if( connIdArray.Count() == 1 )
       
  3559         {
       
  3560         RSyncMLTransport transport;
       
  3561         CleanupClosePushL( transport );
       
  3562 	    transport.OpenL( iSyncSession, connIdArray[0] );
       
  3563 	    const CSyncMLTransportPropertiesArray& props = transport.Properties();
       
  3564 	    TInt index = props.Find( KNSmlIAPId );
       
  3565         if( index > 0 )
       
  3566             {
       
  3567             RSyncMLConnection conn;
       
  3568             CleanupClosePushL( conn );
       
  3569 	        conn.OpenL( iDSProfile, connIdArray[0] );
       
  3570             HBufC8* apIdBuffer = HBufC8::NewLC( 4 );
       
  3571 	        TPtr8 ptrIapIdBuf = apIdBuffer->Des();
       
  3572         	ptrIapIdBuf.Num( aIAPid );
       
  3573             conn.SetPropertyL( KNSmlIAPId, ptrIapIdBuf );
       
  3574             conn.UpdateL();
       
  3575             CleanupStack::PopAndDestroy( 2 ); //conn, apIdBuffer
       
  3576             retVal = KErrNone;
       
  3577             }
       
  3578         else
       
  3579             {
       
  3580             retVal = KErrNotFound;
       
  3581             }
       
  3582         CleanupStack::PopAndDestroy(); //transport
       
  3583         }
       
  3584     else
       
  3585         {
       
  3586         retVal = KErrNotFound;
       
  3587         }
       
  3588     CloseDSProfile();
       
  3589     CleanupStack::PopAndDestroy(); //connIdArray
       
  3590     return retVal;
       
  3591     }
       
  3592 
       
  3593 //------------------------------------------------------------------------------
       
  3594 //	CNSmlDSSettingsAdapter::GetMediumTypeL
       
  3595 //	The function checks the requested medium type and gets it UID.
       
  3596 //------------------------------------------------------------------------------
       
  3597 void CNSmlDSSettingsAdapter::GetMediumTypeL( const TInt aIntObj, 
       
  3598                                             TSmlTransportId& aMediumType )
       
  3599     {
       
  3600     if( aIntObj == EHttp|| aIntObj == ENone || aIntObj == EWsp)
       
  3601         {
       
  3602         aMediumType = KUidNSmlMediumTypeInternet.iUid;
       
  3603         return;
       
  3604         }
       
  3605     RArray<TSmlTransportId> transportIdArray;
       
  3606     CleanupClosePushL( transportIdArray );
       
  3607     iSyncSession.ListTransportsL( transportIdArray );
       
  3608     if ( transportIdArray.Find( KUidNSmlMediumTypeBluetooth.iUid ) != KErrNotFound )
       
  3609         {
       
  3610         aMediumType = KUidNSmlMediumTypeBluetooth.iUid;
       
  3611         }
       
  3612     else if ( transportIdArray.Find( KUidNSmlMediumTypeUSB.iUid ) != KErrNotFound )
       
  3613         {
       
  3614         aMediumType = KUidNSmlMediumTypeUSB.iUid;
       
  3615         }
       
  3616     else if ( transportIdArray.Find( KUidNSmlMediumTypeIrDA.iUid ) != KErrNotFound )
       
  3617         {
       
  3618         aMediumType = KUidNSmlMediumTypeIrDA.iUid;
       
  3619         }
       
  3620     CleanupStack::PopAndDestroy(); //transportIdArray
       
  3621     return;    
       
  3622     }
       
  3623 
       
  3624 
       
  3625 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
  3626 
       
  3627 //------------------------------------------------------------------------------
       
  3628 // TImplementationProxy ImplementationTable[]
       
  3629 //------------------------------------------------------------------------------
       
  3630 
       
  3631 #ifndef IMPLEMENTATION_PROXY_ENTRY
       
  3632 #define IMPLEMENTATION_PROXY_ENTRY(aUid, aFuncPtr)	{{aUid},(aFuncPtr)}
       
  3633 #endif
       
  3634 
       
  3635 const TImplementationProxy ImplementationTable[] = 
       
  3636     {
       
  3637 	IMPLEMENTATION_PROXY_ENTRY( KNSmlDSSettingsAdapterImplUid, CNSmlDSSettingsAdapter::NewL )
       
  3638     };
       
  3639 
       
  3640 //------------------------------------------------------------------------------
       
  3641 // TImplementationProxy* ImplementationGroupProxy()
       
  3642 //------------------------------------------------------------------------------
       
  3643 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount )
       
  3644     {
       
  3645 	_DBG_FILE("ImplementationGroupProxy() for CNSmlDSSettingsAdapter: begin");
       
  3646 
       
  3647     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
  3648 
       
  3649 	_DBG_FILE("ImplementationGroupProxy() for CNSmlDSSettingsAdapter: end");
       
  3650     return ImplementationTable;
       
  3651 	}
       
  3652 
       
  3653 
       
  3654 //--------------------------------------------------------------------
       
  3655 //TInt CNSmlDMSettingsAdapter::IsDSAccUriFormatMatchPredefined(const TDesC8 & aURI)
       
  3656 //
       
  3657 //-------------------------------------------------------------------
       
  3658 
       
  3659 TBool CNSmlDSSettingsAdapter::IsDSAccUriFormatMatchPredefined(const TDesC8 & aURI)
       
  3660 {
       
  3661 	
       
  3662 	// include strings for  tree for Bearer , DNS related Dynamic nodes . 
       
  3663 	
       
  3664 	if(aURI.Match(_L8("SyncML/DSAcc/DSId*"))  != KErrNotFound ||
       
  3665          aURI.Match(_L8("SyncML/DSAcc/DSId*/DB/CTId*"))  != KErrNotFound)
       
  3666 	{
       
  3667 		return ETrue;
       
  3668 	}
       
  3669 	else
       
  3670 	{
       
  3671 		return EFalse;
       
  3672 	}
       
  3673 	
       
  3674 	
       
  3675 }
       
  3676 
       
  3677 //--------------------------------------------------------------------
       
  3678 //TInt CNSmlDMSettingsAdapter::ConstructTreeL(const TDesC8& aURI)
       
  3679 //
       
  3680 //-------------------------------------------------------------------
       
  3681 
       
  3682 TInt CNSmlDSSettingsAdapter::ConstructTreeL(const TDesC8& aURI)
       
  3683 {
       
  3684 		TInt profileID = KErrNotFound;
       
  3685 RDebug::Print( _L("jshong FOTA : ConstructTreeL 1 ")) ;
       
  3686 		TBool notDBSet(EFalse);
       
  3687         if( iSyncSessionOpen == EFalse )
       
  3688             {
       
  3689             iSyncSession.OpenL();
       
  3690             iSyncSessionOpen = ETrue;
       
  3691             }
       
  3692         RArray<TSmlProfileId> profileIdArray;
       
  3693         CleanupClosePushL( profileIdArray );
       
  3694         TSmlUsageType usageType = ESmlDataSync;
       
  3695         iSyncSession.ListProfilesL( profileIdArray, usageType );
       
  3696 RDebug::Print( _L("jshong FOTA : ConstructTreeL 1-2 ") );
       
  3697 	    
       
  3698         for( TInt p = 0; p < profileIdArray.Count(); p++ )
       
  3699 		    {
       
  3700             TInt ddId = profileIdArray[p] ; // update remove KMAxDatasyncID - KMaxDataSyncID;
       
  3701 RDebug::Print( _L("jshong FOTA : ConstructTreeL 1-3 ") );
       
  3702             
       
  3703 		    _LIT8( Kprev, "DSId" );//  update changed from DMId to DSId
       
  3704 		    TBuf8<7> addNAME(Kprev); // DMIdnnn , nnn = profileid
       
  3705             TInt fixedProfId = profileIdArray[p] ; // update remove KMAxDatasyncID // - KMaxDataSyncID; //fit to 3 decimal
       
  3706 		    addNAME.AppendNumFixedWidth( fixedProfId, EDecimal, 3 ); 
       
  3707    		   	DBG_ARGS8( _S8("notInList: Id = %d Name %S"), p, &addNAME );
       
  3708    		   	RDebug::Print( _L("notInList: Id = %d Name %S"), p, &addNAME );
       
  3709 		    // KNSmlDMStart includes start text for URISeg
       
  3710 			    TBuf8<20> addURI; // SyncML/DMAcc/DMIdnnn , nnn = profileid
       
  3711 			    addURI.Append( KNSmlDSStart );
       
  3712 			    addURI.AppendNumFixedWidth( fixedProfId, EDecimal, 3 ); 
       
  3713 				TBuf8<3> addLUID;
       
  3714 	    		addLUID.Num( fixedProfId );
       
  3715 
       
  3716 			HBufC8* mapInfo = iCallBack->GetLuidAllocL(addURI);
       
  3717 RDebug::Print( _L("jshong FOTA : ConstructTreeL 1-4 addURI = %S"), &addURI );
       
  3718 					
       
  3719 						 if (mapInfo->Length() == 0)
       
  3720 						 {
       
  3721 						 	 iCallBack->SetMappingL(addURI,addLUID);
       
  3722 							 
       
  3723 RDebug::Print( _L("jshong FOTA : ConstructTreeL 1-5 ") );
       
  3724 						 	 	 
       
  3725 						 	 if(( aURI.Find(addURI) >= 0 ) && !notDBSet)
       
  3726                     			{ 
       
  3727                     				profileID = fixedProfId;
       
  3728                     			}
       
  3729                     			
       
  3730 						 	 // update , Update ../DB/CTId also 
       
  3731 						 	 	TInt retVal = OpenSyncSessionAndDSProfileL( fixedProfId, ESmlOpenRead );
       
  3732 						    if( retVal == KErrNone )
       
  3733 								{
       
  3734 							
       
  3735 RDebug::Print( _L("jshong FOTA : ConstructTreeL 2 ") );
       
  3736 						        
       
  3737 						 	 						 	 
       
  3738 						    RArray<TSmlTaskId> taskIdArray;
       
  3739 						    CleanupClosePushL( taskIdArray );
       
  3740 						    iDSProfile.ListTasksL( taskIdArray );
       
  3741 							if( taskIdArray.Count() == 0 )
       
  3742 								{
       
  3743 RDebug::Print( _L("jshong FOTA : ConstructTreeL 3 ")) ;
       
  3744 								CloseDSProfile();
       
  3745 								CleanupStack::PopAndDestroy();//taskIdArray
       
  3746 						    //	return KErrNotFound;
       
  3747 								}
       
  3748 							else
       
  3749 							{
       
  3750 								RSyncMLTask task;
       
  3751 RDebug::Print( _L("jshong FOTA : ConstructTreeL 4 ")) ;
       
  3752 
       
  3753 						    CleanupClosePushL( task );
       
  3754 						            
       
  3755 						    for ( TInt i = 0; i < taskIdArray.Count(); i++ )
       
  3756 								{			
       
  3757 								//	
       
  3758 								//	Check if ContentType -> Task ID on list
       
  3759 								//
       
  3760 								TInt ddId( 0 );
       
  3761 RDebug::Print( _L("jshong FOTA : ConstructTreeL 5 ")) ;
       
  3762 								
       
  3763 								task.OpenL( iDSProfile, taskIdArray[i] );
       
  3764 						        ddId = task.DataProvider();
       
  3765 						        task.Close();
       
  3766 								
       
  3767 									//Get Task ID
       
  3768 								//	addNAME.AppendNumFixedWidth( taskIdArray[i], EDecimal,3 ); 
       
  3769 RDebug::Print( _L("jshong FOTA : ConstructTreeL 6 ") );
       
  3770 							
       
  3771 									TBuf8<80> addDBURI;
       
  3772 									
       
  3773 									addDBURI.Append( addURI );
       
  3774 									_LIT8( KDB, "/DB" );// addDb also 
       
  3775 									addDBURI.Append( KDB );
       
  3776 									addDBURI.Append( Kprev2 );
       
  3777 									addDBURI.AppendNumFixedWidth( taskIdArray[i], EDecimal, 3 ); 
       
  3778 RDebug::Print( _L("jshong FOTA : ConstructTreeL 7 ")) ;
       
  3779 
       
  3780 									TBuf8<16> addDBLUID;
       
  3781 									addDBLUID.Num( ddId );
       
  3782 									HBufC8* mapInfo = iCallBack->GetLuidAllocL(addDBURI);
       
  3783 								 	if (mapInfo->Length() == 0)
       
  3784 						 			{
       
  3785 						 	 			iCallBack->SetMappingL(addDBURI,addDBLUID);
       
  3786 					 	 	 
       
  3787 						 	 			if( aURI.Find(addDBURI) >= 0 )
       
  3788                     					{ 
       
  3789                     						profileID = ddId;
       
  3790                     						notDBSet = ETrue;
       
  3791                     					}
       
  3792 						 			}							
       
  3793 								
       
  3794 								} //For
       
  3795 							CloseDSProfile();
       
  3796 							CleanupStack::PopAndDestroy(2);// task, taskIdArray
       
  3797 							}
       
  3798 							
       
  3799 						 //return KErrGeneral;	
       
  3800 								}	 
       
  3801 							else
       
  3802 							{
       
  3803 									CloseDSProfile();
       
  3804 						 }
       
  3805 						 
       
  3806 						 }
       
  3807 						 else
       
  3808 						 {
       
  3809 RDebug::Print( _L("jshong FOTA : ConstructTreeL 1-5 ") );
       
  3810 						 
       
  3811 						 	delete mapInfo;
       
  3812 						 }
       
  3813 						 
       
  3814 	    			
       
  3815     			}
       
  3816 	    	
       
  3817          CleanupStack::PopAndDestroy( 1 );//profileIdArray
       
  3818         return profileID;
       
  3819 }
       
  3820 // End of File
       
  3821