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.

698 lines
23 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: plugdll.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. #define SZFILTERROOT "PROTOCOLS\\Filter\\"
  19. #define SZPROTOCOLROOT "PROTOCOLS\\Handler\\"
  20. #define SZCLASS "CLSID"
  21. #define SZHANDLER "HANDLER"
  22. #ifdef EAPP_TEST
  23. const GUID CLSID_ResProtocol = {0x79eaca00, 0xbaf9, 0x11ce, {0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b}};
  24. const GUID CLSID_OhServNameSp = {0x79eaca01, 0xbaf9, 0x11ce, {0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b}};
  25. const GUID CLSID_MimeHandlerTest1 = {0x79eaca02, 0xbaf9, 0x11ce, {0x8c, 0x82, 0x00, 0xaa, 0x00, 0x4b, 0xa9, 0x0b}};
  26. const GUID CLSID_NotificaitonTest1 = {0xc733e501, 0x576e, 0x11d0, {0xb2, 0x8c, 0x00, 0xc0, 0x4f, 0xd7, 0xcd, 0x22}};
  27. const GUID CLSID_NotificaitonTest2 = {0xc733e502, 0x576e, 0x11d0, {0xb2, 0x8c, 0x00, 0xc0, 0x4f, 0xd7, 0xcd, 0x22}};
  28. const GUID CLSID_NotificaitonTest3 = {0xc733e503, 0x576e, 0x11d0, {0xb2, 0x8c, 0x00, 0xc0, 0x4f, 0xd7, 0xcd, 0x22}};
  29. const GUID CLSID_NotificaitonTest4 = {0xc733e504, 0x576e, 0x11d0, {0xb2, 0x8c, 0x00, 0xc0, 0x4f, 0xd7, 0xcd, 0x22}};
  30. #endif // EAPP_TEST
  31. //****************************** CLSID for pluggable protocols and filters
  32. const GUID CLSID_StdEncodingFilterFac= {0x54c37cd0, 0xd944, 0x11d0, {0xa9, 0xf4, 0x00, 0x60, 0x97, 0x94, 0x23, 0x11}};
  33. const GUID CLSID_DeCompMimeFilter = {0x8f6b0360, 0xb80d, 0x11d0, {0xa9, 0xb3, 0x00, 0x60, 0x97, 0x94, 0x23, 0x11}};
  34. const GUID CLSID_CdlProtocol = {0x3dd53d40, 0x7b8b, 0x11d0, {0xb0, 0x13, 0x00, 0xaa, 0x00, 0x59, 0xce, 0x02}};
  35. const GUID CLSID_ClassInstallFilter = {0x32b533bb, 0xedae, 0x11d0, {0xbd, 0x5a, 0x0, 0xaa, 0x0, 0xb9, 0x2a, 0xf1}};
  36. DECLARE_INFOLEVEL(EProt)
  37. HINSTANCE g_hInst = NULL;
  38. HINSTANCE g_hInst_LZDHtml = NULL;
  39. HINSTANCE g_hInst_Deflate = NULL;
  40. HINSTANCE g_hInst_GZIP = NULL;
  41. // global variables
  42. CRefCount g_cRef(0); // global dll refcount
  43. #define DLL_NAME "plugprot.dll"
  44. STDAPI_(BOOL) TlsDllMain(HINSTANCE hDll, DWORD dwReason, LPVOID lpvReserved);
  45. #ifdef EAPP_TEST
  46. #define HANDLER_RES SZPROTOCOLROOT"res"
  47. #define PROTOCOL_RES_CLSID "{79eaca00-baf9-11ce-8c82-00aa004ba90b}"
  48. #define PROTOCOL_RES_CLSID_REGKEY "CLSID\\"PROTOCOL_RES_CLSID
  49. #define PROTOCOL_RES_DESCRIP "res: Asychronous Pluggable Protocol Handler"
  50. // protocols
  51. //***** PROTOCOL_RES ENTRIES *****
  52. const REGENTRY rgClassesRes[] =
  53. {
  54. STD_ENTRY(PROTOCOL_RES_CLSID_REGKEY, PROTOCOL_RES_DESCRIP),
  55. STD_ENTRY(PROTOCOL_RES_CLSID_REGKEY"\\InprocServer32", "%s"DLL_NAME),
  56. { KEYTYPE_STRING, PROTOCOL_RES_CLSID_REGKEY"\\InprocServer32", "ThreadingModel", REG_SZ, (BYTE*)"Apartment" },
  57. };
  58. const REGENTRY rgHandlerRes [] = { STD_ENTRY(HANDLER_RES , PROTOCOL_RES_DESCRIP ), { KEYTYPE_STRING, HANDLER_RES , "CLSID", REG_SZ, (BYTE*)PROTOCOL_RES_CLSID } };
  59. #define NAMESPACE_OHSERV SZNAMESPACEROOT"http\\ohserv"
  60. #define NAMESPACE_OHSERV_DESCRIP "Asychronous Pluggable NameSpace Handler for http to ohserv"
  61. #define NAMESPACE_OHSERV_CLSID "{79eaca01-baf9-11ce-8c82-00aa004ba90b}"
  62. #define NAMESPACE_OHSERV_CLSID_REGKEY "CLSID\\"NAMESPACE_OHSERV_CLSID
  63. #define NAMESPACE_OHSERV_PROTOCOL NAMESPACE_OHSERV
  64. const REGENTRY rgClassesOhserv[] =
  65. {
  66. STD_ENTRY(NAMESPACE_OHSERV_CLSID_REGKEY, NAMESPACE_OHSERV_DESCRIP),
  67. STD_ENTRY(NAMESPACE_OHSERV_CLSID_REGKEY"\\InprocServer32", "%s"DLL_NAME),
  68. { KEYTYPE_STRING, NAMESPACE_OHSERV_CLSID_REGKEY"\\InprocServer32", "ThreadingModel", REG_SZ, (BYTE*)"Apartment" },
  69. };
  70. const REGENTRY rgNameSpaceOhserv [] =
  71. {
  72. STD_ENTRY(NAMESPACE_OHSERV , NAMESPACE_OHSERV_DESCRIP ),
  73. { KEYTYPE_STRING, NAMESPACE_OHSERV , "CLSID", REG_SZ, (BYTE*)NAMESPACE_OHSERV_CLSID }
  74. };
  75. #define PROT_FILTER_TEST1 SZFILTERROOT"text/html"
  76. #define PROT_FILTER_TEST1_DESCRIP "Asychronous Pluggable Mime Handler for text/mhtml"
  77. #define PROT_FILTER_TEST1_CLSID "{79eaca02-baf9-11ce-8c82-00aa004ba90b}"
  78. #define PROT_FILTER_TEST1_CLSID_REGKEY "CLSID\\"PROT_FILTER_TEST1_CLSID
  79. #define PROT_FILTER_TEST1_PROTOCOL PROT_FILTER_TEST1
  80. const REGENTRY rgClassesMimeHandlerTest1[] =
  81. {
  82. STD_ENTRY(PROT_FILTER_TEST1_CLSID_REGKEY, PROT_FILTER_TEST1_DESCRIP),
  83. STD_ENTRY(PROT_FILTER_TEST1_CLSID_REGKEY"\\InprocServer32", "%s"DLL_NAME),
  84. { KEYTYPE_STRING, PROT_FILTER_TEST1_CLSID_REGKEY"\\InprocServer32", "ThreadingModel", REG_SZ, (BYTE*)"Apartment" },
  85. };
  86. const REGENTRY rgMimeHandlerTest1 [] =
  87. {
  88. STD_ENTRY(PROT_FILTER_TEST1 , PROT_FILTER_TEST1_DESCRIP ),
  89. { KEYTYPE_STRING, PROT_FILTER_TEST1 , "CLSID", REG_SZ, (BYTE*)PROT_FILTER_TEST1_CLSID }
  90. };
  91. #endif // EAPP_TEST
  92. //*************************** Registry keys for CDL protocol handler
  93. #define HANDLER_CDL SZPROTOCOLROOT"cdl"
  94. #define PROTOCOL_CDL_CLSID "{3dd53d40-7b8b-11D0-b013-00aa0059ce02}"
  95. #define PROTOCOL_CDL_CLSID_REGKEY "CLSID\\"PROTOCOL_CDL_CLSID
  96. #define PROTOCOL_CDL_DESCRIP "CDL: Asychronous Pluggable Protocol Handler"
  97. const REGENTRY rgHandlerCdl[] =
  98. {
  99. STD_ENTRY(HANDLER_CDL , PROTOCOL_CDL_DESCRIP ),
  100. { KEYTYPE_STRING, HANDLER_CDL , "CLSID", REG_SZ, (BYTE*)PROTOCOL_CDL_CLSID }
  101. };
  102. const REGENTRY rgClassesCdl[] =
  103. {
  104. STD_ENTRY(PROTOCOL_CDL_CLSID_REGKEY, PROTOCOL_CDL_DESCRIP),
  105. STD_ENTRY(PROTOCOL_CDL_CLSID_REGKEY"\\InprocServer32", "%s"DLL_NAME),
  106. { KEYTYPE_STRING, PROTOCOL_CDL_CLSID_REGKEY"\\InprocServer32", "ThreadingModel", REG_SZ, (BYTE*)"Apartment" },
  107. };
  108. //*************************** Registry keys for Class Install Handler protocol filter
  109. #define PROT_FILTER_CLASS SZFILTERROOT"Class Install Handler"
  110. #define PROT_FILTER_CLASS_DESCRIP "AP Class Install Handler filter"
  111. #define PROT_FILTER_CLASS_CLSID "{32B533BB-EDAE-11d0-BD5A-00AA00B92AF1}"
  112. #define PROT_FILTER_CLASS_CLSID_REGKEY "CLSID\\"PROT_FILTER_CLASS_CLSID
  113. #define PROT_FILTER_CLASS_PROTOCOL PROT_FILTER_CLASS
  114. const REGENTRY rgClassesMimeInstallHandler[] =
  115. {
  116. STD_ENTRY(PROT_FILTER_CLASS_CLSID_REGKEY, PROT_FILTER_CLASS_DESCRIP),
  117. STD_ENTRY(PROT_FILTER_CLASS_CLSID_REGKEY"\\InprocServer32", "%s"DLL_NAME),
  118. { KEYTYPE_STRING, PROT_FILTER_CLASS_CLSID_REGKEY"\\InprocServer32", "ThreadingModel", REG_SZ, (BYTE*)"Apartment" },
  119. };
  120. const REGENTRY rgMimeInstallHandler[] =
  121. {
  122. STD_ENTRY(PROT_FILTER_CLASS , PROT_FILTER_CLASS_DESCRIP ),
  123. { KEYTYPE_STRING, PROT_FILTER_CLASS, "CLSID", REG_SZ, (BYTE*)PROT_FILTER_CLASS_CLSID }
  124. };
  125. //*************************** Registry keys for ENC & Deflate protocol filters
  126. #define PROT_FILTER_ENC SZFILTERROOT"lzdhtml"
  127. #define PROT_FILTER_ENC_DESCRIP "AP lzdhtml encoding/decoding Filter"
  128. #define PROT_FILTER_ENC_CLSID "{8f6b0360-b80d-11d0-a9b3-006097942311}"
  129. #define PROT_FILTER_ENC_CLSID_REGKEY "CLSID\\"PROT_FILTER_ENC_CLSID
  130. #define PROT_FILTER_ENC_PROTOCOL PROT_FILTER_ENC
  131. const REGENTRY rgClassesMimeHandlerEnc[] =
  132. {
  133. STD_ENTRY(PROT_FILTER_ENC_CLSID_REGKEY, PROT_FILTER_ENC_DESCRIP),
  134. STD_ENTRY(PROT_FILTER_ENC_CLSID_REGKEY"\\InprocServer32", "%s"DLL_NAME),
  135. { KEYTYPE_STRING, PROT_FILTER_ENC_CLSID_REGKEY"\\InprocServer32", "ThreadingModel", REG_SZ, (BYTE*)"Apartment" },
  136. };
  137. const REGENTRY rgMimeHandlerEnc [] =
  138. {
  139. STD_ENTRY(PROT_FILTER_ENC , PROT_FILTER_ENC_DESCRIP ),
  140. { KEYTYPE_STRING, PROT_FILTER_ENC , "CLSID", REG_SZ, (BYTE*)PROT_FILTER_ENC_CLSID }
  141. };
  142. #define PROT_FILTER_DEFLATE SZFILTERROOT"deflate"
  143. #define PROT_FILTER_DEFLATE_DESCRIP "AP Deflate Encoding/Decoding Filter "
  144. #define PROT_FILTER_DEFLATE_CLSID "{8f6b0360-b80d-11d0-a9b3-006097942311}"
  145. const REGENTRY rgDeflateEnc [] =
  146. {
  147. STD_ENTRY(PROT_FILTER_DEFLATE , PROT_FILTER_DEFLATE_DESCRIP ),
  148. { KEYTYPE_STRING, PROT_FILTER_DEFLATE , "CLSID", REG_SZ, (BYTE*)PROT_FILTER_DEFLATE_CLSID }
  149. };
  150. #define PROT_FILTER_GZIP SZFILTERROOT"gzip"
  151. #define PROT_FILTER_GZIP_DESCRIP "AP GZIP Encoding/Decoding Filter "
  152. #define PROT_FILTER_GZIP_CLSID "{8f6b0360-b80d-11d0-a9b3-006097942311}"
  153. const REGENTRY rgGZIPEnc [] =
  154. {
  155. STD_ENTRY(PROT_FILTER_GZIP , PROT_FILTER_GZIP_DESCRIP ),
  156. { KEYTYPE_STRING, PROT_FILTER_GZIP , "CLSID", REG_SZ, (BYTE*)PROT_FILTER_GZIP_CLSID }
  157. };
  158. #define STD_ENC_FAC_CLSID "{54c37cd0-d944-11d0-a9f4-006097942311}"
  159. #define STD_ENC_FAC_CLSID_REGKEY "CLSID\\"STD_ENC_FAC_CLSID
  160. const REGENTRY rgClassesStdEncFac[] =
  161. {
  162. STD_ENTRY(STD_ENC_FAC_CLSID_REGKEY"\\InprocServer32", "%s"DLL_NAME),
  163. { KEYTYPE_STRING, STD_ENC_FAC_CLSID_REGKEY"\\InprocServer32", "ThreadingModel", REG_SZ, (BYTE*)"Apartment" },
  164. };
  165. #ifdef EAPP_TEST
  166. // notificaition sink
  167. #define NOTIFICATION_SINK_TEST1_DESCRIP "Notification Sink Test1"
  168. #define NOTIFICATION_SINK_TEST1_CLSID "{c733e501-576e-11d0-b28c-00c04fd7cd22}"
  169. #define NOTIFICATION_SINK_TEST1_CLSID_REGKEY "CLSID\\"NOTIFICATION_SINK_TEST1_CLSID
  170. #define NOTIFICATION_SINK_TEST1_CLSID_REGKEY "CLSID\\"NOTIFICATION_SINK_TEST1_CLSID
  171. const REGENTRY rgNotSinkTest1[] =
  172. {
  173. //***** NOTIFICATION_SINK_TEST1 ENTRIES *****
  174. STD_ENTRY(NOTIFICATION_SINK_TEST1_CLSID_REGKEY, NOTIFICATION_SINK_TEST1_DESCRIP),
  175. STD_ENTRY(NOTIFICATION_SINK_TEST1_CLSID_REGKEY"\\InprocServer32", "%s"DLL_NAME),
  176. { KEYTYPE_STRING, NOTIFICATION_SINK_TEST1_CLSID_REGKEY"\\InprocServer32", "ThreadingModel", REG_SZ, (BYTE*)"Apartment" },
  177. };
  178. #define NOTIFICATION_SINK_TEST2_DESCRIP "Notification Sink Test2"
  179. #define NOTIFICATION_SINK_TEST2_CLSID "{c733e502-576e-11d0-b28c-00c04fd7cd22}"
  180. #define NOTIFICATION_SINK_TEST2_CLSID_REGKEY "CLSID\\"NOTIFICATION_SINK_TEST2_CLSID
  181. #define NOTIFICATION_SINK_TEST2_CLSID_REGKEY "CLSID\\"NOTIFICATION_SINK_TEST2_CLSID
  182. const REGENTRY rgNotSinkTest2[] =
  183. {
  184. //***** NOTIFICATION_SINK_TEST2 ENTRIES *****
  185. STD_ENTRY(NOTIFICATION_SINK_TEST2_CLSID_REGKEY, NOTIFICATION_SINK_TEST2_DESCRIP),
  186. STD_ENTRY(NOTIFICATION_SINK_TEST2_CLSID_REGKEY"\\InprocServer32", "%s"DLL_NAME),
  187. { KEYTYPE_STRING, NOTIFICATION_SINK_TEST2_CLSID_REGKEY"\\InprocServer32", "ThreadingModel", REG_SZ, (BYTE*)"Apartment" },
  188. };
  189. #define NOTIFICATION_SINK_TEST3_DESCRIP "Notification Sink Test3"
  190. #define NOTIFICATION_SINK_TEST3_CLSID "{c733e503-576e-11d0-b28c-00c04fd7cd22}"
  191. #define NOTIFICATION_SINK_TEST3_CLSID_REGKEY "CLSID\\"NOTIFICATION_SINK_TEST3_CLSID
  192. #define NOTIFICATION_SINK_TEST3_CLSID_REGKEY "CLSID\\"NOTIFICATION_SINK_TEST3_CLSID
  193. const REGENTRY rgNotSinkTest3[] =
  194. {
  195. //***** NOTIFICATION_SINK_TEST3 ENTRIES *****
  196. STD_ENTRY(NOTIFICATION_SINK_TEST3_CLSID_REGKEY, NOTIFICATION_SINK_TEST3_DESCRIP),
  197. STD_ENTRY(NOTIFICATION_SINK_TEST3_CLSID_REGKEY"\\InprocServer32", "%s"DLL_NAME),
  198. { KEYTYPE_STRING, NOTIFICATION_SINK_TEST3_CLSID_REGKEY"\\InprocServer32", "ThreadingModel", REG_SZ, (BYTE*)"Apartment" },
  199. };
  200. #define NOTIFICATION_SINK_TEST4_DESCRIP "Notification Sink Test4"
  201. #define NOTIFICATION_SINK_TEST4_CLSID "{c733e504-576e-11d0-b28c-00c04fd7cd22}"
  202. #define NOTIFICATION_SINK_TEST4_CLSID_REGKEY "CLSID\\"NOTIFICATION_SINK_TEST4_CLSID
  203. #define NOTIFICATION_SINK_TEST4_CLSID_REGKEY "CLSID\\"NOTIFICATION_SINK_TEST4_CLSID
  204. const REGENTRY rgNotSinkTest4[] =
  205. {
  206. //***** NOTIFICATION_SINK_TEST4 ENTRIES *****
  207. STD_ENTRY(NOTIFICATION_SINK_TEST4_CLSID_REGKEY, NOTIFICATION_SINK_TEST4_DESCRIP),
  208. STD_ENTRY(NOTIFICATION_SINK_TEST4_CLSID_REGKEY"\\InprocServer32", "%s"DLL_NAME),
  209. { KEYTYPE_STRING, NOTIFICATION_SINK_TEST4_CLSID_REGKEY"\\InprocServer32", "ThreadingModel", REG_SZ, (BYTE*)"Apartment" },
  210. };
  211. #endif // EAPP_TEST
  212. const REGENTRYGROUP rgRegEntryGroups[] = {
  213. #ifdef EAPP_TEST
  214. { HKEY_CLASSES_ROOT, rgClassesRes, ARRAYSIZE(rgClassesRes) },
  215. { HKEY_CLASSES_ROOT, rgHandlerRes , ARRAYSIZE(rgHandlerRes) },
  216. { HKEY_CLASSES_ROOT, rgClassesOhserv, ARRAYSIZE(rgClassesOhserv) },
  217. { HKEY_CLASSES_ROOT, rgNameSpaceOhserv, ARRAYSIZE(rgNameSpaceOhserv) },
  218. { HKEY_CLASSES_ROOT, rgMimeHandlerTest1, ARRAYSIZE(rgMimeHandlerTest1) },
  219. { HKEY_CLASSES_ROOT, rgClassesMimeHandlerTest1, ARRAYSIZE(rgClassesMimeHandlerTest1) },
  220. { HKEY_CLASSES_ROOT, rgNotSinkTest1 , ARRAYSIZE(rgNotSinkTest1) },
  221. { HKEY_CLASSES_ROOT, rgNotSinkTest2 , ARRAYSIZE(rgNotSinkTest2) },
  222. { HKEY_CLASSES_ROOT, rgNotSinkTest3 , ARRAYSIZE(rgNotSinkTest3) },
  223. { HKEY_CLASSES_ROOT, rgNotSinkTest4 , ARRAYSIZE(rgNotSinkTest4) },
  224. #endif //EAPP_TEST
  225. { HKEY_CLASSES_ROOT, rgMimeHandlerEnc, ARRAYSIZE(rgMimeHandlerEnc) },
  226. { HKEY_CLASSES_ROOT, rgClassesMimeHandlerEnc, ARRAYSIZE(rgClassesMimeHandlerEnc) },
  227. { HKEY_CLASSES_ROOT, rgDeflateEnc, ARRAYSIZE(rgDeflateEnc) },
  228. { HKEY_CLASSES_ROOT, rgGZIPEnc, ARRAYSIZE(rgGZIPEnc) },
  229. { HKEY_CLASSES_ROOT, rgClassesStdEncFac, ARRAYSIZE(rgClassesStdEncFac) },
  230. { HKEY_CLASSES_ROOT, rgClassesMimeInstallHandler, ARRAYSIZE(rgClassesMimeInstallHandler) },
  231. { HKEY_CLASSES_ROOT, rgMimeInstallHandler, ARRAYSIZE(rgMimeInstallHandler) },
  232. { HKEY_CLASSES_ROOT, rgClassesCdl, ARRAYSIZE(rgClassesCdl) },
  233. { HKEY_CLASSES_ROOT, rgHandlerCdl , ARRAYSIZE(rgHandlerCdl) },
  234. { NULL, NULL, 0 } // terminator
  235. };
  236. //+---------------------------------------------------------------------------
  237. //
  238. // Function: DllAddRef
  239. //
  240. // Synopsis:
  241. //
  242. // Arguments: [void] --
  243. //
  244. // Returns:
  245. //
  246. // History: 11-07-96 JohannP (Johann Posch) Created
  247. //
  248. // Notes:
  249. //
  250. //----------------------------------------------------------------------------
  251. void DllAddRef(void)
  252. {
  253. g_cRef++;
  254. }
  255. //+---------------------------------------------------------------------------
  256. //
  257. // Function: DllRelease
  258. //
  259. // Synopsis:
  260. //
  261. // Arguments: [void] --
  262. //
  263. // Returns:
  264. //
  265. // History: 11-07-96 JohannP (Johann Posch) Created
  266. //
  267. // Notes:
  268. //
  269. //----------------------------------------------------------------------------
  270. void DllRelease(void)
  271. {
  272. EProtAssert((g_cRef > 0));
  273. if (g_cRef > 0)
  274. {
  275. g_cRef--;
  276. }
  277. }
  278. //+---------------------------------------------------------------------------
  279. //
  280. // Operator: new
  281. //
  282. // Synopsis:
  283. //
  284. // Arguments: [size] --
  285. //
  286. // Returns:
  287. //
  288. // History: 11-07-96 JohannP (Johann Posch) Created
  289. //
  290. // Notes: BUBUG: get and use IMalloc
  291. //
  292. //----------------------------------------------------------------------------
  293. void * _cdecl operator new(size_t size)
  294. {
  295. void * pBuffer;
  296. pBuffer = CoTaskMemAlloc(size);
  297. if (pBuffer)
  298. {
  299. memset(pBuffer,0, size);
  300. }
  301. return pBuffer;
  302. }
  303. //+---------------------------------------------------------------------------
  304. //
  305. // Operator: delete
  306. //
  307. // Synopsis:
  308. //
  309. // Arguments: [lpv] --
  310. //
  311. // Returns:
  312. //
  313. // History: 2-14-96 JohannP (Johann Posch) Created
  314. //
  315. // Notes: BUBUG: get and use IMalloc
  316. //
  317. //----------------------------------------------------------------------------
  318. void _cdecl operator delete(void *lpv)
  319. {
  320. if (lpv == NULL)
  321. {
  322. return;
  323. }
  324. CoTaskMemFree(lpv);
  325. }
  326. //+-------------------------------------------------------------------------
  327. //
  328. // Function: DllGetClassObject
  329. //
  330. // Synopsis: Dll entry point
  331. //
  332. // Arguments: [clsid] - class id for new class
  333. // [iid] - interface required of class
  334. // [ppv] - where to put new interface
  335. //
  336. // Returns: S_OK - class object created successfully created.
  337. //
  338. // History: 11-07-96 JohannP (Johann Posch) Created
  339. //
  340. //--------------------------------------------------------------------------
  341. STDAPI DllGetClassObject(REFCLSID clsid, REFIID iid, void **ppv)
  342. {
  343. EProtDebugOut((DEB_PLUGPROT, "API _IN DllGetClassObject\n"));
  344. HRESULT hr = E_FAIL;
  345. #ifdef EAPP_TEST
  346. if ( (clsid == CLSID_ResProtocol)
  347. || (clsid == CLSID_OhServNameSp)
  348. || (clsid == CLSID_NotificaitonTest1)
  349. || (clsid == CLSID_NotificaitonTest2)
  350. || (clsid == CLSID_NotificaitonTest3)
  351. || (clsid == CLSID_NotificaitonTest4)
  352. || (clsid == CLSID_CdlProtocol)
  353. || (clsid == CLSID_DeCompMimeFilter)
  354. || (clsid == CLSID_MimeHandlerTest1)
  355. || (clsid == CLSID_StdEncodingFilterFac)
  356. || (clsid == CLSID_ClassInstallFilter) )
  357. #else
  358. if( (clsid == CLSID_DeCompMimeFilter)
  359. || (clsid == CLSID_StdEncodingFilterFac)
  360. || (clsid == CLSID_CdlProtocol)
  361. || (clsid == CLSID_ClassInstallFilter) )
  362. #endif // EAPP_TEST
  363. {
  364. CUrlClsFact *pCF = NULL;
  365. hr = CUrlClsFact::Create(clsid, &pCF);
  366. if (hr == NOERROR)
  367. {
  368. EProtAssert((pCF != NULL));
  369. hr = pCF->QueryInterface(iid, ppv);
  370. pCF->Release();
  371. }
  372. }
  373. EProtDebugOut((DEB_PLUGPROT, "API OUT DllGetClassObject (hr:%lx, ppv:%p)\n",hr,*ppv));
  374. return hr;
  375. }
  376. //+-------------------------------------------------------------------------
  377. //
  378. // Function: DllMain
  379. //
  380. // Synopsis:
  381. //
  382. // Arguments: [hDll] - a handle to the dll instance
  383. // [dwReason] - the reason LibMain was called
  384. // [lpvReserved] - NULL - called due to FreeLibrary
  385. // - non-NULL - called due to process exit
  386. //
  387. // Returns: TRUE on success, FALSE otherwise
  388. //
  389. // Notes:
  390. //
  391. // The officially approved DLL entrypoint name is DllMain. This
  392. // entry point will be called by the CRT Init function.
  393. //
  394. // History: 11-07-96 JohannP (Johann Posch) Created
  395. //
  396. //--------------------------------------------------------------------------
  397. BOOL WINAPI DllMain(HINSTANCE hInstance,DWORD dwReason,LPVOID lpvReserved)
  398. {
  399. BOOL fResult = TRUE;
  400. switch (dwReason)
  401. {
  402. case DLL_PROCESS_ATTACH:
  403. #if DBG==1
  404. {
  405. EProtInfoLevel = (DWORD) GetProfileIntA("UrlMon","EProt", (DEB_ERROR | DEB_WARN));
  406. }
  407. #endif //DBG==1
  408. g_hInst = hInstance;
  409. //tsaMain.InitApp(NULL);
  410. //fResult = TlsDllMain(hInstance, dwReason, lpvReserved);
  411. break;
  412. case DLL_PROCESS_DETACH:
  413. if(g_hInst_LZDHtml)
  414. {
  415. FreeLibrary(g_hInst_LZDHtml);
  416. }
  417. if(g_hInst_Deflate)
  418. {
  419. FreeLibrary(g_hInst_Deflate);
  420. }
  421. if(g_hInst_GZIP)
  422. {
  423. FreeLibrary(g_hInst_GZIP);
  424. }
  425. // Fall through
  426. case DLL_THREAD_ATTACH:
  427. case DLL_THREAD_DETACH:
  428. //fResult = TlsDllMain(hInstance, dwReason, lpvReserved);
  429. break;
  430. }
  431. return fResult;
  432. }
  433. //+---------------------------------------------------------------------------
  434. //
  435. // Function: DllCanUnloadNow
  436. //
  437. // Synopsis:
  438. //
  439. // Arguments: [void] --
  440. //
  441. // Returns:
  442. //
  443. // History: 11-07-96 JohannP (Johann Posch) Created
  444. //
  445. // Notes:
  446. //
  447. //----------------------------------------------------------------------------
  448. STDAPI DllCanUnloadNow(void)
  449. {
  450. return (g_cRef ? S_FALSE : S_OK);
  451. }
  452. //+---------------------------------------------------------------------------
  453. //
  454. // Function: DllRegisterServer
  455. //
  456. // Synopsis:
  457. //
  458. // Arguments: (none)
  459. //
  460. // Returns:
  461. //
  462. // History: 10-07-96 JohannP (Johann Posch) Created
  463. //
  464. // Notes:
  465. //
  466. //----------------------------------------------------------------------------
  467. STDAPI DllRegisterServer()
  468. {
  469. EProtDebugOut((DEB_PLUGPROT, "API _IN DllRegisterServer\n"));
  470. HRESULT hr;
  471. hr = HrDllRegisterServer(rgRegEntryGroups, g_hInst, NULL /*pfnLoadString*/);
  472. EProtDebugOut((DEB_PLUGPROT, "API OUT DllRegisterServer (hr:%lx)\n",hr));
  473. return hr;
  474. }
  475. //+---------------------------------------------------------------------------
  476. //
  477. // Function: DllUnregisterServer
  478. //
  479. // Synopsis:
  480. //
  481. // Arguments: (none)
  482. //
  483. // Returns:
  484. //
  485. // History: 11-07-96 JohannP (Johann Posch) Created
  486. //
  487. // Notes:
  488. //
  489. //----------------------------------------------------------------------------
  490. STDAPI DllUnregisterServer()
  491. {
  492. EProtDebugOut((DEB_PLUGPROT, "API _IN DllUnregisterServer\n"));
  493. HRESULT hr;
  494. hr = HrDllUnregisterServer(rgRegEntryGroups, g_hInst, NULL /*pfnLoadString*/);
  495. EProtDebugOut((DEB_PLUGPROT, "API OUT DllUnregisterServer (hr:%lx)\n",hr));
  496. return hr;
  497. }
  498. #if DBG==1
  499. #include <sem.hxx>
  500. CMutexSem mxs;
  501. IDebugOut *v_pEProtDbgOut = NULL;
  502. LPCWSTR v_gDbgFacilitieNames[] =
  503. {
  504. L"*/*"
  505. ,L"EProt"
  506. ,NULL
  507. };
  508. void EProtUrlSpy(int iOption, const char *pscFormat, ...)
  509. {
  510. static char szOutBuffer[2048];
  511. CLock lck(mxs);
  512. DWORD tid = GetCurrentThreadId();
  513. DWORD cbBufLen;
  514. sprintf(szOutBuffer,"%08x> ", tid );
  515. cbBufLen = strlen(szOutBuffer);
  516. va_list args;
  517. if (iOption & EProtInfoLevel)
  518. {
  519. va_start(args, pscFormat);
  520. wvsprintf(szOutBuffer + cbBufLen, pscFormat, args);
  521. va_end(args);
  522. UrlSpySendEntry(v_pEProtDbgOut, szOutBuffer, tid, iOption, 0);
  523. }
  524. }
  525. void UrlSpySendEntry(IDebugOut *pDbgOut, LPSTR szOutBuffer, DWORD ThreadId, DWORD dwFlags, DWORD dwReserved)
  526. {
  527. if (pDbgOut)
  528. {
  529. pDbgOut->SendEntry(ThreadId, dwFlags, szOutBuffer, dwReserved);
  530. }
  531. else
  532. {
  533. OutputDebugString(szOutBuffer);
  534. }
  535. }
  536. HRESULT RegisterDebugOut(LPCWSTR pwzName, DWORD dwOptions, IDebugOut *pDbgOut, DWORD dwReserved)
  537. {
  538. if (pwzName)
  539. {
  540. if ( (!wcsicmp(pwzName, L"*/*"))
  541. || (!wcsicmp(pwzName, L"EProt")) )
  542. {
  543. EProtInfoLevel = dwOptions;
  544. if (v_pEProtDbgOut)
  545. {
  546. v_pEProtDbgOut->Release();
  547. v_pEProtDbgOut = NULL;
  548. }
  549. if (pDbgOut)
  550. {
  551. v_pEProtDbgOut = pDbgOut;
  552. pDbgOut->AddRef();
  553. }
  554. }
  555. }
  556. return NOERROR;
  557. }
  558. void PerfDbgLogFn(int tag, void * pvObj, const char * pchFmt, ...)
  559. {
  560. static char szOutBuffer[2048];
  561. static DWORD * apiLevel[] = { &EProtInfoLevel };
  562. static IDebugOut ** apDbgOut[] = { &v_pEProtDbgOut };
  563. int iIndex = min(tag >> DEB_LEVEL_SHIFT, 0);
  564. int iLevel = *apiLevel[iIndex];
  565. if ((tag & iLevel) == 0)
  566. return;
  567. CLock lck(mxs);
  568. DWORD tid = GetCurrentThreadId();
  569. DWORD cbBufLen;
  570. IDebugOut * pDbgOut = *apDbgOut[iIndex];
  571. sprintf(szOutBuffer, "%08x> %p %s", tid, pvObj,
  572. *pchFmt == '+' ? "_IN " : (*pchFmt == '-' ? "OUT " : ""));
  573. cbBufLen = strlen(szOutBuffer);
  574. if (*pchFmt == '+' || *pchFmt == '-')
  575. pchFmt += 1;
  576. va_list args;
  577. va_start(args, pchFmt);
  578. vsprintf(szOutBuffer + cbBufLen, pchFmt, args);
  579. lstrcat(szOutBuffer, "\n");
  580. va_end(args);
  581. UrlSpySendEntry(pDbgOut, szOutBuffer, tid, tag & DEB_LEVEL_MASK, 0);
  582. }
  583. #endif //DBG==1