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.

425 lines
12 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 <eapp.h>
  18. #ifdef EAPP_TEST
  19. const GUID CLSID_ResProtocol = {0x79eaca00, 0xbaf9, 0x11ce, {0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b}};
  20. const GUID CLSID_OhServNameSp = {0x79eaca01, 0xbaf9, 0x11ce, {0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b}};
  21. const GUID CLSID_MimeHandlerTest1= {0x79eaca02, 0xbaf9, 0x11ce, {0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b}};
  22. const GUID CLSID_NotificaitonTest1 = {0xc733e501, 0x576e, 0x11d0, {0xb2, 0x8c, 0x00, 0xc0, 0x4f, 0xd7, 0xcd, 0x22}};
  23. const GUID CLSID_NotificaitonTest2 = {0xc733e502, 0x576e, 0x11d0, {0xb2, 0x8c, 0x00, 0xc0, 0x4f, 0xd7, 0xcd, 0x22}};
  24. const GUID CLSID_NotificaitonTest3 = {0xc733e503, 0x576e, 0x11d0, {0xb2, 0x8c, 0x00, 0xc0, 0x4f, 0xd7, 0xcd, 0x22}};
  25. const GUID CLSID_NotificaitonTest4 = {0xc733e504, 0x576e, 0x11d0, {0xb2, 0x8c, 0x00, 0xc0, 0x4f, 0xd7, 0xcd, 0x22}};
  26. #endif // EAPP_TEST
  27. const GUID CLSID_StdEncodingFilterFac= {0x54c37cd0, 0xd944, 0x11d0, {0xa9, 0xf4, 0x00, 0x60, 0x97, 0x94, 0x23, 0x11}};
  28. const GUID CLSID_CdlProtocol = {0x3dd53d40, 0x7b8b, 0x11d0, {0xb0, 0x13, 0x00, 0xaa, 0x00, 0x59, 0xce, 0x02}};
  29. const GUID CLSID_DeCompMimeFilter = {0x8f6b0360, 0xb80d, 0x11d0, {0xa9, 0xb3, 0x00, 0x60, 0x97, 0x94, 0x23, 0x11}};
  30. const GUID CLSID_ClassInstallFilter = {0x32b533bb, 0xedae, 0x11d0, {0xbd, 0x5a, 0x0, 0xaa, 0x0, 0xb9, 0x2a, 0xf1}};
  31. #ifdef EAPP_TEST
  32. HRESULT CreateNotificationTest(DWORD dwId, REFCLSID rclsid, IUnknown *pUnkOuter, REFIID riid, IUnknown **ppUnk);
  33. #endif
  34. //+---------------------------------------------------------------------------
  35. //
  36. // Method: CUrlClsFact::Create
  37. //
  38. // Synopsis:
  39. //
  40. // Arguments: [clsid] --
  41. // [ppCF] --
  42. //
  43. // Returns:
  44. //
  45. // History: 12-22-95 JohannP (Johann Posch) Created
  46. //
  47. // Notes:
  48. //
  49. //----------------------------------------------------------------------------
  50. HRESULT CUrlClsFact::Create(REFCLSID clsid, CUrlClsFact **ppCF)
  51. {
  52. EProtDebugOut((DEB_PLUGPROT, "NULL _IN CUrlClsFact::Create\n"));
  53. HRESULT hr = NOERROR;
  54. CUrlClsFact * pCF = NULL;
  55. #ifdef EAPP_TEST
  56. if ( (clsid == CLSID_ResProtocol)
  57. || (clsid == CLSID_OhServNameSp)
  58. )
  59. {
  60. pCF = (CUrlClsFact *) new CUrlClsFact(clsid);
  61. }
  62. else if
  63. (
  64. (clsid == CLSID_NotificaitonTest1)
  65. || (clsid == CLSID_NotificaitonTest2)
  66. || (clsid == CLSID_NotificaitonTest3)
  67. || (clsid == CLSID_NotificaitonTest4)
  68. || (clsid == CLSID_DeCompMimeFilter )
  69. || (clsid == CLSID_MimeHandlerTest1)
  70. )
  71. {
  72. pCF = (CUrlClsFact *) new CUrlClsFact(clsid);
  73. }
  74. #endif
  75. if( (clsid == CLSID_DeCompMimeFilter )
  76. || (clsid == CLSID_StdEncodingFilterFac)
  77. || (clsid == CLSID_ClassInstallFilter)
  78. || (clsid == CLSID_CdlProtocol)
  79. )
  80. {
  81. pCF = (CUrlClsFact *) new CUrlClsFact(clsid);
  82. }
  83. if (pCF == NULL)
  84. {
  85. hr = E_OUTOFMEMORY;
  86. }
  87. else
  88. {
  89. *ppCF = pCF;
  90. }
  91. EProtDebugOut((DEB_PLUGPROT, "%p OUT CUrlClsFact::Create (hr:%lx\n", pCF,hr));
  92. return hr;
  93. }
  94. //+---------------------------------------------------------------------------
  95. //
  96. // Method: CUrlClsFact::CUrlClsFact
  97. //
  98. // Synopsis: constructor
  99. //
  100. // Arguments: [clsid] --
  101. //
  102. // Returns:
  103. //
  104. // History: 12-22-95 JohannP (Johann Posch) Created
  105. //
  106. // Notes: we need to keep a refcount on the dll if for each object given to
  107. // outside, including ClassFactories.
  108. // The corresponding DllRelease is in the destructor
  109. //
  110. //----------------------------------------------------------------------------
  111. CUrlClsFact::CUrlClsFact(REFCLSID clsid) : _CRefs(), _CLocks(0)
  112. {
  113. _ClsID = clsid;
  114. DllAddRef();
  115. }
  116. //+---------------------------------------------------------------------------
  117. //
  118. // Method: CUrlClsFact::~CUrlClsFact
  119. //
  120. // Synopsis:
  121. //
  122. // Arguments: (none)
  123. //
  124. // Returns:
  125. //
  126. // History: 12-22-95 JohannP (Johann Posch) Created
  127. //
  128. // Notes:
  129. //
  130. //----------------------------------------------------------------------------
  131. CUrlClsFact::~CUrlClsFact()
  132. {
  133. DllRelease();
  134. }
  135. //+---------------------------------------------------------------------------
  136. //
  137. // Method: CUrlClsFact::CreateInstance
  138. //
  139. // Synopsis: creates an instance of an Explode Object
  140. //
  141. // Arguments: [pUnkOuter] -- controlling unknown (must be NULL)
  142. // [riid] -- id of desired interface
  143. // [ppv] -- pointer to receive the interface
  144. //
  145. // Returns:
  146. //
  147. // History: 12-22-95 JohannP (Johann Posch) Created
  148. //
  149. // Notes: S_OK - success
  150. // CLASS_E_NOAGGREATION - the caller tried to aggregate
  151. // CLASS_E_CLASSNOTAVAILABLE - couldn't initialize the class
  152. // E_OUTOFMEMORY - not enough memory to instantiate class
  153. //
  154. //----------------------------------------------------------------------------
  155. STDMETHODIMP CUrlClsFact::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID * ppv)
  156. {
  157. EProtDebugOut((DEB_PLUGPROT, "%p _IN CUrlClsFact::CreateInstance\n", this));
  158. HRESULT hr = NOERROR;
  159. // Class factory init time, the pointer to the creation function of
  160. // the object is given. Use that to create the object
  161. //DumpIID(riid);
  162. //DumpIID(_rClsID);
  163. if (riid == IID_IClassFactory)
  164. {
  165. *ppv = (IClassFactory *)this;
  166. AddRef();
  167. }
  168. else if ( (_ClsID == CLSID_CdlProtocol)
  169. )
  170. {
  171. hr = CreateAPP(_ClsID, pUnkOuter, riid, (IUnknown **)ppv);
  172. }
  173. #ifdef EAPP_TEST
  174. else if ( (_ClsID == CLSID_ResProtocol)
  175. || (_ClsID == CLSID_OhServNameSp)
  176. || (_ClsID == CLSID_MimeHandlerTest1)
  177. )
  178. {
  179. hr = CreateAPP(_ClsID, pUnkOuter, riid, (IUnknown **)ppv);
  180. }
  181. else if( (_ClsID == CLSID_NotificaitonTest1)
  182. || (_ClsID == CLSID_NotificaitonTest2)
  183. || (_ClsID == CLSID_NotificaitonTest3)
  184. || (_ClsID == CLSID_NotificaitonTest4))
  185. {
  186. // hr = CreateNotificationTest(
  187. // 0, _ClsID, pUnkOuter, riid, (IUnknown **)ppv);
  188. hr = E_FAIL;
  189. }
  190. #endif
  191. else if (_ClsID == CLSID_ClassInstallFilter)
  192. {
  193. hr = CLASS_E_CLASSNOTAVAILABLE;
  194. if (pUnkOuter)
  195. hr = CLASS_E_NOAGGREGATION;
  196. else
  197. {
  198. CClassInstallFilter *pCIF = NULL;
  199. pCIF = new CClassInstallFilter();
  200. *ppv = (LPVOID)(IOInetProtocol *)pCIF;
  201. if (!*ppv)
  202. hr = E_OUTOFMEMORY;
  203. else
  204. hr = S_OK;
  205. }
  206. }
  207. else if( _ClsID == CLSID_DeCompMimeFilter)
  208. {
  209. hr = CLASS_E_CLASSNOTAVAILABLE;
  210. if( pUnkOuter)
  211. hr = CLASS_E_NOAGGREGATION;
  212. else
  213. {
  214. CMimeFt* pMft = NULL;
  215. hr = CMimeFt::Create(&pMft);
  216. if( (hr == NOERROR) && pMft )
  217. {
  218. hr = pMft->QueryInterface(riid, ppv);
  219. pMft->Release();
  220. }
  221. }
  222. }
  223. else if( _ClsID == CLSID_StdEncodingFilterFac)
  224. {
  225. hr = CLASS_E_CLASSNOTAVAILABLE;
  226. if( pUnkOuter)
  227. hr = CLASS_E_NOAGGREGATION;
  228. else
  229. {
  230. *ppv = NULL;
  231. *ppv = new CEncodingFilterFactory;
  232. if( *ppv == NULL )
  233. hr = E_OUTOFMEMORY;
  234. else
  235. hr = ((IEncodingFilterFactory*)(*ppv))->AddRef();
  236. }
  237. }
  238. EProtDebugOut((DEB_PLUGPROT, "%p OUT CUrlClsFact::CreateInstance (hr:%lx)\n", this,hr));
  239. return hr;
  240. }
  241. //+---------------------------------------------------------------------------
  242. //
  243. // Method: CUrlClsFact::LockServer
  244. //
  245. // Synopsis: locks the server, preventing it from being unloaded
  246. //
  247. // Arguments: [fLock] -- TRUE to lock, FALSE to unlock
  248. //
  249. // Returns:
  250. //
  251. // History: 12-22-95 JohannP (Johann Posch) Created
  252. //
  253. // Notes:
  254. //
  255. //----------------------------------------------------------------------------
  256. STDMETHODIMP CUrlClsFact::LockServer(BOOL fLock)
  257. {
  258. EProtDebugOut((DEB_PLUGPROT, "%p _IN CUrlClsFact::LockServer\n", this));
  259. HRESULT hr = NOERROR;
  260. if (fLock)
  261. {
  262. if (++_CLocks == 1)
  263. {
  264. DllAddRef();
  265. }
  266. }
  267. else
  268. {
  269. EProtAssert((_CLocks > 0));
  270. if (_CLocks > 0)
  271. {
  272. if (--_CLocks == 0)
  273. {
  274. DllRelease();
  275. }
  276. }
  277. }
  278. EProtDebugOut((DEB_PLUGPROT, "%p OUT CUrlClsFact::LockServer (hr:%lx)\n", this,hr));
  279. return hr;
  280. }
  281. //+---------------------------------------------------------------------------
  282. //
  283. // Method: CUrlClsFact::QueryInterface
  284. //
  285. // Synopsis:
  286. //
  287. // Arguments: [riid] --
  288. // [ppvObj] --
  289. //
  290. // Returns:
  291. //
  292. // History: 12-22-95 JohannP (Johann Posch) Created
  293. //
  294. // Notes:
  295. //
  296. //----------------------------------------------------------------------------
  297. STDMETHODIMP CUrlClsFact::QueryInterface(REFIID riid, void **ppvObj)
  298. {
  299. VDATEPTROUT(ppvObj, void *);
  300. HRESULT hr = NOERROR;
  301. EProtDebugOut((DEB_PLUGPROT, "%p _IN CUrlClsFact::QueryInterface\n", this));
  302. if ( riid == IID_IUnknown
  303. || riid == IID_IClassFactory)
  304. {
  305. *ppvObj = this;
  306. }
  307. else
  308. {
  309. *ppvObj = NULL;
  310. hr = E_NOINTERFACE;
  311. }
  312. if (hr == NOERROR)
  313. {
  314. AddRef();
  315. }
  316. EProtDebugOut((DEB_PLUGPROT, "%p OUT CUrlClsFact::QueryInterface (hr:%lx\n", this,hr));
  317. return hr;
  318. }
  319. //+---------------------------------------------------------------------------
  320. //
  321. // Function: CUrlClsFact::AddRef
  322. //
  323. // Synopsis:
  324. //
  325. // Arguments: [ULONG] --
  326. //
  327. // Returns:
  328. //
  329. // History: 12-22-95 JohannP (Johann Posch) Created
  330. //
  331. // Notes:
  332. //
  333. //----------------------------------------------------------------------------
  334. STDMETHODIMP_(ULONG) CUrlClsFact::AddRef(void)
  335. {
  336. EProtDebugOut((DEB_PLUGPROT, "%p _IN CUrlClsFact::AddRef\n", this));
  337. LONG lRet = ++_CRefs;
  338. EProtDebugOut((DEB_PLUGPROT, "%p OUT CUrlClsFact::AddRef (cRefs:%ld)\n", this,lRet));
  339. return lRet;
  340. }
  341. //+---------------------------------------------------------------------------
  342. //
  343. // Function: CUrlClsFact::Release
  344. //
  345. // Synopsis:
  346. //
  347. // Arguments: [ULONG] --
  348. //
  349. // Returns:
  350. //
  351. // History: 12-22-95 JohannP (Johann Posch) Created
  352. //
  353. // Notes:
  354. //
  355. //----------------------------------------------------------------------------
  356. STDMETHODIMP_(ULONG) CUrlClsFact::Release(void)
  357. {
  358. EProtDebugOut((DEB_PLUGPROT, "%p _IN CUrlClsFact::Release\n", this));
  359. LONG lRet = --_CRefs;
  360. if (_CRefs == 0)
  361. {
  362. delete this;
  363. }
  364. EProtDebugOut((DEB_PLUGPROT, "%p OUT CUrlClsFact::Release (cRefs:%ld)\n", this,lRet));
  365. return lRet;
  366. }
  367. #if DBG==1
  368. HRESULT DumpIID(REFIID riid)
  369. {
  370. HRESULT hr;
  371. LPOLESTR pszStr = NULL;
  372. #ifdef EAPP_TEST
  373. hr = StringFromCLSID(riid, &pszStr);
  374. EProtDebugOut((DEB_PLUGPROT, "API >>> DumpIID (riid:%ws) \n", pszStr));
  375. #endif // EAPP_TEST
  376. if (pszStr)
  377. {
  378. delete pszStr;
  379. }
  380. return hr = NOERROR;
  381. }
  382. #endif