📄 kmtree.c
字号:
bItalics = FALSE;
idx = KMDetermineCertIcon (Cert, &bItalics, &bX509);
if (bX509)
{
PGPGetSigPropertyBuffer (Cert,
kPGPSigPropX509LongName, sizeof(sz), sz, &size);
if (CertKey == NULL)
bItalics = TRUE;
}
else
{
if (CertKey) {
KMGetKeyName (CertKey, sz, sizeof(sz));
}
else {
bItalics = TRUE;
KMGetKeyIDFromCert (Cert, szID, sizeof(szID));
LoadString (g_hInst, IDS_UNAVAILABLECERT,
sz2, sizeof(sz2));
wsprintf (sz, sz2, szID);
}
}
if (bItalics) uState |= TLIS_ITALICS;
if (bForceNewAlloc) hTCert = NULL;
hTCert = sSetOneItem (pKM, FALSE, hTCert, hTUID, sz,
(HTLITEM)TLI_LAST, idx,
uState, (LPARAM)Cert);
KMSetCertUserVal (pKM, Cert, (long)hTCert);
// get and set treelist list data for this cert
sSetCertData (pKM, hTCert, Cert, idx);
PGPKeyIterNextUIDSig (KeyIter, &Cert);
}
PGPKeyIterNextUserID (KeyIter, &UserID);
}
// select and expand key, if appropriate
if (bExpandNew && bNew) {
tli.hItem = hTKey;
if (!bNewKeyExpanded) {
TreeList_Select (pKM->hWndTree, &tli, TRUE);
TreeList_Expand (pKM->hWndTree, &tli, TLE_EXPANDALL);
bNewKeyExpanded = TRUE;
}
else {
KMSetFocus (pKM, KMFocusedItem (pKM), TRUE);
TreeList_Expand (pKM->hWndTree, &tli, TLE_EXPANDALL);
}
}
return hTKey;
}
// _______________________________________________
//
// Scan entire keyring loading in any new data
//
// bReInsertExisting - is only used when reordering keys in window.
// This is set TRUE if the caller has already
// deleted the treelist but not deallocated the items.
// bExpandNew - causes new keys to be expanded
// bForceRealloc - forces reallocation of treelist items. Used after
// the caller has deleted the treelist and deallocated
// all the items.
BOOL
KMLoadKeyRingIntoTree (
PKEYMAN pKM,
BOOL bReInsertExisting,
BOOL bExpandNew,
BOOL bForceRealloc)
{
HCURSOR hCursorOld;
PGPKeyListRef KeyList;
PGPKeyIterRef KeyIter;
PGPKeyRef Key;
PGPKeyRef keyDef;
TL_TREEITEM tli;
HTLITEM hTPrevKey;
BOOL bFirst;
PGPBoolean bSecret, bRevoked, bExpired, bCanSign;
hTPrevKey = (HTLITEM)TLI_FIRST;
bFirst = TRUE;
if (pKM->KeySetDisp) {
hCursorOld = SetCursor (LoadCursor (NULL, IDC_WAIT));
PGPOrderKeySet (pKM->KeySetDisp, pKM->lKeyListSortField, &KeyList);
PGPNewKeyIter (KeyList, &KeyIter);
PGPKeyIterNext (KeyIter, &Key);
while (Key) {
hTPrevKey = sReloadKey (pKM, KeyIter, Key, bReInsertExisting,
bForceRealloc, bExpandNew, bFirst, hTPrevKey);
PGPKeyIterNext (KeyIter, &Key);
bFirst = FALSE;
}
PGPFreeKeyIter (KeyIter);
PGPFreeKeyList (KeyList);
if (pKM->bMainKeySet) {
PGPGetDefaultPrivateKey (pKM->KeySetMain, &keyDef);
if (keyDef) {
PGPGetKeyBoolean (keyDef, kPGPKeyPropIsSecret, &bSecret);
PGPGetKeyBoolean (keyDef, kPGPKeyPropIsRevoked, &bRevoked);
PGPGetKeyBoolean (keyDef, kPGPKeyPropIsExpired, &bExpired);
PGPGetKeyBoolean (keyDef, kPGPKeyPropCanSign, &bCanSign);
if (bSecret && bCanSign && !bRevoked && !bExpired) {
KMGetKeyUserVal (pKM, keyDef, (long*)&(tli.hItem));
if (tli.hItem) {
tli.state = TLIS_BOLD;
tli.stateMask = TLIS_BOLD;
tli.mask = TLIF_STATE;
TreeList_SetItem (pKM->hWndTree, &tli);
}
}
}
}
SetCursor (hCursorOld);
if (bExpandNew) {
tli.hItem = KMFocusedItem (pKM);
if (tli.hItem) TreeList_EnsureVisible (pKM->hWndTree, &tli);
}
}
return TRUE;
}
// _______________________________________________
//
// iterate entire keyset, deleting user value linked-list elements
BOOL
KMDeleteAllUserValues (PKEYMAN pKM)
{
PGPKeyListRef KeyList;
PGPKeyIterRef KeyIter;
PGPKeyRef Key;
PGPUserIDRef UserID;
PGPSigRef Cert;
if (!pKM) return FALSE;
if (!pKM->KeySetDisp) return FALSE;
PGPOrderKeySet (pKM->KeySetDisp, kPGPAnyOrdering, &KeyList);
PGPNewKeyIter (KeyList, &KeyIter);
PGPKeyIterNext (KeyIter, &Key);
while (Key) {
PGPKeyIterNextUserID (KeyIter, &UserID);
while (UserID) {
PGPKeyIterNextUIDSig (KeyIter, &Cert);
while (Cert) {
KMSetCertUserVal (pKM, Cert, 0);
PGPKeyIterNextUIDSig (KeyIter, &Cert);
}
KMSetUserIDUserVal (pKM, UserID, 0);
PGPKeyIterNextUserID (KeyIter, &UserID);
}
KMSetKeyUserVal (pKM, Key, 0);
PGPKeyIterNext (KeyIter, &Key);
}
PGPFreeKeyIter (KeyIter);
PGPFreeKeyList (KeyList);
return TRUE;
}
// _______________________________________________
//
// Insert single key into treelist
BOOL
KMUpdateKeyInTree (
PKEYMAN pKM,
PGPKeyRef Key,
BOOL bForceNew)
{
PGPKeyListRef KeyList;
PGPKeyIterRef KeyIter;
PGPKeyRef PrevKey;
PGPKeyRef DefaultKey;
TL_TREEITEM tli;
HTLITEM hTPrevKey;
HTLITEM hTFocused;
PGPBoolean bSecret, bRevoked, bExpired, bCanSign;
if (pKM->KeySetDisp) {
hTFocused = KMFocusedItem (pKM);
if (IsntPGPError (PGPclErrorBox (NULL, KMGetKeyUserVal (pKM, Key,
(long*)&(tli.hItem))))) {
if (bForceNew && tli.hItem) {
TreeList_DeleteItem (pKM->hWndTree, &tli);
KMSetKeyUserVal (pKM, Key, 0L);
}
PGPOrderKeySet (pKM->KeySetDisp,
pKM->lKeyListSortField, &KeyList);
PGPNewKeyIter (KeyList, &KeyIter);
PGPKeyIterSeek (KeyIter, Key);
PGPKeyIterPrev (KeyIter, &PrevKey);
PGPKeyIterSeek (KeyIter, Key);
hTPrevKey = (HTLITEM)TLI_FIRST;
if (PrevKey) {
if (IsntPGPError (PGPclErrorBox (NULL, KMGetKeyUserVal (pKM,
PrevKey, (long*)&(tli.hItem))))) {
hTPrevKey = tli.hItem;
}
}
sReloadKey (pKM, KeyIter, Key, FALSE, bForceNew, FALSE,
TRUE, hTPrevKey);
PGPFreeKeyIter (KeyIter);
PGPFreeKeyList (KeyList);
// only set default key if this is the main keyset
if (pKM->bMainKeySet) {
PGPGetDefaultPrivateKey (pKM->KeySetMain, &DefaultKey);
if (DefaultKey == Key) {
PGPGetKeyBoolean (Key, kPGPKeyPropIsSecret, &bSecret);
PGPGetKeyBoolean (Key, kPGPKeyPropIsRevoked, &bRevoked);
PGPGetKeyBoolean (Key, kPGPKeyPropIsExpired, &bExpired);
PGPGetKeyBoolean (Key, kPGPKeyPropCanSign, &bCanSign);
if (bSecret && bCanSign && !bRevoked && !bExpired) {
KMGetKeyUserVal (pKM,
DefaultKey, (long*)&(tli.hItem));
if (tli.hItem) {
tli.state = TLIS_BOLD;
tli.stateMask = TLIS_BOLD;
tli.mask = TLIF_STATE;
TreeList_SetItem (pKM->hWndTree, &tli);
}
}
}
}
// set selection appropriately
if (bForceNew)
KMGetKeyUserVal (pKM, Key, (long*)&(tli.hItem));
else
tli.hItem = hTFocused;
TreeList_Select (pKM->hWndTree, &tli, TRUE);
return TRUE;
}
}
return FALSE;
}
// _______________________________________________
//
// Set validity for a treelist item
static HTLITEM
sSetItemValidity (
PKEYMAN pKM,
HTLITEM hItem,
INT iValidity)
{
TL_LISTITEM tlL;
tlL.hItem = hItem;
tlL.iSubItem = 1;
tlL.mask = TLIF_DATAVALUE;
if (pKM->ulOptionFlags & KMF_NOVICEMODE) {
if (iValidity > KM_VALIDITY_COMPLETE)
tlL.lDataValue = IDX_AXIOMATIC;
else if (iValidity >= pKM->iValidityThreshold)
tlL.lDataValue = IDX_VALID;
else tlL.lDataValue = IDX_INVALID;
}
else tlL.lDataValue = iValidity;
hItem = (HTLITEM) TreeList_SetListItem (pKM->hWndTree, &tlL, FALSE);
return (hItem);
}
// _______________________________________________
//
// update validity values for all keys/userids
BOOL
KMUpdateAllValidities (PKEYMAN pKM)
{
HCURSOR hCursorOld;
HTLITEM hTKey, hTUID;
PGPKeyListRef keylist;
PGPKeyIterRef keyiter;
PGPKeyRef key;
PGPUserIDRef userid;
Boolean bAxiomatic;
UINT u;
if (pKM->KeySetDisp) {
hCursorOld = SetCursor (LoadCursor (NULL, IDC_WAIT));
PGPOrderKeySet (pKM->KeySetDisp, pKM->lKeyListSortField, &keylist);
PGPNewKeyIter (keylist, &keyiter);
PGPKeyIterNext (keyiter, &key);
// iterate through keys
while (key) {
KMGetKeyUserVal (pKM, key, (long*)&hTKey);
if (hTKey) {
// if axiomatic set trust and validity to out-of-range values
// in order to flag different graphical representation
PGPGetKeyBoolean (key, kPGPKeyPropIsAxiomatic, &bAxiomatic);
if (bAxiomatic)
u = KMConvertFromPGPValidity (kPGPValidity_Complete) + 1;
else {
if (IsPGPError (PGPclErrorBox (NULL,
PGPGetPrimaryUserIDValidity (key, &u)))) u = 0;
else
u = KMConvertFromPGPValidity (u);
}
sSetItemValidity (pKM, hTKey, u);
}
// iterate through userids
PGPKeyIterNextUserID (keyiter, &userid);
while (userid) {
KMGetUserIDUserVal (pKM, userid, (long*)&hTUID);
if (hTUID) {
PGPGetUserIDNumber (userid, kPGPUserIDPropValidity, &u);
u = KMConvertFromPGPValidity (u);
sSetItemValidity (pKM, hTUID, u);
}
PGPKeyIterNextUserID (keyiter, &userid);
}
PGPKeyIterNext (keyiter, &key);
}
PGPFreeKeyIter (keyiter);
PGPFreeKeyList (keylist);
SetCursor (hCursorOld);
return TRUE;
}
// error on open key rings
else return FALSE;
}
// _______________________________________________
//
// Expand a single item
// routine called as a
// callback function from the TreeList control to
// expand a single item.
//
// lptli = pointer to TreeList item to expand
static BOOL CALLBACK
sExpandSingleItem (TL_TREEITEM* lptli, LPARAM lParam)
{
EXPANDCOLLAPSESTRUCT* pecs = (EXPANDCOLLAPSESTRUCT*)lParam;
TreeList_Expand (pecs->hWndTree, lptli, TLE_EXPANDALL);
return TRUE;
}
// _______________________________________________
//
// Expand the selected items
BOOL KMExpandSelected (PKEYMAN pKM) {
EXPANDCOLLAPSESTRUCT ecs;
ecs.lpfnCallback = sExpandSingleItem;
ecs.hWndTree = pKM->hWndTree;
TreeList_IterateSelected (pKM->hWndTree, &ecs);
InvalidateRect (pKM->hWndTree, NULL, TRUE);
return TRUE;
}
// _______________________________________________
//
// Collapse a single item
// routine called as a
// callback function from the TreeList control to
// collapse a single item.
//
// lptli = pointer to TreeList item to collapse
static BOOL CALLBACK
sCollapseSingleItem (TL_TREEITEM* lptli, LPARAM lParam)
{
EXPANDCOLLAPSESTRUCT* pecs = (EXPANDCOLLAPSESTRUCT*)lParam;
TreeList_Expand (pecs->hWndTree, lptli, TLE_COLLAPSEALL);
return TRUE;
}
// _______________________________________________
//
// Collapse the selected items
BOOL KMCollapseSelected (PKEYMAN pKM) {
EXPANDCOLLAPSESTRUCT ecs;
ecs.lpfnCallback = sCollapseSingleItem;
ecs.hWndTree = pKM->hWndTree;
TreeList_IterateSelected (pKM->hWndTree, &ecs);
InvalidateRect (pKM->hWndTree, NULL, TRUE);
return TRUE;
}
// _______________________________________________
//
// Cleanup treelist
PGPError PGPkmExport
PGPkmDestroyKeyManager (
HKEYMAN hKM,
BOOL bSaveColumnInfo)
{
PKEYMAN pKM = (PKEYMAN)hKM;
if (!hKM) return kPGPError_BadParams;
KMDeleteAllKeyProperties (pKM, TRUE);
KMDeleteAllUserValues (pKM);
CloseHandle (pKM->hRequestMutex);
CloseHandle (pKM->hAccessMutex);
RevokeDragDrop (pKM->hWndTree);
KMReleaseDropTarget (pKM->pDropTarget);
CoLockObjectExternal ((IUnknown*)pKM->pDropTarget, FALSE, TRUE);
DragAcceptFiles (pKM->hWndTree, FALSE);
if (bSaveColumnInfo) KMSetColumnPreferences (pKM);
SendMessage (pKM->hWndTree, WM_CLOSE, 0, 0);
ImageList_Destroy (pKM->hIml);
return kPGPError_NoErr;
}
// _______________________________________________
//
// Load keyset into treelist
PGPError PGPkmExport
PGPkmLoadKeySet (
HKEYMAN hKeyMan,
PGPKeySetRef KeySetDisp,
PGPKeySetRef KeySetMain)
{
PKEYMAN pKM = (PKEYMAN)hKeyMan;
if (!pKM) return kPGPError_BadParams;
if (pKM->KeySetDisp) {
KMDeleteAllKeyProperties (pKM, TRUE);
KMDeleteAllUserValues (pKM);
KMSetFocus (pKM, NULL, FALSE);
pKM->KeySetDisp = NULL;
pKM->KeySetMain = NULL;
TreeList_DeleteTree (pKM->hWndTree, TRUE);
}
pKM->KeySetDisp = KeySetDisp;
KMGetColumnPreferences (pKM);
KMAddColumns (pKM);
if (KeySetDisp) {
if (KeySetMain) {
pKM->KeySetMain = KeySetMain;
pKM->bMainKeySet = TRUE;
}
else {
pKM->KeySetMain = KeySetDisp;
pKM->bMainKeySet = FALSE;
}
KMLoadKeyRingIntoTree (pKM, FALSE, FALSE, TRUE);
KMEnableDropTarget (pKM->pDropTarget,
!(pKM->ulOptionFlags & KMF_READONLY) &&
(pKM->ulOptionFlags & KMF_ENABLEDROPIN));
}
else {
pKM->bMainKeySet = TRUE;
}
InvalidateRect (pKM->hWndTree, NULL, TRUE);
UpdateWindow (pKM->hWndTree);
return kPGPError_NoErr;
}
// _______________________________________________
//
// Load keyset into treelist
PGPError PGPkmExport
PGPkmReLoadKeySet (HKEYMAN hKeyMan, BOOL bExpandNew)
{
PKEYMAN pKM = (PKEYMAN)hKeyMan;
if (!pKM) return kPGPError_BadParams;
if (!pKM->KeySetDisp) return kPGPError_BadParams;
KMLoadKeyRingIntoTree (pKM, FALSE, bExpandNew, FALSE);
InvalidateRect (pKM->hWndTree, NULL, TRUE);
UpdateWindow (pKM->hWndTree);
return kPGPError_NoErr;
}
// _______________________________________________
//
// Select specified key
VOID
KMSelectKey (PKEYMAN pKM, PGPKeyRef key, BOOL bDeselect)
{
TL_TREEITEM tli;
KMGetKeyUserVal (pKM, key, (long*)&(tli.hItem));
if (tli.hItem) {
TreeList_Select (pKM->hWndTree, &tli, bDeselect);
}
}
// _______________________________________________
//
// Select specified key
PGPError PGPkmExport
PGPkmSelectKey (HKEYMAN hKeyMan, PGPKeyRef key, BOOL bDeselect)
{
PKEYMAN pKM = (PKEYMAN)hKeyMan;
KMSelectKey (pKM, key, bDeselect);
return kPGPError_NoErr;
}
// _______________________________________________
//
// Get a keyset of all selected keys
PGPError PGPkmExport
PGPkmGetSelectedKeys (HKEYMAN hKeyMan, PGPKeySetRef* pkeysetSelected)
{
PKEYMAN pKM = (PKEYMAN)hKeyMan;
return (KMGetSelectedKeys (pKM, pkeysetSelected, NULL));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -