2 * Copyright 2000, International Business Machines Corporation and others.
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
14 #include <afs/param.h>
19 #include "svr_address.h"
23 * PROTOTYPES _________________________________________________________________
27 void ChangeAddr_OnInitDialog (HWND hDlg
, LPSVR_CHANGEADDR_PARAMS lpp
);
28 void ChangeAddr_Enable (HWND hDlg
, BOOL fEnable
);
29 void ChangeAddr_OnSelect (HWND hDlg
);
30 void ChangeAddr_OnEndTask_Init (HWND hDlg
, LPSVR_CHANGEADDR_PARAMS lpp
, LPTASKPACKET ptp
);
31 void ChangeAddr_OnRemove (HWND hDlg
, LPSVR_CHANGEADDR_PARAMS lpp
);
32 void ChangeAddr_OnChange (HWND hDlg
, LPSVR_CHANGEADDR_PARAMS lpp
);
34 BOOL CALLBACK
NewAddr_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
);
35 void NewAddr_OnInitDialog (HWND hDlg
, LPSOCKADDR_IN pAddr
);
36 void NewAddr_OnOK (HWND hDlg
, LPSOCKADDR_IN pAddr
);
40 * SERVER ADDRESSES ___________________________________________________________
44 void Server_FillAddrList (HWND hDlg
, LPSERVERSTATUS lpss
, BOOL fCanAddUnspecified
)
46 HWND hList
= GetDlgItem (hDlg
, IDC_SVR_ADDRESSES
);
48 LB_StartChange (hList
, TRUE
);
50 if (!lpss
|| !lpss
->nAddresses
)
52 if (fCanAddUnspecified
)
53 (void)LB_AddItem (hList
, IDS_SVR_NO_ADDR
, (LPARAM
)-1);
55 else for (size_t iAddr
= 0; iAddr
< lpss
->nAddresses
; ++iAddr
)
58 AfsClass_AddressToInt (&AddrInt
, &lpss
->aAddresses
[ iAddr
]);
62 LPTSTR pszAddress
= FormatString (TEXT("%1"), TEXT("%a"), &lpss
->aAddresses
[ iAddr
]);
63 (void)LB_AddItem (hList
, pszAddress
, (LPARAM
)iAddr
);
64 FreeString (pszAddress
);
67 LB_EndChange (hList
, 0);
71 void Server_ParseAddress (LPSOCKADDR_IN pAddr
, LPTSTR pszText
)
73 int addrNetwork
= inet_addr (pszText
);
75 memset (pAddr
, 0x00, sizeof(SOCKADDR_IN
));
76 pAddr
->sin_family
= AF_INET
;
77 pAddr
->sin_addr
.s_addr
= addrNetwork
;
81 BOOL
Server_Ping (LPSOCKADDR_IN pAddr
, LPCTSTR pszServerName
)
87 if ((phe
= gethostbyname (pszServerName
)) == NULL
)
88 memset (pAddr
, 0x00, sizeof(SOCKADDR_IN
));
91 memset (pAddr
, 0x00, sizeof(SOCKADDR_IN
));
92 pAddr
->sin_family
= 2;
94 pAddr
->sin_addr
.s_addr
= *(ULONG
*)phe
->h_addr
;
100 memset (pAddr
, 0x00, sizeof(SOCKADDR_IN
));
107 BOOL CALLBACK
ChangeAddr_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
109 if (AfsAppLib_HandleHelp (IDD_SVR_ADDRESS
, hDlg
, msg
, wp
, lp
))
112 if (msg
== WM_INITDIALOG
)
113 SetWindowLongPtr (hDlg
, DWLP_USER
, lp
);
115 LPSVR_CHANGEADDR_PARAMS lpp
;
116 if ((lpp
= (LPSVR_CHANGEADDR_PARAMS
)GetWindowLongPtr (hDlg
, DWLP_USER
)) != NULL
)
121 ChangeAddr_OnInitDialog (hDlg
, lpp
);
122 StartTask (taskSVR_PROP_INIT
, hDlg
, lpp
->lpiServer
);
127 if ((ptp
= (LPTASKPACKET
)lp
) != NULL
)
129 if (ptp
->idTask
== taskSVR_PROP_INIT
)
130 ChangeAddr_OnEndTask_Init (hDlg
, lpp
, ptp
);
131 FreeTaskPacket (ptp
);
138 case IDC_SVR_ADDRESSES
:
139 if (HIWORD(wp
) == LBN_SELCHANGE
)
140 ChangeAddr_OnSelect (hDlg
);
143 case IDC_ADDR_CHANGE
:
144 ChangeAddr_OnChange (hDlg
, lpp
);
147 case IDC_ADDR_REMOVE
:
148 ChangeAddr_OnRemove (hDlg
, lpp
);
152 EndDialog (hDlg
, IDOK
);
156 EndDialog (hDlg
, IDCANCEL
);
167 void ChangeAddr_OnInitDialog (HWND hDlg
, LPSVR_CHANGEADDR_PARAMS lpp
)
169 TCHAR szName
[ cchNAME
];
170 lpp
->lpiServer
->GetServerName (szName
);
172 TCHAR szText
[ cchRESOURCE
];
173 GetDlgItemText (hDlg
, IDC_TITLE
, szText
, cchRESOURCE
);
175 LPTSTR pszTitle
= FormatString (szText
, TEXT("%s"), szName
);
176 SetDlgItemText (hDlg
, IDC_TITLE
, pszTitle
);
177 FreeString (pszTitle
);
179 HWND hList
= GetDlgItem (hDlg
, IDC_SVR_ADDRESSES
);
180 LB_StartChange (hList
, TRUE
);
181 LB_AddItem (hList
, IDS_QUERYING
, 0);
182 LB_EndChange (hList
, 0);
184 ChangeAddr_Enable (hDlg
, FALSE
);
188 void ChangeAddr_Enable (HWND hDlg
, BOOL fEnable
)
190 EnableWindow (GetDlgItem (hDlg
, IDC_SVR_ADDRESSES
), fEnable
);
191 EnableWindow (GetDlgItem (hDlg
, IDC_ADDR_CHANGE
), fEnable
);
192 EnableWindow (GetDlgItem (hDlg
, IDC_ADDR_REMOVE
), fEnable
);
195 ChangeAddr_OnSelect (hDlg
);
199 void ChangeAddr_OnSelect (HWND hDlg
)
201 HWND hList
= GetDlgItem (hDlg
, IDC_SVR_ADDRESSES
);
202 BOOL fSelected
= (LB_GetSelected (hList
) != -1) ? TRUE
: FALSE
;
204 EnableWindow (GetDlgItem (hDlg
, IDC_ADDR_CHANGE
), fSelected
);
205 EnableWindow (GetDlgItem (hDlg
, IDC_ADDR_REMOVE
), fSelected
);
209 void ChangeAddr_OnEndTask_Init (HWND hDlg
, LPSVR_CHANGEADDR_PARAMS lpp
, LPTASKPACKET ptp
)
213 TCHAR szName
[ cchNAME
];
214 lpp
->lpiServer
->GetServerName (szName
);
215 ErrorDialog (ptp
->status
, IDS_ERROR_REFRESH_SERVER_STATUS
, TEXT("%s"), szName
);
219 memcpy (&lpp
->ssOld
, &TASKDATA(ptp
)->ss
, sizeof(SERVERSTATUS
));
220 memcpy (&lpp
->ssNew
, &TASKDATA(ptp
)->ss
, sizeof(SERVERSTATUS
));
221 ChangeAddr_Enable (hDlg
, TRUE
);
224 Server_FillAddrList (hDlg
, &lpp
->ssNew
, FALSE
);
228 void ChangeAddr_OnRemove (HWND hDlg
, LPSVR_CHANGEADDR_PARAMS lpp
)
230 HWND hList
= GetDlgItem (hDlg
, IDC_SVR_ADDRESSES
);
233 if ((iSel
= LB_GetSelected (hList
)) != -1)
235 TCHAR szItem
[ cchRESOURCE
] = TEXT("");
236 SendMessage (hList
, LB_GETTEXT
, iSel
, (LPARAM
)szItem
);
239 Server_ParseAddress (&AddrSel
, szItem
);
242 AfsClass_AddressToInt (&AddrSelInt
, &AddrSel
);
246 for (size_t iAddr
= 0; iAddr
< lpp
->ssOld
.nAddresses
; ++iAddr
)
249 AfsClass_AddressToInt (&OldAddrInt
, &lpp
->ssOld
.aAddresses
[iAddr
]);
252 AfsClass_AddressToInt (&NewAddrInt
, &lpp
->ssNew
.aAddresses
[iAddr
]);
254 if ((OldAddrInt
== AddrSelInt
) || (NewAddrInt
== AddrSelInt
))
256 AfsClass_IntToAddress (&lpp
->ssNew
.aAddresses
[iAddr
], 0);
261 Server_FillAddrList (hDlg
, &lpp
->ssNew
, FALSE
);
262 ChangeAddr_OnSelect (hDlg
);
267 void ChangeAddr_OnChange (HWND hDlg
, LPSVR_CHANGEADDR_PARAMS lpp
)
269 HWND hList
= GetDlgItem (hDlg
, IDC_SVR_ADDRESSES
);
272 if ((iSel
= LB_GetSelected (hList
)) != -1)
274 TCHAR szItem
[ cchRESOURCE
] = TEXT("");
275 SendMessage (hList
, LB_GETTEXT
, iSel
, (LPARAM
)szItem
);
278 Server_ParseAddress (&AddrSel
, szItem
);
281 AfsClass_AddressToInt (&AddrSelInt
, &AddrSel
);
285 SOCKADDR_IN AddrNew
= AddrSel
;
286 if (ModalDialogParam (IDD_SVR_NEWADDR
, hDlg
, (DLGPROC
)NewAddr_DlgProc
, (LPARAM
)&AddrNew
) != IDOK
)
290 AfsClass_AddressToInt (&AddrNewInt
, &AddrNew
);
291 if (AddrNewInt
&& (AddrNewInt
!= AddrSelInt
))
294 // First see if the new IP address is already in the server's
295 // list of IP addresses--if so, just delete the old address.
298 for (iAddr
= 0; iAddr
< lpp
->ssOld
.nAddresses
; ++iAddr
)
301 AfsClass_AddressToInt (&OldAddrInt
, &lpp
->ssOld
.aAddresses
[iAddr
]);
304 AfsClass_AddressToInt (&NewAddrInt
, &lpp
->ssNew
.aAddresses
[iAddr
]);
306 if ((OldAddrInt
== AddrNewInt
) || (NewAddrInt
== AddrNewInt
))
313 // Now update the SERVERSTATUS structure.
315 for (iAddr
= 0; iAddr
< lpp
->ssOld
.nAddresses
; ++iAddr
)
318 AfsClass_AddressToInt (&OldAddrInt
, &lpp
->ssOld
.aAddresses
[iAddr
]);
321 AfsClass_AddressToInt (&NewAddrInt
, &lpp
->ssNew
.aAddresses
[iAddr
]);
323 if ((OldAddrInt
== AddrSelInt
) || (NewAddrInt
== AddrSelInt
))
325 AfsClass_IntToAddress (&lpp
->ssNew
.aAddresses
[iAddr
], AddrNewInt
);
332 Server_FillAddrList (hDlg
, &lpp
->ssNew
, FALSE
);
333 ChangeAddr_OnSelect (hDlg
);
338 BOOL CALLBACK
NewAddr_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
340 if (AfsAppLib_HandleHelp (IDD_SVR_NEWADDR
, hDlg
, msg
, wp
, lp
))
343 if (msg
== WM_INITDIALOG
)
344 SetWindowLongPtr (hDlg
, DWLP_USER
, lp
);
347 if ((pAddr
= (LPSOCKADDR_IN
)GetWindowLongPtr (hDlg
, DWLP_USER
)) != NULL
)
352 NewAddr_OnInitDialog (hDlg
, pAddr
);
359 NewAddr_OnOK (hDlg
, pAddr
);
360 EndDialog (hDlg
, IDOK
);
364 EndDialog (hDlg
, IDCANCEL
);
375 void NewAddr_OnInitDialog (HWND hDlg
, LPSOCKADDR_IN pAddr
)
377 TCHAR szText
[ cchRESOURCE
];
378 GetDlgItemText (hDlg
, IDC_TITLE
, szText
, cchRESOURCE
);
380 LPTSTR pszTitle
= FormatString (szText
, TEXT("%a"), pAddr
);
381 SetDlgItemText (hDlg
, IDC_TITLE
, pszTitle
);
382 FreeString (pszTitle
);
384 SA_SetAddr (GetDlgItem (hDlg
, IDC_ADDRESS
), pAddr
);
388 void NewAddr_OnOK (HWND hDlg
, LPSOCKADDR_IN pAddr
)
390 SA_GetAddr (GetDlgItem (hDlg
, IDC_ADDRESS
), pAddr
);