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.

259 lines
10 KiB

  1. /**MOD+**********************************************************************/
  2. /* Module: nlapi.cpp */
  3. /* */
  4. /* Purpose: Network Layer API */
  5. /* */
  6. /* Copyright(C) Microsoft Corporation 1997-1999 */
  7. /* */
  8. /****************************************************************************/
  9. #include <adcg.h>
  10. extern "C" {
  11. #define TRC_GROUP TRC_GROUP_NETWORK
  12. #define TRC_FILE "anlapi"
  13. #include <atrcapi.h>
  14. }
  15. #include "autil.h"
  16. #include "nl.h"
  17. #include "nc.h"
  18. #include "cd.h"
  19. #include "snd.h"
  20. CNL::CNL(CObjs* objs)
  21. {
  22. _pClientObjects = objs;
  23. }
  24. CNL::~CNL()
  25. {
  26. }
  27. /**PROC+*********************************************************************/
  28. /* Name: NL_Init */
  29. /* */
  30. /* Purpose: Initialize the Network Layer */
  31. /* */
  32. /* Returns: None */
  33. /* */
  34. /* Params: IN pCallbacks - callback functions */
  35. /* */
  36. /**PROC-*********************************************************************/
  37. DCVOID DCAPI CNL::NL_Init(PNL_CALLBACKS pCallbacks)
  38. {
  39. DC_BEGIN_FN("NL_Init");
  40. _pUi = _pClientObjects->_pUiObject;
  41. _pCd = _pClientObjects->_pCdObject;
  42. _pMcs = _pClientObjects->_pMCSObject;
  43. _pNc = _pClientObjects->_pNcObject;
  44. _pUt = _pClientObjects->_pUtObject;
  45. _pRcv = _pClientObjects->_pRcvObject;
  46. TRC_ASSERT((pCallbacks != NULL), (TB, _T("Missing callbacks")));
  47. /************************************************************************/
  48. /* Store the callback functions */
  49. /************************************************************************/
  50. DC_MEMCPY((&_NL.callbacks), pCallbacks, sizeof(NL_CALLBACKS));
  51. /************************************************************************/
  52. /* Start the new thread */
  53. /************************************************************************/
  54. #ifdef OS_WIN32
  55. _pUt->UT_StartThread(CNC::NC_StaticMain, &(_NL.threadData), _pNc);
  56. #else
  57. _pNc->NC_Init();
  58. #endif
  59. /****************************************************************************/
  60. /* Seed the random number generator from the clock */
  61. /****************************************************************************/
  62. #ifdef DC_DEBUG
  63. srand((DCUINT)_pUt->UT_GetCurrentTimeMS());
  64. #endif /* DC_DEBUG */
  65. TRC_NRM((TB, _T("Completed NL_Init")));
  66. DC_END_FN();
  67. return;
  68. } /* NL_Init */
  69. /**PROC+*********************************************************************/
  70. /* Name: NL_Term */
  71. /* */
  72. /* Purpose: Terminate the network layer. */
  73. /* */
  74. /* Returns: nothing */
  75. /* */
  76. /* Params: none */
  77. /* */
  78. /**PROC-*********************************************************************/
  79. DCVOID DCAPI CNL::NL_Term(DCVOID)
  80. {
  81. DC_BEGIN_FN("NL_Term");
  82. _pUt->UT_DestroyThread(_NL.threadData);
  83. TRC_NRM((TB, _T("Completed NL_Term")));
  84. DC_END_FN();
  85. return;
  86. } /* NL_Term */
  87. /**PROC+*********************************************************************/
  88. /* Name: NL_Connect */
  89. /* */
  90. /* Purpose: Connect to a server */
  91. /* */
  92. /* Returns: Nothing */
  93. /* */
  94. /* Params: bInitateConnect - TRUE if initate connection */
  95. /* pServerAddress - address of the Server to connect to */
  96. /* transportType - transport type: NL_TRANSPORT_TCP */
  97. /* pProtocolName - protocol name, one of */
  98. /* - NL_PROTOCOL_T128 */
  99. /* - Er, that's it. */
  100. /* pUserData - user data to pass to Server Security Manager */
  101. /* userDataLength - length of user data */
  102. /* */
  103. /**PROC-*********************************************************************/
  104. HRESULT DCAPI CNL::NL_Connect(BOOL bInitateConnect,
  105. PDCTCHAR pServerAddress,
  106. DCUINT transportType,
  107. PDCTCHAR pProtocolName,
  108. PDCVOID pUserData,
  109. DCUINT userDataLength)
  110. {
  111. DCUINT totalLen;
  112. NC_CONNECT_DATA connect;
  113. HRESULT hr = E_FAIL;
  114. DC_BEGIN_FN("NL_Connect");
  115. DC_IGNORE_PARAMETER(transportType);
  116. TRC_ASSERT((transportType == NL_TRANSPORT_TCP),
  117. (TB, _T("Invalid transport type %d"), transportType));
  118. if( bInitateConnect )
  119. {
  120. TRC_ASSERT((pServerAddress != NULL), (TB, _T("No server address")));
  121. }
  122. TRC_ASSERT((pProtocolName != NULL), (TB, _T("No protocol name")));
  123. DC_IGNORE_PARAMETER(pProtocolName);
  124. if( bInitateConnect )
  125. {
  126. TRC_DBG((TB, _T("ServerAddress %s protocol %s, UD len %d"),
  127. pServerAddress, pProtocolName, userDataLength));
  128. }
  129. else
  130. {
  131. TRC_DBG((TB, _T("Connect endpoint : protocol %s, UD len %d"),
  132. pProtocolName, userDataLength));
  133. }
  134. TRC_DATA_DBG("UserData", pUserData, userDataLength);
  135. /************************************************************************/
  136. /* Copy data to buffer ready to send to NC. */
  137. /************************************************************************/
  138. if( bInitateConnect )
  139. {
  140. connect.addressLen = DC_TSTRBYTELEN(pServerAddress);
  141. connect.bInitateConnect = TRUE;
  142. }
  143. else
  144. {
  145. connect.addressLen = 0;
  146. connect.bInitateConnect = FALSE;
  147. }
  148. connect.protocolLen = DC_TSTRBYTELEN(pProtocolName);
  149. connect.userDataLen = userDataLength;
  150. totalLen = connect.addressLen + connect.protocolLen + connect.userDataLen;
  151. TRC_DBG((TB, _T("Total length %d"), totalLen));
  152. TRC_ASSERT((totalLen <= NC_CONNECT_DATALEN),
  153. (TB, _T("Too much connect data %d"), totalLen));
  154. if( bInitateConnect )
  155. {
  156. hr = StringCchCopy((PDCTCHAR)connect.data,
  157. SIZE_TCHARS(connect.data),
  158. pServerAddress);
  159. if (FAILED(hr)) {
  160. TRC_ERR((TB,_T("String copy failed for pServerAddress: 0x%x"),hr));
  161. DC_QUIT;
  162. }
  163. }
  164. hr = StringCbCopy((PDCTCHAR)(connect.data + connect.addressLen),
  165. totalLen - connect.addressLen,
  166. pProtocolName);
  167. if (SUCCEEDED(hr)) {
  168. DC_MEMCPY(connect.data + connect.addressLen + connect.protocolLen,
  169. pUserData,
  170. connect.userDataLen);
  171. /************************************************************************/
  172. /* Add the header bytes. */
  173. /************************************************************************/
  174. totalLen += FIELDOFFSET(NC_CONNECT_DATA, data[0]);
  175. TRC_DATA_DBG("Connect data", &connect, totalLen);
  176. _pCd->CD_DecoupleNotification(CD_RCV_COMPONENT,
  177. _pNc,
  178. CD_NOTIFICATION_FUNC(CNC,NC_Connect),
  179. (PDCVOID)&connect,
  180. totalLen);
  181. hr = S_OK;
  182. }
  183. else {
  184. TRC_ERR((TB,_T("String copy for user data failed: 0x%x"),hr));
  185. DC_QUIT;
  186. }
  187. DC_EXIT_POINT:
  188. DC_END_FN();
  189. return hr;
  190. } /* NL_Connect */
  191. /**PROC+*********************************************************************/
  192. /* Name: NL_Disconnect */
  193. /* */
  194. /* Purpose: Disconnect from the Server */
  195. /* */
  196. /* Returns: None */
  197. /* */
  198. /* Params: None */
  199. /* */
  200. /**PROC-*********************************************************************/
  201. DCVOID DCAPI CNL::NL_Disconnect(DCVOID)
  202. {
  203. DC_BEGIN_FN("NL_Disconnect");
  204. _pCd->CD_DecoupleSimpleNotification(CD_RCV_COMPONENT,
  205. _pNc,
  206. CD_NOTIFICATION_FUNC(CNC,NC_Disconnect),
  207. (ULONG_PTR) 0);
  208. DC_END_FN();
  209. return;
  210. } /* NL_Disconnect */