persistentstorage/sql/SRC/Server/SqlSrvUtil.cpp
branchRCL_3
changeset 24 cc28652e0254
parent 23 26645d81f48d
equal deleted inserted replaced
23:26645d81f48d 24:cc28652e0254
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 //
    14 //
    15 
    15 
    16 #include <stdlib.h>				//wchar_t
    16 #include <stdlib.h>				//wchar_t
    17 #include "SqlAssert.h"
    17 #include "SqlPanic.h"
    18 #include "SqlSrvUtil.h"
    18 #include "SqlSrvUtil.h"
    19 #include "OstTraceDefinitions.h"
    19 
    20 #ifdef OST_TRACE_COMPILER_IN_USE
    20 #ifdef _NOTIFY
    21 #include "SqlSrvUtilTraces.h"
       
    22 #endif
       
    23 #include "SqlTraceDef.h"
       
    24 
       
    25 #ifdef _SQL_AUTHORIZER_TRACE_ENABLED
       
    26 
    21 
    27 //Used in PrintAuthorizerArguments()
    22 //Used in PrintAuthorizerArguments()
    28 _LIT8(KCreateIndex,			"Create index");			//SQLITE_CREATE_INDEX
    23 _LIT8(KCreateIndex,			"Create index");			//SQLITE_CREATE_INDEX
    29 _LIT8(KCreateTable, 		"Create table");			//SQLITE_CREATE_TABLE
    24 _LIT8(KCreateTable, 		"Create table");			//SQLITE_CREATE_TABLE
    30 _LIT8(KCreateTempIndex, 	"Create temp index");		//SQLITE_CREATE_TEMP_INDEX
    25 _LIT8(KCreateTempIndex, 	"Create temp index");		//SQLITE_CREATE_TEMP_INDEX
    69 	KDropTrigger(), KDropView(), KInsert(), KPragma(), KRead(), 
    64 	KDropTrigger(), KDropView(), KInsert(), KPragma(), KRead(), 
    70 	KSelect(), KTransaction(), KUpdate(), KAttach(), KDetach(), KAlterTable(), KReindex(), KAnalyze(),
    65 	KSelect(), KTransaction(), KUpdate(), KAttach(), KDetach(), KAlterTable(), KReindex(), KAnalyze(),
    71 	KCreateVTable(), KDropVTable(), KFunctionCall()
    66 	KCreateVTable(), KDropVTable(), KFunctionCall()
    72 	};
    67 	};
    73 
    68 
    74 #ifdef _DEBUG
       
    75 const TInt KMaxOpCodes = sizeof(KDbOpNames) / sizeof(KDbOpNames[0]);
    69 const TInt KMaxOpCodes = sizeof(KDbOpNames) / sizeof(KDbOpNames[0]);
    76 #endif
    70 
       
    71 _LIT(KFormatStr, "!!Authorize: %20.20S, %40.40S, %10.10S, %10.10S, %10.10S\r\n"); 
    77 
    72 
    78 /**
    73 /**
    79 This function has a defined implementaion only in _DEBUG mode and is used to print the authorizer arguments.
    74 This function has a defined implementaion only in _DEBUG mode and is used to print the authorizer arguments.
    80 
    75 
    81 @internalComponent
    76 @internalComponent
    82 */
    77 */
    83 void PrintAuthorizerArguments(TInt aDbOpType, const char* aDbObjName1, const char* aDbObjName2, 
    78 void PrintAuthorizerArguments(TInt aDbOpType, const char* aDbObjName1, const char* aDbObjName2, 
    84 							  const char* aDbName, const char* aTrgOrViewName)
    79 							  const char* aDbName, const char* aTrgOrViewName)
    85 	{
    80 	{
    86 	__ASSERT_DEBUG(aDbOpType > 0 && aDbOpType <= KMaxOpCodes, __SQLPANIC2(ESqlPanicInternalError));
    81 	__SQLASSERT(aDbOpType > 0 && aDbOpType <= KMaxOpCodes, ESqlPanicInternalError);
    87 	
    82 	
    88 	//TPtrC8 objects cannot be used for the function arguments, because the arguments may not be 16-bit aligned!!!	
    83 	//TPtrC8 objects cannot be used for the function arguments, because the arguments may not be 16-bit aligned!!!	
    89 
    84 
    90 	TBuf<20> opName;
    85 	TBuf<20> opName;
    91 	opName.Copy(KDbOpNames[aDbOpType - 1]);
    86 	opName.Copy(KDbOpNames[aDbOpType - 1]);
   129 			{
   124 			{
   130 			trgOrViewName.Copy(TPtrC8(reinterpret_cast <const TUint8*> (aTrgOrViewName)));
   125 			trgOrViewName.Copy(TPtrC8(reinterpret_cast <const TUint8*> (aTrgOrViewName)));
   131 			}
   126 			}
   132 		}
   127 		}
   133 		
   128 		
   134 	SQL_TRACE_AUTHORIZER(OstTraceExt5(TRACE_INTERNALS, SQLAUTHORIZER, "0;PrintAuthorizerArguments;%20.20S;%40.40S;%10.10S;%10.10S;%10.10S", __SQLPRNSTR(opName), __SQLPRNSTR(dbObjName1), __SQLPRNSTR(dbObjName2), __SQLPRNSTR(dbName), __SQLPRNSTR(trgOrViewName)));
   129 	RDebug::Print(KFormatStr, &opName, &dbObjName1, &dbObjName2, &dbName, &trgOrViewName);
   135 	}
   130 	}
   136 #endif//_SQL_AUTHORIZER_TRACE_ENABLED
   131 #endif//_NOTIFY
   137 
   132 
   138 /**
   133 /**
   139 Converts a UTF16 encoded descriptor to a UTF8 encoded descriptor.
   134 Converts a UTF16 encoded descriptor to a UTF8 encoded descriptor.
   140 Note: the function works only for input descriptors with length less or equal than KMaxFileName.
   135 Note: the function works only for input descriptors with length less or equal than KMaxFileName.
   141 
   136 
   148 
   143 
   149 @internalComponent
   144 @internalComponent
   150 */
   145 */
   151 TBool UTF16ToUTF8(const TDesC& aIn, TDes8& aOut)
   146 TBool UTF16ToUTF8(const TDesC& aIn, TDes8& aOut)
   152 	{
   147 	{
   153     __ASSERT_DEBUG(aIn.Length() <= KMaxFileName, __SQLPANIC2(ESqlPanicBadArgument));
   148 	__SQLASSERT(aIn.Length() <= KMaxFileName, ESqlPanicBadArgument);
   154     __ASSERT_DEBUG(aOut.MaxLength() >= KMaxFileName, __SQLPANIC2(ESqlPanicBadArgument));
   149 	__SQLASSERT(aOut.MaxLength() >= KMaxFileName, ESqlPanicBadArgument);
   155 	TBuf16<KMaxFileName + 1> des;
   150 	TBuf16<KMaxFileName + 1> des;
   156 	des.Copy(aIn);
   151 	des.Copy(aIn);
   157 	des.Append(TChar(0));
   152 	des.Append(TChar(0));
   158 	TInt len = wcstombs((char*)aOut.Ptr(), (const wchar_t*)des.Ptr(), KMaxFileName);
   153 	TInt len = wcstombs((char*)aOut.Ptr(), (const wchar_t*)des.Ptr(), KMaxFileName);
   159 	//Check the file name length. If it is longer than KMaxFileName characters, then the file name is not valid.
   154 	//Check the file name length. If it is longer than KMaxFileName characters, then the file name is not valid.
   178 
   173 
   179 @internalComponent
   174 @internalComponent
   180 */
   175 */
   181 TBool UTF16ZToUTF8Z(const TDesC& aFileName, TDes8& aFileNameDestBuf)
   176 TBool UTF16ZToUTF8Z(const TDesC& aFileName, TDes8& aFileNameDestBuf)
   182 	{
   177 	{
   183 	__ASSERT_DEBUG(aFileName.Length() <= (KMaxFileName + 1), __SQLPANIC2(ESqlPanicBadArgument));
   178 	__SQLASSERT(aFileName.Length() <= (KMaxFileName + 1), ESqlPanicBadArgument);
   184 	__ASSERT_DEBUG(aFileName[aFileName.Length() - 1] == 0, __SQLPANIC2(ESqlPanicBadArgument));
   179 	__SQLASSERT(aFileName[aFileName.Length() - 1] == 0, ESqlPanicBadArgument);
   185 	__ASSERT_DEBUG(aFileNameDestBuf.MaxLength() >= (KMaxFileName + 1), __SQLPANIC2(ESqlPanicBadArgument));
   180 	__SQLASSERT(aFileNameDestBuf.MaxLength() >= (KMaxFileName + 1), ESqlPanicBadArgument);
   186 	const wchar_t* src = reinterpret_cast <const wchar_t*> (aFileName.Ptr());
   181 	const wchar_t* src = reinterpret_cast <const wchar_t*> (aFileName.Ptr());
   187 	TInt len = wcstombs((char*)aFileNameDestBuf.Ptr(), src, KMaxFileName);
   182 	TInt len = wcstombs((char*)aFileNameDestBuf.Ptr(), src, KMaxFileName);
   188 	//Check the file name length. If it is longer than KMaxFileName characters, then the file name is not valid.
   183 	//Check the file name length. If it is longer than KMaxFileName characters, then the file name is not valid.
   189 	if((TUint)len <= KMaxFileName)
   184 	if((TUint)len <= KMaxFileName)
   190 		{
   185 		{
   207 
   202 
   208 @internalComponent
   203 @internalComponent
   209 */
   204 */
   210 TBool UTF16ToUTF8Z(const TDesC& aFileName, TDes8& aFileNameDestBuf)
   205 TBool UTF16ToUTF8Z(const TDesC& aFileName, TDes8& aFileNameDestBuf)
   211 	{
   206 	{
   212 	__ASSERT_DEBUG(aFileName.Length() <= KMaxFileName, __SQLPANIC2(ESqlPanicBadArgument));
   207 	__SQLASSERT(aFileName.Length() <= KMaxFileName, ESqlPanicBadArgument);
   213 	__ASSERT_DEBUG(aFileNameDestBuf.MaxLength() >= (KMaxFileName + 1), __SQLPANIC2(ESqlPanicBadArgument));
   208 	__SQLASSERT(aFileNameDestBuf.MaxLength() >= (KMaxFileName + 1), ESqlPanicBadArgument);
   214 	TBool rc = ::UTF16ToUTF8(aFileName, aFileNameDestBuf);
   209 	TBool rc = ::UTF16ToUTF8(aFileName, aFileNameDestBuf);
   215 	if(rc)
   210 	if(rc)
   216 		{
   211 		{
   217 		aFileNameDestBuf.Append(0);
   212 		aFileNameDestBuf.Append(0);
   218 		}
   213 		}
   226 	TInt err = aFs.Entry(aDbFileName, entry);
   221 	TInt err = aFs.Entry(aDbFileName, entry);
   227 	if(err == KErrNotFound)
   222 	if(err == KErrNotFound)
   228 		{//Non-existing file
   223 		{//Non-existing file
   229 		return EFalse;	
   224 		return EFalse;	
   230 		}
   225 		}
   231 	__SQLLEAVE_IF_ERROR2(err);
   226 	__SQLLEAVE_IF_ERROR(err);
   232 	return entry.IsReadOnly();
   227 	return entry.IsReadOnly();
   233 	}
   228 	}