Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afssvrmgr / svr_hosts.cpp
bloba9054986eda6fca7afe80dd5a6f3333f239d3c6b
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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 */
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
18 #include "svrmgr.h"
19 #include "svr_hosts.h"
20 #include "propcache.h"
21 #include "display.h"
25 * DEFINITIONS ________________________________________________________________
29 typedef struct
31 LPIDENT lpiServer;
32 LPHOSTLIST lpList;
33 } SVR_HOSTS_PARAMS, *LPSVR_HOSTS_PARAMS;
35 typedef struct
37 LPIDENT lpiServer;
38 TCHAR szHost[ cchNAME ];
39 } SVR_ADDHOST_PARAMS, *LPSVR_ADDHOST_PARAMS;
43 * PROTOTYPES _________________________________________________________________
47 void Server_Hosts_Free (LPSVR_HOSTS_PARAMS lpp);
49 BOOL CALLBACK Server_Hosts_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
51 void Server_Hosts_OnInitDialog (HWND hDlg, LPSVR_HOSTS_PARAMS lpp);
52 void Server_Hosts_OnEndTask_ListOpen (HWND hDlg, LPSVR_HOSTS_PARAMS lpp, LPTASKPACKET ptp);
53 void Server_Hosts_OnApply (HWND hDlg, LPSVR_HOSTS_PARAMS lpp);
54 void Server_Hosts_OnSelect (HWND hDlg, LPSVR_HOSTS_PARAMS lpp);
55 void Server_Hosts_OnAddEntry (HWND hDlg, LPSVR_HOSTS_PARAMS lpp);
56 void Server_Hosts_OnDelEntry (HWND hDlg, LPSVR_HOSTS_PARAMS lpp);
58 BOOL CALLBACK Server_AddHost_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
59 void Server_AddHost_OnInitDialog (HWND hDlg, LPSVR_ADDHOST_PARAMS lpp);
60 void Server_AddHost_EnableOK (HWND hDlg);
64 * ROUTINES ___________________________________________________________________
68 void Server_Hosts (LPIDENT lpiServer)
70 HWND hCurrent;
71 if ((hCurrent = PropCache_Search (pcSVR_HOSTS, lpiServer)) != NULL)
73 SetFocus (hCurrent);
75 else
77 LPSVR_HOSTS_PARAMS lpp = New (SVR_HOSTS_PARAMS);
78 memset (lpp, 0x00, sizeof(SVR_HOSTS_PARAMS));
79 lpp->lpiServer = lpiServer;
81 TCHAR szServer[ cchNAME ];
82 lpiServer->GetServerName (szServer);
83 LPTSTR pszTitle = FormatString (IDS_SVR_HOSTS_TITLE, TEXT("%s"), szServer);
84 LPPROPSHEET psh = PropSheet_Create (pszTitle, FALSE);
85 PropSheet_AddTab (psh, IDS_SVR_HOST_TAB, IDD_SVR_HOSTS, (DLGPROC)Server_Hosts_DlgProc, (LONG_PTR)lpp, TRUE);
86 PropSheet_ShowModeless (psh);
87 FreeString (pszTitle);
92 void Server_Hosts_Free (LPSVR_HOSTS_PARAMS lpp)
94 if (lpp->lpList)
95 AfsClass_HostList_Free (lpp->lpList);
96 Delete (lpp);
100 BOOL CALLBACK Server_Hosts_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
102 if (AfsAppLib_HandleHelp (IDD_SVR_HOSTS, hDlg, msg, wp, lp))
103 return TRUE;
105 LPSVR_HOSTS_PARAMS lpp;
106 if ((msg == WM_INITDIALOG_SHEET) || (msg == WM_DESTROY_SHEET))
107 lpp = (LPSVR_HOSTS_PARAMS)lp;
108 else
109 lpp = (LPSVR_HOSTS_PARAMS)PropSheet_FindTabParam (hDlg);
111 switch (msg)
113 case WM_INITDIALOG_SHEET:
114 PropCache_Add (pcSVR_HOSTS, lpp->lpiServer, hDlg);
115 break;
117 case WM_DESTROY_SHEET:
118 PropCache_Delete (hDlg);
119 break;
121 case WM_INITDIALOG:
122 Server_Hosts_OnInitDialog (hDlg, lpp);
123 break;
125 case WM_DESTROY:
126 Server_Hosts_Free (lpp);
127 break;
129 case WM_ENDTASK:
130 LPTASKPACKET ptp;
131 if ((ptp = (LPTASKPACKET)lp) != NULL)
133 if (ptp->idTask == taskSVR_HOSTLIST_OPEN)
134 Server_Hosts_OnEndTask_ListOpen (hDlg, lpp, ptp);
135 FreeTaskPacket (ptp);
137 break;
139 case WM_COMMAND:
140 switch (LOWORD(wp))
142 case IDAPPLY:
143 Server_Hosts_OnApply (hDlg, lpp);
144 break;
146 case IDC_HOST_ADD:
147 Server_Hosts_OnAddEntry (hDlg, lpp);
148 PropSheetChanged (hDlg);
149 break;
151 case IDC_HOST_REMOVE:
152 Server_Hosts_OnDelEntry (hDlg, lpp);
153 PropSheetChanged (hDlg);
154 break;
156 break;
158 case WM_NOTIFY:
159 switch (((LPNMHDR)lp)->code)
161 case FLN_ITEMSELECT:
162 if (((LPNMHDR)lp)->hwndFrom == GetDlgItem (hDlg, IDC_HOST_LIST))
164 Server_Hosts_OnSelect (hDlg, lpp);
166 break;
168 break;
171 return FALSE;
175 void Server_Hosts_OnInitDialog (HWND hDlg, LPSVR_HOSTS_PARAMS lpp)
177 TCHAR szServer[ cchNAME ];
178 lpp->lpiServer->GetServerName (szServer);
180 LPTSTR pszText = FormatString (IDS_HOST_TITLE, TEXT("%s"), szServer);
181 SetDlgItemText (hDlg, IDC_HOST_TITLE, pszText);
182 FreeString (pszText);
184 HWND hList = GetDlgItem (hDlg, IDC_HOST_LIST);
186 // We'll need an imagelist, if we want icons in the list.
188 HIMAGELIST hLarge;
189 if ((hLarge = ImageList_Create (32, 32, ILC_COLOR4 | ILC_MASK, 1, 1)) != 0)
190 AfsAppLib_AddToImageList (hLarge, IDI_SERVER, TRUE);
192 HIMAGELIST hSmall;
193 if ((hSmall = ImageList_Create (16, 16, ILC_COLOR4 | ILC_MASK, 1, 1)) != 0)
194 AfsAppLib_AddToImageList (hSmall, IDI_SERVER, FALSE);
196 FastList_SetImageLists (hList, hSmall, hLarge);
198 // Start loading the host list
200 StartTask (taskSVR_HOSTLIST_OPEN, hDlg, lpp->lpiServer);
202 EnableWindow (hList, FALSE);
203 EnableWindow (GetDlgItem (hDlg, IDC_HOST_ADD), FALSE);
204 EnableWindow (GetDlgItem (hDlg, IDC_HOST_REMOVE), FALSE);
208 void Server_Hosts_OnEndTask_ListOpen (HWND hDlg, LPSVR_HOSTS_PARAMS lpp, LPTASKPACKET ptp)
210 HWND hList = GetDlgItem (hDlg, IDC_HOST_LIST);
212 lpp->lpList = TASKDATA(ptp)->lpHostList;
214 // Populate the list
216 FL_StartChange (hList, TRUE);
218 if (lpp->lpList)
220 for (size_t iEntry = 0; iEntry < lpp->lpList->cEntries; ++iEntry)
222 LPHOSTLISTENTRY pEntry = &lpp->lpList->aEntries[ iEntry ];
223 if (pEntry->szHost[0] == TEXT('\0'))
224 continue;
226 FL_AddItem (hList, 1, (LPARAM)iEntry, 0, pEntry->szHost);
230 FL_EndChange (hList, 0);
231 EnableWindow (hList, (lpp->lpList != NULL));
232 EnableWindow (GetDlgItem (hDlg, IDC_HOST_ADD), (lpp->lpList != NULL));
234 Server_Hosts_OnSelect (hDlg, lpp);
238 void Server_Hosts_OnSelect (HWND hDlg, LPSVR_HOSTS_PARAMS lpp)
240 HWND hList = GetDlgItem (hDlg, IDC_HOST_LIST);
242 BOOL fEnableRemove = TRUE;
244 if (!IsWindowEnabled (hList))
245 fEnableRemove = FALSE;
247 if (FastList_FindFirstSelected (hList) == NULL)
248 fEnableRemove = FALSE;
250 EnableWindow (GetDlgItem (hDlg, IDC_HOST_REMOVE), fEnableRemove);
254 void Server_Hosts_OnApply (HWND hDlg, LPSVR_HOSTS_PARAMS lpp)
256 if (IsWindowEnabled (GetDlgItem (hDlg, IDC_HOST_LIST)))
258 // Increment the reference counter on this host list before handing
259 // it off to the Save task. When the Save task is done, it will attempt
260 // to free the list--which will decrement the counter again, and
261 // actually free the list if the counter hits zero.
263 InterlockedIncrement (&lpp->lpList->cRef);
264 StartTask (taskSVR_HOSTLIST_SAVE, NULL, lpp->lpList);
269 void Server_Hosts_OnAddEntry (HWND hDlg, LPSVR_HOSTS_PARAMS lpp)
271 LPSVR_ADDHOST_PARAMS pAdd = New (SVR_ADDHOST_PARAMS);
272 memset (pAdd, 0x00, sizeof(pAdd));
273 pAdd->lpiServer = lpp->lpiServer;
275 if (ModalDialogParam (IDD_SVR_ADDHOST, hDlg, (DLGPROC)Server_AddHost_DlgProc, (LPARAM)pAdd) == IDOK)
277 size_t iEntry;
278 for (iEntry = 0; iEntry < lpp->lpList->cEntries; ++iEntry)
280 LPHOSTLISTENTRY pEntry = &lpp->lpList->aEntries[ iEntry ];
281 if (pEntry->szHost[0] == TEXT('\0'))
282 continue;
283 if (!lstrcmpi (pEntry->szHost, pAdd->szHost))
284 break;
287 if (iEntry >= lpp->lpList->cEntries)
289 iEntry = AfsClass_HostList_AddEntry (lpp->lpList, pAdd->szHost);
292 HWND hList = GetDlgItem (hDlg, IDC_HOST_LIST);
293 FL_StartChange (hList, FALSE);
295 HLISTITEM hItem;
296 if ((hItem = FastList_FindItem (hList, (LPARAM)iEntry)) == NULL)
298 hItem = FL_AddItem (hList, 1, (LPARAM)iEntry, 0, pAdd->szHost);
301 FL_EndChange (hList, (LPARAM)hItem);
304 Delete (pAdd);
308 void Server_Hosts_OnDelEntry (HWND hDlg, LPSVR_HOSTS_PARAMS lpp)
310 HWND hList = GetDlgItem (hDlg, IDC_HOST_LIST);
311 FL_StartChange (hList, FALSE);
313 HLISTITEM hItem;
314 while ((hItem = FastList_FindFirstSelected (hList)) != NULL)
316 size_t iEntry = (size_t)FL_GetData (hList, hItem);
317 AfsClass_HostList_DelEntry (lpp->lpList, iEntry);
318 FastList_RemoveItem (hList, hItem);
321 FL_EndChange (hList);
325 BOOL CALLBACK Server_AddHost_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
327 if (AfsAppLib_HandleHelp (IDD_SVR_ADDHOST, hDlg, msg, wp, lp))
328 return TRUE;
330 if (msg == WM_INITDIALOG)
331 SetWindowLongPtr (hDlg, DWLP_USER, lp);
333 LPSVR_ADDHOST_PARAMS lpp;
334 if ((lpp = (LPSVR_ADDHOST_PARAMS)GetWindowLongPtr (hDlg, DWLP_USER)) != NULL)
336 switch (msg)
338 case WM_INITDIALOG:
339 Server_AddHost_OnInitDialog (hDlg, lpp);
340 break;
342 case WM_COMMAND:
343 switch (LOWORD(wp))
345 case IDOK:
346 GetDlgItemText (hDlg, IDC_ADDHOST_HOST, lpp->szHost, cchNAME);
347 EndDialog (hDlg, LOWORD(wp));
348 break;
350 case IDCANCEL:
351 EndDialog (hDlg, LOWORD(wp));
352 break;
354 case IDC_ADDHOST_HOST:
355 Server_AddHost_EnableOK (hDlg);
356 break;
358 break;
362 return FALSE;
366 void Server_AddHost_OnInitDialog (HWND hDlg, LPSVR_ADDHOST_PARAMS lpp)
368 TCHAR szDesc[ cchRESOURCE ];
369 GetDlgItemText (hDlg, IDC_ADDHOST_DESC, szDesc, cchRESOURCE);
371 TCHAR szServer[ cchNAME ];
372 lpp->lpiServer->GetServerName (szServer);
374 LPTSTR pszDesc = FormatString (szDesc, TEXT("%s"), szServer);
375 SetDlgItemText (hDlg, IDC_ADDHOST_DESC, pszDesc);
376 FreeString (pszDesc);
378 Server_AddHost_EnableOK (hDlg);
382 void Server_AddHost_EnableOK (HWND hDlg)
384 TCHAR szHost[ cchNAME ];
385 GetDlgItemText (hDlg, IDC_ADDHOST_HOST, szHost, cchNAME);
387 EnableWindow (GetDlgItem (hDlg, IDOK), (szHost[0] != TEXT('\0')) ? TRUE : FALSE);