void CellEdit_OnInitDialog (HWND hDlg) { PCELLDBLINE pLine = (PCELLDBLINE)PropSheet_FindTabParam (hDlg); if (pLine) { CELLDBLINEINFO Info; CSDB_CrackLine (&Info, pLine->szLine); SetDlgItemText (hDlg, IDC_CELL, Info.szCell); SetDlgItemText (hDlg, IDC_COMMENT, Info.szComment); int iOrder = 0; for (pLine = pLine->pNext; pLine; pLine = pLine->pNext) { CELLDBLINEINFO Info; if (!CSDB_CrackLine (&Info, pLine->szLine)) break; if (Info.szCell[0]) break; CellEdit_AddServerEntry (hDlg, pLine, iOrder++); } } // Prepare the columns on the server list // HWND hList = GetDlgItem (hDlg, IDC_LIST); FASTLISTCOLUMN Column; Column.dwFlags = FLCF_JUSTIFY_LEFT; Column.cxWidth = 200; GetString (Column.szText, IDS_SVRCOL_COMMENT); FastList_SetColumn (hList, 0, &Column); Column.dwFlags = FLCF_JUSTIFY_LEFT; Column.cxWidth = 100; GetString (Column.szText, IDS_SVRCOL_SERVER); FastList_SetColumn (hList, 1, &Column); FastList_SetSortFunction (hList, CellEdit_SortFunction); // Remove the Context Help [?] thing from the title bar // DWORD dwStyle = GetWindowLong (GetParent (hDlg), GWL_STYLE); dwStyle &= ~DS_CONTEXTHELP; SetWindowLong (GetParent (hDlg), GWL_STYLE, dwStyle); dwStyle = GetWindowLong (GetParent (hDlg), GWL_EXSTYLE); dwStyle &= ~WS_EX_CONTEXTHELP; SetWindowLong (GetParent (hDlg), GWL_EXSTYLE, dwStyle); // A little cleanup and we're done! // CellEdit_Enable (hDlg); CellEdit_OnSelect (hDlg); }
void CellEdit_AddServerEntry (HWND hDlg, PCELLDBLINE pLine, int iOrder) { HWND hList = GetDlgItem (hDlg, IDC_LIST); PCELLDBLINE pCopy = New (CELLDBLINE); memcpy (pCopy, pLine, sizeof(CELLDBLINE)); pCopy->pPrev = NULL; pCopy->pNext = (PCELLDBLINE)iOrder; CELLDBLINEINFO Info; CSDB_CrackLine (&Info, pCopy->szLine); TCHAR szServer[ cchRESOURCE ]; lstrcpy (szServer, inet_ntoa (*(struct in_addr *)&Info.ipServer)); FASTLISTADDITEM ai; memset (&ai, 0x00, sizeof(ai)); ai.iFirstImage = IMAGE_NOIMAGE; ai.iSecondImage = IMAGE_NOIMAGE; ai.pszText = Info.szComment; ai.lParam = (LPARAM)pCopy; HLISTITEM hItem = FastList_AddItem (hList, &ai); FastList_SetItemText (hList, hItem, 1, szServer); }
void HostsTab_FillList (HWND hDlg) { HWND hList = GetDlgItem (hDlg, IDC_LIST); FastList_Begin (hList); FastList_RemoveAll (hList); for (PCELLDBLINE pLine = g.Configuration.CellServDB.pFirst; pLine; pLine = pLine->pNext) { CELLDBLINEINFO Info; if (!CSDB_CrackLine (&Info, pLine->szLine)) continue; if (!Info.szCell[0]) continue; TCHAR szText[ MAX_PATH ]; lstrcpy (szText, Info.szCell); #if 0 // Add this if you like a more verbose Cell Hosts tab if (Info.szComment) wsprintf (&szText[ lstrlen(szText) ], TEXT(" (%s)"), Info.szComment); #endif FASTLISTADDITEM ai; memset (&ai, 0x00, sizeof(ai)); ai.iFirstImage = IMAGE_NOIMAGE; ai.iSecondImage = IMAGE_NOIMAGE; ai.pszText = szText; ai.lParam = (LPARAM)pLine; FastList_AddItem (hList, &ai); } FastList_End (hList); }
void HostsTab_OnRemove (HWND hDlg) { HWND hList = GetDlgItem (hDlg, IDC_LIST); HLISTITEM hItem = FastList_FindFirstSelected (hList); HLISTITEM hNext = FastList_FindNextSelected (hList, hItem); if (!hItem) { return; } else if (hNext) { if (Message (MB_ICONEXCLAMATION | MB_OKCANCEL, GetCautionTitle(), IDS_HOSTREM_MANY) != IDOK) return; } else // (!hNext) { PCELLDBLINE pLine = (PCELLDBLINE)FastList_GetItemParam (hList, hItem); CELLDBLINEINFO Info; CSDB_CrackLine (&Info, pLine->szLine); if (Message (MB_ICONEXCLAMATION | MB_OKCANCEL, GetCautionTitle(), IDS_HOSTREM_ONE, TEXT("%s"), Info.szCell) != IDOK) return; } for ( ; hItem; hItem = FastList_FindNextSelected (hList, hItem)) { PCELLDBLINE pLine = (PCELLDBLINE)FastList_GetItemParam (hList, hItem); CSDB_RemoveCell (&g.Configuration.CellServDB, pLine); } HostsTab_FillList (hDlg); HostsTab_OnSelect (hDlg); }
BOOL CALLBACK ServerEdit_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp) { switch (msg) { case WM_INITDIALOG: SetWindowLongPtr (hDlg, DWLP_USER, lp); ServerEdit_OnInitDialog (hDlg); break; case WM_COMMAND: switch (LOWORD(wp)) { case IDOK: if (ServerEdit_OnOK (hDlg)) EndDialog (hDlg, IDOK); break; case IDCANCEL: EndDialog (hDlg, IDCANCEL); break; case IDHELP: ServerEdit_DlgProc (hDlg, WM_HELP, 0, 0); break; case IDC_ADDR_SPECIFIC: case IDC_ADDR_LOOKUP: EnableWindow (GetDlgItem (hDlg, IDC_SERVER), IsDlgButtonChecked (hDlg, IDC_ADDR_SPECIFIC)); break; } break; case WM_HELP: PCELLDBLINE pLine; pLine = (PCELLDBLINE)GetWindowLongPtr (hDlg, DWLP_USER); CELLDBLINEINFO Info; if (!CSDB_CrackLine (&Info, pLine->szLine)) WinHelp (hDlg, g.szHelpFile, HELP_CONTEXT, IDH_AFSCONFIG_CELLPROP_SERVER_ADD); else WinHelp (hDlg, g.szHelpFile, HELP_CONTEXT, IDH_AFSCONFIG_CELLPROP_SERVER_EDIT); break; } return FALSE; }
void CellEdit_OnApply (HWND hDlg) { TCHAR szCell[ cchCELLDBLINE ]; GetDlgItemText (hDlg, IDC_CELL, szCell, cchCELLDBLINE); TCHAR szComment[ cchCELLDBLINE ]; GetDlgItemText (hDlg, IDC_COMMENT, szComment, cchCELLDBLINE); TCHAR szLinkedCell[ cchCELLDBLINE ] = TEXT(""); // Find out if there's already an entry in CellServDB for this cell // PCELLDBLINE pCellLine; if ((pCellLine = CSDB_FindCell (&g.Configuration.CellServDB, szCell)) != NULL) { CELLDBLINEINFO Info; if (CSDB_CrackLine (&Info, pCellLine->szLine)) lstrcpy (szLinkedCell, Info.szLinkedCell); } // Replace our cell's entry in CellServDB, or add one if necessary. // if ((pCellLine = CSDB_AddCell (&g.Configuration.CellServDB, szCell, szLinkedCell, szComment)) != NULL) { // Remove the old servers from this cell // CSDB_RemoveCellServers (&g.Configuration.CellServDB, pCellLine); // Add the servers from our list to the CellServDB // PCELLDBLINE pAppendTo = pCellLine; HWND hList = GetDlgItem (hDlg, IDC_LIST); for (HLISTITEM hItem = FastList_FindFirst (hList); hItem; hItem = FastList_FindNext (hList, hItem)) { PCELLDBLINE pFromList = (PCELLDBLINE)FastList_GetItemParam (hList, hItem); pAppendTo = CSDB_AddLine (&g.Configuration.CellServDB, pAppendTo, pFromList->szLine); } } }
void CellEdit_OnEdit (HWND hDlg) { HWND hList = GetDlgItem (hDlg, IDC_LIST); HLISTITEM hItem = FastList_FindFirstSelected (hList); PCELLDBLINE pInfo = (PCELLDBLINE)FastList_GetItemParam (hList, hItem); CELLDBLINE Line; memcpy (&Line, pInfo, sizeof(CELLDBLINE)); if (ModalDialogParam (IDD_SERVER_EDIT, hDlg, (DLGPROC)ServerEdit_DlgProc, (LPARAM)&Line) == IDOK) { CELLDBLINEINFO Info; CSDB_CrackLine (&Info, Line.szLine); TCHAR szServer[ cchRESOURCE ]; lstrcpy (szServer, inet_ntoa (*(struct in_addr *)&Info.ipServer)); FastList_SetItemText (hList, hItem, 0, Info.szComment); FastList_SetItemText (hList, hItem, 1, szServer); lstrcpy (pInfo->szLine, Line.szLine); } }
void ServerEdit_OnInitDialog (HWND hDlg) { PCELLDBLINE pLine = (PCELLDBLINE)GetWindowLongPtr (hDlg, DWLP_USER); TCHAR szTitle[ cchRESOURCE ]; CELLDBLINEINFO Info; if (!CSDB_CrackLine (&Info, pLine->szLine)) GetString (szTitle, IDS_ADDSERVER_TITLE); else GetString (szTitle, IDS_EDITSERVER_TITLE); SetWindowText (hDlg, szTitle); SOCKADDR_IN Addr; memset (&Addr, 0x00, sizeof(SOCKADDR_IN)); Addr.sin_family = AF_INET; Addr.sin_addr.s_addr = Info.ipServer; SA_SetAddr (GetDlgItem (hDlg, IDC_SERVER), &Addr); CheckDlgButton (hDlg, IDC_ADDR_SPECIFIC, !!Info.ipServer); CheckDlgButton (hDlg, IDC_ADDR_LOOKUP, !Info.ipServer); EnableWindow (GetDlgItem (hDlg, IDC_SERVER), IsDlgButtonChecked (hDlg, IDC_ADDR_SPECIFIC)); SetDlgItemText (hDlg, IDC_COMMENT, Info.szComment); }
void HostsTab_OnEdit (HWND hDlg) { HWND hList = GetDlgItem (hDlg, IDC_LIST); HLISTITEM hItem = FastList_FindFirstSelected (hList); if (hItem) { PCELLDBLINE pLine = (PCELLDBLINE)FastList_GetItemParam (hList, hItem); CELLDBLINEINFO Info; CSDB_CrackLine (&Info, pLine->szLine); LPTSTR pszTitle = FormatString (IDS_CELLEDIT_TITLE, TEXT("%s"), ((Info.szComment[0]) ? Info.szComment : Info.szCell)); LPPROPSHEET psh = PropSheet_Create (pszTitle, FALSE, GetParent(hDlg), (LPARAM)pLine); psh->sh.dwFlags |= PSH_NOAPPLYNOW; // Remove the Apply button psh->sh.dwFlags |= PSH_HASHELP; // Add a Help button instead PropSheet_AddTab (psh, ((Info.szComment[0]) ? Info.szComment : Info.szCell), IDD_CELL_EDIT, (DLGPROC)CellEdit_DlgProc, (LPARAM)pLine, TRUE); PropSheet_ShowModal (psh); FreeString (pszTitle); } HostsTab_FillList (hDlg); HostsTab_OnSelect (hDlg); }
/* * ClientCellServDbUpdate() -- add or remove a client CellServDB entry. * * Common function implementing cfg_ClientCellServDb{Add/Remove}(). */ static int ClientCellServDbUpdate(int updateOp, void *hostHandle, const char *cellName, const char *dbentry, afs_status_p st) { int rc = 1; afs_status_t tst2, tst = 0; cfg_host_p cfg_host = (cfg_host_p) hostHandle; char dbentryFull[MAXHOSTCHARS]; /* validate parameters and resolve dbentry to fully qualified name */ if (!cfgutil_HostHandleValidate(cfg_host, &tst2)) { tst = tst2; } else if (cellName == NULL || *cellName == '\0') { tst = ADMCFGCELLNAMENULL; } else if (strlen(cellName) > (MAXCELLCHARS - 1)) { tst = ADMCFGCELLNAMETOOLONG; } else if (dbentry == NULL || *dbentry == '\0') { tst = ADMCFGHOSTNAMENULL; } else if (strlen(dbentry) > (MAXHOSTCHARS - 1)) { tst = ADMCFGHOSTNAMETOOLONG; } else if (!cfgutil_HostNameGetFull(dbentry, dbentryFull, &tst2)) { tst = tst2; } /* remote configuration not yet supported in this function */ if (tst == 0) { if (!cfg_host->is_local) { tst = ADMCFGNOTSUPPORTED; } } /* modify local client CellServDB entry for specified cell */ #ifdef AFS_NT40_ENV if (tst == 0) { CELLSERVDB clientDb; if (!CSDB_ReadFile(&clientDb, AFSDIR_CLIENT_CELLSERVDB_FILEPATH)) { tst = ADMCFGCLIENTCELLSERVDBNOTREAD; } else { CELLDBLINE *cellLinep = CSDB_FindCell(&clientDb, cellName); CELLDBLINE *serverLinep = NULL; int serverLineCount = 0; if (cellLinep != NULL) { /* found cellName, now find server to add/remove */ CELLDBLINE *workingLinep; for (workingLinep = cellLinep->pNext; workingLinep != NULL; workingLinep = workingLinep->pNext) { CELLDBLINEINFO lineInfo; if (!CSDB_CrackLine(&lineInfo, workingLinep->szLine)) { /* not a server (or cell) line; perhaps a comment */ continue; } else if (lineInfo.szCell[0] != '\0') { /* hit a new cell line */ break; } else { /* found a server line; check if is host of interest */ short isValid; int dbentryAddr = ntohl(lineInfo.ipServer); serverLineCount++; if (!cfgutil_HostAddressIsValid (dbentryFull, dbentryAddr, &isValid, &tst2)) { tst = tst2; break; } else if (isValid) { /* found server of interest */ serverLinep = workingLinep; break; } } } } if (tst == 0) { if (updateOp == CSDB_OP_ADD && serverLinep == NULL) { if (cellLinep == NULL) { cellLinep = CSDB_AddCell(&clientDb, cellName, NULL, NULL); } if (cellLinep == NULL) { tst = ADMNOMEM; } else if (serverLineCount >= MAXHOSTSPERCELL) { tst = ADMCFGCLIENTCELLSERVDBNOSPACE; } else { const char *dbentryAddrStr; if (!cfgutil_HostNameGetAddressString (dbentryFull, &dbentryAddrStr, &tst2)) { tst = tst2; } else { serverLinep = CSDB_AddCellServer(&clientDb, cellLinep, dbentryAddrStr, dbentryFull); if (serverLinep == NULL) { tst = ADMNOMEM; } } } } else if (updateOp == CSDB_OP_REM && serverLinep != NULL) { (void)CSDB_RemoveLine(&clientDb, serverLinep); } if (tst == 0) { if (!CSDB_WriteFile(&clientDb)) { tst = ADMCFGCLIENTCELLSERVDBNOTWRITTEN; } } } CSDB_FreeFile(&clientDb); } } #else if (tst == 0) { /* function not yet implemented for Unix */ tst = ADMCFGNOTSUPPORTED; } #endif /* AFS_NT40_ENV */ if (tst != 0) { /* indicate failure */ rc = 0; } if (st != NULL) { *st = tst; } return rc; }