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.

415 lines
12 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: simpdf.hxx
  7. //
  8. // Contents: Headers for SimpDocfile
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 04-Aug-94 PhilipLa Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #ifndef __SIMPDF_HXX__
  18. #define __SIMPDF_HXX__
  19. #include <dfnlist.hxx>
  20. #include <header.hxx>
  21. #if DBG == 1
  22. DECLARE_DEBUG(simp);
  23. #endif
  24. #if DBG == 1
  25. #define simpDebugOut(x) simpInlineDebugOut x
  26. #define simpAssert(e) Win4Assert(e)
  27. #define simpVerify(e) Win4Assert(e)
  28. #else
  29. #define simpDebugOut(x)
  30. #define simpAssert(e)
  31. #define simpVerify(e) (e)
  32. #endif
  33. #define SECTORSIZE 512
  34. //+---------------------------------------------------------------------------
  35. //
  36. // Struct: SSimpDocfileHints
  37. //
  38. // Purpose: Hints for SimpDocfile
  39. //
  40. // History: 04-Aug-94 PhilipLa Created
  41. //
  42. //----------------------------------------------------------------------------
  43. struct SSimpDocfileHints
  44. {
  45. ULONG cStreams;
  46. ULONG ulSize;
  47. };
  48. //+---------------------------------------------------------------------------
  49. //
  50. // Class: CSimpStorage
  51. //
  52. // Purpose:
  53. //
  54. // Interface:
  55. //
  56. // History: 04-Aug-94 PhilipLa Created
  57. //
  58. // Notes:
  59. //
  60. //----------------------------------------------------------------------------
  61. interface CSimpStorage:
  62. public IStorage,
  63. public IMarshal,
  64. public CPropertySetStorage
  65. {
  66. public:
  67. inline CSimpStorage();
  68. inline ~CSimpStorage();
  69. SCODE Init(WCHAR const *pwcsName, SSimpDocfileHints *psdh);
  70. #ifdef SECURE_SIMPLE_MODE
  71. void ReleaseCurrentStream(ULONG ulHighWater);
  72. #else
  73. void ReleaseCurrentStream(void);
  74. #endif
  75. // From IUnknown
  76. STDMETHOD(QueryInterface)(REFIID iid, void **ppvObj);
  77. STDMETHOD_(ULONG,AddRef)(void);
  78. STDMETHOD_(ULONG,Release)(void);
  79. // IStorage
  80. STDMETHOD(CreateStream)(OLECHAR const *pwcsName,
  81. DWORD grfMode,
  82. DWORD reserved1,
  83. DWORD reserved2,
  84. IStream **ppstm);
  85. STDMETHOD(OpenStream)(OLECHAR const *pwcsName,
  86. void *reserved1,
  87. DWORD grfMode,
  88. DWORD reserved2,
  89. IStream **ppstm);
  90. STDMETHOD(CreateStorage)(OLECHAR const *pwcsName,
  91. DWORD grfMode,
  92. DWORD reserved1,
  93. LPSTGSECURITY reserved2,
  94. IStorage **ppstg);
  95. STDMETHOD(OpenStorage)(OLECHAR const *pwcsName,
  96. IStorage *pstgPriority,
  97. DWORD grfMode,
  98. SNB snbExclude,
  99. DWORD reserved,
  100. IStorage **ppstg);
  101. STDMETHOD(CopyTo)(DWORD ciidExclude,
  102. IID const *rgiidExclude,
  103. SNB snbExclude,
  104. IStorage *pstgDest);
  105. STDMETHOD(MoveElementTo)(OLECHAR const *lpszName,
  106. IStorage *pstgDest,
  107. OLECHAR const *lpszNewName,
  108. DWORD grfFlags);
  109. STDMETHOD(Commit)(DWORD grfCommitFlags);
  110. STDMETHOD(Revert)(void);
  111. STDMETHOD(EnumElements)(DWORD reserved1,
  112. void *reserved2,
  113. DWORD reserved3,
  114. IEnumSTATSTG **ppenm);
  115. STDMETHOD(DestroyElement)(OLECHAR const *pwcsName);
  116. STDMETHOD(RenameElement)(OLECHAR const *pwcsOldName,
  117. OLECHAR const *pwcsNewName);
  118. STDMETHOD(SetElementTimes)(const OLECHAR *lpszName,
  119. FILETIME const *pctime,
  120. FILETIME const *patime,
  121. FILETIME const *pmtime);
  122. STDMETHOD(SetClass)(REFCLSID clsid);
  123. STDMETHOD(SetStateBits)(DWORD grfStateBits, DWORD grfMask);
  124. STDMETHOD(Stat)(STATSTG *pstatstg, DWORD grfStatFlag);
  125. // IMarshal
  126. STDMETHOD(GetUnmarshalClass)(REFIID riid,
  127. LPVOID pv,
  128. DWORD dwDestContext,
  129. LPVOID pvDestContext,
  130. DWORD mshlflags,
  131. LPCLSID pCid);
  132. STDMETHOD(GetMarshalSizeMax)(REFIID riid,
  133. LPVOID pv,
  134. DWORD dwDestContext,
  135. LPVOID pvDestContext,
  136. DWORD mshlflags,
  137. LPDWORD pSize);
  138. STDMETHOD(MarshalInterface)(IStream *pStm,
  139. REFIID riid,
  140. LPVOID pv,
  141. DWORD dwDestContext,
  142. LPVOID pvDestContext,
  143. DWORD mshlflags);
  144. STDMETHOD(UnmarshalInterface)(IStream *pStm,
  145. REFIID riid,
  146. LPVOID *ppv);
  147. STDMETHOD(ReleaseMarshalData)(IStream *pStm);
  148. STDMETHOD(DisconnectObject)(DWORD dwReserved);
  149. protected:
  150. SID BuildTree(CDirEntry *ade, SID sidStart, ULONG cStreams);
  151. LONG _cReferences;
  152. HANDLE _hFile;
  153. BOOL _fDirty;
  154. CMSFHeader _hdr;
  155. BYTE *_pbBuf;
  156. SECT _sectMax;
  157. CLSID _clsid;
  158. CDfNameList *_pdfl;
  159. CDfNameList *_pdflCurrent;
  160. ULONG _cStreams;
  161. };
  162. //+---------------------------------------------------------------------------
  163. //
  164. // Member: CSimpStorage::CSimpStorage, public
  165. //
  166. // Synopsis: Constructor
  167. //
  168. // History: 04-Aug-94 PhilipLa Created
  169. //
  170. //----------------------------------------------------------------------------
  171. inline CSimpStorage::CSimpStorage()
  172. : CPropertySetStorage( MAPPED_STREAM_CREATE ),
  173. _hdr(SECTORSHIFT512)
  174. {
  175. _cReferences = 1;
  176. _pbBuf = NULL;
  177. _sectMax = 0;
  178. _pdfl = NULL;
  179. _hFile = INVALID_HANDLE_VALUE;
  180. _fDirty = FALSE;
  181. _pdflCurrent = NULL;
  182. _cStreams = 0;
  183. CPropertySetStorage::Init( static_cast<IStorage*>(this),
  184. /*IBlockingLock*/NULL,
  185. FALSE ); // fControlLifetimes (=> don't AddRef)
  186. }
  187. //+---------------------------------------------------------------------------
  188. //
  189. // Member: CSimpStorage::~CSimpStorage, public
  190. //
  191. // Synopsis: Destructor
  192. //
  193. // History: 04-Aug-94 PhilipLa Created
  194. //
  195. //----------------------------------------------------------------------------
  196. inline CSimpStorage::~CSimpStorage()
  197. {
  198. if (_pbBuf != NULL)
  199. delete _pbBuf;
  200. while (_pdfl != NULL)
  201. {
  202. CDfNameList *pdfl = _pdfl;
  203. _pdfl = pdfl->GetNext();
  204. delete pdfl;
  205. }
  206. }
  207. SCODE DfCreateSimpDocfile(WCHAR const *pwcsName,
  208. DWORD grfMode,
  209. DWORD reserved,
  210. IStorage **ppstgOpen);
  211. SCODE DfOpenSimpDocfile(WCHAR const *pwcsName,
  212. DWORD grfMode,
  213. DWORD reserved,
  214. IStorage **ppstgOpen);
  215. //+---------------------------------------------------------------------------
  216. //
  217. // Class: CSimpStorageOpen
  218. //
  219. // Purpose: allow simple mode reads
  220. //
  221. // Interface: IStorage, IMarshal
  222. //
  223. // History: 04-Aug-96 HenryLee Created
  224. //
  225. // Notes: overrides CSimpStorage methods
  226. //
  227. //----------------------------------------------------------------------------
  228. class CSimpStorageOpen : public CSimpStorage
  229. {
  230. public:
  231. inline CSimpStorageOpen();
  232. inline ~CSimpStorageOpen();
  233. inline void ReleaseCurrentStream();
  234. SCODE Init(WCHAR const *pwcsName, DWORD grfMode, SSimpDocfileHints *psdh);
  235. SCODE ValidateHeader (CMSFHeader &hdr);
  236. SCODE ValidateDirectory (BYTE *pByte, ULONG ulDirLength);
  237. SCODE ValidateFat (SECT *pSect, ULONG ulFatLength);
  238. SCODE ValidateDIFat (SECT *pSect, ULONG ulDIFatLength, SECT sectStart);
  239. STDMETHOD_(ULONG,Release)(void); // override virtual function
  240. STDMETHOD(Stat)(STATSTG *pstatstg, DWORD grfStatFlag);
  241. STDMETHOD(OpenStream)(OLECHAR const *pwcsName,
  242. void *reserved1,
  243. DWORD grfMode,
  244. DWORD reserved2,
  245. IStream **ppstm);
  246. STDMETHOD(CreateStream)(OLECHAR const *pwcsName,
  247. DWORD grfMode,
  248. DWORD reserved1,
  249. DWORD reserved2,
  250. IStream **ppstm);
  251. STDMETHOD(EnumElements)(DWORD reserved1,
  252. void *reserved2,
  253. DWORD reserved3,
  254. IEnumSTATSTG **ppenm);
  255. STDMETHOD(SetClass)(REFCLSID clsid);
  256. protected:
  257. DWORD _grfMode;
  258. DWORD _grfStateBits;
  259. WCHAR _awcsName[MAX_PATH];
  260. };
  261. //+---------------------------------------------------------------------------
  262. //
  263. // Member: CSimpStorageOpen::CSimpStorageOpen, public
  264. //
  265. // Synopsis: Constructor
  266. //
  267. // History: 04-May-96 HenryLee Created
  268. //
  269. //----------------------------------------------------------------------------
  270. inline CSimpStorageOpen::CSimpStorageOpen()
  271. {
  272. }
  273. //+---------------------------------------------------------------------------
  274. //
  275. // Member: CSimpStorageOpen::~CSimpStorageOpen, public
  276. //
  277. // Synopsis: Destructor
  278. //
  279. // History: 04-May-96 HenryLee Created
  280. //
  281. //----------------------------------------------------------------------------
  282. inline CSimpStorageOpen::~CSimpStorageOpen()
  283. {
  284. }
  285. //+---------------------------------------------------------------------------
  286. //
  287. // Member: CSimpStorageOpen::ReleaseCurrentStream, public
  288. //
  289. // Synopsis: releases current stream so other opens can occur
  290. //
  291. // History: 04-May-96 HenryLee Created
  292. //
  293. //----------------------------------------------------------------------------
  294. inline void CSimpStorageOpen::ReleaseCurrentStream()
  295. {
  296. _pdflCurrent = NULL;
  297. }
  298. //+---------------------------------------------------------------------------
  299. //
  300. // Class: CSimpEnumSTATSTG
  301. //
  302. // Purpose: allow simple mode read enumeration
  303. //
  304. // Interface: IEnumSTATSTG
  305. //
  306. // History: 04-Aug-96 HenryLee Created
  307. //
  308. // Notes: Skip is not supported
  309. //
  310. //----------------------------------------------------------------------------
  311. class CSimpEnumSTATSTG : public IEnumSTATSTG
  312. {
  313. public:
  314. inline CSimpEnumSTATSTG (CDfNameList *pdfl, CDfNameList *pdflCurrent);
  315. inline ~CSimpEnumSTATSTG ();
  316. STDMETHOD(QueryInterface)(REFIID iid, void **ppvObj);
  317. STDMETHOD_(ULONG,AddRef)(void);
  318. STDMETHOD_(ULONG,Release)(void);
  319. STDMETHOD(Next)(ULONG celt, STATSTG FAR *rgelt, ULONG *pceltFetched);
  320. STDMETHOD(Skip)(ULONG celt);
  321. STDMETHOD(Reset)(void);
  322. STDMETHOD(Clone)(IEnumSTATSTG **ppenm);
  323. protected:
  324. ULONG _cReferences;
  325. CDfNameList *_pdfl;
  326. CDfNameList *_pdflCurrent;
  327. };
  328. //+---------------------------------------------------------------------------
  329. //
  330. // Member: CSimpEnumSTATSTG::CSimpEnumSTATSTG, public
  331. //
  332. // Synopsis: Constructor
  333. //
  334. // History: 04-May-96 HenryLee Created
  335. //
  336. //----------------------------------------------------------------------------
  337. inline CSimpEnumSTATSTG::CSimpEnumSTATSTG (CDfNameList *pdfl,
  338. CDfNameList *pdflCurrent) :
  339. _pdfl(pdfl), _pdflCurrent(pdflCurrent), _cReferences(1)
  340. {
  341. }
  342. //+---------------------------------------------------------------------------
  343. //
  344. // Member: CSimpEnumSTATSTG::~CSimpEnumSTATSTG, public
  345. //
  346. // Synopsis: Destructor
  347. //
  348. // History: 04-May-96 HenryLee Created
  349. //
  350. //----------------------------------------------------------------------------
  351. inline CSimpEnumSTATSTG::~CSimpEnumSTATSTG ()
  352. {
  353. }
  354. #define SIMP_VALIDATE(x) if (FAILED(sc = CExpParameterValidate::x)) {simpDebugOut((DEB_ERROR, "Error %lX at %s:%d\n", sc, __FILE__, __LINE__)); return sc;}
  355. #endif // #ifndef __SIMPDF_HXX__