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

📄 pkmsgprc.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
📖 第 1 页 / 共 5 页
字号:
/*____________________________________________________________________________
	Copyright (C) 2002 PGP Corporation
	All rights reserved.
	
	PKMsgPrc - main message processing and associated routines
	
	$Id: PKMsgPrc.c,v 1.104 2002/11/03 16:37:36 pbj Exp $
____________________________________________________________________________*/
#include "pgpPFLConfig.h"	/* or pgpConfig.h in the CDK */

// project header files
#include "PGPkeysx.h"
#include "search.h"
#include "pgpWin32IPC.h"
#include "pgpImageList.h"

// pgp header files
#include "pgpKeyserverPrefs.h" 
#include "PGPpda.h"

// system header files
#include <commdlg.h>
#include <zmouse.h>
#include <htmlhelp.h>

// constant defitions
#define RELOADDELAY			200			//delay to allow clearing of window
#define RELOADTIMER			1112		//

#define WRITELOCKTRIES		3			//num times to try keyring when locked
#define WRITELOCKDELAY		1500		//ms delay when keyring is writelocked

#define LEDTIMER			111
#define LEDTIMERPERIOD		100

#define NUMLEDS				10
#define LEDWIDTH			6
#define LEDSPACING			2
#define TOTALLEDWIDTH		(NUMLEDS*(LEDWIDTH+LEDSPACING+1))

#define ICON_PANE				0
#define STATUS_MSG_PANE			1
#define PROGRESS_PANE			2

#define TLS_NOSEARCHYET			0
#define TLS_NOTAUTHENTICATED	1
#define TLS_AUTHENTICATED		2

#define ICONWIDTH				25

#define SEARCHCONTROLHEIGHT		100

#define GRABBARHEIGHT			2

#define MINSEARCHWINDOWHEIGHT	260
#define MINSEARCHWINDOWWIDTH	460

#define PK_M_COPYFILENAMES		WM_APP+340

// external globals
extern HINSTANCE		g_hinst;
extern HWND				g_hwndMain;
extern HWND				g_hwndActive;
extern HIMAGELIST		g_hilKeys;
extern HICON			g_hiconToken;
extern HICON			g_hiconOpenLock;
extern HICON			g_hiconClosedLock;
extern UINT				g_uReloadPrefsMessage;
extern UINT				g_uReloadKeyringMessage;
extern UINT				g_uReloadKeyserverPrefsMessage;
extern UINT				g_uMouseWheelMessage;
extern PGPContextRef	g_context;
extern PGPtlsContextRef	g_tlscontext;
extern PGPBoolean		g_bExpertMode;
extern PGPBoolean		g_bKeyGenEnabled;
extern PGPBoolean		g_bMarginalAsInvalid;
extern BOOL				g_bShowGroups;
extern INT				g_iGroupsPercent;
extern INT				g_iToolHeight;
extern PGPUInt32		g_uNumTokens;
extern PGPPDASTRUCT*	g_pPDA;

// local globals
static BOOL			s_bKeyHasBeenGenerated		= FALSE;
static BOOL			s_bIgnorePrefsReloads		= FALSE;
static BOOL			s_bPrefsReloadIgnored		= FALSE;
static HWND			s_hwndOpenSearch			= NULL;
static BOOL			s_bInPDAOp					= FALSE;
static BOOL			s_bFirstKeyringLoad			= TRUE;
static ULONG		s_ulColumns					= 0;
static UINT			s_uStatusBarHeight			= 0;

static HBITMAP		s_hbmpWatermark				= NULL;


// typedefs
typedef struct {
	BOOL			bSearch;
	BOOL			bPda;
	BOOL			bReadOnly;
	PGPKeyDBRef		keydbMain;
} PKWINDOWSTRUCT, *PPKWINDOWSTRUCT;

typedef struct {
	BOOL			bNew;
	BOOL			bHavePub;
	BOOL			bHaveSec;
	CHAR			szPub[MAX_PATH];
	CHAR			szSec[MAX_PATH];
} PKOPENFILESTRUCT, *PPKOPENFILESTRUCT;

// local prototypes
static HWND
sNewPGPkeysWindow (
		HWND			hwndParent,
		PGPKEYSSTRUCT*	ppks,
		BOOL			bSearch,
		BOOL			bPda,
		BOOL			bReadOnly,
		LPSTR			pszPath,
		PGPKeyDBRef		keydb);

static DWORD aOpenFilesIds[] = {			// Help IDs
	IDC_PROMPT,				-1,
	IDC_PUBRING,			IDH_PGPPK_OPENPUBRING,
	IDC_SECRING,			IDH_PGPPK_OPENSECRING,
	IDC_BROWSEPUBRING,		IDH_PGPPK_BROWSEPUBRING,
	IDC_BROWSESECRING,		IDH_PGPPK_BROWSESECRING,
	0,0
};


//	____________________________________
//
//  Save keyset to PDA format data file

static BOOL 
sSaveKeySetToPdaFile (
		HWND			hwnd,
		HMODULE			hmod,
		PGPKeySetRef	keyset,
		BOOL			bClose) 
{
	PGPError			err;
	PGPpdaSaveStruct	pss;

	if (IsntNull (hmod))
	{
		PGPError (*pSavePdaKeyset)(PGPpdaSaveStruct*);

		pSavePdaKeyset = (PGPError (*)(PGPpdaSaveStruct*))
				GetProcAddress (hmod, "PGPpdaSaveKeyset");

		if (pSavePdaKeyset)
		{
			pss.context = g_context;
			pss.hwndParent = hwnd;
			pss.keyset = keyset;
			pss.bClose = bClose;

			err = (*pSavePdaKeyset)(&pss);
			if (IsntPGPError (PGPclErrorBox (hwnd, err)))
				return TRUE;
		}
	}

	return FALSE;
}


//	____________________________________
//
//  Open the PGP pda keyset

static BOOL 
sOpenPdaKeyring (
		HWND			hwnd,
		PGPPDASTRUCT*	pPDA,
		PGPKEYSSTRUCT*	ppks,
		BOOL			bNew)
{
	PGPError			err;
	PGPpdaOpenStruct	pos;

	if (IsntNull (pPDA->hmod))
	{
		PGPError (*pOpenPdaKeyset)(PGPpdaOpenStruct*);

		pOpenPdaKeyset = (PGPError (*)(PGPpdaOpenStruct*))
				GetProcAddress (pPDA->hmod, "PGPpdaOpenKeyset");

		if (pOpenPdaKeyset)
		{
			pos.context = g_context;
			pos.hwndParent = hwnd;

			err = (*pOpenPdaKeyset)(&pos);
			if (IsntPGPError (PGPclErrorBox (hwnd, err)))
			{
				if (bNew)
				{
					pPDA->hwnd = sNewPGPkeysWindow (hwnd, 
							ppks, FALSE, TRUE, FALSE, pos.szTitle, pos.keydb);
				}
				else
				{
					PGPclKeyListLoadKeys (ppks->hKL, NULL, NULL);
					PGPFreeKeyDB (ppks->keydbMain);
					ppks->keydbMain = pos.keydb;
					ppks->keysetDisp = PGPPeekKeyDBRootKeySet (pos.keydb);
					PGPclKeyListLoadKeys (
							ppks->hKL, ppks->keydbMain, ppks->keysetDisp);
				}

				PostMessage (pPDA->hwnd, PK_M_REFRESHKEYRINGS, 0, 0);

				return TRUE;
			}
		}
	}

	return FALSE;
}


//	____________________________________
//
//  perform a PDA operation (other than opening keyring)

static VOID 
sPdaOperation (
		HWND			hwnd,
		HMODULE			hmod,
		UINT			uOp)
{
	PGPError			err;
	PGPpdaOpStruct		pos;

	s_bInPDAOp = TRUE;

	if (IsntNull (hmod))
	{
		PGPError (*pPdaOp)(PGPpdaOpStruct*);
		
		pPdaOp = (PGPError (*)(PGPpdaOpStruct*))
				GetProcAddress (hmod, "PGPpdaOperation");

		if (pPdaOp)
		{
			pos.context = g_context;
			pos.hwndParent = hwnd;
			pos.uOperation = uOp;

			err = (*pPdaOp)(&pos);
			PGPclErrorBox (hwnd, err);
		}
	}

	s_bInPDAOp = FALSE;
}


//	____________________________________
//
//  find PDA struct from HWND

static PGPPDASTRUCT* 
sPDAFromWindow (
		HWND	hwnd)
{
	PGPPDASTRUCT*	p	= NULL;

	if (IsntNull (g_pPDA))
	{
		p = g_pPDA;
		while (p->hmod)
		{
			if (p->hwnd == hwnd)
				return p;
			p++;
		}
	}

	return NULL;
}


//	____________________________________
//
//  Process the PDA notification message

static LRESULT 
sProcessPdaNotification (
		HWND			hwnd, 
		PGPKEYSSTRUCT*	ppks,
		WPARAM			wParam,
		LPARAM			lParam)
{
	switch (wParam) {
	case PDA_IDENTIFY :
		return PGPPDA_M_NOTIFY_PALM;

	case PDA_SYNCOKQUERY :
		if (hwnd && IsWindowEnabled (hwnd))
			return 0;
		else
		{
			PKMessageBox (hwnd, IDS_CAPTIONINFO, 
					IDS_ATTEMPTINGPDASYNC, MB_OK|MB_ICONINFORMATION);
		}
		break;

	case PDA_SYNCSTART :
		if (hwnd && IsWindowEnabled (hwnd))
		{
			PGPKeyDBRef		keydb;
			PGPPDASTRUCT*	pPDA;

			pPDA = sPDAFromWindow (hwnd);

			if (IsntNull (pPDA))
			{
				keydb = PGPPeekKeySetKeyDB (ppks->keysetDisp);
				if (sSaveKeySetToPdaFile (hwnd, pPDA->hmod, 
						PGPPeekKeyDBRootKeySet (keydb), FALSE))
				{
					EnableWindow (hwnd, FALSE);
					return 0;
				}
			}
		}
		break;

	case PDA_SYNCSUCCESS :
	{
		PGPPDASTRUCT*	pPDA;

		pPDA = sPDAFromWindow (hwnd);

		if (IsntNull (pPDA))
			sOpenPdaKeyring (hwnd, pPDA, ppks, FALSE);

		EnableWindow (hwnd, TRUE);
		break;
	}

	case PDA_SYNCFAILURE :
		EnableWindow (hwnd, TRUE);
		break;

	case PDA_UPDATEUSERS :
		break;
	}

	return 1;
}


//	____________________________________
//
//  restore main PGPkeys window to saved position

static VOID 
sRestoreWindowPos (
		HWND	hwnd)
{
	DWORD	dwJunk;
	INT		iX, iY, iWidth, iHeight;
	BOOL	bJunk;
	INT		iJunk1, iJunk2;

	WINDOWPLACEMENT		wp;

	PKGetPrivatePrefData (&dwJunk, &iX, &iY, &iWidth, &iHeight, 
			&bJunk, &iJunk1, &iJunk2);

	wp.length			= sizeof (wp);
	wp.flags			= 0;
	
	wp.showCmd			= SW_SHOWNORMAL;
	wp.ptMaxPosition.x	= 0;
	wp.ptMaxPosition.y	= 0;
	wp.ptMinPosition.x	= 0;
	wp.ptMinPosition.y	= 0;

	wp.rcNormalPosition.left	= iX;
	wp.rcNormalPosition.top		= iY;
	wp.rcNormalPosition.right	= iX + iWidth;
	wp.rcNormalPosition.bottom	= iY + iHeight;

	SetWindowPlacement (hwnd, &wp);
}


//	____________________________________
//
//  Process files in command line

static VOID 
sProcessFileList (
		LPSTR			pszList,
		PGPKEYSSTRUCT*	ppks,
		BOOL			bCommandLine, 
		BOOL			bAllowSelect) 
{
	BOOL			bImported		= FALSE;
	PGPFileSpecRef	fileref;
	PGPKeyDBRef		keydbToAdd;
	LPSTR			p, p2;
	INT				iNumKeys;
	CHAR			cTerm;
	PGPInputFormat	format;
	PGPUInt32		uType;
	
	p = pszList;

	// skip over path of program 
	if (bCommandLine)
	{
		while (*p && (*p == ' ')) 
			p++;

		if (*p) 
		{
			if (*p == '"') 
			{
				p++;
				cTerm = '"';
			}
			else 
				cTerm = ' ';
		}

		while (*p && (*p != cTerm)) 
			p++;

		if (*p && (cTerm == '"')) 
			p++;
	}

	// parse file names
	// Unfortunately, the OS hands me names in the command line in all 
	// sorts of forms: space delimited; quoted and space delimited; space
	// delimiter after the program path but then NULL terminated.
	// And this is just NT ...
	while (p && *p) 
	{
		while (*p && (*p == ' ')) 
			p++;

		if (*p) 
		{
			if (*p == '"') 
			{
				while (*p == '"')
					p++;
				cTerm = '"';
				p2 = strchr (p, cTerm);
			}
			else 
			{
				cTerm = ' ';
				p2 = NULL;
			}

			if (p2) 
				*p2 = '\0';

			// import the exported key or group file ...
			if (PKFileIsForImporting (p, &uType, &format))
			{
				if (uType == PK_EXPORTEDGROUPFILE)
				{
					PGPgmImportGroups (ppks->hGM, p);
					ppks->bGroupsVisible = FALSE;
					PostMessage (ppks->hwndMain, WM_COMMAND,
							MAKEWPARAM (IDM_VIEWGROUPS, 0), 0);
				}
				else
				{
					PGPNewFileSpecFromFullPath (g_context, p, &fileref);
					if (fileref) 
					{
						PGPImport (g_context, &keydbToAdd, 
								PGPOInputFile (g_context, fileref),
								PGPOInputFormat (g_context, format),
								PGPOLastOption (g_context));
						if (PGPKeyDBRefIsValid (keydbToAdd))
						{
							PGPCountKeys (PGPPeekKeyDBRootKeySet (keydbToAdd), 
									&iNumKeys);
							if (iNumKeys > 0) 
							{
								if (bAllowSelect) 
								{
									if (IsntPGPError (PGPclImportKeys (
										g_context, g_tlscontext, g_hwndMain, 
										PGPPeekKeyDBRootKeySet (keydbToAdd), 
										ppks->keydbMain, 
										kPGPclDefaultImportFlags)))
									{
										bImported = TRUE;
									}
								}
								else 
								{
									if (IsntPGPError (PGPclImportKeys (
										g_context, g_tlscontext, g_hwndMain, 
										PGPPeekKeyDBRootKeySet (keydbToAdd), 
										ppks->keydbMain, kPGPclNoImportDialog)))
									{
										bImported = TRUE;
									}
								}

								if (bImported)
								{
									PKKeyDBModified (ppks, PK_MOD_INDEX_0);
									PGPclKeyListReloadKeys (ppks->hKL, TRUE);
								}
							}
							PGPFreeKeyDB (keydbToAdd);
						}
						PGPFreeFileSpec (fileref);
					}
				}
			}

			// ... or create new window for it
			else
			{
				PKNewWindowForFile (g_hwndMain, ppks, FALSE, p);
			}

			if (p2)
				*p2 = cTerm;
		}

		if (cTerm == '"')
		{
			while (*p && (*p != cTerm)) 
				p++;

			if (*p) 
				p++;
		}
		else
		{
			while (*p) 

⌨️ 快捷键说明

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