Windows: AFSTearDownExtents may experience active extents
[openafs.git] / src / WINNT / afssvrmgr / dispguts.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 #include <winsock2.h>
11 #include <ws2tcpip.h>
12
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
16 }
17
18 #include "svrmgr.h"
19 #include "display.h"
20 #include "dispguts.h"
21 #include "svr_col.h"
22 #include "svr_window.h"
23 #include "svc_col.h"
24 #include "svc_startstop.h"
25 #include "agg_col.h"
26 #include "set_col.h"
27 #include "set_general.h"
28 #include "creds.h"
29
30
31 /*
32  * PROTOTYPES _________________________________________________________________
33  *
34  */
35
36 void Display_Servers_Internal_Clean (LPDISPLAYREQUEST pdr);
37 void Display_Servers_Internal_AddServer (LPDISPLAYREQUEST pdr, LPSERVER lpServer);
38
39 void Display_Services_Internal_Clean (LPDISPLAYREQUEST pdr);
40 void Display_Services_Internal_AddServer (LPDISPLAYREQUEST pdr, LPSERVER lpServer);
41 void Display_Services_Internal_AddService (LPDISPLAYREQUEST pdr, LPSERVICE lpService, HLISTITEM hServer);
42
43 void Display_Aggregates_Internal_Clean (LPDISPLAYREQUEST pdr);
44 void Display_Aggregates_Internal_AddServer (LPDISPLAYREQUEST pdr, LPSERVER lpServer);
45 void Display_Aggregates_Internal_AddAggregate (LPDISPLAYREQUEST pdr, LPAGGREGATE lpAggregate, HLISTITEM hServer);
46
47 void Display_Filesets_Internal_Clean (LPDISPLAYREQUEST pdr);
48 HLISTITEM Display_Filesets_Internal_AddCell (LPDISPLAYREQUEST pdr, LPCELL lpCell);
49 void Display_Filesets_Internal_AddServer (LPDISPLAYREQUEST pdr, LPSERVER lpServer, HLISTITEM hCell);
50 void Display_Filesets_Internal_AddAggregate (LPDISPLAYREQUEST pdr, LPAGGREGATE lpAggregate, HLISTITEM hServer);
51 void Display_Filesets_Internal_AddFileset (LPDISPLAYREQUEST pdr, LPFILESET lpFileset, HLISTITEM hAggregate);
52
53 #define PIF_ALWAYSSHOWICON     0x00000001
54 #define PIF_ONLYONEICON        0x00000002
55 #define PIF_TREEVIEW_ONLY      0x00000004
56 #define PIF_DISALLOW_COLLAPSE  0x00000008
57 void Display_PickImages (int *piFirstImage, int *piSecondImage, int iTypeImage, int iStatusImage, ICONVIEW iv, DWORD dwPickImageFlags = 0);
58 HLISTITEM Display_InsertItem (HWND hList, HLISTITEM hParent, LPTSTR pszText, LPARAM lp, int iImage0 = IMAGE_NOIMAGE, int iImage1 = IMAGE_NOIMAGE, ICONVIEW iv = (ICONVIEW)-1, DWORD dwPickImageFlags = 0);
59
60
61 /*
62  * CELL _______________________________________________________________________
63  *
64  */
65
66 void Display_Cell_Internal (LPDISPLAYREQUEST pdr)
67 {
68    // Update the "Current Cell:" field on g.hMain
69    //
70    TCHAR szCell[ cchNAME ];
71    if (g.lpiCell == NULL)
72       GetString (szCell, IDS_NO_CELL_SELECTED);
73    else
74       g.lpiCell->GetCellName (szCell);
75
76    SetDlgItemText (g.hMain, IDC_CELL, szCell);
77
78    // Update the "AFS Identity:" field on g.hMain
79    //
80    TCHAR szUser[ cchNAME ];
81    SYSTEMTIME stExpire;
82    if (!AfsAppLib_CrackCredentials (g.hCreds, szCell, szUser, &stExpire))
83       {
84       GetString (szUser, IDS_NO_AFS_ID);
85       SetDlgItemText (g.hMain, IDC_AFS_ID, szUser);
86       }
87    else
88       {
89       int ids = (AfsAppLib_IsTimeInFuture (&stExpire)) ? IDS_AFS_ID_WILLEXP : IDS_AFS_ID_DIDEXP;
90       LPTSTR pszText = FormatString (ids, TEXT("%s%t"), szUser, &stExpire);
91       SetDlgItemText (g.hMain, IDC_AFS_ID, pszText);
92       FreeString (pszText);
93       }
94 }
95
96
97 /*
98  * SERVERS ____________________________________________________________________
99  *
100  */
101
102 void Display_Servers_Internal (LPDISPLAYREQUEST pdr)
103 {
104    pdr->hList = GetDlgItem (g.hMain, IDC_SERVERS);
105    pdr->lpvi = (gr.fPreview && !gr.fVert) ? &gr.diHorz.viewSvr : &gr.diVert.viewSvr;
106
107    if (!IsWindow (pdr->hList))
108       return;
109
110    // Fix up the image lists for the Servers window
111    //
112    HIMAGELIST hiSmall;
113    HIMAGELIST hiLarge;
114    FastList_GetImageLists (pdr->hList, &hiSmall, &hiLarge);
115    if (!hiSmall || !hiLarge)
116       {
117       hiSmall = AfsAppLib_CreateImageList (FALSE);
118       hiLarge = AfsAppLib_CreateImageList (TRUE);
119       FastList_SetImageLists (pdr->hList, hiSmall, hiLarge);
120       }
121
122    // Add an entry in the Servers list for each server in the cell.
123    //
124 //   LPIDENT lpiSelStart = (LPIDENT)FL_GetSelectedData (pdr->hList);
125 //   BOOL fRefresh = FALSE;
126
127    LPCELL lpCell;
128    if (!g.lpiCell || !(lpCell = g.lpiCell->OpenCell()))
129       {
130       LPTSTR pszCover = FormatString (IDS_ERROR_REFRESH_CELLSERVERS_NOCELL);
131       AfsAppLib_CoverWindow (pdr->hList, pszCover);
132       FreeString (pszCover);
133       }
134    else
135       {
136       BOOL rc = TRUE;
137
138       pdr->lpiToSelect = (LPIDENT)FL_StartChange (pdr->hList, (pdr->lpiNotify) ? FALSE : TRUE);
139       pdr->actOnDone = ACT_ENDCHANGE | ACT_SELPREVIEW;
140
141       // Remove any to-be-replaced old servers
142       //
143       Display_Servers_Internal_Clean (pdr);
144
145       // Add a server entry for each server as appropriate
146       //
147       HENUM hEnum;
148       for (LPSERVER lpServer = lpCell->ServerFindFirst (&hEnum, pdr->lpiNotify, FALSE); lpServer; lpServer = lpCell->ServerFindNext (&hEnum))
149          {
150          Display_Servers_Internal_AddServer (pdr, lpServer);
151          lpServer->Close();
152          }
153
154       if (rc)
155          pdr->actOnDone |= ACT_UNCOVER;
156
157       lpCell->Close();
158       }
159 }
160
161
162 void Display_Servers_Internal_Clean (LPDISPLAYREQUEST pdr)
163 {
164    if (pdr->lpiNotify) // else, we already emptied the list
165       {
166       HLISTITEM hItem;
167       if ((hItem = FastList_FindItem (pdr->hList, (LPARAM)(pdr->lpiNotify))) != NULL)
168          FastList_RemoveItem (pdr->hList, hItem);
169       }
170 }
171
172
173 void Display_Servers_Internal_AddServer (LPDISPLAYREQUEST pdr, LPSERVER lpServer)
174 {
175    ULONG status = 0;
176    SERVERSTATUS ss;
177
178    if (lpServer->GetIdentifier() == pdr->lpiNotify)
179       status = pdr->status;
180
181    if (!status)
182       {
183       lpServer->GetStatus (&ss, FALSE, &status);
184
185       LPSERVER_PREF lpsp;
186       if ((lpsp = (LPSERVER_PREF)lpServer->GetUserParam()) != NULL)
187          memcpy (&lpsp->ssLast, &ss, sizeof(SERVERSTATUS));
188       }
189
190    ICONVIEW ivSvr = Display_GetServerIconView();
191
192    if (status != 0)
193       {
194       LPTSTR pszCol1 = FormatString (TEXT("%1 - %2"), TEXT("%s%e"), Server_GetColumnText (lpServer->GetIdentifier(), svrcolNAME), status);
195
196       Display_InsertItem (pdr->hList,
197                           NULL,
198                           pszCol1,
199                           (LPARAM)lpServer->GetIdentifier(),
200                           imageSERVER, imageSERVER_ALERT, ivSvr);
201
202       FreeString (pszCol1);
203       }
204    else
205       {
206       int iStatusImage = IMAGE_NOIMAGE;
207       if (!lpServer->fIsMonitored())
208          iStatusImage = imageSERVER_UNMON;
209       else if (Server_GetAlertCount (lpServer))
210          iStatusImage = imageSERVER_ALERT;
211
212       Display_InsertItem (pdr->hList,
213                           NULL,
214                           NULL,
215                           (LPARAM)lpServer->GetIdentifier(),
216                           imageSERVER, iStatusImage, ivSvr);
217       }
218 }
219
220
221 /*
222  * SERVICES ___________________________________________________________________
223  *
224  */
225
226 void Display_Services_Internal (LPDISPLAYREQUEST pdr)
227 {
228    pdr->hList = GetDlgItem (pdr->hChild, IDC_SVC_LIST);
229    pdr->lpvi = &gr.viewSvc;
230
231    if (!IsWindow (pdr->hList))
232       return;
233
234    // First off, can we totally ignore this request?
235    //
236    LPIDENT lpiWindow = Server_GetServerForChild (pdr->hChild);
237    if (lpiWindow && pdr->lpiNotify && (lpiWindow != pdr->lpiNotify->GetServer()))
238       return;
239
240    // Fix up the image lists for the Services window
241    //
242    HIMAGELIST hiSmall;
243    FastList_GetImageLists (pdr->hList, &hiSmall, NULL);
244    if (!hiSmall)
245       {
246       hiSmall = AfsAppLib_CreateImageList (FALSE);
247       FastList_SetImageLists (pdr->hList, hiSmall, NULL);
248       }
249
250    // Add either all services, or one server's services, or one service.
251    //
252    LPCELL lpCell;
253    if (g.lpiCell && (lpCell = g.lpiCell->OpenCell()))
254       {
255       pdr->lpiToSelect = (LPIDENT)FL_StartChange (pdr->hList, (pdr->lpiNotify) ? FALSE : TRUE);
256       pdr->actOnDone = ACT_ENDCHANGE;
257
258       // Remove any to-be-replaced old services
259       //
260       Display_Services_Internal_Clean (pdr);
261
262       // Update all appropriate service entries
263       //
264       LPIDENT lpiRefresh = (pdr->lpiNotify) ? pdr->lpiNotify : lpiWindow;
265
266       HENUM hEnum;
267       for (LPSERVER lpServer = lpCell->ServerFindFirst (&hEnum, lpiRefresh, FALSE); lpServer; lpServer = lpCell->ServerFindNext (&hEnum))
268          {
269          if (lpServer->fIsMonitored())
270             Display_Services_Internal_AddServer (pdr, lpServer);
271          lpServer->Close();
272          }
273
274       if (pdr->lpiToSelect)
275          FL_SetSelectedByData (pdr->hList, (LPARAM)pdr->lpiToSelect);
276       lpCell->Close();
277       }
278 }
279
280
281 void Display_Services_Internal_Clean (LPDISPLAYREQUEST pdr)
282 {
283    if (pdr->lpiNotify) // else, we already emptied the list
284       {
285       HLISTITEM hItem;
286       if ((hItem = FastList_FindItem (pdr->hList, (LPARAM)(pdr->lpiNotify))) != NULL)
287          FastList_RemoveItem (pdr->hList, hItem);
288       }
289 }
290
291
292 void Display_Services_Internal_AddServer (LPDISPLAYREQUEST pdr, LPSERVER lpServer)
293 {
294    ULONG status = 0;
295    SERVERSTATUS ss;
296
297    if (lpServer->GetIdentifier() == pdr->lpiNotify)
298       status = pdr->status;
299    if (!status)
300       lpServer->GetStatus (&ss, FALSE, &status);
301
302    LPTSTR pszServerText = NULL;
303    int iStatusImage = imageSERVER;
304    BOOL fContinue = TRUE;
305
306    if (status != 0)
307       {
308       pszServerText = FormatString (TEXT("%1 - %2"), TEXT("%s%e"), Server_GetColumnText (lpServer->GetIdentifier(), svrcolNAME), status);
309       iStatusImage = imageSERVER_ALERT;
310       fContinue = FALSE;
311       }
312    else if (Server_GetAlertCount (lpServer))
313       {
314       pszServerText = FormatString (TEXT("%1 - %2"), TEXT("%s%s"), Server_GetColumnText (lpServer->GetIdentifier(), svrcolNAME), Server_GetColumnText (lpServer->GetIdentifier(), svrcolSTATUS));
315       iStatusImage = imageSERVER_ALERT;
316       }
317
318    HLISTITEM hServer;
319    if ((hServer = FastList_FindItem (pdr->hList, (LPARAM)(lpServer->GetIdentifier()))) == NULL)
320       {
321       hServer = Display_InsertItem (pdr->hList, NULL, pszServerText,
322                                     (LPARAM)lpServer->GetIdentifier(),
323                                     imageSERVER, iStatusImage, gr.ivSet, PIF_ALWAYSSHOWICON | PIF_TREEVIEW_ONLY);
324       }
325    else
326       {
327       int iImage1, iImage2;
328       Display_PickImages (&iImage1, &iImage2, imageSERVER, iStatusImage, gr.ivSet, PIF_ALWAYSSHOWICON | PIF_TREEVIEW_ONLY);
329       FastList_SetItemFirstImage (pdr->hList, hServer, iImage1);
330       FastList_SetItemSecondImage (pdr->hList, hServer, iImage2);
331       FastList_SetItemText (pdr->hList, hServer, 0, pszServerText);
332       }
333
334    if (pszServerText)
335       FreeString (pszServerText);
336
337    if (fContinue)
338       {
339       // Update icons for all appropriate services
340       //
341       LPIDENT lpiSearch = (pdr->lpiNotify && pdr->lpiNotify->fIsService()) ? (pdr->lpiNotify) : NULL;
342
343       HENUM hEnum;
344       for (LPSERVICE lpService = lpServer->ServiceFindFirst (&hEnum, lpiSearch, FALSE); lpService; lpService = lpServer->ServiceFindNext (&hEnum))
345          {
346          Display_Services_Internal_AddService (pdr, lpService, hServer);
347          lpService->Close();
348          }
349       }
350 }
351
352
353 void Display_Services_Internal_AddService (LPDISPLAYREQUEST pdr, LPSERVICE lpService, HLISTITEM hServer)
354 {
355    ULONG status = 0;
356    SERVICESTATUS ss;
357
358    if (lpService->GetIdentifier() == pdr->lpiNotify)
359       status = pdr->status;
360    if (!status)
361       lpService->GetStatus (&ss, FALSE, &status);
362
363    BOOL fShowServerName = !Server_GetServer (pdr->hChild);
364
365    if (status != 0)
366       {
367       LPTSTR pszCol1 = FormatString (TEXT("%1 - %2"), TEXT("%s%e"), Services_GetColumnText (lpService->GetIdentifier(), svccolNAME, fShowServerName), status);
368
369       Display_InsertItem (pdr->hList,
370                           hServer,
371                           pszCol1,
372                           (LPARAM)lpService->GetIdentifier(),
373                           imageSERVICE, imageSERVICE_ALERT, gr.ivSvc);
374
375       FreeString (pszCol1);
376       }
377    else
378       {
379       TCHAR szName[ cchRESOURCE ];
380       lpService->GetName (szName);
381
382       BOOL fIsBOS = !lstrcmpi (szName, TEXT("BOS"));
383
384       LPSERVICE_PREF lpsp;
385       if ((lpsp = (LPSERVICE_PREF)lpService->GetUserParam()) != NULL)
386          memcpy (&lpsp->ssLast, &ss, sizeof(SERVICESTATUS));
387
388       int iTypeImage = imageSERVICE;
389       if (fIsBOS)
390          iTypeImage = imageBOSSERVICE;
391
392       int iStatusImage = IMAGE_NOIMAGE;
393       if (Services_GetAlertCount (lpService))
394          iStatusImage = imageSERVICE_ALERT;
395       else if (!Services_fRunning (lpService))
396          iStatusImage = imageSERVICE_STOPPED;
397       else if (fIsBOS)
398          iStatusImage = imageBOSSERVICE;
399
400       Display_InsertItem (pdr->hList,
401                           hServer,
402                           NULL,
403                           (LPARAM)lpService->GetIdentifier(),
404                           iTypeImage, iStatusImage, gr.ivSvc);
405       }
406 }
407
408
409 /*
410  * AGGREGATES _________________________________________________________________
411  *
412  */
413
414 void Display_Aggregates_Internal (LPDISPLAYREQUEST pdr)
415 {
416    if (pdr->lpvi == NULL)
417       pdr->lpvi = &gr.viewAgg;
418
419    if (!IsWindow (pdr->hList))
420       return;
421
422    TCHAR szClassName[ cchRESOURCE ];
423    if (GetClassName (pdr->hList, szClassName, cchRESOURCE))
424       {
425       if (!lstrcmp (szClassName, WC_FASTLIST))
426          pdr->fList = TRUE;
427       }
428
429    // First off, can we totally ignore this request?
430    //
431    if (pdr->lpiServer && pdr->lpiNotify && (pdr->lpiServer != pdr->lpiNotify->GetServer()))
432       return;
433
434    // Fix up the image lists for the Aggregates window
435    //
436    if (pdr->fList)
437       {
438       HIMAGELIST hiSmall;
439       FastList_GetImageLists (pdr->hList, &hiSmall, NULL);
440       if (!hiSmall)
441          {
442          hiSmall = AfsAppLib_CreateImageList (FALSE);
443          FastList_SetImageLists (pdr->hList, hiSmall, NULL);
444          }
445       }
446
447    // Add either all aggregates, or one server's aggregates, or one aggregate.
448    //
449    LPCELL lpCell;
450    if (g.lpiCell && (lpCell = g.lpiCell->OpenCell()))
451       {
452       LPIDENT lpiSelectedNow;
453       if (pdr->fList)
454          lpiSelectedNow = (LPIDENT)FL_StartChange (pdr->hList, (pdr->lpiNotify) ? FALSE : TRUE);
455       else
456          lpiSelectedNow = (LPIDENT)CB_StartChange (pdr->hList, (pdr->lpiNotify) ? FALSE : TRUE);
457
458       if (!pdr->lpiToSelect)
459          pdr->lpiToSelect = lpiSelectedNow;
460
461       pdr->actOnDone = ACT_ENDCHANGE;
462
463       // Remove any to-be-replaced old services
464       //
465       Display_Aggregates_Internal_Clean (pdr);
466
467       // Update all appropriate aggregate entries
468       //
469       LPIDENT lpiRefresh = (pdr->lpiNotify) ? pdr->lpiNotify : pdr->lpiServer;
470
471       HENUM hEnum;
472       for (LPSERVER lpServer = lpCell->ServerFindFirst (&hEnum, lpiRefresh, FALSE); lpServer; lpServer = lpCell->ServerFindNext (&hEnum))
473          {
474          if (lpServer->fIsMonitored())
475             Display_Aggregates_Internal_AddServer (pdr, lpServer);
476          lpServer->Close();
477          }
478
479       if (pdr->lpiToSelect)
480          {
481          if (pdr->fList)
482             FL_SetSelectedByData (pdr->hList, (LPARAM)pdr->lpiToSelect);
483          else
484             CB_SetSelectedByData (pdr->hList, (LPARAM)pdr->lpiToSelect);
485          }
486       if (!pdr->fList) // combobox?  then always pick *something*...
487          {
488          if (!CB_GetSelectedData (pdr->hList))
489             {
490             pdr->lpiToSelect = (LPIDENT)CB_GetData (pdr->hList, 0);
491             }
492          }
493
494       lpCell->Close();
495       }
496 }
497
498
499 void Display_Aggregates_Internal_Clean (LPDISPLAYREQUEST pdr)
500 {
501    if (pdr->lpiNotify) // else, we already emptied the list
502       {
503       if (pdr->fList)
504          {
505          HLISTITEM hItem;
506          if ((hItem = FastList_FindItem (pdr->hList, (LPARAM)(pdr->lpiNotify))) != NULL)
507             FastList_RemoveItem (pdr->hList, hItem);
508          }
509       else
510          {
511          size_t iMax = SendMessage (pdr->hList, CB_GETCOUNT, 0, 0);
512
513          for (UINT iItem = 0; iItem < iMax; )
514             {
515             BOOL fDelete = FALSE;
516
517             LPIDENT lpiItem;
518             if ((lpiItem = (LPIDENT)CB_GetData (pdr->hList, iItem)) != NULL)
519                {
520                // delete the entry if it's the TBD server or aggregate
521                //
522                if (lpiItem == pdr->lpiNotify)
523                   fDelete = TRUE;
524
525                // delete the entry if it's the server of a TBD aggregate
526                //
527                if (lpiItem == pdr->lpiNotify->GetServer())
528                   fDelete = TRUE;
529
530                // delete the entry if it's an aggregate on the TBD server
531                //
532                if (lpiItem->GetServer() == pdr->lpiNotify)
533                   fDelete = TRUE;
534                }
535
536             if (!fDelete)
537                ++iItem;
538             else
539                {
540                SendMessage (pdr->hList, CB_DELETESTRING, iItem, 0);
541                --iMax;
542                }
543             }
544          }
545       }
546 }
547
548
549 void Display_Aggregates_Internal_AddServer (LPDISPLAYREQUEST pdr, LPSERVER lpServer)
550 {
551    ULONG status = 0;
552    SERVERSTATUS ss;
553
554    if (lpServer->GetIdentifier() == pdr->lpiNotify)
555       status = pdr->status;
556    if (!status)
557       lpServer->GetStatus (&ss, FALSE, &status);
558
559    HLISTITEM hServer = NULL;
560    if (pdr->fList)
561       {
562       LPTSTR pszServerText = NULL;
563       int iStatusImage = imageSERVER;
564
565       if (status != 0)
566          {
567          pszServerText = FormatString (TEXT("%1 - %2"), TEXT("%s%e"), Server_GetColumnText (lpServer->GetIdentifier(), svrcolNAME), status);
568          iStatusImage = imageSERVER_ALERT;
569          }
570       else if (Server_GetAlertCount (lpServer))
571          {
572          pszServerText = FormatString (TEXT("%1 - %2"), TEXT("%s%s"), Server_GetColumnText (lpServer->GetIdentifier(), svrcolNAME), Server_GetColumnText (lpServer->GetIdentifier(), svrcolSTATUS));
573          iStatusImage = imageSERVER_ALERT;
574          }
575
576       if ((hServer = FastList_FindItem (pdr->hList, (LPARAM)(lpServer->GetIdentifier()))) == NULL)
577          {
578          hServer = Display_InsertItem (pdr->hList, NULL, pszServerText,
579                                        (LPARAM)lpServer->GetIdentifier(),
580                                        imageSERVER, iStatusImage, gr.ivSet, PIF_ALWAYSSHOWICON | PIF_TREEVIEW_ONLY);
581          }
582       else
583          {
584          int iImage1, iImage2;
585          Display_PickImages (&iImage1, &iImage2, imageSERVER, iStatusImage, gr.ivSet, PIF_ALWAYSSHOWICON | PIF_TREEVIEW_ONLY);
586          FastList_SetItemFirstImage (pdr->hList, hServer, iImage1);
587          FastList_SetItemSecondImage (pdr->hList, hServer, iImage2);
588          FastList_SetItemText (pdr->hList, hServer, 0, pszServerText);
589          }
590
591       if (pszServerText)
592          FreeString (pszServerText);
593       }
594
595    if ((hServer || !pdr->fList) && !status)
596       {
597       // Update icons for all appropriate aggregates
598       //
599       LPIDENT lpiSearch = (pdr->lpiNotify && pdr->lpiNotify->fIsAggregate()) ? (pdr->lpiNotify) : NULL;
600
601       HENUM hEnum;
602       for (LPAGGREGATE lpAggregate = lpServer->AggregateFindFirst (&hEnum, lpiSearch, FALSE); lpAggregate; lpAggregate = lpServer->AggregateFindNext (&hEnum))
603          {
604          Display_Aggregates_Internal_AddAggregate (pdr, lpAggregate, hServer);
605          lpAggregate->Close();
606          }
607       }
608 }
609
610
611 void Display_Aggregates_Internal_AddAggregate (LPDISPLAYREQUEST pdr, LPAGGREGATE lpAggregate, HLISTITEM hServer)
612 {
613    ULONG status = 0;
614    AGGREGATESTATUS as;
615
616    if (lpAggregate->GetIdentifier() == pdr->lpiNotify)
617       status = pdr->status;
618    if (!status)
619       lpAggregate->GetStatus (&as, FALSE, &status);
620
621    BOOL fShowServerName = !Server_GetServer (pdr->hChild);
622
623    if (status != 0)
624       {
625       LPTSTR pszCol1 = FormatString (TEXT("%1 - %2"), TEXT("%s%e"), Aggregates_GetColumnText (lpAggregate->GetIdentifier(), aggcolNAME, fShowServerName), status);
626
627       if (pdr->fList)
628          {
629          Display_InsertItem (pdr->hList, hServer, pszCol1,
630                              (LPARAM)lpAggregate->GetIdentifier(),
631                              imageAGGREGATE, imageAGGREGATE_ALERT, gr.ivAgg);
632          }
633       else
634          {
635          CB_AddItem (pdr->hList, pszCol1, (LPARAM)lpAggregate->GetIdentifier());
636          }
637
638       FreeString (pszCol1);
639       }
640    else
641       {
642       LPAGGREGATE_PREF lpap;
643       if ((lpap = (LPAGGREGATE_PREF)lpAggregate->GetUserParam()) != NULL)
644          {
645          memcpy (&lpap->asLast, &as, sizeof(AGGREGATESTATUS));
646          lpAggregate->GetDevice (lpap->szDevice);
647          }
648
649       if (pdr->fList)
650          {
651          int iStatusImage = IMAGE_NOIMAGE;
652          if (Aggregates_GetAlertCount (lpAggregate))
653             iStatusImage = imageAGGREGATE_ALERT;
654
655          Display_InsertItem (pdr->hList, hServer, NULL,
656                              (LPARAM)lpAggregate->GetIdentifier(),
657                              imageAGGREGATE, iStatusImage, gr.ivAgg);
658          }
659       else
660          {
661          TCHAR szName[ cchNAME ];
662          lpAggregate->GetIdentifier()->GetAggregateName (szName);
663          CB_AddItem (pdr->hList, szName, (LPARAM)lpAggregate->GetIdentifier());
664          }
665       }
666 }
667
668
669 /*
670  * FILESETS ___________________________________________________________________
671  *
672  */
673
674 void Display_Filesets_Internal (LPDISPLAYREQUEST pdr)
675 {
676    if (pdr->hList == NULL)
677       pdr->hList = GetDlgItem (pdr->hChild, IDC_SET_LIST);
678
679    if (!IsWindow (pdr->hList))
680       return;
681
682    TCHAR szClassName[ cchRESOURCE ];
683    if (GetClassName (pdr->hList, szClassName, cchRESOURCE))
684       {
685       if (!lstrcmp (szClassName, WC_FASTLIST))
686          pdr->fList = TRUE;
687       }
688
689    pdr->lpvi = (pdr->fList) ? &gr.viewSet : NULL;
690
691    // First off, can we totally ignore this request?
692    //
693    if (pdr->lpiServer && pdr->lpiNotify && (pdr->lpiServer != pdr->lpiNotify->GetServer()))
694       return;
695
696    // Fix up the image lists for the Filesets window
697    //
698    if (pdr->fList)
699       {
700       HIMAGELIST hiSmall;
701       FastList_GetImageLists (pdr->hList, &hiSmall, NULL);
702       if (!hiSmall)
703          {
704          hiSmall = AfsAppLib_CreateImageList (FALSE);
705          FastList_SetImageLists (pdr->hList, hiSmall, NULL);
706          }
707       }
708
709    // Add either all filesets, or one server's filesets, or one fileset.
710    //
711    LPCELL lpCell;
712    if (g.lpiCell && (lpCell = g.lpiCell->OpenCell()))
713       {
714       pdr->actOnDone = ACT_ENDCHANGE;
715
716       // Remove any to-be-replaced old services
717       //
718       LPIDENT lpiSelectedNow;
719       if (pdr->fList)
720          lpiSelectedNow = (LPIDENT)FL_StartChange (pdr->hList, (pdr->lpiNotify) ? FALSE : TRUE);
721       else
722          lpiSelectedNow = (LPIDENT)CB_StartChange (pdr->hList, (pdr->lpiNotify) ? FALSE : TRUE);
723       Display_Filesets_Internal_Clean (pdr);
724
725       if (! pdr->lpiToSelect)
726          pdr->lpiToSelect = lpiSelectedNow;
727
728       HLISTITEM hCell;
729       hCell = Display_Filesets_Internal_AddCell (pdr, lpCell);
730
731       // Update all appropriate fileset entries
732       //
733       LPIDENT lpiRefresh = (pdr->lpiNotify) ? pdr->lpiNotify : pdr->lpiServer;
734
735       HENUM hEnum;
736       for (LPSERVER lpServer = lpCell->ServerFindFirst (&hEnum, lpiRefresh, FALSE); lpServer; lpServer = lpCell->ServerFindNext (&hEnum))
737          {
738          if (lpServer->fIsMonitored())
739             Display_Filesets_Internal_AddServer (pdr, lpServer, hCell);
740          lpServer->Close();
741          }
742
743       if (pdr->lpiToSelect)
744          {
745          if (pdr->fList)
746             FL_SetSelectedByData (pdr->hList, (LPARAM)pdr->lpiToSelect);
747          else
748             CB_SetSelectedByData (pdr->hList, (LPARAM)pdr->lpiToSelect);
749          }
750       if (!pdr->fList) // combobox?  then always pick *something*...
751          {
752          if (!CB_GetSelectedData (pdr->hList))
753             {
754             pdr->lpiToSelect = (LPIDENT)CB_GetData (pdr->hList, 0);
755             }
756          }
757
758       lpCell->Close();
759       }
760 }
761
762
763 void Display_Filesets_Internal_Clean (LPDISPLAYREQUEST pdr)
764 {
765    if (pdr->lpiNotify)
766       {
767       if (pdr->fList)
768          {
769          HLISTITEM hItem;
770          if ((hItem = FastList_FindItem (pdr->hList, (LPARAM)pdr->lpiNotify)) != NULL)
771             {
772             FastList_RemoveItem (pdr->hList, hItem);
773             }
774          }
775       else // Must be a combobox
776          {
777          size_t iMax = SendMessage (pdr->hList, CB_GETCOUNT, 0, 0);
778
779          for (UINT iItem = 0; iItem < iMax; )
780             {
781             BOOL fDelete = FALSE;
782
783             LPIDENT lpiItem;
784             if ((lpiItem = (LPIDENT)CB_GetData (pdr->hList, iItem)) != NULL)
785                {
786                if (lpiItem->GetServer() == pdr->lpiNotify)
787                   fDelete = TRUE;
788                if (lpiItem->GetAggregate() == pdr->lpiNotify)
789                   fDelete = TRUE;
790                if (lpiItem == pdr->lpiNotify)
791                   fDelete = TRUE;
792                }
793
794             if (!fDelete)
795                ++iItem;
796             else
797                {
798                SendMessage (pdr->hList, CB_DELETESTRING, iItem, 0);
799                --iMax;
800                }
801             }
802          }
803       }
804 }
805
806
807 HLISTITEM Display_Filesets_Internal_AddCell (LPDISPLAYREQUEST pdr, LPCELL lpCell)
808 {
809    if (!pdr->fList)
810       return NULL;
811
812    HLISTITEM hCell;
813    if ((hCell = FastList_FindItem (pdr->hList, (LPARAM)lpCell->GetIdentifier())) == NULL)
814       {
815       TCHAR szName[ cchNAME ];
816       lpCell->GetName (szName);
817
818       hCell = Display_InsertItem (pdr->hList, NULL, szName,
819                                   (LPARAM)lpCell->GetIdentifier(),
820                                   imageCELL, IMAGE_NOIMAGE, gr.ivSet,
821                                   PIF_ALWAYSSHOWICON | PIF_ONLYONEICON | PIF_TREEVIEW_ONLY | PIF_DISALLOW_COLLAPSE);
822       }
823
824    return hCell;
825 }
826
827
828 void Display_Filesets_Internal_AddServer (LPDISPLAYREQUEST pdr, LPSERVER lpServer, HLISTITEM hCell)
829 {
830    ULONG status = 0;
831    SERVERSTATUS ss;
832
833    if (lpServer->GetIdentifier() == pdr->lpiNotify)
834       status = pdr->status;
835    if (!status)
836       lpServer->GetStatus (&ss, FALSE, &status);
837
838    HLISTITEM hServer = NULL;
839    if (pdr->fList)
840       {
841       LPTSTR pszServerText = NULL;
842       int iStatusImage = imageSERVER;
843
844       if (status != 0)
845          {
846          pszServerText = FormatString (TEXT("%1 - %2"), TEXT("%s%e"), Server_GetColumnText (lpServer->GetIdentifier(), svrcolNAME), status);
847          iStatusImage = imageSERVER_ALERT;
848          }
849       else if (Server_GetAlertCount (lpServer))
850          {
851          pszServerText = FormatString (TEXT("%1 - %2"), TEXT("%s%s"), Server_GetColumnText (lpServer->GetIdentifier(), svrcolNAME), Server_GetColumnText (lpServer->GetIdentifier(), svrcolSTATUS));
852          iStatusImage = imageSERVER_ALERT;
853          }
854
855       if ((hServer = FastList_FindItem (pdr->hList, (LPARAM)(lpServer->GetIdentifier()))) == NULL)
856          {
857          hServer = Display_InsertItem (pdr->hList, hCell, pszServerText,
858                                        (LPARAM)lpServer->GetIdentifier(),
859                                        imageSERVER, iStatusImage, gr.ivSet, PIF_ALWAYSSHOWICON | PIF_TREEVIEW_ONLY);
860          }
861       else
862          {
863          int iImage1, iImage2;
864          Display_PickImages (&iImage1, &iImage2, imageSERVER, iStatusImage, gr.ivSet, PIF_ALWAYSSHOWICON | PIF_TREEVIEW_ONLY);
865          FastList_SetItemFirstImage (pdr->hList, hServer, iImage1);
866          FastList_SetItemSecondImage (pdr->hList, hServer, iImage2);
867          FastList_SetItemText (pdr->hList, hServer, 0, pszServerText);
868          }
869
870       if (pszServerText)
871          FreeString (pszServerText);
872       }
873
874    if (status == 0)
875       {
876       // Update filesets on all appropriate aggregates
877       //
878       LPIDENT lpiSearch = (pdr->lpiNotify && !pdr->lpiNotify->fIsServer()) ? (pdr->lpiNotify->GetAggregate()) : pdr->lpiAggregate;
879
880       HENUM hEnum;
881       for (LPAGGREGATE lpAggregate = lpServer->AggregateFindFirst (&hEnum, lpiSearch, FALSE); lpAggregate; lpAggregate = lpServer->AggregateFindNext (&hEnum))
882          {
883          Display_Filesets_Internal_AddAggregate (pdr, lpAggregate, hServer);
884          lpAggregate->Close();
885          }
886
887       if (pdr->fList && hServer)
888          {
889          BOOL fExpand = TRUE;
890
891          LPSERVER_PREF lpsp;
892          if ((lpsp = (LPSERVER_PREF)lpServer->GetUserParam()) != NULL)
893             fExpand = lpsp->fExpandTree;
894
895          FastList_SetExpanded (pdr->hList, hServer, fExpand);
896          }
897       }
898 }
899
900
901 void Display_Filesets_Internal_AddAggregate (LPDISPLAYREQUEST pdr, LPAGGREGATE lpAggregate, HLISTITEM hServer)
902 {
903    ULONG status = 0;
904    AGGREGATESTATUS as;
905
906    if (lpAggregate->GetIdentifier() == pdr->lpiNotify)
907       status = pdr->status;
908    if (!status)
909       lpAggregate->GetStatus (&as, FALSE, &status);
910
911    HLISTITEM hAggregate = NULL;
912    if (pdr->fList)
913       {
914       LPTSTR pszAggregateText = NULL;
915       int iStatusImage = imageAGGREGATE;
916
917       if (status != 0)
918          {
919          pszAggregateText = FormatString (TEXT("%1 - %2"), TEXT("%s%e"), Aggregates_GetColumnText (lpAggregate->GetIdentifier(), aggcolNAME, FALSE), status);
920          iStatusImage = imageAGGREGATE_ALERT;
921          }
922       else if (Aggregates_GetAlertCount (lpAggregate))
923          {
924          pszAggregateText = FormatString (TEXT("%1 - %2"), TEXT("%s%s"), Aggregates_GetColumnText (lpAggregate->GetIdentifier(), aggcolNAME), Aggregates_GetColumnText (lpAggregate->GetIdentifier(), aggcolSTATUS));
925          iStatusImage = imageAGGREGATE_ALERT;
926          }
927
928       if ((hAggregate = FastList_FindItem (pdr->hList, (LPARAM)lpAggregate->GetIdentifier())) == NULL)
929          {
930          hAggregate = Display_InsertItem (pdr->hList, hServer, pszAggregateText,
931                                           (LPARAM)lpAggregate->GetIdentifier(),
932                                           imageAGGREGATE, iStatusImage, gr.ivSet, PIF_ALWAYSSHOWICON | PIF_TREEVIEW_ONLY);
933          }
934       else
935          {
936          int iImage1, iImage2;
937          Display_PickImages (&iImage1, &iImage2, imageAGGREGATE, iStatusImage, gr.ivSet, PIF_ALWAYSSHOWICON | PIF_TREEVIEW_ONLY);
938          FastList_SetItemFirstImage (pdr->hList, hAggregate, iImage1);
939          FastList_SetItemSecondImage (pdr->hList, hAggregate, iImage2);
940          FastList_SetItemText (pdr->hList, hAggregate, 0, pszAggregateText);
941          }
942
943       if (pszAggregateText)
944          FreeString (pszAggregateText);
945       }
946
947    if (status == 0)
948       {
949       // Update all appropriate filesets from this aggregate
950       //
951       LPIDENT lpiSearch = (pdr->lpiNotify && pdr->lpiNotify->fIsFileset()) ? (pdr->lpiNotify) : NULL;
952
953       HENUM hEnum;
954       for (LPFILESET lpFileset = lpAggregate->FilesetFindFirst (&hEnum, lpiSearch, FALSE); lpFileset; lpFileset = lpAggregate->FilesetFindNext (&hEnum))
955          {
956          Display_Filesets_Internal_AddFileset (pdr, lpFileset, hAggregate);
957          lpFileset->Close();
958          }
959
960       if (pdr->fList && hAggregate)
961          {
962          BOOL fExpand = (hServer == NULL) ? TRUE : FALSE;
963
964          LPAGGREGATE_PREF lpap;
965          if ((lpap = (LPAGGREGATE_PREF)lpAggregate->GetUserParam()) != NULL)
966             fExpand = lpap->fExpandTree;
967
968          FastList_SetExpanded (pdr->hList, hAggregate, fExpand);
969          }
970       }
971 }
972
973
974 void Display_Filesets_Internal_AddFileset (LPDISPLAYREQUEST pdr, LPFILESET lpFileset, HLISTITEM hAggregate)
975 {
976    ULONG status = 0;
977    FILESETSTATUS fs;
978
979    if (lpFileset->GetIdentifier() == pdr->lpiNotify)
980       status = pdr->status;
981    if (!status)
982       lpFileset->GetStatus (&fs, FALSE, &status);
983
984    if (status != 0)
985       {
986       if (pdr->fList)
987          {
988          LPTSTR pszFilesetText = FormatString (TEXT("%1 - %2"), TEXT("%s%e"), Filesets_GetColumnText (lpFileset->GetIdentifier(), setcolNAME), status);
989
990          Display_InsertItem (pdr->hList, hAggregate, pszFilesetText,
991                              (LPARAM)lpFileset->GetIdentifier(),
992                              imageFILESET, imageFILESET_ALERT, gr.ivSet);
993
994          FreeString (pszFilesetText);
995          }
996       }
997    else
998       {
999       if (!pdr->fList)
1000          {
1001          TCHAR szName[ cchNAME ];
1002          lpFileset->GetName (szName);
1003          CB_AddItem (pdr->hList, szName, (LPARAM)lpFileset->GetIdentifier());
1004          }
1005       else
1006          {
1007          LPFILESET_PREF lpfp;
1008          if ((lpfp = (LPFILESET_PREF)lpFileset->GetUserParam()) != NULL)
1009             {
1010             memcpy (&lpfp->fsLast, &fs, sizeof(FILESETSTATUS));
1011             lpfp->lpiRW = lpFileset->GetReadWriteIdentifier();
1012             }
1013
1014          int iStatusImage = IMAGE_NOIMAGE;
1015          if (Filesets_GetAlertCount (lpFileset))
1016             iStatusImage = imageFILESET_ALERT;
1017          else if (Filesets_fIsLocked (&fs))
1018             iStatusImage = imageFILESET_LOCKED;
1019
1020          Display_InsertItem (pdr->hList, hAggregate, NULL,
1021                              (LPARAM)lpFileset->GetIdentifier(),
1022                              imageFILESET, iStatusImage, gr.ivSet);
1023          }
1024       }
1025 }
1026
1027
1028 /*
1029  * REPLICAS ___________________________________________________________________
1030  *
1031  * (lpiNotify is the RW for which to list all replicas)
1032  *
1033  */
1034
1035 void Display_Replicas_Internal (LPDISPLAYREQUEST pdr)
1036 {
1037    if (!IsWindow (pdr->hList))
1038       return;
1039
1040    pdr->lpvi = &gr.viewRep;
1041    pdr->actOnDone = ACT_ENDCHANGE;
1042
1043    LPIDENT lpiRW = pdr->lpiNotify;
1044    VOLUMEID vidReadWrite;
1045    lpiRW->GetFilesetID (&vidReadWrite);
1046
1047    FL_StartChange (pdr->hList, TRUE);
1048
1049    LPCELL lpCell;
1050    if ((lpCell = lpiRW->OpenCell()) != NULL)
1051       {
1052       HENUM heServer;
1053       for (LPSERVER lpServer = lpCell->ServerFindFirst (&heServer); lpServer; lpServer = lpCell->ServerFindNext (&heServer))
1054          {
1055          HENUM heAggregate;
1056          for (LPAGGREGATE lpAggregate = lpServer->AggregateFindFirst (&heAggregate); lpAggregate; lpAggregate = lpServer->AggregateFindNext (&heAggregate))
1057             {
1058             HENUM heFileset;
1059             for (LPFILESET lpFileset = lpAggregate->FilesetFindFirst (&heFileset); lpFileset; lpFileset = lpAggregate->FilesetFindNext (&heFileset))
1060                {
1061                FILESETSTATUS fs;
1062                if (lpFileset->GetStatus (&fs))
1063                   {
1064                   if ( (fs.Type == ftREPLICA) &&
1065                        (!memcmp (&vidReadWrite, &fs.idReadWrite, sizeof(VOLUMEID))) )
1066                      {
1067                      LPFILESET_PREF lpfp;
1068                      if ((lpfp = (LPFILESET_PREF)lpFileset->GetUserParam()) != NULL)
1069                         {
1070                         memcpy (&lpfp->fsLast, &fs, sizeof(FILESETSTATUS));
1071                         lpfp->lpiRW = lpiRW;
1072                         }
1073
1074                      Display_InsertItem (pdr->hList, NULL, NULL,
1075                                          (LPARAM)lpFileset->GetIdentifier());
1076                      }
1077                   }
1078                lpFileset->Close();
1079                }
1080             lpAggregate->Close();
1081             }
1082          lpServer->Close();
1083          }
1084       lpCell->Close();
1085       }
1086 }
1087
1088
1089 /*
1090  * SERVER WINDOWS _____________________________________________________________
1091  *
1092  */
1093
1094 void Display_ServerWindow_Internal (LPDISPLAYREQUEST pdr)
1095 {
1096    Server_SelectServer (pdr->hChild, pdr->lpiServer, TRUE); // redraw svr window
1097 }
1098
1099
1100 /*
1101  * ICON SELECTION _____________________________________________________________
1102  *
1103  */
1104
1105 void Display_PickImages (int *piImage0, int *piImage1, int iTypeImage, int iStatusImage, ICONVIEW iv, DWORD dwFlags)
1106 {
1107    switch (iv)
1108       {
1109       case ivTWOICONS:
1110          *piImage0 = iTypeImage;
1111          *piImage1 = (iStatusImage == IMAGE_NOIMAGE) ? IMAGE_BLANKIMAGE : iStatusImage;
1112          if (*piImage1 == *piImage0)
1113             *piImage1 = IMAGE_BLANKIMAGE;
1114          if (dwFlags & PIF_ONLYONEICON)
1115             *piImage1 = IMAGE_NOIMAGE;
1116          break;
1117
1118       case ivONEICON:
1119          *piImage0 = (iStatusImage == IMAGE_NOIMAGE) ? IMAGE_BLANKIMAGE : iStatusImage;
1120          *piImage1 = IMAGE_NOIMAGE;
1121          dwFlags |= PIF_ALWAYSSHOWICON;
1122          break;
1123
1124       case ivSTATUS:
1125          *piImage0 = (iStatusImage == IMAGE_NOIMAGE) ? IMAGE_BLANKIMAGE : iStatusImage;
1126          *piImage1 = IMAGE_NOIMAGE;
1127          break;
1128
1129       default:
1130          *piImage0 = iTypeImage;
1131          *piImage1 = iStatusImage;
1132          return;
1133       }
1134
1135    if ((dwFlags & PIF_ALWAYSSHOWICON) && ((*piImage0 == IMAGE_NOIMAGE) || (*piImage0 == IMAGE_BLANKIMAGE)))
1136       {
1137       *piImage0 = iTypeImage;
1138       }
1139 }
1140
1141
1142 HLISTITEM Display_InsertItem (HWND hList, HLISTITEM hParent, LPTSTR pszText, LPARAM lp, int iImage0, int iImage1, ICONVIEW iv, DWORD dwPickImageFlags)
1143 {
1144    FASTLISTADDITEM flai;
1145    memset (&flai, 0x00, sizeof(flai));
1146    flai.hParent = hParent;
1147    flai.pszText = pszText;
1148    flai.lParam = lp;
1149    Display_PickImages (&flai.iFirstImage, &flai.iSecondImage, iImage0, iImage1, iv, dwPickImageFlags);
1150
1151    if (dwPickImageFlags & PIF_TREEVIEW_ONLY)
1152       flai.dwFlags |= FLIF_TREEVIEW_ONLY;
1153
1154    if (dwPickImageFlags & PIF_DISALLOW_COLLAPSE)
1155       flai.dwFlags |= FLIF_DISALLOW_COLLAPSE;
1156
1157    return FastList_AddItem (hList, &flai);
1158 }
1159