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.

1047 lines
28 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: UrlApi.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 10-25-95 JohannP (Johann Posch) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <mon.h>
  18. #include <shlwapip.h>
  19. #include "urlapi.hxx"
  20. #include "httpneg.hxx"
  21. #include "mpxbsc.hxx"
  22. #ifndef unix
  23. #include "..\trans\transact.hxx"
  24. #include "..\trans\bindctx.hxx"
  25. #include "..\trans\urlmk.hxx"
  26. #else
  27. #include "../trans/transact.hxx"
  28. #include "../trans/bindctx.hxx"
  29. #include "../trans/urlmk.hxx"
  30. #endif /* unix */
  31. PerfDbgTag(tagUrlApi, "Urlmon", "Log UrlMon API", DEB_ASYNCAPIS);
  32. // API defined in trans\oinet.cxx
  33. BOOL IsOInetProtocol(IBindCtx*, LPCWSTR);
  34. //+---------------------------------------------------------------------------
  35. //
  36. // Function: CreateURLMoniker
  37. //
  38. // Synopsis: Create a new empty URL Moniker object
  39. //
  40. // Arguments: [pMkCtx] -- the context moniker
  41. // [szUrl] -- url string
  42. // [ppmk] -- new moniker
  43. //
  44. // Returns:
  45. //
  46. // History: 12-13-95 JohannP (Johann Posch) Created
  47. //
  48. // Notes:
  49. //
  50. //----------------------------------------------------------------------------
  51. STDAPI CreateURLMoniker(LPMONIKER pMkCtx, LPCWSTR szUrl, LPMONIKER FAR * ppMk)
  52. {
  53. DEBUG_ENTER_API((DBG_API,
  54. Hresult,
  55. "CreateURLMoniker",
  56. "%#x, %.80wq, %#x",
  57. pMkCtx, szUrl, ppMk
  58. ));
  59. HRESULT hr = CreateURLMonikerEx(pMkCtx, szUrl, ppMk, URL_MK_LEGACY);
  60. DEBUG_LEAVE_API(hr);
  61. return hr;
  62. }
  63. //+---------------------------------------------------------------------------
  64. //
  65. // Function: CreateURLMonikerEx
  66. //
  67. // Synopsis: Create a new empty URL Moniker object
  68. //
  69. // Arguments: [pMkCtx] -- the context moniker
  70. // [szUrl] -- url string
  71. // [ppmk] -- new moniker
  72. // [dwflags] -- controlling flags
  73. //
  74. // Returns:
  75. //
  76. // History: 12-13-95 JohannP (Johann Posch) Created
  77. //
  78. // Notes:
  79. //
  80. //----------------------------------------------------------------------------
  81. STDAPI CreateURLMonikerEx(LPMONIKER pMkCtx, LPCWSTR szUrl, LPMONIKER FAR * ppMk, DWORD dwFlags)
  82. {
  83. DEBUG_ENTER_API((DBG_API,
  84. Hresult,
  85. "CreateURLMonikerEx",
  86. "%#x, %.200wq, %#x, %08x",
  87. pMkCtx, szUrl, ppMk, dwFlags
  88. ));
  89. VDATEPTROUT(ppMk,LPMONIKER);
  90. VDATEPTRIN(szUrl,WCHAR);
  91. PerfDbgLog2(tagUrlApi, NULL, "+CreateURLMoniker (szUrl%ws, pMkCtx:%lx)",szUrl?szUrl:L"<NULL PATH>", pMkCtx);
  92. HRESULT hr = NOERROR;
  93. LPWSTR szUrlLocal = NULL;
  94. WCHAR wzUrlStr[MAX_URL_SIZE + 1];
  95. CUrlMon * pUMk = NULL;
  96. DWORD dwCUFlags = (dwFlags & URL_MK_UNIFORM) ? CU_STANDARD_FORM : 0;
  97. if (dwFlags & URL_MK_NO_CANONICALIZE)
  98. dwCUFlags |= CU_NO_CANONICALIZE;
  99. else
  100. dwCUFlags |= CU_CANONICALIZE;
  101. hr = ConstructURL(NULL, pMkCtx, NULL, (LPWSTR)szUrl, wzUrlStr,
  102. sizeof(wzUrlStr), dwCUFlags);
  103. if (hr != NOERROR)
  104. {
  105. goto CreateExit;
  106. }
  107. szUrlLocal = new WCHAR [wcslen(wzUrlStr) + 1];
  108. if (szUrlLocal)
  109. {
  110. wcscpy(szUrlLocal, wzUrlStr);
  111. if ((pUMk = new CUrlMon(szUrlLocal)) == NULL)
  112. {
  113. hr = E_OUTOFMEMORY;
  114. }
  115. // CUrlmon has refcount of 1 now
  116. }
  117. else
  118. {
  119. hr = E_OUTOFMEMORY;
  120. }
  121. CreateExit:
  122. *ppMk = pUMk;
  123. PerfDbgLog2(tagUrlApi, NULL, "-CreateURLMoniker(%ws, Mnk:%lx)",wzUrlStr?wzUrlStr:L"<NULL PATH>",pUMk);
  124. DEBUG_LEAVE_API(hr);
  125. return hr;
  126. }
  127. //+---------------------------------------------------------------------------
  128. //
  129. // Function: MkParseDisplayNameEx
  130. //
  131. // Synopsis:
  132. //
  133. // Arguments: [pbc] --
  134. // [pszName] --
  135. // [pchEaten] --
  136. // [ppmk] --
  137. //
  138. // Returns:
  139. //
  140. // History: 12-13-95 JohannP (Johann Posch) Created
  141. //
  142. // Notes:
  143. //
  144. //----------------------------------------------------------------------------
  145. STDAPI MkParseDisplayNameEx(LPBC pbc, LPCWSTR szDispName, ULONG *pchEaten, LPMONIKER *ppmk)
  146. {
  147. DEBUG_ENTER_API((DBG_API,
  148. Hresult,
  149. "MkParseDisplayNameEx",
  150. "%#x, %.80wq, %#x, %#x",
  151. pbc, szDispName, pchEaten, ppmk
  152. ));
  153. VDATEPTROUT(ppmk, LPMONIKER);
  154. VDATEPTROUT(pchEaten, ULONG);
  155. VDATEIFACE(pbc);
  156. VDATEPTRIN(szDispName, WCHAR);
  157. HRESULT hr = NOERROR;
  158. WCHAR wzUrlStr[MAX_URL_SIZE + 1];
  159. PerfDbgLog1(tagUrlApi, NULL, "+MkParseDisplayNameEx(%ws)",szDispName);
  160. // No need to canonicalize the URL here. It will be done later by
  161. // CreateURLMoniker call below.
  162. hr = ConstructURL(pbc, NULL, NULL, (LPWSTR)szDispName, wzUrlStr,
  163. sizeof(wzUrlStr), CU_NO_CANONICALIZE);
  164. // for unknown protocol (not registered)
  165. // instead of returning a Moniker which will fail on the Bind
  166. // we should call the system's MkParseDisplayName()
  167. if( hr == NOERROR )
  168. {
  169. // this is an internal API defined at trans\oinet.cxx
  170. if(!IsOInetProtocol(pbc, wzUrlStr))
  171. {
  172. // for Office backward compatibility...
  173. if( !StrCmpNIW(wzUrlStr, L"telnet", (sizeof("telnet") - 1) ) )
  174. {
  175. hr = NOERROR;
  176. }
  177. else
  178. {
  179. hr = INET_E_UNKNOWN_PROTOCOL;
  180. }
  181. }
  182. }
  183. if (hr == NOERROR)
  184. {
  185. IMoniker *pmk = NULL;
  186. // create a URL Moniker and call ParseDisplayName
  187. hr = CreateURLMoniker(NULL, wzUrlStr, &pmk);
  188. if (hr == NOERROR)
  189. {
  190. *pchEaten = wcslen(szDispName);
  191. *ppmk = pmk;
  192. }
  193. else
  194. {
  195. *pchEaten = 0;
  196. *ppmk = NULL;
  197. }
  198. }
  199. else
  200. {
  201. // call the standard OLE parser
  202. hr = MkParseDisplayName(pbc, szDispName, pchEaten, ppmk);
  203. }
  204. PerfDbgLog1(tagUrlApi, NULL, "-MkParseDisplayNameEx(%ws)",szDispName);
  205. DEBUG_LEAVE_API(hr);
  206. return hr;
  207. }
  208. //+---------------------------------------------------------------------------
  209. //
  210. // Function: CreateAsyncBindCtx
  211. //
  212. // Synopsis:
  213. //
  214. // Arguments: [reserved] --
  215. // [pBSCb] --
  216. // [ppBC] --
  217. //
  218. // Returns:
  219. //
  220. // History: 10-25-95 JohannP (Johann Posch) Created
  221. //
  222. // Notes:
  223. //
  224. //----------------------------------------------------------------------------
  225. STDAPI CreateAsyncBindCtx(DWORD reserved, IBindStatusCallback *pBSCb, IEnumFORMATETC *pEnum, IBindCtx **ppBC)
  226. {
  227. DEBUG_ENTER_API((DBG_API,
  228. Hresult,
  229. "CreateAsyncBindCtx",
  230. "%#x, %#x, %#x, %#x",
  231. reserved, pBSCb, pEnum, ppBC
  232. ));
  233. PerfDbgLog1(tagUrlApi, NULL, "+CreateAsyncBindCtx(%lx)",pBSCb);
  234. HRESULT hr = NOERROR;
  235. IUnknown *pUnk;
  236. if (pBSCb == NULL || ppBC == NULL)
  237. {
  238. hr = E_INVALIDARG;
  239. goto End;
  240. }
  241. hr = CreateBindCtx(reserved, ppBC);
  242. if (hr == NOERROR)
  243. {
  244. BIND_OPTS BindOpts;
  245. BindOpts.cbStruct = sizeof(BIND_OPTS);
  246. BindOpts.grfFlags = BIND_MAYBOTHERUSER;
  247. BindOpts.grfMode = STGM_READWRITE | STGM_SHARE_EXCLUSIVE;
  248. BindOpts.dwTickCountDeadline = 0L;
  249. ((IBindCtx *)*ppBC)->SetBindOptions(&BindOpts);
  250. // Register the IBindStatusCallback in the bind context.
  251. if (pBSCb != NULL)
  252. {
  253. CBSCHolder *pCBSCHolder;
  254. hr = GetBSCHolder(*ppBC, &pCBSCHolder);
  255. if (hr == NOERROR)
  256. {
  257. //hr = pCBSCHolder->AddNode(pBSCb, BSCO_ALLONIBSC);
  258. hr = pCBSCHolder->SetMainNode(pBSCb, 0);
  259. pCBSCHolder->Release();
  260. }
  261. }
  262. if ((hr == NOERROR) && (pEnum != NULL))
  263. {
  264. hr = RegisterFormatEnumerator(*ppBC, pEnum, 0);
  265. }
  266. }
  267. End:
  268. PerfDbgLog1(tagUrlApi, NULL, "-CreateAsyncBindCtx(%lx)",pBSCb);
  269. DEBUG_LEAVE_API(hr);
  270. return hr;
  271. }
  272. //+---------------------------------------------------------------------------
  273. //
  274. // Function: CreateAsyncBindCtxEx
  275. //
  276. // Synopsis:
  277. //
  278. // Arguments: [pbc] --
  279. // [dwOptions] --
  280. // [pBSCb] --
  281. // [pEnum] --
  282. // [ppBC] --
  283. // [reserved] --
  284. //
  285. // Returns:
  286. //
  287. // History: 10-09-1996 JohannP (Johann Posch) Created
  288. //
  289. // Notes:
  290. //
  291. //----------------------------------------------------------------------------
  292. STDAPI CreateAsyncBindCtxEx(IBindCtx *pbc, DWORD dwOptions, IBindStatusCallback *pBSCb, IEnumFORMATETC *pEnum, IBindCtx **ppBC, DWORD reserved)
  293. {
  294. DEBUG_ENTER_API((DBG_API,
  295. Hresult,
  296. "CreateAsyncBindCtxEx",
  297. "%#x, %#x, %#x, %#x, %#x, %#x",
  298. pbc, dwOptions, pBSCb, pEnum, ppBC, reserved
  299. ));
  300. PerfDbgLog1(tagUrlApi, NULL, "+CreateAsyncBindCtxEx(%lx)",pBSCb);
  301. HRESULT hr = NOERROR;
  302. IUnknown *pUnk;
  303. CBindCtx *pCBCtx = NULL;
  304. if (ppBC == NULL)
  305. {
  306. hr = E_INVALIDARG;
  307. }
  308. else
  309. {
  310. hr = CBindCtx::Create(&pCBCtx, pbc);
  311. if (hr == NOERROR)
  312. {
  313. *ppBC = pCBCtx;
  314. BIND_OPTS BindOpts;
  315. BindOpts.cbStruct = sizeof(BIND_OPTS);
  316. BindOpts.grfFlags = BIND_MAYBOTHERUSER;
  317. BindOpts.grfMode = STGM_READWRITE | STGM_SHARE_EXCLUSIVE;
  318. BindOpts.dwTickCountDeadline = 0L;
  319. ((IBindCtx *)*ppBC)->SetBindOptions(&BindOpts);
  320. // Register the IBindStatusCallback in the bind context.
  321. if (pBSCb != NULL)
  322. {
  323. CBSCHolder *pCBSCHolder;
  324. hr = GetBSCHolder(*ppBC, &pCBSCHolder);
  325. if (hr == NOERROR)
  326. {
  327. //hr = pCBSCHolder->AddNode(pBSCb, BSCO_ALLONIBSC);
  328. hr = pCBSCHolder->SetMainNode(pBSCb, 0);
  329. pCBSCHolder->Release();
  330. }
  331. }
  332. if ((hr == NOERROR) && (pEnum != NULL))
  333. {
  334. hr = RegisterFormatEnumerator(*ppBC, pEnum, 0);
  335. }
  336. }
  337. }
  338. PerfDbgLog1(tagUrlApi, NULL, "-CreateAsyncBindCtxEx(%lx)",pBSCb);
  339. DEBUG_LEAVE_API(hr);
  340. return hr;
  341. }
  342. //+---------------------------------------------------------------------------
  343. //
  344. // Function: IsAsyncMoniker
  345. //
  346. // Synopsis:
  347. //
  348. // Arguments: [pmk] --
  349. //
  350. // Returns:
  351. //
  352. // History: 2-13-96 JohannP (Johann Posch) Created
  353. // 3-05-96 JoePe - Changed to use QI for IID_IAsyncMoniker
  354. //
  355. // Notes:
  356. //
  357. //----------------------------------------------------------------------------
  358. STDAPI IsAsyncMoniker(IMoniker* pmk)
  359. {
  360. DEBUG_ENTER_API((DBG_API,
  361. Hresult,
  362. "IsAsyncMoniker",
  363. "%#x",
  364. pmk
  365. ));
  366. PerfDbgLog1(tagUrlApi, NULL, "+IsAsyncMoniker(%lx)", pmk);
  367. HRESULT hr = NOERROR;
  368. if (pmk)
  369. {
  370. IUnknown *punk;
  371. hr = pmk->QueryInterface(IID_IAsyncMoniker, (void**)&punk);
  372. if (hr == S_OK)
  373. {
  374. punk->Release();
  375. }
  376. else
  377. {
  378. hr = S_FALSE;
  379. }
  380. }
  381. else
  382. {
  383. hr = E_INVALIDARG;
  384. }
  385. PerfDbgLog2(tagUrlApi, NULL, "-IsAsyncMoniker(%lx, hr:%lx)",pmk, hr);
  386. DEBUG_LEAVE_API(hr);
  387. return hr;
  388. }
  389. //+---------------------------------------------------------------------------
  390. //
  391. // Function: RegisterBindStatusCallback
  392. //
  393. // Synopsis:
  394. //
  395. // Arguments: [pBC] --
  396. // [pBSCb] --
  397. // [reserved] --
  398. //
  399. // Returns:
  400. //
  401. // History: 12-13-95 JohannP (Johann Posch) Created
  402. //
  403. // Notes:
  404. //
  405. //----------------------------------------------------------------------------
  406. STDAPI RegisterBindStatusCallback(LPBC pBC, IBindStatusCallback *pBSCb,IBindStatusCallback **ppBSCBPrev, DWORD reserved)
  407. {
  408. DEBUG_ENTER_API((DBG_API,
  409. Hresult,
  410. "RegisterBindStatusCallback",
  411. "%#x, %#x, %#x, %#x",
  412. pBC, pBSCb, ppBSCBPrev, reserved
  413. ));
  414. HRESULT hr;
  415. PerfDbgLog2(tagUrlApi, NULL, "+RegisterBindStatusCallback(pBC:%lx, pBSCb:%lx)",pBC,pBSCb);
  416. if (ppBSCBPrev)
  417. {
  418. *ppBSCBPrev = NULL;
  419. }
  420. // Register the IBindStatusCallback in the bind context.
  421. if (pBSCb != NULL && pBC != NULL)
  422. {
  423. CBSCHolder *pCBSCHolder;
  424. IBindStatusCallback *pBSCBUnused = NULL;
  425. // Note: get the previous register IBSC - this
  426. // might be actual a marshaled object
  427. //
  428. if (ppBSCBPrev)
  429. {
  430. // ask for the IBSC and NOT the holder since the holder does NOT get marshaled
  431. hr = GetObjectParam(pBC, REG_BSCB_HOLDER, IID_IBindStatusCallback, (IUnknown **)ppBSCBPrev);
  432. PerfDbgLog1(tagUrlApi, NULL, "=== RegisterBindStatusCallback (pBSCBPrev:%lx)",*ppBSCBPrev);
  433. }
  434. hr = GetBSCHolder(pBC, &pCBSCHolder);
  435. if (hr == NOERROR)
  436. {
  437. hr = pCBSCHolder->SetMainNode(pBSCb, &pBSCBUnused);
  438. pCBSCHolder->Release();
  439. }
  440. if (pBSCBUnused)
  441. {
  442. if (ppBSCBPrev && *ppBSCBPrev)
  443. {
  444. (*ppBSCBPrev)->Release();
  445. }
  446. if (ppBSCBPrev)
  447. {
  448. *ppBSCBPrev = pBSCBUnused;
  449. }
  450. else
  451. {
  452. pBSCBUnused->Release();
  453. }
  454. }
  455. }
  456. else
  457. {
  458. UrlMkAssert((pBSCb != NULL && pBC != NULL && "Invalid argument passed in RegisterBindStatusCallback"));
  459. hr = E_INVALIDARG;
  460. }
  461. PerfDbgLog1(tagUrlApi, NULL, "-RegisterBindStatusCallback(hr:%lx)",hr);
  462. DEBUG_LEAVE_API(hr);
  463. return hr;
  464. }
  465. //+---------------------------------------------------------------------------
  466. //
  467. // Function: RevokeBindStatusCallback
  468. //
  469. // Synopsis:
  470. //
  471. // Arguments: [pBC] --
  472. // [pBSCb] --
  473. // [reserved] --
  474. //
  475. // Returns:
  476. //
  477. // History: 12-13-95 JohannP (Johann Posch) Created
  478. //
  479. // Notes:
  480. //
  481. //----------------------------------------------------------------------------
  482. STDAPI RevokeBindStatusCallback(LPBC pBC, IBindStatusCallback *pBSCb)
  483. {
  484. DEBUG_ENTER_API((DBG_API,
  485. Hresult,
  486. "RevokeBindStatusCallback",
  487. "%#x, %#x",
  488. pBC, pBSCb
  489. ));
  490. HRESULT hr;
  491. PerfDbgLog2(tagUrlApi, NULL, "+RevokeBindStatusCallback(pBC:%lx, pBSCb:%lx)",pBC,pBSCb);
  492. CBSCHolder *pCBSCHolder;
  493. if (pBSCb != NULL && pBC != NULL)
  494. {
  495. hr = GetBSCHolder(pBC, &pCBSCHolder);
  496. if (hr == NOERROR)
  497. {
  498. hr = pCBSCHolder->RemoveNode(pBSCb);
  499. if (hr == S_FALSE)
  500. {
  501. // remove the holder from this bind context
  502. // the holder will be deleted since by the
  503. // last release
  504. PerfDbgLog2(tagUrlApi, NULL, "=== RevokeBindStatusCallback Revoke Holder Start (pBndCtx:%lx, -> %lx)",pBC, pBSCb);
  505. hr = pBC->RevokeObjectParam(REG_BSCB_HOLDER);
  506. PerfDbgLog2(tagUrlApi, NULL, "=== RevokeBindStatusCallback Revoke Holder Done (pBndCtx:%lx, -> %lx)",pBC, pBSCb);
  507. }
  508. else
  509. {
  510. hr = NOERROR;
  511. }
  512. pCBSCHolder->Release();
  513. }
  514. }
  515. else
  516. {
  517. UrlMkAssert((pBSCb != NULL && pBC != NULL && "Invalid argument passed in RevokeBindStatusCallback"));
  518. hr = E_INVALIDARG;
  519. }
  520. PerfDbgLog2(tagUrlApi, NULL, "-RevokeBindStatusCallback(%lx, hr:%lx)",pBSCb, hr);
  521. DEBUG_LEAVE_API(hr);
  522. return hr;
  523. }
  524. //+---------------------------------------------------------------------------
  525. //
  526. // Function: GetClassURL
  527. //
  528. // Synopsis:
  529. //
  530. // Arguments: [szURL] --
  531. // [pClsID] --
  532. //
  533. // Returns:
  534. //
  535. //
  536. // Notes: BUGBUG: do we have to implement this api? Is it really needed?
  537. //
  538. //----------------------------------------------------------------------------
  539. STDAPI GetClassURL(LPCWSTR szURL, CLSID *pClsID)
  540. {
  541. DEBUG_ENTER_API((DBG_API,
  542. Hresult,
  543. "GetClassURL",
  544. "%.80wq, %#x",
  545. szURL, pClsID
  546. ));
  547. HRESULT hr = E_NOTIMPL;
  548. PerfDbgLog(tagUrlApi, NULL, "+GetClassURL");
  549. PerfDbgLog(tagUrlApi, NULL, "-GetClassURL");
  550. DEBUG_LEAVE_API(hr);
  551. return hr;
  552. }
  553. //+---------------------------------------------------------------------------
  554. //
  555. // Function: RegisterMediaTypesW
  556. //
  557. // Synopsis: registers a media types for the current apartment
  558. //
  559. // Arguments: [ctypes] --
  560. // [rgszTypes] --
  561. // [rgcfTypes] --
  562. //
  563. // Returns:
  564. //
  565. // History: 1-20-96 JohannP (Johann Posch) Created
  566. //
  567. // Notes: Media types are registered on apartment level
  568. //
  569. //----------------------------------------------------------------------------
  570. HRESULT RegisterMediaTypesW(UINT ctypes, const LPCWSTR* rgszTypes, CLIPFORMAT* rgcfTypes)
  571. {
  572. DEBUG_ENTER_API((DBG_API,
  573. Hresult,
  574. "RegisterMediaTypesW",
  575. "%u, %#x, %#x",
  576. ctypes, rgszTypes, rgcfTypes
  577. ));
  578. HRESULT hr = E_NOTIMPL;
  579. PerfDbgLog(tagUrlApi, NULL, "+RegisterMediaTypesW");
  580. CMediaTypeHolder *pCMHolder;
  581. CLock lck(g_mxsMedia);
  582. #ifdef UNUSED
  583. pCMHolder = GetMediaTypeHolder();
  584. if (pCMHolder)
  585. {
  586. hr = pCMHolder->Register(ctypes, rgszTypes, rgcfTypes);
  587. }
  588. else
  589. {
  590. hr = E_OUTOFMEMORY;
  591. }
  592. #endif //UNUSED
  593. PerfDbgLog(tagUrlApi, NULL, "-RegisterMediaTypesW");
  594. DEBUG_LEAVE_API(hr);
  595. return hr;
  596. }
  597. //+---------------------------------------------------------------------------
  598. //
  599. // Function: RegisterMediaTypes
  600. //
  601. // Synopsis: registers a media types for the current apartment
  602. //
  603. // Arguments: [ctypes] --
  604. // [rgszTypes] --
  605. // [rgcfTypes] --
  606. //
  607. // Returns:
  608. //
  609. // History: 1-20-96 JohannP (Johann Posch) Created
  610. //
  611. // Notes: Media types are registered on apartment level
  612. //
  613. //----------------------------------------------------------------------------
  614. HRESULT RegisterMediaTypes(UINT ctypes, const LPCSTR* rgszTypes, CLIPFORMAT* rgcfTypes)
  615. {
  616. DEBUG_ENTER_API((DBG_API,
  617. Hresult,
  618. "RegisterMediaTypes",
  619. "%u, %#x, %#x",
  620. ctypes, rgszTypes, rgcfTypes
  621. ));
  622. HRESULT hr;
  623. PerfDbgLog(tagUrlApi, NULL, "+RegisterMediaTypes");
  624. CMediaTypeHolder *pCMHolder;
  625. CLock lck(g_mxsMedia);
  626. if (ctypes > 0)
  627. {
  628. pCMHolder = GetMediaTypeHolder();
  629. if (pCMHolder)
  630. {
  631. hr = pCMHolder->Register(ctypes, rgszTypes, rgcfTypes);
  632. }
  633. else
  634. {
  635. hr = E_OUTOFMEMORY;
  636. }
  637. }
  638. else
  639. {
  640. hr = E_INVALIDARG;
  641. }
  642. PerfDbgLog(tagUrlApi, NULL, "-RegisterMediaTypes");
  643. DEBUG_LEAVE_API(hr);
  644. return hr;
  645. }
  646. //+---------------------------------------------------------------------------
  647. //
  648. // Function: RegisterMediaTypeClass
  649. //
  650. // Synopsis:
  651. //
  652. // Arguments: [UINT] --
  653. // [ctypes] --
  654. // [rgszTypes] --
  655. // [rgclsID] --
  656. // [reserved] --
  657. //
  658. // Returns:
  659. //
  660. // History: 3-26-96 JohannP (Johann Posch) Created
  661. //
  662. // Notes:
  663. //
  664. //----------------------------------------------------------------------------
  665. STDAPI RegisterMediaTypeClass(LPBC pBC,UINT ctypes, const LPCSTR* rgszTypes, CLSID *rgclsID, DWORD reserved)
  666. {
  667. DEBUG_ENTER_API((DBG_API,
  668. Hresult,
  669. "RegisterMediaTypeClass",
  670. "%#x, %u, %#x, %#x, %#x",
  671. pBC, ctypes, rgszTypes, rgclsID, reserved
  672. ));
  673. HRESULT hr = E_FAIL;
  674. PerfDbgLog(tagUrlApi, NULL, "+RegisterMediaTypeClass");
  675. IMediaHolder *pIMHolder = NULL;
  676. if (ctypes > 0)
  677. {
  678. hr = GetObjectParam(pBC, REG_MEDIA_HOLDER, IID_IMediaHolder, (IUnknown**)&pIMHolder);
  679. if (pIMHolder == NULL)
  680. {
  681. pIMHolder = new CMediaTypeHolder();
  682. if (pIMHolder)
  683. {
  684. hr = pBC->RegisterObjectParam(REG_MEDIA_HOLDER, pIMHolder);
  685. }
  686. else
  687. {
  688. hr = E_OUTOFMEMORY;
  689. }
  690. }
  691. }
  692. else
  693. {
  694. hr = E_INVALIDARG;
  695. }
  696. if (hr == NOERROR)
  697. {
  698. UrlMkAssert((pIMHolder));
  699. hr = pIMHolder->RegisterClassMapping(ctypes,(const char **) rgszTypes, rgclsID, 0);
  700. }
  701. if (pIMHolder)
  702. {
  703. pIMHolder->Release();
  704. }
  705. PerfDbgLog(tagUrlApi, NULL, "-RegisterMediaTypeClass");
  706. DEBUG_LEAVE_API(hr);
  707. return hr;
  708. }
  709. //+---------------------------------------------------------------------------
  710. //
  711. // Function: FindMediaTypeClass
  712. //
  713. // Synopsis:
  714. //
  715. // Arguments: [pBC] --
  716. // [pszType] --
  717. // [pclsID] --
  718. // [reserved] --
  719. //
  720. // Returns:
  721. //
  722. // History: 3-26-96 JohannP (Johann Posch) Created
  723. //
  724. // Notes:
  725. //
  726. //----------------------------------------------------------------------------
  727. STDAPI FindMediaTypeClass(LPBC pBC, LPCSTR pszType, CLSID *pclsID, DWORD reserved)
  728. {
  729. DEBUG_ENTER_API((DBG_API,
  730. Hresult,
  731. "FindMediaTypeClass",
  732. "%#x, %.80q, %#x, %#x",
  733. pBC, pszType, pclsID, reserved
  734. ));
  735. HRESULT hr = NOERROR;
  736. PerfDbgLog(tagUrlApi, NULL, "+FindMediaTypeClass");
  737. IMediaHolder *pIMHolder;
  738. CLIPFORMAT cfTypes = CF_NULL;
  739. TransAssert((pclsID));
  740. *pclsID = CLSID_NULL;
  741. cfTypes = (CLIPFORMAT) RegisterClipboardFormat(pszType);
  742. if (cfTypes != CF_NULL)
  743. {
  744. hr = GetObjectParam(pBC, REG_MEDIA_HOLDER, IID_IMediaHolder, (IUnknown**)&pIMHolder);
  745. if (pIMHolder)
  746. {
  747. hr = pIMHolder->FindClassMapping(pszType, pclsID, 0);
  748. pIMHolder->Release();
  749. }
  750. }
  751. else
  752. {
  753. hr = E_INVALIDARG;
  754. }
  755. PerfDbgLog1(tagUrlApi, NULL, "-FindMediaTypeClass (hr:%lx)", hr);
  756. DEBUG_LEAVE_API(hr);
  757. return hr;
  758. }
  759. //+---------------------------------------------------------------------------
  760. //
  761. // Function: CreateFormatEnumerator
  762. //
  763. // Synopsis:
  764. //
  765. // Arguments: [cfmtetc] --
  766. // [rgfmtetc] --
  767. // [ppenumfmtetc] --
  768. //
  769. // Returns:
  770. //
  771. // History: 12-22-95 JohannP (Johann Posch) Created
  772. //
  773. // Notes:
  774. //
  775. //----------------------------------------------------------------------------
  776. HRESULT CreateFormatEnumerator( UINT cfmtetc, FORMATETC* rgfmtetc, IEnumFORMATETC** ppenumfmtetc)
  777. {
  778. DEBUG_ENTER_API((DBG_API,
  779. Hresult,
  780. "CreateFormatEnumerator",
  781. "%u, %#x, %#x",
  782. cfmtetc, rgfmtetc, ppenumfmtetc
  783. ));
  784. HRESULT hr = NOERROR;
  785. PerfDbgLog(tagUrlApi, NULL, "+CreateFormatEnumerator");
  786. if (ppenumfmtetc != NULL)
  787. {
  788. CEnumFmtEtc *pCEnum;
  789. pCEnum = CEnumFmtEtc::Create(cfmtetc, rgfmtetc);
  790. if (pCEnum)
  791. {
  792. *ppenumfmtetc = (IEnumFORMATETC *)pCEnum;
  793. }
  794. else
  795. {
  796. *ppenumfmtetc = NULL;
  797. hr = E_FAIL;
  798. }
  799. }
  800. else
  801. {
  802. hr = E_INVALIDARG;
  803. }
  804. PerfDbgLog(tagUrlApi, NULL, "-CreateFormatEnumerator");
  805. DEBUG_LEAVE_API(hr);
  806. return hr;
  807. }
  808. //+---------------------------------------------------------------------------
  809. //
  810. // Function: BindAsyncMoniker
  811. //
  812. // Synopsis:
  813. //
  814. // Arguments: [pmk] --
  815. // [grfOpt] --
  816. // [iidResult] --
  817. // [ppvResult] --
  818. //
  819. // Returns:
  820. //
  821. //
  822. // Notes:
  823. //
  824. //----------------------------------------------------------------------------
  825. STDAPI BindAsyncMoniker (LPMONIKER pmk, DWORD grfOpt, IBindStatusCallback *pIBSCb, REFIID iidResult, LPVOID FAR* ppvResult)
  826. {
  827. DEBUG_ENTER_API((DBG_API,
  828. Hresult,
  829. "BindAsyncMoniker",
  830. "%#x, %#x, %#x, %#x, %#x",
  831. pmk, grfOpt, pIBSCb, iidResult, ppvResult
  832. ));
  833. VDATEPTROUT(ppvResult,LPVOID);
  834. *ppvResult = NULL;
  835. VDATEIFACE(pmk);
  836. VDATEIID(iidResult);
  837. LPBC pbc = NULL;
  838. HRESULT hr = E_INVALIDARG;
  839. PerfDbgLog1(tagUrlApi, NULL, "+BindAsyncMoniker(%lx)",pmk);
  840. if (pmk)
  841. {
  842. hr = CreateAsyncBindCtx(0, pIBSCb, NULL, &pbc);
  843. if (hr == NOERROR)
  844. {
  845. hr = pmk->BindToObject(pbc, NULL, iidResult, ppvResult);
  846. pbc->Release();
  847. }
  848. }
  849. PerfDbgLog1(tagUrlApi, NULL, "-BindAsyncMoniker(%lx)",pmk);
  850. DEBUG_LEAVE_API(hr);
  851. return hr;
  852. }
  853. //+---------------------------------------------------------------------------
  854. //
  855. // Function: RegisterFormatEnumerator
  856. //
  857. // Synopsis:
  858. //
  859. // Arguments: [pBC] --
  860. // [pEFetc] --
  861. // [reserved] --
  862. //
  863. // Returns:
  864. //
  865. // History: 1-19-96 JohannP (Johann Posch) Created
  866. //
  867. // Notes:
  868. //
  869. //----------------------------------------------------------------------------
  870. STDAPI RegisterFormatEnumerator(LPBC pBC, IEnumFORMATETC *pEFetc, DWORD reserved)
  871. {
  872. DEBUG_ENTER_API((DBG_API,
  873. Hresult,
  874. "RegisterFormatEnumerator",
  875. "%#x, %#x, %#x",
  876. pBC, pEFetc, reserved
  877. ));
  878. HRESULT hr = E_INVALIDARG;
  879. PerfDbgLog1(tagUrlApi, NULL, "+RegisterFormatEnumerator(%lx)",pBC);
  880. if (pBC)
  881. {
  882. hr = pBC->RegisterObjectParam(REG_ENUMFORMATETC, pEFetc);
  883. }
  884. PerfDbgLog1(tagUrlApi, NULL, "-RegisterFormatEnumerator(%lx)",pBC);
  885. DEBUG_LEAVE_API(hr);
  886. return hr;
  887. }
  888. //+---------------------------------------------------------------------------
  889. //
  890. // Function: RevokeFormatEnumerator
  891. //
  892. // Synopsis:
  893. //
  894. // Arguments: [pBC] --
  895. // [pEFetc] --
  896. //
  897. // Returns:
  898. //
  899. // History: 1-19-96 JohannP (Johann Posch) Created
  900. //
  901. // Notes:
  902. //
  903. //----------------------------------------------------------------------------
  904. STDAPI RevokeFormatEnumerator(LPBC pBC, IEnumFORMATETC *pEFetc)
  905. {
  906. DEBUG_ENTER_API((DBG_API,
  907. Hresult,
  908. "RevokeFormatEnumerator",
  909. "%#x, %#x",
  910. pBC, pEFetc
  911. ));
  912. HRESULT hr = E_INVALIDARG;
  913. PerfDbgLog1(tagUrlApi, NULL, "+RevokeFormatEnumerator(%lx)",pBC);
  914. if (pBC)
  915. {
  916. hr = pBC->RevokeObjectParam(REG_ENUMFORMATETC);
  917. }
  918. PerfDbgLog1(tagUrlApi, NULL, "-RevokeFormatEnumerator(%lx)",pBC);
  919. DEBUG_LEAVE_API(hr);
  920. return hr;
  921. }