📄 pnstatus.c
字号:
/*____________________________________________________________________________
Copyright (C) 1998 Network Associates, Inc.
All rights reserved.
PGPstatus.c - PGPnet status window message procedure
$Id: PNstatus.c,v 1.49.4.1 1999/06/08 16:32:07 pbj Exp $
____________________________________________________________________________*/
#include <windows.h>
#include <commctrl.h>
#include "resource.h"
#include "PGPnetApp.h"
#include "pgpNetIPC.h"
#include "PGPnetHelp.h"
#include "pflPrefTypes.h"
#include "pgpIke.h"
#define TOP_LIST_OFFSET 8
#define HOR_LIST_OFFSET 8
#define HOR_CONTROL_OFFSET 8
#define BOTTOM_LIST_OFFSET 50
#define BOTTOM_BUTTON_OFFSET 10
#define BUTTON_HEIGHT 24
#define BUTTON_WIDTH 64
#define BUTTON_SPACING 8
#define DESTCOLWIDTH 100
#define PROTOCOLWIDTH 55
#define ENCRYPTCOLWIDTH 65
#define AUTHCOLWIDTH 80
#define EXPIRESCOLWIDTH 120
#define REMAININGCOLWIDTH 100
#define COL_DEST 0
#define COL_PROTOCOL 1
#define COL_ENCRYPTION 2
#define COL_AUTHENTICATION 3
#define COL_EXPIRATION 4
#define COL_REMAINING 5
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;
extern HINSTANCE g_hinst;
extern INT g_iMinWindowWidth;
extern HWND g_hwndHostDlg;
extern PGPContextRef g_context;
extern APPOPTIONSSTRUCT g_AOS;
extern CHAR g_szHelpFile[];
extern BOOL g_bReadOnly;
#define SORT_ASCENDING 1
#define SORT_DESCENDING -1
typedef struct {
LONG lSPI;
DWORD dwIP;
DWORD dwIPstart;
DWORD dwIPmask;
} SALISTSTRUCT, *PSALISTSTRUCT;
static struct {
INT iDestinationWidth;
INT iProtocolWidth;
INT iEncryptionWidth;
INT iAuthenticationWidth;
INT iExpirationWidth;
INT iRemainingWidth;
INT iSortField;
INT iSortDirection;
} s_ColumnPrefs;
static INT s_iCurrentIndex = 0;
static PSALISTSTRUCT g_pSelectedItem = NULL;
static HIMAGELIST hil;
static DWORD aStatusIds[] = { // Help IDs
IDC_STATUSLIST, IDH_PNSTATUS_LIST,
IDC_PGPNETON, IDH_PNMAIN_PGPNETENABLE,
IDC_PGPNETOFF, IDH_PNMAIN_PGPNETDISABLE,
IDC_SAVE, IDH_PNSTATUS_SAVE,
IDC_REMOVE, IDH_PNSTATUS_REMOVE,
0,0
};
// ___________________________________________
//
// Get widths of columns from prefs file
static VOID
sGetColumnPreferences (VOID)
{
PGPError err;
PGPPrefRef prefref;
PGPSize size;
PVOID pvoid;
s_ColumnPrefs.iDestinationWidth = DESTCOLWIDTH;
s_ColumnPrefs.iProtocolWidth = PROTOCOLWIDTH;
s_ColumnPrefs.iEncryptionWidth = ENCRYPTCOLWIDTH;
s_ColumnPrefs.iAuthenticationWidth = AUTHCOLWIDTH;
s_ColumnPrefs.iExpirationWidth = EXPIRESCOLWIDTH;
s_ColumnPrefs.iRemainingWidth = REMAININGCOLWIDTH;
s_ColumnPrefs.iSortField = COL_DEST;
s_ColumnPrefs.iSortDirection = SORT_ASCENDING;
err = PGPnetOpenPrefs (PGPGetContextMemoryMgr (g_context), &prefref);
if (IsntPGPError (err))
{
err = PGPGetPrefData (prefref,
kPGPNetPrefAppWinStatusWindowData, &size, &pvoid);
if (IsntPGPError (err))
{
if (size == sizeof(s_ColumnPrefs))
{
memcpy (&s_ColumnPrefs, pvoid, sizeof(s_ColumnPrefs));
}
PGPDisposePrefData (prefref, pvoid);
}
PGPnetClosePrefs (prefref, FALSE);
}
}
// ___________________________________________
//
// Put window position information in registry
static VOID
sSetColumnPreferences (
HWND hwndList)
{
PGPError err;
PGPPrefRef prefref;
err = PGPnetOpenPrefs (PGPGetContextMemoryMgr (g_context), &prefref);
if (IsntPGPError (err))
{
s_ColumnPrefs.iDestinationWidth =
ListView_GetColumnWidth (hwndList, COL_DEST);
s_ColumnPrefs.iProtocolWidth =
ListView_GetColumnWidth (hwndList, COL_PROTOCOL);
s_ColumnPrefs.iEncryptionWidth =
ListView_GetColumnWidth (hwndList, COL_ENCRYPTION);
s_ColumnPrefs.iAuthenticationWidth =
ListView_GetColumnWidth (hwndList, COL_AUTHENTICATION);
s_ColumnPrefs.iExpirationWidth =
ListView_GetColumnWidth (hwndList, COL_EXPIRATION);
s_ColumnPrefs.iRemainingWidth =
ListView_GetColumnWidth (hwndList, COL_REMAINING);
PGPSetPrefData (prefref,
kPGPNetPrefAppWinStatusWindowData,
sizeof(s_ColumnPrefs), &s_ColumnPrefs);
PGPnetClosePrefs (prefref, TRUE);
}
}
// ____________________________________
//
// initialize the list control
static VOID
sInitStatusList (
HWND hwnd)
{
HWND hwndList;
LV_COLUMN lvc;
CHAR sz[64];
HBITMAP hBmp;
HDC hDC;
INT iNumBits;
hwndList = GetDlgItem (hwnd, IDC_STATUSLIST);
// load appropriate ImageList
hDC = GetDC (NULL); // DC for desktop
iNumBits = GetDeviceCaps (hDC, BITSPIXEL) * GetDeviceCaps (hDC, PLANES);
ReleaseDC (NULL, hDC);
if (iNumBits <= 8) {
hil = ImageList_Create (16, 16, ILC_COLOR|ILC_MASK,
NUM_HOST_BITMAPS, 0);
hBmp = LoadBitmap (g_hinst, MAKEINTRESOURCE (IDB_IMAGES4));
ImageList_AddMasked (hil, hBmp, RGB(255, 0, 255));
DeleteObject (hBmp);
}
else {
hil = ImageList_Create (16, 16, ILC_COLOR24|ILC_MASK,
NUM_HOST_BITMAPS, 0);
hBmp = LoadBitmap (g_hinst, MAKEINTRESOURCE (IDB_IMAGES24));
ImageList_AddMasked (hil, hBmp, RGB(255, 0, 255));
DeleteObject (hBmp);
}
// Associate the image list with the listview control.
ListView_SetImageList (hwndList, hil, LVSIL_SMALL);
// create columns
sGetColumnPreferences ();
lvc.mask = LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH;
lvc.pszText = sz;
LoadString (g_hinst, IDS_DESTCOLNAME, sz, sizeof(sz));
lvc.fmt = LVCFMT_LEFT;
lvc.cx = s_ColumnPrefs.iDestinationWidth;
lvc.iSubItem = COL_DEST;
ListView_InsertColumn (hwndList, COL_DEST, &lvc);
LoadString (g_hinst, IDS_PROTOCOLNAME, sz, sizeof(sz));
lvc.fmt = LVCFMT_LEFT;
lvc.cx = s_ColumnPrefs.iProtocolWidth;
lvc.iSubItem = COL_PROTOCOL;
ListView_InsertColumn (hwndList, COL_PROTOCOL, &lvc);
LoadString (g_hinst, IDS_ENCRYPTCOLNAME, sz, sizeof(sz));
lvc.fmt = LVCFMT_LEFT;
lvc.cx = s_ColumnPrefs.iEncryptionWidth;
lvc.iSubItem = COL_ENCRYPTION;
ListView_InsertColumn (hwndList, COL_ENCRYPTION, &lvc);
LoadString (g_hinst, IDS_AUTHCOLNAME, sz, sizeof(sz));
lvc.fmt = LVCFMT_LEFT;
lvc.cx = s_ColumnPrefs.iAuthenticationWidth;
lvc.iSubItem = COL_AUTHENTICATION;
ListView_InsertColumn (hwndList, COL_AUTHENTICATION, &lvc);
LoadString (g_hinst, IDS_EXPIRESCOLNAME, sz, sizeof(sz));
lvc.fmt = LVCFMT_LEFT;
lvc.cx = s_ColumnPrefs.iExpirationWidth;
lvc.iSubItem = COL_EXPIRATION;
ListView_InsertColumn (hwndList, COL_EXPIRATION, &lvc);
LoadString (g_hinst, IDS_REMAININGCOLNAME, sz, sizeof(sz));
lvc.fmt = LVCFMT_LEFT;
lvc.cx = s_ColumnPrefs.iRemainingWidth;
lvc.iSubItem = COL_REMAINING;
ListView_InsertColumn (hwndList, COL_REMAINING, &lvc);
}
// ____________________________________
//
// 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 (6);
DeferWindowPos (hdwp,
GetDlgItem (hwnd, IDC_STATUSLIST), NULL,
HOR_LIST_OFFSET, TOP_LIST_OFFSET,
wXsize - (2*HOR_LIST_OFFSET),
wYsize - g_uBottomListOffset - TOP_LIST_OFFSET -1,
SWP_NOZORDER);
// move the "On/Off" box
DeferWindowPos (hdwp,
GetDlgItem (hwnd, IDC_ONOFFBOX), NULL,
HOR_LIST_OFFSET,
wYsize - BOTTOM_ONOFF_OFFSET - g_uOnOffBoxHeight,
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 "remove" button
DeferWindowPos (hdwp,
GetDlgItem (hwnd, IDC_REMOVE), NULL,
wXsize - HOR_LIST_OFFSET - g_uButtonWidth,
wYsize - BOTTOM_BUTTON_OFFSET - g_uButtonHeight,
0, 0,
SWP_NOZORDER|SWP_NOSIZE);
// move the "save" button
DeferWindowPos (hdwp,
GetDlgItem (hwnd, IDC_SAVE), NULL,
wXsize - HOR_LIST_OFFSET - BUTTON_SPACING - 2*g_uButtonWidth,
wYsize - BOTTOM_BUTTON_OFFSET - g_uButtonHeight,
0, 0,
SWP_NOZORDER|SWP_NOSIZE);
EndDeferWindowPos (hdwp);
}
// ____________________________________
//
// find the encryption transform
static INT
sGetEncryptionTransformIndex (
PGPikeSA* pSA)
{
INT iTransform = -1;
INT nTransforms = min (pSA->numTransforms, kPGPike_MaxTransforms);
INT i;
for (i=0; i<nTransforms; i++)
{
if (pSA->transform[i].u.ipsec.protocol == kPGPike_PR_ESP)
{
iTransform = i;
break;
}
}
return iTransform;
}
// ____________________________________
//
// find the compression transform
static INT
sGetCompressionTransformIndex (
PGPikeSA* pSA)
{
INT iTransform = -1;
INT nTransforms = min (pSA->numTransforms, kPGPike_MaxTransforms);
INT i;
for (i=0; i<nTransforms; i++)
{
if (pSA->transform[i].u.ipsec.protocol == kPGPike_PR_IPCOMP)
{
iTransform = i;
break;
}
}
return iTransform;
}
// ____________________________________
//
// find the authentication transform
static INT
sGetAuthenticationTransformIndex (
PGPikeSA* pSA)
{
INT iTransform = -1;
INT nTransforms = min (pSA->numTransforms, kPGPike_MaxTransforms);
INT i;
for (i=0; i<nTransforms; i++)
{
if (pSA->transform[i].u.ipsec.protocol == kPGPike_PR_AH)
{
iTransform = i;
break;
}
}
return iTransform;
}
// ____________________________________
//
// get the ListView index based on the SPI
static INT
sGetIndexFromSPI (
HWND hwndList,
LONG lSPI)
{
LV_ITEM lvi;
PSALISTSTRUCT psals;
lvi.mask = LVIF_PARAM;
lvi.iItem = 0;
while (ListView_GetItem (hwndList, &lvi))
{
psals = (PSALISTSTRUCT)lvi.lParam;
if (psals->lSPI == lSPI)
return lvi.iItem;
else
lvi.iItem++;
}
return -1;
}
// ____________________________________
//
// free the SALISTSTRUCT associated with a particular ListView item
static BOOL
sFreeSAListStruct (
HWND hwndList,
INT iIndex)
{
LV_ITEM lvi;
lvi.mask = LVIF_PARAM;
lvi.iItem = iIndex;
if (ListView_GetItem (hwndList, &lvi))
{
free ((VOID*)lvi.lParam);
return TRUE;
}
else
return FALSE;
}
// ____________________________________
//
// free the SALISTSTRUCT associated with a particular ListView item
static VOID
sFreeAllSAListStructs (
HWND hwndList)
{
INT iIndex = 0;
while (sFreeSAListStruct (hwndList, iIndex))
iIndex++;
}
// ____________________________________
//
// remove a single SA from the list
static VOID
sSADied (
HWND hwndList,
LPARAM* pSPI)
{
INT iIndex;
iIndex = sGetIndexFromSPI (hwndList, *pSPI);
if (iIndex != -1)
{
sFreeSAListStruct (hwndList, iIndex);
ListView_DeleteItem (hwndList, iIndex);
PNDecStatusSACount ();
}
}
// ____________________________________
//
// create string reprentation of remaining data
static VOID
sConvertBytesToString (
PGPUInt32 uKBytes,
LPSTR psz,
UINT uLen)
{
CHAR szUnits[16];
UINT uDivisor;
UINT uWhole;
UINT uDecimal;
UINT uPlaces;
if (uKBytes < 0x00000400)
{
LoadString (g_hinst, IDS_KBYTES, szUnits, sizeof(szUnits));
uDivisor = 1;
}
else if (uKBytes < 0x00100000)
{
LoadString (g_hinst, IDS_MBYTES, szUnits, sizeof(szUnits));
uDivisor = 0x00000400;
}
else if (uKBytes < 0x40000000)
{
LoadString (g_hinst, IDS_GBYTES, szUnits, sizeof(szUnits));
uDivisor = 0x00100000;
}
else
{
LoadString (g_hinst, IDS_TBYTES, szUnits, sizeof(szUnits));
uDivisor = 0x40000000;
}
uWhole = uKBytes / uDivisor;
if (uWhole >= 100)
uPlaces = 0;
else if (uWhole >= 10)
{
uPlaces = 1;
uDecimal = 10 * (uKBytes % uDivisor) / uDivisor;
}
else
{
uPlaces = 2;
uDecimal = 100 * (uKBytes % uDivisor) / uDivisor;
}
if (uPlaces)
wsprintf (psz, "%i.%i", uWhole, uDecimal);
else
wsprintf (psz, "%i", uWhole);
lstrcat (psz, szUnits);
}
// ____________________________________
//
// create string reprentation of remaining data
static VOID
sComputeRemaining (
PGPUInt32 uTotal,
PGPUInt32 uRemaining,
LPSTR psz,
UINT uLen)
{
CHAR szTemp[64];
psz[0] = '\0';
if (uTotal == 0)
return;
if (uLen >= 64)
{
/// sConvertBytesToString (uRemaining, psz, sizeof(szTemp));
/// lstrcat (psz, " / ");
sConvertBytesToString (uTotal, szTemp, sizeof(szTemp));
lstrcat (psz, szTemp);
}
}
// ____________________________________
//
// add a single SA to the list
static VOID
sAddSAToList (
HWND hwndList,
PGPikeSA* pSA)
{
LV_ITEM lvi;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -