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.

258 lines
7.7 KiB

  1. /************************************************************************
  2. * *
  3. * INTEL CORPORATION PROPRIETARY INFORMATION *
  4. * *
  5. * This software is supplied under the terms of a license *
  6. * agreement or non-disclosure agreement with Intel Corporation *
  7. * and may not be copied or disclosed except in accordance *
  8. * with the terms of that agreement. *
  9. * *
  10. * Copyright (C) 1997 Intel Corp. All Rights Reserved *
  11. * *
  12. * $Archive: S:\sturgeon\src\gki\vcs\gki.cpv $
  13. * *
  14. * $Revision: 1.14 $
  15. * $Date: 28 Feb 1997 15:46:46 $
  16. * *
  17. * $Author: CHULME $
  18. * *
  19. * $Log: S:\sturgeon\src\gki\vcs\gki.cpv $
  20. //
  21. // Rev 1.14 28 Feb 1997 15:46:46 CHULME
  22. // In Cleanup - check pReg still valid before waiting for 2nd thread to exit
  23. //
  24. // Rev 1.13 14 Feb 1997 16:45:40 CHULME
  25. // Wait for all threads to exit prior to returning from synchronous Cleanup ca
  26. //
  27. // Rev 1.12 12 Feb 1997 01:12:38 CHULME
  28. // Redid thread synchronization to use Gatekeeper.Lock
  29. //
  30. // Rev 1.11 11 Feb 1997 15:35:32 CHULME
  31. // Added GKI_CleanupRequest function to offload DLL_PROCESS_DETACH
  32. //
  33. // Rev 1.10 05 Feb 1997 19:28:18 CHULME
  34. // Remove deletion code from PROCESS_DETACH
  35. //
  36. // Rev 1.9 05 Feb 1997 16:53:10 CHULME
  37. //
  38. // Rev 1.8 05 Feb 1997 15:25:12 CHULME
  39. // Don't wait for retry thread to exit
  40. //
  41. // Rev 1.7 05 Feb 1997 13:50:24 CHULME
  42. // On PROCESS_DETACH - close socket and let retry thread delete pReg
  43. //
  44. // Rev 1.6 17 Jan 1997 09:02:00 CHULME
  45. // Changed reg.h to gkreg.h to avoid name conflict with inc directory
  46. //
  47. // Rev 1.5 13 Jan 1997 17:01:18 CHULME
  48. // Moved error debug message to error condition
  49. //
  50. // Rev 1.4 13 Jan 1997 16:31:20 CHULME
  51. // Changed debug string to 512 - Description can be 256 chars
  52. //
  53. // Rev 1.3 13 Jan 1997 14:25:54 EHOWARDX
  54. // Increased size of szGKDebug debug string buffer from 80 to 128 bytes.
  55. //
  56. // Rev 1.2 10 Jan 1997 16:14:30 CHULME
  57. // Removed MFC dependency
  58. //
  59. // Rev 1.1 22 Nov 1996 14:57:10 CHULME
  60. // Changed the default spider flags, to quit logging raw PDU and XRS
  61. *************************************************************************/
  62. // gki.cpp : Defines the initialization routines for the DLL.
  63. //
  64. #include "precomp.h"
  65. #include <winsock.h>
  66. #include "dgkiexp.h"
  67. #include "dspider.h"
  68. #include "dgkilit.h"
  69. #include "DGKIPROT.H"
  70. #include "GATEKPR.H"
  71. #include "gksocket.h"
  72. #include "GKREG.H"
  73. #include "h225asn.h"
  74. #include "coder.hpp"
  75. #if (defined(_DEBUG) || defined(PCS_COMPLIANCE))
  76. // INTEROP
  77. #include "interop.h"
  78. #include "rasplog.h"
  79. LPInteropLogger RasLogger;
  80. #endif
  81. #ifdef _DEBUG
  82. #undef THIS_FILE
  83. static char THIS_FILE[] = __FILE__;
  84. #endif
  85. DLL_EXPORT DWORD dwGKIDLLFlags = 0xff3f;
  86. DLL_EXPORT BOOL fGKIEcho = FALSE;
  87. DLL_EXPORT BOOL fGKIDontSend = FALSE;
  88. char *pEchoBuff = 0;
  89. int nEchoLen;
  90. CRegistration *g_pReg = NULL;
  91. Coder *g_pCoder = NULL;
  92. /////////////////////////////////////////////////////////////////////////////
  93. // The one and only CGatekeeper object
  94. CGatekeeper *g_pGatekeeper = NULL;
  95. /////////////////////////////////////////////////////////////////////////////
  96. // DLLMain
  97. extern "C" HRESULT DLL_EXPORT
  98. GKI_Initialize(void)
  99. {
  100. HRESULT hr = GKI_OK;
  101. int nRet;
  102. WSADATA wsaData;
  103. #ifdef _DEBUG
  104. char szGKDebug[512];
  105. #endif
  106. #if (defined(_DEBUG) || defined(PCS_COMPLIANCE))
  107. //INTEROP
  108. RasLogger = InteropLoad(RASLOG_PROTOCOL); // found in rasplog.h
  109. #endif
  110. nRet = WSAStartup(MAKEWORD(WSVER_MAJOR, WSVER_MINOR), &wsaData);
  111. if (nRet != 0)
  112. {
  113. SpiderWSErrDecode(nRet);
  114. hr = GKI_NOT_INITIALIZED;
  115. goto ERROR_EXIT;
  116. }
  117. if ((HIBYTE(wsaData.wVersion) != WSVER_MINOR) ||
  118. (LOBYTE(wsaData.wVersion) != WSVER_MAJOR))
  119. {
  120. hr = GKI_NOT_INITIALIZED;
  121. goto WSA_CLEANUP_EXIT;
  122. }
  123. g_pGatekeeper = new CGatekeeper;
  124. if(!g_pGatekeeper)
  125. {
  126. hr = GKI_NO_MEMORY;
  127. goto WSA_CLEANUP_EXIT;
  128. }
  129. g_pCoder = new Coder;
  130. if(!g_pCoder)
  131. {
  132. hr = GKI_NO_MEMORY;
  133. goto WSA_CLEANUP_EXIT;
  134. }
  135. // initialize the oss library
  136. nRet = g_pCoder->InitCoder();
  137. if (nRet)
  138. {
  139. hr = GKI_NOT_INITIALIZED;
  140. goto WSA_CLEANUP_EXIT;
  141. }
  142. // Get the gatekeeper information from the registry
  143. g_pGatekeeper->Read();
  144. return hr;
  145. WSA_CLEANUP_EXIT:
  146. nRet = WSACleanup();
  147. if (nRet != 0)
  148. {
  149. SpiderWSErrDecode(-1);
  150. }
  151. // fall out to ERROR_EXIT
  152. ERROR_EXIT:
  153. if(g_pGatekeeper)
  154. delete g_pGatekeeper;
  155. if(g_pCoder)
  156. delete g_pCoder;
  157. g_pGatekeeper = NULL;
  158. g_pCoder = NULL;
  159. return hr;
  160. }
  161. extern "C" HRESULT DLL_EXPORT
  162. GKI_CleanupRequest(void)
  163. {
  164. // ABSTRACT: This function is exported. It is called by the client application
  165. // as a precursor to unloading the DLL. This function is responsible
  166. // for all cleanup - This allows us to basically do nothing in the
  167. // DllMain DLL_PROCESS_DETACH, which doesn't appear to work as intended.
  168. // AUTHOR: Colin Hulme
  169. int nRet;
  170. #ifdef _DEBUG
  171. char szGKDebug[512];
  172. #endif
  173. SPIDER_TRACE(SP_FUNC, "GKI_CleanupRequest()\n", 0);
  174. SPIDER_TRACE(SP_GKI, "GKI_CleanupRequest()\n", 0);
  175. if(g_pGatekeeper) // if initialized
  176. {
  177. ASSERT(g_pCoder); // g_pGatekeeper and g_pCoder come and go as a unit
  178. g_pGatekeeper->Lock();
  179. if (g_pReg != 0)
  180. {
  181. g_pReg->m_pSocket->Close(); // Close socket will terminate the other threads
  182. g_pGatekeeper->Unlock();
  183. WaitForSingleObject(g_pReg->GetRcvThread(), TIMEOUT_THREAD);
  184. #ifdef BROADCAST_DISCOVERY
  185. if (g_pReg)
  186. WaitForSingleObject(g_pReg->GetDiscThread(), TIMEOUT_THREAD);
  187. #endif // #ifdef BROADCAST_DISCOVERY
  188. g_pGatekeeper->Lock();
  189. if (g_pReg != 0)
  190. {
  191. SPIDER_TRACE(SP_NEWDEL, "del g_pReg = %X\n", g_pReg);
  192. delete g_pReg;
  193. g_pReg = 0;
  194. }
  195. }
  196. #if (defined(_DEBUG) || defined(PCS_COMPLIANCE))
  197. //INTEROP
  198. InteropUnload((LPInteropLogger)RasLogger);
  199. #endif
  200. SPIDER_TRACE(SP_WSOCK, "WSACleanup()\n", 0);
  201. nRet = WSACleanup();
  202. if (nRet != 0)
  203. {
  204. SpiderWSErrDecode(-1);
  205. }
  206. g_pGatekeeper->Unlock();
  207. delete g_pGatekeeper;
  208. delete g_pCoder; // see ASSERT abovr
  209. g_pGatekeeper = NULL;
  210. g_pCoder = NULL;
  211. }
  212. // GK_TermModule();
  213. return (GKI_OK);
  214. }
  215. extern "C" VOID DLL_EXPORT
  216. GKI_SetGKAddress(PSOCKADDR_IN pAddr)
  217. {
  218. if (!pAddr)
  219. {
  220. return;
  221. }
  222. g_pGatekeeper->SetSockAddr(pAddr);
  223. }