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.

273 lines
6.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: CSTREAM.CXX
  7. //
  8. // Contents:
  9. //
  10. // Classes: Implements the IStream class.
  11. //
  12. // Functions:
  13. //
  14. // History: 12-01-95 JoeS (Joe Souza) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <urlint.h>
  18. #include <urlmon.hxx>
  19. #include "cstream.hxx"
  20. CStream::CStream(IStream *pStr) : _CRefs()
  21. {
  22. _pStream = pStr;
  23. }
  24. STDMETHODIMP CStream::QueryInterface
  25. (REFIID riid, LPVOID FAR* ppvObj)
  26. {
  27. VDATETHIS(this);
  28. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStream::QueryInterface\n", this));
  29. HRESULT hresult = NOERROR;
  30. if ( IsEqualIID(riid, IID_IUnknown)
  31. || IsEqualIID(riid, IID_IStream)
  32. )
  33. {
  34. *ppvObj = this;
  35. AddRef();
  36. }
  37. else
  38. {
  39. *ppvObj = NULL;
  40. hresult = E_NOINTERFACE;
  41. }
  42. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStream::QueryInterface\n", this));
  43. return hresult;
  44. }
  45. STDMETHODIMP_(ULONG) CStream::AddRef(void)
  46. {
  47. VDATETHIS(this);
  48. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStream::AddRef\n", this));
  49. LONG lRet = ++_CRefs;
  50. if (_pStream)
  51. _pStream->AddRef();
  52. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStream::AddRef\n", this));
  53. return lRet;
  54. }
  55. STDMETHODIMP_(ULONG) CStream::Release(void)
  56. {
  57. VDATETHIS(this);
  58. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStream::Release\n", this));
  59. UrlMkAssert((_CRefs > 0));
  60. LONG lRet = --_CRefs;
  61. if (_pStream)
  62. _pStream->Release();
  63. if (_CRefs == 0)
  64. {
  65. delete this;
  66. }
  67. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStream::Release\n", this));
  68. return lRet;
  69. }
  70. HRESULT CStream::Read(THIS_ VOID HUGEP *pv, ULONG cb, ULONG FAR *pcbRead)
  71. {
  72. HRESULT hresult = E_FAIL;
  73. ULONG readcount;
  74. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStream::Read\n", this));
  75. if (_pStream)
  76. {
  77. #if 0
  78. while (TRUE)
  79. {
  80. #endif
  81. hresult = _pStream->Read(pv, cb, &readcount);
  82. if (pcbRead)
  83. *pcbRead = readcount;
  84. #if 0
  85. if (hresult != NOERROR)
  86. break;
  87. if (readcount == cb)
  88. break;
  89. hresult = BlockOnIFillLockBytes(this); // BUGBUG:
  90. if (hresult != S_OK)
  91. break;
  92. }
  93. #endif
  94. }
  95. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStream::Read\n", this));
  96. return(hresult);
  97. }
  98. HRESULT CStream::Write(THIS_ VOID const HUGEP *pv, ULONG cb,
  99. ULONG FAR *pcbWritten)
  100. {
  101. HRESULT hresult = E_FAIL;
  102. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStream::Write\n", this));
  103. if (_pStream)
  104. hresult = _pStream->Write(pv, cb, pcbWritten);
  105. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStream::Write\n", this));
  106. return(hresult);
  107. }
  108. HRESULT CStream::Seek(THIS_ LARGE_INTEGER dlibMove, DWORD dwOrigin,
  109. ULARGE_INTEGER FAR *plibNewPosition)
  110. {
  111. HRESULT hresult = E_FAIL;
  112. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStream::Seek\n", this));
  113. if (_pStream)
  114. hresult = _pStream->Seek(dlibMove, dwOrigin, plibNewPosition);
  115. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStream::Seek\n", this));
  116. return(hresult);
  117. }
  118. HRESULT CStream::SetSize(THIS_ ULARGE_INTEGER libNewSize)
  119. {
  120. HRESULT hresult = E_FAIL;
  121. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStream::SetSize\n", this));
  122. if (_pStream)
  123. hresult = _pStream->SetSize(libNewSize);
  124. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStream::SetSize\n", this));
  125. return(hresult);
  126. }
  127. HRESULT CStream::CopyTo(THIS_ LPSTREAM pStm, ULARGE_INTEGER cb,
  128. ULARGE_INTEGER FAR *pcbRead, ULARGE_INTEGER FAR *pcbWritten)
  129. {
  130. HRESULT hresult = E_FAIL;
  131. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStream::CopyTo\n", this));
  132. if (_pStream)
  133. hresult = _pStream->CopyTo(pStm, cb, pcbRead, pcbWritten);
  134. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStream::CopyTo\n", this));
  135. return(hresult);
  136. }
  137. HRESULT CStream::Commit(THIS_ DWORD dwCommitFlags)
  138. {
  139. HRESULT hresult = E_FAIL;
  140. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStream::Commit\n", this));
  141. if (_pStream)
  142. hresult = _pStream->Commit(dwCommitFlags);
  143. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStream::Commit\n", this));
  144. return(hresult);
  145. }
  146. HRESULT CStream::Revert(THIS)
  147. {
  148. HRESULT hresult = E_FAIL;
  149. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStream::Revert\n", this));
  150. if (_pStream)
  151. hresult = _pStream->Revert();
  152. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStream::Revert\n", this));
  153. return(hresult);
  154. }
  155. HRESULT CStream::LockRegion(THIS_ ULARGE_INTEGER libOffset,
  156. ULARGE_INTEGER cb, DWORD dwLockType)
  157. {
  158. HRESULT hresult = E_FAIL;
  159. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStream::LockRegion\n", this));
  160. if (_pStream)
  161. hresult = _pStream->LockRegion(libOffset, cb, dwLockType);
  162. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStream::LockRegion\n", this));
  163. return(hresult);
  164. }
  165. HRESULT CStream::UnlockRegion(THIS_ ULARGE_INTEGER libOffset,
  166. ULARGE_INTEGER cb, DWORD dwLockType)
  167. {
  168. HRESULT hresult = E_FAIL;
  169. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStream::UnlockRegion\n", this));
  170. if (_pStream)
  171. hresult = _pStream->UnlockRegion(libOffset, cb, dwLockType);
  172. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStream::UnlockRegion\n", this));
  173. return(hresult);
  174. }
  175. HRESULT CStream::Stat(THIS_ STATSTG FAR *pStatStg, DWORD grfStatFlag)
  176. {
  177. HRESULT hresult = E_FAIL;
  178. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStream::Stat\n", this));
  179. if (_pStream)
  180. hresult = _pStream->Stat(pStatStg, grfStatFlag);
  181. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStream::Stat\n", this));
  182. return(hresult);
  183. }
  184. HRESULT CStream::Clone(THIS_ LPSTREAM FAR *ppStm)
  185. {
  186. HRESULT hresult = E_FAIL;
  187. IStream *pStr, *pStrTop;
  188. UrlMkDebugOut((DEB_ISTREAM, "%p IN CStream::Clone\n", this));
  189. *ppStm = NULL;
  190. if (_pStream)
  191. {
  192. hresult = _pStream->Clone(&pStr);
  193. if (hresult == S_OK)
  194. {
  195. if (!(pStrTop = new CStream(pStr)))
  196. {
  197. // BUGBUG: Delete pStr here!
  198. hresult = E_OUTOFMEMORY;
  199. goto CloneExit;
  200. }
  201. *ppStm = pStrTop;
  202. }
  203. }
  204. CloneExit:
  205. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CStream::Clone\n", this));
  206. return(hresult);
  207. }