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.

397 lines
13 KiB

  1. //+-------------------------------------------------------------------------
  2. // Microsoft OLE
  3. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  4. // All rights reserved.
  5. //
  6. // File: util.hxx
  7. //
  8. // Contents: test utility functions
  9. //
  10. // Functions: - AddStorage
  11. // - AddStream
  12. // - CalculateCRCForName
  13. // - CalculateCRCForDataBuffer
  14. // - CalculateInMemoryCRCForStg
  15. // - CalculateInMemoryCRCForStm
  16. // - CalculateDiskCRCForStg
  17. // - CalculateCRCForDocFile
  18. // - CalculateCRCForDocFileStmData
  19. // - CloseRandomVirtualCtrNodeStg
  20. // - DestroyStorage
  21. // - DestroyStream
  22. // - EnumerateInMemoryDocFile
  23. // - EnumerateDiskDocFile
  24. // - GenerateRandomName
  25. // - GenerateVirtualDFFromDiskDF
  26. // - GetVirtualCtrNodeForTest
  27. // - GetVirtualStmNodeForTest
  28. // - OpenRandomVirtualCtrNodeStg
  29. // - ReadAndCalculateDiskCRCForForStm
  30. // - TStringToOleString
  31. // - PrivAtol
  32. // - GenerateRandomString
  33. // - ParseVirtualDFAndOpenAllSubStgsStms
  34. //
  35. // History: Narindk 21-April-96 Created
  36. // SCousens 2-Feb-97 Added 2 funcs. for Conversion
  37. //--------------------------------------------------------------------------
  38. #ifndef __COMMON_UTIL_HXX__
  39. #define __COMMON_UTIL_HXX__
  40. // 32 bit CRC declarations and macro definitions. The logic was taken
  41. // from the book 'C Programmer's Guide to Netbios'.
  42. extern ULONG aulCrc[256];
  43. #define CRC_PRECONDITION 0xFFFFFFFFL
  44. #define CRC_CALC(X,Y) \
  45. { \
  46. register BYTE ibCrcIndex; \
  47. ibCrcIndex = (BYTE) ((X ^ Y) & 0x000000FFL); \
  48. X = ((X >> 8) & 0x00FFFFFFL) ^ aulCrc[ibCrcIndex]; \
  49. }
  50. // Combine 2 crcs into one. Used when have
  51. // CRC for data and a CRC for name.
  52. #define MUNGECRC(a,b) \
  53. { \
  54. for (int i=0; i < sizeof(b); i++) \
  55. { \
  56. CRC_CALC(a, (BYTE)((b >> (i<<3)) & 0xff)); \
  57. } \
  58. }
  59. #define DEF_FATNAME_MAXLEN 8 // Default max length for FAT file names
  60. #define FILEEXT_MAXLEN 3 // Max length for file name extensions
  61. #define DEF_OFSNAME_MAXLEN 20 // Default max length for non-FAT file names
  62. #define FAT_CHARSET_SIZE 80 // Buffer size for FAT name char set
  63. #define OFS_CHARSET_SIZE 124 // Buffer size for non-FAT name char set
  64. // Definitions
  65. // Review- The docfile/componnet name lengths can be b/w 1-31 char long. So
  66. // define MAXLENGTH to be 27, since "." and extension (max 3 chars long) is
  67. // also used for names.
  68. #define MAXLENGTH 27
  69. #define MINLENGTH 5
  70. #define STM_BUFLEN 4096
  71. // sector size definitions
  72. #define DEFAULT_SECTOR_SIZE 512
  73. #define LARGE_SECTOR_SIZE 4096
  74. // These macros are used in the GenerateRandomStreamData function.
  75. // CHARSET is the size of our 'alphabet'
  76. // DATABUFFER is the size of our buffer that we reuse to fill huge buffers.
  77. // The smaller this number is the larger the probablity of duplication in
  78. // the stream, but the more efficient we are at not generating chars for fill
  79. #define CB_STMDATA_CHARSET 255 //ASCII 0-255 - printable chars
  80. #define CB_STMDATA_DATABUFFER 255 // may want to try 512
  81. // For hack in function GenerateVirtualDFTreeFromDiskDF
  82. #define NRETRIES 20
  83. #define NWAIT_TIME 100
  84. // Enumeration for use by Verify functions like EnumerateDiskDocFile,
  85. // Calulate CRCForDiskDocFile
  86. typedef enum verifyOp
  87. {
  88. VERIFY_EXC_TOPSTG_NAME = 0,
  89. VERIFY_INC_TOPSTG_NAME = 1,
  90. VERIFY_SHORT,
  91. VERIFY_DETAIL
  92. } VERIFY_OP;
  93. // Flags for stuff to include in CRC calculations
  94. const DWORD CRC_INC_TOPSTG_NAME = 1;
  95. const DWORD CRC_INC_STATEBITS = 2;
  96. // Enumeration for use by utility functions like function
  97. // ParseVirtualDFAndCloseOpenStgsStms
  98. typedef enum nodeOp
  99. {
  100. NODE_INC_TOPSTG,
  101. NODE_EXC_TOPSTG
  102. } NODE_OP;
  103. // Function Prototypes
  104. // Function to generate a random string.
  105. HRESULT GenerateRandomName(
  106. DG_STRING *pgds,
  107. ULONG ulMinLen,
  108. ULONG ulMaxLen,
  109. LPTSTR *pptszName);
  110. // Functions to pick up randomly VirtualCTrNode/VirtualStmNode for tests.
  111. HRESULT GetVirtualCtrNodeForTest(
  112. VirtualCtrNode *pVirtualCtrNode,
  113. DG_INTEGER *pdgi,
  114. ULONG cMin,
  115. ULONG cMax,
  116. VirtualCtrNode **ppVirtualCtrNodeForTest);
  117. HRESULT GetVirtualCtrNodeForTest(
  118. VirtualDF *pVirtualDF,
  119. DG_INTEGER *pdgi,
  120. ULONG cMin,
  121. ULONG cMax,
  122. VirtualCtrNode **ppVirtualCtrNodeForTest);
  123. HRESULT GetVirtualStmNodeForTest(
  124. VirtualCtrNode *pVirtualCtrNode,
  125. DG_INTEGER *pdgi,
  126. ULONG cMin,
  127. ULONG cMax,
  128. VirtualCtrNode **ppVirtualCtrNodeParent,
  129. VirtualStmNode **ppVirtualStmNodeForTest);
  130. HRESULT GetVirtualStmNodeForTest(
  131. VirtualDF *pVirtualDF,
  132. DG_INTEGER *pdgi,
  133. ULONG cMin,
  134. ULONG cMax,
  135. VirtualCtrNode **ppVirtualCtrNodeParent,
  136. VirtualStmNode **ppVirtualStmNodeForTest);
  137. // Function to add a VirtualCtrNode and corresponding IStorage to existing
  138. // VirtualDF tree.
  139. HRESULT AddStorage(
  140. VirtualDF *pVirtualDF,
  141. VirtualCtrNode *pVirtualCtrNode,
  142. LPTSTR pName,
  143. DWORD grfMode,
  144. VirtualCtrNode **ppNewVirtualCtrNode);
  145. // Function to delete a VirtualCtrNode and corresponfing IStorage and readjust
  146. // -ing the VirtualDF tree.
  147. HRESULT DestroyStorage(
  148. VirtualDF *pVirtualDF,
  149. VirtualCtrNode *pVirtualCtrNode);
  150. // Function to delete a VirtualStmNode and corresponfing IStream and readjust
  151. // -ing the parent VirtualCtrNode in the VirtualDF tree.
  152. HRESULT DestroyStream(
  153. VirtualDF *pVirtualDF,
  154. VirtualStmNode *pVirtualStmNode);
  155. // Function to add a VirtualStmNode and corresponding IStream to existing
  156. // VirtualCtrNode in VirtualDF tree.
  157. HRESULT AddStream(
  158. VirtualDF *pVirtualDF,
  159. VirtualCtrNode *pVirtualCtrNode,
  160. LPTSTR pName,
  161. ULONG cbSize,
  162. DWORD grfMode,
  163. VirtualStmNode **ppNewVirtualStmNode);
  164. // CRC function to calculate InMemory CRC for a stream both for name and data.
  165. // Function is dependent on VirtualDF tree dependencies.
  166. HRESULT CalculateInMemoryCRCForStm(
  167. VirtualStmNode *pvsn,
  168. const LPTSTR ptszBuffer,
  169. ULONG culBufferSize,
  170. DWCRCSTM *pdwCRC);
  171. // Function to calculate CRC for open IStream
  172. HRESULT CalculateStreamDataCRC(
  173. IStream *pStm,
  174. DWORD dwSize,
  175. DWORD *pdwCRC,
  176. DWORD dwChunkSize=STM_CHUNK_SIZE);
  177. // CRC function to calculate CRC for a disk stream by stat'ng on it, reading
  178. // its contents and thereny calculating CRC on its name and data. Function is
  179. // dependent on VirtualDF tree dependencies.
  180. HRESULT ReadAndCalculateDiskCRCForStm(
  181. VirtualStmNode *pvsn,
  182. DWCRCSTM *pdwCRC,
  183. DWORD dwChunkSize=STM_CHUNK_SIZE);
  184. // CRC function to calculate CRC for IStorage/IStream name. Function used by
  185. // by other CRC functions. Function independent of VirtualDF tree dependencies.
  186. HRESULT CalculateCRCForName(
  187. const LPTSTR ptszName,
  188. DWORD *pdwCRCForName);
  189. // CRC function to calculate CRC for a data buffer. Function used by other CRC
  190. // functions. Function independent of VirtualDF tree dependencies.
  191. HRESULT CalculateCRCForDataBuffer(
  192. const LPTSTR ptszBuffer,
  193. ULONG culBufferSize,
  194. DWORD *pdwCRCForName);
  195. // CRC function to calculate InMemory CRC for a storage for its name.
  196. // Function is dependent on VirtualDF tree dependencies.
  197. HRESULT CalculateInMemoryCRCForStg(
  198. VirtualCtrNode *pvcn,
  199. DWORD *pdwCRC);
  200. // CRC function to calculate CRC for a disk storage by stat'ng on it, thereby
  201. // calculating CRC on its name. Function is dependent on VirtualDF tree
  202. // dependencies.
  203. HRESULT CalculateDiskCRCForStg(
  204. VirtualCtrNode *pvcn,
  205. DWORD *pdwCRC);
  206. // CRC function to calculate CRC for a disk docfile by enumerating and opening
  207. // up all its substorages/streams and thereby calculating CRC on all of its
  208. // storages and streams. Function independent of VirtualDF tree dependencies
  209. HRESULT CalculateCRCForDocFile(
  210. IStorage *pIStorage,
  211. DWORD crcflags,
  212. DWORD *pdwCRC,
  213. DWORD dwChunkSize=STM_CHUNK_SIZE);
  214. // CRC function to calculate CRC for a disk stream by opening and reading its
  215. // contents. Function is independent of VirtualDF tree dependencies.
  216. HRESULT CalculateCRCForDocFileStmData(
  217. LPSTORAGE pIStorage,
  218. LPTSTR ptcsName,
  219. DWORD cbSize,
  220. DWORD *pdwCurrStmDataCRC,
  221. DWORD dwChunkSize=STM_CHUNK_SIZE);
  222. HRESULT CalculateCRCForDocFileStmData(
  223. LPTSTR ptcsName,
  224. LPSTREAM pIChildStream,
  225. DWORD cbSize,
  226. DWORD *pdwCurrStmDataCRC,
  227. DWORD dwChunkSize=STM_CHUNK_SIZE);
  228. // Function to enumerate a in memory VirtualDocFile tree anc count the number
  229. // of storages and streams in it.
  230. HRESULT EnumerateInMemoryDocFile(
  231. VirtualCtrNode *pvcn,
  232. ULONG *pNumStg,
  233. ULONG *pNumStm);
  234. // Function to enumerate a disk DocFile tree anc count the number of storages
  235. // and streams in it.
  236. HRESULT EnumerateDiskDocFile(
  237. LPSTORAGE pIStorage,
  238. VERIFY_OP fVerifyOp,
  239. ULONG *pNumStg,
  240. ULONG *pNumStm );
  241. // Function to generate a VirtualDocFile tree from a disk DocFile by
  242. // enumerating it.
  243. HRESULT GenerateVirtualDFFromDiskDF(
  244. VirtualDF *pNewVirtualDF,
  245. LPTSTR ptszRootDFName,
  246. DWORD grfMode,
  247. VirtualCtrNode **ppvcnRoot,
  248. LPSTORAGE pIRootStg = NULL,
  249. BOOL fDFOpened = FALSE,
  250. ULONG ulSeed = UL_INVALIDSEED);
  251. HRESULT GenerateVirtualDFFromDiskDF(
  252. VirtualDF *pNewVirtualDF,
  253. LPTSTR ptszRootDFName,
  254. DWORD grfMode,
  255. VirtualCtrNode **ppvcnRoot,
  256. ULONG ulSeed);
  257. // Function to open the storage for a randomly selected VirtualCtrNode. Opens
  258. // all parent storages above it, except root that is assumed opened before this
  259. // call is made.
  260. HRESULT OpenRandomVirtualCtrNodeStg(
  261. VirtualCtrNode *pvcn,
  262. DWORD grfMode);
  263. // Function to close the storage for a randomly selected VirtualCtrNode opened
  264. // by call to OpenRandomVirtualCtrNodeStg. Closes all parent storages above it
  265. // , except root since that wasn't reopened by open call.
  266. HRESULT CloseRandomVirtualCtrNodeStg(VirtualCtrNode *pvcn);
  267. // Function to close the open IStorage/IStream pointers by parsing the Virtual
  268. // DF tree under the given node
  269. HRESULT ParseVirtualDFAndCloseOpenStgsStms(
  270. VirtualCtrNode *pvcn,
  271. NODE_OP fNodeOp);
  272. // Function to commit all the open IStorages by parsing the Virtual DF tree
  273. // under the given node
  274. HRESULT ParseVirtualDFAndCommitAllOpenStgs(
  275. VirtualCtrNode *pvcn,
  276. DWORD grfCommitMode,
  277. NODE_OP fNodeOp);
  278. HRESULT PrivAtol(char *pszNum, LONG *plResult);
  279. HRESULT GenerateRandomString(
  280. DG_STRING *pgds,
  281. ULONG ulMinLen,
  282. ULONG ulMaxLen,
  283. LPTSTR *pptszName);
  284. HRESULT GenerateRandomStreamData(
  285. DG_STRING *pgds,
  286. LPTSTR *pptszData,
  287. ULONG ulMinLen,
  288. ULONG ulMaxLen=0);
  289. // recursively open everything below given VirtualCtrNode
  290. HRESULT ParseVirtualDFAndOpenAllSubStgsStms (VirtualCtrNode * pvcn,
  291. DWORD dwStgMode, DWORD dwStmMode);
  292. // get the document name, given the seed
  293. HRESULT GetDocFileName (ULONG ulSeed, LPTSTR *pptszDocName);
  294. // commit the changes all way up to the root
  295. HRESULT CommitRandomVirtualCtrNodeStg(VirtualCtrNode *pvcn,
  296. DWORD grfCommitMode);
  297. // functions in createdf.cxx
  298. enum {ALWAYS = -1,
  299. NEVER = -2};
  300. HRESULT CreateTestDocfile (
  301. OUT VirtualDF **ppvdf,
  302. IN CDFD *pcdfd,
  303. IN LPTSTR cmdline=NULL,
  304. IN LPTSTR pFileName=NULL);
  305. HRESULT CreateTestDocfile (
  306. OUT VirtualDF **ppvdf,
  307. IN DWORD type,
  308. IN ULONG ulSeed,
  309. IN LPTSTR cmdline=NULL,
  310. IN LPTSTR pFileName=NULL);
  311. HRESULT CleanupTestDocfile (
  312. IN VirtualDF *pvdf,
  313. IN BOOL fDeleteFile);
  314. #endif // __COMMON_UTIL_HXX__