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.

323 lines
8.8 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\gkireg.cpv $
  13. * *
  14. * $Revision: 1.13 $
  15. * $Date: 14 Feb 1997 16:44:06 $
  16. * *
  17. * $Author: CHULME $
  18. * *
  19. * $Log: S:\sturgeon\src\gki\vcs\gkireg.cpv $
  20. //
  21. // Rev 1.13 14 Feb 1997 16:44:06 CHULME
  22. // If fail to create semaphore - delete registration object before returning
  23. //
  24. // Rev 1.12 12 Feb 1997 01:11:06 CHULME
  25. // Redid thread synchronization to use Gatekeeper.Lock
  26. //
  27. // Rev 1.11 08 Feb 1997 12:14:02 CHULME
  28. // Added semaphore creation for later terminating the retry thread
  29. //
  30. // Rev 1.10 24 Jan 1997 18:30:00 CHULME
  31. // Reverted to rev 1.8
  32. //
  33. // Rev 1.8 22 Jan 1997 20:46:08 EHOWARDX
  34. // Work-around for race condition that may result in
  35. // GKI_RegistrationRequest returning GKI_ALREADY_REG.
  36. //
  37. // Rev 1.7 17 Jan 1997 09:02:16 CHULME
  38. // Changed reg.h to gkreg.h to avoid name conflict with inc directory
  39. //
  40. // Rev 1.6 10 Jan 1997 16:15:40 CHULME
  41. // Removed MFC dependency
  42. //
  43. // Rev 1.5 20 Dec 1996 16:38:28 CHULME
  44. // Fixed access synchronization with Gatekeeper lock
  45. //
  46. // Rev 1.4 13 Dec 1996 14:26:04 CHULME
  47. // Fixed access error on thread synchronization
  48. //
  49. // Rev 1.3 02 Dec 1996 23:50:50 CHULME
  50. // Added premptive synchronization code
  51. //
  52. // Rev 1.2 22 Nov 1996 15:22:24 CHULME
  53. // Added VCS log to the header
  54. *************************************************************************/
  55. // gkiregistration.cpp : Handles the GKI_RegistrationRequest API
  56. //
  57. #include "precomp.h"
  58. #include <process.h>
  59. #include <winsock.h>
  60. #include "GKICOM.H"
  61. #include "dspider.h"
  62. #include "dgkilit.h"
  63. #include "DGKIPROT.H"
  64. #include "GATEKPR.H"
  65. #include "gksocket.h"
  66. #include "GKREG.H"
  67. #include "h225asn.h"
  68. #include "coder.hpp"
  69. #include "dgkiext.h"
  70. #ifdef _DEBUG
  71. #undef THIS_FILE
  72. static char THIS_FILE[] = __FILE__;
  73. #endif
  74. extern "C" HRESULT DLL_EXPORT
  75. GKI_RegistrationRequest(long lVersion,
  76. SeqTransportAddr *pCallSignalAddr,
  77. EndpointType *pTerminalType,
  78. SeqAliasAddr *pRgstrtnRqst_trmnlAls,
  79. PCC_VENDORINFO pVendorInfo,
  80. HWND hWnd,
  81. WORD wBaseMessage,
  82. unsigned short usRegistrationTransport)
  83. {
  84. // ABSTRACT: This function is exported. It is called by the client application
  85. // to register with the Gatekeeper. It will create a CRegistration
  86. // object to track all pertanent information.
  87. // AUTHOR: Colin Hulme
  88. int nAddrFam;
  89. int nRet;
  90. HRESULT hResult;
  91. //char *pDestAddr;
  92. PSOCKADDR_IN pDestAddr;
  93. SeqTransportAddr *pTA;
  94. SeqAliasAddr *pAA;
  95. HANDLE hThread;
  96. #ifdef _DEBUG
  97. char szGKDebug[80];
  98. #endif
  99. BOOL fRAS = FALSE;
  100. SPIDER_TRACE(SP_FUNC, "GKI_RegistrationRequest(%x)\n", usRegistrationTransport);
  101. ASSERT(g_pGatekeeper);
  102. if(g_pGatekeeper == NULL)
  103. return (GKI_NOT_INITIALIZED);
  104. #ifdef _DEBUG
  105. if (dwGKIDLLFlags & SP_GKI)
  106. {
  107. SPIDER_TRACE(SP_GKI, "GKI_RegistrationRequest()\n", 0);
  108. Dump_GKI_RegistrationRequest(lVersion,
  109. pCallSignalAddr,
  110. pTerminalType,
  111. pRgstrtnRqst_trmnlAls,
  112. hWnd,
  113. wBaseMessage,
  114. usRegistrationTransport);
  115. }
  116. #endif
  117. // Check if there is already a registration
  118. // Create a Gatekeeper lock object on the stack
  119. // It's constructor will lock pGK and when we return
  120. // from any path, its destructor will unlock pGK
  121. CGatekeeperLock GKLock(g_pGatekeeper);
  122. if (g_pReg)
  123. {
  124. if (g_pReg->GetRasMessage() != 0)
  125. return (GKI_BUSY);
  126. else
  127. return (GKI_ALREADY_REG);
  128. }
  129. if (lVersion != GKI_VERSION)
  130. return (GKI_VERSION_ERROR);
  131. ASSERT((usRegistrationTransport == ipAddress_chosen) ||(usRegistrationTransport == ipxAddress_chosen));
  132. // Create a registration object
  133. g_pReg = new CRegistration;
  134. SPIDER_TRACE(SP_NEWDEL, "new g_pReg = %X\n", g_pReg);
  135. if (g_pReg == 0)
  136. return (GKI_NO_MEMORY);
  137. #if(0)
  138. // Create the semaphore used to signal the retry thread to exit
  139. g_pReg->m_hRetrySemaphore = CreateSemaphore(NULL,0,1,NULL);
  140. if(!g_pReg->m_hRetrySemaphore){
  141. SPIDER_TRACE(SP_NEWDEL, "del g_pReg = %X\n", g_pReg);
  142. delete g_pReg;
  143. g_pReg = 0;
  144. return (GKI_SEMAPHORE_ERROR);
  145. }
  146. #endif
  147. // Create a socket and bind to a local address
  148. g_pReg->m_pSocket = new CGKSocket;
  149. SPIDER_TRACE(SP_NEWDEL, "new g_pReg->m_pSocket = %X\n", g_pReg->m_pSocket);
  150. if (g_pReg->m_pSocket == 0)
  151. {
  152. SPIDER_TRACE(SP_NEWDEL, "del g_pReg = %X\n", g_pReg);
  153. delete g_pReg;
  154. g_pReg = 0;
  155. return (GKI_NO_MEMORY);
  156. }
  157. ASSERT(usRegistrationTransport == ipAddress_chosen);
  158. if(usRegistrationTransport != ipAddress_chosen)
  159. {
  160. delete g_pReg;
  161. g_pReg = 0;
  162. return (GKI_NO_MEMORY);
  163. }
  164. nAddrFam = PF_INET;
  165. pDestAddr = g_pGatekeeper->GetSockAddr();
  166. if ((nRet = g_pReg->m_pSocket->Create(nAddrFam, 0)) != 0)
  167. {
  168. SPIDER_TRACE(SP_NEWDEL, "del g_pReg = %X\n", g_pReg);
  169. delete g_pReg;
  170. g_pReg = 0;
  171. return (GKI_WINSOCK2_ERROR(nRet));
  172. }
  173. // Initialize registration member variables
  174. for (pTA = pCallSignalAddr; pTA != 0; pTA = pTA->next)
  175. {
  176. if ((hResult = g_pReg->AddCallSignalAddr(pTA->value)) != GKI_OK)
  177. {
  178. SPIDER_TRACE(SP_NEWDEL, "del g_pReg = %X\n", g_pReg);
  179. delete g_pReg;
  180. g_pReg = 0;
  181. return (hResult);
  182. }
  183. // if the transport type of the address being registered is the same as
  184. // the transport type of the gatekeeper, set RAS address
  185. if (pTA->value.choice == usRegistrationTransport)
  186. {
  187. if ((hResult = g_pReg->AddRASAddr(pTA->value, g_pReg->m_pSocket->GetPort())) != GKI_OK)
  188. {
  189. SPIDER_TRACE(SP_NEWDEL, "del g_pReg = %X\n", g_pReg);
  190. delete g_pReg;
  191. g_pReg = 0;
  192. return (hResult);
  193. }
  194. else
  195. fRAS = TRUE;
  196. }
  197. }
  198. if(pVendorInfo)
  199. {
  200. hResult = g_pReg->AddVendorInfo(pVendorInfo);
  201. }
  202. if (fRAS == FALSE) // No RAS address registered for this transport
  203. {
  204. SPIDER_TRACE(SP_NEWDEL, "del g_pReg = %X\n", g_pReg);
  205. delete g_pReg;
  206. g_pReg = 0;
  207. return (GKI_NO_TA_ERROR);
  208. }
  209. g_pReg->SetTerminalType(pTerminalType);
  210. for (pAA = pRgstrtnRqst_trmnlAls; pAA != 0; pAA = pAA->next)
  211. {
  212. if ((hResult = g_pReg->AddAliasAddr(pAA->value)) != GKI_OK)
  213. {
  214. SPIDER_TRACE(SP_NEWDEL, "del g_pReg = %X\n", g_pReg);
  215. delete g_pReg;
  216. g_pReg = 0;
  217. return (hResult);
  218. }
  219. }
  220. g_pReg->SetHWnd(hWnd);
  221. g_pReg->SetBaseMessage(wBaseMessage);
  222. g_pReg->SetRegistrationTransport(usRegistrationTransport);
  223. #if(0)
  224. // Start the retries thread
  225. hThread = (HANDLE)_beginthread(Retry, 0, 0);
  226. SPIDER_TRACE(SP_THREAD, "_beginthread(Retry, 0 0); <%X>\n", hThread);
  227. if (hThread == (HANDLE)-1)
  228. {
  229. SPIDER_TRACE(SP_NEWDEL, "del g_pReg = %X\n", g_pReg);
  230. delete g_pReg;
  231. g_pReg = 0;
  232. return (GKI_NO_THREAD);
  233. }
  234. g_pReg->SetRetryThread(hThread);
  235. #else
  236. // initialize timer and values
  237. UINT_PTR uTimer = g_pReg->StartRetryTimer();
  238. if (!uTimer)
  239. {
  240. SPIDER_TRACE(SP_NEWDEL, "del g_pReg = %X\n", g_pReg);
  241. delete g_pReg;
  242. g_pReg = 0;
  243. return (GKI_NO_THREAD);
  244. }
  245. #endif
  246. #ifdef BROADCAST_DISCOVERY
  247. // Check to see if we are not bound to a gatekeeper
  248. if (pDestAddr == 0)
  249. {
  250. hThread = (HANDLE)_beginthread(GKDiscovery, 0, 0);
  251. SPIDER_TRACE(SP_THREAD, "_beginthread(GKDiscovery, 0, 0); <%X>\n", hThread);
  252. if (hThread == (HANDLE)-1)
  253. {
  254. SPIDER_TRACE(SP_NEWDEL, "del g_pReg = %X\n", g_pReg);
  255. delete g_pReg;
  256. g_pReg = 0;
  257. return (GKI_NO_THREAD);
  258. }
  259. g_pReg->SetDiscThread(hThread);
  260. return (GKI_OK);
  261. }
  262. #else
  263. ASSERT(pDestAddr);
  264. #endif
  265. // Connect to destination gatekeeper and retrieve RAS port
  266. if ((nRet = g_pReg->m_pSocket->Connect(pDestAddr)) != 0)
  267. {
  268. SPIDER_TRACE(SP_NEWDEL, "del g_pReg = %X\n", g_pReg);
  269. delete g_pReg;
  270. g_pReg = 0;
  271. return (GKI_WINSOCK2_ERROR(nRet));
  272. }
  273. // Create RegistrationRequest structure - Encode and send PDU
  274. if ((hResult = g_pReg->RegistrationRequest(FALSE)) != GKI_OK)
  275. {
  276. SPIDER_TRACE(SP_NEWDEL, "del g_pReg = %X\n", g_pReg);
  277. delete g_pReg;
  278. g_pReg = 0;
  279. return (hResult);
  280. }
  281. // Post a receive on this socket
  282. hThread = (HANDLE)_beginthread(PostReceive, 0, 0);
  283. SPIDER_TRACE(SP_THREAD, "_beginthread(PostReceive, 0, 0); <%X>\n", hThread);
  284. if (hThread == (HANDLE)-1)
  285. {
  286. SPIDER_TRACE(SP_NEWDEL, "del g_pReg = %X\n", g_pReg);
  287. delete g_pReg;
  288. g_pReg = 0;
  289. return (GKI_NO_THREAD);
  290. }
  291. g_pReg->SetRcvThread(hThread);
  292. return (GKI_OK);
  293. }
  294.