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.

282 lines
6.0 KiB

  1. #include "private.h"
  2. #include "cdlabsc.h"
  3. CDLAgentBSC::CDLAgentBSC(CCDLAgent *pCdlAgent, DWORD dwMaxSizeKB, BOOL fSilentOperation,
  4. LPWSTR szCDFUrl)
  5. {
  6. m_cRef = 1;
  7. m_pIBinding = NULL;
  8. m_pCdlAgent = pCdlAgent;
  9. m_fSilentOperation = fSilentOperation;
  10. m_dwMaxSize = dwMaxSizeKB*1024;
  11. m_pSecMgr = NULL;
  12. StrCpyNW(m_pwzCDFBase, szCDFUrl, ARRAYSIZE(m_pwzCDFBase));
  13. if (m_pCdlAgent != NULL)
  14. {
  15. m_pCdlAgent->AddRef();
  16. }
  17. }
  18. CDLAgentBSC::~CDLAgentBSC()
  19. {
  20. if (m_pCdlAgent != NULL)
  21. {
  22. m_pCdlAgent->Release();
  23. }
  24. if (m_pIBinding != NULL)
  25. {
  26. m_pIBinding->Release();
  27. }
  28. if (m_pSecMgr) {
  29. m_pSecMgr->Release();
  30. }
  31. }
  32. HRESULT CDLAgentBSC::Abort()
  33. {
  34. if (m_pIBinding != NULL) {
  35. return m_pIBinding->Abort();
  36. } else {
  37. return S_OK;
  38. }
  39. }
  40. /*
  41. *
  42. * IUnknown Methods
  43. *
  44. */
  45. STDMETHODIMP CDLAgentBSC::QueryInterface(REFIID riid, void **ppv)
  46. {
  47. HRESULT hr = E_NOINTERFACE;
  48. *ppv = NULL;
  49. if (riid == IID_IUnknown || riid == IID_IBindStatusCallback)
  50. {
  51. *ppv = (IBindStatusCallback *)this;
  52. }
  53. else if (riid == IID_IServiceProvider)
  54. {
  55. *ppv = (IServiceProvider *) this;
  56. AddRef();
  57. }
  58. if (*ppv != NULL)
  59. {
  60. ((IUnknown *)*ppv)->AddRef();
  61. hr = S_OK;
  62. }
  63. return hr;
  64. }
  65. STDMETHODIMP CDLAgentBSC::QueryService(REFGUID rsid, REFIID riid, void ** ppvObj)
  66. {
  67. HRESULT hr = NOERROR;
  68. IServiceProvider *pIServiceProvider = NULL;
  69. if (!ppvObj)
  70. return E_INVALIDARG;
  71. *ppvObj = 0;
  72. if (IsEqualGUID(rsid, IID_IInternetHostSecurityManager) &&
  73. IsEqualGUID(riid, IID_IInternetHostSecurityManager)) {
  74. if (m_pSecMgr == NULL) {
  75. hr = CoInternetCreateSecurityManager(NULL, &m_pSecMgr, NULL);
  76. }
  77. if (m_pSecMgr) {
  78. *ppvObj = (IInternetHostSecurityManager *)this;
  79. AddRef();
  80. }
  81. else {
  82. hr = E_NOINTERFACE;
  83. }
  84. }
  85. else {
  86. hr = E_NOINTERFACE;
  87. *ppvObj = NULL;
  88. }
  89. return hr;
  90. }
  91. STDMETHODIMP_(ULONG) CDLAgentBSC::AddRef()
  92. {
  93. return ++m_cRef;
  94. }
  95. STDMETHODIMP_(ULONG) CDLAgentBSC::Release()
  96. {
  97. if (0L != --m_cRef)
  98. {
  99. return m_cRef;
  100. }
  101. delete this;
  102. return 0;
  103. }
  104. /*
  105. *
  106. * IBindStatusCallback Methods
  107. *
  108. */
  109. STDMETHODIMP CDLAgentBSC::OnStartBinding(DWORD grfBSCOption, IBinding *pib)
  110. {
  111. if (m_pIBinding != NULL)
  112. {
  113. m_pIBinding->Release();
  114. }
  115. m_pIBinding = pib;
  116. if (m_pIBinding != NULL)
  117. {
  118. m_pIBinding->AddRef();
  119. }
  120. return S_OK;
  121. }
  122. STDMETHODIMP CDLAgentBSC::OnStopBinding(HRESULT hresult, LPCWSTR szError)
  123. {
  124. HRESULT hr = S_OK;
  125. if (m_pCdlAgent != NULL)
  126. {
  127. m_pCdlAgent->SetErrorEndText(szError);
  128. m_pCdlAgent->SetEndStatus(hresult);
  129. m_pCdlAgent->CleanUp();
  130. }
  131. return hr;
  132. }
  133. STDMETHODIMP CDLAgentBSC::OnObjectAvailable(REFIID riid, IUnknown *punk)
  134. {
  135. return S_OK;
  136. }
  137. STDMETHODIMP CDLAgentBSC::GetPriority(LONG *pnPriority)
  138. {
  139. return S_OK;
  140. }
  141. STDMETHODIMP CDLAgentBSC::OnLowResource(DWORD dwReserved)
  142. {
  143. return S_OK;
  144. }
  145. STDMETHODIMP CDLAgentBSC::OnProgress(ULONG ulProgress, ULONG ulProgressMax,
  146. ULONG ulStatusCode,
  147. LPCWSTR szStatusText)
  148. {
  149. if ((m_dwMaxSize > 0) && (ulStatusCode == BINDSTATUS_DOWNLOADINGDATA)) {
  150. if (ulProgress > m_dwMaxSize || ulProgressMax > m_dwMaxSize) {
  151. Abort();
  152. }
  153. }
  154. return S_OK;
  155. }
  156. STDMETHODIMP CDLAgentBSC::GetBindInfo(DWORD *pgrfBINDF, BINDINFO *pbindInfo)
  157. {
  158. if (m_fSilentOperation)
  159. {
  160. *pgrfBINDF |= BINDF_SILENTOPERATION;
  161. }
  162. return S_OK;
  163. }
  164. STDMETHODIMP CDLAgentBSC::OnDataAvailable(DWORD grfBSCF, DWORD dwSize,
  165. FORMATETC *pformatetc,
  166. STGMEDIUM *pstgmed)
  167. {
  168. return S_OK;
  169. }
  170. HRESULT CDLAgentBSC::Pause()
  171. {
  172. HRESULT hr = E_FAIL;
  173. if (m_pIBinding != NULL)
  174. {
  175. hr = m_pIBinding->Suspend();
  176. }
  177. return hr;
  178. }
  179. HRESULT CDLAgentBSC::Resume()
  180. {
  181. HRESULT hr = E_FAIL;
  182. if (m_pIBinding != NULL)
  183. {
  184. hr = m_pIBinding->Resume();
  185. }
  186. return hr;
  187. }
  188. // IInternetHostSecurityManager
  189. STDMETHODIMP CDLAgentBSC::GetSecurityId(BYTE *pbSecurityId, DWORD *pcbSecurityId,
  190. DWORD_PTR dwReserved)
  191. {
  192. HRESULT hr = E_FAIL;
  193. if (m_pSecMgr) {
  194. hr = m_pSecMgr->GetSecurityId(m_pwzCDFBase, pbSecurityId,
  195. pcbSecurityId, dwReserved);
  196. }
  197. return hr;
  198. }
  199. STDMETHODIMP CDLAgentBSC::ProcessUrlAction(DWORD dwAction, BYTE *pPolicy, DWORD cbPolicy,
  200. BYTE *pContext, DWORD cbContext, DWORD dwFlags,
  201. DWORD dwReserved)
  202. {
  203. HRESULT hr = E_FAIL;
  204. if (m_pSecMgr) {
  205. hr = m_pSecMgr->ProcessUrlAction(m_pwzCDFBase, dwAction, pPolicy,
  206. cbPolicy, pContext, cbContext,
  207. dwFlags, dwReserved);
  208. }
  209. return hr;
  210. }
  211. STDMETHODIMP CDLAgentBSC::QueryCustomPolicy(REFGUID guidKey, BYTE **ppPolicy,
  212. DWORD *pcbPolicy, BYTE *pContext,
  213. DWORD cbContext, DWORD dwReserved)
  214. {
  215. HRESULT hr = E_FAIL;
  216. if (m_pSecMgr) {
  217. hr = m_pSecMgr->QueryCustomPolicy(m_pwzCDFBase, guidKey, ppPolicy,
  218. pcbPolicy, pContext, cbContext,
  219. dwReserved);
  220. }
  221. return hr;
  222. }