secureswitools/swisistools/source/rscparser/aplappinforeader.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
child 27 e8965914fac7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
     1 // Copyright (c) 2009 - 2010 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 // aplappinforeader.cpp
       
    15 //
       
    16 /** 
       
    17 * @file aplappinforeader.cpp
       
    18 *
       
    19 * @internalComponent
       
    20 * @released
       
    21 */
       
    22 
       
    23 #include <stdlib.h> 
       
    24 #include <iostream.h> 
       
    25 #include <string> 
       
    26 #include "aplappinforeader.h"
       
    27 #include "barsc2.h"
       
    28 #include "barsread2.h"
       
    29 #include <cassert>
       
    30 #include "parse.h"
       
    31 #include "uidtype.h"
       
    32 #include "stringutils.h"
       
    33 #include "is_utils.h"
       
    34 #include "apsecutils.h"
       
    35 #include "parse.h"
       
    36 
       
    37 using namespace std;
       
    38 
       
    39 const TUint KNonLocalized = 0;
       
    40 
       
    41 #define REINTERPRET_CAST(type,exp) (reinterpret_cast<type>(exp))
       
    42 
       
    43 const TUint KResourceOffsetMask = 0xFFFFF000;
       
    44 
       
    45 #ifdef __LINUX__
       
    46 std::string KAppBinaryPathAndExtension("/sys/bin/.exe");
       
    47 #else
       
    48 std::string KAppBinaryPathAndExtension("\\sys\\bin\\.exe");
       
    49 #endif
       
    50 
       
    51 const TInt KAppRegistrationInfoResourceId = 1;
       
    52 
       
    53 // The 2nd UID that defines a resource file as being an application registration resource file.
       
    54 const TUid KUidAppRegistrationFile = {0x101F8021};
       
    55 
       
    56 /**
       
    57 @internalTechnology
       
    58 */
       
    59 std::string KAppResourceFileExtension(".rsc");
       
    60 
       
    61 #ifdef __LINUX__
       
    62 std::string KLitPathForUntrustedRegistrationResourceFiles("/private/10003a3f/import/apps/");
       
    63 #else
       
    64 std::string KLitPathForUntrustedRegistrationResourceFiles("\\private\\10003a3f\\import\\apps\\");
       
    65 #endif
       
    66 
       
    67 //
       
    68 // CAppInfoReader
       
    69 //
       
    70 
       
    71 // The behaviour of the Take-methods of this class is a little non-standard, as it
       
    72 // transfers ownership of the pointer owned by a CAppInfoReader derived object
       
    73 // to the caller. This means that this function is only designed to be called once.
       
    74 // Doing things this way provides a small performance optimisation by enabling the caller
       
    75 // to delete it's stored pointer, and replace it with one returned by this function,
       
    76 // instead of having to copy the object (copying could be expensive for the methods
       
    77 // of this class that need to return arrays).
       
    78 
       
    79 
       
    80 CAppInfoReader* CAppInfoReader::NewL(const std::string& aRegistrationFileName, TUid aAppUid, const std::string& aLocalizeFilePath)
       
    81 {
       
    82 	CAppInfoReader* self = new CAppInfoReader(aRegistrationFileName, aAppUid, aLocalizeFilePath);
       
    83 	if(NULL == self)
       
    84 	{
       
    85 		std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
    86 		throw CResourceFileException(errMsg);
       
    87 	}
       
    88 	return self;
       
    89 }
       
    90 
       
    91 CAppInfoReader::CAppInfoReader(const std::string& aRegistrationFileName, TUid aAppUid, const std::string& aLocalizeFilePath) :
       
    92 	iAppUid(aAppUid),
       
    93 	iDefaultScreenNumber(0),
       
    94 	iNonMbmIconFile(false),
       
    95 	iApplicationLanguage(ELangNone),
       
    96 	iIndexOfFirstOpenService(KErrNotFound),
       
    97 	iRegistrationFileName(aRegistrationFileName),
       
    98 	iDrivePath(aLocalizeFilePath)
       
    99 	{
       
   100 
       
   101 	 	iAppBinaryFullName = NULL;;
       
   102 		iCapability.iGroupName = NULL;
       
   103 		iCaption = NULL;
       
   104 		iShortCaption = NULL;
       
   105 		iViewDataArray = NULL;;
       
   106 		iOwnedFileArray = NULL;
       
   107 		iIconFileName = NULL;
       
   108 	 	iLocalisableResourceFileName = NULL;
       
   109 		iServiceArray = NULL;
       
   110 	}
       
   111 
       
   112 CAppInfoReader::~CAppInfoReader()
       
   113 {
       
   114 	delete iAppBinaryFullName;
       
   115 	delete iCaption;
       
   116 	delete iShortCaption;
       
   117 	if(iViewDataArray)
       
   118 		iViewDataArray->clear();
       
   119 	delete iViewDataArray;
       
   120 	if(iOwnedFileArray)
       
   121 		iOwnedFileArray->clear();
       
   122 	delete iOwnedFileArray;
       
   123 	delete iIconFileName;
       
   124 	delete iLocalisableResourceFileName;
       
   125 	if(iServiceArray)
       
   126 		iServiceArray->clear();
       
   127 	delete iServiceArray;
       
   128 	if(iAppLocalizableInfo.size())
       
   129 		iAppLocalizableInfo.clear();
       
   130 	if(iOpaqueDataArray.size())
       
   131 		iOpaqueDataArray.clear();
       
   132 }
       
   133 
       
   134 Ptr16* CAppInfoReader::AppBinaryFullName()
       
   135 {
       
   136 	Ptr16* fileName = iAppBinaryFullName;
       
   137 	return fileName;
       
   138 }
       
   139 
       
   140 TUidType CAppInfoReader::AppBinaryUidType() const
       
   141 {
       
   142 	return iAppBinaryUidType;
       
   143 }
       
   144 
       
   145 TUid CAppInfoReader::AppUid() const
       
   146 {
       
   147 	return iAppUid;
       
   148 }
       
   149 
       
   150 void CAppInfoReader::Capability(TAppCapability& aCapabilityBuf) const
       
   151 {
       
   152 	memcpy(&aCapabilityBuf, &iCapability,sizeof(TAppCapability));
       
   153 }
       
   154 
       
   155 TUint CAppInfoReader::DefaultScreenNumber() const
       
   156 {
       
   157 	return iDefaultScreenNumber;
       
   158 }
       
   159 
       
   160 Ptr16* CAppInfoReader::Caption()
       
   161 {
       
   162 	Ptr16* caption = iCaption;
       
   163 	iCaption = NULL; // ownership transferred to caller
       
   164 	return caption;
       
   165 }
       
   166 
       
   167 Ptr16* CAppInfoReader::ShortCaption()
       
   168 {
       
   169 	Ptr16* shortCaption = iShortCaption;
       
   170 	iShortCaption = NULL; // ownership transferred to caller
       
   171 	return shortCaption;
       
   172 }
       
   173 
       
   174 TInt CAppInfoReader::NumOfAppIcons() const
       
   175 {
       
   176 	return iNumOfAppIcons;
       
   177 }
       
   178 
       
   179 std::vector<CAppViewData*>* CAppInfoReader::Views()
       
   180 {
       
   181 	std::vector<CAppViewData*>* viewDataArray = iViewDataArray;
       
   182 	iViewDataArray = NULL; // ownership transferred to caller
       
   183 	return viewDataArray;
       
   184 }
       
   185 
       
   186 std::vector<CAppLocalizableInfo*> CAppInfoReader::LocalizableInfo()
       
   187 {
       
   188 	std::vector<CAppLocalizableInfo*> AppLocalizableInfo = iAppLocalizableInfo;
       
   189 	return AppLocalizableInfo;
       
   190 }
       
   191 
       
   192 std::vector<CAppLocalOpaqueDataInfo*> CAppInfoReader::GetOpaqueDataArray()
       
   193 {
       
   194 	std::vector<CAppLocalOpaqueDataInfo*> opaqueDataArray = iOpaqueDataArray;
       
   195 	return opaqueDataArray;
       
   196 }
       
   197 
       
   198 std::vector<Ptr16*>* CAppInfoReader::OwnedFiles()
       
   199 {
       
   200 	std::vector<Ptr16*>* ownedFileArray = iOwnedFileArray;
       
   201 	iOwnedFileArray = NULL; // ownership transferred to caller
       
   202 	return ownedFileArray;
       
   203 }
       
   204 
       
   205 Ptr16* CAppInfoReader::IconFileName()
       
   206 {
       
   207 	Ptr16* iconFileName = iIconFileName;
       
   208 	iIconFileName = NULL; // ownership transferred to caller
       
   209 	ConvertToPlatformSpecificPath(iconFileName->GetPtr(), iconFileName->GetLength());
       
   210 	return iconFileName;
       
   211 }
       
   212 
       
   213 TBool CAppInfoReader::NonMbmIconFile() const
       
   214 {
       
   215 	return iNonMbmIconFile;
       
   216 }
       
   217 
       
   218 Ptr16* CAppInfoReader::LocalisableResourceFileName()
       
   219 {
       
   220 	Ptr16* localisableResourceFileName = iLocalisableResourceFileName;
       
   221 	iLocalisableResourceFileName = NULL; // ownership transferred to caller
       
   222 	return localisableResourceFileName;
       
   223 }
       
   224 
       
   225 TLanguage CAppInfoReader::AppLanguage() const
       
   226 {
       
   227 	return iApplicationLanguage;
       
   228 }
       
   229 
       
   230 std::vector<TAppServiceInfo*>* CAppInfoReader::ServiceArray(TInt& aIndexOfFirstOpenService)
       
   231 {
       
   232 	std::vector<TAppServiceInfo*>* serviceArray = iServiceArray;
       
   233 	iServiceArray = NULL;
       
   234 	aIndexOfFirstOpenService = iIndexOfFirstOpenService;
       
   235 	return serviceArray;
       
   236 }
       
   237 
       
   238 TBool CAppInfoReader::ReadL(const std::vector<FileDescription*>& aFileDescription, std::string& aRomPath, int aInRom )
       
   239 {
       
   240 		TUint fileOffset = 0;
       
   241 		TInt fileLength = 0;
       
   242 		TUid firstUid(KExecutableImageUidVal);
       
   243 		TUid middleUid(KUidApp);
       
   244 		TInt err;
       
   245 		TInt LocalizeError = 0;
       
   246 		TUid reguid;
       
   247 		CResourceFile* registrationFile = new CResourceFile(iRegistrationFileName, fileOffset, fileLength);
       
   248 		if(NULL==registrationFile)
       
   249 		{
       
   250 			std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   251 			throw CResourceFileException(errMsg);
       
   252 		}
       
   253 	
       
   254 		if(registrationFile)
       
   255 		{
       
   256 			iAppUid = registrationFile->ReadAppUidL();
       
   257 			if(!iAppUid.GetUid())
       
   258 			{
       
   259 				std::string errMsg= "Failed : Invalid Resource File. Null Application UID.";
       
   260 				throw CResourceFileException(errMsg);
       
   261 			}
       
   262 
       
   263 			reguid = registrationFile->ReadFileUidL();
       
   264 			if(reguid.GetUid()!= KUidAppRegistrationResourceFile)
       
   265 			{
       
   266 				std::string errMsg= "Failed : Invalid Resource File. UID2 is not defined.";
       
   267 				throw CResourceFileException(errMsg);
       
   268 			}
       
   269 		}
       
   270 	
       
   271 		// set the TUidType for the app binary
       
   272 		// cannot read the TEntry info from the app binary because it's in \sys\bin
       
   273 		iAppBinaryUidType = TUidType(firstUid, middleUid, iAppUid); 
       
   274 		
       
   275 		RResourceReader resourceReader;
       
   276 		resourceReader.OpenL(registrationFile, KAppRegistrationInfoResourceId); 
       
   277 	
       
   278 		TUint localisableResourceId = 1; // only initialising this here to keep the compiler happy, as it's concerned that the variable might be used without having been initialised. The variable should be initialised later, before it's used
       
   279 	
       
   280 		try {
       
   281 				ReadMandatoryInfoL(resourceReader);
       
   282 			
       
   283 				err = ReadNonLocalisableInfoL(resourceReader, localisableResourceId);
       
   284 	
       
   285 				if (!err)
       
   286 				{	
       
   287 					err = ReadNonLocalisableOptionalInfoL(resourceReader, registrationFile);
       
   288 				}
       
   289 			}
       
   290 			catch(const CResourceFileException& aObject)
       
   291 			{
       
   292 			
       
   293 				delete registrationFile;
       
   294 				cout<< aObject.GetMsg()<< endl;
       
   295 				return EFalse; // might have read something, but failed to setup enough info to make it worthwhile trying to read any more
       
   296 			}
       
   297 		
       
   298 		TBool useDefaultIcons = ETrue;
       
   299 	
       
   300 		if(iLocalisableResourceFileName)
       
   301 		{
       
   302 			std::string localizeFileName = Ptr16ToString(iLocalisableResourceFileName);
       
   303 
       
   304 			std::vector<FileDescription*>::const_iterator filedesIter;
       
   305 			//std::wstring iFile;
       
   306 			std::wstring iLocalizeFile;
       
   307 			//std::string aFileName;
       
   308 			std::string iLocalFilePath;
       
   309 
       
   310 			std::string iLocalFileExt(".r");
       
   311 			
       
   312 			for(filedesIter = aFileDescription.begin() ; filedesIter != aFileDescription.end(); ++filedesIter)
       
   313 			{
       
   314 				iLocalizeFile = (*filedesIter)->GetLocalFile();
       
   315 			
       
   316 				iLocalFilePath = wstring2string(iLocalizeFile);
       
   317 
       
   318 				if((iLocalFilePath.find(localizeFileName,0) == std::wstring::npos) 
       
   319 						|| (iLocalFilePath.find(iLocalFileExt,0) == std::wstring::npos))
       
   320 					continue;
       
   321 
       
   322 				size_t found;
       
   323 				std::string Locale;
       
   324 				int iLocale = 0;
       
   325 			
       
   326 				found=iLocalFilePath.find_last_of(".");
       
   327 				if(found)
       
   328 					Locale = iLocalFilePath.substr(found+2);
       
   329 
       
   330 				iLocale = atoi(Locale.c_str()); 
       
   331 				if(!iLocale)
       
   332 					iLocale = KNonLocalized;
       
   333 			
       
   334 				CResourceFile* tlocalisableFile = NULL;
       
   335 
       
   336 				if(aInRom)
       
   337 				{
       
   338 					std::string LocalFile = FullNameWithoutDrive(iLocalFilePath);
       
   339 					iLocalFilePath = aRomPath + LocalFile;
       
   340 				}
       
   341 
       
   342 				try {
       
   343 					// open the localisable resource file	
       
   344 					tlocalisableFile = new CResourceFile(iLocalFilePath, 0, 0);
       
   345 					if(NULL==tlocalisableFile)
       
   346 					{
       
   347 						std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   348 						throw CResourceFileException(errMsg);
       
   349 					}
       
   350 	
       
   351 					if (!err)
       
   352 					{
       
   353 						if (tlocalisableFile && (localisableResourceId & KResourceOffsetMask))
       
   354 							tlocalisableFile->ConfirmSignatureL();
       
   355 
       
   356 						err = ReadLocalisableInfoLoopL(*tlocalisableFile, localisableResourceId, useDefaultIcons, iLocale);
       
   357 					}
       
   358 						
       
   359 					delete tlocalisableFile;
       
   360 				}
       
   361 				catch(const CResourceFileException& aObject)
       
   362 				{
       
   363 					LocalizeError = 1;
       
   364 					aObject.Display();
       
   365 					delete tlocalisableFile;
       
   366 				}
       
   367 			}
       
   368 		}
       
   369 	
       
   370 	// if anything went wrong, we tell the caller that the read was unsuccessful. Some
       
   371 	// of the members of this class may contain data which is not complete, but this doesn't matter
       
   372 	// because the caller shouldn't try to access the data if the read was unsuccessful
       
   373 	TBool readSuccessful = 0;
       
   374 	if(!LocalizeError)
       
   375 		readSuccessful = (err == KErrNone);
       
   376 	delete registrationFile;
       
   377 	return readSuccessful;
       
   378 }
       
   379 
       
   380 
       
   381 // reads as much info as it can
       
   382 // at least captions and icons must be setup on return from this method (using defaults if necessary)
       
   383 TBool CAppInfoReader::ReadL()
       
   384 {
       
   385 	TUint fileOffset = 0;
       
   386 	TInt fileLength = 0;
       
   387 	TUid firstUid(KExecutableImageUidVal);
       
   388 	TUid middleUid(KUidApp);
       
   389 	TInt err;
       
   390 	TInt LocalizeError = 0;
       
   391 	TUid reguid;
       
   392 	
       
   393 	CResourceFile* registrationFile = new CResourceFile(iRegistrationFileName, fileOffset, fileLength);
       
   394 	if(NULL==registrationFile)
       
   395 	{
       
   396 		std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   397 		throw CResourceFileException(errMsg);
       
   398 	}
       
   399 
       
   400 	if(registrationFile)
       
   401 	{
       
   402 		iAppUid = registrationFile->ReadAppUidL();
       
   403 		if(!iAppUid.GetUid())
       
   404 		{
       
   405 			std::string errMsg= "Failed : Invalid Resource File. Null Application UID.";
       
   406 			throw CResourceFileException(errMsg);
       
   407 		}
       
   408 
       
   409 		reguid = registrationFile->ReadFileUidL();
       
   410 		if(reguid.GetUid()!= KUidAppRegistrationResourceFile)
       
   411 		{
       
   412 			std::string errMsg= "Failed : Invalid Resource File. UID2 is not defined.";
       
   413 			throw CResourceFileException(errMsg);
       
   414 		}
       
   415 	}
       
   416 
       
   417 	// set the TUidType for the app binary
       
   418 	// cannot read the TEntry info from the app binary because it's in \sys\bin
       
   419 	iAppBinaryUidType = TUidType(firstUid, middleUid, iAppUid);	
       
   420 	
       
   421 	RResourceReader	resourceReader;
       
   422 	resourceReader.OpenL(registrationFile, KAppRegistrationInfoResourceId);	
       
   423 
       
   424 	TUint localisableResourceId = 1; // only initialising this here to keep the compiler happy, as it's concerned that the variable might be used without having been initialised. The variable should be initialised later, before it's used
       
   425 
       
   426 	try {
       
   427 			ReadMandatoryInfoL(resourceReader);
       
   428 		
       
   429 			err = ReadNonLocalisableInfoL(resourceReader, localisableResourceId);
       
   430 
       
   431 			if (!err)
       
   432 			{	
       
   433 				err = ReadNonLocalisableOptionalInfoL(resourceReader, registrationFile);
       
   434 			}
       
   435 		}
       
   436 		catch(const CResourceFileException& aObject)
       
   437 		{
       
   438 		
       
   439 			delete registrationFile;
       
   440 			cout<< aObject.GetMsg()<< endl;
       
   441 			return EFalse; // might have read something, but failed to setup enough info to make it worthwhile trying to read any more
       
   442 		}
       
   443 	
       
   444 	TBool useDefaultIcons = ETrue;
       
   445 
       
   446 	if(iLocalisableResourceFileName)
       
   447 	{
       
   448 		std::string localizeFileName = Ptr16ToString(iLocalisableResourceFileName);
       
   449 		std::string folder;
       
   450 		std::string file;
       
   451 		size_t found;
       
   452 		std::string iLocalPath(iDrivePath);
       
   453 
       
   454 		#ifdef __LINUX__
       
   455 	  	found=localizeFileName.find_last_of("//");
       
   456 		#else
       
   457 		found=localizeFileName.find_last_of("/\\");
       
   458 		#endif
       
   459 
       
   460 	  	if(found)
       
   461 	  		folder = localizeFileName.substr(0,found);
       
   462 	  	else
       
   463 		{
       
   464 			#ifdef __LINUX__
       
   465 			folder.assign("/");	  		
       
   466 			#else
       
   467 			folder.assign("\\");
       
   468 			#endif
       
   469 		}
       
   470 	  	
       
   471 	  	file = localizeFileName.substr(found+1);
       
   472 		file.append(".");
       
   473 		
       
   474 		iLocalPath.append(folder);
       
   475 				
       
   476 		std::wstring iFilePath = string2wstring(iLocalPath);
       
   477 		std::wstring iFileName = string2wstring(file);
       
   478 
       
   479 		#ifdef __LINUX__
       
   480 		iLocalPath.append("/");
       
   481 		#else
       
   482 		iLocalPath.append("\\");
       
   483 		#endif
       
   484 		
       
   485 		std::list<std::wstring> locDirs;
       
   486 		GetDirContents( iFilePath, locDirs );
       
   487 
       
   488 	 	std::list<std::wstring>::iterator curr = locDirs.begin();
       
   489 		for( curr = locDirs.begin(); curr != locDirs.end(); ++curr )
       
   490 		{
       
   491 			if (curr->find(iFileName,0) != std::wstring::npos)
       
   492 			{
       
   493 			    std::string fName;
       
   494 				std::string sAbsolutePath;
       
   495 				sAbsolutePath.assign(iLocalPath);
       
   496 			 	fName = wstring2string( *curr );
       
   497 
       
   498 			   	sAbsolutePath.append(fName);
       
   499 				//cout << sAbsolutePath<<endl;
       
   500 				
       
   501 				std::string Locale;
       
   502 				int iLocale = 0;
       
   503 		
       
   504 				found=fName.rfind(".r");
       
   505 				if(found!=string::npos)
       
   506 					Locale = fName.substr(found+2);
       
   507 				else
       
   508 					continue;
       
   509 
       
   510 				iLocale = atoi(Locale.c_str()); 
       
   511 			    if(!iLocale)
       
   512 					iLocale = KNonLocalized;
       
   513 				   
       
   514 				CResourceFile* tlocalisableFile = NULL;
       
   515 
       
   516 				try {
       
   517 					// open the localisable resource file	
       
   518 					tlocalisableFile = new CResourceFile(sAbsolutePath, 0, 0);
       
   519 					if(NULL==tlocalisableFile)
       
   520 					{
       
   521 						std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   522 						throw CResourceFileException(errMsg);
       
   523 					}
       
   524 
       
   525 					if (!err)
       
   526 					{
       
   527 						if (tlocalisableFile && (localisableResourceId & KResourceOffsetMask))
       
   528 							tlocalisableFile->ConfirmSignatureL();
       
   529 
       
   530 						err = ReadLocalisableInfoLoopL(*tlocalisableFile, localisableResourceId, useDefaultIcons, iLocale);
       
   531 					}
       
   532 					
       
   533 					delete tlocalisableFile;
       
   534 				}
       
   535 				catch(const CResourceFileException& aObject)
       
   536 				{
       
   537 					LocalizeError = 1;
       
   538 					aObject.Display();
       
   539 					delete tlocalisableFile;
       
   540 				}
       
   541 			}
       
   542 		}
       
   543 	}
       
   544 
       
   545 	// if anything went wrong, we tell the caller that the read was unsuccessful. Some
       
   546 	// of the members of this class may contain data which is not complete, but this doesn't matter
       
   547 	// because the caller shouldn't try to access the data if the read was unsuccessful
       
   548 	TBool readSuccessful = 0;
       
   549 	if(!LocalizeError)
       
   550 		readSuccessful = (err == KErrNone);
       
   551 	delete registrationFile;
       
   552 	return readSuccessful;
       
   553 }
       
   554 
       
   555 // this method reads the minimum information required to register an app
       
   556 // if this fails (Leaves), we say the read has been unsuccessful
       
   557 
       
   558 void CAppInfoReader::ReadMandatoryInfoL(RResourceReader& aResourceReader)
       
   559 {
       
   560 	aResourceReader.ReadUint32L(); // skip over LONG reserved_long
       
   561 	aResourceReader.ReadUint32L(); // skip over LLINK reserved_llink
       
   562 
       
   563 	// read LTEXT app_file
       
   564 	PtrC16* appFile = aResourceReader.ReadTPtrCL();
       
   565 
       
   566 	if(NULL==appFile)
       
   567 	{
       
   568 		std::string errMsg= "Failed : Invalid Resource File Name. Application File Name is Mandatory.";
       
   569 		throw CResourceFileException(errMsg);
       
   570 	}
       
   571 
       
   572 	ConvertToPlatformSpecificPath(appFile->iPtr, appFile->iMaxLength);
       
   573 
       
   574 	TInt err=0;
       
   575 	// this object gets used for 2 purposes: first to check that a ParsePtrC can be created over "appFile" without it panicking, and second to construct iAppBinaryFullName
       
   576 	err = FindWild(appFile); // do this before creating a TParsePtrC, since TParsePtrC's constructor panics if it fails (which would provide an easy way for malware to kill the Apparc server)
       
   577 
       
   578 	if(err==1)
       
   579 	{
       
   580 		std::string errMsg= "Failed : Invalid Resource File Name : Wild Characters Present.";
       
   581 		throw CResourceFileException(errMsg);
       
   582 	}
       
   583 		
       
   584 	ParsePtrC appFileParser(appFile);
       
   585 
       
   586 	// read LONG attributes
       
   587 	iCapability.iAttributes = aResourceReader.ReadUint32L();
       
   588 
       
   589 
       
   590 	if(!appFileParser.NamePresent())
       
   591 	{
       
   592 		appFileParser.SetToNull();	//Pointer pointing to the content of Resource file. To be destroyed by RResourceReader.
       
   593 		std::string errMsg= "Failed : Invalid Resource File Name : Name Not Present.";
       
   594 		throw CResourceFileException(errMsg);
       
   595 	}
       
   596 		
       
   597 	std::string appNameWithoutExtension(appFileParser.Name());
       
   598 	std::string registrationFileDrive;
       
   599 	
       
   600 	string::size_type index = iRegistrationFileName.find( ':' );
       
   601 	if( index != string::npos )
       
   602 		registrationFileDrive.assign(iRegistrationFileName, index-1, 2);
       
   603 
       
   604 	if (iCapability.iAttributes & TAppCapability::ENonNative)
       
   605 	{
       
   606 		if (!appFileParser.PathPresent() || !appFileParser.ExtPresent())
       
   607 		{
       
   608 			appFileParser.SetToNull();	//Pointer pointing to the content of Resource file. To be destroyed by RResourceReader.
       
   609 			std::string errMsg= "Failed : Invalid Resource File Name : Path And Extension Not Present.";
       
   610 			throw CResourceFileException(errMsg);
       
   611 		}
       
   612 
       
   613 		std::string appFilePath(appFileParser.Path());
       
   614 		std::string appFileNameAndExt(appFileParser.NameAndExt());
       
   615 
       
   616 		if (appFileParser.DrivePresent())
       
   617 			registrationFileDrive = appFileParser.Drive();
       
   618 
       
   619 		err = FindWild(registrationFileDrive, appFilePath, appFileNameAndExt);
       
   620 		if(err==1)
       
   621 		{
       
   622 			appFileParser.SetToNull();	//Pointer pointing to the content of Resource file. To be destroyed by RResourceReader.
       
   623 			std::string errMsg= "Failed : Invalid Resource File Name : Wild Characters Present.";
       
   624 			throw CResourceFileException(errMsg);
       
   625 		}
       
   626 	}
       
   627 	else if (iCapability.iAttributes & TAppCapability::EBuiltAsDll)
       
   628 	{
       
   629 		appFileParser.SetToNull();	//Pointer pointing to the content of Resource file. To be destroyed by RResourceReader.
       
   630 		std::string errMsg= "Failed : legacy dll-style app.";
       
   631 		throw CResourceFileException(errMsg);
       
   632 	}
       
   633 	else
       
   634 	{
       
   635 		// exe-style app
       
   636 		err = FindWild(registrationFileDrive, KAppBinaryPathAndExtension, appNameWithoutExtension);
       
   637 		if(err==1)
       
   638 		{
       
   639 			appFileParser.SetToNull();	//Pointer pointing to the content of Resource file. To be destroyed by RResourceReader.
       
   640 			std::string errMsg= "Failed : Invalid Resource File Name : Wild Characters Present.";
       
   641 			throw CResourceFileException(errMsg);
       
   642 		}
       
   643 	}
       
   644 
       
   645 	iAppBinaryFullName = new Ptr16(appFileParser.FullName()->iMaxLength);
       
   646 	if(NULL==iAppBinaryFullName || NULL == iAppBinaryFullName->GetPtr())
       
   647 	{
       
   648 		std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   649 		throw CResourceFileException(errMsg);
       
   650 	}
       
   651 	iAppBinaryFullName->UpdateLength(appFileParser.FullName()->iMaxLength);
       
   652 	BufCpy(iAppBinaryFullName->GetPtr(),appFileParser.FullName()->iPtr,appFileParser.FullName()->iMaxLength);
       
   653 
       
   654 	appFileParser.SetToNull();	//Pointer pointing to the content of Resource file. To be destroyed by RResourceReader.
       
   655 	appFile->iPtr = NULL;		//Pointer pointing to the content of Resource file. To be destroyed by RResourceReader.
       
   656 	delete appFile;
       
   657 }
       
   658 
       
   659 /*
       
   660 * Converts PtrC16* to Ptr16* datatype. Creates a Buffer copy.
       
   661 */
       
   662 
       
   663 Ptr16* CAppInfoReader::CreateFullIconFileNameL(const PtrC16* aIconFileName) const
       
   664 {
       
   665 	Ptr16* filename = NULL;
       
   666 
       
   667 	if (aIconFileName->iMaxLength == 0)
       
   668 		return NULL;
       
   669 
       
   670 	/*
       
   671 	 * aIconFileName may contain a valid string in some format (for eg. URI format) other than path to a regular file on disk
       
   672 	 * and that can be a mbm or non-mbm file. Such a filename will be reported as invalid filename by iFs.IsValidName() method. 
       
   673 	 * aIconFileName will be returned since it is a valid string. 
       
   674 	 */	
       
   675 	
       
   676 	ParsePtrC parsePtr(aIconFileName);
       
   677 
       
   678 	if (parsePtr.IsWild() || !parsePtr.PathPresent() || !parsePtr.NamePresent())
       
   679 		return NULL;
       
   680 
       
   681 	filename = new Ptr16(aIconFileName->iMaxLength);
       
   682 	if(NULL==filename || NULL == filename->GetPtr())
       
   683 	{
       
   684 		parsePtr.SetToNull();
       
   685 		std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   686 		throw CResourceFileException(errMsg);
       
   687 	}
       
   688 	filename->UpdateLength(aIconFileName->iMaxLength);
       
   689 	BufCpy(filename->GetPtr(),aIconFileName->iPtr,aIconFileName->iMaxLength);
       
   690 
       
   691 	std::wstring iFileName = Ptr16ToWstring(filename);
       
   692 	std::wstring iFilePath = string2wstring(iDrivePath);
       
   693 	std::string fullnamewitoutdrive = parsePtr.FullNameWithoutDrive();
       
   694 	std::wstring iFilename1 = string2wstring(fullnamewitoutdrive);
       
   695 
       
   696 	if(parsePtr.DrivePresent())
       
   697 		iFilePath.append(iFilename1);
       
   698 	else
       
   699 		iFilePath.append(iFileName);
       
   700 	
       
   701 	// check for fully qualified icon filename
       
   702 	if (parsePtr.DrivePresent() && FileExists(iFileName))
       
   703 	{
       
   704 		parsePtr.SetToNull();
       
   705 		return filename;	
       
   706 	}
       
   707 	else
       
   708 	{
       
   709 		// check for icon file on same drive as localisable resource file
       
   710 		std::string localisableResourceFileDrive = parsePtr.Drive();
       
   711 		TInt ret = FindWild(aIconFileName);
       
   712 		if(ret == 0 && FileExists(iFilePath))
       
   713 		{
       
   714 			parsePtr.SetToNull();
       
   715 			return filename;
       
   716 		}
       
   717 		else
       
   718 		{
       
   719 			ParsePtrC parsePtr_reg(iRegistrationFileName);
       
   720 			std::string registrationFileDrive = parsePtr_reg.Drive();
       
   721 
       
   722 			if(registrationFileDrive.compare(localisableResourceFileDrive))
       
   723 			{
       
   724 				// check for icon file on same drive as registration file
       
   725 				std::string Registrationfilepath(parsePtr_reg.FullPath());
       
   726 				Registrationfilepath.append(parsePtr.NameAndExt());
       
   727 				std::wstring iRegFilePath = string2wstring(Registrationfilepath);
       
   728 				std::string iconfile = parsePtr.StrName();
       
   729 					
       
   730 				ret = FindWild(registrationFileDrive,iconfile,localisableResourceFileDrive);
       
   731 				if(ret == 0 && FileExists(iRegFilePath))
       
   732 				{
       
   733 					parsePtr_reg.SetToNull();
       
   734 					parsePtr.SetToNull();
       
   735 					return filename;
       
   736 				}
       
   737 			}
       
   738 			parsePtr_reg.SetToNull();
       
   739 		}
       
   740 	}
       
   741 
       
   742 	parsePtr.SetToNull();	//To Avoid double delete in destructor. To be destroyed by RResourceReader.
       
   743 							//Same as iIconFileName data member of class CAppInfoReader. Destructor will delete.
       
   744 	return NULL;					// Or to be deleted by calling function.
       
   745 }
       
   746 
       
   747 /*
       
   748 * Read Localizable resource file.
       
   749 @ Param: aResourceFile - Localizable file Handler.
       
   750 @ Param: aResourceId of Localizable file.
       
   751 */
       
   752 
       
   753 TInt CAppInfoReader::ReadLocalisableInfoLoopL(CResourceFile& aResourceFile, TUint aResourceId, TBool& aUseDefaultIcons, TInt& iLocale)
       
   754 {
       
   755 	CAppLocalizableInfo* localinfo = CAppLocalizableInfo::NewL(iRegistrationFileName, iDrivePath);
       
   756 	RResourceReader resourceReader;
       
   757 	resourceReader.OpenL(&aResourceFile, aResourceId); //original
       
   758 
       
   759 	localinfo->SetLocale(iLocale);
       
   760 
       
   761 	resourceReader.ReadUint32L(); // skip over LONG reserved_long
       
   762 	resourceReader.ReadUint32L(); // skip over LLINK reserved_llink
       
   763 
       
   764 	// read LTEXT short_caption
       
   765 	Ptr16* shortCaption = resourceReader.ReadHBufCL();
       
   766 	localinfo->SetShortCaption(shortCaption);
       
   767 
       
   768 	resourceReader.ReadUint32L(); // skip over LONG reserved_long
       
   769 	resourceReader.ReadUint32L(); // skip over LLINK reserved_llink
       
   770 
       
   771 	// read LTEXT caption
       
   772 	Ptr16* caption = resourceReader.ReadHBufCL();
       
   773 	if(NULL == caption)
       
   774 	{
       
   775 		Ptr16* appBinaryFullName = CAppInfoReader::AppBinaryFullName();
       
   776 
       
   777 		caption = new Ptr16(appBinaryFullName->GetLength());
       
   778 		if(NULL == caption)
       
   779 			{
       
   780 				std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   781 				throw CResourceFileException(errMsg);
       
   782 			}
       
   783 		BufCpy(caption->GetPtr(),appBinaryFullName->GetPtr(),appBinaryFullName->GetLength());
       
   784 		caption->UpdateLength(appBinaryFullName->GetLength());
       
   785 	}
       
   786 	localinfo->SetCaption(caption);
       
   787 	
       
   788 	// read WORD number_of_icons
       
   789 	const TInt numOfIcons = resourceReader.ReadInt16L();
       
   790 	localinfo->SetNumOfAppIcons(numOfIcons);
       
   791 
       
   792 	// read LTEXT icon_file
       
   793 	iIconFileName = NULL;
       
   794 	PtrC16* iconFile = resourceReader.ReadTPtrCL();
       
   795 
       
   796 	if(NULL != iconFile)
       
   797 	{
       
   798 		ConvertToPlatformSpecificPath(iconFile->iPtr, iconFile->iMaxLength);
       
   799 		Ptr16*	iconFileName = CreateFullIconFileNameL(iconFile);
       
   800 		
       
   801 		if (iconFileName)
       
   802 		{
       
   803 			localinfo->SetIconFileName(iconFileName);
       
   804 			aUseDefaultIcons = EFalse;
       
   805 			iNonMbmIconFile = ETrue;
       
   806 			iconFile->iPtr = NULL;
       
   807 			delete iconFile;
       
   808 		}
       
   809 		else
       
   810 		{
       
   811 			iconFile->iPtr = NULL;
       
   812 			delete iconFile;
       
   813 			std::string errMsg= "Failed : Icon File not present in Device.";
       
   814 			throw CResourceFileException(errMsg);
       
   815 		}
       
   816 	}
       
   817 
       
   818 	//Read ViewData  of Localizable file.
       
   819 	localinfo->ReadViewDataL(resourceReader);
       
   820 
       
   821 	// Read LTEXT group_name
       
   822 	// If a localised group name has been specified, it overrides
       
   823 	// The group name (if any), specified by APP_REGISTRATION_INFO
       
   824 
       
   825 	PtrC16* groupName = resourceReader.ReadTPtrCL();
       
   826 
       
   827 	if(NULL != groupName)
       
   828 	{
       
   829 		if (groupName->iMaxLength > 0)
       
   830 		{
       
   831 			Ptr16* gName = new Ptr16(groupName->iMaxLength);
       
   832 			if(NULL==gName || NULL == gName->GetPtr())
       
   833 			{
       
   834 				delete groupName;
       
   835 				std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   836 				throw CResourceFileException(errMsg);
       
   837 			}
       
   838 			gName->UpdateLength(groupName->iMaxLength);
       
   839 			BufCpy(gName->GetPtr(),groupName->iPtr,groupName->iMaxLength);
       
   840 			localinfo->SetGroupName(gName);
       
   841 			groupName->iPtr = NULL; //To Avoid double delete in destructor. To be destroyed by RResourceReader.
       
   842 		}
       
   843 	}
       
   844 
       
   845 	iAppLocalizableInfo.push_back(localinfo);
       
   846 	delete groupName;
       
   847 	return 0;
       
   848 }
       
   849 
       
   850 void CAppInfoReader::ReadOpaqueDataL(TUint aResourceId, CResourceFile* aRegistrationFile, TUint32 aServiceUid)
       
   851 {
       
   852 	Ptr8* opaqueData = NULL;
       
   853 	int iLocale = 0;
       
   854 
       
   855 	if (aResourceId == 0)
       
   856 	{
       
   857 		opaqueData = new Ptr8(1);
       
   858 		if(NULL==opaqueData || NULL==opaqueData->GetPtr())
       
   859 		{
       
   860 			std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   861 			throw CResourceFileException(errMsg);
       
   862 		}
       
   863 		*(opaqueData->GetPtr()) = 0;
       
   864 		opaqueData->UpdateLength(1);
       
   865 	}
       
   866 	else
       
   867 	{
       
   868 		if (aResourceId & KResourceOffsetMask)
       
   869 		{
       
   870 			if(iLocalisableResourceFileName)
       
   871 			{
       
   872 				std::string localizeFileName = Ptr16ToString(iLocalisableResourceFileName);
       
   873 				std::string folder;
       
   874 				std::string file;
       
   875 				size_t found;
       
   876 				size_t find;
       
   877 				std::string iLocalPath(iDrivePath);
       
   878 		
       
   879 				#ifdef __LINUX__
       
   880 				found=localizeFileName.find_last_of("//");
       
   881 				#else
       
   882 				found=localizeFileName.find_last_of("/\\");
       
   883 				#endif
       
   884 
       
   885 				if(found)
       
   886 					folder = localizeFileName.substr(0,found);
       
   887 				else
       
   888 				{
       
   889 					#ifdef __LINUX__
       
   890 					folder.assign("/");
       
   891 					#else
       
   892 					folder.assign("\\");
       
   893 					#endif					
       
   894 				}
       
   895 			
       
   896 				file = localizeFileName.substr(found+1);
       
   897 				file.append(".");
       
   898 			
       
   899 				iLocalPath.append(folder);
       
   900 					
       
   901 				std::wstring iFilePath = string2wstring(iLocalPath);
       
   902 				std::wstring iFileName = string2wstring(file);
       
   903 				#ifdef __LINUX__
       
   904 				iLocalPath.append("/");
       
   905 				#else
       
   906 				iLocalPath.append("\\");
       
   907 				#endif
       
   908 
       
   909 		
       
   910 				std::list<std::wstring> locDirs;
       
   911 				GetDirContents( iFilePath, locDirs );
       
   912 			
       
   913 				std::list<std::wstring>::iterator curr = locDirs.begin();
       
   914 				for( curr = locDirs.begin(); curr != locDirs.end(); ++curr )
       
   915 				{
       
   916 					if (curr->find(iFileName,0) != std::wstring::npos)
       
   917 					{
       
   918 						std::string fName;
       
   919 						std::string sAbsolutePath;
       
   920 						std::string Locale;
       
   921 						sAbsolutePath.assign(iLocalPath);
       
   922 						fName = wstring2string( *curr );
       
   923 
       
   924 						find=fName.rfind("backup");
       
   925 						if(find != string::npos)
       
   926 							continue;
       
   927 
       
   928 						sAbsolutePath.append(fName);										
       
   929 						found=fName.find_last_of(".");
       
   930 						if(found)
       
   931 							Locale = fName.substr(found+2);
       
   932 			
       
   933 						iLocale = atoi(Locale.c_str()); 
       
   934 						if(!iLocale)
       
   935 							iLocale = KNonLocalized;
       
   936 					   
       
   937 						CResourceFile* tlocalisableFile = NULL;
       
   938 			
       
   939 						// open the localisable resource file	
       
   940 						tlocalisableFile = new CResourceFile(sAbsolutePath, 0, 0);
       
   941 						if(NULL==tlocalisableFile)
       
   942 						{
       
   943 							std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   944 							throw CResourceFileException(errMsg);
       
   945 						}
       
   946 			
       
   947 						if (tlocalisableFile)
       
   948 						{
       
   949 							if (tlocalisableFile && (aResourceId & KResourceOffsetMask))
       
   950 								tlocalisableFile->ConfirmSignatureL();
       
   951 
       
   952 							opaqueData = tlocalisableFile->AllocReadL(aResourceId);
       
   953 
       
   954 							if(opaqueData)
       
   955 							{
       
   956 								const TUint8* currentPtr=opaqueData->GetPtr();//TUint8 pointer is used
       
   957 									
       
   958 								//resource string length is limited to 255 characters max.
       
   959 								const TInt unicodeLength=*currentPtr;
       
   960 		
       
   961 								++currentPtr;
       
   962 								if (unicodeLength!=0)
       
   963 								{
       
   964 									if (REINTERPRET_CAST(TUint,currentPtr)&0x1)
       
   965 									{			
       
   966 										// The resource compiler puts out a padding byte (arbitrarily 0xab)
       
   967 										// to ensure the alignment of Unicode strings within each resource.
       
   968 										if(*currentPtr!=0xab)
       
   969 										{
       
   970 											std::string errMsg= "Failed : Trying to access invalid registrationFile";
       
   971 											throw CResourceFileException(errMsg);
       
   972 										}
       
   973 										++currentPtr;
       
   974 									}
       
   975 								}
       
   976 								
       
   977 								opaqueData->SetPtr(currentPtr);
       
   978 								opaqueData->ForceLength(unicodeLength*2);
       
   979 							}
       
   980 							else
       
   981 							{
       
   982 								opaqueData = new Ptr8(1);
       
   983 								if(NULL==opaqueData || NULL==opaqueData->GetPtr())
       
   984 								{
       
   985 									std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   986 									throw CResourceFileException(errMsg);
       
   987 								}
       
   988 								*(opaqueData->GetPtr()) = 0;
       
   989 								opaqueData->SetLength(1);
       
   990 							}
       
   991 
       
   992 							CAppLocalOpaqueDataInfo* opaqueInfo = CAppLocalOpaqueDataInfo::NewL(iLocale, aServiceUid, opaqueData);
       
   993 							iOpaqueDataArray.push_back(opaqueInfo);
       
   994 							
       
   995 						}
       
   996 						delete tlocalisableFile;
       
   997 					}
       
   998 				}
       
   999 			}
       
  1000 		}
       
  1001 		else
       
  1002 		{	// expecting opaque data to be in the registration file
       
  1003 			assert(aRegistrationFile);
       
  1004 			opaqueData = aRegistrationFile->AllocReadL(aResourceId); //lint !e613 Suppress ossible use of null pointer
       
  1005 
       
  1006 			const TUint8* currentPtr=opaqueData->GetPtr();//TUint8 pointer is used
       
  1007 
       
  1008 			//resource string length is limited to 255 characters max.
       
  1009 			const TInt unicodeLength=*currentPtr;
       
  1010 		
       
  1011 			++currentPtr;
       
  1012 			if (unicodeLength!=0)
       
  1013 			{
       
  1014 				if (REINTERPRET_CAST(TUint,currentPtr)&0x1)
       
  1015 				{
       
  1016 					// The resource compiler puts out a padding byte (arbitrarily 0xab)
       
  1017 					// to ensure the alignment of Unicode strings within each resource.
       
  1018 					if(*currentPtr!=0xab)
       
  1019 					{
       
  1020 						std::string errMsg= "Failed : Trying to access invalid registrationFile";
       
  1021 						throw CResourceFileException(errMsg);
       
  1022 					}
       
  1023 					++currentPtr;
       
  1024 				}
       
  1025 			}
       
  1026 
       
  1027 			opaqueData->SetPtr(currentPtr);
       
  1028 			opaqueData->SetLength(unicodeLength*2);
       
  1029 
       
  1030 			CAppLocalOpaqueDataInfo* opaqueInfo = CAppLocalOpaqueDataInfo::NewL(iLocale, aServiceUid, opaqueData);
       
  1031 			iOpaqueDataArray.push_back(opaqueInfo);
       
  1032 		}
       
  1033 	}
       
  1034 }
       
  1035 
       
  1036 TInt CAppInfoReader::ReadNonLocalisableOptionalInfoL(RResourceReader& aResourceReader, CResourceFile* aRegistrationFile)	
       
  1037 {
       
  1038 	// read LEN WORD STRUCT service_list[]
       
  1039 	TInt serviceCount = 0;
       
  1040 	TInt err = 0;
       
  1041 	// service information was not present in the first release of the registration file
       
  1042 	// APP_REGISTRATION_INFO resource struct
       
  1043 	// this method must not leave if the registration file doesn't contain service information, so the
       
  1044 	// following call to ReadInt16L is trapped to ensure this method doesn't leave just because
       
  1045 	// there is no more information in the resource to read (KErrEof)
       
  1046 
       
  1047 	serviceCount = aResourceReader.ReadInt16L();
       
  1048 
       
  1049 	if (!iServiceArray && serviceCount > 0)
       
  1050 	{
       
  1051 		iServiceArray = new std::vector<TAppServiceInfo*>;
       
  1052 
       
  1053 		if(NULL==iServiceArray){
       
  1054 			std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
  1055 			throw CResourceFileException(errMsg);
       
  1056 		}
       
  1057 	}
       
  1058 	
       
  1059 	while (serviceCount--)
       
  1060 	{
       
  1061 		const TUid serviceUid = {aResourceReader.ReadUint32L()};
       
  1062 		
       
  1063 		if ((serviceUid == KOpenServiceUid) && (iOpenServiceIsLegacy))
       
  1064 		{
       
  1065 			assert(iIndexOfFirstOpenService == 0);
       
  1066 			// If we found an Open service in the SERVICE_INFO declaration
       
  1067 			// then we must ignore the legacy one
       
  1068 			if ( 0 < iServiceArray->size() )
       
  1069 			{
       
  1070 				(*iServiceArray)[0]->Release();
       
  1071 				iServiceArray->erase(iServiceArray->begin());
       
  1072 			}
       
  1073 			iOpenServiceIsLegacy = EFalse;
       
  1074 			iIndexOfFirstOpenService = KErrNotFound;
       
  1075 		}
       
  1076 		
       
  1077 		std::vector<TDataTypeWithPriority*>* mimeTypesSupported = new std::vector<TDataTypeWithPriority*>;
       
  1078 		if(NULL==mimeTypesSupported)
       
  1079 		{
       
  1080 			std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
  1081 			throw CResourceFileException(errMsg);
       
  1082 		}
       
  1083 
       
  1084 		ReadMimeTypesSupportedL(aResourceReader, *mimeTypesSupported);
       
  1085 		
       
  1086 		const TUint resourceId = aResourceReader.ReadUint32L();
       
  1087 
       
  1088 		ReadOpaqueDataL(resourceId, aRegistrationFile, serviceUid.iUid);
       
  1089 
       
  1090 		TAppServiceInfo* serviceInfo = new TAppServiceInfo(serviceUid, *mimeTypesSupported);
       
  1091 		if(NULL==serviceInfo)
       
  1092 		{
       
  1093 			std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
  1094 			throw CResourceFileException(errMsg);
       
  1095 		}
       
  1096 
       
  1097 		iServiceArray->push_back(serviceInfo);
       
  1098 
       
  1099 		if ((serviceUid == KOpenServiceUid) && (iIndexOfFirstOpenService < 0))
       
  1100 			iIndexOfFirstOpenService = iServiceArray->size() - 1;
       
  1101 	}
       
  1102 
       
  1103 	// read LLINK opaque_data
       
  1104 	const TUint resourceId = aResourceReader.ReadUint32L();
       
  1105 
       
  1106 	ReadOpaqueDataL(resourceId, aRegistrationFile, 0);
       
  1107 
       
  1108 	return 0;
       
  1109 }
       
  1110 
       
  1111 TInt CAppInfoReader::ReadNonLocalisableInfoL(RResourceReader& aResourceReader, TUint& aLocalisableResourceId)
       
  1112 {
       
  1113 	// read LTEXT localisable_resource_file
       
  1114 	PtrC16*	localisableResourceFileName = aResourceReader.ReadTPtrCL();
       
  1115 
       
  1116 	if(NULL == localisableResourceFileName)
       
  1117 	{
       
  1118 		iLocalisableResourceFileName = NULL;
       
  1119 	}
       
  1120 	else
       
  1121 	{
       
  1122 		ConvertToPlatformSpecificPath(localisableResourceFileName->iPtr, localisableResourceFileName->iMaxLength);
       
  1123 		if (localisableResourceFileName->iMaxLength > 0 )
       
  1124 		{
       
  1125 			ParsePtrC parsePtr(localisableResourceFileName);
       
  1126 
       
  1127 			if(parsePtr.IsValidName())
       
  1128 			{
       
  1129 				iLocalisableResourceFileName = NULL;
       
  1130 				parsePtr.SetToNull();	//To Avoid double Delete in destructor.
       
  1131 				std::string errMsg= "Failed : Invalid localisable Resource File Name";
       
  1132 				throw CResourceFileException(errMsg);
       
  1133 			}
       
  1134 			
       
  1135 			std::string registrationFileDrive;
       
  1136 	
       
  1137 			string::size_type index = iRegistrationFileName.find( ':' );
       
  1138 			if( index != string::npos )
       
  1139 				registrationFileDrive.assign(iRegistrationFileName, index-1, 2);
       
  1140 
       
  1141 			TInt err=0;
       
  1142 			std::string sTemp = parsePtr.StrName();
       
  1143 
       
  1144 			err = FindWild(registrationFileDrive, KAppResourceFileExtension, sTemp);
       
  1145 			if(err==1)
       
  1146 			{
       
  1147 				std::string errMsg= "Failed : Invalid drive for Registration File";
       
  1148 				parsePtr.SetToNull();	//To Avoid double Delete in destructor.
       
  1149 				throw CResourceFileException(errMsg);
       
  1150 			}
       
  1151 
       
  1152 			iLocalisableResourceFileName = new Ptr16(parsePtr.FullName()->iMaxLength);
       
  1153 			if(NULL==iLocalisableResourceFileName || NULL==iLocalisableResourceFileName->GetPtr())
       
  1154 			{
       
  1155 				std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
  1156 				parsePtr.SetToNull();	//To Avoid double Delete in destructor.
       
  1157 				throw CResourceFileException(errMsg);
       
  1158 			}
       
  1159 
       
  1160 			iLocalisableResourceFileName->UpdateLength(parsePtr.FullName()->iMaxLength);
       
  1161 			BufCpy(iLocalisableResourceFileName->GetPtr(),parsePtr.FullName()->iPtr,parsePtr.FullName()->iMaxLength);
       
  1162 
       
  1163 			parsePtr.SetToNull();	//To Avoid double Delete in destructor.
       
  1164 		}
       
  1165 	}
       
  1166 	// read LONG localisable_resource_id
       
  1167 	aLocalisableResourceId = aResourceReader.ReadUint32L();
       
  1168 
       
  1169 	iCapability.iAppIsHidden = aResourceReader.ReadInt8L();
       
  1170 	iCapability.iEmbeddability = static_cast<TAppCapability::TEmbeddability>(aResourceReader.ReadInt8L());
       
  1171 	iCapability.iSupportsNewFile = aResourceReader.ReadInt8L();
       
  1172 	iCapability.iLaunchInBackground = aResourceReader.ReadInt8L();
       
  1173 
       
  1174 	PtrC16* iTemp = aResourceReader.ReadTPtrCL();
       
  1175 
       
  1176 	if(NULL==iTemp || NULL==iTemp->iPtr)
       
  1177 		iCapability.iGroupName = NULL;
       
  1178 	else 
       
  1179 	{
       
  1180 		iCapability.iGroupName = new Ptr16(iTemp->iMaxLength);
       
  1181 		if(NULL==iCapability.iGroupName || NULL == iCapability.iGroupName->GetPtr())
       
  1182 		{
       
  1183 			std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
  1184 			throw CResourceFileException(errMsg);
       
  1185 		}
       
  1186 		iCapability.iGroupName->UpdateLength(iTemp->iMaxLength);
       
  1187 		BufCpy(iCapability.iGroupName->GetPtr(), iTemp->iPtr, iTemp->iMaxLength );
       
  1188 	}
       
  1189 	// read BYTE default_screen_number
       
  1190 	iDefaultScreenNumber = aResourceReader.ReadUint8L();
       
  1191  	
       
  1192 	//read the datatypes
       
  1193 	std::vector<TDataTypeWithPriority*>* datatypes = new std::vector<TDataTypeWithPriority*>;
       
  1194 	if(NULL==datatypes)
       
  1195 	{
       
  1196 			std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
  1197 			throw CResourceFileException(errMsg);
       
  1198 	}
       
  1199 
       
  1200 	ReadMimeTypesSupportedL(aResourceReader, *datatypes);
       
  1201 	//dataTypes is deleted if 
       
  1202 	// A. There are no legacy datatypes
       
  1203 	// B. Control panel plugin apps are not allowed to register MIME types.If they happen to have any, these datatypes should be ignored.
       
  1204 	iServiceArray = NULL;
       
  1205 	if ((iCapability.iAttributes & TAppCapability::EControlPanelItem) || (datatypes->size() == 0))
       
  1206 		delete datatypes;
       
  1207 	else
       
  1208 	{
       
  1209 		iServiceArray = new std::vector<TAppServiceInfo*>;
       
  1210 		if(NULL==iServiceArray)
       
  1211 		{
       
  1212 				delete datatypes;
       
  1213 				std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
  1214 				throw CResourceFileException(errMsg);
       
  1215 		}
       
  1216 
       
  1217 		Ptr8* opaqueData = new Ptr8(1);
       
  1218 		if(NULL==opaqueData || NULL==opaqueData->GetPtr())
       
  1219 		{
       
  1220 			delete datatypes;
       
  1221 			std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
  1222 			throw CResourceFileException(errMsg);
       
  1223 		}
       
  1224 		*(opaqueData->GetPtr()) = 0;
       
  1225 		opaqueData->UpdateLength(0);
       
  1226 
       
  1227 		TAppServiceInfo* serviceInfo = new TAppServiceInfo(KOpenServiceUid, *datatypes);
       
  1228 		if(NULL==serviceInfo)
       
  1229 		{
       
  1230 			delete datatypes;
       
  1231 			std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
  1232 			throw CResourceFileException(errMsg);
       
  1233 		}
       
  1234 		iServiceArray->push_back(serviceInfo);
       
  1235 		iIndexOfFirstOpenService = 0;
       
  1236 		iOpenServiceIsLegacy = ETrue;
       
  1237 	}
       
  1238 
       
  1239 	// read LEN WORD STRUCT file_ownership_list[]
       
  1240 	const TInt fileOwnershipArraySize = aResourceReader.ReadInt16L();
       
  1241 
       
  1242 	iOwnedFileArray = NULL;
       
  1243 	if (fileOwnershipArraySize > 0)
       
  1244 	{
       
  1245 		iOwnedFileArray = new std::vector<Ptr16*>;
       
  1246 		if(NULL==iOwnedFileArray)
       
  1247 		{
       
  1248 			std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
  1249 			throw CResourceFileException(errMsg);
       
  1250 		}
       
  1251 	}
       
  1252 	for (TInt i=0; i < fileOwnershipArraySize; i++)
       
  1253 	{
       
  1254 		PtrC16* fileNamePtr_temp = aResourceReader.ReadTPtrCL();
       
  1255 
       
  1256 		if(NULL != fileNamePtr_temp)
       
  1257 		{
       
  1258 			ConvertToPlatformSpecificPath(fileNamePtr_temp->iPtr, fileNamePtr_temp->iMaxLength);
       
  1259 			Ptr16* fileNamePtr = new Ptr16(fileNamePtr_temp->iMaxLength);
       
  1260 			if(NULL==fileNamePtr || NULL==fileNamePtr->GetPtr())
       
  1261 			{
       
  1262 				std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
  1263 				throw CResourceFileException(errMsg);
       
  1264 			}
       
  1265 			fileNamePtr->UpdateLength(fileNamePtr_temp->iMaxLength);			  
       
  1266 			BufCpy(fileNamePtr->GetPtr(),fileNamePtr_temp->iPtr,fileNamePtr_temp->iMaxLength);
       
  1267 
       
  1268 			iOwnedFileArray->push_back(fileNamePtr);
       
  1269 		}
       
  1270 		else
       
  1271 		{
       
  1272 			Ptr16* fileNamePtr = NULL;
       
  1273 			iOwnedFileArray->push_back(fileNamePtr);
       
  1274 		}
       
  1275 	}
       
  1276 
       
  1277 	return 0;
       
  1278 }
       
  1279 
       
  1280 // This method can be used to check whether app has a WriteDeviceCap 
       
  1281 // and its sid is trusted
       
  1282 void CAppInfoReader::ReadAppSecurityInfo()
       
  1283 {
       
  1284     if (!iSecurityInfoHasBeenRead)
       
  1285     {
       
  1286 		if(NULL==iAppBinaryFullName)
       
  1287 		{
       
  1288 			std::string errMsg= "Failed : Invalid Application Name";
       
  1289 			throw CResourceFileException(errMsg);
       
  1290 		}
       
  1291 
       
  1292 		Ptr16* iBinaryName = new Ptr16(iAppBinaryFullName->GetLength());
       
  1293 		if(NULL == iBinaryName)
       
  1294 		{
       
  1295 				std::string errMsg= "Failed : Memory Allocation Failed";
       
  1296 				throw CResourceFileException(errMsg);
       
  1297 		}
       
  1298 		BufCpy(iBinaryName->GetPtr(),iAppBinaryFullName->GetPtr(),iAppBinaryFullName->GetLength());
       
  1299 		iBinaryName->UpdateLength(iAppBinaryFullName->GetLength());
       
  1300 
       
  1301 		const TInt err = CApaSecurityUtils::CheckAppSecurity( *iBinaryName, 
       
  1302                                         iHasWriteDeviceDataCap, iIsSidTrusted, iDrivePath);
       
  1303 
       
  1304 		delete iBinaryName;
       
  1305 	
       
  1306         if ( KErrNone != err )
       
  1307         {
       
  1308             iHasWriteDeviceDataCap = EFalse;
       
  1309             iIsSidTrusted = EFalse;
       
  1310         }
       
  1311 
       
  1312         iSecurityInfoHasBeenRead = ETrue;   
       
  1313      }
       
  1314 }
       
  1315 
       
  1316 
       
  1317 void CAppInfoReader::ReadMimeTypesSupportedL(RResourceReader& aResourceReader,
       
  1318 	std::vector<TDataTypeWithPriority*>& aMimeTypesSupported)
       
  1319 {
       
  1320 	// read LEN WORD STRUCT datatype_list[]
       
  1321 	const TInt dataTypeArraySize = aResourceReader.ReadInt16L();
       
  1322 	if (dataTypeArraySize <= 0)
       
  1323 		return;
       
  1324 	
       
  1325 	for (TInt i=0; i < dataTypeArraySize; i++)
       
  1326 	{
       
  1327 		TDataTypePriority priority = static_cast<TDataTypePriority>(aResourceReader.ReadInt32L());
       
  1328 
       
  1329 		//Check for data priority of UnTrusted apps however the trusted apps will not have any restrictions 
       
  1330 		//over the data priority.	
       
  1331 		//If an untrusted app has write device data capability (i.e. still has priority = KDataTypePrioritySystem),
       
  1332 		//do not restrict to KDataTypeUnTrustedPriorityThreshold
       
  1333 		if (priority > KDataTypeUnTrustedPriorityThreshold || priority == KDataTypePrioritySystem )
       
  1334 	    {
       
  1335 		    ReadAppSecurityInfo();
       
  1336 
       
  1337             if (priority == KDataTypePrioritySystem)
       
  1338             {
       
  1339                 // Check that the app has capability WriteDeviceData
       
  1340                 if (!iHasWriteDeviceDataCap)
       
  1341                     priority = KDataTypePriorityNormal;
       
  1342             }
       
  1343             else
       
  1344             {
       
  1345                 //data priority for UnTrusted apps would be capped if it is greater than the threshold priority i.e, KMaxTInt16.
       
  1346                 TInt match=iRegistrationFileName.find(KLitPathForUntrustedRegistrationResourceFiles);
       
  1347                 if (match != KErrNotFound && !iIsSidTrusted) 
       
  1348                 {
       
  1349                     //if registration file is in import directory and 
       
  1350                     //its sid is in unprotected range - downgrade the priority
       
  1351                     priority = KDataTypeUnTrustedPriorityThreshold;	
       
  1352                 }
       
  1353              }
       
  1354 	    }
       
  1355 
       
  1356 		PtrC8* dataTypePtr  = aResourceReader.ReadTPtrC8L();
       
  1357 
       
  1358 		if(NULL != dataTypePtr)
       
  1359 		{
       
  1360 			TDataType* dataType = new TDataType(dataTypePtr);
       
  1361 			if(NULL==dataType)
       
  1362 			{
       
  1363 				std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
  1364 				throw CResourceFileException(errMsg);
       
  1365 			}
       
  1366 			TDataTypeWithPriority* dataTypeWithPriority = new TDataTypeWithPriority(*dataType, priority);
       
  1367 			if(NULL==dataTypeWithPriority)
       
  1368 			{	
       
  1369 				delete dataType;
       
  1370 				std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
  1371 				throw CResourceFileException(errMsg);
       
  1372 			}
       
  1373 			aMimeTypesSupported.push_back(dataTypeWithPriority);
       
  1374 		}
       
  1375 		else
       
  1376 		{
       
  1377 			TDataTypeWithPriority* dataTypeWithPriority = NULL;
       
  1378 			aMimeTypesSupported.push_back(dataTypeWithPriority);
       
  1379 		}
       
  1380 	}
       
  1381 }
       
  1382 
       
  1383