⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pnhosts.c

📁 vc环境下的pgp源码
💻 C
📖 第 1 页 / 共 3 页
字号:
	TL_LISTITEM		tlI;
	BOOL			bBehindGateway;

	tlI.hItem		= hItem;
	tlI.stateMask	= TLIS_VISIBLE;

	// authentication stuff
	if (g_bAuthAccess)
	{
		tlI.state		= TLIS_VISIBLE;
		tlI.mask		= TLIF_DATAVALUE | TLIF_STATE;
		tlI.iSubItem	= AUTHENTICATIONCOLUMN;
		tlI.lDataValue	= 0;
		if ((pentry->hostType == kPGPnetSecureHost) ||
			(pentry->hostType == kPGPnetSecureGateway))
		{
			if (paos->bPGPKey)
				tlI.lDataValue |= IDXB_PGPCRYPTO;
			if (paos->bX509Key)
				tlI.lDataValue |= IDXB_X509CRYPTO;
			if (pentry->sharedSecret[0])
				tlI.lDataValue |= IDXB_SSCRYPTO;
		}
		TreeList_SetListItem (paos->hwndHostTreeList, &tlI, FALSE);
	}

	// SA
	tlI.mask		= TLIF_DATAVALUE | TLIF_STATE;
	tlI.iSubItem	= SACOLUMN;

	bBehindGateway = (pentry->childOf != -1);
	if (PNDoesHostHaveSA (bBehindGateway, pentry->ipAddress, pentry->ipMask))
	{
		tlI.state		= TLIS_VISIBLE;
		tlI.lDataValue	= IDX_EXISTINGSA;
	}
	else
	{
		tlI.state		= TLIS_VISIBLE;
		tlI.lDataValue	= -1;
	}
	TreeList_SetListItem (paos->hwndHostTreeList, &tlI, FALSE);
}


//	_______________________________________________
//
//  Update treelist list data for item

static VOID 
sUpdateEditedHostItem (
		PAPPOPTIONSSTRUCT	paos,
		PGPNetHostEntry*	pentry,
		HTLITEM				hItem)
{
	TL_TREEITEM		tTI;
	TL_LISTITEM		tlI;
	INT				iImage;

	tTI.hItem		= hItem;
	tlI.hItem		= hItem;
	tlI.stateMask	= TLIS_VISIBLE;

	// if not a gateway but there are children, delete them
	if (pentry->hostType != kPGPnetSecureGateway)
		TreeList_DeleteChildren (paos->hwndHostTreeList, &tTI);

	// 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;
	}
	tTI.mask			= TLIF_TEXT | TLIF_IMAGE;
	tTI.pszText			= pentry->hostName;
	tTI.iImage			= iImage;
	tTI.iSelectedImage	= iImage;
	TreeList_SetItem (paos->hwndHostTreeList, &tTI);
}


//	____________________________________
//
//	update the tree control recursively

static VOID
sUpdateHostItems (
		HWND				hwnd,
		HTLITEM				hItem,
		PAPPOPTIONSSTRUCT	paos)
{
	PGPNetHostEntry*	pentry;
	TL_TREEITEM			tlI;

	tlI.mask = TLIF_PARAM;
	tlI.hItem = hItem;

	while (hItem)
	{
		tlI.mask = TLIF_PARAM | TLIF_CHILDHANDLE;
		TreeList_GetItem (paos->hwndHostTreeList, &tlI);

		pentry = &paos->pnconfig.pHostList[tlI.lParam];
		if (pentry)
			sUpdateSingleHostItem (paos, pentry, hItem);

		// if there are children, update them too
		if (tlI.hItem)
			sUpdateHostItems (hwnd, tlI.hItem, paos);

		tlI.hItem = hItem;
		tlI.mask = TLIF_NEXTHANDLE;
		TreeList_GetItem (paos->hwndHostTreeList, &tlI);
		hItem = tlI.hItem;
	}
}


//	____________________________________
//
//	update the authentication and SA columns of the tree control

static VOID
sUpdateHostTreeList (
		HWND				hwnd,
		PAPPOPTIONSSTRUCT	paos)
{
	HTLITEM				hItem;

	hItem = TreeList_GetFirstItem (paos->hwndHostTreeList);

	sUpdateHostItems (hwnd, hItem, paos);

	if (sIsHostEntryDisconnectable (hwnd, paos))
	{
		ShowWindow (GetDlgItem (hwnd, IDC_CONNECT), SW_HIDE);
		ShowWindow (GetDlgItem (hwnd, IDC_DISCONNECT), SW_SHOW);
		EnableWindow (GetDlgItem (hwnd, IDC_DISCONNECT), TRUE);
	}
	else
	{
		ShowWindow (GetDlgItem (hwnd, IDC_DISCONNECT), SW_HIDE);
		ShowWindow (GetDlgItem (hwnd, IDC_CONNECT), SW_SHOW);
		EnableWindow (GetDlgItem (hwnd, IDC_CONNECT), 
				sIsHostEntryConnectable (hwnd, paos));
	}
}


//	____________________________________
//
//	load the tree control with configuration

static VOID
sLoadHostTreeList (
		HWND				hwnd,
		PAPPOPTIONSSTRUCT	paos,
		UINT				uPrevCount)
{
	UINT				u;
	PGPNetHostEntry*	pentry;
	HTLITEM				hItem;

	g_hTLSelected = NULL;

	for (u=uPrevCount; u<paos->pnconfig.uHostCount; u++)
	{
		pentry = &paos->pnconfig.pHostList[u];
		hItem = sInsertHostIntoTreeList (paos->hwndHostTreeList, pentry, u);
		sAddHostInfoToItem (paos, pentry, hItem);
	}

	EnableWindow (GetDlgItem (hwnd, IDC_EDIT), FALSE);
	EnableWindow (GetDlgItem (hwnd, IDC_REMOVE), FALSE);
	EnableWindow (GetDlgItem (hwnd, IDC_CONNECT), FALSE);
	EnableWindow (GetDlgItem (hwnd, IDC_DISCONNECT), FALSE);
}


//	____________________________________
//
//	send message to service to attempt IKE connection with host

static BOOL
sConnectToHostEntry (
		HWND				hwndParent,
		PAPPOPTIONSSTRUCT	paos)
{
	TL_TREEITEM		tlI;
	UINT			uIndex;
	
	tlI.hItem = g_hTLSelected;
	tlI.mask = TLIF_PARAM;
	TreeList_GetItem (paos->hwndHostTreeList, &tlI);
	uIndex = tlI.lParam;

	if (!PNSendServiceMessage (PGPNET_M_APPMESSAGE,
		(WPARAM)PGPNET_ATTEMPTIKE, 
		(LPARAM)uIndex))
	{
		PNMessageBox (hwndParent, IDS_CAPTION, IDS_SERVICENOTAVAIL, 
				MB_OK|MB_ICONEXCLAMATION);
	}

	return TRUE;
}


//	____________________________________
//
//	remove the selected host entry

static BOOL
sRemoveHostEntry (
		HWND				hwndParent,
		PAPPOPTIONSSTRUCT	paos)
{
	TL_TREEITEM		tlI;
#if 0 // Delete confirmation
	UINT			uIndex;
	CHAR			szText[kMaxNetHostNameLength + 129];
	CHAR			szCaption[32];
#endif
	
	tlI.hItem = g_hTLSelected;

#if 0 // Delete confirmation?
	tlI.mask = TLIF_PARAM;
	TreeList_GetItem (paos->hwndHostTreeList, &tlI);
	uIndex = tlI.lParam;

	LoadString (g_hinst, IDS_REMOVEHOSTCONFIRM, szText, sizeof(szText));
	lstrcat (szText, paos->pnconfig.pHostList[uIndex].hostName);
	lstrcat (szText, " ?");

	LoadString (g_hinst, IDS_CAPTION, szCaption, sizeof(szCaption));

	if (MessageBox (hwndParent, szText, szCaption, 
					MB_YESNO|MB_ICONEXCLAMATION) == IDYES)
#endif
	{
		TreeList_DeleteItem (paos->hwndHostTreeList, &tlI);
		g_hTLSelected = NULL;

		return TRUE;
	}

	return FALSE;
}


//	______________________________________________
//
//  save the host data structure to the prefs file

static INT
sCreateNewHostEntry (
		PPNCONFIG	ppnconfig,
		INT			iIndex)
{
	PGPNetHostEntry		entryNew;
	PGPNetHostEntry*	pNewHostList;
	DWORD				dwAddress;
	CHAR				szAddress[128];

	memset (&entryNew, '\0', sizeof(PGPNetHostEntry));
	entryNew.childOf		= iIndex;

#if !PGPNET_SECURE_HOSTS_BEHIND_GATEWAYS
	if (iIndex >= 0)
		entryNew.hostType		= kPGPnetInsecureHost;
	else
#endif
		entryNew.hostType		= kPGPnetSecureHost;

	entryNew.ipMask				= 0xFFFFFFFF;
	entryNew.identityType		= kPGPike_ID_IPV4_Addr;
	dwAddress					= 0;
	PNGetLocalHostInfo (&dwAddress, szAddress, sizeof(szAddress));
	entryNew.identityIPAddress	= dwAddress;
	entryNew.authKeyAlg			= kPGPPublicKeyAlgorithm_Invalid;

	pNewHostList = 
		PGPNewData (PGPGetContextMemoryMgr (g_context),
				(ppnconfig->uHostCount+1) * sizeof(PGPNetHostEntry),
				kPGPMemoryMgrFlags_Clear);

	if (pNewHostList) 
	{
		if (ppnconfig->uHostCount > 0)
			pgpCopyMemory (ppnconfig->pHostList, pNewHostList,
					ppnconfig->uHostCount * sizeof(PGPNetHostEntry));
		pgpCopyMemory (&entryNew, &pNewHostList[ppnconfig->uHostCount],
				sizeof(PGPNetHostEntry));
		ppnconfig->uHostCount++;

		if (ppnconfig->pHostList)
			PGPFreeData (ppnconfig->pHostList);
		ppnconfig->pHostList = pNewHostList;

		return ppnconfig->uHostCount -1;
	}

	return -1;
}

//	____________________________________
//
//	add a host entry

BOOL
PNAddHostEntry (
		HWND			hwnd,
		PPNCONFIG		ppnconfig,
		BOOL			bGateway,
		INT				iChildOf,
		LPSTR			pszParent)
{
	INT				iNewIndex;
	CHAR			szPrompt[256];
	CHAR			sz[128];
	
	if (ppnconfig->bExpertMode)
	{
		if (iChildOf >= 0)
		{
			if (bGateway)
			{
				LoadString (g_hinst, IDS_ADDHOSTPROMPT, sz, sizeof(sz));
				wsprintf (szPrompt, sz, pszParent);
				LoadString (g_hinst, IDS_CAPTION, sz, sizeof(sz));
				if (MessageBox (hwnd, szPrompt, 
							sz, MB_YESNO|MB_ICONQUESTION) == IDNO)
					iChildOf = -1;
			}
			else
				iChildOf = -1;
		}

		iNewIndex = sCreateNewHostEntry (ppnconfig, iChildOf);
		if (!PNEditHostEntry (hwnd, ppnconfig, iNewIndex, FALSE))
		{
			ppnconfig->uHostCount--;
			return FALSE;
		}
		else 
		{
			if (ppnconfig->pHostList[iNewIndex].sharedSecret[0] == '\0')
			{
				if (!g_AOS.bPGPKey && !g_AOS.bX509Key)
				{
					if (PNMessageBox (hwnd, IDS_CAPTION, IDS_NEEDAUTHKEY,
								MB_ICONINFORMATION|MB_YESNO) == IDYES)
					{
						PNOptionsPropSheet (hwnd, PGPNET_AUTHOPTIONS);
					}
				}
			}
			return TRUE;
		}
	}
	else
		return (PNAddHostWizard (hwnd, ppnconfig, iChildOf));
}


//	____________________________________
//
//	add a host entry

static BOOL
sAddHostEntry (
		HWND				hwnd,
		PAPPOPTIONSSTRUCT	paos)
{
	TL_TREEITEM		tlI;
	CHAR			szParent[256];
	INT				iChildOf;
	BOOL			bGateway;
	
	tlI.lParam = -1;

	// first get the index of the selected host
	if (g_hTLSelected)
	{
		tlI.hItem = g_hTLSelected;
		tlI.pszText = szParent;
		tlI.cchTextMax = sizeof(szParent);
		tlI.mask = TLIF_PARAM | TLIF_TEXT | TLIF_IMAGE;
		TreeList_GetItem (paos->hwndHostTreeList, &tlI);
	}

	iChildOf = tlI.lParam;
	bGateway = (tlI.iImage == IDX_GATEWAY);

	return (PNAddHostEntry (hwnd, 
				&paos->pnconfig, bGateway, iChildOf, szParent));
}


//	_____________________________________________________
//
//  process host list context menu 

static VOID
sHostContextMenu (
		HWND				hwnd, 
		PAPPOPTIONSSTRUCT	paos,
		INT					iX, 
		INT					iY)
{
	HMENU			hMC;
	HMENU			hMenuTrackPopup;

	hMC = LoadMenu (g_hinst, MAKEINTRESOURCE (IDR_MENUHOSTCONTEXT));
	hMenuTrackPopup = GetSubMenu (hMC, 0);

	if (g_hTLSelected) 
	{
		if (!g_bReadOnly)
		{
			EnableMenuItem (hMenuTrackPopup, IDC_EDIT, 
									MF_BYCOMMAND|MF_ENABLED);
			EnableMenuItem (hMenuTrackPopup, IDC_REMOVE, 
									MF_BYCOMMAND|MF_ENABLED);
		}

		if (sIsHostEntryDisconnectable (hwnd, paos))
		{
			EnableMenuItem (hMenuTrackPopup, IDC_DISCONNECT, 
									MF_BYCOMMAND|MF_ENABLED);
		}
		else if (sIsHostEntryConnectable (hwnd, paos))
		{
			EnableMenuItem (hMenuTrackPopup, IDC_CONNECT, 
									MF_BYCOMMAND|MF_ENABLED);
		}
	}

	if (!g_bReadOnly)
	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -