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.

361 lines
9.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: CSTORAGE.CXX
  7. //
  8. // Contents:
  9. //
  10. // Classes: Implements the IStorage class.
  11. //
  12. // Functions:
  13. //
  14. // History: 12-20-95 JoeS (Joe Souza) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <urlint.h>
  18. #include <urlmon.hxx>
  19. #include "cstorage.hxx"
  20. #include "cstream.hxx"
  21. // Internal Function Prototypes
  22. CStorage *NewCStorage(IStorage *pStg);
  23. CStorage::CStorage(IStorage *pStorage) : _CRefs()
  24. {
  25. _pStg = pStorage;
  26. }
  27. STDMETHODIMP CStorage::QueryInterface
  28. (REFIID riid, LPVOID FAR* ppvObj)
  29. {
  30. VDATETHIS(this);
  31. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStorage::QueryInterface\n", this));
  32. HRESULT hresult = NOERROR;
  33. if ( IsEqualIID(riid, IID_IUnknown)
  34. || IsEqualIID(riid, IID_IStream)
  35. )
  36. {
  37. *ppvObj = this;
  38. AddRef();
  39. }
  40. else
  41. {
  42. *ppvObj = NULL;
  43. hresult = E_NOINTERFACE;
  44. }
  45. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStorage::QueryInterface\n", this));
  46. return hresult;
  47. }
  48. STDMETHODIMP_(ULONG) CStorage::AddRef(void)
  49. {
  50. VDATETHIS(this);
  51. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStorage::AddRef\n", this));
  52. LONG lRet = ++_CRefs;
  53. if (_pStg)
  54. _pStg->AddRef();
  55. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStorage::AddRef\n", this));
  56. return lRet;
  57. }
  58. STDMETHODIMP_(ULONG) CStorage::Release(void)
  59. {
  60. VDATETHIS(this);
  61. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStorage::Release\n", this));
  62. UrlMkAssert((_CRefs > 0));
  63. LONG lRet = --_CRefs;
  64. if (_pStg)
  65. _pStg->Release();
  66. if (_CRefs == 0)
  67. {
  68. delete this;
  69. }
  70. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStorage::Release\n", this));
  71. return lRet;
  72. }
  73. HRESULT CStorage::CreateStream(THIS_ const OLECHAR *pwcsName, DWORD grfMode,
  74. DWORD dwReserved1, DWORD dwReserved2, LPSTREAM FAR *ppStm)
  75. {
  76. HRESULT hresult = E_FAIL;
  77. IStream *pStream;
  78. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStorage::CreateStream\n", this));
  79. if (_pStg)
  80. {
  81. hresult = _pStg->CreateStream(pwcsName, grfMode, dwReserved1, dwReserved2,
  82. &pStream);
  83. if (hresult == S_OK)
  84. {
  85. if (!(*ppStm = new CStream(pStream)))
  86. {
  87. hresult = E_OUTOFMEMORY;
  88. // BUGBUG: Delete pStream!
  89. }
  90. }
  91. }
  92. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStorage::CreateStream\n", this));
  93. return(hresult);
  94. }
  95. HRESULT CStorage::OpenStream(THIS_ const OLECHAR *pwcsName,
  96. void FAR *pReserved1, DWORD grfMode, DWORD dwReserved2,
  97. LPSTREAM FAR *ppStm)
  98. {
  99. HRESULT hresult = E_FAIL;
  100. IStream *pStream;
  101. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStorage::OpenStream\n", this));
  102. if (_pStg)
  103. {
  104. hresult = _pStg->OpenStream(pwcsName, pReserved1, grfMode, dwReserved2,
  105. &pStream);
  106. if (hresult == S_OK)
  107. {
  108. if (!(*ppStm = new CStream(pStream)))
  109. {
  110. hresult = E_OUTOFMEMORY;
  111. // BUGBUG: Delete pStream!
  112. }
  113. }
  114. }
  115. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStorage::OpenStream\n", this));
  116. return(hresult);
  117. }
  118. HRESULT CStorage::CreateStorage(THIS_ const OLECHAR *pwcsName, DWORD grfMode,
  119. DWORD dwReserved1, DWORD dwReserved2, LPSTORAGE FAR *ppStg)
  120. {
  121. HRESULT hresult = E_FAIL;
  122. IStorage *pStorage;
  123. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStorage::CreateStorage\n", this));
  124. if (_pStg)
  125. {
  126. hresult = _pStg->CreateStorage(pwcsName, grfMode, dwReserved1, dwReserved2,
  127. &pStorage);
  128. if (hresult == S_OK)
  129. {
  130. if (!(*ppStg = ::NewCStorage(pStorage)))
  131. {
  132. hresult = E_OUTOFMEMORY;
  133. // BUGBUG: Delete pStorage!
  134. }
  135. }
  136. }
  137. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStorage::CreateStorage\n", this));
  138. return(hresult);
  139. }
  140. HRESULT CStorage::OpenStorage(THIS_ const OLECHAR *pwcsName,
  141. LPSTORAGE pstgPriority, DWORD grfMode, SNB snbExclude,
  142. DWORD dwReserved, LPSTORAGE FAR *ppStg)
  143. {
  144. HRESULT hresult = E_FAIL;
  145. IStorage *pStorage;
  146. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStorage::OpenStorage\n", this));
  147. if (_pStg)
  148. {
  149. hresult = _pStg->OpenStorage(pwcsName, pstgPriority, grfMode, snbExclude,
  150. dwReserved, &pStorage);
  151. if (hresult == S_OK)
  152. {
  153. if (!(*ppStg = ::NewCStorage(pStorage)))
  154. {
  155. hresult = E_OUTOFMEMORY;
  156. // BUGBUG: Delete pStorage!
  157. }
  158. }
  159. }
  160. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStorage::OpenStorage\n", this));
  161. return(hresult);
  162. }
  163. HRESULT CStorage::CopyTo(THIS_ DWORD dwCiidExclude, IID const FAR *rgiidExclude,
  164. SNB snbExclude, LPSTORAGE pStgDest)
  165. {
  166. HRESULT hresult = E_FAIL;
  167. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStorage::CopyTo\n", this));
  168. if (_pStg)
  169. hresult = _pStg->CopyTo(dwCiidExclude, rgiidExclude, snbExclude, pStgDest);
  170. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStorage::CopyTo\n", this));
  171. return(hresult);
  172. }
  173. HRESULT CStorage::MoveElementTo(THIS_ const OLECHAR *lpszName,
  174. LPSTORAGE pStgDest, const OLECHAR *lpszNewName, DWORD grfFlags)
  175. {
  176. HRESULT hresult = E_FAIL;
  177. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStorage::MoveElementTo\n", this));
  178. if (_pStg)
  179. hresult = _pStg->MoveElementTo(lpszName, pStgDest, lpszNewName, grfFlags);
  180. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStorage::MoveElementTo\n", this));
  181. return(hresult);
  182. }
  183. HRESULT CStorage::Commit(THIS_ DWORD grfCommitFlags)
  184. {
  185. HRESULT hresult = E_FAIL;
  186. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStorage::Commit\n", this));
  187. if (_pStg)
  188. hresult = _pStg->Commit(grfCommitFlags);
  189. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStorage::Commit\n", this));
  190. return(hresult);
  191. }
  192. HRESULT CStorage::Revert(THIS)
  193. {
  194. HRESULT hresult = E_FAIL;
  195. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStorage::Revert\n", this));
  196. if (_pStg)
  197. hresult = _pStg->Revert();
  198. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStorage::Revert\n", this));
  199. return(hresult);
  200. }
  201. HRESULT CStorage::EnumElements(THIS_ DWORD dwReserved1, void FAR *pReserved2,
  202. DWORD dwReserved3, LPENUMSTATSTG FAR *ppenumStatStg)
  203. {
  204. HRESULT hresult = E_FAIL;
  205. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStorage::EnumElements\n", this));
  206. if (_pStg)
  207. hresult = _pStg->EnumElements(dwReserved1, pReserved2, dwReserved3,
  208. ppenumStatStg);
  209. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStorage::EnumElements\n", this));
  210. return(hresult);
  211. }
  212. HRESULT CStorage::DestroyElement(THIS_ const OLECHAR *pwcsName)
  213. {
  214. HRESULT hresult = E_FAIL;
  215. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStorage::DestroyElement\n", this));
  216. if (_pStg)
  217. hresult = _pStg->DestroyElement(pwcsName);
  218. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStorage::DestroyElement\n", this));
  219. return(hresult);
  220. }
  221. HRESULT CStorage::RenameElement(THIS_ const OLECHAR *pwcsOldName,
  222. const OLECHAR *pwcsNewName)
  223. {
  224. HRESULT hresult = E_FAIL;
  225. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStorage::RenameElement\n", this));
  226. if (_pStg)
  227. hresult = _pStg->RenameElement(pwcsOldName, pwcsNewName);
  228. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStorage::RenameElement\n", this));
  229. return(hresult);
  230. }
  231. HRESULT CStorage::SetElementTimes(THIS_ const OLECHAR *lpszName,
  232. FILETIME const FAR *pctime, FILETIME const FAR *patime,
  233. FILETIME const FAR *pmtime)
  234. {
  235. HRESULT hresult = E_FAIL;
  236. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStorage::SetElementTimes\n", this));
  237. if (_pStg)
  238. hresult = _pStg->SetElementTimes(lpszName, pctime, patime, pmtime);
  239. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStorage::SetElementTimes\n", this));
  240. return(hresult);
  241. }
  242. HRESULT CStorage::SetClass(THIS_ REFCLSID rclsid)
  243. {
  244. HRESULT hresult = E_FAIL;
  245. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStorage::SetClass\n", this));
  246. if (_pStg)
  247. hresult = _pStg->SetClass(rclsid);
  248. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStorage::SetClass\n", this));
  249. return(hresult);
  250. }
  251. HRESULT CStorage::SetStateBits(THIS_ DWORD grfStateBits, DWORD grfMask)
  252. {
  253. HRESULT hresult = E_FAIL;
  254. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStorage::SetStateBits\n", this));
  255. if (_pStg)
  256. hresult = _pStg->SetStateBits(grfStateBits, grfMask);
  257. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStorage::SetStateBits\n", this));
  258. return(hresult);
  259. }
  260. HRESULT CStorage::Stat(THIS_ STATSTG FAR *pStatStg, DWORD grfStatFlag)
  261. {
  262. HRESULT hresult = E_FAIL;
  263. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStorage::Stat\n", this));
  264. if (_pStg)
  265. hresult = _pStg->Stat(pStatStg, grfStatFlag);
  266. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStorage::Stat\n", this));
  267. return(hresult);
  268. }
  269. // Internal functions
  270. CStorage *NewCStorage(IStorage *pStg)
  271. {
  272. return(new CStorage(pStg));
  273. }