Source code of Windows XP (NT5)
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.

287 lines
5.8 KiB

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