rx: Remove RX_CALL_BUSY
[openafs.git] / src / WINNT / afssvrcfg / info2_page.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * INCLUDES _________________________________________________________________
12  *
13  */
14 #include <winsock2.h>
15 #include <ws2tcpip.h>
16
17 extern "C" {
18 #include <afsconfig.h>
19 #include <afs/param.h>
20 #include <afs/stds.h>
21 #include <roken.h>
22 }
23
24 #include "afscfg.h"
25 #include "resource.h"
26
27
28 /*
29  * DEFINITIONS _________________________________________________________________
30  *
31  */
32 static HWND hDlg = 0;                           // HWND for this page's dialog
33
34 #define FIRST_SERVER_STEP               sidSTEP_THREE
35 #define NOT_FIRST_SERVER_STEP   sidSTEP_FOUR
36
37 #define MIN_AFS_UID             1
38 #define MAX_AFS_UID             UD_MAXVAL
39
40
41 /*
42  * PROTOTYPES _________________________________________________________________
43  *
44  */
45 static void OnInitDialog(HWND hwndDlg);
46 static void CheckEnableButtons();
47 static void SavePageInfo();
48 static void ShowPageInfo();
49 static void UseNextUid(BOOL bUseNext);
50
51
52 /*
53  * EXPORTED FUNCTIONS _________________________________________________________________
54  *
55  */
56
57 /*
58  * Dialog Procs _________________________________________________________________
59  *
60  */
61 BOOL CALLBACK InfoPage2DlgProc(HWND hRHS, UINT msg, WPARAM wp, LPARAM lp)
62 {
63     if (WizStep_Common_DlgProc (hRHS, msg, wp, lp))
64         return FALSE;
65
66     switch (msg) {
67     case WM_INITDIALOG:
68         OnInitDialog(hRHS);
69         break;
70
71     case WM_COMMAND:
72         switch (LOWORD(wp)) {
73         case IDC_WIZARD:
74             if (HIWORD(wp) == wcIS_STATE_DISABLED) {
75                 int nState = g_pWiz->GetState();
76
77                 // Disable step 3 if we are not the first server
78                 if (nState == sidSTEP_THREE)
79                     return !g_CfgData.bFirstServer;
80
81                 // Disable step 4 if we are the first server
82                 if (nState == sidSTEP_FOUR)
83                     return g_CfgData.bFirstServer;
84             }
85             break;
86
87         case IDNEXT:
88             SavePageInfo();
89             g_pWiz->SetState (sidSTEP_FIVE);
90             break;
91
92         case IDBACK:
93             SavePageInfo();
94             g_pWiz->SetState (sidSTEP_TWO);
95             break;
96
97         case IDC_USE_NEXT_UID:
98             UseNextUid(TRUE);
99             CheckEnableButtons();
100             break;
101
102         case IDC_USE_THIS_UID:
103             UseNextUid(FALSE);
104             CheckEnableButtons();
105             break;
106
107         case IDC_ADMIN_NAME:
108         case IDC_ADMIN_PW:
109         case IDC_VERIFY_ADMIN_PW:
110         case IDC_HOSTNAME:
111             if (HIWORD(wp) == EN_CHANGE)
112                 CheckEnableButtons();
113             break;
114
115         }
116         break;
117     }
118
119     return FALSE;
120 }
121
122 /*
123  * STATIC FUNCTIONS _________________________________________________________________
124  *
125  */
126
127 /*
128  * Event Handler Functions _________________________________________________________________
129  *
130  */
131 static void OnInitDialog(HWND hwndDlg)
132 {
133     hDlg = hwndDlg;
134
135     g_pWiz->EnableButtons(BACK_BUTTON);
136
137     SetUpDownRange(hDlg, IDC_AFS_UID_SPINNER, MIN_AFS_UID, MAX_AFS_UID);
138
139     ShowPageInfo();
140
141     g_pWiz->SetDefaultControl(IDC_ADMIN_NAME);
142 }
143
144
145 /*
146  * Utility Functions _________________________________________________________________
147  *
148  */
149 static void CheckEnableButtons()
150 {
151     BOOL bDisable = FALSE;
152
153     TCHAR szDummy[cchRESOURCE];
154     TCHAR szPW[cchRESOURCE];
155     TCHAR szVerifyPW[cchRESOURCE];
156
157     bDisable |= lstrlen(GetWndText(hDlg, IDC_ADMIN_NAME, szDummy)) == 0;
158
159     bDisable |= lstrlen(GetWndText(hDlg, IDC_ADMIN_PW, szPW)) == 0;
160
161     if (IsWindowEnabled(GetDlgItem(hDlg, IDC_VERIFY_ADMIN_PW))) {
162         GetWndText(hDlg, IDC_VERIFY_ADMIN_PW, szVerifyPW);
163         bDisable |= !lstrlen(szVerifyPW) || lstrcmp(szPW, szVerifyPW);
164     }
165
166     if (IsWindowEnabled(GetDlgItem(hDlg, IDC_ADMIN_UID)))
167         bDisable |= lstrlen(GetWndText(hDlg, IDC_ADMIN_UID, szDummy)) == 0;
168
169     if (IsWindowEnabled(GetDlgItem(hDlg, IDC_HOSTNAME)))
170         bDisable |= lstrlen(GetWndText(hDlg, IDC_HOSTNAME, szDummy)) == 0;
171
172     if (bDisable)
173         g_pWiz->EnableButtons(BACK_BUTTON);
174     else
175         g_pWiz->EnableButtons(BACK_BUTTON | NEXT_BUTTON);
176 }
177
178 static void SavePageInfo()
179 {
180     TCHAR szText[cchRESOURCE];
181
182     lstrncpy(g_CfgData.szAdminName, GetWndText(hDlg, IDC_ADMIN_NAME, szText), MAX_ADMIN_NAME_LEN);
183     lstrncpy(g_CfgData.szAdminPW, GetWndText(hDlg, IDC_ADMIN_PW, szText), MAX_ADMIN_PW_LEN);
184
185     if (g_pWiz->GetState() == FIRST_SERVER_STEP) {
186         g_CfgData.bUseNextUid = IsButtonChecked(hDlg, IDC_USE_NEXT_UID);
187         if (!g_CfgData.bUseNextUid)
188             lstrncpy(g_CfgData.szAdminUID, GetWndText(hDlg, IDC_ADMIN_UID, szText), MAX_UID_LEN);
189     }
190
191     if (g_pWiz->GetState() == NOT_FIRST_SERVER_STEP)
192         lstrncpy(g_CfgData.szCellServDbHostname, GetWndText(hDlg, IDC_HOSTNAME, szText), MAX_MACHINE_NAME_LEN);
193 }
194
195 static void ShowPageInfo()
196 {
197     SetWndText(hDlg, IDC_ADMIN_NAME, g_CfgData.szAdminName);
198     SetWndText(hDlg, IDC_ADMIN_PW, g_CfgData.szAdminPW);
199     SetWndText(hDlg, IDC_VERIFY_ADMIN_PW, g_CfgData.szAdminPW);
200     SetWndText(hDlg, IDC_HOSTNAME, g_CfgData.szCellServDbHostname);
201
202     if (g_pWiz->GetState() == FIRST_SERVER_STEP) {
203         if (g_CfgData.bUseNextUid)
204             SetCheck(hDlg, IDC_USE_NEXT_UID);
205         else
206             SetCheck(hDlg, IDC_USE_THIS_UID);
207         UseNextUid(g_CfgData.bUseNextUid);
208         SetWndText(hDlg, IDC_ADMIN_UID, g_CfgData.szAdminUID);
209     }
210 }
211
212 static void UseNextUid(BOOL bUseNext)
213 {
214     ENABLE_STATE es = bUseNext ? ES_DISABLE : ES_ENABLE;
215
216     SetEnable(hDlg, IDC_ADMIN_UID, es);
217     SetEnable(hDlg, IDC_AFS_UID_SPINNER, es);
218 }
219