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.

519 lines
20 KiB

  1. //+-------------------------------------------------------------------------
  2. // Microsoft OLE
  3. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  4. // All rights reserved.
  5. //
  6. // File: virtdf.hxx
  7. //
  8. // Contents: Virtual docfile functions
  9. //
  10. // Classes: VirtualCtrNode
  11. // VirtualStmNode
  12. // VirtualDF
  13. //
  14. // Notes: <describe storage & stream node relationships>
  15. // A VirtualDocFile tree (VIrtualDF) consists of VirtualCtrNodes
  16. // and VirtualStmNodes. In a real docfile, VirtualCtrNodes would
  17. // be equivalent of IStorages and VirtualStmNodes of IStreams.
  18. //
  19. // History: DeanE 21-Mar-96 Created
  20. // SCousens 2-Feb-97 Added for Conversion/NSS testing
  21. //--------------------------------------------------------------------------
  22. #ifndef __VIRTDF_HXX__
  23. #define __VIRTDF_HXX__
  24. // Forward declarations
  25. class VirtualCtrNode;
  26. typedef VirtualCtrNode *PVCTRNODE;
  27. class VirtualStmNode;
  28. typedef VirtualStmNode *PVSTMNODE;
  29. class VirtualDF;
  30. typedef VirtualDF *PVIRTUALDF;
  31. class ChanceDF;
  32. class ChanceNode;
  33. class CDBCSStringGen;
  34. // Enumeration for use by VirtualDF class functions
  35. typedef enum treeOp
  36. {
  37. NEW_STGSTM,
  38. OLD_STGSTM
  39. } TREEOP;
  40. // Enumeration for the type of storage to be used by VirtualDF class
  41. enum STGTYPE
  42. {
  43. STGTYPE_DOCFILE = 0,
  44. STGTYPE_NSSFILE = 1,
  45. };
  46. // Structure to contain CRC for stream name and data
  47. typedef struct dwCRCStm
  48. {
  49. DWORD dwCRCName;
  50. DWORD dwCRCData;
  51. DWORD dwCRCSum;
  52. }DWCRCSTM;
  53. #define UL_INVALIDSEED (ULONG)-1
  54. #define STM_CHUNK_SIZE 1024 // Chunk for large stream operations
  55. //+-------------------------------------------------------------------------
  56. // Class: VirtualDF (vdf)
  57. //
  58. // Synopsis: In-memory docfile object - virtualizes a real docfile to
  59. // allow more efficient and easier verification when the
  60. // real one is being manipulated by tests.
  61. //
  62. // Methods: AppendVirtualStmNodesToVirtualCtrNode
  63. // AppendVirtualCtrNode
  64. // AppendVirtualStmNode
  65. // AdjustTreeOnStgMoveElement
  66. // AdjustTreeOnStmMoveElement
  67. // AdjustTreeOnStgCopyElement
  68. // AdjustTreeOnStmCopyElement
  69. // AdjustTreeOnCopyTo
  70. // CopyVirtualDocFileTree
  71. // CopyVirtualDFRoot
  72. // CopyGrowVirtualDFTree
  73. // CopyAppendVirtualStmNodesToVirtualCtrNode
  74. // CopyAppendVirtualCtrNode
  75. // CopyAppendVirtualStmNode
  76. // DeleteVirtualDocFileTree
  77. // DeleteVirtualDocFileSubTree
  78. // DeleteVirtualCtrNodeStreamTree
  79. // DeleteVirtualCtrNodeStreamNode
  80. // GenerateVirtualDF
  81. // GenerateVirtualDFRoot
  82. // GrowVirtualDFTree
  83. // GetVirtualDFRoot
  84. // GetDocFileName
  85. // GetDataGenInteger
  86. // GetDataGenUnicode
  87. // CommitCloseThenOpenDocfile
  88. // VirtualDF
  89. // ~VirtualDF
  90. //
  91. // Data: [_ptszName] - Name of this storage
  92. // [_pvcnRoot] - Root node
  93. // [_pdgi] - Random integer generator
  94. // [_pgdu] - Random string generator
  95. //
  96. // History: 21-Mar-96 DeanE Created
  97. // 2-Feb-96 SCousens Added funcs for Cnvrs/NSS
  98. //--------------------------------------------------------------------------
  99. class VirtualDF
  100. {
  101. public:
  102. // Constructor/Destructor
  103. VirtualDF(VOID);
  104. VirtualDF(STGTYPE dwStgType);
  105. virtual ~VirtualDF(VOID);
  106. // Functions for Virtual DocFile tree
  107. virtual HRESULT GenerateVirtualDF(
  108. ChanceDF *pChanceDF,
  109. VirtualCtrNode **ppvcnRoot);
  110. HRESULT DeleteVirtualDocFileTree(VirtualCtrNode *pvcn);
  111. HRESULT AdjustTreeOnStgMoveElement(
  112. VirtualCtrNode *pvcnFrom,
  113. VirtualCtrNode *pvcnTo);
  114. HRESULT AdjustTreeOnStmMoveElement(
  115. VirtualStmNode *pvsnFrom,
  116. VirtualCtrNode *pvcnTo);
  117. HRESULT AdjustTreeOnStgCopyElement(
  118. VirtualCtrNode *pvcnFrom,
  119. VirtualCtrNode *pvcnTo);
  120. HRESULT AdjustTreeOnStmCopyElement(
  121. VirtualStmNode *pvsnFrom,
  122. VirtualCtrNode *pvcnTo);
  123. HRESULT AdjustTreeOnCopyTo(
  124. VirtualCtrNode *pvcnFrom,
  125. VirtualCtrNode *pvcnTo);
  126. HRESULT CopyVirtualDocFileTree(
  127. VirtualCtrNode *pvcnRootOld,
  128. TREEOP fNewDiskStgStm,
  129. VirtualCtrNode **ppvcnRootNew);
  130. HRESULT Associate(
  131. VirtualCtrNode *pvcnRoot,
  132. LPSTORAGE pIStorage,
  133. ULONG ulSeed = UL_INVALIDSEED);
  134. HRESULT DeleteVirtualCtrNodeStreamNode(VirtualStmNode *pvsn);
  135. // inline functions
  136. inline VirtualCtrNode *GetVirtualDFRoot(){return _pvcnRoot;}
  137. inline LPTSTR GetDocFileName() {return _ptszName;}
  138. inline DG_INTEGER *GetDataGenInteger(){return _pdgi;}
  139. inline DG_STRING *GetDataGenUnicode(){return _pgdu;}
  140. protected:
  141. virtual HRESULT GenerateVirtualDFRoot (ChanceNode *pcnRoot);
  142. HRESULT GrowVirtualDFTree (ChanceNode *pcnCurrent,
  143. VirtualCtrNode *pvcnCurrent);
  144. HRESULT DeleteVirtualDocFileSubTree (VirtualCtrNode **ppvcn);
  145. HRESULT DeleteVirtualCtrNodeStreamTree (VirtualCtrNode *pvcn);
  146. HRESULT CopyVirtualDFRoot (VirtualCtrNode *pvcnOldRoot,
  147. TREEOP fNewDiskStgStm,
  148. VirtualCtrNode **ppvcnNewRoot);
  149. HRESULT CopyGrowVirtualDFTree (VirtualCtrNode *pvcnFrom,
  150. VirtualCtrNode *pvcnTo,
  151. TREEOP fNewDiskStgStm);
  152. HRESULT AppendVirtualStmNodesToVirtualCtrNode(
  153. ULONG cStreams,
  154. VirtualCtrNode *pvcn,
  155. ULONG cbMinStream,
  156. ULONG cbMaxStream);
  157. HRESULT AppendVirtualCtrNode(
  158. VirtualCtrNode *pvcnParent,
  159. ChanceNode *pcnCurrent,
  160. VirtualCtrNode **ppvcnNew);
  161. HRESULT AppendVirtualStmNode(
  162. VirtualCtrNode *pvcnParent,
  163. ULONG cbMinStream,
  164. ULONG cbMaxStream);
  165. HRESULT CopyAppendVirtualStmNodesToVirtualCtrNode(
  166. ULONG cStreams,
  167. VirtualCtrNode *pvcn,
  168. VirtualCtrNode *pvcnSource,
  169. TREEOP fNewDiskStgStm);
  170. HRESULT CopyAppendVirtualCtrNode(
  171. VirtualCtrNode *pvcnParent,
  172. VirtualCtrNode *pvcnSource,
  173. TREEOP fNewDiskStgStm,
  174. VirtualCtrNode **ppvcnNew);
  175. HRESULT CopyAppendVirtualStmNode(
  176. VirtualCtrNode *pvcnParent,
  177. VirtualStmNode *pvsnSource,
  178. TREEOP fNewDiskStgStm);
  179. // protected class data members
  180. LPTSTR _ptszName;
  181. VirtualCtrNode *_pvcnRoot;
  182. DG_INTEGER *_pdgi;
  183. DG_STRING *_pgdu;
  184. ULONG _ulSeed;
  185. DWORD _dwRootMode;
  186. DWORD _dwStgMode;
  187. DWORD _dwStmMode;
  188. STGTYPE _dwStgType; // create or open nss vs.doc file
  189. CDBCSStringGen *_pDBCSStrGen;
  190. };
  191. //+-------------------------------------------------------------------------
  192. // Class: VirtualCtrNode (vcn)
  193. //
  194. // Synopsis: In-memory storage object - virtualizes a real storage to
  195. // allow more efficient and easier verification when the
  196. // real one is being manipulated by tests.
  197. //
  198. // Methods: AddRefCount
  199. // AppendChildCtr
  200. // AppendSisterCtr
  201. // AppendFirstChildStm
  202. // CreateRoot
  203. // CreateRootEx
  204. // Create
  205. // Close
  206. // Commit
  207. // CopyTo
  208. // DecreaseChildrenStgCount
  209. // DecreaseChildrenStmCount
  210. // Destroy
  211. // EnumElements
  212. // GetFirstChildVirtualStmNode
  213. // GetFirstChildVirtualCtrNode
  214. // GetFirstSisterVirtualCtrNode
  215. // GetParentVirtualCtrNode
  216. // GetVirtualCtrNodeName
  217. // GetVirtualCtrNodeChildrenCount
  218. // GetVirtualCtrNodeStreamCount
  219. // GetVirtualCtrNodeCRC
  220. // GetIStoragePointer
  221. // Init
  222. // IncreaseChildrenStgCount
  223. // IncreaseChildrenStmCount
  224. // MoveElementTo
  225. // Open
  226. // OpenRoot
  227. // OpenRootEx
  228. // QueryInterface
  229. // Rename
  230. // Revert
  231. // Stat
  232. // SetStateBits
  233. // SetElementTimes
  234. // SetClass
  235. // VirtualCtrNode
  236. // ~VirtualCtrNode
  237. //
  238. // Data: [_ptszName] - Name of this storage
  239. // [_cChildren] - Number of contained child storages
  240. // [_cStreams] - Number of contained streams
  241. // [_dwCRC] - CRC value of this storage w/all subobjects
  242. // [_pvsnStream] - First contained stream
  243. // [_pvcnChild] - First contained child storage
  244. // [_pvcnSister] - First contained sister storage (child of its
  245. // parent)
  246. // [_pvcnParent] - Containing storage
  247. // [_pstg] - Open IStorage for this storage
  248. //
  249. // History: 21-Mar-96 DeanE Created
  250. // 2-Feb-97 SCousens Added Open/CreateRoot for NSS files
  251. //--------------------------------------------------------------------------
  252. class VirtualCtrNode
  253. {
  254. public:
  255. VirtualCtrNode();
  256. ~VirtualCtrNode();
  257. // Methods corresponding to IStorage methods
  258. HRESULT CreateRoot (DWORD grfmode,
  259. DWORD dwReserved,
  260. DSKSTG DiskStgType = DSKSTG_DEFAULT);
  261. HRESULT CreateRootEx(DWORD grfMode,
  262. DWORD stgfmt,
  263. DWORD grfAttrs,
  264. STGOPTIONS *pStgOptions,
  265. PVOID pTransaction,
  266. REFIID riid = IID_IStorage);
  267. HRESULT Create (DWORD grfmode,
  268. DWORD dwReserved1,
  269. DWORD dwReserved2);
  270. HRESULT Stat (STATSTG *pStatStg,
  271. DWORD grfStatFlag);
  272. HRESULT SetStateBits(DWORD grfStateBits,
  273. DWORD grfMask);
  274. HRESULT Open (LPSTORAGE pstgPriority,
  275. DWORD grfmode,
  276. SNB snbExclude,
  277. DWORD dwReserved);
  278. HRESULT OpenRoot (LPSTORAGE pstgPriority,
  279. DWORD grfmode,
  280. SNB snbExclude,
  281. DWORD dwReserved,
  282. DSKSTG DiskStgType = DSKSTG_DEFAULT);
  283. HRESULT OpenRootEx (DWORD grfMode,
  284. DWORD stgfmt,
  285. DWORD grfAttrs,
  286. STGOPTIONS *pStgOptions,
  287. PVOID pTransaction,
  288. REFIID riid = IID_IStorage);
  289. HRESULT AddRefCount (void);
  290. HRESULT Close (void);
  291. HRESULT QueryInterface(REFIID riid,
  292. LPVOID *ppvObj);
  293. HRESULT Commit (DWORD grfCommitFlags);
  294. HRESULT Rename (LPCTSTR ptcsNewName);
  295. HRESULT Destroy (void);
  296. HRESULT EnumElements(DWORD dwReserved1,
  297. PVOID pReserved2,
  298. DWORD dwReserved3,
  299. LPENUMSTATSTG *ppenumStatStg);
  300. HRESULT SetElementTimes(FILETIME const *pctime,
  301. FILETIME const *patime,
  302. FILETIME const *pmtime);
  303. HRESULT SetClass (REFCLSID rclsid);
  304. HRESULT MoveElementTo(LPCTSTR ptszName,
  305. VirtualCtrNode *pvcnDest,
  306. LPCTSTR ptszNewName,
  307. DWORD grfFlags);
  308. HRESULT Revert (void);
  309. HRESULT CopyTo (DWORD ciidExclude,
  310. IID const* rgiidExclude,
  311. SNB snbExclude,
  312. VirtualCtrNode *pvcnDest);
  313. // Methods for operating on VirtualStgNodes
  314. HRESULT Init(LPTSTR tszName, ULONG cstg, ULONG cStm);
  315. HRESULT AppendChildCtr(VirtualCtrNode *pVCN);
  316. HRESULT AppendSisterCtr(VirtualCtrNode *pVCN);
  317. HRESULT AppendFirstChildStm(VirtualStmNode *pVSN);
  318. // inline functions
  319. inline VirtualStmNode *GetFirstChildVirtualStmNode() {return _pvsnStream;}
  320. inline VirtualCtrNode *GetFirstChildVirtualCtrNode() {return _pvcnChild;}
  321. inline VirtualCtrNode *GetFirstSisterVirtualCtrNode() {return _pvcnSister;}
  322. inline VirtualCtrNode *GetParentVirtualCtrNode() {return _pvcnParent;}
  323. inline LPTSTR GetVirtualCtrNodeName() {return _ptszName;}
  324. inline ULONG GetVirtualCtrNodeChildrenCount(){return _cChildren;}
  325. inline ULONG GetVirtualCtrNodeStreamCount() {return _cStreams;}
  326. inline VOID IncreaseChildrenStgCount() {_cChildren++;}
  327. inline VOID DecreaseChildrenStgCount() {_cChildren--;}
  328. inline VOID IncreaseChildrenStmCount() {_cStreams++;}
  329. inline VOID DecreaseChildrenStmCount() {_cStreams--;}
  330. inline DWORD GetVirtualCtrNodeCRC() {return _dwCRC;}
  331. inline LPSTORAGE GetIStoragePointer() {return _pstg;}
  332. // friend class
  333. friend VirtualDF;
  334. friend VirtualStmNode;
  335. // Custom ILockBytes based DocFile methods
  336. HRESULT CreateRootOnCustomILockBytes(DWORD grfMode,
  337. ILockBytes *pILockBytes);
  338. HRESULT OpenRootOnCustomILockBytes (LPSTORAGE pstgPriority,
  339. DWORD grfmode,
  340. SNB snbExclude,
  341. DWORD dwReserved,
  342. ILockBytes *pILockBytes);
  343. private:
  344. LPTSTR _ptszName;
  345. ULONG _cChildren;
  346. ULONG _cStreams;
  347. DWORD _dwCRC;
  348. VirtualStmNode *_pvsnStream;
  349. VirtualCtrNode *_pvcnChild;
  350. VirtualCtrNode *_pvcnSister;
  351. VirtualCtrNode *_pvcnParent;
  352. IStorage *_pstg;
  353. };
  354. //+-------------------------------------------------------------------------
  355. // Class: VirtualStmNode (vsn)
  356. //
  357. // Synopsis: In-memory stream object - virtualizes a real stream to
  358. // allow more efficient and easier verification when the
  359. // real one is being manipulated by tests.
  360. //
  361. // Methods: AddRefCount
  362. // AppendSisterStm
  363. // Create
  364. // Commit
  365. // Clone
  366. // Close
  367. // CalculateCRCs
  368. // Destroy
  369. // GetFirstSisterVirtualStmNode
  370. // GetParentVirtualStmNode
  371. // GetVirtualStmNodeName
  372. // GetVirtualStmNodeCRC
  373. // GetVirtualStmNodeCRCName
  374. // GetVirtualStmNodeCRCData
  375. // GetIStreamPointer
  376. // Init
  377. // LockRegion
  378. // Open
  379. // QueryInterface
  380. // Read
  381. // Revert
  382. // Rename
  383. // Seek
  384. // SetSize
  385. // Stat
  386. // UnlockRegion
  387. // VirtualStmNode
  388. // ~VirtualStmNode
  389. // Write
  390. //
  391. // Data: [_ptszName] - Name of this stream
  392. // [_cb] - Number of bytes in the stream
  393. // [_dwCRC] - CRC value for this stream
  394. // [_pvsnSister] - Pointer to next sister stream
  395. // [_pvcnParent] - Pointer to parent container
  396. // [_pstm] - IStream open for this stream
  397. //
  398. // History: 21-Mar-96 DeanE Created
  399. // 02-Apr-98 georgis +CalculateCRCs
  400. //--------------------------------------------------------------------------
  401. class VirtualStmNode
  402. {
  403. public:
  404. VirtualStmNode();
  405. ~VirtualStmNode();
  406. // Methods corresponding to IStorage stream-manipulation methods
  407. HRESULT Create (DWORD grfmode,
  408. DWORD dwReserved1,
  409. DWORD dwReserved2);
  410. HRESULT Read (PVOID pv,
  411. ULONG cb,
  412. ULONG *pcbRead);
  413. HRESULT Write (PVOID pv,
  414. ULONG cb,
  415. ULONG *pcbWritten);
  416. HRESULT Open (PVOID pvReserved1,
  417. DWORD grfmode,
  418. DWORD dwReserved2);
  419. HRESULT AddRefCount (void);
  420. HRESULT Close (void);
  421. HRESULT QueryInterface(REFIID riid,
  422. LPVOID *ppvObj);
  423. HRESULT Commit (DWORD grfCommitFlags);
  424. HRESULT Revert (void);
  425. HRESULT Stat (STATSTG *pStatStg,
  426. DWORD grfStatFlag);
  427. HRESULT Clone (LPSTREAM *ppstm);
  428. HRESULT Seek (LARGE_INTEGER dlibMove,
  429. DWORD dwOrigin,
  430. ULARGE_INTEGER *plibNewPosition);
  431. HRESULT SetSize (ULARGE_INTEGER libNewSize);
  432. HRESULT CopyTo (VirtualStmNode *pvsnDest,
  433. ULARGE_INTEGER cb,
  434. ULARGE_INTEGER *pcbRead,
  435. ULARGE_INTEGER *pcbWritten);
  436. HRESULT LockRegion (ULARGE_INTEGER libOffset,
  437. ULARGE_INTEGER cb,
  438. DWORD dwLockType);
  439. HRESULT UnlockRegion(ULARGE_INTEGER libOffset,
  440. ULARGE_INTEGER cb,
  441. DWORD dwLockType);
  442. HRESULT Destroy (void);
  443. HRESULT Rename (LPCTSTR ptcsNewName);
  444. // inline functions
  445. inline VirtualStmNode *GetFirstSisterVirtualStmNode(){return _pvsnSister;}
  446. inline VirtualCtrNode *GetParentVirtualCtrNode() {return _pvcnParent;}
  447. inline LPTSTR GetVirtualStmNodeName() {return _ptszName;}
  448. inline DWORD GetVirtualStmNodeCRC() {return _dwCRC.dwCRCSum;}
  449. inline DWORD GetVirtualStmNodeCRCName() {return _dwCRC.dwCRCName;}
  450. inline DWORD GetVirtualStmNodeCRCData() {return _dwCRC.dwCRCData;}
  451. inline DWORD GetVirtualStmNodeSize() {return _cb;}
  452. inline LPSTREAM GetIStreamPointer() {return _pstm;}
  453. // Methods for operating on VirtualStmNodes
  454. HRESULT Init (LPTSTR tszName, ULONG cb);
  455. HRESULT AppendSisterStm (VirtualStmNode *pVSN);
  456. HRESULT UpdateCRC (DWORD dwChunkSize=STM_CHUNK_SIZE);
  457. // friend class
  458. friend VirtualCtrNode;
  459. friend VirtualDF;
  460. private:
  461. LPTSTR _ptszName;
  462. ULONG _cb;
  463. DWCRCSTM _dwCRC;
  464. VirtualStmNode *_pvsnSister;
  465. VirtualCtrNode *_pvcnParent;
  466. IStream *_pstm;
  467. };
  468. #endif