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