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.

1212 lines
32 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: protbase.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 11-07-1996 JohannP (Johann Posch) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <eapp.h>
  18. //+---------------------------------------------------------------------------
  19. //
  20. // Method: CBaseProtocol::QueryInterface
  21. //
  22. // Synopsis:
  23. //
  24. // Arguments: [riid] --
  25. // [ppvObj] --
  26. //
  27. // Returns:
  28. //
  29. // History: 10-29-1996 JohannP (Johann Posch) Created
  30. //
  31. // Notes:
  32. //
  33. //----------------------------------------------------------------------------
  34. STDMETHODIMP CBaseProtocol::QueryInterface(REFIID riid, void **ppvObj)
  35. {
  36. VDATEPTROUT(ppvObj, void *);
  37. VDATETHIS(this);
  38. HRESULT hr = NOERROR;
  39. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::QueryInterface\n", this));
  40. hr = _pUnkOuter->QueryInterface(riid, ppvObj);
  41. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::QueryInterface (hr:%lx\n", this,hr));
  42. return hr;
  43. }
  44. //+---------------------------------------------------------------------------
  45. //
  46. // Function: CBaseProtocol::AddRef
  47. //
  48. // Synopsis:
  49. //
  50. // Arguments: [ULONG] --
  51. //
  52. // Returns:
  53. //
  54. // History: 10-29-1996 JohannP (Johann Posch) Created
  55. //
  56. // Notes:
  57. //
  58. //----------------------------------------------------------------------------
  59. STDMETHODIMP_(ULONG) CBaseProtocol::AddRef(void)
  60. {
  61. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::AddRef\n", this));
  62. LONG lRet = _pUnkOuter->AddRef();
  63. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::AddRef (cRefs:%ld)\n", this,lRet));
  64. return lRet;
  65. }
  66. //+---------------------------------------------------------------------------
  67. //
  68. // Function: CBaseProtocol::Release
  69. //
  70. // Synopsis:
  71. //
  72. // Arguments: [ULONG] --
  73. //
  74. // Returns:
  75. //
  76. // History: 10-29-1996 JohannP (Johann Posch) Created
  77. //
  78. // Notes:
  79. //
  80. //----------------------------------------------------------------------------
  81. STDMETHODIMP_(ULONG) CBaseProtocol::Release(void)
  82. {
  83. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::Release\n", this));
  84. LONG lRet = _pUnkOuter->Release();
  85. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::Release (cRefs:%ld)\n",this,lRet));
  86. return lRet;
  87. }
  88. //+---------------------------------------------------------------------------
  89. //
  90. // Method: CBaseProtocol::Start
  91. //
  92. // Synopsis:
  93. //
  94. // Arguments: [pwzUrl] --
  95. // [pTrans] --
  96. // [pOIBindInfo] --
  97. // [grfSTI] --
  98. // [dwReserved] --
  99. //
  100. // Returns:
  101. //
  102. // History: 10-29-1996 JohannP (Johann Posch) Created
  103. //
  104. // Notes:
  105. //
  106. //----------------------------------------------------------------------------
  107. STDMETHODIMP CBaseProtocol::Start(LPCWSTR pwzUrl, IOInetProtocolSink *pTrans, IOInetBindInfo *pOIBindInfo,
  108. DWORD grfSTI, DWORD_PTR dwReserved)
  109. {
  110. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::Start\n", this));
  111. HRESULT hr = NOERROR;
  112. EProtAssert((!_pProtSink && pOIBindInfo && pTrans));
  113. EProtAssert((_pwzUrl == NULL));
  114. if ( !(grfSTI & PI_PARSE_URL))
  115. {
  116. _pProtSink = pTrans;
  117. _pProtSink->AddRef();
  118. _pOIBindInfo = pOIBindInfo;
  119. _pOIBindInfo->AddRef();
  120. }
  121. _BndInfo.cbSize = sizeof(BINDINFO);
  122. hr = pOIBindInfo->GetBindInfo(&_grfBindF, &_BndInfo);
  123. // Do we need to append the extra data to the url?
  124. if (_BndInfo.szExtraInfo)
  125. {
  126. // append extra info at the end of the url
  127. // Make sure we don't overflow the URL
  128. if (wcslen(_BndInfo.szExtraInfo) + wcslen(pwzUrl) >= MAX_URL_SIZE)
  129. {
  130. hr = E_INVALIDARG;
  131. goto End;
  132. }
  133. wcscpy(_wzFullURL, pwzUrl);
  134. // Append the extra data to the url. Note that we have already
  135. // checked for overflow, so we need not worry about it here.
  136. wcscat(_wzFullURL + wcslen(_wzFullURL), _BndInfo.szExtraInfo);
  137. }
  138. else
  139. {
  140. // Make sure we don't overflow the URL
  141. if (wcslen(pwzUrl) + 1 > MAX_URL_SIZE)
  142. {
  143. hr = E_INVALIDARG;
  144. goto End;
  145. }
  146. wcscpy(_wzFullURL, pwzUrl);
  147. }
  148. if ( !(grfSTI & PI_PARSE_URL))
  149. {
  150. // save the URL
  151. _pwzUrl = OLESTRDuplicate((LPCWSTR)pwzUrl);
  152. }
  153. _grfSTI = grfSTI;
  154. End:
  155. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::Start (hr:%lx)\n",this, hr));
  156. return hr;
  157. }
  158. //+---------------------------------------------------------------------------
  159. //
  160. // Method: CBaseProtocol::Continue
  161. //
  162. // Synopsis:
  163. //
  164. // Arguments: [pStateInfoIn] --
  165. //
  166. // Returns:
  167. //
  168. // History: 10-29-1996 JohannP (Johann Posch) Created
  169. //
  170. // Notes:
  171. //
  172. //----------------------------------------------------------------------------
  173. STDMETHODIMP CBaseProtocol::Continue(PROTOCOLDATA *pStateInfoIn)
  174. {
  175. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::Continue\n", this));
  176. HRESULT hr = E_FAIL;
  177. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::Continue (hr:%lx)\n",this, hr));
  178. return hr;
  179. }
  180. //+---------------------------------------------------------------------------
  181. //
  182. // Method: CBaseProtocol::Abort
  183. //
  184. // Synopsis:
  185. //
  186. // Arguments: [hrReason] --
  187. // [dwOptions] --
  188. //
  189. // Returns:
  190. //
  191. // History: 11-09-1996 JohannP (Johann Posch) Created
  192. //
  193. // Notes:
  194. //
  195. //----------------------------------------------------------------------------
  196. STDMETHODIMP CBaseProtocol::Abort(HRESULT hrReason, DWORD dwOptions)
  197. {
  198. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::Abort\n", this));
  199. HRESULT hr = NOERROR;
  200. EProtAssert((_pProtSink));
  201. hr = _pProtSink->ReportResult(E_ABORT, 0, 0);
  202. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::Abort (hr:%lx)\n",this, hr));
  203. return hr;
  204. }
  205. //+---------------------------------------------------------------------------
  206. //
  207. // Method: CBaseProtocol::Terminate
  208. //
  209. // Synopsis:
  210. //
  211. // Arguments: [dwOptions] --
  212. //
  213. // Returns:
  214. //
  215. // History: 10-29-1996 JohannP (Johann Posch) Created
  216. //
  217. // Notes:
  218. //
  219. //----------------------------------------------------------------------------
  220. STDMETHODIMP CBaseProtocol::Terminate(DWORD dwOptions)
  221. {
  222. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::Terminate\n", this));
  223. HRESULT hr = NOERROR;
  224. EProtAssert((_pProtSink));
  225. if (_pProt)
  226. {
  227. _pProt->Terminate(dwOptions);
  228. _pProt->Release();
  229. _pProt = NULL;
  230. }
  231. if (_pOIBindInfo)
  232. {
  233. _pOIBindInfo->Release();
  234. _pOIBindInfo = NULL;
  235. }
  236. if (_pProtSink)
  237. {
  238. _pProtSink->Release();
  239. _pProtSink = NULL;
  240. }
  241. #if DBG == 1
  242. if ( _BndInfo.stgmedData.tymed != TYMED_NULL )
  243. EProtDebugOut((DEB_PLUGPROT, "%p --- CBaseProtocol::Terminate ReleaseStgMedium (%p)\n", this,_BndInfo.stgmedData));
  244. #endif
  245. ReleaseBindInfo(&_BndInfo);
  246. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::Terminate (hr:%lx)\n",this, hr));
  247. return hr;
  248. }
  249. //+---------------------------------------------------------------------------
  250. //
  251. // Method: CBaseProtocol::Suspend
  252. //
  253. // Synopsis:
  254. //
  255. // Arguments: (none)
  256. //
  257. // Returns:
  258. //
  259. // History: 10-29-1996 JohannP (Johann Posch) Created
  260. //
  261. // Notes:
  262. //
  263. //----------------------------------------------------------------------------
  264. STDMETHODIMP CBaseProtocol::Suspend()
  265. {
  266. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::Suspend\n", this));
  267. HRESULT hr = E_NOTIMPL;
  268. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::Suspend (hr:%lx)\n",this, hr));
  269. return hr;
  270. }
  271. //+---------------------------------------------------------------------------
  272. //
  273. // Method: CBaseProtocol::Resume
  274. //
  275. // Synopsis:
  276. //
  277. // Arguments: (none)
  278. //
  279. // Returns:
  280. //
  281. // History: 10-29-1996 JohannP (Johann Posch) Created
  282. //
  283. // Notes:
  284. //
  285. //----------------------------------------------------------------------------
  286. STDMETHODIMP CBaseProtocol::Resume()
  287. {
  288. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::Resume\n", this));
  289. HRESULT hr = E_NOTIMPL;
  290. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::Resume (hr:%lx)\n",this, hr));
  291. return hr;
  292. }
  293. //+---------------------------------------------------------------------------
  294. //
  295. // Method: CBaseProtocol::SetPriority
  296. //
  297. // Synopsis:
  298. //
  299. // Arguments: [nPriority] --
  300. //
  301. // Returns:
  302. //
  303. // History: 10-29-1996 JohannP (Johann Posch) Created
  304. //
  305. // Notes:
  306. //
  307. //----------------------------------------------------------------------------
  308. STDMETHODIMP CBaseProtocol::SetPriority(LONG nPriority)
  309. {
  310. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::SetPriority\n", this));
  311. HRESULT hr = E_NOTIMPL;
  312. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::SetPriority (hr:%lx)\n",this, hr));
  313. return hr;
  314. }
  315. //+---------------------------------------------------------------------------
  316. //
  317. // Method: CBaseProtocol::GetPriority
  318. //
  319. // Synopsis:
  320. //
  321. // Arguments: [pnPriority] --
  322. //
  323. // Returns:
  324. //
  325. // History: 10-29-1996 JohannP (Johann Posch) Created
  326. //
  327. // Notes:
  328. //
  329. //----------------------------------------------------------------------------
  330. STDMETHODIMP CBaseProtocol::GetPriority(LONG * pnPriority)
  331. {
  332. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::GetPriority\n", this));
  333. HRESULT hr = E_NOTIMPL;
  334. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::GetPriority (hr:%lx)\n",this, hr));
  335. return hr;
  336. }
  337. //+---------------------------------------------------------------------------
  338. //
  339. // Method: CBaseProtocol::Read
  340. //
  341. // Synopsis:
  342. //
  343. // Arguments: [ULONG] --
  344. // [ULONG] --
  345. // [pcbRead] --
  346. //
  347. // Returns:
  348. //
  349. // History: 10-29-1996 JohannP (Johann Posch) Created
  350. //
  351. // Notes:
  352. //
  353. //----------------------------------------------------------------------------
  354. STDMETHODIMP CBaseProtocol::Read(void *pv,ULONG cb,ULONG *pcbRead)
  355. {
  356. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::Read\n", this));
  357. HRESULT hr = E_FAIL;
  358. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::Read (hr:%lx)\n",this, hr));
  359. return hr;
  360. }
  361. //+---------------------------------------------------------------------------
  362. //
  363. // Method: CBaseProtocol::Seek
  364. //
  365. // Synopsis:
  366. //
  367. // Arguments: [DWORD] --
  368. // [ULARGE_INTEGER] --
  369. // [plibNewPosition] --
  370. //
  371. // Returns:
  372. //
  373. // History: 10-29-1996 JohannP (Johann Posch) Created
  374. //
  375. // Notes:
  376. //
  377. //----------------------------------------------------------------------------
  378. STDMETHODIMP CBaseProtocol::Seek(LARGE_INTEGER dlibMove,DWORD dwOrigin,ULARGE_INTEGER *plibNewPosition)
  379. {
  380. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::Seek\n", this));
  381. HRESULT hr = E_FAIL;
  382. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::Seek (hr:%lx)\n",this, hr));
  383. return hr;
  384. }
  385. //+---------------------------------------------------------------------------
  386. //
  387. // Method: CBaseProtocol::LockRequest
  388. //
  389. // Synopsis:
  390. //
  391. // Arguments: [dwOptions] --
  392. //
  393. // Returns:
  394. //
  395. // History: 10-29-1996 JohannP (Johann Posch) Created
  396. //
  397. // Notes:
  398. //
  399. //----------------------------------------------------------------------------
  400. STDMETHODIMP CBaseProtocol::LockRequest(DWORD dwOptions)
  401. {
  402. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::LockRequest\n", this));
  403. HRESULT hr = NOERROR;
  404. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::LockRequest (hr:%lx)\n",this, hr));
  405. return hr;
  406. }
  407. //+---------------------------------------------------------------------------
  408. //
  409. // Method: CBaseProtocol::UnlockRequest
  410. //
  411. // Synopsis:
  412. //
  413. // Arguments: (none)
  414. //
  415. // Returns:
  416. //
  417. // History: 10-29-1996 JohannP (Johann Posch) Created
  418. //
  419. // Notes:
  420. //
  421. //----------------------------------------------------------------------------
  422. STDMETHODIMP CBaseProtocol::UnlockRequest()
  423. {
  424. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::UnlockRequest\n", this));
  425. HRESULT hr = NOERROR;
  426. CloseTempFile();
  427. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::UnlockRequest (hr:%lx)\n",this, hr));
  428. return hr;
  429. }
  430. //+---------------------------------------------------------------------------
  431. //
  432. // Method: CBaseProtocol::Prepare
  433. //
  434. // Synopsis:
  435. //
  436. // Arguments: (none)
  437. //
  438. // Returns:
  439. //
  440. // History: 11-07-1996 JohannP (Johann Posch) Created
  441. //
  442. // Notes:
  443. //
  444. //----------------------------------------------------------------------------
  445. STDMETHODIMP CBaseProtocol::Prepare()
  446. {
  447. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::Prepare\n", this));
  448. HRESULT hr = NOERROR;
  449. EProtAssert(( IsApartmentThread() ));
  450. EProtDebugOut((DEB_PLUGPROT,"%p OUT CBaseProtocol::Prepare (hr:%lx)\n",this, hr));
  451. return hr;
  452. }
  453. //+---------------------------------------------------------------------------
  454. //
  455. // Method: CBaseProtocol::Continue
  456. //
  457. // Synopsis:
  458. //
  459. // Arguments: (none)
  460. //
  461. // Returns:
  462. //
  463. // History: 11-09-1996 JohannP (Johann Posch) Created
  464. //
  465. // Notes:
  466. //
  467. //----------------------------------------------------------------------------
  468. STDMETHODIMP CBaseProtocol::Continue()
  469. {
  470. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::Continue\n", this));
  471. HRESULT hr = NOERROR;
  472. EProtAssert(( !IsApartmentThread() ));
  473. _dwThreadID = GetCurrentThreadId();
  474. EProtDebugOut((DEB_PLUGPROT,"%p OUT CBaseProtocol::Continue (hr:%lx)\n",this, hr));
  475. return hr;
  476. }
  477. STDMETHODIMP CBaseProtocol::QueryService(REFGUID rsid, REFIID riid, void ** ppvObj)
  478. {
  479. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::QueryService \n", this));
  480. HRESULT hr = NOERROR;
  481. VDATETHIS(this);
  482. EProtAssert((ppvObj));
  483. *ppvObj = 0;
  484. if (riid == IID_IHttpNegotiate)
  485. {
  486. IServiceProvider *pServProv = 0;
  487. if ((hr = _pUnkInner->QueryInterface(IID_IServiceProvider, (void **)&pServProv)) == NOERROR)
  488. {
  489. // hand back oo
  490. if ((hr = pServProv->QueryService(rsid, riid, ppvObj)) == NOERROR)
  491. {
  492. _pHttpNeg = new CHttpNegotiate((IHttpNegotiate *)*ppvObj);
  493. if (_pHttpNeg)
  494. {
  495. *ppvObj = _pHttpNeg;
  496. }
  497. else
  498. {
  499. hr = E_OUTOFMEMORY;
  500. }
  501. }
  502. pServProv->Release();
  503. }
  504. }
  505. else
  506. {
  507. IServiceProvider *pServProv = 0;
  508. if ((hr = _pUnkInner->QueryInterface(IID_IServiceProvider, (void **)&pServProv)) == NOERROR)
  509. {
  510. hr = pServProv->QueryService(rsid, riid, ppvObj);
  511. pServProv->Release();
  512. }
  513. }
  514. EProtAssert(( (hr == E_NOINTERFACE) || ((hr == NOERROR) && *ppvObj) ));
  515. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::QueryService (hr:%lx) \n", this, hr));
  516. return hr;
  517. }
  518. //+---------------------------------------------------------------------------
  519. //
  520. // Method: CBaseProtocol::CBaseProtocol
  521. //
  522. // Synopsis:
  523. //
  524. // Arguments: (none)
  525. //
  526. // Returns:
  527. //
  528. // History: 1-27-96 JohannP (Johann Posch) Created
  529. //
  530. // Notes:
  531. //
  532. //----------------------------------------------------------------------------
  533. CBaseProtocol::CBaseProtocol(REFCLSID rclsid, IUnknown *pUnkOuter, IUnknown **ppUnkInner) : _CRefs(), _pclsidProtocol(rclsid), _Unknown()
  534. {
  535. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::CBaseProtocol \n", this));
  536. _dwThreadID = GetCurrentThreadId();
  537. _bscf = BSCF_FIRSTDATANOTIFICATION;
  538. _pOIBindInfo = 0;
  539. if (!pUnkOuter)
  540. {
  541. pUnkOuter = &_Unknown;
  542. }
  543. else
  544. {
  545. EProtAssert((ppUnkInner));
  546. if (ppUnkInner)
  547. {
  548. *ppUnkInner = &_Unknown;
  549. _CRefs = 0;
  550. }
  551. }
  552. _pUnkOuter = pUnkOuter;
  553. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::CBaseProtocol \n", this));
  554. }
  555. //+---------------------------------------------------------------------------
  556. //
  557. // Method: CBaseProtocol::~CBaseProtocol
  558. //
  559. // Synopsis:
  560. //
  561. // Arguments: (none)
  562. //
  563. // Returns:
  564. //
  565. // History: 11-09-1996 JohannP (Johann Posch) Created
  566. //
  567. // Notes:
  568. //
  569. //----------------------------------------------------------------------------
  570. CBaseProtocol::~CBaseProtocol()
  571. {
  572. if (_pUnkInner)
  573. {
  574. _pUnkInner->Release();
  575. }
  576. if (_pwzUrl)
  577. {
  578. delete _pwzUrl;
  579. }
  580. EProtAssert(( _hFile == NULL));
  581. if (_szTempFile[0] != '\0')
  582. {
  583. DeleteFile(_szTempFile);
  584. }
  585. EProtDebugOut((DEB_PLUGPROT, "%p _IN/OUT CBaseProtocol::~CBaseProtocol \n", this));
  586. }
  587. //+---------------------------------------------------------------------------
  588. //
  589. // Method: CBaseProtocol::CPrivUnknown::QueryInterface
  590. //
  591. // Synopsis:
  592. //
  593. // Arguments: [riid] --
  594. // [ppvObj] --
  595. //
  596. // Returns:
  597. //
  598. // History: 10-29-1996 JohannP (Johann Posch) Created
  599. //
  600. // Notes:
  601. //
  602. //----------------------------------------------------------------------------
  603. STDMETHODIMP CBaseProtocol::CPrivUnknown::QueryInterface(REFIID riid, void **ppvObj)
  604. {
  605. VDATEPTROUT(ppvObj, void *);
  606. VDATETHIS(this);
  607. HRESULT hr = NOERROR;
  608. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::CPrivUnknown::QueryInterface\n", this));
  609. CBaseProtocol *pCBaseProtocol = GETPPARENT(this, CBaseProtocol, _Unknown);
  610. *ppvObj = NULL;
  611. if ((riid == IID_IUnknown) || (riid == IID_IOInetProtocol) || (riid == IID_IOInetProtocolRoot) )
  612. {
  613. *ppvObj = (IOInetProtocol *) pCBaseProtocol;
  614. pCBaseProtocol->AddRef();
  615. }
  616. else if (riid == IID_IOInetThreadSwitch)
  617. {
  618. *ppvObj = (IOInetThreadSwitch *)pCBaseProtocol;
  619. pCBaseProtocol->AddRef();
  620. }
  621. else if (riid == IID_IServiceProvider)
  622. {
  623. *ppvObj = (IServiceProvider *)pCBaseProtocol;
  624. pCBaseProtocol->AddRef();
  625. }
  626. else if (pCBaseProtocol->_pUnkInner)
  627. {
  628. hr = pCBaseProtocol->_pUnkInner->QueryInterface(riid, ppvObj);
  629. }
  630. else
  631. {
  632. hr = E_NOINTERFACE;
  633. }
  634. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::CPrivUnknown::QueryInterface (hr:%lx\n", this,hr));
  635. return hr;
  636. }
  637. //+---------------------------------------------------------------------------
  638. //
  639. // Function: CBaseProtocol::CPrivUnknown::AddRef
  640. //
  641. // Synopsis:
  642. //
  643. // Arguments: [ULONG] --
  644. //
  645. // Returns:
  646. //
  647. // History: 10-29-1996 JohannP (Johann Posch) Created
  648. //
  649. // Notes:
  650. //
  651. //----------------------------------------------------------------------------
  652. STDMETHODIMP_(ULONG) CBaseProtocol::CPrivUnknown::AddRef(void)
  653. {
  654. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::CPrivUnknown::AddRef\n", this));
  655. LONG lRet = ++_CRefs;
  656. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::CPrivUnknown::AddRef (cRefs:%ld)\n", this,lRet));
  657. return lRet;
  658. }
  659. //+---------------------------------------------------------------------------
  660. //
  661. // Function: CBaseProtocol::Release
  662. //
  663. // Synopsis:
  664. //
  665. // Arguments: [ULONG] --
  666. //
  667. // Returns:
  668. //
  669. // History: 10-29-1996 JohannP (Johann Posch) Created
  670. //
  671. // Notes:
  672. //
  673. //----------------------------------------------------------------------------
  674. STDMETHODIMP_(ULONG) CBaseProtocol::CPrivUnknown::Release(void)
  675. {
  676. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::CPrivUnknown::Release\n", this));
  677. CBaseProtocol *pCBaseProtocol = GETPPARENT(this, CBaseProtocol, _Unknown);
  678. LONG lRet = --_CRefs;
  679. if (lRet == 0)
  680. {
  681. delete pCBaseProtocol;
  682. }
  683. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::CPrivUnknown::Release (cRefs:%ld)\n",this,lRet));
  684. return lRet;
  685. }
  686. //+---------------------------------------------------------------------------
  687. //
  688. // Method: CBaseProtocol::OpenTempFile
  689. //
  690. // Synopsis:
  691. //
  692. // Arguments: (none)
  693. //
  694. // Returns:
  695. //
  696. // History: 11-09-1996 JohannP (Johann Posch) Created
  697. //
  698. // Notes:
  699. //
  700. //----------------------------------------------------------------------------
  701. BOOL CBaseProtocol::OpenTempFile()
  702. {
  703. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::OpenTempFile\n", this));
  704. HANDLE hTempFile;
  705. BOOL fRet = FALSE;
  706. static char szTempPath[MAX_PATH+32] = {0};
  707. if (!szTempPath[0])
  708. {
  709. GetTempPath(MAX_PATH, szTempPath);
  710. }
  711. if (GetTempFileName(szTempPath, "Res", 0, _szTempFile))
  712. {
  713. // the file should be delete
  714. DWORD dwFileAtr = FILE_ATTRIBUTE_TEMPORARY;
  715. EProtDebugOut((DEB_PLUGPROT, "%p +++ CBaseProtocol::OpenTempFile (szFile:%s)\n",this, _szTempFile));
  716. hTempFile = CreateFile(_szTempFile, GENERIC_WRITE,FILE_SHARE_READ, NULL,CREATE_ALWAYS,dwFileAtr, NULL);
  717. if (hTempFile == INVALID_HANDLE_VALUE)
  718. {
  719. _hFile = NULL;
  720. }
  721. else
  722. {
  723. WCHAR wzTempFile[MAX_PATH];
  724. A2W(_szTempFile,wzTempFile,MAX_PATH);
  725. _pProtSink->ReportProgress(BINDSTATUS_CACHEFILENAMEAVAILABLE, wzTempFile);
  726. _hFile = hTempFile;
  727. fRet = TRUE;
  728. }
  729. }
  730. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::OpenTempFile (_szTempFile:%s, fRet:%d)\n",this, _szTempFile, fRet));
  731. return fRet;
  732. }
  733. //+---------------------------------------------------------------------------
  734. //
  735. // Method: CBaseProtocol::CloseTempFile
  736. //
  737. // Synopsis:
  738. //
  739. // Arguments: (none)
  740. //
  741. // Returns:
  742. //
  743. // History: 1-27-96 JohannP (Johann Posch) Created
  744. //
  745. // Notes:
  746. //
  747. //----------------------------------------------------------------------------
  748. BOOL CBaseProtocol::CloseTempFile()
  749. {
  750. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::CloseTempFile\n", this));
  751. BOOL fRet = FALSE;
  752. if (_hFile)
  753. {
  754. CloseHandle(_hFile);
  755. _hFile = 0;
  756. fRet = TRUE;
  757. }
  758. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::CloseTempFile (fRet:%d)\n",this, fRet));
  759. return fRet;
  760. }
  761. //+---------------------------------------------------------------------------
  762. //
  763. // Function: CreateAPP
  764. //
  765. // Synopsis:
  766. //
  767. // Arguments: [rclsid] --
  768. // [pUnkOuter] --
  769. // [riid] --
  770. // [ppUnk] --
  771. //
  772. // Returns:
  773. //
  774. // History: 11-09-1996 JohannP (Johann Posch) Created
  775. //
  776. // Notes:
  777. //
  778. //----------------------------------------------------------------------------
  779. HRESULT CreateAPP(REFCLSID rclsid, IUnknown *pUnkOuter, REFIID riid, IUnknown **ppUnk)
  780. {
  781. EProtDebugOut((DEB_PLUGPROT, "API _IN CreateKnownProtocolInstance\n"));
  782. HRESULT hr = NOERROR;
  783. EProtAssert((ppUnk));
  784. if (!ppUnk || (pUnkOuter && (riid != IID_IUnknown)) )
  785. {
  786. // Note: aggregation only works if asked for IUnknown
  787. EProtAssert((FALSE && "Dude, look up aggregation rules - need to ask for IUnknown"));
  788. hr = E_INVALIDARG;
  789. }
  790. else
  791. {
  792. CBaseProtocol *pCBaseProtocol = NULL;
  793. if (rclsid == CLSID_CdlProtocol)
  794. {
  795. pCBaseProtocol = new CCdlProtocol(CLSID_CdlProtocol,pUnkOuter, ppUnk);
  796. }
  797. #ifdef TEST_EAPP
  798. else if (rclsid == CLSID_OhServNameSp)
  799. {
  800. pCBaseProtocol = new COhServNameSp(CLSID_OhServNameSp,pUnkOuter, ppUnk);
  801. }
  802. else if (rclsid == CLSID_MimeHandlerTest1)
  803. {
  804. pCBaseProtocol = new CMimeHandlerTest1(CLSID_MimeHandlerTest1,pUnkOuter, ppUnk);
  805. }
  806. else if (rclsid == CLSID_ResProtocol)
  807. {
  808. pCBaseProtocol = new CResProtocol(CLSID_ResProtocol,pUnkOuter, ppUnk);
  809. }
  810. #endif
  811. if (pCBaseProtocol)
  812. {
  813. if (riid == IID_IUnknown)
  814. {
  815. }
  816. else if (riid == IID_IOInetProtocol)
  817. {
  818. // ok, got the right interface already
  819. *ppUnk = (IOInetProtocol *)pCBaseProtocol;
  820. }
  821. else
  822. {
  823. hr = pCBaseProtocol->QueryInterface(riid, (void **)ppUnk);
  824. // remove extra refcount
  825. pCBaseProtocol->Release();
  826. }
  827. }
  828. else
  829. {
  830. hr = E_OUTOFMEMORY;
  831. }
  832. }
  833. EProtDebugOut((DEB_PLUGPROT, "API OUT CreateKnownProtocolInstance(hr:%lx)\n", hr));
  834. return hr;
  835. }
  836. HRESULT CBaseProtocol::ObtainService(REFGUID rsid, REFIID riid, void ** ppvObj)
  837. {
  838. EProtDebugOut((DEB_PLUGPROT, "%p _IN CBaseProtocol::ObtainService \n", this));
  839. HRESULT hr = NOERROR;
  840. VDATETHIS(this);
  841. LPVOID pvLocal = NULL;
  842. #ifdef unusedXXX
  843. CBSCNode *pNode;
  844. pNode = _pCBSCNode;
  845. if (riid == IID_IHttpNegotiate)
  846. {
  847. *ppvObj = (void*)(IHttpNegotiate *) this;
  848. AddRef();
  849. // loop once to get all interfaces
  850. if (!_fHttpNegotiate)
  851. {
  852. while (pNode)
  853. {
  854. if ( (pNode->GetBSCB()->QueryInterface(riid, &pvLocal) == NOERROR)
  855. || ( pNode->GetServiceProvider()
  856. && (pNode->GetHttpNegotiate() == NULL)
  857. && (pNode->GetServiceProvider()->QueryService(riid, riid, &pvLocal)) == NOERROR)
  858. )
  859. {
  860. // Note: the interface is addref'd by QI or QS
  861. pNode->SetHttpNegotiate((IHttpNegotiate *)pvLocal);
  862. }
  863. pNode = pNode->GetNextNode();
  864. }
  865. _fHttpNegotiate = TRUE;
  866. }
  867. }
  868. else if (riid == IID_IAuthenticate)
  869. {
  870. *ppvObj = (void*)(IAuthenticate *) this;
  871. AddRef();
  872. if (!_fAuthenticate)
  873. {
  874. while (pNode)
  875. {
  876. if ( (pNode->GetBSCB()->QueryInterface(riid, &pvLocal) == NOERROR)
  877. || ( pNode->GetServiceProvider()
  878. && (pNode->GetAuthenticate() == NULL)
  879. && (pNode->GetServiceProvider()->QueryService(riid, riid, &pvLocal)) == NOERROR)
  880. )
  881. {
  882. // Note: the interface is addref'd by QI or QS
  883. pNode->SetAuthenticate((IAuthenticate *)pvLocal);
  884. }
  885. pNode = pNode->GetNextNode();
  886. }
  887. _fAuthenticate = TRUE;
  888. }
  889. }
  890. else
  891. {
  892. *ppvObj = NULL;
  893. hr = E_NOINTERFACE;
  894. while (pNode)
  895. {
  896. if ( (pNode->GetBSCB()->QueryInterface(riid, &pvLocal) == NOERROR)
  897. || ( pNode->GetServiceProvider()
  898. && (pNode->GetServiceProvider()->QueryService(riid, riid, &pvLocal)) == NOERROR)
  899. )
  900. {
  901. *ppvObj = pvLocal;
  902. hr = NOERROR;
  903. // Note: the interface is addref'd by QI or QS
  904. // stop looking at other nodes for this service
  905. pNode = NULL;
  906. }
  907. if (pNode)
  908. {
  909. pNode = pNode->GetNextNode();
  910. }
  911. }
  912. }
  913. #endif //unused
  914. EProtDebugOut((DEB_PLUGPROT, "%p OUT CBaseProtocol::ObtainService (hr:%lx) \n", this, hr));
  915. return hr;
  916. }
  917. //+---------------------------------------------------------------------------
  918. //
  919. // Method: CHttpNegotiate::QueryInterface
  920. //
  921. // Synopsis:
  922. //
  923. // Arguments: [riid] --
  924. // [ppvObj] --
  925. //
  926. // Returns:
  927. //
  928. // History: 10-29-1996 JohannP (Johann Posch) Created
  929. //
  930. // Notes:
  931. //
  932. //----------------------------------------------------------------------------
  933. STDMETHODIMP CHttpNegotiate::QueryInterface(REFIID riid, void **ppvObj)
  934. {
  935. VDATEPTROUT(ppvObj, void *);
  936. VDATETHIS(this);
  937. HRESULT hr = NOERROR;
  938. EProtDebugOut((DEB_PLUGPROT, "%p _IN CHttpNegotiate::QueryInterface\n", this));
  939. if ((riid == IID_IUnknown) || (riid == IID_IHttpNegotiate))
  940. {
  941. *ppvObj = (IHttpNegotiate *) this;
  942. AddRef();
  943. }
  944. else
  945. {
  946. hr = E_NOINTERFACE;
  947. }
  948. EProtDebugOut((DEB_PLUGPROT, "%p OUT CHttpNegotiate::QueryInterface (hr:%lx\n", this,hr));
  949. return hr;
  950. }
  951. //+---------------------------------------------------------------------------
  952. //
  953. // Function: CHttpNegotiate::AddRef
  954. //
  955. // Synopsis:
  956. //
  957. // Arguments: [ULONG] --
  958. //
  959. // Returns:
  960. //
  961. // History: 10-29-1996 JohannP (Johann Posch) Created
  962. //
  963. // Notes:
  964. //
  965. //----------------------------------------------------------------------------
  966. STDMETHODIMP_(ULONG) CHttpNegotiate::AddRef(void)
  967. {
  968. EProtDebugOut((DEB_PLUGPROT, "%p _IN CHttpNegotiate::AddRef\n", this));
  969. LONG lRet = ++_CRefs;
  970. EProtDebugOut((DEB_PLUGPROT, "%p OUT CHttpNegotiate::AddRef (cRefs:%ld)\n", this,lRet));
  971. return lRet;
  972. }
  973. //+---------------------------------------------------------------------------
  974. //
  975. // Function: CHttpNegotiate::Release
  976. //
  977. // Synopsis:
  978. //
  979. // Arguments: [ULONG] --
  980. //
  981. // Returns:
  982. //
  983. // History: 10-29-1996 JohannP (Johann Posch) Created
  984. //
  985. // Notes:
  986. //
  987. //----------------------------------------------------------------------------
  988. STDMETHODIMP_(ULONG) CHttpNegotiate::Release(void)
  989. {
  990. EProtDebugOut((DEB_PLUGPROT, "%p _IN CHttpNegotiate::Release\n", this));
  991. LONG lRet = --_CRefs;
  992. if (lRet == 0)
  993. {
  994. delete this;
  995. }
  996. EProtDebugOut((DEB_PLUGPROT, "%p OUT CHttpNegotiate::Release (cRefs:%ld)\n",this,lRet));
  997. return lRet;
  998. }
  999. //+---------------------------------------------------------------------------
  1000. //
  1001. // Method: CHttpNegotiate::BeginningTransaction
  1002. //
  1003. // Synopsis:
  1004. //
  1005. // Arguments: [szURL] --
  1006. // [szHeaders] --
  1007. // [dwReserved] --
  1008. // [pszAdditionalHeaders] --
  1009. //
  1010. // Returns:
  1011. //
  1012. //
  1013. // Notes:
  1014. //
  1015. //----------------------------------------------------------------------------
  1016. HRESULT CHttpNegotiate::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeaders,
  1017. DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
  1018. {
  1019. EProtDebugOut((DEB_PLUGPROT, "%p _IN CHttpNegotiate::BeginningTransaction (szURL:%ws, szHeaders:%ws)\n", this, szURL, szHeaders));
  1020. VDATETHIS(this);
  1021. HRESULT hr = NOERROR;
  1022. LPWSTR szTmp = NULL, szNew = NULL, szRunning = NULL;
  1023. EProtAssert((szURL));
  1024. EProtDebugOut((DEB_PLUGPROT, "%p OUT CHttpNegotiate::BeginningTransaction (pszAdditionalHeaders:%ws )\n", this, *pszAdditionalHeaders));
  1025. return hr;
  1026. }
  1027. //+---------------------------------------------------------------------------
  1028. //
  1029. // Method: CHttpNegotiate::OnResponse
  1030. //
  1031. // Synopsis:
  1032. //
  1033. // Arguments: [LPCWSTR] --
  1034. // [szResponseHeaders] --
  1035. // [LPWSTR] --
  1036. // [pszAdditionalRequestHeaders] --
  1037. //
  1038. // Returns:
  1039. //
  1040. // History: 4-05-96 JohannP (Johann Posch) Created
  1041. //
  1042. // Notes:
  1043. //
  1044. //----------------------------------------------------------------------------
  1045. HRESULT CHttpNegotiate::OnResponse(DWORD dwResponseCode,LPCWSTR wzResponseHeaders,
  1046. LPCWSTR wzRequestHeaders,LPWSTR *pszAdditionalRequestHeaders)
  1047. {
  1048. EProtDebugOut((DEB_PLUGPROT, "%p _IN CHttpNegotiate::OnResponse\n", this));
  1049. VDATETHIS(this);
  1050. HRESULT hr;
  1051. LPWSTR szTmp = NULL, szNew = NULL, szRunning = NULL;
  1052. hr = IsStatusOk(dwResponseCode) ? S_OK : S_FALSE;
  1053. EProtDebugOut((DEB_PLUGPROT, "%p OUT CHttpNegotiate::OnResponse\n", this));
  1054. return hr;
  1055. }