Leaked source code of windows server 2003

511 lines
14 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: ROSTMDIR.CXX
  7. //
  8. // Contents:
  9. //
  10. // Classes: Implements the CReadOnlyStreamDirect class.
  11. //
  12. // Functions:
  13. //
  14. // History: 12-21-95 JoeS (Joe Souza) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <urlint.h>
  18. #ifndef unix
  19. #include "..\trans\transact.hxx"
  20. #else
  21. #include "../trans/transact.hxx"
  22. #endif /* unix */
  23. #include "rostmdir.hxx"
  24. CReadOnlyStreamDirect::CReadOnlyStreamDirect(CTransData *pCTransData, DWORD grfBindF, BOOL fFile) : _CRefs()
  25. {
  26. DEBUG_ENTER((DBG_STORAGE,
  27. None,
  28. "CReadOnlyStreamDirect::CReadOnlyStreamDirect",
  29. "this=%#x, %#x, %#x",
  30. this, pCTransData, grfBindF
  31. ));
  32. UrlMkDebugOut((DEB_ISTREAM, "%p IN CReadOnlyStreamDirect::CReadOnlyStreamDirect (pCTransData:%p)\n", NULL,pCTransData));
  33. _pCTransData = pCTransData;
  34. _grfBindF = grfBindF;
  35. _fFile = fFile;
  36. if (_pCTransData)
  37. {
  38. _pCTransData->AddRef();
  39. }
  40. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CReadOnlyStreamDirect::CReadOnlyStreamDirect \n", this));
  41. DEBUG_LEAVE(0);
  42. }
  43. CReadOnlyStreamDirect::~CReadOnlyStreamDirect()
  44. {
  45. DEBUG_ENTER((DBG_STORAGE,
  46. None,
  47. "CReadOnlyStreamDirect::~CReadOnlyStreamDirect",
  48. "this=%#x",
  49. this
  50. ));
  51. UrlMkDebugOut((DEB_ISTREAM, "%p IN/OUT CReadOnlyStreamDirect::~CReadOnlyStreamDirect\n", this));
  52. if (_pCTransData)
  53. {
  54. _pCTransData->Release();
  55. }
  56. DEBUG_LEAVE(0);
  57. }
  58. //+---------------------------------------------------------------------------
  59. //
  60. // Method: CReadOnlyStreamDirect::GetFileName
  61. //
  62. // Synopsis:
  63. //
  64. // Arguments: (none)
  65. //
  66. // Returns:
  67. //
  68. // History: 7-22-96 JohannP (Johann Posch) Created
  69. //
  70. // Notes:
  71. //
  72. //----------------------------------------------------------------------------
  73. LPWSTR CReadOnlyStreamDirect::GetFileName()
  74. {
  75. DEBUG_ENTER((DBG_STORAGE,
  76. String,
  77. "CReadOnlyStreamDirect::GetFileName",
  78. "this=%#x",
  79. this
  80. ));
  81. UrlMkDebugOut((DEB_ISTREAM, "%p IN CReadOnlyStreamDirect::GetFileName\n", this));
  82. LPWSTR pwzFilename = NULL;
  83. LPWSTR pwzDupname = NULL;
  84. if (_pCTransData)
  85. {
  86. pwzFilename = _pCTransData->GetFileName();
  87. }
  88. if (pwzFilename)
  89. {
  90. pwzDupname = OLESTRDuplicate(pwzFilename);
  91. }
  92. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CReadOnlyStreamDirect::GetFileName (Filename:%ws)\n", this, pwzDupname));
  93. DEBUG_LEAVE(pwzDupname);
  94. return pwzDupname;
  95. }
  96. STDMETHODIMP CReadOnlyStreamDirect::QueryInterface
  97. (REFIID riid, LPVOID FAR* ppvObj)
  98. {
  99. DEBUG_ENTER((DBG_STORAGE,
  100. Hresult,
  101. "CReadOnlyStreamDirect::IUnknown::QueryInterface",
  102. "this=%#x, %#x, %#x",
  103. this, &riid, ppvObj
  104. ));
  105. VDATETHIS(this);
  106. UrlMkDebugOut((DEB_ISTREAM, "%p IN CReadOnlyStreamDirect::QueryInterface\n", this));
  107. HRESULT hresult = NOERROR;
  108. if ( IsEqualIID(riid, IID_IUnknown)
  109. || IsEqualIID(riid, IID_IStream)
  110. )
  111. {
  112. *ppvObj = this;
  113. AddRef();
  114. }
  115. else if (_fFile
  116. && IsEqualIID(riid, IID_IWinInetFileStream))
  117. {
  118. *ppvObj = (void *)(IWinInetFileStream *)this;
  119. AddRef();
  120. }
  121. else
  122. {
  123. *ppvObj = NULL;
  124. hresult = E_NOINTERFACE;
  125. }
  126. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CReadOnlyStreamDirect::QueryInterface\n", this));
  127. DEBUG_LEAVE(hresult);
  128. return hresult;
  129. }
  130. STDMETHODIMP_(ULONG) CReadOnlyStreamDirect::AddRef(void)
  131. {
  132. DEBUG_ENTER((DBG_STORAGE,
  133. Dword,
  134. "CReadOnlyStreamDirect::IUnknown::AddRef",
  135. "this=%#x",
  136. this
  137. ));
  138. GEN_VDATEPTRIN(this,ULONG,0L);
  139. UrlMkDebugOut((DEB_ISTREAM, "%p IN CReadOnlyStreamDirect::AddRef\n", this));
  140. LONG lRet = ++_CRefs;
  141. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CReadOnlyStreamDirect::::AddRef (%ld)\n", this, lRet));
  142. DEBUG_LEAVE(lRet);
  143. return lRet;
  144. }
  145. STDMETHODIMP_(ULONG) CReadOnlyStreamDirect::Release(void)
  146. {
  147. DEBUG_ENTER((DBG_STORAGE,
  148. Dword,
  149. "CReadOnlyStreamDirect::IUnknown::Release",
  150. "this=%#x",
  151. this
  152. ));
  153. GEN_VDATEPTRIN(this,ULONG,0L);
  154. UrlMkDebugOut((DEB_ISTREAM, "%p IN CReadOnlyStreamDirect::Release\n", this));
  155. UrlMkAssert((_CRefs > 0));
  156. LONG lRet = --_CRefs;
  157. if (_CRefs == 0)
  158. {
  159. delete this;
  160. }
  161. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CReadOnlyStreamDirect::Release (%ld)\n", this, lRet));
  162. DEBUG_LEAVE(lRet);
  163. return lRet;
  164. }
  165. HRESULT CReadOnlyStreamDirect::Read(THIS_ VOID HUGEP *pv, ULONG cb, ULONG FAR *pcbRead)
  166. {
  167. DEBUG_ENTER((DBG_STORAGE,
  168. Hresult,
  169. "CReadOnlyStreamDirect::IStream::Read",
  170. "this=%#x, %#x, %#x, %#x",
  171. this, pv, cb, pcbRead
  172. ));
  173. HRESULT hresult = NOERROR;
  174. DWORD dwRead = 0;
  175. UrlMkDebugOut((DEB_ISTREAM, "%p IN CReadOnlyStreamDirect::Read\n", this));
  176. if( _pCTransData )
  177. {
  178. hresult = _pCTransData->ReadHere((LPBYTE) pv, cb, &dwRead);
  179. if( hresult != S_OK && hresult != E_PENDING )
  180. {
  181. // break connection with CTransData
  182. CTransData *pCTD = _pCTransData;
  183. _pCTransData = 0;
  184. pCTD->Release();
  185. }
  186. }
  187. else
  188. {
  189. hresult = S_FALSE;
  190. dwRead = 0;
  191. }
  192. if (pcbRead)
  193. {
  194. *pcbRead = dwRead;
  195. }
  196. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CReadOnlyStreamDirect::Read\n", this));
  197. DEBUG_LEAVE(hresult);
  198. return(hresult);
  199. }
  200. HRESULT CReadOnlyStreamDirect::Write(THIS_ VOID const HUGEP *pv, ULONG cb,
  201. ULONG FAR *pcbWritten)
  202. {
  203. DEBUG_ENTER((DBG_STORAGE,
  204. Hresult,
  205. "CReadOnlyStreamDirect::IStream::Write",
  206. "this=%#x, %#x, %#x, %#x",
  207. this, pv, cb, pcbWritten
  208. ));
  209. UrlMkDebugOut((DEB_ISTREAM, "%p CReadOnlyStreamDirect::Write (NoOp)\n", this));
  210. DEBUG_LEAVE(STG_E_ACCESSDENIED);
  211. return(STG_E_ACCESSDENIED);
  212. }
  213. HRESULT CReadOnlyStreamDirect::Seek(THIS_ LARGE_INTEGER dlibMove, DWORD dwOrigin,
  214. ULARGE_INTEGER FAR *plibNewPosition)
  215. {
  216. DEBUG_ENTER((DBG_STORAGE,
  217. Hresult,
  218. "CReadOnlyStreamDirect::IStream::Seek",
  219. "this=%#x, %#x, %#x, %#x",
  220. this, dlibMove, dwOrigin, plibNewPosition
  221. ));
  222. HRESULT hresult = NOERROR;
  223. UrlMkDebugOut((DEB_ISTREAM, "%p CReadOnlyStreamDirect::Seek (NoOp)\n", this));
  224. // This is a true stream, and thus seeking is not possible.
  225. if( _pCTransData )
  226. {
  227. hresult = _pCTransData->Seek(dlibMove, dwOrigin, plibNewPosition);
  228. }
  229. else
  230. {
  231. hresult = S_FALSE;
  232. }
  233. DEBUG_LEAVE(hresult);
  234. return hresult;
  235. }
  236. HRESULT CReadOnlyStreamDirect::SetSize(THIS_ ULARGE_INTEGER libNewSize)
  237. {
  238. DEBUG_ENTER((DBG_STORAGE,
  239. Hresult,
  240. "CReadOnlyStreamDirect::IStream::SetSize",
  241. "this=%#x, %#x",
  242. this, libNewSize
  243. ));
  244. UrlMkDebugOut((DEB_ISTREAM, "%p CReadOnlyStreamDirect::SetSize (NoOp)\n", this));
  245. // BUGBUG: Should we just return S_OK here?
  246. DEBUG_LEAVE(E_FAIL);
  247. return(E_FAIL);
  248. }
  249. HRESULT CReadOnlyStreamDirect::CopyTo(THIS_ LPSTREAM pStm, ULARGE_INTEGER cb,
  250. ULARGE_INTEGER FAR *pcbRead, ULARGE_INTEGER FAR *pcbWritten)
  251. {
  252. DEBUG_ENTER((DBG_STORAGE,
  253. Hresult,
  254. "CReadOnlyStreamDirect::IStream::CopyTo",
  255. "this=%#x, %#x, %#x, %#x, %#x",
  256. this, pStm, cb, pcbRead, pcbWritten
  257. ));
  258. HRESULT hresult = STG_E_INSUFFICIENTMEMORY;
  259. LPVOID memptr = NULL;
  260. DWORD readcount, writecount;
  261. UrlMkDebugOut((DEB_ISTREAM, "%p IN CReadOnlyStreamDirect::CopyTo\n", this));
  262. if (cb.HighPart || (pStm == NULL))
  263. {
  264. hresult = E_INVALIDARG;
  265. goto CopyToExit;
  266. }
  267. // do not need to copy to ourself
  268. if (pStm == this)
  269. {
  270. hresult = NOERROR;
  271. goto CopyToExit;
  272. }
  273. memptr = new BYTE [cb.LowPart];
  274. if (memptr)
  275. {
  276. hresult = Read((LPBYTE) memptr, cb.LowPart, &readcount);
  277. if (hresult)
  278. {
  279. goto CopyToExit;
  280. }
  281. if (pcbRead)
  282. {
  283. pcbRead->HighPart = 0;
  284. pcbRead->LowPart = readcount;
  285. }
  286. hresult = pStm->Write(memptr, readcount, &writecount);
  287. if (pcbWritten && !hresult)
  288. {
  289. pcbWritten->HighPart = 0;
  290. pcbWritten->LowPart = writecount;
  291. }
  292. }
  293. CopyToExit:
  294. if (memptr)
  295. {
  296. delete memptr;
  297. }
  298. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CReadOnlyStreamDirect::CopyTo\n", this));
  299. DEBUG_LEAVE(hresult);
  300. return(hresult);
  301. }
  302. HRESULT CReadOnlyStreamDirect::Commit(THIS_ DWORD dwCommitFlags)
  303. {
  304. DEBUG_ENTER((DBG_STORAGE,
  305. Hresult,
  306. "CReadOnlyStreamDirect::IStream::Commit",
  307. "this=%#x, %#x",
  308. this, dwCommitFlags
  309. ));
  310. UrlMkDebugOut((DEB_ISTREAM, "%p CReadOnlyStreamDirect::Commit (NoOp)\n", this));
  311. // This is a read-only stream, so nothing to commit.
  312. DEBUG_LEAVE(E_NOTIMPL);
  313. return(E_NOTIMPL);
  314. }
  315. HRESULT CReadOnlyStreamDirect::Revert(THIS)
  316. {
  317. DEBUG_ENTER((DBG_STORAGE,
  318. Hresult,
  319. "CReadOnlyStreamDirect::IStream::Revert",
  320. "this=%#x",
  321. this
  322. ));
  323. UrlMkDebugOut((DEB_ISTREAM, "%p CReadOnlyStreamDirect::Revert (NoOp)\n", this));
  324. DEBUG_LEAVE(E_NOTIMPL);
  325. return(E_NOTIMPL);
  326. }
  327. HRESULT CReadOnlyStreamDirect::LockRegion(THIS_ ULARGE_INTEGER libOffset,
  328. ULARGE_INTEGER cb, DWORD dwLockType)
  329. {
  330. DEBUG_ENTER((DBG_STORAGE,
  331. Hresult,
  332. "CReadOnlyStreamDirect::IStream::LockRegion",
  333. "this=%#x, %#x, %#x, %#x",
  334. this, libOffset, cb, dwLockType
  335. ));
  336. UrlMkDebugOut((DEB_ISTREAM, "%p CReadOnlyStreamDirect::LockRegion (NoOp)\n", this));
  337. DEBUG_LEAVE(E_NOTIMPL);
  338. return(E_NOTIMPL);
  339. }
  340. HRESULT CReadOnlyStreamDirect::UnlockRegion(THIS_ ULARGE_INTEGER libOffset,
  341. ULARGE_INTEGER cb, DWORD dwLockType)
  342. {
  343. DEBUG_ENTER((DBG_STORAGE,
  344. Hresult,
  345. "CReadOnlyStreamDirect::IStream::UnlockRegion",
  346. "this=%#x, %#x, %#x, %#x",
  347. this, libOffset, cb, dwLockType
  348. ));
  349. UrlMkDebugOut((DEB_ISTREAM, "%p CReadOnlyStreamDirect::UnlockRegion (NoOp)\n", this));
  350. DEBUG_LEAVE(E_NOTIMPL);
  351. return(E_NOTIMPL);
  352. }
  353. HRESULT CReadOnlyStreamDirect::Stat(THIS_ STATSTG FAR *pStatStg, DWORD grfStatFlag)
  354. {
  355. DEBUG_ENTER((DBG_STORAGE,
  356. Hresult,
  357. "CReadOnlyStreamDirect::IStream::Stat",
  358. "this=%#x, %#x, %#x",
  359. this, pStatStg, grfStatFlag
  360. ));
  361. HRESULT hresult = E_FAIL;
  362. UrlMkDebugOut((DEB_ISTREAM, "%p IN CReadOnlyStreamDirect::Stat\n", this));
  363. if (pStatStg)
  364. {
  365. memset(pStatStg, 0, sizeof(STATSTG));
  366. pStatStg->type = STGTY_STREAM;
  367. pStatStg->clsid = IID_IStream;
  368. pStatStg->pwcsName = GetFileName();
  369. hresult = NOERROR;
  370. }
  371. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CReadOnlyStreamDirect::Stat\n", this));
  372. DEBUG_LEAVE(hresult);
  373. return(hresult);
  374. }
  375. HRESULT CReadOnlyStreamDirect::Clone(THIS_ LPSTREAM FAR *ppStm)
  376. {
  377. DEBUG_ENTER((DBG_STORAGE,
  378. Hresult,
  379. "CReadOnlyStreamDirect::IStream::Clone",
  380. "this=%#x, %#x",
  381. this, ppStm
  382. ));
  383. HRESULT hresult = NOERROR;
  384. UrlMkDebugOut((DEB_ISTREAM, "%p IN CReadOnlyStreamDirect::Clone\n", this));
  385. if (!(*ppStm = new CReadOnlyStreamDirect(_pCTransData, _grfBindF)))
  386. hresult = E_OUTOFMEMORY;
  387. UrlMkDebugOut((DEB_ISTREAM, "%p OUT CReadOnlyStreamDirect::Clone\n", this));
  388. DEBUG_LEAVE(hresult);
  389. return(hresult);
  390. }
  391. HRESULT CReadOnlyStreamDirect::SetHandleForUnlock(THIS_ DWORD_PTR hWinInetLockHandle, DWORD_PTR dwReserved)
  392. {
  393. DEBUG_ENTER((DBG_STORAGE,
  394. Hresult,
  395. "CReadOnlyStreamDirect::IWinInetFileStream::SetHandleForUnlock",
  396. "this=%#x, handle=%#x",
  397. this, hWinInetLockHandle
  398. ));
  399. DEBUG_LEAVE(E_NOTIMPL);
  400. return E_NOTIMPL;
  401. }
  402. HRESULT CReadOnlyStreamDirect::SetDeleteFile(THIS_ DWORD_PTR dwReserved)
  403. {
  404. DEBUG_ENTER((DBG_STORAGE,
  405. Hresult,
  406. "CReadOnlyStreamDirect::IWinInetFileStream::SetDeleteFile",
  407. "this=%#x",
  408. this
  409. ));
  410. DEBUG_LEAVE(E_NOTIMPL);
  411. return E_NOTIMPL;
  412. }