Beispiel #1
0
/**
 * Identify if input file is a Registration Resource File.
 @ Param : aRegistrationFileName - File name to be scanned.
 */
TInt FindRegistrationResourceFileL(std::string& aRegistrationFileName)
{
	CResourceFile* registrationFile = NULL;
	try {
			registrationFile = new CResourceFile(aRegistrationFileName, 0, 0);
			if(NULL==registrationFile)
			{
				std::cout<<"Failed : Error in Reading File. Memory Allocation Failed"<<std::endl;
				return 1;
			}
			else
			{
				TUid iAppUid = registrationFile->ReadFileUidL();
				if(KUidAppRegistrationResourceFile == iAppUid.GetUid())
				{
					delete registrationFile;
					return 0;
				}
			}
		}
		catch(const CResourceFileException& aObject)
		{
			if(registrationFile)
				delete registrationFile;
			return 1;
		}
	
	delete registrationFile;
	return 1;
}
/**
@SYMTestCaseID SYSLIB-DBMS-CT-0008
@SYMTestCaseDesc Database tests. Some of the calls must fail because the caller has no enough rights
                 for the requested operation.
@SYMTestPriority High
@SYMTestActions  RDbNamedDatabase::Open()/RDbNamedDatabase::DatabaseNamesL()/RDbNamedDatabase::Create().
@SYMTestExpectedResults The test must not fail.
@SYMREQ REQ2429
                 DBMS shall provide an API to apply security policies to database tables.
*/
static void DbTestL()
	{
	TBuf<32> format;

	TDBSCUtils::DeleteDatabase(TheDbs, KSecureDbUid, KDbName);
	TheTest.Printf(_L("Create database\n"));
	//The test must pass, because the test app has "SCHEMA" capability
	format.Copy(KSecure);
	format.Append(KSecureDbUid.Name());
	TInt err = TheDb.Create(TheDbs, KDbName, format);
	TEST2(err, KErrNone);

	//The test must pass, because "DatabaseNamesL" is a DBMS operation available for everyone.
	TheTest.Printf(_L("Database list\n"));
	CDbDatabaseNames* dbNames = TheDbs.DatabaseNamesL(EDriveC, KSecureDbUid);
	TEST(dbNames->Count() > 0);
	TBool casePreserved = EFalse;
	for(TInt i=0;i<dbNames->Count();++i)
		{
		const TDesC& dbName = (*dbNames)[i];
		RDebug::Print(_L("--Database: %S\n"), &dbName);
		TBuf<128> dbName2;
		dbName2.Append(TChar('A' + EDriveC));
		dbName2.Append(TChar(':'));
		dbName2.Append(dbName);
		if(dbName2 == KDbName())
			{
			casePreserved = ETrue;
			}
		}
	//if casePreserved is non-zero that means the DBMS server does not change the database names to
	//upper or lower case - that's what we want to check
	TEST(casePreserved);
	delete dbNames;

	TheDb.Close();

	TheTest.Printf(_L("An attempt to create database - existing, but protected UID\n"));
	//The test must fail, because the test app does not have capabilities to satisfy
	//KProtSecureDbUid "SCHEMA" policy.
	format.Copy(KSecure);
	format.Append(KProtSecureDbUid.Name());
	err = TheDb.Create(TheDbs, KDbName, format);
	TEST2(err, KErrPermissionDenied);

	//The test must pass, because the test app has "SCHEMA" capability (it must have capabilities,
	//satisfying at least one of the UID's R/W/S policies)
	TheTest.Printf(_L("Open database\n"));
	format.Copy(KSecure);
	format.Append(KSecureDbUid.Name());
	err = TheDb.Open(TheDbs, KDbName, format);
	TEST2(err, KErrNone);
	}
Beispiel #3
0
/**
 * Generate XML for Class AppInfoReader and call the function to Update Installation Information in Database using SRCTOOL
 */
void ReadApplicationInformationFromResourceFilesL(XmlDetails::TScrPreProvisionDetail& aScrPreProvisionDetail, 
															const std::string& aFileName,const CParameterList* aParamList, 
															const CInterpretSIS& aInterpretSis, int& aNewFileFlag)
{

	std::string LocalizePath = GetLocalizeFilePath(aFileName, aParamList);
	
	CAppInfoReader* appInfoReader = NULL;
	appInfoReader = CAppInfoReader::NewL(aFileName, NullUid, LocalizePath);	
	if (!appInfoReader)
	{
		std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
		throw CResourceFileException(errMsg);
	}
	else
	{
		TBool readSuccessful=EFalse;

		readSuccessful= appInfoReader->ReadL();

		if (readSuccessful)
		{
			const SisRegistry* SisReg( aInterpretSis.GetSisRegistry());
			const DbHelper* dbHelper( SisReg->GetDbHelper());
				
			TUid aAppUid = appInfoReader->AppUid();
			int val = dbHelper->IsAppUidInstalled(aAppUid.GetUid());
			if(!val)
			{
				aNewFileFlag = 1;
				// for sis file entries the software type would always be Native.
				aScrPreProvisionDetail.iSoftwareTypeName = L"native";;
						
				XmlDetails::TScrPreProvisionDetail::TComponent component;
				CreateApplicationRegistrationInfoL(component,appInfoReader);
				aScrPreProvisionDetail.iComponents.push_back(component);
			}
			else
			{
				std::cout<<",Ignoring : AppUid "<<hex<<aAppUid.iUid<<" already present in SCR.";
			}
		}
		else
		{
			delete appInfoReader;
			std::string errMsg= "Reading Resource File failed.";
			throw CResourceFileException(errMsg);
		}
		delete appInfoReader;
	}

}
Beispiel #4
0
/**
 * Creates Class TViewData for XML Parsing
 */
void CreateViewDataL(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo& aLocalizableAttribute, 
							const CAppLocalizableInfo* aAppInfoReader)
{
	std::wstring sStr1;
	std::wstring sStr;

	std::vector<CAppViewData*>* viewDataArray = aAppInfoReader->GetViewDataArray();

	if(viewDataArray)
	{
		for(TInt i = 0; i<viewDataArray->size(); i++)
		{

			XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo::TViewData ViewData;
			CAppViewData *temp = viewDataArray->at(i);
	
			sStr = DbConstants::CompUID;
			TUid ID = temp->Uid();
			sStr1 = Utils::IntegerToWideString(ID.GetUid());
			CreateViewDataAttributes(ViewData,sStr,sStr1,true,false);
	
			sStr = DbConstants::CompScreenMode;
			TInt SMode = temp->GetScreenMode();
	
			sStr1 = Utils::IntegerToWideString(SMode);
			CreateViewDataAttributes(ViewData,sStr,sStr1,true,false);
			
			sStr = DbConstants::CompCaption;
			Ptr16* caption = temp->GetCaption();
			if(caption)
				sStr1 = Ptr16ToWstring(caption);
			else
				sStr1=L'\0';		
			CreateViewDataAttributes(ViewData,sStr,sStr1,false,false);
			
			sStr = DbConstants::CompNumberOfIcons;
			TInt IconNum = temp->GetNumOfViewIcons();
			sStr1 = Utils::IntegerToWideString(IconNum);
			CreateViewDataAttributes(ViewData,sStr,sStr1,true,false);
	
			sStr = DbConstants::CompIconFile;
			Ptr16* IconName = temp->GetIconFileName();
			if(IconName)
				sStr1 = Ptr16ToWstring(IconName);
			else
				sStr1=L'\0';
			CreateViewDataAttributes(ViewData,sStr,sStr1,false,false);

			aLocalizableAttribute.iViewData.push_back(ViewData);
		}
	}
}
TInt E32Main()
    {
	__UHEAP_MARK;
	CTrapCleanup* tc = CTrapCleanup::New();
	TEST(tc != NULL);

	TInt err = TheDbs.Connect();
	TEST2(err, KErrNone);

	TBuf<32> format;
	TheTest.Printf(_L("Open database\n"));
	format.Copy(KSecure);
	format.Append(KSecureDbUid.Name());
	err = TheDb.Open(TheDbs, KDbName, format);
	TEST2(err, KErrNone);

	TRAP(err, DoTestL());
	TEST2(err, KErrNone);

	TheView.Close();
	TheTbl.Close();
	TheDb.Close();
	TheDbs.Close();

	TheTest.End();
	TheTest.Close();

	delete tc;

	__UHEAP_MARKEND;
	User::Heap().Check();
	return KErrNone;
    }
// -----------------------------------------------------------------------------
// GetClientIapsL
// -----------------------------------------------------------------------------
//
void CHssIapHandler::GetClientIapsL( const TUid aUId, RArray<TUint>& aIapIdArray )
    {
    DEBUG("CHssIapSettingsHandler::GetClientsIapsL");
    TBuf<32> buffer;                    // Temporary buffer for found UID from destination.
    TUint32 iapId = 0;                  // IAP Identifiier.
    TBuf<KIapNameLength> uidClient;     // UID of the client.
    
    uidClient.Copy( aUId.Name() );
    ModifyClientUid( uidClient );

    RArray<TUint32> destArray = RArray<TUint32>( 10 );  // KCmArrayGranularity instead of 10
    CleanupClosePushL( destArray );

    RCmManager cmManager;
    cmManager.OpenL();
    CleanupClosePushL( cmManager );    

    cmManager.AllDestinationsL( destArray );

    for (TInt i = 0; i < destArray.Count(); i++)
        {
        RCmDestination dest = cmManager.DestinationL( destArray[i] );
        CleanupClosePushL( dest );

        for (TInt j = 0; j < dest.ConnectionMethodCount(); j++)
            {
            TInt bearerType = dest.ConnectionMethodL(j).
                GetIntAttributeL( CMManager::ECmBearerType );

            if (bearerType == KUidWlanBearerType)
                {
                HBufC* uid = dest.ConnectionMethodL(j).
                        GetStringAttributeL( EWlanServiceExtensionTableName );
                CleanupStack::PushL( uid );

                // Copy found uid to temporary buffer
                buffer.Copy( *uid );    

                // If uids match, store corresponding IapId to aIapIdArray.    
                if (buffer.Compare( uidClient ) == 0)
                    {
                    iapId = dest.ConnectionMethodL(j).GetIntAttributeL( ECmIapId );
                    aIapIdArray.AppendL( iapId );
                    DEBUG("CHssIapSettingsHandler::GetClientsIapsL: UIDs matched");
                    DEBUG1("CHssIapSettingsHandler::Found IapId: %d", iapId);
                    }
                else
                    {
                    DEBUG("CHssIapSettingsHandler::GetClientsIapsL: NO match");
                    }
                CleanupStack::PopAndDestroy( uid );
                }
            }
        CleanupStack::PopAndDestroy( &dest );
        }

    CleanupStack::PopAndDestroy( &cmManager );
    CleanupStack::PopAndDestroy( &destArray );
    }
Beispiel #7
0
LOCAL_C void testUid()
//
// Test UIDs
//
{

    test.Start(_L("All functions"));
    test(g1==g11);
    test(g2==g22);
    test(g1!=g2);
    TName a1Name = g1.Name();
    TName a11Name = g11.Name();
    TName a2Name = g2.Name();
    TName a22Name = g22.Name();
    test.Printf(_L("%S %S\n"),&a1Name,&a11Name);
    test.Printf(_L("%S %S\n"),&a2Name,&a22Name);
    test.End();
}
Beispiel #8
0
EXPORT_C void TRequestContext::AddSubjectAttributeL( const TDesC8& aAttributeId, const TUid& aSecureId)
{
	TBuf8<20> secureIdString;
	
	//create UID string
	secureIdString.Append( KSecureIdString);
	secureIdString.Append( aSecureId.Name());
	secureIdString.UpperCase();
	
	//and UID string to request.....
	AddSubjectAttributeL( aAttributeId, secureIdString, PolicyEngineXACML::KStringDataType);
}
// ---------------------------------------------------------
// ProcessRegister
// ---------------------------------------------------------
//
void CHotSpotSession::ProcessRegisterL( const RMessage2& aMessage )
    {
    DEBUG("CHotSpotSession::ProcessRegisterL");
    
    iAllowNotifications = EFalse;
    TBufC< KIapNameLength > iapName;
    TPckgBuf< TIapName > iapPckg;
    TUid clientUid;
    TPckgBuf< TClientUid > uidPckg;
    TPckgBuf<TInt> iapPackage( iIapId );
    
    // Read message
    aMessage.ReadL( 0, uidPckg );
    clientUid = uidPckg().ClientUid();
    aMessage.ReadL( 1, iapPckg );
    iapName = iapPckg().IapName();
    
    TBuf<KIapNameLength> bufUid;
    bufUid.Copy( clientUid.Name() );
    ModifyClientUid( bufUid );
        
    TUint32 iapId( 0 );
    
    TInt ret( KErrNone );
    TRAP( ret, iIapSettingsHandler->CreateClientIapL( iapName, iapId, bufUid ));
    DEBUG1( "CHotSpotSession::EHssRegister iapId: %d", iapId );
    DEBUG1( "CHotSpotSession::EHssRegister ret: %d", ret );
    if ( KErrNone == ret )
        {
        iServer.SetClientIapL( iapId, bufUid );
        aMessage.Complete( iapId );
        }

    else 
        {
        // Error, we are returning 0 to client
        // and no IAP is created
        aMessage.Complete( KErrNone );
        }
    }
Beispiel #10
0
void CreateAppServiceInfo(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo& aAppServiceInfo, 
									const TUid& aUid, const std::vector<TDataTypeWithPriority*>& aDataType) 
{
		XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppServiceInfo componentServiceInfo;

		componentServiceInfo.iUid = aUid.GetUid();
		for(TInt ii = 0; ii<aDataType.size(); ii++)
		{
			TDataTypeWithPriority *temp = aDataType.at(ii);
			CreateAppDataType(componentServiceInfo,temp);
		}
	
		aAppServiceInfo.iApplicationServiceInfo.push_back(componentServiceInfo);
}
// ---------------------------------------------------------------------------
// 2nd phase constructor
// ---------------------------------------------------------------------------
//
void CCenRepDatabaseUtil::ConstructL( TUid aUid )
    {
    if( iColIncrement - 1 + iColMask != KMaxTUint )
        {
        User::Leave( KErrArgument );
        }
        
    iRepository = CRepository::NewL( aUid );

    // Create semaphore name from repository uid
    TUidName uidName = aUid.Name();
    TInt err = iSemaphore.OpenGlobal( uidName );
    if ( err != KErrNone )
        {
        User::LeaveIfError( iSemaphore.CreateGlobal( uidName, 1 ) );
        }
    
    }
// -----------------------------------------------------------------------------
// CSisxUIStartupFile::ConstructL
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CSisxUIStartupFile::ConstructL( const TUid& aUid )
    {
    User::LeaveIfError( iFileSession.Connect() );

    TUidName uidStr = aUid.Name();
    TFileName tmp;
    
    iFileSession.PrivatePath( tmp );    
    tmp.Insert( 0, TParsePtrC( PathInfo::PhoneMemoryRootPath() ).Drive() );
    tmp.Append( KImportDir );      
    tmp.AppendFormat( KNewFileFormat, &uidStr ); 
    iNewFile = tmp.AllocL();
    tmp.Zero();
        
    iFileSession.PrivatePath( tmp );
    tmp.Insert( 0, TParsePtrC( PathInfo::PhoneMemoryRootPath() ).Drive() );
    tmp.Append( KPrivateFileDir );    
    iFileSession.MkDir( tmp );    
    tmp.AppendFormat( KPrivateFileFormat, &uidStr );
    iPrivateFile = tmp.AllocL();
    }
/**
@SYMTestCaseID          PDS-SQL-UT-4224
@SYMTestCaseDesc        CSqlServer::GetBackUpListL() functional test
@SYMTestPriority        High
@SYMTestActions         Calls CSqlServer::GetBackUpListL() and tests the output, when the drive is read-only,
                        when there is a sub-directory which name is matching the search pattern.
@SYMTestExpectedResults Test must not fail
*/  
void GetBackupListFunctionalTest()
	{
    CSqlServer* server = NULL;
    TRAPD(err, server = CreateSqlServerL());
    TEST2(err, KErrNone);
    //Case 1: database with specified uid bellow do exist (on drive C). There will be one subdirectory matching the search pattern. 
    const TDriveNumber KTestDrvNum1 = EDriveC;
    const TUid KDbUid = {0x98765432};
	TDriveUnit testDrive(KTestDrvNum1);
	TDriveName testDriveName = testDrive.Name();
	testDriveName.LowerCase(); 
	//One test directory will be created, which name will be matching the search pattern.
	//The directory name should not be included in the list with the file names.
    TFileName testFileName;
    err = server->Fs().PrivatePath(testFileName);
    TEST2(err, KErrNone);
    testFileName.Append(KDbUid.Name());
    _LIT(KTestPath, "t_startup\\");
    testFileName.Append(KTestPath);
    testFileName.Append(_L("t_startup.db"));
    TParse parse;
    err = parse.Set(testFileName, &testDriveName, 0);
    TEST2(err, KErrNone);
    err = server->Fs().MkDirAll(parse.FullName());
    TEST(err == KErrNone || err == KErrAlreadyExists);
    //
    RArray<HBufC*> files;
    TRAP(err, server->GetBackUpListL(KDbUid, KTestDrvNum1, files));
    TEST2(err, KErrNone);
    TInt fileCnt = files.Count();
    for(TInt i=0;i<fileCnt;++i)
    	{
		TPtrC fname = files[i]->Des();
		TheTest.Printf(_L("Db: %S\r\n"), &fname);
		TEST(fname.FindF(KTestPath) < 0);
		//The name should include the full path + the drive
		err = parse.Set(fname, 0, 0);
		TEST2(err, KErrNone);
		TEST(parse.DrivePresent());
		TEST(parse.PathPresent());
		TDriveName driveName(parse.Drive());
		driveName.LowerCase(); 
		delete files[i];
		TEST(driveName == testDriveName);		
    	}
    files.Close();
    //Case 2: drive Z:. No files should be returned.
    const TDriveNumber KTestDrvNum2 = EDriveZ;
    TRAP(err, server->GetBackUpListL(KDbUid, KTestDrvNum2, files));
    TEST2(err, KErrNone);
    fileCnt = files.Count();
    TEST2(fileCnt, 0);
    //Case 3: drive A:. The drive does not exist. No files should be returned.
    const TDriveNumber KTestDrvNum3 = EDriveA;
    TRAP(err, server->GetBackUpListL(KDbUid, KTestDrvNum3, files));
	TheTest.Printf(_L("Drive %d, err=%d\r\n"), KTestDrvNum3, err);
    fileCnt = files.Count();
    TEST2(fileCnt, 0);
    //
    delete server;
	}
// reads as much info as it can
// at least captions and icons must be setup on return from this method (using defaults if necessary)
TBool CAppInfoReader::ReadL()
{
	TUint fileOffset = 0;
	TInt fileLength = 0;
	TUid firstUid(KExecutableImageUidVal);
	TUid middleUid(KUidApp);
	TInt err;
	TInt LocalizeError = 0;
	TUid reguid;
	
	CResourceFile* registrationFile = new CResourceFile(iRegistrationFileName, fileOffset, fileLength);
	if(NULL==registrationFile)
	{
		std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
		throw CResourceFileException(errMsg);
	}

	if(registrationFile)
	{
		iAppUid = registrationFile->ReadAppUidL();
		if(!iAppUid.GetUid())
		{
			std::string errMsg= "Failed : Invalid Resource File. Null Application UID.";
			throw CResourceFileException(errMsg);
		}

		reguid = registrationFile->ReadFileUidL();
		if(reguid.GetUid()!= KUidAppRegistrationResourceFile)
		{
			std::string errMsg= "Failed : Invalid Resource File. UID2 is not defined.";
			throw CResourceFileException(errMsg);
		}
	}

	// set the TUidType for the app binary
	// cannot read the TEntry info from the app binary because it's in \sys\bin
	iAppBinaryUidType = TUidType(firstUid, middleUid, iAppUid);	
	
	RResourceReader	resourceReader;
	resourceReader.OpenL(registrationFile, KAppRegistrationInfoResourceId);	

	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

	try {
			ReadMandatoryInfoL(resourceReader);
		
			err = ReadNonLocalisableInfoL(resourceReader, localisableResourceId);

			if (!err)
			{	
				err = ReadNonLocalisableOptionalInfoL(resourceReader, registrationFile);
			}
		}
		catch(const CResourceFileException& aObject)
		{
		
			delete registrationFile;
			cout<< aObject.GetMsg()<< endl;
			return EFalse; // might have read something, but failed to setup enough info to make it worthwhile trying to read any more
		}
	
	TBool useDefaultIcons = ETrue;

	if(iLocalisableResourceFileName)
	{
		std::string localizeFileName = Ptr16ToString(iLocalisableResourceFileName);
		std::string folder;
		std::string file;
		size_t found;
		std::string iLocalPath(iDrivePath);

		#ifdef __LINUX__
	  	found=localizeFileName.find_last_of("//");
		#else
		found=localizeFileName.find_last_of("/\\");
		#endif

	  	if(found)
	  		folder = localizeFileName.substr(0,found);
	  	else
		{
			#ifdef __LINUX__
			folder.assign("/");	  		
			#else
			folder.assign("\\");
			#endif
		}
	  	
	  	file = localizeFileName.substr(found+1);
		file.append(".");
		
		iLocalPath.append(folder);
				
		std::wstring iFilePath = string2wstring(iLocalPath);
		std::wstring iFileName = string2wstring(file);

		#ifdef __LINUX__
		iLocalPath.append("/");
		#else
		iLocalPath.append("\\");
		#endif
		
		std::list<std::wstring> locDirs;
		GetDirContents( iFilePath, locDirs );

	 	std::list<std::wstring>::iterator curr = locDirs.begin();
		for( curr = locDirs.begin(); curr != locDirs.end(); ++curr )
		{
			if (curr->find(iFileName,0) != std::wstring::npos)
			{
			    std::string fName;
				std::string sAbsolutePath;
				sAbsolutePath.assign(iLocalPath);
			 	fName = wstring2string( *curr );

			   	sAbsolutePath.append(fName);
				//cout << sAbsolutePath<<endl;
				
				std::string Locale;
				int iLocale = 0;
		
				found=fName.rfind(".r");
				if(found!=string::npos)
					Locale = fName.substr(found+2);
				else
					continue;

				iLocale = atoi(Locale.c_str()); 
			    if(!iLocale)
					iLocale = KNonLocalized;
				   
				CResourceFile* tlocalisableFile = NULL;

				try {
					// open the localisable resource file	
					tlocalisableFile = new CResourceFile(sAbsolutePath, 0, 0);
					if(NULL==tlocalisableFile)
					{
						std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
						throw CResourceFileException(errMsg);
					}

					if (!err)
					{
						if (tlocalisableFile && (localisableResourceId & KResourceOffsetMask))
							tlocalisableFile->ConfirmSignatureL();

						err = ReadLocalisableInfoLoopL(*tlocalisableFile, localisableResourceId, useDefaultIcons, iLocale);
					}
					
					delete tlocalisableFile;
				}
				catch(const CResourceFileException& aObject)
				{
					LocalizeError = 1;
					aObject.Display();
					delete tlocalisableFile;
				}
			}
		}
	}

	// if anything went wrong, we tell the caller that the read was unsuccessful. Some
	// of the members of this class may contain data which is not complete, but this doesn't matter
	// because the caller shouldn't try to access the data if the read was unsuccessful
	TBool readSuccessful = 0;
	if(!LocalizeError)
		readSuccessful = (err == KErrNone);
	delete registrationFile;
	return readSuccessful;
}
TBool CAppInfoReader::ReadL(const std::vector<FileDescription*>& aFileDescription, std::string& aRomPath, int aInRom )
{
		TUint fileOffset = 0;
		TInt fileLength = 0;
		TUid firstUid(KExecutableImageUidVal);
		TUid middleUid(KUidApp);
		TInt err;
		TInt LocalizeError = 0;
		TUid reguid;
		CResourceFile* registrationFile = new CResourceFile(iRegistrationFileName, fileOffset, fileLength);
		if(NULL==registrationFile)
		{
			std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
			throw CResourceFileException(errMsg);
		}
	
		if(registrationFile)
		{
			iAppUid = registrationFile->ReadAppUidL();
			if(!iAppUid.GetUid())
			{
				std::string errMsg= "Failed : Invalid Resource File. Null Application UID.";
				throw CResourceFileException(errMsg);
			}

			reguid = registrationFile->ReadFileUidL();
			if(reguid.GetUid()!= KUidAppRegistrationResourceFile)
			{
				std::string errMsg= "Failed : Invalid Resource File. UID2 is not defined.";
				throw CResourceFileException(errMsg);
			}
		}
	
		// set the TUidType for the app binary
		// cannot read the TEntry info from the app binary because it's in \sys\bin
		iAppBinaryUidType = TUidType(firstUid, middleUid, iAppUid); 
		
		RResourceReader resourceReader;
		resourceReader.OpenL(registrationFile, KAppRegistrationInfoResourceId); 
	
		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
	
		try {
				ReadMandatoryInfoL(resourceReader);
			
				err = ReadNonLocalisableInfoL(resourceReader, localisableResourceId);
	
				if (!err)
				{	
					err = ReadNonLocalisableOptionalInfoL(resourceReader, registrationFile);
				}
			}
			catch(const CResourceFileException& aObject)
			{
			
				delete registrationFile;
				cout<< aObject.GetMsg()<< endl;
				return EFalse; // might have read something, but failed to setup enough info to make it worthwhile trying to read any more
			}
		
		TBool useDefaultIcons = ETrue;
	
		if(iLocalisableResourceFileName)
		{
			std::string localizeFileName = Ptr16ToString(iLocalisableResourceFileName);

			std::vector<FileDescription*>::const_iterator filedesIter;
			//std::wstring iFile;
			std::wstring iLocalizeFile;
			//std::string aFileName;
			std::string iLocalFilePath;

			std::string iLocalFileExt(".r");
			
			for(filedesIter = aFileDescription.begin() ; filedesIter != aFileDescription.end(); ++filedesIter)
			{
				iLocalizeFile = (*filedesIter)->GetLocalFile();
			
				iLocalFilePath = wstring2string(iLocalizeFile);

				if((iLocalFilePath.find(localizeFileName,0) == std::wstring::npos) 
						|| (iLocalFilePath.find(iLocalFileExt,0) == std::wstring::npos))
					continue;

				size_t found;
				std::string Locale;
				int iLocale = 0;
			
				found=iLocalFilePath.find_last_of(".");
				if(found)
					Locale = iLocalFilePath.substr(found+2);

				iLocale = atoi(Locale.c_str()); 
				if(!iLocale)
					iLocale = KNonLocalized;
			
				CResourceFile* tlocalisableFile = NULL;

				if(aInRom)
				{
					std::string LocalFile = FullNameWithoutDrive(iLocalFilePath);
					iLocalFilePath = aRomPath + LocalFile;
				}

				try {
					// open the localisable resource file	
					tlocalisableFile = new CResourceFile(iLocalFilePath, 0, 0);
					if(NULL==tlocalisableFile)
					{
						std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
						throw CResourceFileException(errMsg);
					}
	
					if (!err)
					{
						if (tlocalisableFile && (localisableResourceId & KResourceOffsetMask))
							tlocalisableFile->ConfirmSignatureL();

						err = ReadLocalisableInfoLoopL(*tlocalisableFile, localisableResourceId, useDefaultIcons, iLocale);
					}
						
					delete tlocalisableFile;
				}
				catch(const CResourceFileException& aObject)
				{
					LocalizeError = 1;
					aObject.Display();
					delete tlocalisableFile;
				}
			}
		}
	
	// if anything went wrong, we tell the caller that the read was unsuccessful. Some
	// of the members of this class may contain data which is not complete, but this doesn't matter
	// because the caller shouldn't try to access the data if the read was unsuccessful
	TBool readSuccessful = 0;
	if(!LocalizeError)
		readSuccessful = (err == KErrNone);
	delete registrationFile;
	return readSuccessful;
}
Beispiel #16
0
void CreateApplicationRegistrationInfoL(XmlDetails::TScrPreProvisionDetail::TComponent& aComponent, 
												const CAppInfoReader* aAppInfoReader)
{
	XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo iApplicationRegistrationInfo;

	Ptr16* iAppBinaryFullName = aAppInfoReader->AppBinaryFullName();
	std::wstring sAppAttributeName = DbConstants::CompAppFile;
	std::wstring sAppAttributeValue = Ptr16ToWstring(iAppBinaryFullName);
	CreateAppAttribute(iApplicationRegistrationInfo,sAppAttributeName,sAppAttributeValue,false,false);

	TUidType iAppBinaryUidType = aAppInfoReader->AppBinaryUidType();;
	sAppAttributeName = DbConstants::CompAppUid;
	TUid Uid = iAppBinaryUidType[2];
	sAppAttributeValue = Utils::IntegerToWideString(Uid.GetUid());
	CreateAppAttribute(iApplicationRegistrationInfo,sAppAttributeName,sAppAttributeValue,true,false);

	sAppAttributeName = DbConstants::CompTypeId;
	TInt TypeId = -1367772926;
	sAppAttributeValue = Utils::IntegerToWideString(TypeId);
	CreateAppAttribute(iApplicationRegistrationInfo,sAppAttributeName,sAppAttributeValue,true,false);

	TAppCapability iCapability;
	aAppInfoReader->Capability(iCapability);

 	sAppAttributeName = DbConstants::CompAttributes;
	sAppAttributeValue = Utils::IntegerToWideString(iCapability.iAttributes);
	CreateAppAttribute(iApplicationRegistrationInfo,sAppAttributeName,sAppAttributeValue,true,false);

	sAppAttributeName = DbConstants::CompHidden;
	sAppAttributeValue = Utils::IntegerToWideString(iCapability.iAppIsHidden);
	CreateAppAttribute(iApplicationRegistrationInfo,sAppAttributeName,sAppAttributeValue,true,false);

	sAppAttributeName = DbConstants::CompEmbeddable;
	sAppAttributeValue = Utils::IntegerToWideString(iCapability.iEmbeddability);
	CreateAppAttribute(iApplicationRegistrationInfo,sAppAttributeName,sAppAttributeValue,true,false);

	sAppAttributeName = DbConstants::CompNewfile;
	sAppAttributeValue = Utils::IntegerToWideString(iCapability.iSupportsNewFile);
	CreateAppAttribute(iApplicationRegistrationInfo,sAppAttributeName,sAppAttributeValue,true,false);

	sAppAttributeName = DbConstants::CompLaunch;
	sAppAttributeValue = Utils::IntegerToWideString(iCapability.iLaunchInBackground);
	CreateAppAttribute(iApplicationRegistrationInfo,sAppAttributeName,sAppAttributeValue,true,false);

	sAppAttributeName = DbConstants::CompGroupName;
	if(iCapability.iGroupName)
		sAppAttributeValue = Ptr16ToWstring(iCapability.iGroupName);
	else
		sAppAttributeValue=L'\0';
	CreateAppAttribute(iApplicationRegistrationInfo,sAppAttributeName,sAppAttributeValue,false,false);

	TUint iDefaultScreenNumber = aAppInfoReader->DefaultScreenNumber();
	sAppAttributeName = DbConstants::CompDefaultScreenNumber;
	sAppAttributeValue = Utils::IntegerToWideString(iDefaultScreenNumber);
	CreateAppAttribute(iApplicationRegistrationInfo,sAppAttributeName,sAppAttributeValue,true,false);

	std::vector<Ptr16*>* ownedFileArray = aAppInfoReader->OwnedFiles();
	std::wstring sFileName;
	if(ownedFileArray)
	{
		for(TInt ii = 0; ii<ownedFileArray->size(); ii++)
		{
			Ptr16 *temp = ownedFileArray->at(ii);
			if(temp)
				sFileName = Ptr16ToWstring(temp);
			else
				sFileName = L'\0';
			iApplicationRegistrationInfo.iFileOwnershipInfo.push_back(sFileName);
		}
	}

	std::string sOpaqueData;
	TInt iIndexOfFirstOpenService;
	std::vector<TAppServiceInfo*>* iServiceArray = aAppInfoReader->ServiceArray(iIndexOfFirstOpenService);
	if(iServiceArray)
	{
		for(TInt i = 0; i<iServiceArray->size(); i++)
		{
			TAppServiceInfo* temp = iServiceArray->at(i);
			TUid iUid = temp->GetUid();
			std::vector<TDataTypeWithPriority*> iData = temp->GetDataType();
			CreateAppServiceInfo(iApplicationRegistrationInfo,iUid,iData);

			int servUid = iUid.GetUid();
			std::vector<CAppLocalOpaqueDataInfo*> opaqueDataArray = aAppInfoReader->GetOpaqueDataArray();
			for(TInt i = 0; i<opaqueDataArray.size(); i++)
			{
				CAppLocalOpaqueDataInfo* tp = opaqueDataArray.at(i);
			
				TUint32 serviceUid = tp->GetServiceUid();
				if(servUid == serviceUid)
				{
					Ptr8*	opaqueData = tp->GetOpaqueData();

					if(opaqueData)
						sOpaqueData.assign(opaqueData->GetPtr(), opaqueData->GetPtr()+opaqueData->GetLength());
					else
						sOpaqueData = '\0';
					TInt locale = tp->GetLocale();
					CreateOpaqueDataType(iApplicationRegistrationInfo,sOpaqueData,locale,serviceUid);
				}
			}
		}
	}

	std::vector<CAppLocalizableInfo*> aAppLocalizable = aAppInfoReader->LocalizableInfo();

	for(TInt i = 0; i<aAppLocalizable.size(); i++)
	{
		CAppLocalizableInfo* tp = aAppLocalizable.at(i);
		CreateLocalizableInfoL(iApplicationRegistrationInfo,tp);
	}

	std::vector<CAppLocalOpaqueDataInfo*> opaqueDataArray = aAppInfoReader->GetOpaqueDataArray();
	for(TInt i = 0; i<opaqueDataArray.size(); i++)
	{
		CAppLocalOpaqueDataInfo* tp = opaqueDataArray.at(i);

		TUint32 serviceUid = tp->GetServiceUid();
		if(0 == serviceUid)
		{
			Ptr8* 	opaqueData = tp->GetOpaqueData();

			if(opaqueData)
				sOpaqueData.assign(opaqueData->GetPtr(), opaqueData->GetPtr()+opaqueData->GetLength());
			else
				sOpaqueData='\0';
			
			TInt locale = tp->GetLocale();
			CreateOpaqueDataType(iApplicationRegistrationInfo,sOpaqueData,locale,serviceUid);
		}
	}

	aComponent.iApplicationRegistrationInfo.push_back(iApplicationRegistrationInfo);
}