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.

192 lines
5.7 KiB

  1. // --------------------------------------------------------------------------------
  2. // Inetprot.cpp
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // Steven J. Bailey
  5. // --------------------------------------------------------------------------------
  6. #include "pch.hxx"
  7. #include "inetprot.h"
  8. #include "icdebug.h"
  9. // --------------------------------------------------------------------------------
  10. // HrPluggableProtocolRead
  11. // --------------------------------------------------------------------------------
  12. HRESULT HrPluggableProtocolRead(
  13. /* in,out */ LPPROTOCOLSOURCE pSource,
  14. /* in,out */ LPVOID pv,
  15. /* in */ ULONG cb,
  16. /* out */ ULONG *pcbRead)
  17. {
  18. // Locals
  19. HRESULT hr=S_OK;
  20. ULONG cbRead;
  21. // Invalid Arg
  22. if (NULL == pv && cbRead > 0)
  23. return TrapError(E_INVALIDARG);
  24. // Init
  25. if (pcbRead)
  26. *pcbRead = 0;
  27. // No Stream Yet
  28. Assert(pSource);
  29. if (NULL == pSource->pLockBytes)
  30. {
  31. hr = TrapError(E_FAIL);
  32. goto exit;
  33. }
  34. // Read from the external offset
  35. CHECKHR(hr = pSource->pLockBytes->ReadAt(pSource->offExternal, pv, cb, &cbRead));
  36. // Tracking
  37. #ifdef MAC
  38. DOUTL(APP_DOUTL, "HrPluggableProtocolRead - Offset = %d, cbWanted = %d, cbRead = %d, fDownloaded = %d", (DWORD)pSource->offExternal.LowPart, cb, cbRead, ISFLAGSET(pSource->dwFlags, INETPROT_DOWNLOADED));
  39. // Increment External Offset
  40. Assert(0 == pSource->offExternal.HighPart);
  41. Assert(INT_MAX - cbRead >= pSource->offExternal.LowPart);
  42. pSource->offExternal.LowPart += cbRead;
  43. #else // !MAC
  44. DOUTL(APP_DOUTL, "HrPluggableProtocolRead - Offset = %d, cbWanted = %d, cbRead = %d, fDownloaded = %d", (DWORD)pSource->offExternal.QuadPart, cb, cbRead, ISFLAGSET(pSource->dwFlags, INETPROT_DOWNLOADED));
  45. // Increment External Offset
  46. pSource->offExternal.QuadPart += cbRead;
  47. #endif // MAC
  48. // Return Read Count
  49. if (pcbRead)
  50. *pcbRead = cbRead;
  51. // No Data Read
  52. if (0 == cbRead)
  53. {
  54. // Finished
  55. if (ISFLAGSET(pSource->dwFlags, INETPROT_DOWNLOADED))
  56. hr = S_FALSE;
  57. // Not all data could be read
  58. else
  59. hr = E_PENDING;
  60. }
  61. exit:
  62. // Done
  63. return hr;
  64. }
  65. // --------------------------------------------------------------------------------
  66. // HrPluggableProtocolSeek
  67. // --------------------------------------------------------------------------------
  68. HRESULT HrPluggableProtocolSeek(
  69. /* in,out */ LPPROTOCOLSOURCE pSource,
  70. /* in */ LARGE_INTEGER dlibMove,
  71. /* in */ DWORD dwOrigin,
  72. /* out */ ULARGE_INTEGER *plibNew)
  73. {
  74. // Locals
  75. HRESULT hr=S_OK;
  76. ULARGE_INTEGER uliNew;
  77. // Invalid Arg
  78. Assert(pSource);
  79. // Tracking
  80. DOUTL(APP_DOUTL, "HrPluggableProtocolSeek");
  81. // No Stream Yet
  82. if (NULL == pSource->pLockBytes)
  83. {
  84. hr = TrapError(E_FAIL);
  85. goto exit;
  86. }
  87. // Seek pSource->offExternal
  88. switch (dwOrigin)
  89. {
  90. case STREAM_SEEK_SET:
  91. #ifdef MAC
  92. Assert(0 == dlibMove.HighPart);
  93. ULISet32(uliNew, dlibMove.LowPart);
  94. #else // !MAC
  95. uliNew.QuadPart = (DWORDLONG)dlibMove.QuadPart;
  96. #endif // MAC
  97. break;
  98. case STREAM_SEEK_CUR:
  99. #ifdef MAC
  100. if (dlibMove.LowPart < 0)
  101. {
  102. if ((DWORDLONG)(0 - dlibMove.LowPart) > pSource->offExternal.LowPart)
  103. {
  104. hr = TrapError(E_FAIL);
  105. goto exit;
  106. }
  107. }
  108. Assert(0 == pSource->offExternal.HighPart);
  109. uliNew = pSource->offExternal;
  110. Assert(INT_MAX - uliNew.LowPart >= dlibMove.LowPart);
  111. uliNew.LowPart += dlibMove.LowPart;
  112. #else // !MAC
  113. if (dlibMove.QuadPart < 0)
  114. {
  115. if ((DWORDLONG)(0 - dlibMove.QuadPart) > pSource->offExternal.QuadPart)
  116. {
  117. hr = TrapError(E_FAIL);
  118. goto exit;
  119. }
  120. }
  121. uliNew.QuadPart = pSource->offExternal.QuadPart + dlibMove.QuadPart;
  122. #endif // MAC
  123. break;
  124. case STREAM_SEEK_END:
  125. #ifdef MAC
  126. if (dlibMove.LowPart < 0 || dlibMove.LowPart > pSource->offInternal.LowPart)
  127. {
  128. hr = TrapError(E_FAIL);
  129. goto exit;
  130. }
  131. Assert(0 == pSource->cbSize.HighPart);
  132. uliNew = pSource->cbSize;
  133. Assert(INT_MAX - uliNew.LowPart >= dlibMove.LowPart);
  134. uliNew.LowPart -= dlibMove.LowPart;
  135. #else // !MAC
  136. if (dlibMove.QuadPart < 0 || (DWORDLONG)dlibMove.QuadPart > pSource->offInternal.QuadPart)
  137. {
  138. hr = TrapError(E_FAIL);
  139. goto exit;
  140. }
  141. uliNew.QuadPart = pSource->cbSize.QuadPart - dlibMove.QuadPart;
  142. #endif // MAC
  143. break;
  144. default:
  145. hr = TrapError(STG_E_INVALIDFUNCTION);
  146. goto exit;
  147. }
  148. // New offset greater than size...
  149. #ifdef MAC
  150. Assert(0 == pSource->offInternal.HighPart);
  151. Assert(0 == uliNew.HighPart);
  152. ULISet32(pSource->offExternal, min(uliNew.LowPart, pSource->offInternal.LowPart));
  153. // Return Position
  154. if (plibNew)
  155. {
  156. Assert(0 == pSource->offExternal.HighPart);
  157. LISet32(*plibNew, pSource->offExternal.LowPart);
  158. }
  159. #else // !MAC
  160. pSource->offExternal.QuadPart = min(uliNew.QuadPart, pSource->offInternal.QuadPart);
  161. // Return Position
  162. if (plibNew)
  163. plibNew->QuadPart = (LONGLONG)pSource->offExternal.QuadPart;
  164. #endif // MAC
  165. exit:
  166. // Done
  167. return hr;
  168. }