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.

245 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. dllentry.cxx
  5. Abstract:
  6. Entry point for WinInet Internet client DLL
  7. Contents:
  8. WinInetDllEntryPoint
  9. Author:
  10. Richard L Firth (rfirth) 10-Nov-1994
  11. Environment:
  12. Win32 (user-mode) DLL
  13. Revision History:
  14. 10-Nov-1994 rfirth
  15. Created
  16. --*/
  17. #include <wininetp.h>
  18. #include <process.h>
  19. #include <perfdiag.hxx>
  20. #include <shlwapi.h>
  21. #include <advpub.h>
  22. #ifndef WINHTTP_STATIC_LIBRARY
  23. #error libentry.cxx should not be compiled into winhttpx.dll
  24. #endif
  25. #if defined(__cplusplus)
  26. extern "C" {
  27. #endif
  28. BOOL
  29. WINAPI
  30. WinHttpDllMainHook(
  31. IN HINSTANCE DllHandle,
  32. IN DWORD Reason,
  33. IN LPVOID Reserved
  34. );
  35. #if defined(__cplusplus)
  36. }
  37. #endif
  38. //
  39. // global data
  40. //
  41. GLOBAL CCritSec GeneralInitCritSec;
  42. //
  43. // functions
  44. //
  45. BOOL
  46. WINAPI
  47. WinHttpDllMainHook(
  48. IN HINSTANCE DllHandle,
  49. IN DWORD Reason,
  50. IN LPVOID Reserved
  51. )
  52. /*++
  53. Routine Description:
  54. Performs global initialization and termination for all protocol modules.
  55. This function only handles process attach and detach which are required for
  56. global initialization and termination, respectively. We disable thread
  57. attach and detach. New threads calling Wininet APIs will get an
  58. INTERNET_THREAD_INFO structure created for them by the first API requiring
  59. this structure
  60. Arguments:
  61. DllHandle - handle of this DLL. Unused
  62. Reason - process attach/detach or thread attach/detach
  63. Reserved - if DLL_PROCESS_ATTACH, NULL means DLL is being dynamically
  64. loaded, else static. For DLL_PROCESS_DETACH, NULL means DLL
  65. is being freed as a consequence of call to FreeLibrary()
  66. else the DLL is being freed as part of process termination
  67. Return Value:
  68. BOOL
  69. Success - TRUE
  70. Failure - FALSE. Failed to initialize
  71. --*/
  72. {
  73. if (Reason != DLL_PROCESS_ATTACH) {
  74. DEBUG_ENTER((DBG_DLL,
  75. Bool,
  76. "DllMain",
  77. "%#x, %s, %#x",
  78. DllHandle,
  79. (Reason == DLL_PROCESS_ATTACH) ? "DLL_PROCESS_ATTACH"
  80. : (Reason == DLL_PROCESS_DETACH) ? "DLL_PROCESS_DETACH"
  81. : (Reason == DLL_THREAD_ATTACH) ? "DLL_THREAD_ATTACH"
  82. : (Reason == DLL_THREAD_DETACH) ? "DLL_THREAD_DETACH"
  83. : "?",
  84. Reserved
  85. ));
  86. }
  87. DWORD error;
  88. //
  89. // perform global dll initialization, if any.
  90. //
  91. switch (Reason) {
  92. case DLL_PROCESS_ATTACH:
  93. GlobalDllHandle = DllHandle;
  94. GlobalPlatformType = PlatformType(&GlobalPlatformVersion5);
  95. if (!GeneralInitCritSec.Init())
  96. return FALSE;
  97. if (!g_pAsyncCount)
  98. {
  99. g_pAsyncCount = New CAsyncCount();
  100. if (!g_pAsyncCount)
  101. return FALSE;
  102. }
  103. INITIALIZE_DEBUG_REGKEY();
  104. INITIALIZE_DEBUG_MEMORY();
  105. INET_DEBUG_START();
  106. if (!GlobalDllInitialize() || !InternetCreateThreadInfo(TRUE))
  107. {
  108. return FALSE;
  109. }
  110. DEBUG_ENTER((DBG_DLL,
  111. Bool,
  112. "DllMain",
  113. "%#x, %s, %#x",
  114. DllHandle,
  115. (Reason == DLL_PROCESS_ATTACH) ? "DLL_PROCESS_ATTACH"
  116. : (Reason == DLL_PROCESS_DETACH) ? "DLL_PROCESS_DETACH"
  117. : (Reason == DLL_THREAD_ATTACH) ? "DLL_THREAD_ATTACH"
  118. : (Reason == DLL_THREAD_DETACH) ? "DLL_THREAD_DETACH"
  119. : "?",
  120. Reserved
  121. ));
  122. DEBUG_LEAVE(TRUE);
  123. break;
  124. case DLL_PROCESS_DETACH:
  125. //
  126. // signal to all APIs (and any other function that might have an
  127. // interest) that the DLL is being shutdown
  128. //
  129. GlobalDynaUnload = (Reserved == NULL) ? TRUE : FALSE;
  130. InDllCleanup = TRUE;
  131. DEBUG_PRINT(DLL,
  132. INFO,
  133. ("DLL Terminated\n"
  134. ));
  135. DEBUG_LEAVE(TRUE);
  136. if (GlobalDynaUnload) {
  137. if (GlobalDataInitialized) {
  138. GlobalDataTerminate();
  139. }
  140. GlobalDllTerminate();
  141. InternetTerminateThreadInfo();
  142. }
  143. PERF_DUMP();
  144. PERF_END();
  145. if (g_pAsyncCount)
  146. {
  147. delete g_pAsyncCount;
  148. g_pAsyncCount = 0;
  149. }
  150. //TERMINATE_DEBUG_MEMORY(FALSE);
  151. TERMINATE_DEBUG_MEMORY(TRUE);
  152. INET_DEBUG_FINISH();
  153. TERMINATE_DEBUG_REGKEY();
  154. //InternetDestroyThreadInfo();
  155. GeneralInitCritSec.FreeLock();
  156. break;
  157. case DLL_THREAD_DETACH:
  158. //
  159. // kill the INTERNET_THREAD_INFO
  160. //
  161. DEBUG_LEAVE(TRUE);
  162. InternetDestroyThreadInfo();
  163. break;
  164. case DLL_THREAD_ATTACH:
  165. //
  166. // we do nothing for thread attach - if we need an INTERNET_THREAD_INFO
  167. // then it gets created by the function which realises we need one
  168. //
  169. AllowCAP();
  170. DEBUG_LEAVE(TRUE);
  171. break;
  172. }
  173. return TRUE;
  174. }