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.

465 lines
12 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: cbinding.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 11-11-95 JohannP (Johann Posch) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <trans.h>
  18. PerfDbgTag(tagCBSC, "Urlmon", "Log CBSC", DEB_BINDING);
  19. CBSC::CBSC(Medium medium)
  20. {
  21. DEBUG_ENTER((DBG_TRANS,
  22. None,
  23. "CBSC::CBSC",
  24. "this=%#x, %#x",
  25. this, medium
  26. ));
  27. PerfDbgLog(tagCBSC, this, "+CBSC::CBSC");
  28. _cRef = 1;
  29. _pBdg = NULL;
  30. _fBindToObject = (medium == Medium_Unknown) ? TRUE : FALSE;
  31. _fGotStopBinding = FALSE;
  32. _Medium = medium;
  33. _pStm = NULL;
  34. _pStg = NULL;
  35. _pUnk = NULL;
  36. _hrResult = NOERROR;
  37. PerfDbgLog(tagCBSC, this, "-CBSC::CBSC");
  38. DEBUG_LEAVE(0);
  39. }
  40. CBSC::~CBSC()
  41. {
  42. DEBUG_ENTER((DBG_TRANS,
  43. None,
  44. "CBSC::~CBSC",
  45. "this=%#x",
  46. this
  47. ));
  48. PerfDbgLog(tagCBSC, this, "+CBSC::~CBSC");
  49. if (_pStm)
  50. {
  51. _pStm->Release();
  52. }
  53. if (_pUnk)
  54. {
  55. _pUnk->Release();
  56. }
  57. PerfDbgLog(tagCBSC, this, "-CBSC::~CBSC");
  58. DEBUG_LEAVE(0);
  59. }
  60. HRESULT CBSC::GetRequestedObject(IBindCtx *pbc, void **ppvObj)
  61. {
  62. DEBUG_ENTER((DBG_TRANS,
  63. Hresult,
  64. "CBSC::GetRequestedObject",
  65. "this=%#x, %#x, %#x",
  66. this, pbc, ppvObj
  67. ));
  68. HRESULT hr = NOERROR;
  69. PerfDbgLog1(tagCBSC, this, "+CBSC::GetRequestedObject (_wzPath:%ws)", _wzPath);
  70. if (_Medium == Medium_Stream)
  71. {
  72. *ppvObj = _pStm;
  73. //TransAssert((_pStm));
  74. if (_pStm)
  75. {
  76. _pStm->AddRef();
  77. }
  78. else if (_hrResult != NOERROR)
  79. {
  80. hr = _hrResult;
  81. }
  82. else
  83. {
  84. hr = E_FAIL;
  85. }
  86. }
  87. else if (_Medium == Medium_Storage)
  88. {
  89. BIND_OPTS bindopts;
  90. bindopts.cbStruct = sizeof(BIND_OPTS);
  91. hr = pbc->GetBindOptions(&bindopts);
  92. if (hr == NOERROR)
  93. {
  94. hr = StgOpenStorage(_wzPath, NULL, bindopts.grfMode, NULL, 0, (LPSTORAGE FAR*)ppvObj );
  95. if (hr != NOERROR)
  96. {
  97. hr = StgOpenStorage(_wzPath, NULL, STGM_READWRITE | STGM_SHARE_DENY_NONE, NULL, 0, (LPSTORAGE FAR*)ppvObj );
  98. }
  99. if (hr != NOERROR)
  100. {
  101. hr = StgOpenStorage(_wzPath, NULL, STGM_READ | STGM_SHARE_DENY_WRITE, NULL, 0, (LPSTORAGE FAR*)ppvObj );
  102. }
  103. }
  104. }
  105. else if (_Medium == Medium_Unknown)
  106. {
  107. *ppvObj = _pUnk;
  108. TransAssert((_pUnk));
  109. if (_pUnk)
  110. {
  111. _pUnk->AddRef();
  112. }
  113. else
  114. {
  115. hr = E_FAIL;
  116. }
  117. }
  118. PerfDbgLog1(tagCBSC, this, "-CBSC::GetRequestedObject hr:%lx", hr);
  119. DEBUG_LEAVE(hr);
  120. return hr;
  121. }
  122. STDMETHODIMP CBSC::QueryInterface(REFIID riid, void **ppvObj)
  123. {
  124. DEBUG_ENTER((DBG_TRANS,
  125. Hresult,
  126. "CBSC::IUnknown::QueryInterface",
  127. "this=%#x, %#x, %#x",
  128. this, &riid, ppvObj
  129. ));
  130. HRESULT hr = NOERROR;
  131. PerfDbgLog(tagCBSC, this, "+CBSC::QueryInterface");
  132. if ( IsEqualIID(riid, IID_IBindStatusCallback)
  133. || IsEqualIID(riid, IID_IUnknown))
  134. {
  135. _cRef++; // A pointer to this object is returned
  136. *ppvObj = (void *)(IBindStatusCallback *)this;
  137. }
  138. else
  139. {
  140. *ppvObj = NULL;
  141. hr = E_NOINTERFACE;
  142. }
  143. PerfDbgLog1(tagCBSC, this, "-CBSC::QueryInterface hr:%lx", hr);
  144. DEBUG_LEAVE(hr);
  145. return hr;
  146. }
  147. STDMETHODIMP_(ULONG) CBSC::AddRef(void)
  148. {
  149. DEBUG_ENTER((DBG_TRANS,
  150. Dword,
  151. "CBSC::IUnknown::AddRef",
  152. "this=%#x",
  153. this
  154. ));
  155. ULONG cRef = ++_cRef;
  156. PerfDbgLog1(tagCBSC, this, "CBSC::AddRef (cRef:%ld)", cRef);
  157. DEBUG_LEAVE(cRef);
  158. return cRef;
  159. }
  160. STDMETHODIMP_(ULONG) CBSC::Release(void)
  161. {
  162. DEBUG_ENTER((DBG_TRANS,
  163. Dword,
  164. "CBSC::IUnknown::Release",
  165. "this=%#x",
  166. this
  167. ));
  168. ULONG cRef = 0;
  169. PerfDbgLog(tagCBSC, this, "+CBSC::Release");
  170. cRef = --_cRef;
  171. if (cRef == 0)
  172. {
  173. delete this;
  174. }
  175. PerfDbgLog1(tagCBSC, this, "-CBSC::Release cref:%ld", cRef);
  176. DEBUG_LEAVE(cRef);
  177. return cRef;
  178. }
  179. STDMETHODIMP CBSC::GetBindInfo(
  180. /* [out] */ DWORD *grfBINDINFOF,
  181. /* [out] */ BINDINFO *pbindinfo)
  182. {
  183. DEBUG_ENTER((DBG_TRANS,
  184. Hresult,
  185. "CBSC::IBindStatusCallback::GetBindInfo",
  186. "this=%#x, %#x, %#x",
  187. this, grfBINDINFOF, pbindinfo
  188. ));
  189. HRESULT hr = NOERROR;
  190. PerfDbgLog(tagCBSC, this, "+CBSC::GetBindInfo");
  191. if ( (grfBINDINFOF == NULL)
  192. || (pbindinfo == NULL)
  193. || (pbindinfo->cbSize == 0)
  194. )
  195. {
  196. DEBUG_LEAVE(E_INVALIDARG);
  197. return E_INVALIDARG;
  198. }
  199. // Nuke BINDINFO preserving cbSize;
  200. DWORD cbSize = pbindinfo->cbSize;
  201. memset(pbindinfo, 0, cbSize);
  202. pbindinfo->cbSize = cbSize;
  203. if (_Medium == Medium_Storage)
  204. {
  205. *grfBINDINFOF = 0;
  206. }
  207. else
  208. {
  209. *grfBINDINFOF = 0;
  210. *grfBINDINFOF |= BINDF_ASYNCSTORAGE;
  211. *grfBINDINFOF |= BINDF_PULLDATA;
  212. *grfBINDINFOF |= BINDF_NEEDFILE;
  213. }
  214. PerfDbgLog1(tagCBSC, this, "-CBSC::GetBindInfo hr:%lx", hr);
  215. DEBUG_LEAVE(hr);
  216. return hr;
  217. }
  218. STDMETHODIMP CBSC::OnStartBinding(DWORD grfBINDINFOF, IBinding *pib)
  219. {
  220. DEBUG_ENTER((DBG_TRANS,
  221. Hresult,
  222. "CBSC::IBindStatusCallback::OnStartBinding",
  223. "this=%#x, %#x, %#x",
  224. this, grfBINDINFOF, pib
  225. ));
  226. HRESULT hr = NOERROR;
  227. PerfDbgLog(tagCBSC, this, "+CBSC::OnStartBinding");
  228. if (pib)
  229. {
  230. _pBdg = pib;
  231. _pBdg->AddRef();
  232. }
  233. PerfDbgLog1(tagCBSC, this, "-CBSC::OnStartBinding hr:%lx", hr);
  234. DEBUG_LEAVE(hr);
  235. return hr;
  236. }
  237. STDMETHODIMP CBSC::GetPriority(
  238. /* [out] */ LONG *pnPriority)
  239. {
  240. DEBUG_ENTER((DBG_TRANS,
  241. Hresult,
  242. "CBSC::IBindStatusCallback::GetPriority",
  243. "this=%#x, %#x",
  244. this, pnPriority
  245. ));
  246. HRESULT hr = NOERROR;
  247. PerfDbgLog(tagCBSC, this, "+CBSC::GetPriority");
  248. if (pnPriority == NULL)
  249. {
  250. hr = E_INVALIDARG;
  251. }
  252. else
  253. {
  254. *pnPriority = THREAD_PRIORITY_NORMAL;
  255. }
  256. PerfDbgLog1(tagCBSC, this, "-CBSC::GetPriority hr:%lx", hr);
  257. DEBUG_LEAVE(hr);
  258. return hr;
  259. }
  260. STDMETHODIMP CBSC::OnProgress(
  261. /* [in] */ ULONG ulProgress,
  262. /* [in] */ ULONG ulProgressMax,
  263. /* [in] */ ULONG ulStatusCode,
  264. /* [in] */ LPCWSTR szStatusText)
  265. {
  266. DEBUG_ENTER((DBG_TRANS,
  267. Hresult,
  268. "CBSC::IBindStatusCallback::OnProgress",
  269. "this=%#x, %#x, %#x, %#x, %.80wq",
  270. this, ulProgress, ulProgressMax, ulStatusCode, szStatusText
  271. ));
  272. HRESULT hr = NOERROR;
  273. PerfDbgLog4(tagCBSC, this, "+CBSC::OnProgress (StatusCode:%ld/%lx, Progress:%ld ProgressMax:%ld))",
  274. ulStatusCode, ulStatusCode, ulProgress, ulProgressMax);
  275. PerfDbgLog1(tagCBSC, this, "-CBSC::OnProgress hr:%lx", hr);
  276. DEBUG_LEAVE(hr);
  277. return hr;
  278. }
  279. STDMETHODIMP CBSC::OnDataAvailable(
  280. /* [in] */ DWORD grfBSC,
  281. /* [in] */ DWORD dwSize,
  282. /* [in] */ FORMATETC *pFmtetc,
  283. /* [in] */ STGMEDIUM *pstgmed)
  284. {
  285. DEBUG_ENTER((DBG_TRANS,
  286. Hresult,
  287. "CBSC::IBindStatusCallback::OnDataAvailable",
  288. "this=%#x, %#x, %#x, %#x, %#x",
  289. this, grfBSC, dwSize, pFmtetc, pstgmed
  290. ));
  291. HRESULT hr = NOERROR;
  292. HRESULT hr1 = NOERROR;
  293. PerfDbgLog(tagCBSC, this, "+CBSC::OnDataAvailable");
  294. UrlMkAssert((dwSize > 0));
  295. UrlMkAssert((pFmtetc != NULL && pstgmed != NULL));
  296. // if this is the first notification then make sure that the proper formatetc
  297. // is passed in.
  298. if (grfBSC & BSCF_FIRSTDATANOTIFICATION)
  299. {
  300. if (pFmtetc->tymed & TYMED_ISTREAM ||
  301. pstgmed->tymed == TYMED_ISTREAM )
  302. {
  303. STATSTG statstg;
  304. PerfDbgLog1(tagCBSC, this, "CBSC::OnDataAvailable - received IStream %lx", pstgmed->pstm);
  305. _pStm = pstgmed->pstm;
  306. _pStm->AddRef();
  307. if (pstgmed->pUnkForRelease)
  308. {
  309. _pUnk = pstgmed->pUnkForRelease;
  310. _pUnk->AddRef();
  311. }
  312. }
  313. }
  314. if (grfBSC & BSCF_LASTDATANOTIFICATION)
  315. {
  316. // if this is the final notification then get the data and display it
  317. if (_pStm)
  318. {
  319. UrlMkAssert((pFmtetc->tymed & TYMED_ISTREAM));
  320. //_pStm->Release();
  321. //_pStm = 0;
  322. }
  323. // if this is the final notification then get the data and display it
  324. if (pFmtetc->tymed & TYMED_FILE)
  325. {
  326. PerfDbgLog1(tagCBSC, this, "CBSC::OnDataAvailable - received File:%ws", pstgmed->lpszFileName);
  327. wcscpy(_wzPath, pstgmed->lpszFileName);
  328. }
  329. UrlMkAssert((_wzPath ));
  330. }
  331. PerfDbgLog1(tagCBSC, this, "-CBSC::OnDataAvailable hr:%lx", hr);
  332. DEBUG_LEAVE(hr);
  333. return hr;
  334. }
  335. STDMETHODIMP CBSC::OnLowResource(
  336. /* [in] */ DWORD reserved)
  337. {
  338. DEBUG_ENTER((DBG_TRANS,
  339. Hresult,
  340. "CBSC::IBindStatusCallback::OnLowResource",
  341. "this=%#x, %#x",
  342. this, reserved
  343. ));
  344. HRESULT hr = NOERROR;
  345. PerfDbgLog(tagCBSC, this, "+CBSC::OnLowResource");
  346. PerfDbgLog1(tagCBSC, this, "-CBSC::OnLowResource hr:%lx", hr);
  347. DEBUG_LEAVE(hr);
  348. return hr;
  349. }
  350. STDMETHODIMP CBSC::OnStopBinding(HRESULT hresult, LPCWSTR szError)
  351. {
  352. DEBUG_ENTER((DBG_TRANS,
  353. Hresult,
  354. "CBSC::IBindStatusCallback::OnStopBinding",
  355. "this=%#x, %#x, %.80wq",
  356. this, hresult, szError
  357. ));
  358. HRESULT hr = NOERROR;
  359. PerfDbgLog1(tagCBSC, this, "+CBSC::OnStopBinding (hresult:%lx)", hresult);
  360. _fGotStopBinding = TRUE;
  361. _hrResult = hresult;
  362. if (_pBdg)
  363. {
  364. _pBdg->Release();
  365. _pBdg = NULL;
  366. }
  367. PerfDbgLog2(tagCBSC, this, "-CBSC::OnStopBinding (hresult:%lx) hr:%lx", hresult, hr);
  368. DEBUG_LEAVE(hr);
  369. return hr;
  370. }
  371. STDMETHODIMP CBSC::OnObjectAvailable(REFIID riid, IUnknown *punk)
  372. {
  373. DEBUG_ENTER((DBG_TRANS,
  374. Hresult,
  375. "CBSC::IBindStatusCallback::OnObjectAvailable",
  376. "this=%#x, %#x, %#x",
  377. this, &riid, punk
  378. ));
  379. HRESULT hr = NOERROR;
  380. PerfDbgLog(tagCBSC, this, "+CBSC::OnObjectAvailable");
  381. UrlMkAssert((_Medium == Medium_Unknown));
  382. UrlMkAssert((punk));
  383. punk->AddRef();
  384. _pUnk = punk;
  385. PerfDbgLog1(tagCBSC, this, "-CBSC::OnObjectAvailable hr:%lx", hr);
  386. DEBUG_LEAVE(hr);
  387. return hr;
  388. }