Source code of Windows XP (NT5)
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.

300 lines
11 KiB

  1. /*
  2. File ipxui.c
  3. Dialog that edits the ipx properties.
  4. Paul Mayfield, 10/9/97
  5. */
  6. #include "rassrv.h"
  7. // Help maps
  8. static const DWORD phmIpxui[] =
  9. {
  10. CID_NetTab_Ipxui_RB_AutoAssign, IDH_NetTab_Ipxui_RB_AutoAssign,
  11. CID_NetTab_Ipxui_RB_ManualAssign, IDH_NetTab_Ipxui_RB_ManualAssign,
  12. CID_NetTab_Ipxui_CB_AssignSame, IDH_NetTab_Ipxui_CB_AssignSame,
  13. CID_NetTab_Ipxui_EB_Netnum, IDH_NetTab_Ipxui_EB_Netnum,
  14. //CID_NetTab_Ipxui_ST_Network, IDH_NetTab_Ipxui_ST_Network,
  15. CID_NetTab_Ipxui_CB_CallerSpec, IDH_NetTab_Ipxui_CB_CallerSpec,
  16. //CID_NetTab_Ipxui_CB_ExposeNetwork, IDH_NetTab_Ipxui_CB_ExposeNetwork,
  17. 0, 0
  18. };
  19. void IpxUiDisplayError(HWND hwnd, DWORD dwErr) {
  20. ErrDisplayError(hwnd, dwErr, ERR_IPXPROP_CATAGORY, 0, Globals.dwErrorData);
  21. }
  22. // Enables/disables windows in the dialog box depending
  23. // on the ipx parameters
  24. DWORD IpxEnableWindows(HWND hwndDlg, IPX_PARAMS * pIpxParams) {
  25. // If auto assign is selected, disable address and global wan fields
  26. EnableWindow(GetDlgItem(hwndDlg, CID_NetTab_Ipxui_EB_Netnum), !pIpxParams->bAutoAssign);
  27. //EnableWindow(GetDlgItem(hwndDlg, CID_NetTab_Ipxui_CB_AssignSame), !pIpxParams->bAutoAssign);
  28. return NO_ERROR;
  29. }
  30. // Adjusts the label that determines whether internal net numbers
  31. // are automatically assigned.
  32. DWORD IpxAdjustNetNumberLabel(HWND hwndDlg, BOOL bGlobalWan) {
  33. PWCHAR pszManAssignLabel, pszAutoAssignLabel;
  34. // Modify the net num label according to the global wan setting
  35. if (bGlobalWan) {
  36. pszManAssignLabel =
  37. (PWCHAR) PszLoadString(Globals.hInstDll, SID_NETWORKNUMBERLABEL);
  38. pszAutoAssignLabel =
  39. (PWCHAR) PszLoadString(Globals.hInstDll, SID_AUTO_NETNUM_LABEL);
  40. }
  41. else {
  42. pszManAssignLabel =
  43. (PWCHAR) PszLoadString(Globals.hInstDll, SID_STARTNETNUMLABEL);
  44. pszAutoAssignLabel =
  45. (PWCHAR) PszLoadString(Globals.hInstDll, SID_AUTO_NETNUMS_LABEL);
  46. }
  47. SetWindowTextW(GetDlgItem(hwndDlg, CID_NetTab_Ipxui_RB_ManualAssign), pszManAssignLabel);
  48. SetWindowTextW(GetDlgItem(hwndDlg, CID_NetTab_Ipxui_RB_AutoAssign), pszAutoAssignLabel);
  49. return NO_ERROR;
  50. }
  51. #define isBetween(b,a,c) ((b >= a) && (b <= c))
  52. // Filters characters that can be edited into an ipx net number control
  53. BOOL IpxValidNetNumberChar(WCHAR wcNumChar) {
  54. return (iswdigit(wcNumChar) ||
  55. isBetween(wcNumChar, (WCHAR)'A', (WCHAR)'F') ||
  56. isBetween(wcNumChar, (WCHAR)'a', (WCHAR)'f') );
  57. }
  58. // Returns TRUE if buf points to a valid ipx net number (8 digit hex)
  59. // Otherwise returns FALSE and puts a corrected version of the number
  60. // in pszCorrect. pszCorrect will always contain the correct version.
  61. BOOL IpxValidNetNumber(PWCHAR pszNum, PWCHAR pszCorrect) {
  62. BOOL cFlag = TRUE;
  63. int i, j=0, len = (int) wcslen(pszNum);
  64. // Validate the name
  65. if (len > 8) {
  66. lstrcpynW(pszCorrect, pszNum, 8);
  67. pszCorrect[8] = (WCHAR)0;
  68. return FALSE;
  69. }
  70. // Validate the characters
  71. for (i = 0; i < len; i++) {
  72. if (IpxValidNetNumberChar(pszNum[i]))
  73. pszCorrect[j++] = pszNum[i];
  74. else
  75. cFlag = FALSE;
  76. }
  77. pszCorrect[j] = (WCHAR)0;
  78. return cFlag;
  79. }
  80. // We subclass the ipx address text fields so that they don't
  81. // allow bogus values to be typed.
  82. LRESULT CALLBACK IpxNetNumProc (HWND hwnd,
  83. UINT uMsg,
  84. WPARAM wParam,
  85. LPARAM lParam) {
  86. WNDPROC wProc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_USERDATA);
  87. if (uMsg == WM_CHAR) {
  88. if ((wParam != VK_BACK) && (!IpxValidNetNumberChar((WCHAR)wParam)))
  89. return FALSE;
  90. }
  91. return CallWindowProc(wProc, hwnd, uMsg, wParam, lParam);
  92. }
  93. // Initializes the Ipx Properties Dialog
  94. DWORD IpxInitDialog(HWND hwndDlg, LPARAM lParam) {
  95. WCHAR pszAddr[16];
  96. IPX_PARAMS * pIpxParams = (IPX_PARAMS *)(((PROT_EDIT_DATA*)lParam)->pbData);
  97. ULONG_PTR pOldWndProc;
  98. HWND hwndEdit;
  99. // Store the parameters with the window handle
  100. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
  101. // Subclass the edit control(s)
  102. hwndEdit = GetDlgItem(hwndDlg, CID_NetTab_Ipxui_EB_Netnum);
  103. pOldWndProc = SetWindowLongPtr(hwndEdit, GWLP_WNDPROC, (LONG_PTR)IpxNetNumProc);
  104. SetWindowLongPtr(hwndEdit, GWLP_USERDATA, (LONG_PTR)pOldWndProc);
  105. // Set the network exposure check
  106. SendDlgItemMessage(hwndDlg,
  107. CID_NetTab_Ipxui_CB_ExposeNetwork,
  108. BM_SETCHECK,
  109. (((PROT_EDIT_DATA*)lParam)->bExpose) ? BST_CHECKED : BST_UNCHECKED,
  110. 0);
  111. // Set the address assignmnet radio buttons
  112. SendDlgItemMessage(hwndDlg,
  113. CID_NetTab_Ipxui_RB_AutoAssign,
  114. BM_SETCHECK,
  115. (pIpxParams->bAutoAssign) ? BST_CHECKED : BST_UNCHECKED,
  116. 0);
  117. // Set the address assignmnet radio buttons
  118. SendDlgItemMessage(hwndDlg,
  119. CID_NetTab_Ipxui_RB_ManualAssign,
  120. BM_SETCHECK,
  121. (pIpxParams->bAutoAssign) ? BST_UNCHECKED : BST_CHECKED,
  122. 0);
  123. // Set the "allow caller to request an ipx node number" check
  124. SendDlgItemMessage(hwndDlg,
  125. CID_NetTab_Ipxui_CB_CallerSpec,
  126. BM_SETCHECK,
  127. (pIpxParams->bCaller) ? BST_CHECKED : BST_UNCHECKED,
  128. 0);
  129. // Set the global wan number check
  130. SendDlgItemMessage(hwndDlg,
  131. CID_NetTab_Ipxui_CB_AssignSame,
  132. BM_SETCHECK,
  133. (pIpxParams->bGlobalWan) ? BST_CHECKED : BST_UNCHECKED,
  134. 0);
  135. // Set the maximum amount of text that can be entered into the edit control
  136. SendDlgItemMessage(hwndDlg, CID_NetTab_Ipxui_EB_Netnum, EM_SETLIMITTEXT , 8, 0);
  137. // Set the text of the ip addresses
  138. wsprintfW(pszAddr, L"%x", pIpxParams->dwIpxAddress);
  139. SetDlgItemTextW(hwndDlg, CID_NetTab_Ipxui_EB_Netnum, pszAddr);
  140. // Enable/disable windows as per the settings
  141. IpxEnableWindows(hwndDlg, pIpxParams);
  142. IpxAdjustNetNumberLabel(hwndDlg, pIpxParams->bGlobalWan);
  143. return NO_ERROR;
  144. }
  145. // Gets the settings from the ui and puts them into
  146. // the ipx parameter structure.
  147. DWORD IpxGetUISettings(HWND hwndDlg, PROT_EDIT_DATA * pEditData) {
  148. IPX_PARAMS * pIpxParams = (IPX_PARAMS *) pEditData->pbData;
  149. WCHAR pszAddr[10];
  150. GetDlgItemTextW(hwndDlg, CID_NetTab_Ipxui_EB_Netnum, pszAddr, 10);
  151. pIpxParams->dwIpxAddress = wcstoul(pszAddr, (WCHAR)NULL, 16);
  152. // A configuration that specificies a wan net pool begining with
  153. // zero or 0xffffffff is illegal. Force the user to enter a
  154. // valid config
  155. if ((!pIpxParams->bAutoAssign) &&
  156. ((pIpxParams->dwIpxAddress == 0x0) ||
  157. (pIpxParams->dwIpxAddress == 0xFFFFFFFF)))
  158. {
  159. IpxUiDisplayError(hwndDlg, ERR_IPX_BAD_POOL_CONFIG);
  160. return ERROR_CAN_NOT_COMPLETE;
  161. }
  162. pEditData->bExpose = SendDlgItemMessage(hwndDlg, CID_NetTab_Ipxui_CB_ExposeNetwork, BM_GETCHECK, 0, 0) == BST_CHECKED;
  163. return NO_ERROR;
  164. }
  165. // Dialog proc that governs the ipx settings dialog
  166. INT_PTR CALLBACK IpxSettingsDialogProc (HWND hwndDlg,
  167. UINT uMsg,
  168. WPARAM wParam,
  169. LPARAM lParam) {
  170. switch (uMsg) {
  171. case WM_INITDIALOG:
  172. IpxInitDialog(hwndDlg, lParam);
  173. return FALSE;
  174. case WM_HELP:
  175. case WM_CONTEXTMENU:
  176. {
  177. RasSrvHelp (hwndDlg, uMsg, wParam, lParam, phmIpxui);
  178. break;
  179. }
  180. case WM_DESTROY:
  181. // Cleanup the work done at WM_INITDIALOG
  182. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
  183. break;
  184. case WM_COMMAND:
  185. {
  186. IPX_PARAMS * pIpxParams = (IPX_PARAMS *)(((PROT_EDIT_DATA*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA))->pbData);
  187. switch (wParam) {
  188. case IDOK:
  189. if (IpxGetUISettings(hwndDlg, (PROT_EDIT_DATA*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA)) == NO_ERROR)
  190. EndDialog(hwndDlg, 1);
  191. break;
  192. case IDCANCEL:
  193. EndDialog(hwndDlg, 0);
  194. break;
  195. case CID_NetTab_Ipxui_RB_AutoAssign:
  196. pIpxParams->bAutoAssign = TRUE;
  197. IpxEnableWindows(hwndDlg, pIpxParams);
  198. break;
  199. case CID_NetTab_Ipxui_RB_ManualAssign:
  200. pIpxParams->bAutoAssign = FALSE;
  201. IpxEnableWindows(hwndDlg, pIpxParams);
  202. break;
  203. case CID_NetTab_Ipxui_CB_CallerSpec:
  204. pIpxParams->bCaller = (BOOL)SendDlgItemMessage(hwndDlg,
  205. CID_NetTab_Ipxui_CB_CallerSpec,
  206. BM_GETCHECK,
  207. 0,
  208. 0);
  209. break;
  210. case CID_NetTab_Ipxui_CB_AssignSame:
  211. pIpxParams->bGlobalWan = (BOOL)SendDlgItemMessage(hwndDlg,
  212. CID_NetTab_Ipxui_CB_AssignSame,
  213. BM_GETCHECK,
  214. 0,
  215. 0);
  216. IpxAdjustNetNumberLabel(hwndDlg, pIpxParams->bGlobalWan);
  217. break;
  218. }
  219. // Adjust the values written to the ipx address edit control
  220. if (HIWORD(wParam) == EN_UPDATE) {
  221. WCHAR wbuf[10], wcorrect[10];
  222. POINT pt;
  223. GetWindowTextW((HWND)lParam, wbuf, 10);
  224. if (!IpxValidNetNumber(wbuf, wcorrect)) {
  225. GetCaretPos(&pt);
  226. SetWindowTextW((HWND)lParam, wcorrect);
  227. SetCaretPos(pt.x, pt.y);
  228. }
  229. }
  230. break;
  231. }
  232. }
  233. return FALSE;
  234. }
  235. // Edits tcp ip protocol properties
  236. DWORD IpxEditProperties(HWND hwndParent, PROT_EDIT_DATA * pEditData, BOOL * pbCommit) {
  237. DWORD dwErr;
  238. int ret;
  239. // Popup the dialog box
  240. ret = (int) DialogBoxParam(Globals.hInstDll,
  241. MAKEINTRESOURCE(DID_NetTab_Ipxui),
  242. hwndParent,
  243. IpxSettingsDialogProc,
  244. (LPARAM)pEditData);
  245. if (ret == -1) {
  246. IpxUiDisplayError(hwndParent, ERR_IPX_CANT_DISPLAY);
  247. }
  248. // If ok was pressed, save off the new settings
  249. *pbCommit = FALSE;
  250. if (ret && ret != -1)
  251. *pbCommit = TRUE;
  252. return NO_ERROR;
  253. }