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.

223 lines
7.3 KiB

  1. #include "pmcfg.h"
  2. #include <atlbase.h>
  3. #include <atlconv.h>
  4. DWORD g_dwSiteNameBufLen;
  5. DWORD g_dwHostNameBufLen;
  6. DWORD g_dwHostIPBufLen;
  7. LPTSTR g_szSiteNameBuf;
  8. LPTSTR g_szHostNameBuf;
  9. LPTSTR g_szHostIPBuf;
  10. LRESULT CALLBACK NewConfigSetDlgProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  11. BOOL IsValidIP(
  12. LPCTSTR pszIP
  13. )
  14. {
  15. BOOL bIsValid = TRUE;
  16. ULONG ulAddr;
  17. USES_CONVERSION;
  18. ulAddr = inet_addr(T2A(const_cast<LPTSTR>(pszIP)));
  19. bIsValid = (ulAddr != INADDR_NONE);
  20. return bIsValid;
  21. }
  22. BOOL NewConfigSet
  23. (
  24. HWND hWndDlg,
  25. LPTSTR szSiteNameBuf,
  26. DWORD dwSiteNameBufLen,
  27. LPTSTR szHostNameBuf,
  28. DWORD dwHostNameBufLen,
  29. LPTSTR szHostIPBuf,
  30. DWORD dwHostIPBufLen
  31. )
  32. {
  33. g_dwSiteNameBufLen = dwSiteNameBufLen;
  34. g_dwHostNameBufLen = dwHostNameBufLen;
  35. g_dwHostIPBufLen = dwHostIPBufLen;
  36. g_szSiteNameBuf = szSiteNameBuf;
  37. g_szHostNameBuf = szHostNameBuf;
  38. g_szHostIPBuf = szHostIPBuf;
  39. if (IDOK == DialogBox( g_hInst,
  40. MAKEINTRESOURCE (IDD_NEW_CONFIGSET),
  41. hWndDlg,
  42. (DLGPROC)NewConfigSetDlgProc ))
  43. return TRUE;
  44. else
  45. return FALSE;
  46. }
  47. BOOL RemoveConfigSetWarning
  48. (
  49. HWND hWndDlg
  50. )
  51. {
  52. TCHAR szWarning[MAX_RESOURCE];
  53. TCHAR szTitle[MAX_RESOURCE];
  54. LoadString(g_hInst, IDS_REMOVE_WARNING, szWarning, sizeof(szWarning));
  55. LoadString(g_hInst, IDS_REMOVE_TITLE, szTitle, sizeof(szTitle));
  56. return (MessageBox(hWndDlg, szWarning, szTitle, MB_OKCANCEL | MB_ICONQUESTION) == IDOK);
  57. }
  58. LRESULT CALLBACK NewConfigSetDlgProc
  59. (
  60. HWND hWndDlg,
  61. UINT uMsg,
  62. WPARAM wParam,
  63. LPARAM lParam
  64. )
  65. {
  66. switch ( uMsg )
  67. {
  68. case WM_INITDIALOG:
  69. {
  70. SendDlgItemMessage(hWndDlg, IDC_CONFIGSETEDIT, EM_SETLIMITTEXT, MAX_CONFIGSETNAME - 1, 0L);
  71. SendDlgItemMessage(hWndDlg, IDC_HOSTNAMEEDIT, EM_SETLIMITTEXT, INTERNET_MAX_HOST_NAME_LENGTH - 1, 0L);
  72. SendDlgItemMessage(hWndDlg, IDC_HOSTIPEDIT, EM_SETLIMITTEXT, MAX_IPLEN, 0L);
  73. SetFocus(GetDlgItem(hWndDlg, IDC_CONFIGSETEDIT));
  74. return FALSE;
  75. }
  76. case WM_COMMAND:
  77. {
  78. switch (LOWORD(wParam))
  79. {
  80. case IDOK:
  81. {
  82. TCHAR szTemp[MAX_RESOURCE];
  83. TCHAR szTitle[MAX_RESOURCE];
  84. LPTSTR lpszConfigSetNames, lpszCur;
  85. //
  86. // Check for empty site name
  87. //
  88. GetDlgItemText(hWndDlg, IDC_CONFIGSETEDIT, g_szSiteNameBuf, g_dwSiteNameBufLen);
  89. if(lstrlen(g_szSiteNameBuf) == 0)
  90. {
  91. LoadString(g_hInst, IDS_EMPTYSITENAME, szTemp, sizeof(szTemp));
  92. LoadString(g_hInst, IDS_ERROR, szTitle, sizeof(szTemp));
  93. MessageBox(hWndDlg, szTemp, szTitle, MB_OK | MB_ICONEXCLAMATION);
  94. SetFocus(GetDlgItem(hWndDlg, IDC_CONFIGSETEDIT));
  95. break;
  96. }
  97. //
  98. // Make sure the site name isn't default
  99. //
  100. LoadString(g_hInst, IDS_DEFAULT, szTemp, sizeof(szTemp));
  101. if(lstrcmp(g_szSiteNameBuf, szTemp) == 0)
  102. {
  103. LoadString(g_hInst, IDS_INVALIDSITENAME, szTemp, sizeof(szTemp));
  104. LoadString(g_hInst, IDS_ERROR, szTitle, sizeof(szTitle));
  105. MessageBox(hWndDlg, szTemp, szTitle, MB_OK | MB_ICONEXCLAMATION);
  106. SetFocus(GetDlgItem(hWndDlg, IDC_CONFIGSETEDIT));
  107. break;
  108. }
  109. //
  110. // Check for existing site w/same name
  111. //
  112. if(ReadRegConfigSetNames(hWndDlg, g_szRemoteComputer, &lpszConfigSetNames) &&
  113. lpszConfigSetNames)
  114. {
  115. BOOL bFoundMatch = FALSE;
  116. lpszCur = lpszConfigSetNames;
  117. while(*lpszCur)
  118. {
  119. if(lstrcmp(lpszCur, g_szSiteNameBuf) == 0)
  120. {
  121. LoadString(g_hInst, IDS_EXISTINGSITENAME, szTemp, sizeof(szTemp));
  122. LoadString(g_hInst, IDS_ERROR, szTitle, sizeof(szTitle));
  123. MessageBox(hWndDlg, szTemp, szTitle, MB_OK | MB_ICONEXCLAMATION);
  124. SetFocus(GetDlgItem(hWndDlg, IDC_CONFIGSETEDIT));
  125. bFoundMatch = TRUE;
  126. break;
  127. }
  128. lpszCur = _tcschr(lpszCur, TEXT('\0')) + 1;
  129. }
  130. free(lpszConfigSetNames);
  131. lpszConfigSetNames = NULL;
  132. if(bFoundMatch)
  133. break;
  134. }
  135. //
  136. // Get data from other controls.
  137. //
  138. GetDlgItemText(hWndDlg, IDC_HOSTNAMEEDIT, g_szHostNameBuf, g_dwHostNameBufLen);
  139. if(lstrlen(g_szHostNameBuf) == 0)
  140. {
  141. LoadString(g_hInst, IDS_EMPTYHOSTNAME, szTemp, sizeof(szTemp));
  142. LoadString(g_hInst, IDS_ERROR, szTitle, sizeof(szTemp));
  143. MessageBox(hWndDlg, szTemp, szTitle, MB_OK | MB_ICONEXCLAMATION);
  144. SetFocus(GetDlgItem(hWndDlg, IDC_HOSTNAMEEDIT));
  145. break;
  146. }
  147. GetDlgItemText(hWndDlg, IDC_HOSTIPEDIT, g_szHostIPBuf, g_dwHostIPBufLen);
  148. if(lstrlen(g_szHostIPBuf) == 0)
  149. {
  150. LoadString(g_hInst, IDS_EMPTYHOSTIP, szTemp, sizeof(szTemp));
  151. LoadString(g_hInst, IDS_ERROR, szTitle, sizeof(szTemp));
  152. MessageBox(hWndDlg, szTemp, szTitle, MB_OK | MB_ICONEXCLAMATION);
  153. SetFocus(GetDlgItem(hWndDlg, IDC_HOSTIPEDIT));
  154. break;
  155. }
  156. //
  157. // Valid IP address?
  158. //
  159. if(!IsValidIP(g_szHostIPBuf))
  160. {
  161. LoadString(g_hInst, IDS_HOSTIP_ERROR, szTemp, sizeof(szTemp));
  162. LoadString(g_hInst, IDS_ERROR, szTitle, sizeof(szTemp));
  163. MessageBox(hWndDlg, szTemp, szTitle, MB_OK | MB_ICONEXCLAMATION);
  164. SetFocus(GetDlgItem(hWndDlg, IDC_HOSTIPEDIT));
  165. break;
  166. }
  167. EndDialog( hWndDlg, TRUE );
  168. break;
  169. }
  170. case IDCANCEL:
  171. {
  172. g_szSiteNameBuf[0] = TEXT('\0');
  173. g_szHostNameBuf[0] = TEXT('\0');
  174. g_szHostIPBuf[0] = TEXT('\0');
  175. EndDialog( hWndDlg, FALSE );
  176. break;
  177. }
  178. }
  179. break;
  180. }
  181. }
  182. return FALSE;
  183. }