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.

891 lines
23 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 <urlint.h>
  18. #include <stdio.h>
  19. #include <sem.hxx>
  20. #include <wininet.h>
  21. #include "urlcf.hxx"
  22. #include "protbase.hxx"
  23. #include "resprot.hxx"
  24. extern GUID CLSID_ResProtocol;
  25. //+---------------------------------------------------------------------------
  26. //
  27. // Method: CBaseProtocol::QueryInterface
  28. //
  29. // Synopsis:
  30. //
  31. // Arguments: [riid] --
  32. // [ppvObj] --
  33. //
  34. // Returns:
  35. //
  36. // History: 10-29-1996 JohannP (Johann Posch) Created
  37. //
  38. // Notes:
  39. //
  40. //----------------------------------------------------------------------------
  41. STDMETHODIMP CBaseProtocol::QueryInterface(REFIID riid, void **ppvObj)
  42. {
  43. VDATEPTROUT(ppvObj, void *);
  44. VDATETHIS(this);
  45. HRESULT hr = NOERROR;
  46. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::QueryInterface\n", this));
  47. hr = _pUnkOuter->QueryInterface(riid, ppvObj);
  48. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::QueryInterface (hr:%lx\n", this,hr));
  49. return hr;
  50. }
  51. //+---------------------------------------------------------------------------
  52. //
  53. // Function: CBaseProtocol::AddRef
  54. //
  55. // Synopsis:
  56. //
  57. // Arguments: [ULONG] --
  58. //
  59. // Returns:
  60. //
  61. // History: 10-29-1996 JohannP (Johann Posch) Created
  62. //
  63. // Notes:
  64. //
  65. //----------------------------------------------------------------------------
  66. STDMETHODIMP_(ULONG) CBaseProtocol::AddRef(void)
  67. {
  68. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::AddRef\n", this));
  69. LONG lRet = _pUnkOuter->AddRef();
  70. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::AddRef (cRefs:%ld)\n", this,lRet));
  71. return lRet;
  72. }
  73. //+---------------------------------------------------------------------------
  74. //
  75. // Function: CBaseProtocol::Release
  76. //
  77. // Synopsis:
  78. //
  79. // Arguments: [ULONG] --
  80. //
  81. // Returns:
  82. //
  83. // History: 10-29-1996 JohannP (Johann Posch) Created
  84. //
  85. // Notes:
  86. //
  87. //----------------------------------------------------------------------------
  88. STDMETHODIMP_(ULONG) CBaseProtocol::Release(void)
  89. {
  90. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::Release\n", this));
  91. LONG lRet = _pUnkOuter->Release();
  92. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::Release (cRefs:%ld)\n",this,lRet));
  93. return lRet;
  94. }
  95. //+---------------------------------------------------------------------------
  96. //
  97. // Method: CBaseProtocol::Start
  98. //
  99. // Synopsis:
  100. //
  101. // Arguments: [pwzUrl] --
  102. // [pTrans] --
  103. // [pOIBindInfo] --
  104. // [grfSTI] --
  105. // [dwReserved] --
  106. //
  107. // Returns:
  108. //
  109. // History: 10-29-1996 JohannP (Johann Posch) Created
  110. //
  111. // Notes:
  112. //
  113. //----------------------------------------------------------------------------
  114. STDMETHODIMP CBaseProtocol::Start(LPCWSTR pwzUrl, IOInetProtocolSink *pTrans, IOInetBindInfo *pOIBindInfo,
  115. DWORD grfSTI, DWORD dwReserved)
  116. {
  117. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::Start\n", this));
  118. HRESULT hr = NOERROR;
  119. TransAssert((!_pProtSink && pOIBindInfo && pTrans));
  120. TransAssert((_pszUrl == NULL));
  121. _pProtSink = pTrans;
  122. _pProtSink->AddRef();
  123. _BndInfo.cbSize = sizeof(BINDINFO);
  124. _pOIBindInfo = pOIBindInfo;
  125. _pOIBindInfo->AddRef();
  126. hr = pOIBindInfo->GetBindInfo(&_grfBindF, &_BndInfo);
  127. // save the URL
  128. _pszUrl = DupW2A(pwzUrl);
  129. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::Start (hr:%lx)\n",this, hr));
  130. return hr;
  131. }
  132. //+---------------------------------------------------------------------------
  133. //
  134. // Method: CBaseProtocol::Continue
  135. //
  136. // Synopsis:
  137. //
  138. // Arguments: [pStateInfoIn] --
  139. //
  140. // Returns:
  141. //
  142. // History: 10-29-1996 JohannP (Johann Posch) Created
  143. //
  144. // Notes:
  145. //
  146. //----------------------------------------------------------------------------
  147. STDMETHODIMP CBaseProtocol::Continue(PROTOCOLDATA *pStateInfoIn)
  148. {
  149. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::Continue\n", this));
  150. HRESULT hr = E_FAIL;
  151. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::Continue (hr:%lx)\n",this, hr));
  152. return hr;
  153. }
  154. //+---------------------------------------------------------------------------
  155. //
  156. // Method: CBaseProtocol::Abort
  157. //
  158. // Synopsis:
  159. //
  160. // Arguments: [hrReason] --
  161. // [dwOptions] --
  162. //
  163. // Returns:
  164. //
  165. // History: 11-09-1996 JohannP (Johann Posch) Created
  166. //
  167. // Notes:
  168. //
  169. //----------------------------------------------------------------------------
  170. STDMETHODIMP CBaseProtocol::Abort(HRESULT hrReason, DWORD dwOptions)
  171. {
  172. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::Abort\n", this));
  173. HRESULT hr = NOERROR;
  174. if (_pProt)
  175. return _pProt->Abort(hrReason, dwOptions);
  176. TransAssert((_pProtSink));
  177. hr = _pProtSink->ReportResult(E_ABORT, 0, 0);
  178. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::Abort (hr:%lx)\n",this, hr));
  179. return hr;
  180. }
  181. //+---------------------------------------------------------------------------
  182. //
  183. // Method: CBaseProtocol::Terminate
  184. //
  185. // Synopsis:
  186. //
  187. // Arguments: [dwOptions] --
  188. //
  189. // Returns:
  190. //
  191. // History: 10-29-1996 JohannP (Johann Posch) Created
  192. //
  193. // Notes:
  194. //
  195. //----------------------------------------------------------------------------
  196. STDMETHODIMP CBaseProtocol::Terminate(DWORD dwOptions)
  197. {
  198. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::Terminate\n", this));
  199. HRESULT hr = NOERROR;
  200. if (_pProt)
  201. {
  202. hr = _pProt->Terminate(dwOptions);
  203. if (FAILED(hr))
  204. return hr;
  205. _pProt->Release();
  206. _pProt = NULL;
  207. }
  208. TransAssert((_pProtSink));
  209. if (_pOIBindInfo)
  210. {
  211. _pOIBindInfo->Release();
  212. _pOIBindInfo = NULL;
  213. }
  214. if (_pProtSink)
  215. {
  216. _pProtSink->Release();
  217. _pProtSink = NULL;
  218. }
  219. #if DBG == 1
  220. if ( _BndInfo.stgmedData.tymed != TYMED_NULL )
  221. TransDebugOut((DEB_TRANS, "%p --- CBaseProtocol::Stop ReleaseStgMedium (%p)\n", this,_BndInfo.stgmedData));
  222. #endif
  223. ReleaseBindInfo(&_BndInfo);
  224. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::Terminate (hr:%lx)\n",this, hr));
  225. return hr;
  226. }
  227. //+---------------------------------------------------------------------------
  228. //
  229. // Method: CBaseProtocol::Suspend
  230. //
  231. // Synopsis:
  232. //
  233. // Arguments: (none)
  234. //
  235. // Returns:
  236. //
  237. // History: 10-29-1996 JohannP (Johann Posch) Created
  238. //
  239. // Notes:
  240. //
  241. //----------------------------------------------------------------------------
  242. STDMETHODIMP CBaseProtocol::Suspend()
  243. {
  244. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::Suspend\n", this));
  245. HRESULT hr = E_NOTIMPL;
  246. if (_pProt)
  247. hr = _pProt->Suspend();
  248. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::Suspend (hr:%lx)\n",this, hr));
  249. return hr;
  250. }
  251. //+---------------------------------------------------------------------------
  252. //
  253. // Method: CBaseProtocol::Resume
  254. //
  255. // Synopsis:
  256. //
  257. // Arguments: (none)
  258. //
  259. // Returns:
  260. //
  261. // History: 10-29-1996 JohannP (Johann Posch) Created
  262. //
  263. // Notes:
  264. //
  265. //----------------------------------------------------------------------------
  266. STDMETHODIMP CBaseProtocol::Resume()
  267. {
  268. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::Resume\n", this));
  269. HRESULT hr = E_NOTIMPL;
  270. if (_pProt)
  271. hr = _pProt->Resume();
  272. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::Resume (hr:%lx)\n",this, hr));
  273. return hr;
  274. }
  275. //+---------------------------------------------------------------------------
  276. //
  277. // Method: CBaseProtocol::SetPriority
  278. //
  279. // Synopsis:
  280. //
  281. // Arguments: [nPriority] --
  282. //
  283. // Returns:
  284. //
  285. // History: 10-29-1996 JohannP (Johann Posch) Created
  286. //
  287. // Notes:
  288. //
  289. //----------------------------------------------------------------------------
  290. STDMETHODIMP CBaseProtocol::SetPriority(LONG nPriority)
  291. {
  292. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::SetPriority\n", this));
  293. HRESULT hr = E_NOTIMPL;
  294. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::SetPriority (hr:%lx)\n",this, hr));
  295. return hr;
  296. }
  297. //+---------------------------------------------------------------------------
  298. //
  299. // Method: CBaseProtocol::GetPriority
  300. //
  301. // Synopsis:
  302. //
  303. // Arguments: [pnPriority] --
  304. //
  305. // Returns:
  306. //
  307. // History: 10-29-1996 JohannP (Johann Posch) Created
  308. //
  309. // Notes:
  310. //
  311. //----------------------------------------------------------------------------
  312. STDMETHODIMP CBaseProtocol::GetPriority(LONG * pnPriority)
  313. {
  314. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::GetPriority\n", this));
  315. HRESULT hr = E_NOTIMPL;
  316. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::GetPriority (hr:%lx)\n",this, hr));
  317. return hr;
  318. }
  319. //+---------------------------------------------------------------------------
  320. //
  321. // Method: CBaseProtocol::Read
  322. //
  323. // Synopsis:
  324. //
  325. // Arguments: [ULONG] --
  326. // [ULONG] --
  327. // [pcbRead] --
  328. //
  329. // Returns:
  330. //
  331. // History: 10-29-1996 JohannP (Johann Posch) Created
  332. //
  333. // Notes:
  334. //
  335. //----------------------------------------------------------------------------
  336. STDMETHODIMP CBaseProtocol::Read(void *pv,ULONG cb,ULONG *pcbRead)
  337. {
  338. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::Read\n", this));
  339. HRESULT hr = E_FAIL;
  340. if (_pProt)
  341. hr = _pProt->Read(pv, cb, pcbRead);
  342. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::Read (hr:%lx)\n",this, hr));
  343. return hr;
  344. }
  345. //+---------------------------------------------------------------------------
  346. //
  347. // Method: CBaseProtocol::Seek
  348. //
  349. // Synopsis:
  350. //
  351. // Arguments: [DWORD] --
  352. // [ULARGE_INTEGER] --
  353. // [plibNewPosition] --
  354. //
  355. // Returns:
  356. //
  357. // History: 10-29-1996 JohannP (Johann Posch) Created
  358. //
  359. // Notes:
  360. //
  361. //----------------------------------------------------------------------------
  362. STDMETHODIMP CBaseProtocol::Seek(LARGE_INTEGER dlibMove,DWORD dwOrigin,ULARGE_INTEGER *plibNewPosition)
  363. {
  364. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::Seek\n", this));
  365. HRESULT hr = E_FAIL;
  366. if (_pProt)
  367. hr = _pProt->Seek(dlibMove, dwOrigin, plibNewPosition);
  368. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::Seek (hr:%lx)\n",this, hr));
  369. return hr;
  370. }
  371. //+---------------------------------------------------------------------------
  372. //
  373. // Method: CBaseProtocol::LockRequest
  374. //
  375. // Synopsis:
  376. //
  377. // Arguments: [dwOptions] --
  378. //
  379. // Returns:
  380. //
  381. // History: 10-29-1996 JohannP (Johann Posch) Created
  382. //
  383. // Notes:
  384. //
  385. //----------------------------------------------------------------------------
  386. STDMETHODIMP CBaseProtocol::LockRequest(DWORD dwOptions)
  387. {
  388. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::LockRequest\n", this));
  389. HRESULT hr = NOERROR;
  390. if (_pProt)
  391. hr = _pProt->LockRequest(dwOptions);
  392. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::LockRequest (hr:%lx)\n",this, hr));
  393. return hr;
  394. }
  395. //+---------------------------------------------------------------------------
  396. //
  397. // Method: CBaseProtocol::UnlockRequest
  398. //
  399. // Synopsis:
  400. //
  401. // Arguments: (none)
  402. //
  403. // Returns:
  404. //
  405. // History: 10-29-1996 JohannP (Johann Posch) Created
  406. //
  407. // Notes:
  408. //
  409. //----------------------------------------------------------------------------
  410. STDMETHODIMP CBaseProtocol::UnlockRequest()
  411. {
  412. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::UnlockRequest\n", this));
  413. HRESULT hr = NOERROR;
  414. if (_pProt)
  415. hr = _pProt->UnlockRequest();
  416. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::UnlockRequest (hr:%lx)\n",this, hr));
  417. return hr;
  418. }
  419. //+---------------------------------------------------------------------------
  420. //
  421. // Method: CBaseProtocol::Prepare
  422. //
  423. // Synopsis:
  424. //
  425. // Arguments: (none)
  426. //
  427. // Returns:
  428. //
  429. // History: 11-07-1996 JohannP (Johann Posch) Created
  430. //
  431. // Notes:
  432. //
  433. //----------------------------------------------------------------------------
  434. STDMETHODIMP CBaseProtocol::Prepare()
  435. {
  436. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::Prepare\n", this));
  437. HRESULT hr = NOERROR;
  438. TransAssert(( IsApartmentThread() ));
  439. TransDebugOut((DEB_PROT,"%p OUT CBaseProtocol::Prepare (hr:%lx)\n",this, hr));
  440. return hr;
  441. }
  442. //+---------------------------------------------------------------------------
  443. //
  444. // Method: CBaseProtocol::Continue
  445. //
  446. // Synopsis:
  447. //
  448. // Arguments: (none)
  449. //
  450. // Returns:
  451. //
  452. // History: 11-09-1996 JohannP (Johann Posch) Created
  453. //
  454. // Notes:
  455. //
  456. //----------------------------------------------------------------------------
  457. STDMETHODIMP CBaseProtocol::Continue()
  458. {
  459. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::Continue\n", this));
  460. HRESULT hr = NOERROR;
  461. TransAssert(( !IsApartmentThread() ));
  462. _dwThreadID = GetCurrentThreadId();
  463. TransDebugOut((DEB_PROT,"%p OUT CBaseProtocol::Continue (hr:%lx)\n",this, hr));
  464. return hr;
  465. }
  466. //+---------------------------------------------------------------------------
  467. //
  468. // Method: CBaseProtocol::CBaseProtocol
  469. //
  470. // Synopsis:
  471. //
  472. // Arguments: (none)
  473. //
  474. // Returns:
  475. //
  476. // History: 1-27-96 JohannP (Johann Posch) Created
  477. //
  478. // Notes:
  479. //
  480. //----------------------------------------------------------------------------
  481. CBaseProtocol::CBaseProtocol(REFCLSID rclsid, IUnknown *pUnkOuter, IUnknown **ppUnkInner) : _CRefs(), _pclsidProtocol(rclsid), _Unknown()
  482. {
  483. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::CBaseProtocol \n", this));
  484. _dwThreadID = GetCurrentThreadId();
  485. _bscf = BSCF_FIRSTDATANOTIFICATION;
  486. _pOIBindInfo = 0;
  487. _pszUrl = 0;
  488. _pProt = 0;
  489. if (!pUnkOuter)
  490. {
  491. pUnkOuter = &_Unknown;
  492. }
  493. else
  494. {
  495. TransAssert((ppUnkInner));
  496. if (ppUnkInner)
  497. {
  498. *ppUnkInner = &_Unknown;
  499. _CRefs = 0;
  500. }
  501. }
  502. _pUnkOuter = pUnkOuter;
  503. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::CBaseProtocol \n", this));
  504. }
  505. //+---------------------------------------------------------------------------
  506. //
  507. // Method: CBaseProtocol::~CBaseProtocol
  508. //
  509. // Synopsis:
  510. //
  511. // Arguments: (none)
  512. //
  513. // Returns:
  514. //
  515. // History: 11-09-1996 JohannP (Johann Posch) Created
  516. //
  517. // Notes:
  518. //
  519. //----------------------------------------------------------------------------
  520. CBaseProtocol::~CBaseProtocol()
  521. {
  522. if (_pszUrl)
  523. delete _pszUrl;
  524. TransDebugOut((DEB_PROT, "%p _IN/OUT CBaseProtocol::~CBaseProtocol \n", this));
  525. }
  526. //+---------------------------------------------------------------------------
  527. //
  528. // Method: CBaseProtocol::CPrivUnknown::QueryInterface
  529. //
  530. // Synopsis:
  531. //
  532. // Arguments: [riid] --
  533. // [ppvObj] --
  534. //
  535. // Returns:
  536. //
  537. // History: 10-29-1996 JohannP (Johann Posch) Created
  538. //
  539. // Notes:
  540. //
  541. //----------------------------------------------------------------------------
  542. STDMETHODIMP CBaseProtocol::CPrivUnknown::QueryInterface(REFIID riid, void **ppvObj)
  543. {
  544. VDATEPTROUT(ppvObj, void *);
  545. VDATETHIS(this);
  546. HRESULT hr = NOERROR;
  547. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::CPrivUnknown::QueryInterface\n", this));
  548. CBaseProtocol *pCBaseProtocol = GETPPARENT(this, CBaseProtocol, _Unknown);
  549. *ppvObj = NULL;
  550. if ((riid == IID_IUnknown) || (riid == IID_IOInetProtocol) || (riid == IID_IOInetProtocolRoot) )
  551. {
  552. *ppvObj = (IOInetProtocol *) pCBaseProtocol;
  553. pCBaseProtocol->AddRef();
  554. }
  555. else if (riid == IID_IOInetThreadSwitch)
  556. {
  557. *ppvObj = (IOInetThreadSwitch *)pCBaseProtocol;
  558. pCBaseProtocol->AddRef();
  559. }
  560. else
  561. {
  562. hr = E_NOINTERFACE;
  563. }
  564. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::CPrivUnknown::QueryInterface (hr:%lx\n", this,hr));
  565. return hr;
  566. }
  567. //+---------------------------------------------------------------------------
  568. //
  569. // Function: CBaseProtocol::CPrivUnknown::AddRef
  570. //
  571. // Synopsis:
  572. //
  573. // Arguments: [ULONG] --
  574. //
  575. // Returns:
  576. //
  577. // History: 10-29-1996 JohannP (Johann Posch) Created
  578. //
  579. // Notes:
  580. //
  581. //----------------------------------------------------------------------------
  582. STDMETHODIMP_(ULONG) CBaseProtocol::CPrivUnknown::AddRef(void)
  583. {
  584. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::CPrivUnknown::AddRef\n", this));
  585. LONG lRet = ++_CRefs;
  586. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::CPrivUnknown::AddRef (cRefs:%ld)\n", this,lRet));
  587. return lRet;
  588. }
  589. //+---------------------------------------------------------------------------
  590. //
  591. // Function: CBaseProtocol::Release
  592. //
  593. // Synopsis:
  594. //
  595. // Arguments: [ULONG] --
  596. //
  597. // Returns:
  598. //
  599. // History: 10-29-1996 JohannP (Johann Posch) Created
  600. //
  601. // Notes:
  602. //
  603. //----------------------------------------------------------------------------
  604. STDMETHODIMP_(ULONG) CBaseProtocol::CPrivUnknown::Release(void)
  605. {
  606. TransDebugOut((DEB_PROT, "%p _IN CBaseProtocol::CPrivUnknown::Release\n", this));
  607. CBaseProtocol *pCBaseProtocol = GETPPARENT(this, CBaseProtocol, _Unknown);
  608. LONG lRet = --_CRefs;
  609. if (lRet == 0)
  610. {
  611. delete pCBaseProtocol;
  612. }
  613. TransDebugOut((DEB_PROT, "%p OUT CBaseProtocol::CPrivUnknown::Release (cRefs:%ld)\n",this,lRet));
  614. return lRet;
  615. }
  616. //+---------------------------------------------------------------------------
  617. //
  618. // Function: OLESTRDuplicate
  619. //
  620. // Synopsis:
  621. //
  622. // Arguments: [ws] --
  623. //
  624. // Returns:
  625. //
  626. // History: 11-09-1996 JohannP (Johann Posch) Created
  627. //
  628. // Notes:
  629. //
  630. //----------------------------------------------------------------------------
  631. LPWSTR OLESTRDuplicate(LPWSTR ws)
  632. {
  633. LPWSTR wsNew = NULL;
  634. if (ws)
  635. {
  636. wsNew = (LPWSTR) new WCHAR [wcslen(ws) + 1];
  637. if (wsNew)
  638. {
  639. wcscpy(wsNew, ws);
  640. }
  641. }
  642. return wsNew;
  643. }
  644. //+---------------------------------------------------------------------------
  645. //
  646. // Function: DupW2A
  647. //
  648. // Synopsis: duplicates a wide string to an ansi string
  649. //
  650. // Arguments: [pwz] --
  651. //
  652. // History: 7-20-96 JohannP (Johann Posch) Created
  653. //
  654. // Notes:
  655. //
  656. //----------------------------------------------------------------------------
  657. LPSTR DupW2A(const WCHAR *pwz)
  658. {
  659. LPSTR szNew = NULL;
  660. if (pwz)
  661. {
  662. DWORD dwlen = wcslen(pwz) + 1;
  663. szNew = (LPSTR) new char [dwlen];
  664. if (szNew)
  665. {
  666. W2A(pwz, szNew, dwlen);
  667. }
  668. }
  669. return szNew;
  670. }
  671. //+---------------------------------------------------------------------------
  672. //
  673. // Function: DupA2W
  674. //
  675. // Synopsis: duplicates an ansi string to a wide string
  676. //
  677. // Arguments: [lpszAnsi] --
  678. //
  679. // History: 7-20-96 JohannP (Johann Posch) Created
  680. //
  681. // Notes:
  682. //
  683. //----------------------------------------------------------------------------
  684. LPWSTR DupA2W(const LPSTR psz)
  685. {
  686. LPWSTR wzNew = NULL;
  687. if (psz)
  688. {
  689. DWORD dwlen = strlen(psz) + 1;
  690. wzNew = (LPWSTR) new WCHAR [dwlen];
  691. if (wzNew)
  692. {
  693. A2W(psz, wzNew, dwlen);
  694. }
  695. }
  696. return wzNew;
  697. }
  698. //BUG-WORK remove this and link to lib
  699. const GUID IID_IOInet = { 0x79eac9e0, 0xbaf9, 0x11ce, {0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b} };
  700. const GUID IID_IOInetBindInfo = { 0x79eac9e1, 0xbaf9, 0x11ce, {0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b} };
  701. const GUID IID_IOInetBindClient = { 0x79eac9e2, 0xbaf9, 0x11ce, {0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b} };
  702. const GUID IID_IOInetProtocolRoot = { 0x79eac9e3, 0xbaf9, 0x11ce, {0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b} };
  703. const GUID IID_IOInetProtocol = { 0x79eac9e4, 0xbaf9, 0x11ce, {0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b} };
  704. const GUID IID_IOInetProtocolSink = { 0x79eac9e5, 0xbaf9, 0x11ce, {0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b} };
  705. const GUID IID_IOInetBinding = { 0x79eac9e6, 0xbaf9, 0x11ce, {0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b} };
  706. const GUID IID_IOInetSession = { 0x79eac967, 0xbaf9, 0x11ce, {0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b} };
  707. const GUID IID_IOInetThreadSwitch = { 0x79eac968, 0xbaf9, 0x11ce, {0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b} };
  708. const GUID IID_IOInetBindSink = { 0x79eac9e9, 0xbaf9, 0x11ce, {0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b} };
  709. const GUID IID_IOInetCache = { 0x79eac9ea, 0xbaf9, 0x11ce, {0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b} };
  710. const GUID IID_IOInetPriority = { 0x79eac9eb, 0xbaf9, 0x11ce, {0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b} };
  711. //+---------------------------------------------------------------------------
  712. //
  713. // Function: CreateAPP
  714. //
  715. // Synopsis:
  716. //
  717. // Arguments: [rclsid] --
  718. // [pUnkOuter] --
  719. // [riid] --
  720. // [ppUnk] --
  721. //
  722. // Returns:
  723. //
  724. // History: 11-09-1996 JohannP (Johann Posch) Created
  725. //
  726. // Notes:
  727. //
  728. //----------------------------------------------------------------------------
  729. HRESULT CreateAPP(REFCLSID rclsid, IUnknown *pUnkOuter, REFIID riid, IUnknown **ppUnk)
  730. {
  731. TransDebugOut((DEB_PROT, "API _IN CreateKnownProtocolInstance\n"));
  732. HRESULT hr = NOERROR;
  733. TransAssert((ppUnk));
  734. if (!ppUnk || (pUnkOuter && (riid != IID_IUnknown)) )
  735. {
  736. // Note: aggregation only works if asked for IUnknown
  737. TransAssert((FALSE && "Dude, look up aggregation rules - need to ask for IUnknown"));
  738. hr = E_INVALIDARG;
  739. }
  740. else
  741. {
  742. CBaseProtocol *pCBaseProtocol = NULL;
  743. if (rclsid == CLSID_ResProtocol)
  744. {
  745. pCBaseProtocol = new CResProtocol(CLSID_ResProtocol,pUnkOuter, ppUnk);
  746. }
  747. if (pCBaseProtocol)
  748. {
  749. if (riid == IID_IUnknown)
  750. {
  751. }
  752. else if (riid == IID_IOInetProtocol)
  753. {
  754. // ok, got the right interface already
  755. *ppUnk = (IOInetProtocol *)pCBaseProtocol;
  756. }
  757. else
  758. {
  759. hr = pCBaseProtocol->QueryInterface(riid, (void **)ppUnk);
  760. // remove extra refcount
  761. pCBaseProtocol->Release();
  762. }
  763. }
  764. else
  765. {
  766. hr = E_OUTOFMEMORY;
  767. }
  768. }
  769. TransDebugOut((DEB_PROT, "API OUT CreateKnownProtocolInstance(hr:%lx)\n", hr));
  770. return hr;
  771. }