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.

319 lines
8.8 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. BindStatusCallback.h
  5. Abstract:
  6. This file contains the implementation of the CPAData class, which is
  7. used to specify a single problem area
  8. Revision History:
  9. Davide Massarenti (Dmassare) 07/05/99
  10. created
  11. ******************************************************************************/
  12. #include "stdafx.h"
  13. CHCPBindStatusCallback::CHCPBindStatusCallback()
  14. {
  15. __HCP_FUNC_ENTRY("CHCPBindStatusCallback::CHCPBindStatusCallback");
  16. m_pT = NULL;
  17. m_dwTotalRead = 0;
  18. m_dwAvailableToRead = 0;
  19. }
  20. CHCPBindStatusCallback::~CHCPBindStatusCallback()
  21. {
  22. __HCP_FUNC_ENTRY("CHCPBindStatusCallback::~CHCPBindStatusCallback");
  23. }
  24. /////////////////////////////////////////////////////////////////////////////
  25. STDMETHODIMP CHCPBindStatusCallback::OnStartBinding( DWORD dwReserved ,
  26. IBinding *pBinding )
  27. {
  28. __HCP_FUNC_ENTRY("CHCPBindStatusCallback::OnStartBinding");
  29. m_spBinding = pBinding;
  30. __HCP_FUNC_EXIT(S_OK);
  31. }
  32. STDMETHODIMP CHCPBindStatusCallback::GetPriority( LONG *pnPriority )
  33. {
  34. __HCP_FUNC_ENTRY("CHCPBindStatusCallback::GetPriority");
  35. HRESULT hr;
  36. __MPC_PARAMCHECK_BEGIN(hr)
  37. __MPC_PARAMCHECK_POINTER_AND_SET(pnPriority,THREAD_PRIORITY_NORMAL);
  38. __MPC_PARAMCHECK_END();
  39. hr = S_OK;
  40. __HCP_FUNC_CLEANUP;
  41. __HCP_FUNC_EXIT(hr);
  42. }
  43. STDMETHODIMP CHCPBindStatusCallback::OnLowResource( DWORD reserved )
  44. {
  45. __HCP_FUNC_ENTRY("CHCPBindStatusCallback::OnLowResource");
  46. __HCP_FUNC_EXIT(S_OK);
  47. }
  48. STDMETHODIMP CHCPBindStatusCallback::OnProgress( ULONG ulProgress ,
  49. ULONG ulProgressMax ,
  50. ULONG ulStatusCode ,
  51. LPCWSTR szStatusText )
  52. {
  53. __HCP_FUNC_ENTRY("CHCPBindStatusCallback::OnProgress");
  54. HRESULT hr = m_pT->OnProgress( ulProgress, ulProgressMax, ulStatusCode, szStatusText );
  55. __HCP_FUNC_EXIT(hr);
  56. }
  57. STDMETHODIMP CHCPBindStatusCallback::OnStopBinding( HRESULT hresult ,
  58. LPCWSTR szError )
  59. {
  60. __HCP_FUNC_ENTRY("CHCPBindStatusCallback::OnStopBinding");
  61. if(FAILED(hresult))
  62. {
  63. m_pT->OnBindingFailure( hresult, szError );
  64. }
  65. m_pT = NULL;
  66. m_spBinding.Release();
  67. m_spBindCtx.Release();
  68. m_spMoniker.Release();
  69. __HCP_FUNC_EXIT(S_OK);
  70. }
  71. STDMETHODIMP CHCPBindStatusCallback::GetBindInfo( DWORD *pgrfBINDF ,
  72. BINDINFO *pbindInfo )
  73. {
  74. __HCP_FUNC_ENTRY("CHCPBindStatusCallback::GetBindInfo");
  75. HRESULT hr;
  76. ULONG cbSize;
  77. if(pgrfBINDF == NULL ||
  78. pbindInfo == NULL ||
  79. pbindInfo->cbSize == 0 )
  80. {
  81. __MPC_SET_ERROR_AND_EXIT(hr, E_INVALIDARG);
  82. }
  83. cbSize = pbindInfo->cbSize; // remember incoming cbSize
  84. memset( pbindInfo, 0, cbSize ); // zero out structure
  85. pbindInfo->cbSize = cbSize; // restore cbSize
  86. *pgrfBINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE | BINDF_GETNEWESTVERSION | BINDF_NOWRITECACHE;
  87. hr = m_pT->GetBindInfo( pbindInfo );
  88. if(hr == S_FALSE)
  89. {
  90. pbindInfo->dwBindVerb = BINDVERB_GET; // set verb
  91. }
  92. __HCP_FUNC_CLEANUP;
  93. __HCP_FUNC_EXIT(hr);
  94. }
  95. STDMETHODIMP CHCPBindStatusCallback::OnDataAvailable( DWORD grfBSCF ,
  96. DWORD dwSize ,
  97. FORMATETC *pformatetc ,
  98. STGMEDIUM *pstgmed )
  99. {
  100. __HCP_FUNC_ENTRY("CHCPBindStatusCallback::OnDataAvailable");
  101. HRESULT hr;
  102. BYTE* pBytes = NULL;
  103. // Get the Stream passed
  104. if(grfBSCF & BSCF_FIRSTDATANOTIFICATION)
  105. {
  106. if(!m_spStream && pstgmed->tymed == TYMED_ISTREAM)
  107. {
  108. m_spStream = pstgmed->pstm;
  109. }
  110. }
  111. DWORD dwRead = dwSize - m_dwTotalRead; // Minimum amount available that hasn't been read
  112. DWORD dwActuallyRead = 0; // Placeholder for amount read during this pull
  113. // If there is some data to be read then go ahead and read them
  114. if(m_spStream)
  115. {
  116. if(dwRead > 0)
  117. {
  118. __MPC_EXIT_IF_ALLOC_FAILS(hr, pBytes, new BYTE[dwRead]);
  119. __MPC_EXIT_IF_METHOD_FAILS(hr, m_spStream->Read( pBytes, dwRead, &dwActuallyRead ));
  120. if(dwActuallyRead > 0)
  121. {
  122. m_pT->OnData( this, pBytes, dwActuallyRead, grfBSCF, pformatetc , pstgmed );
  123. m_dwTotalRead += dwActuallyRead;
  124. }
  125. }
  126. }
  127. if(grfBSCF & BSCF_LASTDATANOTIFICATION)
  128. {
  129. m_spStream.Release();
  130. }
  131. hr = S_OK;
  132. __HCP_FUNC_CLEANUP;
  133. delete[] pBytes;
  134. __HCP_FUNC_EXIT(hr);
  135. }
  136. STDMETHODIMP CHCPBindStatusCallback::OnObjectAvailable( REFIID riid ,
  137. IUnknown *punk )
  138. {
  139. __HCP_FUNC_ENTRY("CHCPBindStatusCallback::OnObjectAvailable");
  140. __HCP_FUNC_EXIT(S_OK);
  141. }
  142. /////////////////////////////////////////////////////////////////////////////
  143. STDMETHODIMP CHCPBindStatusCallback::BeginningTransaction( LPCWSTR szURL ,
  144. LPCWSTR szHeaders ,
  145. DWORD dwReserved ,
  146. LPWSTR *pszAdditionalHeaders )
  147. {
  148. HRESULT hr = E_NOTIMPL;
  149. if(m_pT)
  150. {
  151. CComPtr<IHttpNegotiate> pIHttpNegotiate;
  152. if(SUCCEEDED(hr = m_pT->ForwardQueryInterface( IID_IHttpNegotiate, (void **)&pIHttpNegotiate )))
  153. {
  154. hr = pIHttpNegotiate->BeginningTransaction( szURL ,
  155. szHeaders ,
  156. dwReserved ,
  157. pszAdditionalHeaders );
  158. }
  159. }
  160. return hr;
  161. }
  162. STDMETHODIMP CHCPBindStatusCallback::OnResponse( DWORD dwResponseCode ,
  163. LPCWSTR szResponseHeaders ,
  164. LPCWSTR szRequestHeaders ,
  165. LPWSTR *pszAdditionalRequestHeaders )
  166. {
  167. HRESULT hr = E_NOTIMPL;
  168. if(m_pT)
  169. {
  170. CComPtr<IHttpNegotiate> pIHttpNegotiate;
  171. if(SUCCEEDED(hr = m_pT->ForwardQueryInterface( IID_IHttpNegotiate, (void **)&pIHttpNegotiate )))
  172. {
  173. hr = pIHttpNegotiate->OnResponse( dwResponseCode ,
  174. szResponseHeaders ,
  175. szRequestHeaders ,
  176. pszAdditionalRequestHeaders );
  177. }
  178. }
  179. return hr;
  180. }
  181. /////////////////////////////////////////////////////////////////////////////
  182. HRESULT CHCPBindStatusCallback::StartAsyncDownload( ISimpleBindStatusCallback* pT ,
  183. BSTR bstrURL ,
  184. IUnknown* pUnkContainer ,
  185. BOOL bRelative )
  186. {
  187. __HCP_FUNC_ENTRY("CHCPBindStatusCallback::StartAsyncDownload");
  188. HRESULT hr = S_OK;
  189. CComQIPtr<IServiceProvider> spServiceProvider( pUnkContainer );
  190. CComPtr<IBindHost> spBindHost;
  191. CComPtr<IStream> spStream;
  192. m_pT = pT;
  193. m_dwTotalRead = 0;
  194. m_dwAvailableToRead = 0;
  195. if(spServiceProvider)
  196. {
  197. spServiceProvider->QueryService( SID_IBindHost, IID_IBindHost, (void**)&spBindHost );
  198. }
  199. __MPC_EXIT_IF_METHOD_FAILS(hr, ::CreateBindCtx( 0, &m_spBindCtx ));
  200. __MPC_EXIT_IF_METHOD_FAILS(hr, ::RegisterBindStatusCallback( m_spBindCtx, static_cast<IBindStatusCallback*>(this), 0, 0L ));
  201. if(bRelative)
  202. {
  203. if(spBindHost == NULL)
  204. {
  205. __MPC_SET_ERROR_AND_EXIT(hr, E_NOINTERFACE); // relative asked for, but no IBindHost
  206. }
  207. __MPC_EXIT_IF_METHOD_FAILS(hr, spBindHost->CreateMoniker( bstrURL, m_spBindCtx, &m_spMoniker, 0 ));
  208. }
  209. else
  210. {
  211. __MPC_EXIT_IF_METHOD_FAILS(hr, ::CreateURLMoniker( NULL, bstrURL, &m_spMoniker ));
  212. }
  213. __MPC_EXIT_IF_METHOD_FAILS(hr, m_pT->PreBindMoniker( m_spBindCtx, m_spMoniker ));
  214. if(spBindHost == NULL)
  215. {
  216. __MPC_EXIT_IF_METHOD_FAILS(hr, m_spMoniker->BindToStorage( m_spBindCtx, 0, IID_IStream, (void**)&spStream ));
  217. }
  218. else
  219. {
  220. __MPC_EXIT_IF_METHOD_FAILS(hr, spBindHost->MonikerBindToStorage(m_spMoniker, m_spBindCtx, this, IID_IStream, (void**)&spStream));
  221. }
  222. hr = S_OK;
  223. __HCP_FUNC_CLEANUP;
  224. __HCP_FUNC_EXIT(hr);
  225. }
  226. HRESULT CHCPBindStatusCallback::Abort()
  227. {
  228. __HCP_FUNC_ENTRY("CHCPBindStatusCallback::Abort");
  229. if(m_spBinding)
  230. {
  231. m_spBinding->Abort();
  232. }
  233. __HCP_FUNC_EXIT(S_OK);
  234. }