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.

400 lines
13 KiB

  1. //+--------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: expdf.hxx
  7. //
  8. // Contents: Exposed DocFile header
  9. //
  10. // Classes: CExposedDocFile
  11. //
  12. // Notes:
  13. // The CExposedDocFile class is the implementation
  14. // of IStorage. It implements IPropertySetStorage
  15. // by inheriting from CPropertySetStorage. CPropertySetStorage
  16. // implements all the functionality of IPropertySetStorage.
  17. //
  18. // Note that this interface is solely UNICODE, the ASCII layer
  19. // support which is present if _UNICODE is not defined, provides
  20. // the overloaded functions that handles the ASCII to Unicode
  21. // conversion.
  22. //
  23. //
  24. //---------------------------------------------------------------
  25. #ifndef __EXPDF_HXX__
  26. #define __EXPDF_HXX__
  27. #include "h/dfmsp.hxx"
  28. #include "dfbasis.hxx"
  29. #include "h/revert.hxx"
  30. #include "h/cdocfile.hxx"
  31. #include "h/chinst.hxx"
  32. #ifdef NEWPROPS
  33. #include "props/h/windef.h"
  34. #include "props/psetstg.hxx"
  35. #endif
  36. // CopyDocFileToIStorage flags
  37. #define COPY_STORAGES 1
  38. #define COPY_STREAMS 2
  39. #define COPY_PROPERTIES 4
  40. #define COPY_ALL (COPY_STORAGES | COPY_STREAMS | COPY_PROPERTIES)
  41. class CDocFile;
  42. interface CExposedStream;
  43. class CPropertySetStorage;
  44. //+--------------------------------------------------------------
  45. //
  46. // Class: CExposedDocFile (df)
  47. //
  48. // Purpose: Exposed DocFile class
  49. //
  50. // Note: PRevertable is a general virtual class base that
  51. // handles updates to the storage elements. E.g.
  52. // when an IStorage parent is deleted, the children
  53. // underneadth them will have the reverted state.
  54. //
  55. // IPrivateStorage is a virtual class which has the functionality
  56. // of returning the IStorage interface pointer. It is used by the
  57. // propertyset interfaces to access the IStorage functions of
  58. // CExposedDocfile.
  59. //
  60. //---------------------------------------------------------------
  61. interface CExposedDocFile
  62. :
  63. public IStorage,
  64. public IRootStorage,
  65. #ifdef NEWPROPS
  66. public CPropertySetStorage,
  67. public IPrivateStorage,
  68. #endif
  69. public PRevertable
  70. {
  71. public:
  72. CExposedDocFile( CExposedDocFile *pdfParent,
  73. CDocFile *pdf,
  74. DFLAGS const df,
  75. DFLUID luid,
  76. ILockBytes *pilbBase,
  77. CDfName const *pdfn,
  78. CMStream* pmsBase,
  79. CDFBasis *pdfb);
  80. virtual ~CExposedDocFile(void);
  81. // From IUnknown
  82. STDMETHOD(QueryInterface)(REFIID iid, void **ppvObj);
  83. STDMETHOD_(ULONG,AddRef)(void);
  84. STDMETHOD_(ULONG,Release)(void);
  85. // IStorage
  86. STDMETHOD(Commit)(DWORD grfCommitFlags);
  87. STDMETHOD(Revert)(void);
  88. STDMETHOD(EnumElements)(DWORD reserved1,
  89. void *reserved2,
  90. DWORD reserved3,
  91. IEnumSTATSTG **ppenm);
  92. STDMETHOD(SetClass)(REFCLSID clsid);
  93. STDMETHOD(SetStateBits)(DWORD grfStateBits, DWORD grfMask);
  94. // functions that uses char/wchar directly or indirectly
  95. STDMETHOD(CreateStream)(TCHAR const *pwcsName,
  96. DWORD grfMode,
  97. DWORD reserved1,
  98. DWORD reserved2,
  99. IStream **ppstm);
  100. STDMETHOD(OpenStream)(TCHAR const *pwcsName,
  101. void *reserved1,
  102. DWORD grfMode,
  103. DWORD reserved2,
  104. IStream **ppstm);
  105. STDMETHOD(CreateStorage)(TCHAR const *pwcsName,
  106. DWORD grfMode,
  107. DWORD reserved1,
  108. DWORD reserved2,
  109. IStorage **ppstg);
  110. STDMETHOD(OpenStorage)(TCHAR const *pwcsName,
  111. IStorage *pstgPriority,
  112. DWORD grfMode,
  113. SNB snbExclude,
  114. DWORD reserved,
  115. IStorage **ppstg);
  116. STDMETHOD(CopyTo)(DWORD ciidExclude,
  117. IID const *rgiidExclude,
  118. SNB snbExclude,
  119. IStorage *pstgDest);
  120. STDMETHOD(MoveElementTo)(TCHAR const *lpszName,
  121. IStorage *pstgDest,
  122. TCHAR const *lpszNewName,
  123. DWORD grfFlags);
  124. STDMETHOD(DestroyElement)(TCHAR const *pwcsName);
  125. STDMETHOD(RenameElement)(TCHAR const *pwcsOldName,
  126. TCHAR const *pwcsNewName);
  127. STDMETHOD(SetElementTimes)(const TCHAR *lpszName,
  128. FILETIME const *pctime,
  129. FILETIME const *patime,
  130. FILETIME const *pmtime);
  131. STDMETHOD(Stat)(STATSTG *pstatstg, DWORD grfStatFlag);
  132. private:
  133. SCODE CreateExposedStream( CDfName const *pdfnName,
  134. DFLAGS const df,
  135. CExposedStream **ppStream);
  136. SCODE GetExposedStream( CDfName const *pdfnName,
  137. DFLAGS const df,
  138. CExposedStream **ppStream);
  139. SCODE CreateExposedDocFile(CDfName const *pdfnName,
  140. DFLAGS const df,
  141. CExposedDocFile **ppdfDocFile);
  142. SCODE GetExposedDocFile( CDfName const *pdfnName,
  143. DFLAGS const df,
  144. CExposedDocFile **ppdfDocFile);
  145. SCODE DestroyEntry( CDfName const *pdfnName, BOOL fClean);
  146. SCODE RenameEntry(CDfName const *pdfnName,
  147. CDfName const *pdfnNewName);
  148. #ifndef _UNICODE // the real code will map to the
  149. // block above if we are using UNICODE
  150. private:
  151. // internal functions that uses wide character
  152. SCODE CreateStream(WCHAR const *pwcsName,
  153. DWORD grfMode,
  154. DWORD reserved1,
  155. DWORD reserved2,
  156. IStream **ppstm);
  157. SCODE OpenStream(WCHAR const *pwcsName,
  158. void *reserved1,
  159. DWORD grfMode,
  160. DWORD reserved2,
  161. IStream **ppstm);
  162. SCODE CreateStorage(WCHAR const *pwcsName,
  163. DWORD grfMode,
  164. DWORD reserved1,
  165. DWORD reserved2,
  166. IStorage **ppstg);
  167. SCODE OpenStorage(WCHAR const *pwcsName,
  168. IStorage *pstgPriority,
  169. DWORD grfMode,
  170. SNBW snbExclude,
  171. DWORD reserved,
  172. IStorage **ppstg);
  173. SCODE CopyTo(DWORD ciidExclude,
  174. IID const *rgiidExclude,
  175. SNBW snbExclude,
  176. IStorage *pstgDest);
  177. SCODE MoveElementTo(WCHAR const *pwcsName,
  178. IStorage *pstgDest,
  179. TCHAR const *ptcsNewName,
  180. DWORD grfFlags);
  181. SCODE DestroyElement(WCHAR const *pwcsName);
  182. SCODE RenameElement(WCHAR const *pwcsOldName,
  183. WCHAR const *pwcsNewName);
  184. SCODE SetElementTimes(WCHAR const *pwcsName,
  185. FILETIME const *pctime,
  186. FILETIME const *patime,
  187. FILETIME const *pmtime);
  188. STDMETHOD(Stat)(STATSTGW *pstatstg, DWORD grfStatFlag);
  189. #endif // !_UNICODE
  190. public:
  191. // IRootStorage
  192. STDMETHOD(SwitchToFile)(TCHAR *ptcsFile);
  193. #ifdef NEWPROPS
  194. // IPrivateStorage
  195. STDMETHOD_(IStorage *,GetStorage)(VOID);
  196. #endif
  197. // New methods
  198. inline SCODE Validate(void) const;
  199. inline CDocFile* GetDF() const
  200. { return _pdf; }
  201. public: // methods related to maintaining the tree
  202. inline void SetDF( CDocFile* pdf)
  203. { _pdf = pdf; }
  204. inline BOOL IsRoot(void) const
  205. { return _pdfParent == NULL; }
  206. inline CExposedDocFile* GetParent(void) const
  207. { return _pdfParent; }
  208. inline void SetClean(void)
  209. { _fDirty = FALSE; }
  210. inline BOOL IsDirty(void) const
  211. { return _fDirty; }
  212. inline void SetDirty(void);
  213. inline void SetDirtyBit(void)
  214. { _fDirty = TRUE; }
  215. BOOL IsAtOrAbove(CExposedDocFile *pdf);
  216. CMStream* GetBaseMS(void)
  217. { return _pmsBase; }
  218. inline SCODE FindGreaterEntry(CDfName const *pdfnKey,
  219. CDfName *pNextKey,
  220. STATSTGW *pstat);
  221. inline SCODE CheckReverted(void) const;
  222. inline void ReleaseChild(PRevertable *prv);
  223. inline void AddChild(PRevertable *prv);
  224. // PRevertable
  225. virtual void RevertFromAbove(void);
  226. #ifdef NEWPROPS
  227. virtual SCODE FlushBufferedData(void);
  228. #endif
  229. private:
  230. SCODE CreateEntry(WCHAR const *pwcsName,
  231. DWORD dwType,
  232. DWORD grfMode,
  233. void **ppv);
  234. SCODE OpenEntry(WCHAR const *pwcsName,
  235. DWORD dwType,
  236. DWORD grfMode,
  237. void **ppv);
  238. static DWORD MakeCopyFlags(DWORD ciidExclude,
  239. IID const *rgiidExclude);
  240. SCODE CopyDocFileToIStorage( CDocFile *pdfFrom,
  241. IStorage *pstgTo,
  242. SNBW snbExclude,
  243. DWORD dwCopyFlags);
  244. SCODE CopyDStreamToIStream( CDirectStream *pstFrom,
  245. IStream *pstTo);
  246. SCODE ConvertInternalStream( CExposedDocFile *pdfExp);
  247. inline SCODE CheckCopyTo(void);
  248. CExposedDocFile *_pdfParent;
  249. CChildInstanceList _cilChildren;
  250. BOOL _fDirty;
  251. ULONG _sig;
  252. ULONG _ulAccessLockBase;
  253. protected:
  254. ILockBytes *_pilbBase;
  255. CMStream *_pmsBase;
  256. CDocFile *_pdf;
  257. LONG _cReferences;
  258. CDFBasis *_pdfb; // stores docfile wide stuff
  259. };
  260. #define CEXPOSEDDOCFILE_SIG LONGSIG('E', 'D', 'F', 'L')
  261. #define CEXPOSEDDOCFILE_SIGDEL LONGSIG('E', 'd', 'F', 'l')
  262. //+--------------------------------------------------------------
  263. //
  264. // Member: CExposedDocFile::Validate, public
  265. //
  266. // Synopsis: Validates the class signature
  267. //
  268. // Returns: Returns STG_E_INVALIDHANDLE for failure
  269. //
  270. //---------------------------------------------------------------
  271. inline SCODE CExposedDocFile::Validate(void) const
  272. {
  273. return (this == NULL || _sig != CEXPOSEDDOCFILE_SIG) ?
  274. STG_E_INVALIDHANDLE : S_OK;
  275. }
  276. //+---------------------------------------------------------------------------
  277. //
  278. // Member: CExposedDocFile::SetDirty, public
  279. //
  280. // Synopsis: Sets the dirty flag and all parents' dirty flags
  281. //
  282. //----------------------------------------------------------------------------
  283. inline void CExposedDocFile::SetDirty(void)
  284. {
  285. CExposedDocFile *ppdf = this;
  286. olAssert( this && aMsg("Attempted to dirty parent of root"));
  287. do
  288. {
  289. ppdf->SetDirtyBit();
  290. ppdf = ppdf->GetParent();
  291. } while (ppdf != NULL);
  292. }
  293. //+--------------------------------------------------------------
  294. //
  295. // Member: CExposedDocFile::ReleaseChild, private
  296. //
  297. // Synopsis: Releases a child instance
  298. //
  299. // Arguments: [prv] - Child instance
  300. //
  301. //---------------------------------------------------------------
  302. inline void CExposedDocFile::ReleaseChild(PRevertable *prv)
  303. {
  304. olAssert(SUCCEEDED(CheckReverted()));
  305. _cilChildren.RemoveRv(prv);
  306. }
  307. //+--------------------------------------------------------------
  308. //
  309. // Member: CExposedDocFile::AddChild, public
  310. //
  311. // Synopsis: Adds a child instance
  312. //
  313. // Arguments: [prv] - Child
  314. //
  315. //---------------------------------------------------------------
  316. inline void CExposedDocFile::AddChild(PRevertable *prv)
  317. {
  318. olAssert(SUCCEEDED(CheckReverted()));
  319. _cilChildren.Add(prv);
  320. }
  321. //+---------------------------------------------------------------------------
  322. //
  323. // Member: CExposedDocFile::FindGreaterEntry, public
  324. //
  325. // Synopsis: Returns the next greater child
  326. //
  327. // Arguments: [pdfnKey] - Previous key
  328. // [pstat] - iterator buffer
  329. //
  330. // Returns: Appropriate status code
  331. //
  332. // Modifies: [pstat]
  333. //
  334. //----------------------------------------------------------------------------
  335. inline SCODE CExposedDocFile::FindGreaterEntry(CDfName const *pdfnKey,
  336. CDfName *pNextKey,
  337. STATSTGW *pstat)
  338. {
  339. olAssert(SUCCEEDED(CheckReverted()));
  340. return _pdf->FindGreaterEntry(pdfnKey, pNextKey, pstat);
  341. }
  342. //+--------------------------------------------------------------
  343. //
  344. // Member: CExposedDocFile::CheckReverted, private
  345. //
  346. // Synopsis: Returns STG_E_REVERTED if reverted
  347. //
  348. //---------------------------------------------------------------
  349. inline SCODE CExposedDocFile::CheckReverted(void) const
  350. {
  351. return P_REVERTED(_df) ? STG_E_REVERTED : S_OK;
  352. }
  353. #endif