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.

624 lines
15 KiB

  1. //============================================================================
  2. // Copyright (C) Microsoft Corporation, 1996 - 1999
  3. //
  4. // File: conndlg.cpp
  5. //
  6. // History:
  7. // 09/22/96 Abolade Gbadegesin Created.
  8. //
  9. // Implementation of the connection-status dialog.
  10. //============================================================================
  11. #include "stdafx.h"
  12. #include "dialog.h"
  13. #include "rtrutilp.h"
  14. //nclude "ddmadmin.h"
  15. //nclude "ddmroot.h"
  16. extern "C" {
  17. //nclude "dim.h"
  18. #include "ras.h"
  19. }
  20. #include "conndlg.h"
  21. #include "rtrstr.h"
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. //----------------------------------------------------------------------------
  28. // Class: CConnDlg
  29. //
  30. //----------------------------------------------------------------------------
  31. //----------------------------------------------------------------------------
  32. // Function: CConnDlg::CConnDlg
  33. //
  34. // Constructor: initialize the base-class and the dialog's data.
  35. //----------------------------------------------------------------------------
  36. CConnDlg::CConnDlg(
  37. CString strMachineName,
  38. HANDLE hConnection,
  39. ITFSNode* pDialInNode,
  40. CWnd* pParent
  41. ) : CBaseDialog(IDD_DDM_CONN, pParent)
  42. {
  43. m_strMachineName = strMachineName;
  44. m_hConnection = hConnection;
  45. // m_spDialInNode = pDialInNode;
  46. m_bChanged = FALSE;
  47. }
  48. //----------------------------------------------------------------------------
  49. // Function: CConnDlg::DoDataExchange
  50. //
  51. // DDX handler.
  52. //----------------------------------------------------------------------------
  53. VOID
  54. CConnDlg::DoDataExchange(
  55. CDataExchange* pDX
  56. ) {
  57. CBaseDialog::DoDataExchange(pDX);
  58. DDX_Control(pDX, IDC_DC_COMBO_CONNLIST, m_cbConnections);
  59. }
  60. BEGIN_MESSAGE_MAP(CConnDlg, CBaseDialog)
  61. ON_COMMAND(IDC_DC_BTN_RESET, OnReset)
  62. ON_COMMAND(IDC_DC_BTN_HANGUP, OnHangUp)
  63. ON_COMMAND(IDC_DC_BTN_REFRESH, OnRefresh)
  64. ON_CBN_SELENDOK(IDC_DC_COMBO_CONNLIST, OnSelendokConnList)
  65. END_MESSAGE_MAP()
  66. BOOL
  67. CConnDlg::OnInitDialog(
  68. ) {
  69. CBaseDialog::OnInitDialog();
  70. ::MprAdminServerConnect((LPWSTR)(LPCTSTR)m_strMachineName, &m_hServer);
  71. RefreshItem(m_hConnection);
  72. return FALSE;
  73. }
  74. void
  75. CConnDlg::OnCancel()
  76. {
  77. //Extra clean up
  78. ::MprAdminServerDisconnect(m_hServer);
  79. CDialog::OnCancel();
  80. }
  81. BOOL
  82. CConnDlg::RefreshItem(
  83. HANDLE hConnection,
  84. BOOL bDisconnected
  85. ) {
  86. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  87. DWORD dwErr, dwTotal;
  88. DWORD rp0Count, rc0Count;
  89. BYTE* rp0Table, *rc0Table;
  90. BOOL bChanged = FALSE;
  91. rp0Table = rc0Table = 0;
  92. rp0Count = 0;
  93. do {
  94. //
  95. // Retrieve an array of ports
  96. //
  97. /*--ft: actually this is never needed in this context
  98. dwErr = ::MprAdminPortEnum(
  99. m_hServer,
  100. 0,
  101. INVALID_HANDLE_VALUE,
  102. (BYTE**)&rp0Table,
  103. (DWORD)-1,
  104. &rp0Count,
  105. &dwTotal,
  106. NULL
  107. );
  108. if (dwErr != NO_ERROR) { break; }
  109. */
  110. //
  111. // Retrieve an array of connections
  112. //
  113. dwErr = ::MprAdminConnectionEnum(
  114. m_hServer,
  115. 0,
  116. (BYTE**)&rc0Table,
  117. (DWORD)-1,
  118. &rc0Count,
  119. &dwTotal,
  120. NULL
  121. );
  122. if (dwErr != NO_ERROR) { break; }
  123. // if the caller signals this connection to be terminated, we remove its record from the
  124. // array returned by MprAdminConnectionEnum().
  125. if (bDisconnected)
  126. {
  127. INT i;
  128. RAS_CONNECTION_0* prc0;
  129. for (i = 0, prc0 = (RAS_CONNECTION_0*)rc0Table; i < (INT)rc0Count; i++, prc0++)
  130. {
  131. // if the record to delete was found, just move the memory over it and update rc0Count.
  132. // the memory will still be freed by MprAdminBufferFree().
  133. if (prc0->hConnection == hConnection)
  134. {
  135. if (i != (INT)(rc0Count - 1))
  136. {
  137. // MoveMemory(dest, src, size)
  138. MoveMemory(prc0, prc0+1, (rc0Count - (i + 1))*sizeof(RAS_CONNECTION_0));
  139. }
  140. rc0Count--;
  141. break;
  142. }
  143. }
  144. }
  145. //
  146. // Do the refresh of the display,
  147. // selecting the item specified by the caller.
  148. //
  149. bChanged = Refresh(rp0Table, rp0Count, rc0Table, rc0Count, hConnection);
  150. dwErr = NO_ERROR;
  151. } while (FALSE);
  152. if (rc0Table) { ::MprAdminBufferFree(rc0Table); }
  153. if (rp0Table) { ::MprAdminBufferFree(rp0Table); }
  154. if (dwErr != NO_ERROR) {
  155. TCHAR szText[1024];
  156. FormatSystemError(HRESULT_FROM_WIN32(dwErr),
  157. szText, DimensionOf(szText),
  158. IDS_ERR_INITDLGERROR, FSEFLAG_ANYMESSAGE);
  159. AfxMessageBox(szText);
  160. EndDialog(IDCANCEL);
  161. }
  162. return bChanged;
  163. }
  164. VOID
  165. CConnDlg::OnHangUp(
  166. ) {
  167. INT iSel;
  168. DWORD dwErr;
  169. HANDLE hConnection;
  170. RAS_CONNECTION_0* prc0;
  171. CWaitCursor wait;
  172. iSel = m_cbConnections.GetCurSel();
  173. if (iSel == CB_ERR) { return; }
  174. //
  175. // Get the connection to be hung up
  176. //
  177. hConnection = (HANDLE)m_cbConnections.GetItemData(iSel);
  178. //
  179. // Retrieve the interface for this connection;
  180. // we then hang up the connection by disconnecting its interface
  181. //
  182. dwErr = ::MprAdminConnectionGetInfo(
  183. m_hServer,
  184. 0,
  185. hConnection,
  186. (BYTE**)&prc0
  187. );
  188. if (dwErr == NO_ERROR && prc0) {
  189. //
  190. // Disconnect the connections interface
  191. //
  192. dwErr = ::MprAdminInterfaceDisconnect(
  193. m_hServer,
  194. prc0->hInterface
  195. );
  196. ::MprAdminBufferFree(prc0);
  197. m_bChanged |= RefreshItem(hConnection, dwErr == NO_ERROR);
  198. }
  199. }
  200. VOID
  201. CConnDlg::OnReset(
  202. ) {
  203. INT iSel;
  204. HANDLE hConnection;
  205. iSel = m_cbConnections.GetCurSel();
  206. if (iSel == CB_ERR) { return; }
  207. hConnection = (HANDLE)m_cbConnections.GetItemData(iSel);
  208. ::MprAdminConnectionClearStats(
  209. m_hServer,
  210. hConnection
  211. );
  212. m_bChanged |= RefreshItem(INVALID_HANDLE_VALUE);
  213. }
  214. VOID
  215. CConnDlg::OnSelendokConnList(
  216. ) {
  217. m_bChanged |= RefreshItem(INVALID_HANDLE_VALUE);
  218. }
  219. VOID
  220. CConnDlg::OnRefresh(
  221. ) {
  222. m_bChanged |= RefreshItem(INVALID_HANDLE_VALUE);
  223. }
  224. BOOL
  225. CConnDlg::Refresh(
  226. BYTE* rp0Table,
  227. DWORD rp0Count,
  228. BYTE* rc0Table,
  229. DWORD rc0Count,
  230. VOID* pParam
  231. ) {
  232. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  233. DWORD dwErr;
  234. CString sItem;
  235. RAS_PORT_0* prp0;
  236. RAS_PORT_1* prp1;
  237. RAS_CONNECTION_0* prc0;
  238. RAS_CONNECTION_1* prc1;
  239. INT i, j, iSel, count;
  240. HANDLE hConnection, hConnSel = NULL, *pConnTable;
  241. TCHAR szNumber[32];
  242. BOOL bChanged = FALSE;
  243. hConnSel = (HANDLE)pParam;
  244. //
  245. // Fill an array of connection-handles with the connections which are
  246. // already in the combobox.
  247. //
  248. count = m_cbConnections.GetCount();
  249. if (count) {
  250. pConnTable = new HANDLE[count];
  251. }
  252. for (i = 0; i < count; i++) {
  253. pConnTable[i] = (HANDLE)m_cbConnections.GetItemData(i);
  254. }
  255. //
  256. // Refresh the combobox with connection-names;
  257. // We do this in two passes, first adding the names of connections
  258. // which aren't already in the combobox,
  259. // and then removing the names of connections which aren't
  260. // in the table of connections ('rc0Table').
  261. //
  262. for (i = 0, prc0 = (RAS_CONNECTION_0*)rc0Table; i < (INT)rc0Count;
  263. i++, prc0++) {
  264. //
  265. // See if connection 'i' is already in the combobox.
  266. //
  267. for (j = 0; j < count; j++) {
  268. if (pConnTable[j] == prc0->hConnection) { break; }
  269. }
  270. if (j < count) { continue; }
  271. //
  272. // Connection 'i' isn't already in the combobox, so add it.
  273. //
  274. sItem.Format(TEXT("%ls"), prc0->wszInterfaceName);
  275. iSel = m_cbConnections.AddString(sItem);
  276. if (iSel >= 0) {
  277. m_cbConnections.SetItemData(iSel, reinterpret_cast<ULONG_PTR>(prc0->hConnection));
  278. if (prc0->hConnection == hConnSel) {
  279. m_cbConnections.SetCurSel(iSel);
  280. }
  281. bChanged = TRUE;
  282. }
  283. }
  284. if (count) { delete [] pConnTable; }
  285. //
  286. // Second stage: remove all connections which aren't in 'rc0Table'.
  287. // This is only necessary if there were any connections in the combobox
  288. // before.
  289. //
  290. if (count > 0) {
  291. count = m_cbConnections.GetCount();
  292. for (i = 0; i < count; i++) {
  293. hConnection = (HANDLE)m_cbConnections.GetItemData(i);
  294. //
  295. // See if the connection is in 'rc0Table'.
  296. //
  297. for (j = 0, prc0 = (RAS_CONNECTION_0*)rc0Table; j < (INT)rc0Count;
  298. j++, prc0++) {
  299. if (prc0->hConnection == hConnection) { break; }
  300. }
  301. if (j < (INT)rc0Count) {
  302. if (prc0->hConnection == hConnSel) {
  303. m_cbConnections.SetCurSel(i);
  304. }
  305. continue;
  306. }
  307. //
  308. // The connection wasn't found in 'rc0Table',
  309. // so remove it from the combobox,
  310. // and adjust the enumeration indices.
  311. //
  312. m_cbConnections.DeleteString(i);
  313. --i; --count;
  314. bChanged = TRUE;
  315. }
  316. }
  317. // Clear out the address fields
  318. SetDlgItemText(IDC_DC_TEXT_IPADDRESS, c_szEmpty);
  319. SetDlgItemText(IDC_DC_TEXT_IPXADDRESS, c_szEmpty);
  320. SetDlgItemText(IDC_DC_TEXT_NBFADDRESS, c_szEmpty);
  321. SetDlgItemText(IDC_DC_TEXT_ATLKADDRESS, c_szEmpty);
  322. // Clear out the line bps field
  323. SetDlgItemText(IDC_DC_TEXT_DURATION, c_szEmpty);
  324. SetDlgItemText(IDC_DC_TEXT_BYTESIN, c_szEmpty);
  325. SetDlgItemText(IDC_DC_TEXT_BYTESOUT, c_szEmpty);
  326. SetDlgItemText(IDC_DC_TEXT_FRAMESIN, c_szEmpty);
  327. SetDlgItemText(IDC_DC_TEXT_FRAMESOUT, c_szEmpty);
  328. SetDlgItemText(IDC_DC_TEXT_COMPIN, c_szEmpty);
  329. SetDlgItemText(IDC_DC_TEXT_COMPOUT, c_szEmpty);
  330. SetDlgItemText(IDC_DC_TEXT_TIMEOUT, c_szEmpty);
  331. SetDlgItemText(IDC_DC_TEXT_ALIGNMENT, c_szEmpty);
  332. SetDlgItemText(IDC_DC_TEXT_FRAMING, c_szEmpty);
  333. SetDlgItemText(IDC_DC_TEXT_HWOVERRUN, c_szEmpty);
  334. SetDlgItemText(IDC_DC_TEXT_BUFOVERRUN, c_szEmpty);
  335. SetDlgItemText(IDC_DC_TEXT_CRC, c_szEmpty);
  336. //
  337. // If there is no selection select the first item
  338. //
  339. if ((iSel = m_cbConnections.GetCurSel()) == CB_ERR) {
  340. iSel = m_cbConnections.SetCurSel(0);
  341. }
  342. if (iSel == CB_ERR)
  343. {
  344. if (GetFocus() == GetDlgItem(IDC_DC_BTN_HANGUP))
  345. GetDlgItem(IDC_DC_BTN_RESET)->SetFocus();
  346. GetDlgItem(IDC_DC_BTN_HANGUP)->EnableWindow(FALSE);
  347. return bChanged;
  348. }
  349. //
  350. // Update the display with information for the selected item
  351. //
  352. hConnection = (HANDLE)m_cbConnections.GetItemData(iSel);
  353. for (i = 0, prc0 = (RAS_CONNECTION_0*)rc0Table; i < (INT)rc0Count;
  354. i++, prc0++) {
  355. if (prc0->hConnection == hConnection) { break; }
  356. }
  357. if (i >= (INT)rc0Count) { return bChanged; }
  358. //
  359. // First update the RAS_CONNECTION_0-based information
  360. //
  361. FormatDuration(prc0->dwConnectDuration, sItem, UNIT_SECONDS);
  362. SetDlgItemText(IDC_DC_TEXT_DURATION, sItem);
  363. do {
  364. //
  365. // Now retrieve the RAS_CONNECTION_1 information for this connection.
  366. //
  367. dwErr = ::MprAdminConnectionGetInfo(
  368. m_hServer,
  369. 1,
  370. prc0->hConnection,
  371. (BYTE**)&prc1
  372. );
  373. if (dwErr != NO_ERROR || !prc1) { break; }
  374. //
  375. // Set the information in the dialog text-controls
  376. //
  377. FormatNumber(prc1->dwBytesRcved, szNumber, DimensionOf(szNumber), FALSE);
  378. SetDlgItemText(IDC_DC_TEXT_BYTESIN, szNumber);
  379. FormatNumber(prc1->dwBytesXmited, szNumber, DimensionOf(szNumber), FALSE);
  380. SetDlgItemText(IDC_DC_TEXT_BYTESOUT, szNumber);
  381. FormatNumber(prc1->dwFramesRcved, szNumber, DimensionOf(szNumber), FALSE);
  382. SetDlgItemText(IDC_DC_TEXT_FRAMESIN, szNumber);
  383. FormatNumber(prc1->dwFramesXmited, szNumber, DimensionOf(szNumber), FALSE);
  384. SetDlgItemText(IDC_DC_TEXT_FRAMESOUT, szNumber);
  385. FormatNumber(prc1->dwCompressionRatioIn, szNumber, DimensionOf(szNumber), FALSE);
  386. sItem = szNumber;
  387. sItem += TEXT( "%" );
  388. SetDlgItemText(IDC_DC_TEXT_COMPIN, sItem);
  389. FormatNumber(prc1->dwCompressionRatioOut, szNumber, DimensionOf(szNumber), FALSE);
  390. sItem = szNumber;
  391. sItem += TEXT( "%" );
  392. SetDlgItemText(IDC_DC_TEXT_COMPOUT, sItem);
  393. FormatNumber(prc1->dwCrcErr, szNumber, DimensionOf(szNumber), FALSE);
  394. SetDlgItemText(IDC_DC_TEXT_CRC, szNumber);
  395. FormatNumber(prc1->dwTimeoutErr, szNumber, DimensionOf(szNumber), FALSE);
  396. SetDlgItemText(IDC_DC_TEXT_TIMEOUT, szNumber);
  397. FormatNumber(prc1->dwAlignmentErr, szNumber, DimensionOf(szNumber), FALSE);
  398. SetDlgItemText(IDC_DC_TEXT_ALIGNMENT, szNumber);
  399. FormatNumber(prc1->dwFramingErr, szNumber, DimensionOf(szNumber), FALSE);
  400. SetDlgItemText(IDC_DC_TEXT_FRAMING, szNumber);
  401. FormatNumber(prc1->dwHardwareOverrunErr, szNumber, DimensionOf(szNumber), FALSE);
  402. SetDlgItemText(IDC_DC_TEXT_HWOVERRUN, szNumber);
  403. FormatNumber(prc1->dwBufferOverrunErr, szNumber, DimensionOf(szNumber), FALSE);
  404. SetDlgItemText(IDC_DC_TEXT_BUFOVERRUN, szNumber);
  405. //
  406. // Fill in the network registration info for projected networks.
  407. //
  408. if (prc1->PppInfo.ip.dwError == NO_ERROR) {
  409. SetDlgItemTextW(IDC_DC_TEXT_IPADDRESS, prc1->PppInfo.ip.wszRemoteAddress);
  410. }
  411. if (prc1->PppInfo.ipx.dwError == NO_ERROR) {
  412. SetDlgItemTextW(IDC_DC_TEXT_IPXADDRESS, prc1->PppInfo.ipx.wszAddress);
  413. }
  414. if (prc1->PppInfo.nbf.dwError == NO_ERROR) {
  415. SetDlgItemTextW(IDC_DC_TEXT_NBFADDRESS, prc1->PppInfo.nbf.wszWksta);
  416. }
  417. if (prc1->PppInfo.at.dwError == NO_ERROR) {
  418. SetDlgItemTextW(IDC_DC_TEXT_ATLKADDRESS, prc1->PppInfo.at.wszAddress);
  419. }
  420. ::MprAdminBufferFree(prc1);
  421. } while (FALSE);
  422. if (dwErr != NO_ERROR) {
  423. TCHAR szText[1024];
  424. FormatSystemError(HRESULT_FROM_WIN32(dwErr),
  425. szText, DimensionOf(szText),
  426. IDS_ERR_INITDLGERROR, FSEFLAG_ANYMESSAGE);
  427. AfxMessageBox(szText);
  428. EndDialog(IDCANCEL);
  429. }
  430. return bChanged;
  431. }