pimprotocols/phonebooksync/Server/PhonebookIniFile.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Implementation of CPhoneBookIniFile class which manages the PhBkSync.INI
       
    15 // file.
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalComponent
       
    22 */
       
    23 
       
    24 #include "phbksync.h"
       
    25 #include "Phonebook.h"
       
    26 #include "PhonebookIniFile.h"
       
    27 #include "PhonebookManager.h"
       
    28 #include "phbksynclog.h"
       
    29 #include "common.h"
       
    30 
       
    31 
       
    32 //
       
    33 // Constants for the INI file.  Do not change these.
       
    34 //
       
    35 _LIT8(KPhBkSyncStartOptionText, "PhBkSyncStartOption");
       
    36 _LIT8(KPhBkSyncTemplateIdText,  "PhBkSyncTemplateId");
       
    37 _LIT8(KPhBkSyncGroupIdText,     "PhBkSyncGroupId");
       
    38 _LIT8(KPhBkSyncPhonebookIdText, "PhBkSyncPhonebookId");
       
    39 
       
    40 
       
    41 //
       
    42 // Minimum and maximum dimensions of an INI file...
       
    43 //
       
    44 const TInt KIniFileMaxPhonebooks = KMaxPhonebooks;
       
    45 const TInt KIniFileMinimumSize   = 1;
       
    46 const TInt KIniFileNoOfSettings  = 4;
       
    47 const TInt KIniFileMaxLineLength = 64; // Approx. 20+1+9+1+15=46 max.
       
    48 const TInt KIniFileMaximumSize   = (KIniFileMaxPhonebooks *
       
    49                                     KIniFileNoOfSettings *
       
    50                                     KIniFileMaxLineLength);
       
    51 
       
    52 
       
    53 /**
       
    54  *  Static factory method used to create a CPhoneBookIniFile object.
       
    55  *
       
    56  *  @param aPhonebookList  A list of phonebook UIDs supported by the Phonebook
       
    57  *                         synchroniser.
       
    58  *
       
    59  *  @return  Pointer to the created CPhoneBookIniFile object, or NULL.
       
    60  */
       
    61 CPhoneBookIniFile* CPhoneBookIniFile::NewL(RPointerArray<CPhoneBook>& aPhonebookList)
       
    62 	{
       
    63 	LOGINIFILE2(_L8("NewL(%d phonebooks)"), aPhonebookList.Count());
       
    64 
       
    65 	CPhoneBookIniFile*  ptr = new (ELeave) CPhoneBookIniFile(aPhonebookList);
       
    66 	CleanupStack::PushL(ptr);
       
    67 	ptr->ConstructL();
       
    68 	CleanupStack::Pop(ptr);
       
    69 	return ptr;
       
    70 	} // CPhoneBookIniFile::NewL
       
    71 
       
    72 
       
    73 /**
       
    74  *  Standard constructor.
       
    75  *
       
    76  *  @param aPhonebookList  A list of phonebook UIDs supported by the Phonebook
       
    77  *                         synchroniser.
       
    78  */
       
    79 CPhoneBookIniFile::CPhoneBookIniFile(RPointerArray<CPhoneBook>& aPhonebookList)
       
    80   : iPhonebookList(aPhonebookList),
       
    81     iIsIniFileCacheValid(EFalse)
       
    82 	{
       
    83 	// NOP
       
    84 	} // CPhoneBookIniFile::CPhoneBookIniFile
       
    85 
       
    86 
       
    87 /**
       
    88  *  Standard destructor.
       
    89  */
       
    90 CPhoneBookIniFile::~CPhoneBookIniFile()
       
    91 	{
       
    92 	// NOP
       
    93 	} // CPhoneBookIniFile::~CPhoneBookIniFile
       
    94 
       
    95 
       
    96 /**
       
    97  *  Second stage contructor.
       
    98  */
       
    99 void CPhoneBookIniFile::ConstructL()
       
   100 	{
       
   101 	LOGINIFILE1(_L8("ConstructL()"));
       
   102 	
       
   103 	__ASSERT_DEBUG(iPhonebookList.Count() <= KMaxPhonebooks,
       
   104 				   PhBkSyncPanic(EPhBkSyncPanicTooManyPhonebooks));
       
   105 
       
   106 	//
       
   107 	// Read the INI file and initialise the cache. If a problem occurs
       
   108 	// during the read of the INI file then we let it go as the server
       
   109 	// must still start. If the file is corrupt then we write a new one
       
   110 	// out straight away.
       
   111 	//
       
   112 	TRAPD(result, ReadIniFileL());
       
   113 	LOGINIFILE2(_L8("Read of the INI file returned %d"), result);
       
   114 
       
   115 	if (result == KErrNone)
       
   116 		{
       
   117 		UpdatePhonebookParamsCache();
       
   118 		}
       
   119 	else if (result == KErrCorrupt)
       
   120 		{
       
   121 		WriteIniFileSettingsIfNeeded();
       
   122 		}
       
   123 	} // CPhoneBookIniFile::ConstructL
       
   124 
       
   125 
       
   126 /**
       
   127  *  Requests the writting of the Ini file if required.
       
   128  *
       
   129  *  @return KErrNone if successful or a Standard Symbian error code.
       
   130  */
       
   131 TInt CPhoneBookIniFile::WriteIniFileSettingsIfNeeded()
       
   132 	{
       
   133 	LOGINIFILE1(_L8("WriteIniFileSettingsIfNeeded()"));
       
   134 	
       
   135 	//
       
   136 	// Check the current cached values against the phonebooks to see if
       
   137 	// we need to file the INI file. If so then write the file.
       
   138 	//
       
   139 	TInt  result(KErrNone);
       
   140 	
       
   141 	if (CheckPhonebookParamsForChanges())
       
   142 		{
       
   143 		TRAP(result, WriteIniFileL());
       
   144 		LOGINIFILE2(_L8("Write of the INI file returned %d"), result);
       
   145 	
       
   146 		//
       
   147 		// If the INI file was written ok, then update the cache...
       
   148 		//
       
   149 		if (result == KErrNone)
       
   150 			{
       
   151 			UpdatePhonebookParamsCache();
       
   152 			}
       
   153 		}
       
   154 	
       
   155 	return result;
       
   156 	} // CPhoneBookIniFile::WriteIniFileSettingsIfNeeded
       
   157 
       
   158 
       
   159 /**
       
   160  *  Checks if any of the phonebook parameters have changed. This would indicate
       
   161  *  that the INI file should be re-written.
       
   162  *
       
   163  *  @return ETrue if the phonebook parameters have changed, EFalse otherwise.
       
   164  */
       
   165 TBool CPhoneBookIniFile::CheckPhonebookParamsForChanges() const
       
   166 	{
       
   167 	LOGINIFILE1(_L8("CheckPhonebookParamsForChanges()"));
       
   168 				
       
   169 	//
       
   170 	// If the INI file does not exist or is corrupt, then write it...
       
   171 	//
       
   172 	if (iIsIniFileCacheValid == EFalse)
       
   173 		{
       
   174 		LOGINIFILE1(_L8("No INI file data loaded so file needs writting"));
       
   175 		return ETrue;
       
   176 		}
       
   177 	
       
   178 	//
       
   179 	// Check each phonebook against the cache for unwritten changes.
       
   180 	//
       
   181 	TInt  needsWriting(EFalse);
       
   182 	TInt  phonebookCount(iPhonebookList.Count());
       
   183 	
       
   184 	for (TInt index = 0;  index < phonebookCount;  index++)
       
   185 		{
       
   186 		CPhoneBook*  phonebook = iPhonebookList[index];
       
   187 
       
   188 		if (phonebook != NULL)
       
   189 			{
       
   190 			RMobilePhoneBookStore::TMobilePhoneBookInfoV5  phBkInfo;
       
   191 			
       
   192 			phBkInfo = phonebook->GetPhoneBookInfo();
       
   193 
       
   194 			if (iIniFileSyncModeCache[index] != phonebook->GetSyncMode()  ||
       
   195 				iIniFileTemplateIdCache[index] != phonebook->GetTemplateId()  ||
       
   196 				iIniFileGroupIdCache[index] != phonebook->GetGroupId()  ||
       
   197 				iIniFileIdentityCache[index] != phBkInfo.iIdentity)
       
   198 				{
       
   199 				needsWriting = ETrue;
       
   200 				break;
       
   201 				}
       
   202 			}
       
   203 		}
       
   204 	
       
   205 	//
       
   206 	// Log if the INI file needs writing...
       
   207 	//
       
   208 	if (needsWriting == EFalse)
       
   209 		{
       
   210 		LOGINIFILE1(_L8("INI file does not need to be written"));
       
   211 		}
       
   212 	else
       
   213 		{
       
   214 		LOGINIFILE1(_L8("INI file needs to be written"));
       
   215 		}
       
   216 	
       
   217 	return needsWriting;
       
   218 	} // CPhoneBookIniFile::CheckPhonebookParamsForChanges
       
   219 
       
   220 
       
   221 /**
       
   222  *  Get the full path name for the INI file.
       
   223  *
       
   224  *  @param aFs           File server handle.
       
   225  *  @param aIniFileName  Path will be returned in aPath.
       
   226  */
       
   227 void CPhoneBookIniFile::GetIniFileName(RFs& aFs, TDes& aIniFileName) const
       
   228 	{
       
   229 	LOGINIFILE1(_L8("GetIniFileName()"));
       
   230 	
       
   231 	//
       
   232 	// Name is made up of the system drive, private path and INI file name...
       
   233 	//
       
   234 	_LIT(KPhBkSyncIniFileName, "PhBkSync.ini");
       
   235 
       
   236 	TDriveUnit  systemDrive(aFs.GetSystemDrive()); 
       
   237 	TPath  privatePath;
       
   238 	
       
   239 	aFs.PrivatePath(privatePath);
       
   240 
       
   241 	aIniFileName.Zero();
       
   242 	aIniFileName.Append(systemDrive.Name());
       
   243 	aIniFileName.Append(privatePath);
       
   244 	aIniFileName.Append(KPhBkSyncIniFileName);
       
   245 
       
   246 	//
       
   247 	// Debug logging of the INI file name...
       
   248 	//	
       
   249 #ifdef _DEBUG
       
   250 	TBuf8<KMaxFileName>  aIniFileNameIn8Bit;
       
   251 	aIniFileNameIn8Bit.Copy(aIniFileName);
       
   252 	LOGINIFILE2(_L8("INI file \"%S\""), &aIniFileNameIn8Bit);
       
   253 #endif
       
   254 	} // CPhoneBookIniFile::GetIniFileName
       
   255 
       
   256 
       
   257 /**
       
   258  *  Write all phonebook settings to the Phonebook INI file. If the file
       
   259  *  does not exist it will create one.
       
   260  */
       
   261 void CPhoneBookIniFile::WriteIniFileL() const
       
   262 	{
       
   263 	LOGINIFILE1(_L8("WriteIniFileL()"));
       
   264 
       
   265 	//
       
   266 	// Connect to the File Server...
       
   267 	//
       
   268 	RFs  fs;
       
   269 
       
   270 	User::LeaveIfError(fs.Connect());
       
   271 	CleanupClosePushL(fs);
       
   272 
       
   273 	//
       
   274 	// Get the name of the INI file...
       
   275 	//
       
   276 	TFileName  iniFileName;
       
   277 	GetIniFileName(fs, iniFileName);
       
   278 
       
   279 	//
       
   280 	// Ensure that the private directory exists...
       
   281 	//
       
   282 	TInt  result = fs.MkDirAll(iniFileName);
       
   283 	if (result != KErrAlreadyExists  &&  result != KErrNone)
       
   284 		{
       
   285 		User::Leave(result);
       
   286 		}
       
   287 	
       
   288 	//
       
   289 	// Open the file for writing, truncating it if needed...
       
   290 	//
       
   291 	RFile  file;
       
   292 
       
   293 	User::LeaveIfError(file.Replace(fs, iniFileName, EFileShareAny|EFileWrite));
       
   294 	CleanupClosePushL(file);
       
   295 
       
   296 	//
       
   297 	// Write the settings for each phonebook...
       
   298 	//
       
   299 	_LIT8(KIniLineValueFormat, "%S= %d %d\r\n");
       
   300 	_LIT8(KIniLineStringFormat, "%S= %d %S\r\n");
       
   301 	TInt  phonebookCount(iPhonebookList.Count());
       
   302 	TBuf8<KIniFileMaxLineLength>  line;
       
   303 	
       
   304 	for (TInt index = 0;  index < phonebookCount;  index++)
       
   305 		{
       
   306 		CPhoneBook*  phonebook = iPhonebookList[index];
       
   307 
       
   308 		if (phonebook != NULL)
       
   309 			{
       
   310 			TUid  phonebookUid = phonebook->GetPhonebookUid();
       
   311 
       
   312 			// Phonebook Sync Mode...
       
   313 			line.Format(KIniLineValueFormat, &KPhBkSyncStartOptionText,
       
   314 						phonebookUid.iUid, phonebook->GetSyncMode());
       
   315 			User::LeaveIfError(file.Write(line));
       
   316 #ifdef _DEBUG
       
   317 			line.SetLength(line.Length() - 2);
       
   318 			LOGINIFILE2(_L8("INI line \"%S\""), &line);
       
   319 #endif
       
   320 
       
   321 			// Phonebook Template ID...
       
   322 			line.Format(KIniLineValueFormat, &KPhBkSyncTemplateIdText,
       
   323 						phonebookUid.iUid, phonebook->GetTemplateId());
       
   324 			User::LeaveIfError(file.Write(line));
       
   325 #ifdef _DEBUG
       
   326 			line.SetLength(line.Length() - 2);
       
   327 			LOGINIFILE2(_L8("INI line \"%S\""), &line);
       
   328 #endif
       
   329 
       
   330 			// Phonebook Group ID...
       
   331 			line.Format(KIniLineValueFormat, &KPhBkSyncGroupIdText,
       
   332 						phonebookUid.iUid, phonebook->GetGroupId());
       
   333 			User::LeaveIfError(file.Write(line));
       
   334 #ifdef _DEBUG
       
   335 			line.SetLength(line.Length() - 2);
       
   336 			LOGINIFILE2(_L8("INI line \"%S\""), &line);
       
   337 #endif
       
   338 
       
   339 			// Phonebook ID string...
       
   340 			RMobilePhoneBookStore::TMobilePhoneBookInfoV5  phBkInfo;
       
   341 			
       
   342 			phBkInfo = phonebook->GetPhoneBookInfo();
       
   343 
       
   344 			line.Format(KIniLineStringFormat, &KPhBkSyncPhonebookIdText,
       
   345 						phonebookUid.iUid, &phBkInfo.iIdentity);
       
   346 			User::LeaveIfError(file.Write(line));
       
   347 #ifdef _DEBUG
       
   348 			line.SetLength(line.Length() - 2);
       
   349 			LOGINIFILE2(_L8("INI line \"%S\""), &line);
       
   350 #endif
       
   351 			}
       
   352 		}
       
   353 
       
   354 	CleanupStack::PopAndDestroy(2, &fs); // fs, file
       
   355 	} // CPhoneBookIniFile::WriteIniFileL
       
   356 
       
   357 
       
   358 /**
       
   359  *  Read all phonebook settings from the Phonebook INI file if it exists.
       
   360  */
       
   361 void CPhoneBookIniFile::ReadIniFileL() const
       
   362 	{
       
   363 	LOGINIFILE1(_L8("ReadIniFileL()"));
       
   364 
       
   365 	//
       
   366 	// Connect to the File Server...
       
   367 	//
       
   368 	RFs  fs;
       
   369 
       
   370 	User::LeaveIfError(fs.Connect());
       
   371 	CleanupClosePushL(fs);
       
   372 
       
   373 	//
       
   374 	// Get the name of the INI file...
       
   375 	//
       
   376 	TFileName  iniFileName;
       
   377 	GetIniFileName(fs, iniFileName);
       
   378 
       
   379 	//
       
   380 	// Open the INI file...
       
   381 	//
       
   382 	RFile  file;
       
   383 
       
   384 	User::LeaveIfError(file.Open(fs, iniFileName, EFileShareAny | EFileRead));
       
   385 	CleanupClosePushL(file);
       
   386 
       
   387 	//
       
   388 	// Load the file into memory...
       
   389 	//
       
   390 	TInt  fileSize;
       
   391 
       
   392 	User::LeaveIfError(file.Size(fileSize));
       
   393 
       
   394 	if (fileSize < KIniFileMinimumSize  ||  fileSize > KIniFileMaximumSize)
       
   395 		{
       
   396 		User::Leave(KErrCorrupt);
       
   397 		}
       
   398 
       
   399 	HBufC8*  iniFileBuf = HBufC8::NewLC(fileSize);
       
   400 	TPtr8  iniFilePtr(iniFileBuf->Des());
       
   401 	User::LeaveIfError(file.Read(0, iniFilePtr));
       
   402 
       
   403 	//
       
   404 	// Parse the INI file text...
       
   405 	//
       
   406 	TLex8  iniFile(*iniFileBuf);
       
   407 
       
   408 	while (!iniFile.Eos()) 
       
   409 		{
       
   410 		//
       
   411 		// The settings for each follow the pattern:
       
   412 		//
       
   413 		//   <Setting>= <Phonebook> <Value>
       
   414 		//
       
   415 		TPtrC8  settingsToken(iniFile.NextToken());
       
   416 		iniFile.SkipSpace();
       
   417 
       
   418 		//
       
   419 		// Check the setting field is correct...
       
   420 		//
       
   421 		if (iniFile.Eos())
       
   422 			{
       
   423 			break;
       
   424 			}
       
   425 
       
   426 		if (settingsToken.Find(KPhBkSyncStartOptionText) != KErrNone  &&
       
   427 			settingsToken.Find(KPhBkSyncTemplateIdText) != KErrNone  &&
       
   428 			settingsToken.Find(KPhBkSyncGroupIdText) != KErrNone  &&
       
   429 			settingsToken.Find(KPhBkSyncPhonebookIdText) != KErrNone)
       
   430 			{
       
   431 			LOGINIFILE2(_L8("Invalid setting token (%S)"), &settingsToken);
       
   432 			continue;
       
   433 			}
       
   434 
       
   435 		//
       
   436 		// Get the phonebook. This is the UID value but was previously
       
   437 		// a constant, so we read both.
       
   438 		//
       
   439 		iniFile.SkipSpace();
       
   440 		if (iniFile.Eos())
       
   441 			{
       
   442 			break;
       
   443 			}
       
   444 
       
   445 		TInt  phonebookNum(0);
       
   446 		TUid  phonebookUid;
       
   447 
       
   448 		TInt  result = iniFile.Val(phonebookNum);
       
   449 		if (result != KErrNone)
       
   450 			{
       
   451 			LOGINIFILE2(_L8("Invalid phonebook number (error %d)"), result);
       
   452 			continue;
       
   453 			}
       
   454 		
       
   455 		switch (phonebookNum)
       
   456 			{
       
   457 			case 1:
       
   458 				{
       
   459 				phonebookUid = KUidIccGlobalAdnPhonebook;
       
   460 				}
       
   461 				break;
       
   462 				
       
   463 			case 2:
       
   464 				{
       
   465 				phonebookUid = KUidIccGlobalSdnPhonebook;
       
   466 				}
       
   467 				break;
       
   468 				
       
   469 			case 3:
       
   470 				{
       
   471 				phonebookUid = KUidIccGlobalLndPhonebook;
       
   472 				}
       
   473 				break;
       
   474 				
       
   475 			case 4:
       
   476 				{
       
   477 				phonebookUid = KUidUsimAppAdnPhonebook;
       
   478 				}
       
   479 				break;
       
   480 				
       
   481 			case 5:
       
   482 				{
       
   483 				phonebookUid = KUidIccGlobalFdnPhonebook;
       
   484 				}
       
   485 				break;
       
   486 				
       
   487 			default:
       
   488 				{
       
   489 				phonebookUid = TUid::Uid(phonebookNum);
       
   490 				}
       
   491 				break;
       
   492 			}	
       
   493 
       
   494 		TInt  phonebookCount(iPhonebookList.Count());
       
   495 		CPhoneBook*  phonebook(NULL);
       
   496 
       
   497 		for (TInt index = 0;  index < phonebookCount;  index++)
       
   498 			{
       
   499 			if (iPhonebookList[index]->GetPhonebookUid() == phonebookUid)
       
   500 				{
       
   501 				phonebook = iPhonebookList[index];
       
   502 				break;
       
   503 				}
       
   504 			}
       
   505 
       
   506 		if (phonebook == NULL)
       
   507 			{
       
   508 			LOGINIFILE2(_L8("Phonebook does not exist (%d)"), phonebookNum);
       
   509 			continue;
       
   510 			}
       
   511 
       
   512 		//
       
   513 		// Read the value and set it...
       
   514 		//
       
   515 		iniFile.SkipSpace();
       
   516 		if (iniFile.Eos())
       
   517 			{
       
   518 			break;
       
   519 			}
       
   520 
       
   521 		if (settingsToken.Find(KPhBkSyncStartOptionText) == KErrNone)
       
   522 			{
       
   523 			TInt  syncModeNum(-1);
       
   524 			
       
   525 			result = iniFile.Val(syncModeNum);
       
   526 			if (result != KErrNone)
       
   527 				{
       
   528 				LOGINIFILE2(_L8("Invalid sync mode number (error %d)"), result);
       
   529 				continue;
       
   530 				}
       
   531 
       
   532 			RPhoneBookSession::TPhonebookSyncMode  syncMode;
       
   533 
       
   534 			syncMode = static_cast<RPhoneBookSession::TPhonebookSyncMode>(syncModeNum);
       
   535 
       
   536 			if (syncMode != RPhoneBookSession::EAutoCurrentIcc  &&
       
   537 				syncMode != RPhoneBookSession::EAutoSameIcc  &&
       
   538 				syncMode != RPhoneBookSession::EManual)
       
   539 				{
       
   540 				LOGINIFILE2(_L8("Invalid sync mode value (%d)"),
       
   541 				            (TInt) syncMode);
       
   542 				continue;
       
   543 				}
       
   544 
       
   545 			phonebook->SetSyncMode(syncMode);
       
   546 			
       
   547 			LOGINIFILE4(_L8("INI read as \"%S %d %d\""),
       
   548 						&KPhBkSyncStartOptionText,
       
   549 						phonebook->GetPhonebookUid().iUid, (TInt) syncMode);
       
   550 			}
       
   551 		else if (settingsToken.Find(KPhBkSyncTemplateIdText) == KErrNone)
       
   552 			{
       
   553 			TContactItemId  templateId(-1);
       
   554 			
       
   555 			result = iniFile.Val(templateId);
       
   556 			if (result != KErrNone)
       
   557 				{
       
   558 				LOGINIFILE3(_L8("Invalid template Id number (error %d, number %d)"),
       
   559 				            result, templateId);
       
   560 				continue;
       
   561 				}
       
   562 
       
   563 			phonebook->SetTemplateId(templateId);
       
   564 
       
   565 			LOGINIFILE4(_L8("INI read as \"%S %d %d\""),
       
   566 						&KPhBkSyncTemplateIdText,
       
   567 						phonebook->GetPhonebookUid().iUid, templateId);
       
   568 			}
       
   569 		else if (settingsToken.Find(KPhBkSyncGroupIdText) == KErrNone)
       
   570 			{
       
   571 			TContactItemId  groupId(0);
       
   572 			
       
   573 			result = iniFile.Val(groupId);
       
   574 			if (result != KErrNone)
       
   575 				{
       
   576 				LOGINIFILE3(_L8("Invalid group ID number (error %d, number %d)"),
       
   577 				            result, groupId);
       
   578 				continue;
       
   579 				}
       
   580 
       
   581 			phonebook->SetGroupId(groupId);
       
   582 
       
   583 			LOGINIFILE4(_L8("INI read as \"%S %d %d\""),
       
   584 						&KPhBkSyncGroupIdText,
       
   585 						phonebook->GetPhonebookUid().iUid, groupId);
       
   586 			}
       
   587 		else if (settingsToken.Find(KPhBkSyncPhonebookIdText) == KErrNone)
       
   588 			{
       
   589 			TPtrC8  phonebookId(iniFile.NextToken());
       
   590 			RMobilePhoneBookStore::TMobilePhoneBookInfoV5  phBkInfo;
       
   591 
       
   592 			phBkInfo = phonebook->GetPhoneBookInfo();
       
   593 
       
   594 			if (phonebookId.Length() > phBkInfo.iIdentity.MaxSize())
       
   595 				{
       
   596 				LOGINIFILE2(_L8("Invalid phonebook ID (\"%S\")"), &phonebookId);
       
   597 				}
       
   598 
       
   599 			phBkInfo.iIdentity.Copy(phonebookId);
       
   600 			phonebook->SetPhoneBookInfo(phBkInfo);
       
   601 
       
   602 			LOGINIFILE4(_L8("INI read as \"%S %d %S\""),
       
   603 						&KPhBkSyncPhonebookIdText,
       
   604 						phonebook->GetPhonebookUid().iUid, &phBkInfo.iIdentity);
       
   605 			}
       
   606 		}
       
   607 
       
   608 	CleanupStack::PopAndDestroy(3, &fs); // fs, file, contents
       
   609 	} // CPhoneBookIniFile::ReadIniFileL
       
   610 
       
   611 
       
   612 /**
       
   613  *  Update the internal cache of phonebook parameters with the real values.
       
   614  *  This function is used after the INI file is written.
       
   615  */
       
   616 void CPhoneBookIniFile::UpdatePhonebookParamsCache()
       
   617 	{
       
   618 	LOGINIFILE1(_L8("UpdatePhonebookParamsCache()"));
       
   619 				
       
   620 	TInt  phonebookCount(iPhonebookList.Count());
       
   621 	
       
   622 	for (TInt index = 0;  index < phonebookCount;  index++)
       
   623 		{
       
   624 		CPhoneBook*  phonebook = iPhonebookList[index];
       
   625 
       
   626 		if (phonebook != NULL)
       
   627 			{
       
   628 			RMobilePhoneBookStore::TMobilePhoneBookInfoV5  phBkInfo;
       
   629 			
       
   630 			phBkInfo = phonebook->GetPhoneBookInfo();
       
   631 
       
   632 			iIniFileSyncModeCache[index] = phonebook->GetSyncMode();
       
   633 			iIniFileTemplateIdCache[index] = phonebook->GetTemplateId();
       
   634 			iIniFileGroupIdCache[index] = phonebook->GetGroupId();
       
   635 			iIniFileIdentityCache[index].Copy(phBkInfo.iIdentity);
       
   636 			}
       
   637 		}
       
   638 
       
   639 	iIsIniFileCacheValid = ETrue;
       
   640 	} // CPhoneBookIniFile::UpdatePhonebookParamsCache
       
   641 
       
   642