📄 pnhosts.c
字号:
/*____________________________________________________________________________
Copyright (C) 1998 Network Associates, Inc.
All rights reserved.
PGPhosts.c - PGPnet hosts window message procedure
$Id: PNhosts.c,v 1.55.4.1 1999/06/08 16:32:07 pbj Exp $
____________________________________________________________________________*/
#include <windows.h>
#include <commctrl.h>
#include "resource.h"
#include "PGPnetApp.h"
#include "TreeList.h"
#include "PGPnetHelp.h"
#include "pgpNetIPC.h"
#include "pgpIke.h"
#define IDC_PN_HOSTTREELIST 50001
#define TOP_LIST_OFFSET 7
#define HOR_LIST_OFFSET 7
#define HOR_CONTROL_OFFSET 8
#define BOTTOM_LIST_OFFSET 49
#define BOTTOM_BUTTON_OFFSET 10
#define BUTTON_HEIGHT 24
#define BUTTON_WIDTH 64
#define BUTTON_SPACING 8
#define HOSTNAMEWIDTH 204
#define IPADDRESSWIDTH 90
#define SUBNETMASKWIDTH 90
#define AUTHENTICATIONWIDTH 82
#define SAWIDTH 36
#define HOSTNAMECOLUMN 0
#define IPADDRESSCOLUMN 1
#define SUBNETMASKCOLUMN 2
#define AUTHENTICATIONCOLUMN 3
#define SACOLUMN 4
static UINT g_uBottomListOffset = BOTTOM_LIST_OFFSET;
static UINT g_uOnOffBoxHeight = ONOFFBOX_HEIGHT;
static UINT g_uOnOffBoxWidth = ONOFFBOX_WIDTH;
static UINT g_uButtonHeight = BUTTON_HEIGHT;
static UINT g_uButtonWidth = BUTTON_WIDTH;
static HIMAGELIST g_hil;
static HTLITEM g_hTLSelected;
extern HINSTANCE g_hinst;
extern INT g_iMinWindowWidth;
extern PGPContextRef g_context;
extern APPOPTIONSSTRUCT g_AOS;
extern CHAR g_szHelpFile[];
extern BOOL g_bReadOnly;
extern BOOL g_bAuthAccess;
extern HWND g_hwndForeground;
static DWORD aHostsIds[] = { // Help IDs
IDC_PN_HOSTTREELIST, IDH_PNHOSTS_LIST,
IDC_PGPNETON, IDH_PNMAIN_PGPNETENABLE,
IDC_PGPNETOFF, IDH_PNMAIN_PGPNETDISABLE,
IDC_EDIT, IDH_PNHOSTS_EDIT,
IDC_REMOVE, IDH_PNHOSTS_REMOVE,
IDC_ADD, IDH_PNHOSTS_ADD,
IDC_CONNECT, IDH_PNHOSTS_CONNECT,
IDC_DISCONNECT, IDH_PNHOSTS_DISCONNECT,
0,0
};
// ____________________________________
//
// initialize the tree control
static VOID
sInitHostTreeList (
HWND hwndTree)
{
HBITMAP hBmp;
HDC hDC;
INT iNumBits;
TL_COLUMN tlc;
CHAR sz[64];
// Initialize the tree view window.
// First create imagelist and load the appropriate bitmaps based on
// current display capabilities.
hDC = GetDC (NULL); // DC for desktop
iNumBits = GetDeviceCaps (hDC, BITSPIXEL) * GetDeviceCaps (hDC, PLANES);
ReleaseDC (NULL, hDC);
if (iNumBits <= 8) {
g_hil = ImageList_Create (16, 16, ILC_COLOR|ILC_MASK,
NUM_HOST_BITMAPS, 0);
hBmp = LoadBitmap (g_hinst, MAKEINTRESOURCE (IDB_IMAGES4));
ImageList_AddMasked (g_hil, hBmp, RGB(255, 0, 255));
DeleteObject (hBmp);
}
else {
g_hil = ImageList_Create (16, 16, ILC_COLOR24|ILC_MASK,
NUM_HOST_BITMAPS, 0);
hBmp = LoadBitmap (g_hinst, MAKEINTRESOURCE (IDB_IMAGES24));
ImageList_AddMasked (g_hil, hBmp, RGB(255, 0, 255));
DeleteObject (hBmp);
}
// Associate the image list with the tree view control.
TreeList_SetImageList (hwndTree, g_hil);
// setup columns
tlc.mask = TLCF_FMT | TLCF_WIDTH | TLCF_TEXT |
TLCF_SUBITEM | TLCF_DATATYPE | TLCF_DATAMAX;
tlc.pszText = sz;
tlc.iSubItem = 0;
tlc.fmt = TLCFMT_LEFT;
tlc.iDataType = TLC_DATASTRING;
tlc.cx = HOSTNAMEWIDTH;
LoadString (g_hinst, IDS_HOSTNAMEFIELD, sz, sizeof(sz));
TreeList_InsertColumn (hwndTree, HOSTNAMECOLUMN, &tlc);
tlc.fmt = TLCFMT_LEFT;
tlc.iDataType = TLC_DATASTRING;
tlc.cx = IPADDRESSWIDTH;
LoadString (g_hinst, IDS_IPADDRESSFIELD, sz, sizeof(sz));
TreeList_InsertColumn (hwndTree, IPADDRESSCOLUMN, &tlc);
tlc.fmt = TLCFMT_LEFT;
tlc.iDataType = TLC_DATASTRING;
tlc.cx = SUBNETMASKWIDTH;
LoadString (g_hinst, IDS_SUBNETMASKFIELD, sz, sizeof(sz));
TreeList_InsertColumn (hwndTree, SUBNETMASKCOLUMN, &tlc);
tlc.fmt = TLCFMT_IMAGELIST;
tlc.iDataType = TLC_DATALONG;
tlc.cx = AUTHENTICATIONWIDTH;
LoadString (g_hinst, IDS_AUTHENTICATIONFIELD, sz, sizeof(sz));
TreeList_InsertColumn (hwndTree, AUTHENTICATIONCOLUMN, &tlc);
tlc.fmt = TLCFMT_IMAGE;
tlc.iDataType = TLC_DATALONG;
tlc.cx = SAWIDTH;
LoadString (g_hinst, IDS_SAFIELD, sz, sizeof(sz));
TreeList_InsertColumn (hwndTree, SACOLUMN, &tlc);
}
// ____________________________________
//
// size the list control and move the buttons
static VOID
sSizeControls (
HWND hwnd,
WORD wXsize,
WORD wYsize)
{
HDWP hdwp;
// size the tree control accordingly
hdwp = BeginDeferWindowPos (9);
DeferWindowPos (hdwp,
GetDlgItem (hwnd, IDC_PN_HOSTTREELIST), NULL,
HOR_LIST_OFFSET, TOP_LIST_OFFSET,
wXsize - (2*HOR_LIST_OFFSET),
wYsize - g_uBottomListOffset - TOP_LIST_OFFSET,
SWP_NOZORDER);
// move the "On/Off" box
DeferWindowPos (hdwp,
GetDlgItem (hwnd, IDC_ONOFFBOX), NULL,
HOR_CONTROL_OFFSET,
wYsize - g_uBottomListOffset + TOP_ONOFFBOX_OFFSET,
g_uOnOffBoxWidth, g_uOnOffBoxHeight,
SWP_NOZORDER);
// move the "On" button
DeferWindowPos (hdwp,
GetDlgItem (hwnd, IDC_PGPNETON), NULL,
HOR_CONTROL_OFFSET + (g_uOnOffBoxWidth/5),
wYsize - g_uBottomListOffset +
TOP_ONOFFBOX_OFFSET + (g_uOnOffBoxHeight/3),
0, 0,
SWP_NOZORDER|SWP_NOSIZE);
// move the "Off" button
DeferWindowPos (hdwp,
GetDlgItem (hwnd, IDC_PGPNETOFF), NULL,
HOR_CONTROL_OFFSET + 3*(g_uOnOffBoxWidth/5),
wYsize - g_uBottomListOffset +
TOP_ONOFFBOX_OFFSET + (g_uOnOffBoxHeight/3),
0, 0,
SWP_NOZORDER|SWP_NOSIZE);
// move the "connect" button
DeferWindowPos (hdwp,
GetDlgItem (hwnd, IDC_CONNECT), NULL,
wXsize - HOR_CONTROL_OFFSET - g_uButtonWidth,
wYsize - BOTTOM_BUTTON_OFFSET - g_uButtonHeight,
g_uButtonWidth, g_uButtonHeight,
SWP_NOZORDER|SWP_NOSIZE);
// move the "disconnect" button
DeferWindowPos (hdwp,
GetDlgItem (hwnd, IDC_DISCONNECT), NULL,
wXsize - HOR_CONTROL_OFFSET - g_uButtonWidth,
wYsize - BOTTOM_BUTTON_OFFSET - g_uButtonHeight,
g_uButtonWidth, g_uButtonHeight,
SWP_NOZORDER|SWP_NOSIZE);
// move the "add" button
DeferWindowPos (hdwp,
GetDlgItem (hwnd, IDC_ADD), NULL,
wXsize - HOR_CONTROL_OFFSET - BUTTON_SPACING - 2*g_uButtonWidth,
wYsize - BOTTOM_BUTTON_OFFSET - g_uButtonHeight,
g_uButtonWidth, g_uButtonHeight,
SWP_NOZORDER|SWP_NOSIZE);
// move the "remove" button
DeferWindowPos (hdwp,
GetDlgItem (hwnd, IDC_REMOVE), NULL,
wXsize - HOR_CONTROL_OFFSET - 2*BUTTON_SPACING - 3*g_uButtonWidth,
wYsize - BOTTOM_BUTTON_OFFSET - g_uButtonHeight,
g_uButtonWidth, g_uButtonHeight,
SWP_NOZORDER|SWP_NOSIZE);
// move the "edit" button
DeferWindowPos (hdwp,
GetDlgItem (hwnd, IDC_EDIT), NULL,
wXsize - HOR_CONTROL_OFFSET - 3*BUTTON_SPACING - 4*g_uButtonWidth,
wYsize - BOTTOM_BUTTON_OFFSET - g_uButtonHeight,
g_uButtonWidth, g_uButtonHeight,
SWP_NOZORDER|SWP_NOSIZE);
EndDeferWindowPos (hdwp);
}
// ____________________________________
//
// find the specified item
static HTLITEM
sFindTreeListItemByParam (
HWND hwndTree,
LPARAM lParam)
{
HTLITEM hItem;
TL_TREEITEM tlI;
// first get the index of the first host
hItem = TreeList_GetFirstItem (hwndTree);
while (hItem)
{
tlI.hItem = hItem;
tlI.mask = TLIF_PARAM | TLIF_NEXTHANDLE;
TreeList_GetItem (hwndTree, &tlI);
if (tlI.lParam == lParam)
return hItem;
else
hItem = tlI.hItem;
}
return NULL;
}
// ____________________________________
//
// determine if disconnect button should be shown for selected host
static BOOL
sIsHostEntryDisconnectable (
HWND hwnd,
PAPPOPTIONSSTRUCT paos)
{
TL_LISTITEM tlI;
if (g_hTLSelected)
{
tlI.hItem = g_hTLSelected;
tlI.mask = TLIF_DATAVALUE;
tlI.iSubItem = SACOLUMN;
TreeList_GetListItem (paos->hwndHostTreeList, &tlI);
if (tlI.lDataValue == IDX_EXISTINGSA)
return TRUE;
}
return FALSE;
}
// ____________________________________
//
// determine if connect button should be enabled for selected host
static BOOL
sIsHostEntryConnectable (
HWND hwnd,
PAPPOPTIONSSTRUCT paos)
{
TL_TREEITEM tlI;
if (g_hTLSelected)
{
tlI.hItem = g_hTLSelected;
tlI.mask = TLIF_PARAM | TLIF_IMAGE;
TreeList_GetItem (paos->hwndHostTreeList, &tlI);
if (paos->pnconfig.pHostList[tlI.lParam].childOf == -1)
{
// entry is not behind gateway
switch (tlI.iImage) {
case IDX_GATEWAY :
case IDX_SECUREHOST :
return TRUE;
default :
return FALSE;
}
}
else
{
// entry is behind gateway
switch (tlI.iImage) {
case IDX_SECUREHOST :
case IDX_INSECUREHOST :
case IDX_INSECURESUBNET :
return TRUE;
default :
return FALSE;
}
}
}
return FALSE;
}
// ____________________________________
//
// load the tree control with configuration
static HTLITEM
sInsertHostIntoTreeList (
HWND hwndTree,
PGPNetHostEntry* pentry,
UINT uIndex)
{
TL_TREEITEM tlI;
TL_INSERTSTRUCT tlIns;
INT iImage;
INT iParent;
tlI.hItem = NULL;
tlI.mask = TLIF_TEXT|TLIF_IMAGE|TLIF_PARAM;
tlI.pszText = pentry->hostName;
tlI.lParam = uIndex;
// determine icon to display
switch (pentry->hostType)
{
case kPGPnetInsecureHost :
if (pentry->ipMask == 0xFFFFFFFF)
iImage = IDX_INSECUREHOST;
else
iImage = IDX_INSECURESUBNET;
break;
case kPGPnetSecureHost :
if (pentry->ipMask == 0xFFFFFFFF)
iImage = IDX_SECUREHOST;
else
iImage = IDX_SECURESUBNET;
break;
case kPGPnetSecureGateway :
iImage = IDX_GATEWAY;
break;
}
tlI.iImage = iImage;
tlI.iSelectedImage = iImage;
// Insert the data into the tree.
iParent = pentry->childOf;
if (iParent < 0)
tlIns.hParent = NULL;
else
tlIns.hParent =
sFindTreeListItemByParam (hwndTree, (LPARAM)iParent);
tlIns.item = tlI;
tlIns.hInsertAfter = TLI_SORT;
return (TreeList_InsertItem (hwndTree, &tlIns));
}
// _______________________________________________
//
// Set treelist list data for item
static VOID
sAddHostInfoToItem (
PAPPOPTIONSSTRUCT paos,
PGPNetHostEntry* pentry,
HTLITEM hItem)
{
TL_LISTITEM tlI;
CHAR szText [128];
struct in_addr ia;
tlI.pszText = szText;
tlI.hItem = hItem;
tlI.stateMask = TLIS_VISIBLE;
// IP address
ia.S_un.S_addr = pentry->ipAddress;
lstrcpy (szText, inet_ntoa(ia));
tlI.state = TLIS_VISIBLE;
tlI.mask = TLIF_TEXT | TLIF_STATE;
tlI.iSubItem = IPADDRESSCOLUMN;
TreeList_SetListItem (paos->hwndHostTreeList, &tlI, FALSE);
// subnet mask
if (pentry->ipMask != 0xFFFFFFFF)
{
ia.S_un.S_addr = pentry->ipMask;
lstrcpy (szText, inet_ntoa(ia));
}
else
szText[0] = '\0';
tlI.state = TLIS_VISIBLE;
tlI.mask = TLIF_TEXT | TLIF_STATE;
tlI.iSubItem = SUBNETMASKCOLUMN;
TreeList_SetListItem (paos->hwndHostTreeList, &tlI, FALSE);
}
// _______________________________________________
//
// Update treelist list data for item
static VOID
sUpdateSingleHostItem (
PAPPOPTIONSSTRUCT paos,
PGPNetHostEntry* pentry,
HTLITEM hItem)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -