Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

356 lines
7.0 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // File:
  6. //
  7. // Contents:
  8. //
  9. // History:
  10. //
  11. //---------------------------------------------------------------------------
  12. #ifndef __JBDEF_H__
  13. #define __JBDEF_H__
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #include <ntddkbd.h>
  18. #include <ntddmou.h>
  19. #include <windows.h>
  20. #include <winbase.h>
  21. #include <winerror.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <tchar.h>
  25. #include <esent.h>
  26. #include "tlsdef.h"
  27. #include "tlsassrt.h"
  28. #ifdef JB_ASSERT
  29. #undef JB_ASSERT
  30. #endif
  31. #define JB_ASSERT TLSASSERT
  32. #define MAX_JB_ERRSTRING 512
  33. //
  34. //
  35. //
  36. #define INDEXNAME _TEXT("idx")
  37. #define SEPERATOR _TEXT("_")
  38. #define JBSTRING_NULL _TEXT("")
  39. #define JETBLUE_NULL _TEXT("")
  40. #define INDEX_SORT_ASCENDING _TEXT("+")
  41. #define INDEX_SORT_DESCENDING _TEXT("-")
  42. #define INDEX_END_COLNAME _TEXT("\0")
  43. #define JB_COLTYPE_TEXT JET_coltypLongBinary
  44. //------------------------------------------------------------------
  45. //
  46. // JetBlue does not support UNICODE string
  47. //
  48. //------------------------------------------------------------------
  49. #undef JET_BLUE_SUPPORT_UNICODE
  50. #ifdef JET_BLUE_SUPPORT_UNICODE
  51. typedef LPTSTR JB_STRING;
  52. #else
  53. typedef LPSTR JB_STRING;
  54. #endif
  55. //----------------------------------------------------------------
  56. #ifndef AllocateMemory
  57. #define AllocateMemory(size) \
  58. LocalAlloc(LPTR, size)
  59. #endif
  60. #ifndef FreeMemory
  61. #define FreeMemory(ptr) \
  62. if(ptr) \
  63. { \
  64. LocalFree(ptr); \
  65. ptr=NULL; \
  66. }
  67. #endif
  68. #ifndef ReallocateMemory
  69. #define ReallocateMemory(ptr, size) \
  70. LocalReAlloc(ptr, size, LMEM_ZEROINIT)
  71. #endif
  72. //
  73. // Private member function
  74. //
  75. #define CLASS_PRIVATE
  76. //
  77. // No define for NIL instance ID
  78. //
  79. #define JET_NIL_INSTANCE JET_sesidNil
  80. //
  81. // No define for NIL column id
  82. //
  83. #define JET_NIL_COLUMN JET_sesidNil
  84. //
  85. // No define for max table name length,
  86. // user2.doc says 64 ASCII
  87. //
  88. #define MAX_TABLENAME_LENGTH 32
  89. //
  90. // Jet Blue text only 255 BYTES
  91. //
  92. #define MAX_JETBLUE_TEXT_LENGTH LSERVER_MAX_STRING_SIZE
  93. //
  94. // Jet Blue Index, Column, ... name length
  95. //
  96. #define MAX_JETBLUE_NAME_LENGTH 64
  97. //
  98. // Jet Blue column code page must be 1200 or 1250
  99. //
  100. #define TLS_JETBLUE_COLUMN_CODE_PAGE 1252
  101. //
  102. // Jet Blue Text column language ID
  103. //
  104. #define TLS_JETBLUE_COLUMN_LANGID 0x409
  105. //
  106. // Jet Blue Column Country Code
  107. //
  108. #define TLS_JETBLUE_COLUMN_COUNTRY_CODE 1
  109. //
  110. // Max Jet Blue index key length - 127 fix columns
  111. //
  112. #define TLS_JETBLUE_MAX_INDEXKEY_LENGTH \
  113. (127 + 1) * MAX_JETBLUE_NAME_LENGTH
  114. //
  115. // Max. Jet Blue key length documented is 255 in user2.doc
  116. //
  117. //
  118. // Default table density
  119. //
  120. #define TLS_JETBLUE_DEFAULT_TABLE_DENSITY 20
  121. //
  122. // JetBlue max key size - user2.doc
  123. //
  124. #define TLS_JETBLUE_MAX_KEY_LENGTH 255
  125. //
  126. //
  127. #define TLS_TABLE_INDEX_DEFAULT_DENSITY 20
  128. ///////////////////////////////////////////////////////////////
  129. //
  130. // Various structure
  131. //
  132. ///////////////////////////////////////////////////////////////
  133. typedef struct __TLSJBTable {
  134. LPCTSTR pszTemplateTableName;
  135. unsigned long ulPages;
  136. unsigned long ulDensity;
  137. JET_GRBIT jbGrbit;
  138. } TLSJBTable, *PTLSJBTable;
  139. typedef struct __TLSJBColumn {
  140. TCHAR pszColumnName[MAX_JETBLUE_NAME_LENGTH];
  141. JET_COLTYP colType;
  142. unsigned long cbMaxLength; // max length of column
  143. JET_GRBIT jbGrbit;
  144. PVOID pbDefValue; // column default value
  145. int cbDefValue;
  146. unsigned short colCodePage;
  147. unsigned short wCountry;
  148. unsigned short langid;
  149. } TLSJBColumn, *PTLSJBColumn;
  150. typedef struct __TLSJBIndex {
  151. TCHAR pszIndexName[MAX_JETBLUE_NAME_LENGTH];
  152. LPTSTR pszIndexKey;
  153. unsigned long cbKey; // length of key
  154. JET_GRBIT jbGrbit;
  155. unsigned long ulDensity;
  156. } TLSJBIndex, *PTLSJBIndex;
  157. #ifdef __cplusplus
  158. extern "C" {
  159. #endif
  160. BOOL
  161. ConvertJBstrToWstr(
  162. JB_STRING in,
  163. LPTSTR* out
  164. );
  165. BOOL
  166. ConvertWstrToJBstr(
  167. LPCTSTR in,
  168. JB_STRING* out
  169. );
  170. void
  171. FreeJBstr(
  172. JB_STRING pstr
  173. );
  174. BOOL
  175. ConvertMWstrToMJBstr(
  176. LPCTSTR in,
  177. DWORD length,
  178. JB_STRING* out
  179. );
  180. BOOL
  181. ConvertMJBstrToMWstr(
  182. JB_STRING in,
  183. DWORD length,
  184. LPTSTR* out
  185. );
  186. #ifdef __cplusplus
  187. }
  188. #endif
  189. //
  190. /////////////////////////////////////////////////////////////////////
  191. //
  192. class JBError {
  193. public:
  194. JET_ERR m_JetErr;
  195. JBError() : m_JetErr(JET_errSuccess) {}
  196. JBError(const JET_ERR jet_error) : m_JetErr(jet_error) {}
  197. const JET_ERR
  198. GetLastJetError() const {
  199. return m_JetErr;
  200. }
  201. void
  202. SetLastJetError(JET_ERR jetError = JET_errSuccess) {
  203. m_JetErr = jetError;
  204. }
  205. BOOL
  206. IsSuccess() const {
  207. return m_JetErr >= JET_errSuccess;
  208. }
  209. BOOL
  210. GetJBErrString(
  211. const JET_ERR jbErr,
  212. LPTSTR* pszErrString
  213. )
  214. /*++
  215. --*/
  216. {
  217. BOOL bStatus=FALSE;
  218. JET_ERR err;
  219. CHAR szAnsiBuffer[MAX_JB_ERRSTRING+1];
  220. if(pszErrString == NULL)
  221. {
  222. SetLastError(ERROR_INVALID_PARAMETER);
  223. return bStatus;
  224. }
  225. memset(szAnsiBuffer, 0, sizeof(szAnsiBuffer));
  226. err = JetGetSystemParameter(
  227. JET_instanceNil,
  228. JET_sesidNil,
  229. JET_paramErrorToString,
  230. (ULONG_PTR *) &jbErr,
  231. szAnsiBuffer,
  232. MAX_JB_ERRSTRING
  233. );
  234. if(err == JET_errBufferTooSmall || err == JET_errSuccess)
  235. {
  236. // return partial error string.
  237. if(ConvertJBstrToWstr(szAnsiBuffer, pszErrString))
  238. {
  239. bStatus = TRUE;
  240. }
  241. }
  242. return bStatus;
  243. }
  244. void
  245. DebugOutput(
  246. LPTSTR format, ...
  247. ) const
  248. /*++
  249. ++*/
  250. {
  251. va_list marker;
  252. va_start(marker, format);
  253. #ifdef DEBUG_JETBLUE
  254. TCHAR buf[8096];
  255. DWORD dump;
  256. memset(buf, 0, sizeof(buf));
  257. _vsntprintf(
  258. buf,
  259. sizeof(buf)/sizeof(buf[0]),
  260. format,
  261. marker
  262. );
  263. _tprintf(_TEXT("%s"), buf);
  264. #endif
  265. va_end(marker);
  266. }
  267. };
  268. //------------------------------------------------------------
  269. #endif