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.

550 lines
13 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: urlcf.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 12-22-95 JohannP (Johann Posch) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <mon.h>
  18. #include <eapp.h>
  19. #include "urlcf.hxx"
  20. #ifndef unix
  21. #include "..\eapp\protbase.hxx"
  22. #include "..\trans\urlmk.hxx"
  23. #include "..\trans\bindctx.hxx"
  24. #include "..\trans\oinet.hxx"
  25. #include "..\download\cdl.h"
  26. #else
  27. #include "../eapp/protbase.hxx"
  28. #include "../trans/urlmk.hxx"
  29. #include "../trans/bindctx.hxx"
  30. #include "../trans/oinet.hxx"
  31. #include "../download/cdl.h"
  32. #endif /* unix */
  33. //+---------------------------------------------------------------------------
  34. //
  35. // Method: CUrlClsFact::Create
  36. //
  37. // Synopsis:
  38. //
  39. // Arguments: [clsid] --
  40. // [ppCF] --
  41. //
  42. // Returns:
  43. //
  44. // History: 12-22-95 JohannP (Johann Posch) Created
  45. //
  46. // Notes:
  47. //
  48. //----------------------------------------------------------------------------
  49. HRESULT CUrlClsFact::Create(REFCLSID clsid, CUrlClsFact **ppCF)
  50. {
  51. UrlMkDebugOut((DEB_URLMON, "NULL _IN CUrlClsFact::Create\n"));
  52. HRESULT hr = NOERROR;
  53. CUrlClsFact * pCF = NULL;
  54. DWORD dwId = IsKnownOInetProtocolClass( (CLSID*)&clsid );
  55. if ( (dwId != DLD_PROTOCOL_NONE)
  56. || (clsid == CLSID_StdURLMoniker)
  57. || (clsid == CLSID_UrlMkBindCtx)
  58. || (clsid == CLSID_StdURLProtocol)
  59. || (clsid == CLSID_SoftDistExt)
  60. || (clsid == CLSID_DeCompMimeFilter)
  61. || (clsid == CLSID_StdEncodingFilterFac)
  62. || (clsid == CLSID_ClassInstallFilter)
  63. || (clsid == CLSID_CdlProtocol)
  64. || (clsid == CLSID_InternetSecurityManager)
  65. || (clsid == CLSID_InternetZoneManager)
  66. )
  67. {
  68. pCF = (CUrlClsFact *) new CUrlClsFact(clsid, dwId);
  69. }
  70. if (pCF == NULL)
  71. {
  72. hr = E_OUTOFMEMORY;
  73. }
  74. else
  75. {
  76. *ppCF = pCF;
  77. }
  78. UrlMkDebugOut((DEB_URLMON, "%p OUT CUrlClsFact::Create (hr:%lx\n", pCF,hr));
  79. return hr;
  80. }
  81. //+---------------------------------------------------------------------------
  82. //
  83. // Method: CUrlClsFact::CUrlClsFact
  84. //
  85. // Synopsis: constructor
  86. //
  87. // Arguments: [clsid] --
  88. //
  89. // Returns:
  90. //
  91. // History: 12-22-95 JohannP (Johann Posch) Created
  92. //
  93. // Notes: we need to keep a refcount on the dll if for each object given to
  94. // outside, including ClassFactories.
  95. // The corresponding DllRelease is in the destructor
  96. //
  97. //----------------------------------------------------------------------------
  98. CUrlClsFact::CUrlClsFact(REFCLSID clsid, DWORD dwId) : _CRefs(), _CLocks(0)
  99. {
  100. _ClsID = clsid;
  101. _dwId = dwId;
  102. DllAddRef();
  103. }
  104. //+---------------------------------------------------------------------------
  105. //
  106. // Method: CUrlClsFact::~CUrlClsFact
  107. //
  108. // Synopsis:
  109. //
  110. // Arguments: (none)
  111. //
  112. // Returns:
  113. //
  114. // History: 12-22-95 JohannP (Johann Posch) Created
  115. //
  116. // Notes:
  117. //
  118. //----------------------------------------------------------------------------
  119. CUrlClsFact::~CUrlClsFact()
  120. {
  121. DllRelease();
  122. }
  123. //+---------------------------------------------------------------------------
  124. //
  125. // Method: CUrlClsFact::CreateInstance
  126. //
  127. // Synopsis: creates an instance of an Explode Object
  128. //
  129. // Arguments: [pUnkOuter] -- controlling unknown (must be NULL)
  130. // [riid] -- id of desired interface
  131. // [ppv] -- pointer to receive the interface
  132. //
  133. // Returns:
  134. //
  135. // History: 12-22-95 JohannP (Johann Posch) Created
  136. //
  137. // Notes: S_OK - success
  138. // CLASS_E_NOAGGREATION - the caller tried to aggregate
  139. // CLASS_E_CLASSNOTAVAILABLE - couldn't initialize the class
  140. // E_OUTOFMEMORY - not enough memory to instantiate class
  141. //
  142. //----------------------------------------------------------------------------
  143. STDMETHODIMP CUrlClsFact::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID * ppv)
  144. {
  145. //UrlMkDebugOut((DEB_URLMON, "%p _IN CUrlClsFact::CreateInstance\n", this));
  146. HRESULT hr = NOERROR;
  147. // Class factory init time, the pointer to the creation function of
  148. // the object is given. Use that to create the object
  149. //DumpIID(riid);
  150. //DumpIID(_rClsID);
  151. if (riid == IID_IClassFactory)
  152. {
  153. *ppv = (IClassFactory *)this;
  154. AddRef();
  155. }
  156. else if (_dwId != DLD_PROTOCOL_NONE)
  157. {
  158. hr = CreateKnownProtocolInstance(_dwId, _ClsID, pUnkOuter, riid, (IUnknown **)ppv);
  159. }
  160. else if (_ClsID == CLSID_StdURLMoniker)
  161. {
  162. CUrlMon * pMnk = NULL;
  163. LPWSTR szUrl = NULL;
  164. if ((pMnk = new CUrlMon(szUrl)) != NULL)
  165. {
  166. hr = pMnk->QueryInterface(riid, ppv);
  167. pMnk->Release();
  168. }
  169. else
  170. {
  171. hr = E_OUTOFMEMORY;
  172. }
  173. }
  174. else if (_ClsID == CLSID_UrlMkBindCtx)
  175. {
  176. CBindCtx *pCBCtx = NULL;
  177. hr = CBindCtx::Create(&pCBCtx);
  178. if (hr == NOERROR)
  179. {
  180. TransAssert((pCBCtx));
  181. hr = pCBCtx->QueryInterface(riid, ppv);
  182. pCBCtx->Release();
  183. }
  184. else
  185. {
  186. hr = E_OUTOFMEMORY;
  187. }
  188. }
  189. else if (_ClsID == CLSID_StdURLProtocol)
  190. {
  191. // BUGBUG: add protocol here
  192. }
  193. else if (_ClsID == CLSID_InternetSecurityManager)
  194. {
  195. hr = InternetCreateSecurityManager(pUnkOuter, riid, ppv, 0);
  196. }
  197. else if (_ClsID == CLSID_InternetZoneManager)
  198. {
  199. hr = InternetCreateZoneManager(pUnkOuter, riid, ppv, 0);
  200. }
  201. else if (_ClsID == CLSID_SoftDistExt)
  202. {
  203. CSoftDist * pSoftDist = NULL;
  204. if ((pSoftDist = new CSoftDist()) != NULL)
  205. {
  206. hr = pSoftDist->QueryInterface(riid, ppv);
  207. pSoftDist->Release();
  208. }
  209. else
  210. {
  211. hr = E_OUTOFMEMORY;
  212. }
  213. }
  214. else if( _ClsID == CLSID_DeCompMimeFilter)
  215. {
  216. hr = CLASS_E_CLASSNOTAVAILABLE;
  217. if( pUnkOuter)
  218. hr = CLASS_E_NOAGGREGATION;
  219. else
  220. {
  221. CMimeFt* pMft = NULL;
  222. hr = CMimeFt::Create(&pMft);
  223. if( (hr == NOERROR) && pMft )
  224. {
  225. hr = pMft->QueryInterface(riid, ppv);
  226. pMft->Release();
  227. }
  228. }
  229. }
  230. else if( _ClsID == CLSID_StdEncodingFilterFac)
  231. {
  232. hr = CLASS_E_CLASSNOTAVAILABLE;
  233. if( pUnkOuter)
  234. hr = CLASS_E_NOAGGREGATION;
  235. else
  236. {
  237. *ppv = NULL;
  238. *ppv = new CEncodingFilterFactory;
  239. if( *ppv == NULL )
  240. hr = E_OUTOFMEMORY;
  241. else
  242. hr = ((IEncodingFilterFactory*)(*ppv))->AddRef();
  243. }
  244. }
  245. else if( _ClsID == CLSID_ClassInstallFilter)
  246. {
  247. hr = CLASS_E_CLASSNOTAVAILABLE;
  248. if (pUnkOuter)
  249. hr = CLASS_E_NOAGGREGATION;
  250. else
  251. {
  252. CClassInstallFilter *pCIF = NULL;
  253. pCIF = new CClassInstallFilter();
  254. *ppv = (LPVOID)(IOInetProtocol *)pCIF;
  255. if (!*ppv)
  256. hr = E_OUTOFMEMORY;
  257. else
  258. hr = S_OK;
  259. }
  260. }
  261. else if (_ClsID == CLSID_CdlProtocol)
  262. {
  263. hr = CreateAPP(_ClsID, pUnkOuter, riid, (IUnknown **)ppv);
  264. }
  265. UrlMkDebugOut((DEB_URLMON, "%p OUT CUrlClsFact::CreateInstance (hr:%lx)\n", this,hr));
  266. return hr;
  267. }
  268. //+---------------------------------------------------------------------------
  269. //
  270. // Method: CUrlClsFact::LockServer
  271. //
  272. // Synopsis: locks the server, preventing it from being unloaded
  273. //
  274. // Arguments: [fLock] -- TRUE to lock, FALSE to unlock
  275. //
  276. // Returns:
  277. //
  278. // History: 12-22-95 JohannP (Johann Posch) Created
  279. //
  280. // Notes:
  281. //
  282. //----------------------------------------------------------------------------
  283. STDMETHODIMP CUrlClsFact::LockServer(BOOL fLock)
  284. {
  285. UrlMkDebugOut((DEB_URLMON, "%p _IN CUrlClsFact::LockServer\n", this));
  286. HRESULT hr = NOERROR;
  287. if (fLock)
  288. {
  289. if (++_CLocks == 1)
  290. {
  291. DllAddRef();
  292. }
  293. }
  294. else
  295. {
  296. UrlMkAssert((_CLocks > 0));
  297. if (_CLocks > 0)
  298. {
  299. if (--_CLocks == 0)
  300. {
  301. DllRelease();
  302. }
  303. }
  304. }
  305. UrlMkDebugOut((DEB_URLMON, "%p OUT CUrlClsFact::LockServer (hr:%lx)\n", this,hr));
  306. return hr;
  307. }
  308. //+---------------------------------------------------------------------------
  309. //
  310. // Method: CUrlClsFact::QueryInterface
  311. //
  312. // Synopsis:
  313. //
  314. // Arguments: [riid] --
  315. // [ppvObj] --
  316. //
  317. // Returns:
  318. //
  319. // History: 12-22-95 JohannP (Johann Posch) Created
  320. //
  321. // Notes:
  322. //
  323. //----------------------------------------------------------------------------
  324. STDMETHODIMP CUrlClsFact::QueryInterface(REFIID riid, void **ppvObj)
  325. {
  326. VDATEPTROUT(ppvObj, void *);
  327. HRESULT hr = NOERROR;
  328. UrlMkDebugOut((DEB_URLMON, "%p _IN CUrlClsFact::QueryInterface\n", this));
  329. if ( riid == IID_IUnknown
  330. || riid == IID_IClassFactory)
  331. {
  332. *ppvObj = this;
  333. }
  334. else
  335. {
  336. *ppvObj = NULL;
  337. hr = E_NOINTERFACE;
  338. }
  339. if (hr == NOERROR)
  340. {
  341. AddRef();
  342. }
  343. UrlMkDebugOut((DEB_URLMON, "%p OUT CUrlClsFact::QueryInterface (hr:%lx\n", this,hr));
  344. return hr;
  345. }
  346. //+---------------------------------------------------------------------------
  347. //
  348. // Function: CUrlClsFact::AddRef
  349. //
  350. // Synopsis:
  351. //
  352. // Arguments: [ULONG] --
  353. //
  354. // Returns:
  355. //
  356. // History: 12-22-95 JohannP (Johann Posch) Created
  357. //
  358. // Notes:
  359. //
  360. //----------------------------------------------------------------------------
  361. STDMETHODIMP_(ULONG) CUrlClsFact::AddRef(void)
  362. {
  363. UrlMkDebugOut((DEB_URLMON, "%p _IN CUrlClsFact::AddRef\n", this));
  364. LONG lRet = ++_CRefs;
  365. UrlMkDebugOut((DEB_URLMON, "%p OUT CUrlClsFact::AddRef (cRefs:%ld)\n", this,lRet));
  366. return lRet;
  367. }
  368. //+---------------------------------------------------------------------------
  369. //
  370. // Function: CUrlClsFact::Release
  371. //
  372. // Synopsis:
  373. //
  374. // Arguments: [ULONG] --
  375. //
  376. // Returns:
  377. //
  378. // History: 12-22-95 JohannP (Johann Posch) Created
  379. //
  380. // Notes:
  381. //
  382. //----------------------------------------------------------------------------
  383. STDMETHODIMP_(ULONG) CUrlClsFact::Release(void)
  384. {
  385. UrlMkDebugOut((DEB_URLMON, "%p _IN CUrlClsFact::Release\n", this));
  386. LONG lRet = --_CRefs;
  387. if (_CRefs == 0)
  388. {
  389. delete this;
  390. }
  391. UrlMkDebugOut((DEB_URLMON, "%p OUT CUrlClsFact::Release (cRefs:%ld)\n", this,lRet));
  392. return lRet;
  393. }
  394. #if DBG==1
  395. HRESULT DumpIID(REFIID riid)
  396. {
  397. HRESULT hr;
  398. LPOLESTR pszStr = NULL;
  399. hr = StringFromCLSID(riid, &pszStr);
  400. UrlMkDebugOut((DEB_BINDING, "API >>> DumpIID (riid:%ws) \n", pszStr));
  401. if (pszStr)
  402. {
  403. delete pszStr;
  404. }
  405. return hr;
  406. }
  407. #endif
  408. #ifdef FOR_SHDOCVW
  409. //+---------------------------------------------------------------------------
  410. //
  411. // Function: GetObjectOffFileMoniker
  412. //
  413. // Synopsis: tries to create on object using a file moniker
  414. // this is a work around for OLE
  415. //
  416. // Arguments: [pMnk] --
  417. // [REFIID] --
  418. // [riid] --
  419. // [ppv] --
  420. //
  421. // Returns:
  422. //
  423. // History: 3-10-96 JohannP (Johann Posch) Created
  424. //
  425. // Notes: See comments inside function
  426. //
  427. //----------------------------------------------------------------------------
  428. HRESULT GetObjectOffFileMoniker(IMoniker *pMnk, IBindCtx *pbc,REFIID riid, void **ppv)
  429. {
  430. HRESULT hr = E_FAIL;
  431. DWORD dwMnk;
  432. LPWSTR wzFilename = NULL;
  433. CLSID * pClsID = NULL;
  434. IUnknown * pUnk = NULL;
  435. IPersistFile *pPersistFile = NULL;
  436. BIND_OPTS bindopts;
  437. bindopts.cbStruct = sizeof(BIND_OPTS);
  438. hr = pbc->GetBindOptions(&bindopts);
  439. pMnk->IsSystemMoniker(&dwMnk);
  440. if (dwMnk != MKSYS_FILEMONIKER)
  441. {
  442. goto Done;
  443. }
  444. //get path and filename
  445. hr = pMnk->GetDisplayName(NULL, NULL, &wzFilename);
  446. if (wzFilename == NULL)
  447. {
  448. goto Done;
  449. }
  450. // try to find class
  451. hr = GetClassFile(wzFilename, pClsID);
  452. if (hr != NOERROR)
  453. {
  454. goto Done;
  455. }
  456. // create object
  457. hr = CoCreateInstance(*pClsID, NULL, CLSCTX_INPROC_SERVER |CLSCTX_LOCAL_SERVER,
  458. riid, (void**)&pUnk);
  459. if (hr != NOERROR)
  460. {
  461. goto Done;
  462. }
  463. // ask for the IPersistFile interface
  464. hr = pUnk->QueryInterface(IID_IPersistFile, (void**)&pPersistFile);
  465. if (hr != NOERROR)
  466. {
  467. goto Done;
  468. }
  469. // load the object
  470. hr = pPersistFile->Load(wzFilename, bindopts.grfMode);
  471. Done:
  472. if (hr != NOERROR)
  473. {
  474. if (pUnk)
  475. {
  476. pUnk->Release();
  477. }
  478. }
  479. else
  480. {
  481. *ppv = (void *)pUnk;
  482. }
  483. if (pPersistFile)
  484. {
  485. pPersistFile->Release();
  486. }
  487. if (pClsID)
  488. {
  489. delete pClsID;
  490. }
  491. if (wzFilename)
  492. {
  493. delete wzFilename;
  494. }
  495. return hr;
  496. }
  497. #endif //FOR_SHDOCVW