emailservices/emailstore/message_store/client/src/MsgStorePropertyContainer.cpp
changeset 0 8466d47a6819
child 8 e1b6206813b4
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Message store property container client implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "MsgStorePropertyContainer.h"
       
    21 //<cmail>
       
    22 #include "DebugLogMacros.h"
       
    23 #include "MsgStorePropertyKeys.h"
       
    24 //</cmail>
       
    25 #include "PropertiesSerializer.h"
       
    26 
       
    27 // ===========
       
    28 // LOCAL TYPES
       
    29 // ===========
       
    30 
       
    31 // --------------------------
       
    32 // CMsgStorePropertyContainer
       
    33 // --------------------------
       
    34 
       
    35 // ==========================================================================
       
    36 // FUNCTION: NewL
       
    37 // ==========================================================================
       
    38 EXPORT_C CMsgStorePropertyContainer* CMsgStorePropertyContainer::NewL()
       
    39 	{
       
    40     CMsgStorePropertyContainer* self = new( ELeave ) CMsgStorePropertyContainer();
       
    41     return self;
       
    42 	} // end NewL
       
    43 
       
    44 // ==========================================================================
       
    45 // FUNCTION: Constructor
       
    46 // ==========================================================================
       
    47 CMsgStorePropertyContainer::CMsgStorePropertyContainer()
       
    48 	{
       
    49 	iId       = KMsgStoreInvalidId;
       
    50 	iParentId = KMsgStoreInvalidId;
       
    51 	} // end constructor
       
    52 	
       
    53 // ==========================================================================
       
    54 // FUNCTION: Destructor
       
    55 // ==========================================================================
       
    56 CMsgStorePropertyContainer::~CMsgStorePropertyContainer()
       
    57 	{
       
    58 	iProperties.ResetAndDestroy();
       
    59 	} // end destructor
       
    60 	
       
    61 // ==========================================================================
       
    62 // FUNCTION: Id
       
    63 // ==========================================================================
       
    64 EXPORT_C TMsgStoreId CMsgStorePropertyContainer::Id() const
       
    65 	{
       
    66 	return iId;
       
    67 	} // end Id
       
    68 
       
    69 // ==========================================================================
       
    70 // FUNCTION: ParentId
       
    71 // ==========================================================================
       
    72 EXPORT_C TMsgStoreId CMsgStorePropertyContainer::ParentId() const
       
    73 	{
       
    74 	return iParentId;
       
    75 	} // end ParentId
       
    76 
       
    77 // ==========================================================================
       
    78 // FUNCTION: PropertyCount
       
    79 // ==========================================================================
       
    80 EXPORT_C TUint CMsgStorePropertyContainer::PropertyCount() const
       
    81 	{
       
    82 	return iProperties.Count();
       
    83 	} // end PropertyCount
       
    84 	
       
    85 // ==========================================================================
       
    86 // FUNCTION: PropertyNameL
       
    87 // ==========================================================================
       
    88 EXPORT_C const TDesC8& CMsgStorePropertyContainer::PropertyNameL( TUint aPropertyIndex ) const
       
    89 	{
       
    90 	ValidateIndexL( aPropertyIndex );
       
    91 
       
    92 	return iProperties[aPropertyIndex]->iName;
       
    93 	} // end PropertyNameL
       
    94 
       
    95 // ==========================================================================
       
    96 // FUNCTION: PropertyTypeL
       
    97 // ==========================================================================
       
    98 EXPORT_C TMsgStorePropertyValueType CMsgStorePropertyContainer::PropertyTypeL( TUint aPropertyIndex ) const
       
    99 	{
       
   100 	ValidateIndexL( aPropertyIndex );
       
   101 	
       
   102 	return iProperties[aPropertyIndex]->iType;
       
   103 	} // end PropertyTypeL
       
   104 
       
   105 // ==========================================================================
       
   106 // FUNCTION: DoAddPropertyL
       
   107 // ==========================================================================
       
   108 TUint CMsgStorePropertyContainer::DoAddPropertyL( TMsgStorePropertyValueType aType, const TDesC8& aName, const TDesC8& aValue )	
       
   109 	{
       
   110 	ValidateLengthsL( aName.Length(), aValue.Length() );
       
   111 	
       
   112 	TMsgStoreProperty* newNode = new(ELeave) TMsgStoreProperty;
       
   113 	CleanupStack::PushL( newNode );
       
   114 	
       
   115 	newNode->iName.CreateL( aName );
       
   116     newNode->iValue.CreateL( aValue );	
       
   117 	newNode->iType = aType;
       
   118 	
       
   119 	iProperties.AppendL( newNode );
       
   120 	
       
   121 	CleanupStack::Pop( newNode );
       
   122 	
       
   123 	return iProperties.Count() - 1;
       
   124 	} // end DoAddPropertyL
       
   125 	
       
   126 // ==========================================================================
       
   127 // FUNCTION: AddPropertyL
       
   128 // ==========================================================================
       
   129 EXPORT_C TUint CMsgStorePropertyContainer::AddPropertyL( const TDesC8& aName, TBool aValue )	
       
   130     {
       
   131 	TPckg<TBool> valuePckg( aValue );
       
   132 
       
   133     return DoAddPropertyL( EMsgStoreTypeBool, aName, valuePckg );	
       
   134 	} // end AddPropertyL
       
   135 
       
   136 // ==========================================================================
       
   137 // FUNCTION: AddPropertyL
       
   138 // ==========================================================================
       
   139 EXPORT_C TUint CMsgStorePropertyContainer::AddPropertyL( const TDesC8& aName, TUint32 aValue )
       
   140 	{
       
   141 	TPckg<TUint> valuePckg( aValue );
       
   142 
       
   143     return DoAddPropertyL( EMsgStoreTypeUint32, aName, valuePckg );	
       
   144 	} // end AddPropertyL
       
   145 
       
   146 // ==========================================================================
       
   147 // FUNCTION: AddPropertyL
       
   148 // ==========================================================================
       
   149 EXPORT_C TUint CMsgStorePropertyContainer::AddPropertyL( const TDesC8& aName, const TTime& aValue )
       
   150 	{
       
   151 	TPckg<TInt64> valuePckg( aValue.Int64() );
       
   152 
       
   153     return DoAddPropertyL( EMsgStoreTypeTime, aName, valuePckg );	
       
   154 	} // end AddPropertyL
       
   155 
       
   156 // ==========================================================================
       
   157 // FUNCTION: AddPropertyL
       
   158 // ==========================================================================
       
   159 EXPORT_C TUint CMsgStorePropertyContainer::AddPropertyL( const TDesC8& aName, const RMsgStoreAddress& aValue )
       
   160 	{
       
   161 	CMsgStorePropertyContainer* props = CMsgStorePropertyContainer::NewL();
       
   162 	CleanupStack::PushL( props );
       
   163 	
       
   164 	props->AddPropertyL( KMsgStorePropertyEmailAddress, aValue.iEmailAddress );
       
   165 	props->AddPropertyL( KMsgStorePropertyDisplayName, aValue.iDisplayName );
       
   166 	
       
   167     TUint index = AddPropertyL( aName, *props, EMsgStoreTypeAddress );	
       
   168     
       
   169     CleanupStack::PopAndDestroy( props );
       
   170     return index;
       
   171 	} // end AddPropertyL
       
   172 
       
   173 // ==========================================================================
       
   174 // FUNCTION: AddPropertyL
       
   175 // ==========================================================================
       
   176 EXPORT_C TUint CMsgStorePropertyContainer::AddPropertyL( const TDesC8& aName, const TDesC8& aValue )
       
   177 	{
       
   178     return DoAddPropertyL( EMsgStoreTypeDes8, aName, aValue );	
       
   179 	} // end AddPropertyL
       
   180 	
       
   181 // ==========================================================================
       
   182 // FUNCTION: AddPropertyL
       
   183 // ==========================================================================
       
   184 EXPORT_C TUint CMsgStorePropertyContainer::AddPropertyL( const TDesC8& aName, const TDesC& aValue )
       
   185 	{
       
   186 	const TUint8* valuePtr     = reinterpret_cast<const TUint8*>( aValue.Ptr() );
       
   187 	TUint         valueLength = aValue.Length() * 2;
       
   188 	
       
   189     TPtrC8 valueDes8( valuePtr, valueLength );	
       
   190 	
       
   191     TUint index = DoAddPropertyL( EMsgStoreTypeDes, aName, valueDes8 );	
       
   192     
       
   193 	const TUint16* valuePtr16 = reinterpret_cast<const TUint16*>( iProperties[index]->iValue.Ptr() );
       
   194 	
       
   195 	iProperties[index]->iValue16.Set( valuePtr16, aValue.Length() );
       
   196 	
       
   197     return index;
       
   198 	} // end AddPropertyL
       
   199 
       
   200 // ==========================================================================
       
   201 // FUNCTION: AddPropertyL
       
   202 // ==========================================================================
       
   203 EXPORT_C TUint CMsgStorePropertyContainer::AddPropertyL( const TDesC8& aName, const CMsgStorePropertyContainer& aContainer )
       
   204 	{
       
   205 	return AddPropertyL( aName, aContainer, EMsgStoreTypeContainer );
       
   206 	} // end AddPropertyL
       
   207 
       
   208 
       
   209 // ==========================================================================
       
   210 // FUNCTION: DoUpdatePropertyL
       
   211 // ==========================================================================
       
   212 void CMsgStorePropertyContainer::DoUpdatePropertyL( TUint aPropertyIndex, TMsgStorePropertyValueType aType, const TDesC8& aValue )
       
   213 	{
       
   214 	// An update cannot change the type of the property.
       
   215 	ValidateIndexAndTypeL( aPropertyIndex, aType );
       
   216 	ValidateValueLengthL( aValue.Length() );	
       
   217 
       
   218     iProperties[aPropertyIndex]->iValue.Close();
       
   219     
       
   220     iProperties[aPropertyIndex]->iValue.CreateL( aValue );
       
   221     iProperties[aPropertyIndex]->iType = aType;
       
   222 	} // end DoUpdatePropertyL
       
   223 
       
   224 // ==========================================================================
       
   225 // FUNCTION: UpdatePropertyL
       
   226 // ==========================================================================
       
   227 EXPORT_C void CMsgStorePropertyContainer::UpdatePropertyL( TUint aPropertyIndex, const TDesC8& aValue )
       
   228 	{
       
   229 	return DoUpdatePropertyL( aPropertyIndex, EMsgStoreTypeDes8, aValue );
       
   230 	}  // end UpdatePropertyL
       
   231 
       
   232 // ==========================================================================
       
   233 // FUNCTION: UpdatePropertyL
       
   234 // ==========================================================================
       
   235 EXPORT_C void CMsgStorePropertyContainer::UpdatePropertyL( TUint aPropertyIndex, const TDesC& aValue )
       
   236 	{
       
   237 	const TUint8* valuePtr     = reinterpret_cast<const TUint8*>( aValue.Ptr() );
       
   238 	TUint         valueLength = aValue.Length() * 2;
       
   239 	
       
   240     TPtrC8 valueDes8( valuePtr, valueLength );	
       
   241 	
       
   242 	DoUpdatePropertyL( aPropertyIndex, EMsgStoreTypeDes, valueDes8 );
       
   243 	
       
   244 	const TUint16* valuePtr16 = reinterpret_cast<const TUint16*>( iProperties[aPropertyIndex]->iValue.Ptr() );
       
   245 
       
   246 	iProperties[aPropertyIndex]->iValue16.Set( valuePtr16, aValue.Length() );
       
   247 	} // end 
       
   248 
       
   249 // ==========================================================================
       
   250 // FUNCTION: UpdatePropertyL
       
   251 // ==========================================================================
       
   252 EXPORT_C void CMsgStorePropertyContainer::UpdatePropertyL( TUint aPropertyIndex, TUint32 aValue )
       
   253 	{
       
   254 	TPckg<TUint> valuePckg( aValue );
       
   255 
       
   256 	DoUpdatePropertyL( aPropertyIndex, EMsgStoreTypeUint32, valuePckg );
       
   257 	} // end 
       
   258 
       
   259 // ==========================================================================
       
   260 // FUNCTION: UpdatePropertyL
       
   261 // ==========================================================================
       
   262 EXPORT_C void CMsgStorePropertyContainer::UpdatePropertyL( TUint aPropertyIndex, const TTime& aValue )
       
   263 	{
       
   264 	TPckg<TInt64> valuePckg( aValue.Int64() );
       
   265 
       
   266 	DoUpdatePropertyL( aPropertyIndex, EMsgStoreTypeTime, valuePckg );
       
   267 	} // end 
       
   268 
       
   269 // ==========================================================================
       
   270 // FUNCTION: UpdatePropertyL
       
   271 // ==========================================================================
       
   272 EXPORT_C void CMsgStorePropertyContainer::UpdatePropertyL( TUint aPropertyIndex, const RMsgStoreAddress& aValue )
       
   273 	{
       
   274 	CMsgStorePropertyContainer* props = CMsgStorePropertyContainer::NewL();
       
   275 	CleanupStack::PushL( props );
       
   276 	
       
   277 	props->AddPropertyL( KMsgStorePropertyEmailAddress, aValue.iEmailAddress );
       
   278 	props->AddPropertyL( KMsgStorePropertyDisplayName, aValue.iDisplayName );
       
   279 	
       
   280     UpdatePropertyL( aPropertyIndex, *props, EMsgStoreTypeAddress );	
       
   281     
       
   282     CleanupStack::PopAndDestroy( props );
       
   283 	} // end 
       
   284 
       
   285 // ==========================================================================
       
   286 // FUNCTION: UpdatePropertyL
       
   287 // ==========================================================================
       
   288 EXPORT_C void CMsgStorePropertyContainer::UpdatePropertyL( TUint aPropertyIndex, TBool aValue )
       
   289 	{
       
   290 	TPckg<TBool> valuePckg( aValue );
       
   291 
       
   292 	DoUpdatePropertyL( aPropertyIndex, EMsgStoreTypeBool, valuePckg );
       
   293 	} // end UpdatePropertyL
       
   294 
       
   295 // ==========================================================================
       
   296 // FUNCTION: UpdatePropertyL
       
   297 // ==========================================================================
       
   298 EXPORT_C void CMsgStorePropertyContainer::UpdatePropertyL( TUint aPropertyIndex, const CMsgStorePropertyContainer& aContainer )
       
   299 	{
       
   300 	UpdatePropertyL( aPropertyIndex, aContainer, EMsgStoreTypeContainer );
       
   301 	} // end UpdatePropertyL
       
   302 
       
   303 // ==========================================================================
       
   304 // FUNCTION: AddOrUpdatePropertyL
       
   305 // ==========================================================================
       
   306 EXPORT_C TUint CMsgStorePropertyContainer::AddOrUpdatePropertyL( const TDesC8& aName, TBool aValue )
       
   307 	{
       
   308 	TUint index;
       
   309 	if( FindProperty( aName, index ) )
       
   310 		{
       
   311 		UpdatePropertyL( index, aValue );
       
   312 		}
       
   313 	else
       
   314 		{
       
   315 		index = AddPropertyL( aName, aValue );
       
   316 		} // end if
       
   317 		
       
   318 	return index;
       
   319 	} // end AddOrUpdatePropertyL
       
   320 
       
   321 // ==========================================================================
       
   322 // FUNCTION: AddOrUpdatePropertyL
       
   323 // ==========================================================================
       
   324 EXPORT_C TUint CMsgStorePropertyContainer::AddOrUpdatePropertyL( const TDesC8& aName, TUint32 aValue )
       
   325 	{
       
   326 	TUint index;
       
   327 	if( FindProperty( aName, index ) )
       
   328 		{
       
   329 		UpdatePropertyL( index, aValue );
       
   330 		}
       
   331 	else
       
   332 		{
       
   333 		index = AddPropertyL( aName, aValue );
       
   334 		} // end if
       
   335 		
       
   336 	return index;
       
   337 	} // end AddOrUpdatePropertyL
       
   338 
       
   339 // ==========================================================================
       
   340 // FUNCTION: AddOrUpdatePropertyL
       
   341 // ==========================================================================
       
   342 EXPORT_C TUint CMsgStorePropertyContainer::AddOrUpdatePropertyL( const TDesC8& aName, const TTime& aValue )
       
   343 	{
       
   344 	TUint index;
       
   345 	if( FindProperty( aName, index ) )
       
   346 		{
       
   347 		UpdatePropertyL( index, aValue );
       
   348 		}
       
   349 	else
       
   350 		{
       
   351 		index = AddPropertyL( aName, aValue );
       
   352 		} // end if
       
   353 		
       
   354 	return index;
       
   355 	} // end AddOrUpdatePropertyL
       
   356 
       
   357 // ==========================================================================
       
   358 // FUNCTION: AddOrUpdatePropertyL
       
   359 // ==========================================================================
       
   360 EXPORT_C TUint CMsgStorePropertyContainer::AddOrUpdatePropertyL( const TDesC8& aName, const RMsgStoreAddress& aValue )
       
   361 	{
       
   362 	TUint index;
       
   363 	if( FindProperty( aName, index ) )
       
   364 		{
       
   365 		UpdatePropertyL( index, aValue );
       
   366 		}
       
   367 	else
       
   368 		{
       
   369 		index = AddPropertyL( aName, aValue );
       
   370 		} // end if
       
   371 		
       
   372 	return index;
       
   373 	} // end AddOrUpdatePropertyL
       
   374 
       
   375 // ==========================================================================
       
   376 // FUNCTION: AddOrUpdatePropertyL
       
   377 // ==========================================================================
       
   378 EXPORT_C TUint CMsgStorePropertyContainer::AddOrUpdatePropertyL( const TDesC8& aName, const TDesC8& aValue )
       
   379 	{
       
   380 	TUint index;
       
   381 	if( FindProperty( aName, index ) )
       
   382 		{
       
   383 		UpdatePropertyL( index, aValue );
       
   384 		}
       
   385 	else
       
   386 		{
       
   387 		index = AddPropertyL( aName, aValue );
       
   388 		} // end if
       
   389 		
       
   390 	return index;
       
   391 	} // end AddOrUpdatePropertyL
       
   392 
       
   393 // ==========================================================================
       
   394 // FUNCTION: AddOrUpdatePropertyL
       
   395 // ==========================================================================
       
   396 EXPORT_C TUint CMsgStorePropertyContainer::AddOrUpdatePropertyL( const TDesC8& aName, const TDesC& aValue )
       
   397 	{
       
   398 	TUint index;
       
   399 	if( FindProperty( aName, index ) )
       
   400 		{
       
   401 		UpdatePropertyL( index, aValue );
       
   402 		}
       
   403 	else
       
   404 		{
       
   405 		index = AddPropertyL( aName, aValue );
       
   406 		} // end if
       
   407 		
       
   408 	return index;
       
   409 	} // end AddOrUpdatePropertyL
       
   410 
       
   411 // ==========================================================================
       
   412 // FUNCTION: AddOrUpdatePropertyL
       
   413 // ==========================================================================
       
   414 EXPORT_C TUint CMsgStorePropertyContainer::AddOrUpdatePropertyL( const TDesC8& aName, const CMsgStorePropertyContainer& aContainer )
       
   415 	{
       
   416 	TUint index;
       
   417 	if( FindProperty( aName, index ) )
       
   418 		{
       
   419 		UpdatePropertyL( index, aContainer );
       
   420 		}
       
   421 	else
       
   422 		{
       
   423 		index = AddPropertyL( aName, aContainer );
       
   424 		} // end if
       
   425 		
       
   426 	return index;
       
   427 	} // end AddOrUpdatePropertyL
       
   428 	
       
   429 // ==========================================================================
       
   430 // FUNCTION: PropertyValueDes8L
       
   431 // ==========================================================================
       
   432 EXPORT_C const TDesC8& CMsgStorePropertyContainer::PropertyValueDes8L( TUint aPropertyIndex ) const
       
   433 	{
       
   434 	ValidateIndexAndTypeL( aPropertyIndex, EMsgStoreTypeDes8 );
       
   435 
       
   436 	return iProperties[aPropertyIndex]->iValue;
       
   437 	} // end PropertyValueDes8L
       
   438 
       
   439 // ==========================================================================
       
   440 // FUNCTION: PropertyValueDesL
       
   441 // ==========================================================================
       
   442 EXPORT_C const TDesC& CMsgStorePropertyContainer::PropertyValueDesL( TUint aPropertyIndex ) const
       
   443 	{
       
   444 	ValidateIndexAndTypeL( aPropertyIndex, EMsgStoreTypeDes );
       
   445 	
       
   446 	return iProperties[aPropertyIndex]->iValue16;
       
   447 	} // end PropertyValueDesL
       
   448 
       
   449 // ==========================================================================
       
   450 // FUNCTION: PropertyValueUint32L
       
   451 // ==========================================================================
       
   452 EXPORT_C TUint32 CMsgStorePropertyContainer::PropertyValueUint32L( TUint aPropertyIndex ) const
       
   453 	{
       
   454 	ValidateIndexAndTypeL( aPropertyIndex, EMsgStoreTypeUint32 );
       
   455 
       
   456 	TPckgBuf<TUint> intValue;
       
   457 
       
   458 	TPtrC8 des8( iProperties[aPropertyIndex]->iValue.Ptr(), iProperties[aPropertyIndex]->iValue.Length() );
       
   459 	
       
   460 	intValue.Copy( des8 );
       
   461 	
       
   462 	return intValue();
       
   463 	} // end PropertyValueUint32L
       
   464 
       
   465 // ==========================================================================
       
   466 // FUNCTION: PropertyValueTimeL
       
   467 // ==========================================================================
       
   468 EXPORT_C void CMsgStorePropertyContainer::PropertyValueTimeL( TUint aPropertyIndex, TTime& aTime ) const
       
   469 	{
       
   470 	ValidateIndexAndTypeL( aPropertyIndex, EMsgStoreTypeTime );
       
   471 
       
   472 	TPckgBuf<TInt64> int64Value;
       
   473 
       
   474 	TPtrC8 des8( iProperties[aPropertyIndex]->iValue.Ptr(), iProperties[aPropertyIndex]->iValue.Length() );
       
   475 	
       
   476 	int64Value.Copy( des8 );
       
   477 	
       
   478 	aTime = int64Value();
       
   479 	} // end PropertyValueTimeL
       
   480 
       
   481 // ==========================================================================
       
   482 // FUNCTION: PropertyValueAddressL
       
   483 // ==========================================================================
       
   484 EXPORT_C void CMsgStorePropertyContainer::PropertyValueAddressL( TUint aPropertyIndex, RMsgStoreAddress& aAddress ) const
       
   485 	{
       
   486 	CMsgStorePropertyContainer* address = PropertyValueContainerL( aPropertyIndex, EMsgStoreTypeAddress );
       
   487 	CleanupStack::PushL( address );
       
   488 	
       
   489 	TUint index = 0;
       
   490 	if ( address->FindProperty(KMsgStorePropertyEmailAddress, index) )
       
   491 		{
       
   492 		aAddress.iEmailAddress.Create( address->PropertyValueDesL(index) );
       
   493 		}
       
   494 	
       
   495 	if ( address->FindProperty(KMsgStorePropertyDisplayName, index) )
       
   496 		{
       
   497 		aAddress.iDisplayName.Create( address->PropertyValueDesL(index) );
       
   498 		}
       
   499 	
       
   500 	CleanupStack::PopAndDestroy( address );
       
   501 	
       
   502 	} // end PropertyValueAddressL
       
   503 
       
   504 // ==========================================================================
       
   505 // FUNCTION: PropertyValueBoolL
       
   506 // ==========================================================================
       
   507 EXPORT_C TBool CMsgStorePropertyContainer::PropertyValueBoolL( TUint aPropertyIndex ) const
       
   508 	{
       
   509 	ValidateIndexAndTypeL( aPropertyIndex, EMsgStoreTypeBool );
       
   510 
       
   511 	TPckgBuf<TBool> boolValue;
       
   512 
       
   513 	TPtrC8 des8( iProperties[aPropertyIndex]->iValue.Ptr(), iProperties[aPropertyIndex]->iValue.Length() );
       
   514 	
       
   515 	boolValue.Copy( des8 );
       
   516 	
       
   517 	return boolValue();
       
   518 	} // end PropertyValueBoolL
       
   519 
       
   520 // ==========================================================================
       
   521 // FUNCTION: PropertyValueContainerL
       
   522 // ==========================================================================
       
   523 EXPORT_C CMsgStorePropertyContainer* CMsgStorePropertyContainer::PropertyValueContainerL( TUint aPropertyIndex ) const
       
   524 	{
       
   525 	return PropertyValueContainerL( aPropertyIndex, EMsgStoreTypeContainer );
       
   526 	} // end PropertyValueContainerL
       
   527 
       
   528 // ==========================================================================
       
   529 // FUNCTION: RemovePropertyL
       
   530 // ==========================================================================
       
   531 EXPORT_C void CMsgStorePropertyContainer::RemovePropertyL( TUint aPropertyIndex )
       
   532 	{
       
   533 	ValidateIndexL( aPropertyIndex );
       
   534 
       
   535     delete iProperties[aPropertyIndex];
       
   536 	iProperties.Remove( aPropertyIndex );
       
   537 	} // end RemovePropertyL
       
   538 
       
   539 // ==========================================================================
       
   540 // FUNCTION: FindProperty
       
   541 // ==========================================================================
       
   542 EXPORT_C TBool CMsgStorePropertyContainer::FindProperty( const TDesC8& aName, TUint& aFoundIndex, TUint aStartIndex ) const
       
   543 	{
       
   544 	TInt  index = aStartIndex;
       
   545 	TBool found = EFalse;
       
   546 	while( (index < iProperties.Count()) && !found )
       
   547 		{
       
   548 		if( iProperties[index]->iName.Compare( aName ) == 0 )
       
   549 			{
       
   550 			aFoundIndex = index;
       
   551 			found       = ETrue;
       
   552 			}
       
   553 		else
       
   554 			{
       
   555 			index++;
       
   556 			}
       
   557 		} // end while
       
   558 		
       
   559 	return found;
       
   560 	} // end FindProperty
       
   561 	
       
   562 
       
   563 // ==========================================================================
       
   564 // FUNCTION: AddPropertyL
       
   565 // ==========================================================================
       
   566 TUint CMsgStorePropertyContainer::AddPropertyL( const TDesC8& aName, const CMsgStorePropertyContainer& aContainer, TMsgStorePropertyValueType aType )
       
   567 	{
       
   568 	TMsgStoreProperty* newNode = new(ELeave) TMsgStoreProperty;
       
   569 	CleanupStack::PushL( newNode );
       
   570 	
       
   571 	newNode->iName.CreateL( aName );
       
   572     aContainer.SerializeL( newNode->iValue );	
       
   573 	newNode->iType = aType;
       
   574 
       
   575 	ValidateLengthsL( aName.Length(), newNode->iValue.Length() );
       
   576 		
       
   577 	iProperties.AppendL( newNode );
       
   578 	
       
   579 	CleanupStack::Pop( newNode );
       
   580 	
       
   581 	return iProperties.Count() - 1;
       
   582 	} // end AddPropertyL
       
   583 	
       
   584 // ==========================================================================
       
   585 // FUNCTION: UpdatePropertyL
       
   586 // ==========================================================================
       
   587 void CMsgStorePropertyContainer::UpdatePropertyL( TUint aPropertyIndex, const CMsgStorePropertyContainer& aContainer, TMsgStorePropertyValueType aType )
       
   588 	{
       
   589 	ValidateIndexAndTypeL( aPropertyIndex, aType );
       
   590 
       
   591     iProperties[aPropertyIndex]->iValue.Close();
       
   592     
       
   593     RBuf8 serializedBuf;
       
   594     CleanupClosePushL( serializedBuf );
       
   595     
       
   596     aContainer.SerializeL( serializedBuf );
       
   597     
       
   598     ValidateValueLengthL( serializedBuf.Length() );
       
   599     
       
   600     CleanupStack::Pop( &serializedBuf );
       
   601     
       
   602     iProperties[aPropertyIndex]->iValue.Swap( serializedBuf );
       
   603     iProperties[aPropertyIndex]->iType = aType;
       
   604 	} // end UpdatePropertyL
       
   605 
       
   606 // ==========================================================================
       
   607 // FUNCTION: PropertyValueContainerL
       
   608 // ==========================================================================
       
   609 CMsgStorePropertyContainer* CMsgStorePropertyContainer::PropertyValueContainerL( TUint aPropertyIndex, TMsgStorePropertyValueType aType ) const
       
   610 	{
       
   611 	ValidateIndexAndTypeL( aPropertyIndex, aType );
       
   612 	
       
   613 	CMsgStorePropertyContainer* container = CMsgStorePropertyContainer::NewL();
       
   614 	CleanupStack::PushL( container );
       
   615 	
       
   616 	container->DeserializeL( iProperties[aPropertyIndex]->iValue );
       
   617 
       
   618 	CleanupStack::Pop( container );
       
   619 
       
   620 	return container;	
       
   621 	} // end PropertyValueContainerL
       
   622 
       
   623 // ==========================================================================
       
   624 // FUNCTION: SetIds
       
   625 // ==========================================================================
       
   626 void CMsgStorePropertyContainer::SetIds( TMsgStoreId aId, TMsgStoreId aParentId )
       
   627 	{
       
   628 	iId       = aId;
       
   629 	iParentId = aParentId;
       
   630 	} // end SetIds
       
   631 	
       
   632 // ==========================================================================
       
   633 // FUNCTION: ValidateIndexL
       
   634 // ==========================================================================
       
   635 void CMsgStorePropertyContainer::ValidateIndexL( TUint aIndex ) const
       
   636     {
       
   637     if( aIndex >= iProperties.Count() )
       
   638         {
       
   639     	__LOG_STATIC_ENTER( "MsgClient", "ValidateIndexL" )
       
   640     	__LOG_WRITE_ERROR( "invalid index" )
       
   641 	    __LOG_STATIC_EXIT
       
   642         User::Leave( KErrNotFound );
       
   643         } // end if
       
   644       
       
   645     } // end ValidateIndexL
       
   646     
       
   647 // ==========================================================================
       
   648 // FUNCTION: ValidateIndexAndTypeL
       
   649 // ==========================================================================
       
   650 void CMsgStorePropertyContainer::ValidateIndexAndTypeL( TUint aIndex, TMsgStorePropertyValueType aType ) const
       
   651     {
       
   652     ValidateIndexL( aIndex );
       
   653     
       
   654     if( aType != iProperties[aIndex]->iType )
       
   655         {
       
   656     	__LOG_STATIC_ENTER( "MsgClient", "ValidateIndexAndTypeL" )
       
   657         __LOG_WRITE8_FORMAT2_ERROR( "Invalid type (expected=%i actual=%i)", iProperties[aIndex]->iType, aType  )
       
   658 	    __LOG_STATIC_EXIT
       
   659         User::Leave( KErrArgument );
       
   660         } // end if
       
   661         
       
   662     }  // end ValidateIndexAndTypeL   
       
   663 
       
   664 // ==========================================================================
       
   665 // FUNCTION: ValidateLengthsL
       
   666 // ==========================================================================
       
   667 void CMsgStorePropertyContainer::ValidateLengthsL( TUint aNameLength, TUint aValueLength ) const
       
   668     {
       
   669     if( aNameLength == 0 )
       
   670         {
       
   671         __LOG_STATIC_ENTER( "MsgClient", "ValidateLengthsL" )    
       
   672         __LOG_WRITE_ERROR( "underflow" )
       
   673         __LOG_STATIC_EXIT
       
   674         User::Leave( KErrUnderflow );
       
   675         }
       
   676     else if( aNameLength > KMaxTUint8 )
       
   677         {
       
   678         __LOG_STATIC_ENTER( "MsgClient", "ValidateLengthsL" )    
       
   679         __LOG_WRITE_ERROR( "overflow" )
       
   680         __LOG_STATIC_EXIT
       
   681         User::Leave( KErrOverflow );        
       
   682         }
       
   683     else
       
   684         {
       
   685         ValidateValueLengthL( aValueLength );
       
   686         } // end if
       
   687         
       
   688     } // end ValidateLengthsL
       
   689     
       
   690 // ==========================================================================
       
   691 // FUNCTION: ValidateValueLengthL
       
   692 // ==========================================================================
       
   693 void CMsgStorePropertyContainer::ValidateValueLengthL( TUint /*aValueLength*/ ) const
       
   694     {    
       
   695     // There is no longer a limit on value lengths.
       
   696         
       
   697     } // ValidateValueLengthL 
       
   698 
       
   699 // ==========================================================================
       
   700 // FUNCTION: SerializeL
       
   701 // ==========================================================================
       
   702 void CMsgStorePropertyContainer::SerializeL( RBuf8& aBuffer ) const
       
   703 	{
       
   704 	TInt totalLength = TPropertiesSerializer::EFixedOverhead;
       
   705 	
       
   706 	TInt index;
       
   707 	for( index = 0; index < iProperties.Count(); index++ )
       
   708 		{		
       
   709 		const TMsgStoreProperty* property = iProperties[index];
       
   710 		
       
   711 		totalLength += (property->iName.Length() + property->iValue.Length() + TPropertiesSerializer::EPerNodeOverhead);
       
   712 		} // end for
       
   713 
       
   714 	aBuffer.CreateL( totalLength );
       
   715 
       
   716 	TPropertiesSerializer serializer( aBuffer );
       
   717 	
       
   718 	for( index = 0; index < iProperties.Count(); index++ )
       
   719 		{	
       
   720 		const TMsgStoreProperty* property = iProperties[index];
       
   721 		
       
   722 		serializer.AddPropertyL( property->iName, property->iType, property->iValue );
       
   723 		} // end for
       
   724 	} // end SerializeL
       
   725 
       
   726 // ==========================================================================
       
   727 // FUNCTION: DeserializeL
       
   728 // ==========================================================================
       
   729 void CMsgStorePropertyContainer::DeserializeL( const TDesC8& aSerializedBuffer )
       
   730 	{
       
   731 	TPropertiesDeserializer deserializer( aSerializedBuffer );
       
   732 	
       
   733     TBool moreProperties = deserializer.First();
       
   734     
       
   735 	while( moreProperties )
       
   736 		{
       
   737         TMsgStoreProperty* property = new(ELeave) TMsgStoreProperty;
       
   738         CleanupStack::PushL( property );
       
   739         
       
   740         property->iName.CreateL( deserializer.Name() );
       
   741         property->iValue.CreateL( deserializer.Value() );
       
   742         property->iType = static_cast<TMsgStorePropertyValueType>(deserializer.Type());
       
   743         
       
   744 		if( property->iType == EMsgStoreTypeDes )
       
   745 		    {
       
   746         	const TUint16* valuePtr16 = reinterpret_cast<const TUint16*>( property->iValue.Ptr() );
       
   747 
       
   748         	property->iValue16.Set( valuePtr16, property->iValue.Length() / 2 );
       
   749 		    } // end if
       
   750 		
       
   751 		iProperties.AppendL( property );
       
   752 		
       
   753 		CleanupStack::Pop( property );
       
   754         
       
   755         moreProperties = deserializer.Next();
       
   756 		
       
   757 		} // end while				
       
   758 	} // end DeserializeL
       
   759