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.

253 lines
7.2 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Copyright (C) Microsoft Corporation, 1998
  4. //
  5. // Module: rwstream.cpp
  6. //
  7. // Description: Contains implementation of the read only / write only
  8. // mailmsg property stream in epoxy shared memory.
  9. //
  10. // 10/20/98 - MaheshJ Created
  11. // 8/17/99 - MikeSwa Modified to use files instead of shared memory
  12. //----------------------------------------------------------------------------
  13. #include "aqprecmp.h"
  14. #include "propstrm.h"
  15. // Constructor.
  16. CFilePropertyStream::CFilePropertyStream()
  17. {
  18. TraceFunctEnter("CFilePropertyStream::CFilePropertyStream");
  19. m_dwSignature = FILE_PROPERTY_STREAM;
  20. m_hDestFile = NULL;
  21. TraceFunctLeave();
  22. }
  23. // Destructor.
  24. CFilePropertyStream::~CFilePropertyStream()
  25. {
  26. TraceFunctEnter("CFilePropertyStream::~CFilePropertyStream");
  27. _ASSERT(FILE_PROPERTY_STREAM == m_dwSignature);
  28. m_dwSignature = FILE_PROPERTY_STREAM_FREE;
  29. if (m_hDestFile && (INVALID_HANDLE_VALUE != m_hDestFile))
  30. _VERIFY(CloseHandle(m_hDestFile));
  31. TraceFunctLeave();
  32. }
  33. //---[ CFilePropertyStream::HrInitialize ]-------------------------------------
  34. //
  35. //
  36. // Description:
  37. // Creates a file for the property stream
  38. // Parameters:
  39. // szFileName Name of file to create for the property stream
  40. // Returns:
  41. // S_OK on success
  42. // NT error from Create File
  43. // History:
  44. // 8/17/99 - MikeSwa Created
  45. //
  46. //-----------------------------------------------------------------------------
  47. HRESULT CFilePropertyStream::HrInitialize(LPSTR szFileName)
  48. {
  49. TraceFunctEnterEx((LPARAM) this, "CFilePropertyStream::HrInitialize");
  50. HRESULT hr = S_OK;
  51. m_hDestFile = CreateFile(szFileName,
  52. GENERIC_WRITE,
  53. 0,
  54. NULL,
  55. CREATE_ALWAYS,
  56. FILE_FLAG_SEQUENTIAL_SCAN,
  57. NULL);
  58. if (INVALID_HANDLE_VALUE == m_hDestFile)
  59. {
  60. hr = HRESULT_FROM_WIN32(GetLastError());
  61. ErrorTrace((LPARAM) this,
  62. "Unable to create badmail reason file - err 0x%08X - file %s",
  63. hr, szFileName);
  64. if (SUCCEEDED(hr))
  65. hr = E_FAIL;
  66. }
  67. TraceFunctLeave();
  68. return hr;
  69. }
  70. //---[ CFilePropertyStream::QueryInterface ]-----------------------------------------
  71. //
  72. //
  73. // Description:
  74. // QueryInterface for CFilePropertyStream that supports:
  75. // - IMailMsgPropertyStream
  76. // Parameters:
  77. //
  78. // Returns:
  79. //
  80. // History:
  81. // 8/17/99 - MikeSwa Created
  82. //
  83. //-----------------------------------------------------------------------------
  84. STDMETHODIMP CFilePropertyStream::QueryInterface(REFIID riid, LPVOID *ppvObj)
  85. {
  86. HRESULT hr = S_OK;
  87. if (!ppvObj)
  88. {
  89. hr = E_POINTER;
  90. goto Exit;
  91. }
  92. if (IID_IUnknown == riid)
  93. {
  94. *ppvObj = static_cast<IMailMsgPropertyStream *>(this);
  95. }
  96. else if (IID_IMailMsgPropertyStream == riid)
  97. {
  98. *ppvObj = static_cast<IMailMsgPropertyStream *>(this);
  99. }
  100. else
  101. {
  102. *ppvObj = NULL;
  103. hr = E_NOINTERFACE;
  104. goto Exit;
  105. }
  106. static_cast<IUnknown *>(*ppvObj)->AddRef();
  107. Exit:
  108. return hr;
  109. }
  110. // Property stream methods.
  111. // Start a write transaction.
  112. HRESULT STDMETHODCALLTYPE
  113. CFilePropertyStream::StartWriteBlocks(IN IMailMsgProperties *pMsg,
  114. IN DWORD dwBlocksToWrite,
  115. IN DWORD dwTotalBytesToWrite)
  116. {
  117. HRESULT hr = S_OK;
  118. TraceFunctEnter("CFilePropertyStream::StartWriteBlocks");
  119. // Should be writing something.
  120. _ASSERT(dwBlocksToWrite > 0);
  121. _ASSERT(dwTotalBytesToWrite > 0);
  122. //We actually don't case, since we will just dump this to a file
  123. TraceFunctLeave();
  124. return(hr);
  125. }
  126. // End a write transaction.
  127. HRESULT STDMETHODCALLTYPE
  128. CFilePropertyStream::EndWriteBlocks(IN IMailMsgProperties *pMsg)
  129. {
  130. TraceFunctEnter("CFilePropertyStream::EndWriteBlocks");
  131. HRESULT hr = S_OK;
  132. TraceFunctLeave();
  133. return(hr);
  134. }
  135. // Cancel a write transaction.
  136. HRESULT STDMETHODCALLTYPE
  137. CFilePropertyStream::CancelWriteBlocks(IN IMailMsgProperties *pMsg)
  138. {
  139. TraceFunctEnter("CFilePropertyStream::CancelWriteBlocks");
  140. HRESULT hr = S_OK;
  141. TraceFunctLeave();
  142. return(hr);
  143. }
  144. // Get the size of the stream.
  145. HRESULT STDMETHODCALLTYPE
  146. CFilePropertyStream::GetSize(IN IMailMsgProperties *pMsg,
  147. IN DWORD * pdwSize,
  148. IN IMailMsgNotify * pNotify)
  149. {
  150. TraceFunctEnter("CFilePropertyStream::GetSize");
  151. HRESULT hr = E_NOTIMPL;
  152. TraceFunctLeave();
  153. return(hr);
  154. }
  155. // Read blocks from the stream.
  156. HRESULT STDMETHODCALLTYPE
  157. CFilePropertyStream::ReadBlocks(IN IMailMsgProperties *pMsg,
  158. IN DWORD dwCount,
  159. IN DWORD *pdwOffset,
  160. IN DWORD *pdwLength,
  161. IN BYTE **ppbBlock,
  162. IN IMailMsgNotify *pNotify)
  163. {
  164. TraceFunctEnter("CFilePropertyStream::ReadBlocks");
  165. HRESULT hr = E_NOTIMPL;
  166. ErrorTrace((LPARAM) this, "ReadBlocks call on CFilePropertyStream!");
  167. TraceFunctLeave();
  168. return(hr);
  169. }
  170. // Write blocks to the stream.
  171. HRESULT STDMETHODCALLTYPE
  172. CFilePropertyStream::WriteBlocks(IN IMailMsgProperties *pMsg,
  173. IN DWORD dwCount,
  174. IN DWORD *pdwOffset,
  175. IN DWORD *pdwLength,
  176. IN BYTE **ppbBlock,
  177. IN IMailMsgNotify *pNotify)
  178. {
  179. TraceFunctEnter("CFilePropertyStream::WriteBlocks");
  180. HRESULT hr = S_OK;
  181. DWORD irgCount = 0;
  182. DWORD cbWritten = 0;
  183. OVERLAPPED ov;
  184. ZeroMemory(&ov, sizeof(OVERLAPPED));
  185. if ((0 == dwCount)||
  186. (NULL == pdwOffset)||
  187. (NULL == pdwLength)||
  188. (NULL == ppbBlock))
  189. {
  190. hr = E_INVALIDARG;
  191. DebugTrace((LPARAM)this,
  192. "WriteBlocks failed with hr : 0x%x",
  193. hr);
  194. goto Exit;
  195. }
  196. if (!m_hDestFile)
  197. {
  198. ErrorTrace((LPARAM) this,
  199. "WriteBlocks called with no file handle");
  200. hr = E_FAIL;
  201. _ASSERT(0 && "WriteBlocks called with no file handle");
  202. goto Exit;
  203. }
  204. for (irgCount = 0; irgCount < dwCount; irgCount++)
  205. {
  206. ov.Offset = pdwOffset[irgCount];
  207. cbWritten = 0;
  208. if (!WriteFile(m_hDestFile, ppbBlock[irgCount], pdwLength[irgCount],
  209. &cbWritten, &ov))
  210. {
  211. hr = HRESULT_FROM_WIN32(GetLastError());
  212. ErrorTrace((LPARAM)this,
  213. "WriteFile of blob %d failed with hr : 0x%08X",
  214. irgCount, hr);
  215. goto Exit;
  216. }
  217. }
  218. Exit:
  219. TraceFunctLeave();
  220. return(hr);
  221. }