persistentstorage/sql/SRC/Server/SqlSrvMain.cpp
changeset 51 7d4490026038
parent 31 ba1c4f4a893f
child 55 44f437012c90
equal deleted inserted replaced
40:b8bdbc8f59c7 51:7d4490026038
    37 #ifndef SQLSRV_STARTUP_TEST
    37 #ifndef SQLSRV_STARTUP_TEST
    38 static  
    38 static  
    39 #endif
    39 #endif
    40 CSqlServer* TheServer = NULL;//The single CSqlServer instance
    40 CSqlServer* TheServer = NULL;//The single CSqlServer instance
    41 
    41 
       
    42 #ifdef _DEBUG
       
    43 #define __SQLDEBUG_EXPR(expr) expr
       
    44 #else
       
    45 #define __SQLDEBUG_EXPR(expr)
       
    46 #endif
       
    47 
    42 _LIT(KMatchAllDbFiles, "*");
    48 _LIT(KMatchAllDbFiles, "*");
    43 _LIT(KDefaultICollationDllName, "");
    49 _LIT(KDefaultICollationDllName, "");
    44 
    50 
    45 //Constants for enabling/disabling the shared cache
    51 //Constants for enabling/disabling the shared cache
    46 enum TSharedCacheState 
    52 enum TSharedCacheState 
   112 */
   118 */
   113 CSqlServer::~CSqlServer()
   119 CSqlServer::~CSqlServer()
   114 	{
   120 	{
   115 	SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, CSQLSERVER_CSQLSERVER2_ENTRY, "Entry;0x%x;CSqlServer::~CSqlServer", (TUint)this));
   121 	SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, CSQLSERVER_CSQLSERVER2_ENTRY, "Entry;0x%x;CSqlServer::~CSqlServer", (TUint)this));
   116 	delete iCompactor;
   122 	delete iCompactor;
   117 	delete iBackupClient;
   123 	delete iBurEventMonitor;
   118 	iDriveSpaceCol.ResetAndDestroy();
   124 	iDriveSpaceCol.ResetAndDestroy();
   119 	sqlite3_soft_heap_limit(0);//Set to 0 the soft heap limit
   125 	sqlite3_soft_heap_limit(0);//Set to 0 the soft heap limit
   120 	iSecurityMap.Close();
   126 	iSecurityMap.Close();
   121 	(void)sqlite3_enable_shared_cache(static_cast <TInt> (EDisableSharedCache));
   127 	(void)sqlite3_enable_shared_cache(static_cast <TInt> (EDisableSharedCache));
   122 	iFlatBuf.Close();
   128 	iFlatBuf.Close();
   343 	TInt err = sqlite3_enable_shared_cache(static_cast <TInt> (EEnableSharedCache));
   349 	TInt err = sqlite3_enable_shared_cache(static_cast <TInt> (EEnableSharedCache));
   344 	__SQLLEAVE_IF_ERROR(::Sql2OsErrCode(err, sqlite3SymbianLastOsError()));
   350 	__SQLLEAVE_IF_ERROR(::Sql2OsErrCode(err, sqlite3SymbianLastOsError()));
   345 	//Create an empty "drive space" collection
   351 	//Create an empty "drive space" collection
   346 	iDriveSpaceCol.Create(fs);
   352 	iDriveSpaceCol.Create(fs);
   347 	// Create the BUR instance
   353 	// Create the BUR instance
   348 	iBackupClient=CSqlBackupClient::NewL(this);
   354 	iBurEventMonitor = CSqlBurEventMonitor::NewL(*this);
   349 	//Compactor
   355 	//Compactor
   350 	iCompactor = CSqlCompactor::NewL(&SqlCreateCompactConnL, KSqlCompactStepIntervalMs);
   356 	iCompactor = CSqlCompactor::NewL(&SqlCreateCompactConnL, KSqlCompactStepIntervalMs);
   351 #ifdef _DEBUG
   357 #ifdef _DEBUG
   352     //The following statements exist to prevent the failure of the OOM testing in debug mode.
   358     //The following statements exist to prevent the failure of the OOM testing in debug mode.
   353 	//The standard C library allocates some memory at the startup and stores a pointer to the allocated memory
   359 	//The standard C library allocates some memory at the startup and stores a pointer to the allocated memory
   412 	extdlocale.LoadSystemSettings();
   418 	extdlocale.LoadSystemSettings();
   413 	TFileName fname;
   419 	TFileName fname;
   414 	TParse fileName;
   420 	TParse fileName;
   415 	TInt err = extdlocale.GetLocaleDllName(ELocaleCollateSetting, fname);
   421 	TInt err = extdlocale.GetLocaleDllName(ELocaleCollateSetting, fname);
   416 	if(err!= KErrNone)
   422 	if(err!= KErrNone)
   417 		iCollationDllName = KDefaultICollationDllName;	
   423 		{
       
   424 		iCollationDllName = KDefaultICollationDllName;
       
   425 		}
   418 	else
   426 	else
   419 		{
   427 		{
   420 		//only get the file name + extension 
   428 		//only get the file name + extension 
   421 		fileName.Set(fname, NULL, NULL);
   429 		fileName.Set(fname, NULL, NULL);
   422 		iCollationDllName = fileName.NameAndExt();
   430 		iCollationDllName = fileName.NameAndExt();
   433 	TParse parseDbConfig;	
   441 	TParse parseDbConfig;	
   434 	__SQLLEAVE_IF_ERROR(parseDbConfig.Set(KSqlSrvDbConfigFileFormat, &aServerPrivatePath, NULL));
   442 	__SQLLEAVE_IF_ERROR(parseDbConfig.Set(KSqlSrvDbConfigFileFormat, &aServerPrivatePath, NULL));
   435 	TFileName configFilePath(parseDbConfig.FullName());	// get 'drive:\private path\cfg*' search string
   443 	TFileName configFilePath(parseDbConfig.FullName());	// get 'drive:\private path\cfg*' search string
   436 	CDir* entryList = 0; // memory will be allocated for this in GetDir()
   444 	CDir* entryList = 0; // memory will be allocated for this in GetDir()
   437 	TInt err = aFs.GetDir(configFilePath, KEntryAttNormal, ESortByName, entryList);
   445 	TInt err = aFs.GetDir(configFilePath, KEntryAttNormal, ESortByName, entryList);
   438 	CleanupStack::PushL(entryList);
   446 	if(err == KErrNone)
   439 	if(!err)
   447 		{
   440 		{
   448 		__ASSERT_DEBUG(entryList != NULL, __SQLPANIC(ESqlPanicInternalError));
   441 		if(entryList && (entryList->Count() > 0))
   449 		CleanupStack::PushL(entryList);
       
   450 		if(entryList->Count() > 0)
   442 			{	
   451 			{	
   443 			iDbConfigFiles = CDbConfigFiles::NewL(*entryList);
   452 			iDbConfigFiles = CDbConfigFiles::NewL(*entryList);
   444 			}
   453 			}
       
   454 		CleanupStack::PopAndDestroy(entryList);	
   445 		}
   455 		}
   446 	else
   456 	else
   447 		{
   457 		{
   448 		SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSERVER_CACHEDDBCONFIGFILENAMESL, "0x%X;CSqlServer::CacheDbConfigFileNamesL;GetDir() failed with error code %d", (TUint)this, err));	
   458 		SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSERVER_CACHEDDBCONFIGFILENAMESL, "0x%X;CSqlServer::CacheDbConfigFileNamesL;GetDir() failed with error code %d", (TUint)this, err));	
   449 		}
   459 		__ASSERT_DEBUG(!entryList, __SQLPANIC(ESqlPanicInternalError));
   450 	CleanupStack::PopAndDestroy(); // entryList	
   460 		}
   451 	}
   461 	}
   452 
   462 
   453 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
   463 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
   454 ////////////////////////////////////////   MSqlPolicyInspector implementation  ///////////////////////////////
   464 ////////////////////////////////////////   MSqlPolicyInspector implementation  ///////////////////////////////
   455 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
   465 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
   484 	return iFileData.Fs();		
   494 	return iFileData.Fs();		
   485 	}
   495 	}
   486 	
   496 	
   487 /**
   497 /**
   488 Implements MSqlSrvBurInterface::GetBackupListL().
   498 Implements MSqlSrvBurInterface::GetBackupListL().
   489 Retrieves in aFileList parameter a list of secure database names (full database paths actually) 
   499 Retrieves in aFileNameList parameter a list of secure database names (full database names, including path) 
   490 which security UID matches aUid parameter.
   500 which security UID matches aUid parameter.
   491 Database files on ROM drive(s) won't be put in aFileList.
   501 No databases will be included into the list, if the drive is read-only.
   492 
   502 
   493 @param aUid Database security UID.
   503 @param aUid Database security UID.
   494 @param aFileList An output parameter. If the function completes successfully, then aFileList will be filled
   504 @param aDrive The drive where the database search will be performed, in the SQL server private data cage.
   495 				 with all secure database file names which security UID matches aUid parameter.
   505 @param aFileNameList An output parameter.
   496 				 Database files on ROM drive(s) won't be put in aFileList.
   506 				 Each array entry represents the full name of a database in SQL server private data cage
       
   507 				 on the specified drive (aDrive), which uid matches the aUid parameter.
   497 				 
   508 				 
   498 @leave KErrNoMemory, an out of memory condition has occured;
   509 @leave KErrNoMemory, an out of memory condition has occured;
   499 					 Note that the function may leave also with some other database specific or OS specific
   510 					 Note that the function may leave also with some other database specific or OS specific
   500 					 error codes.
   511 					 error codes.
   501 */
   512 */
   502 void CSqlServer::GetBackUpListL(TSecureId aUid, RArray<TParse>& aFileList)
   513 void CSqlServer::GetBackUpListL(TSecureId aUid, TDriveNumber aDrive, RArray<HBufC*>& aFileNameList)
   503 	{
   514 	{
   504 	SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSERVER_GETBACKUPLISTL_ENTRY, "Entry;0x%x;CSqlServer::GetBackUpListL;aUid=0x%X", (TUint)this, (TUint)aUid.iId));
   515 	SQL_TRACE_INTERNALS(OstTraceExt3(TRACE_INTERNALS, CSQLSERVER_GETBACKUPLISTL_ENTRY, "Entry;0x%x;CSqlServer::GetBackUpListL;aDrive=%d;aUid=0x%X", (TUint)this, (TInt)aDrive, (TUint)aUid.iId));
   505 	aFileList.Reset();
   516 	__ASSERT_DEBUG(aFileNameList.Count() == 0, __SQLPANIC(ESqlPanicBadArgument));
   506 	TFindFile findFile(iFileData.Fs());
   517 	RFs& fs = iFileData.Fs();
   507 	CDir* fileNameCol = NULL;
   518 	//No files in the list if aDrive is a read-only drive
       
   519 	TDriveInfo driveInfo;
       
   520 	__SQLLEAVE_IF_ERROR(fs.Drive(driveInfo, aDrive));
       
   521 	if(driveInfo.iDriveAtt & KDriveAttRom)
       
   522 		{
       
   523 		return;
       
   524 		}
       
   525 	//Compose the search path
       
   526 	TDriveUnit driveUnit(aDrive);
       
   527 	TDriveName driveName = driveUnit.Name();
       
   528 	TFileName path;
       
   529 	path.Copy(driveName);
       
   530 	path.Append(iFileData.PrivatePath());
       
   531 	//Include the aUid and the "*" mask
   508 	TUidName uidName = (static_cast <TUid> (aUid)).Name();
   532 	TUidName uidName = (static_cast <TUid> (aUid)).Name();
   509 	TBuf<KMaxUidName + sizeof(KMatchAllDbFiles)> fileNameMask(uidName);
   533 	TBuf<KMaxUidName + sizeof(KMatchAllDbFiles)> fileNameMask(uidName);
   510 	fileNameMask.Append(KMatchAllDbFiles);
   534 	fileNameMask.Append(KMatchAllDbFiles);
   511 	//Find all files which name is matching "[aUid]*" pattern.
   535 	TParse parse;
   512 	TInt err = findFile.FindWildByDir(fileNameMask, iFileData.PrivatePath(), fileNameCol);
   536 	__SQLLEAVE_IF_ERROR(parse.Set(path, &fileNameMask, NULL)); 
   513 	if(err == KErrNone)
   537 	//Do the search
   514 		{
   538 	TPtrC fullPath(parse.FullName());
   515 		//The first set of files, which name is matching "[aUid]*" pattern, is ready.
   539 	SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSERVER_GETBACKUPLISTL_FULLPATH, "Exit;0x%x;CSqlServer::GetBackUpListL;fullPath=%S", (TUint)this, __SQLPRNSTR(fullPath)));
   516 		do
   540 	CDir* fileNameCol = NULL;
   517 			{
   541 	TInt err = fs.GetDir(fullPath, KEntryAttNormal, ESortNone, fileNameCol);
   518 			__ASSERT_DEBUG(fileNameCol != NULL, __SQLPANIC(ESqlPanicInternalError));
   542 	if(err == KErrNotFound)
   519 			CleanupStack::PushL(fileNameCol);
   543 		{
   520 			const TDesC& file = findFile.File();//"file" variable contains the drive and the path. the file name in "file" is invalid in this case.
   544 		__ASSERT_DEBUG(!fileNameCol, __SQLPANIC(ESqlPanicInternalError));
   521 			//Check that the drive, where the database files are, is not ROM drive
   545 		SQL_TRACE_INTERNALS(OstTrace1(TRACE_INTERNALS, CSQLSERVER_GETBACKUPLISTL_EXIT1, "Exit;0x%x;CSqlServer::GetBackUpListL;no files found", (TUint)this));
   522 			TParse parse;
   546 		return;
   523 			(void)parse.Set(file, NULL, NULL);//this call can't file, the file name comes from findFile call.
   547 		}
   524 			TPtrC driveName = parse.Drive();
   548 	__SQLLEAVE_IF_ERROR(err);
   525 			__ASSERT_DEBUG(driveName.Length() > 0, __SQLPANIC(ESqlPanicInternalError));
   549 	__ASSERT_DEBUG(fileNameCol != NULL, __SQLPANIC(ESqlPanicInternalError));
   526 			TInt driveNumber = -1;
   550 	CleanupStack::PushL(fileNameCol);
   527 			__SQLLEAVE_IF_ERROR(RFs::CharToDrive(driveName[0], driveNumber));
   551 	TInt fileCount = fileNameCol->Count();
   528 			TDriveInfo driveInfo;
   552 	__SQLLEAVE_IF_ERROR(aFileNameList.Reserve(fileCount));
   529 			__SQLLEAVE_IF_ERROR(iFileData.Fs().Drive(driveInfo, static_cast <TDriveNumber> (driveNumber)));
   553 	//Append the full database file paths to the file names list.
   530 			//If current drive is not ROM drive then process the files
   554 	for(TInt i=0;i<fileCount;++i)
   531 			if(!(driveInfo.iDriveAtt & KDriveAttRom))
   555 		{
   532 				{
   556 		const ::TEntry& entry = (*fileNameCol)[i];
   533 				TInt cnt = fileNameCol->Count();
   557 		__ASSERT_DEBUG(!entry.IsDir(), __SQLPANIC(ESqlPanicInternalError));//RFs::GetDir() search attributes exclude directories (see the GetDir() call above).
   534 				//For each found database file, which name is matching "[aUid]*" pattern, do:
   558 		__SQLLEAVE_IF_ERROR(parse.Set(path, &entry.iName, NULL));
   535 				for(TInt i=0;i<cnt;++i)
   559 		TPtrC fname(parse.FullName());
   536 					{
   560 		SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSERVER_GETBACKUPLISTL, "0x%x;CSqlServer::GetBackUpListL;fname=%S", (TUint)this, __SQLPRNSTR(fname)));
   537 					const ::TEntry& entry = (*fileNameCol)[i];
   561 		HBufC* fnameBuf = fname.AllocL();
   538 					if(!entry.IsDir())
   562 		__SQLDEBUG_EXPR(err = )aFileNameList.Append(fnameBuf);
   539 						{
   563 		__ASSERT_DEBUG(err == KErrNone, __SQLPANIC(ESqlPanicInternalError));
   540 						(void)parse.Set(entry.iName, &file, NULL);//"parse" variable now contains the full file path
   564 		}
   541 						__SQLTRACE_INTERNALSVAR(TPtrC fname = parse.FullName());
   565 	CleanupStack::PopAndDestroy(fileNameCol);
   542 						SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSERVER_GETBACKUPLISTL, "0x%x;CSqlServer::GetBackUpListL;fname=%S", (TUint)this, __SQLPRNSTR(fname)));
   566 	SQL_TRACE_INTERNALS(OstTraceExt2(TRACE_INTERNALS, CSQLSERVER_GETBACKUPLISTL_EXIT2, "Exit;0x%x;CSqlServer::GetBackUpListL;file count=%d", (TUint)this, fileCount));
   543 						__SQLLEAVE_IF_ERROR(aFileList.Append(parse));
       
   544 						}
       
   545 					}
       
   546 				}
       
   547 			CleanupStack::PopAndDestroy(fileNameCol);
       
   548 			fileNameCol = NULL;
       
   549 			} while((err = findFile.FindWild(fileNameCol)) == KErrNone);//Get the next set of files
       
   550 		}//end of "if(err == KErrNone)"
       
   551 	__ASSERT_DEBUG(!fileNameCol, __SQLPANIC(ESqlPanicInternalError));
       
   552 	if(err != KErrNotFound && err != KErrNone)
       
   553 		{
       
   554 		__SQLLEAVE(err);
       
   555 		}
       
   556 	SQL_TRACE_INTERNALS(OstTraceExt3(TRACE_INTERNALS, CSQLSERVER_GETBACKUPLISTL_EXIT, "Exit;0x%x;CSqlServer::GetBackUpListL;file count=%d;err=%d", (TUint)this, aFileList.Count(), err));
       
   557 	}
   567 	}
   558 
   568 
   559 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
   569 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
   560 ////////////////////////////////////////   SQL server startup   //////////////////////////////////////////////
   570 ////////////////////////////////////////   SQL server startup   //////////////////////////////////////////////
   561 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
   571 //////////////////////////////////////////////////////////////////////////////////////////////////////////////