syncmlfw/ds/dsutils/dbcaps/src/NSmldbcapsSerializer.cpp
changeset 68 415c00f1675d
parent 0 b497e44ab2fc
equal deleted inserted replaced
63:e0c1916b8ddc 68:415c00f1675d
   342 	CNSmlDataStoreFormatFromDbCaps* self = new ( ELeave ) CNSmlDataStoreFormatFromDbCaps();
   342 	CNSmlDataStoreFormatFromDbCaps* self = new ( ELeave ) CNSmlDataStoreFormatFromDbCaps();
   343 	CleanupStack::PushL( self );
   343 	CleanupStack::PushL( self );
   344 	const sml_devinf_datastore_s* dds = aDbCaps.Datastore();
   344 	const sml_devinf_datastore_s* dds = aDbCaps.Datastore();
   345 	
   345 	
   346 	//display name
   346 	//display name
   347 	NSmlUnicodeConverter::HBufC16InUnicodeLC( 
   347 	if(dds)
   348 		TNSmlDbCapsSerializer::SafePtr( dds->displayname ), self->iDisplayName );
   348 	    {
   349 	CleanupStack::Pop( self->iDisplayName ); // self->iDisplayName
   349         NSmlUnicodeConverter::HBufC16InUnicodeLC( 
       
   350                 TNSmlDbCapsSerializer::SafePtr( dds->displayname ), self->iDisplayName );
       
   351         CleanupStack::Pop( self->iDisplayName ); // self->iDisplayName
       
   352 	    }
   350 	
   353 	
   351 	//sync types
   354 	//sync types
   352 	TSmlSyncTypeMask& synctype( self->iSyncTypeMask );
   355 	TSmlSyncTypeMask& synctype( self->iSyncTypeMask );
   353 			
   356 			
   354 	if ( aDbCaps.SupportsSyncType( CNSmlDbCaps::ETwoWaySync ) )
   357 	if ( aDbCaps.SupportsSyncType( CNSmlDbCaps::ETwoWaySync ) )
   402 		}
   405 		}
   403 	else
   406 	else
   404 		{
   407 		{
   405 		synctype.SetNotSupported( ESmlRefreshFromClient );
   408 		synctype.SetNotSupported( ESmlRefreshFromClient );
   406 		}
   409 		}
   407 	
   410 	if (dds)
   408 	if ( dds->dsmem )
   411         {
   409 		{
   412         if ( dds->dsmem )
   410 		//max size
   413             {
   411 		if ( dds->dsmem->maxmem )
   414             //max size
   412 			{
   415             if ( dds->dsmem->maxmem )
   413 			TLex8 lex( dds->dsmem->maxmem->Data() );
   416                 {
   414 			User::LeaveIfError( lex.Val( self->iMaxSize, EDecimal ) );
   417                 TLex8 lex( dds->dsmem->maxmem->Data() );
   415 			self->iFlags |= KSmlDataStore_HasMaxSize;
   418                 User::LeaveIfError( lex.Val( self->iMaxSize, EDecimal ) );
   416 			}
   419                 self->iFlags |= KSmlDataStore_HasMaxSize;
   417 		
   420                 }
   418 		//max items
   421             
   419 		if ( dds->dsmem->maxid )
   422             //max items
   420 			{
   423             if ( dds->dsmem->maxid )
   421 			TLex8 lex( dds->dsmem->maxid->Data() );
   424                 {
   422 			User::LeaveIfError( lex.Val( self->iMaxItems, EDecimal ) );
   425                 TLex8 lex( dds->dsmem->maxid->Data() );
   423 			self->iFlags |= KSmlDataStore_HasMaxItems;
   426                 User::LeaveIfError( lex.Val( self->iMaxItems, EDecimal ) );
   424 			}
   427                 self->iFlags |= KSmlDataStore_HasMaxItems;
   425 		}
   428                 }
   426 	
   429             }
   427 	//options
   430         
   428 	if ( dds->supportHierarchicalSync )
   431         
   429 		{
   432         //options
   430 		self->iFlags |= KSmlDataStore_Hierarchical;
   433         if ( dds->supportHierarchicalSync )
   431 		}
   434             {
       
   435             self->iFlags |= KSmlDataStore_Hierarchical;
       
   436             }
       
   437         }
   432 	
   438 	
   433 	//filter caps
   439 	//filter caps
   434 	const sml_devinf_filtercaplist_s* filterList = aDbCaps.FilterCapsList();
   440 	const sml_devinf_filtercaplist_s* filterList = aDbCaps.FilterCapsList();
   435 	
   441 	
   436 	for ( ; filterList; filterList = filterList->next )
   442 	for ( ; filterList; filterList = filterList->next )
   448 	RPointerArray<CSmlMimeFormat> mimeFormatArray;
   454 	RPointerArray<CSmlMimeFormat> mimeFormatArray;
   449 	CleanupClosePushL( mimeFormatArray );
   455 	CleanupClosePushL( mimeFormatArray );
   450 	// First search all mime types that server supports at receiving
   456 	// First search all mime types that server supports at receiving
   451 	// RX-pref
   457 	// RX-pref
   452 	CSmlMimeFormat* tempFormatRX = CSmlMimeFormat::NewLC();
   458 	CSmlMimeFormat* tempFormatRX = CSmlMimeFormat::NewLC();
   453 	const TPtrC8& ctTypeRX = TNSmlDbCapsSerializer::SafePtr( dds->rxpref->cttype );
   459     if( dds )
   454 	const TPtrC8& verCtRX = TNSmlDbCapsSerializer::SafePtr( dds->rxpref->verct );
   460         {
   455 	if ( ctTypeRX.Compare( KNullDesC8 ) != 0 && verCtRX.Compare( KNullDesC8 ) != 0 )
   461         const TPtrC8& ctTypeRX = TNSmlDbCapsSerializer::SafePtr( dds->rxpref->cttype );
   456 		{
   462         const TPtrC8& verCtRX = TNSmlDbCapsSerializer::SafePtr( dds->rxpref->verct );
   457 		RStringF mimeFormatRX = aStringPool.OpenFStringL( ctTypeRX );
   463                     
   458 		RStringF mimeVersionRX = aStringPool.OpenFStringL( verCtRX );
   464         if ( ctTypeRX.Compare( KNullDesC8 ) != 0 && verCtRX.Compare( KNullDesC8 ) != 0 )
   459 		tempFormatRX->SetMimeTypeL( mimeFormatRX );
   465             {
   460 		tempFormatRX->SetMimeVersionL( mimeVersionRX );
   466             RStringF mimeFormatRX = aStringPool.OpenFStringL( ctTypeRX );
   461 		mimeFormatArray.AppendL( tempFormatRX );
   467             RStringF mimeVersionRX = aStringPool.OpenFStringL( verCtRX );
   462 		CleanupStack::Pop(); // tempFormatRX
   468             tempFormatRX->SetMimeTypeL( mimeFormatRX );
   463 		}
   469             tempFormatRX->SetMimeVersionL( mimeVersionRX );
   464 	else
   470             mimeFormatArray.AppendL( tempFormatRX );
   465 		{
   471             CleanupStack::Pop(); // tempFormatRX
   466 		CleanupStack::PopAndDestroy(); // tempFormatRX
   472             }
   467 		}
   473         else
   468 	// RXs
   474             {
   469 	if ( dds )
   475             CleanupStack::PopAndDestroy(); // tempFormatRX
   470 		{
   476             }
   471 		SmlDevInfXmitListPtr_t rx = dds->rx;
   477         // RXs
   472 		for ( ; rx ; rx = rx->next )
   478         
   473 			{
   479             SmlDevInfXmitListPtr_t rx = dds->rx;
   474 			CSmlMimeFormat* tempFormat = CSmlMimeFormat::NewLC();
   480             for ( ; rx ; rx = rx->next )
   475 			const TPtrC8& ctType = TNSmlDbCapsSerializer::SafePtr( rx->data->cttype );
   481                 {
   476 			const TPtrC8& verCt = TNSmlDbCapsSerializer::SafePtr( rx->data->verct );
   482                 CSmlMimeFormat* tempFormat = CSmlMimeFormat::NewLC();
   477 			if ( ctType.Compare( KNullDesC8 ) != 0 && verCt.Compare( KNullDesC8 ) != 0 )
   483                 const TPtrC8& ctType = TNSmlDbCapsSerializer::SafePtr( rx->data->cttype );
   478 				{
   484                 const TPtrC8& verCt = TNSmlDbCapsSerializer::SafePtr( rx->data->verct );
   479 				RStringF mimeFormat = aStringPool.OpenFStringL( ctType );
   485                 if ( ctType.Compare( KNullDesC8 ) != 0 && verCt.Compare( KNullDesC8 ) != 0 )
   480 				RStringF mimeVersion = aStringPool.OpenFStringL( verCt );
   486                     {
   481 				tempFormat->SetMimeTypeL( mimeFormat );
   487                     RStringF mimeFormat = aStringPool.OpenFStringL( ctType );
   482 				tempFormat->SetMimeVersionL( mimeVersion );
   488                     RStringF mimeVersion = aStringPool.OpenFStringL( verCt );
   483 				mimeFormatArray.AppendL( tempFormat );
   489                     tempFormat->SetMimeTypeL( mimeFormat );
   484 				CleanupStack::Pop(); // tempFormat
   490                     tempFormat->SetMimeVersionL( mimeVersion );
   485 				}
   491                     mimeFormatArray.AppendL( tempFormat );
   486 			else
   492                     CleanupStack::Pop(); // tempFormat
   487 				{
   493                     }
   488 				CleanupStack::PopAndDestroy(); // tempFormat
   494                 else
   489 				}
   495                     {
   490 			}
   496                     CleanupStack::PopAndDestroy(); // tempFormat
   491 		}
   497                     }
   492 	
   498                 }
   493 	const sml_devinf_ctcaplist_s*  ctCapList = dds->ctcap;
   499             
   494 	if ( ctCapList == 0 )
   500         
   495 		{
   501         const sml_devinf_ctcaplist_s*  ctCapList = dds->ctcap;
   496 		ctCapList = aDbCaps.CtCaps();
   502         if ( ctCapList == 0 )
   497 		}
   503             {
   498 	// Then add CTCaps to correct mime types
   504             ctCapList = aDbCaps.CtCaps();
   499 	if ( ctCapList != 0 )
   505             }
   500 	    {    
   506         // Then add CTCaps to correct mime types
   501         for (; ctCapList; ctCapList = ctCapList->next )
   507         if ( ctCapList != 0 )
   502     		{
   508             {    
   503     		const SmlDevInfCtCapPtr_t ctCap = ctCapList->data;
   509             for (; ctCapList; ctCapList = ctCapList->next )
   504     		if ( ctCap->cttype->Data() == KNSmlFolderType )
   510                 {
   505     			{
   511                 const SmlDevInfCtCapPtr_t ctCap = ctCapList->data;
   506     			SmlDevInfPropertyListPtr_t dipl = ctCap->property;
   512                 if ( ctCap->cttype->Data() == KNSmlFolderType )
   507     			for ( ; dipl; dipl = dipl->next )
   513                     {
   508     				{
   514                     SmlDevInfPropertyListPtr_t dipl = ctCap->property;
   509     				const SmlDevInfPropertyPtr_t dip = dipl->data;
   515                     for ( ; dipl; dipl = dipl->next )
   510     				if ( dip )
   516                         {
   511     					{
   517                         const SmlDevInfPropertyPtr_t dip = dipl->data;
   512     					CSmlDataProperty *temppoint = CNSmlDataPropertyFromDbCaps::NewLC( aStringPool, dip );
   518                         if ( dip )
   513     					self->iFolderProperties.AppendL( temppoint );
   519                             {
   514     					CleanupStack::Pop(); //  temppoint
   520                             CSmlDataProperty *temppoint = CNSmlDataPropertyFromDbCaps::NewLC( aStringPool, dip );
   515     					}
   521                             self->iFolderProperties.AppendL( temppoint );
   516     				}
   522                             CleanupStack::Pop(); //  temppoint
   517     			}
   523                             }
   518     		else
   524                         }
   519     			{
   525                     }
   520     			for ( TInt j(0); j < mimeFormatArray.Count(); j++ )
   526                 else
   521     			    {
   527                     {
   522     			    if ( mimeFormatArray[j]->MimeType().DesC().Compare( ctCap->cttype->Data() ) == 0 )
   528                     for ( TInt j(0); j < mimeFormatArray.Count(); j++ )
   523     			        {
   529                         {
   524     			        // Mime version is only in rx-pref or in rx so it must be copied to new mime format
   530                         if ( mimeFormatArray[j]->MimeType().DesC().Compare( ctCap->cttype->Data() ) == 0 )
   525     			        CSmlMimeFormat* temppoint = CNSmlMimeFormatFromDbCaps::NewLC( aStringPool, *ctCap );
   531                             {
   526     			        RStringF newMimeVersion = aStringPool.OpenFStringL( mimeFormatArray[j]->MimeVersion().DesC() );
   532                             // Mime version is only in rx-pref or in rx so it must be copied to new mime format
   527     			        temppoint->SetMimeVersionL( newMimeVersion );
   533                             CSmlMimeFormat* temppoint = CNSmlMimeFormatFromDbCaps::NewLC( aStringPool, *ctCap );
   528     			        delete mimeFormatArray[j];
   534                             RStringF newMimeVersion = aStringPool.OpenFStringL( mimeFormatArray[j]->MimeVersion().DesC() );
   529     			        mimeFormatArray[j] = NULL;
   535                             temppoint->SetMimeVersionL( newMimeVersion );
   530     			        mimeFormatArray[j] = temppoint;
   536                             delete mimeFormatArray[j];
   531     			        CleanupStack::Pop(); //  temppoint
   537                             mimeFormatArray[j] = NULL;
   532     			        }
   538                             mimeFormatArray[j] = temppoint;
   533     			    }
   539                             CleanupStack::Pop(); //  temppoint
   534     			}
   540                             }
   535     		}
   541                         }
   536 	    }
   542                     }
       
   543                 }
       
   544             }
       
   545         }
   537 	self->SetMimeFormatsL( mimeFormatArray );
   546 	self->SetMimeFormatsL( mimeFormatArray );
   538 	mimeFormatArray.ResetAndDestroy();
   547 	mimeFormatArray.ResetAndDestroy();
   539 	CleanupStack::PopAndDestroy(); // mimeFormatArray
   548 	CleanupStack::PopAndDestroy(); // mimeFormatArray
   540 	return self;
   549 	return self;
   541 	}
   550 	}