📄 pgprecipientdialogcommon.cpp
字号:
while(*p && *p != '>')
p++;
if(*p == '>')
*p = '\0';
}
}
static void
pgpFreeServerList(
PGPContextRef context,
PGPKeyServerSpec *inList,
PGPUInt32 serverCount)
{
if( IsntNull( inList ) )
{
PGPUInt32 specIndex;
for( specIndex = 0; specIndex < serverCount; specIndex++)
{
PGPKeyServerSpec *spec = &(inList[specIndex]);
if( IsntNull( spec->serverName ) )
pgpContextMemFree( context, (char *) spec->serverName );
if( IsntNull( spec->serverDomain ) )
pgpContextMemFree( context, (char *) spec->serverDomain );
if( PGPKeyServerRefIsValid( spec->server ) )
PGPFreeKeyServer( spec->server );
}
PGPFreeData( (PGPKeyServerSpec *) inList );
}
}
static PGPError
pgpCopyServersMatchingDomain(
PGPContextRef context,
const PGPKeyServerSpec *inList,
PGPUInt32 serverCount,
const char *domain,
PGPKeyServerSpec **outList,
PGPUInt32 *outServerCount)
{
PGPError err = kPGPError_NoErr;
PGPUInt32 specIndex, loopPass;
PGPBoolean useThisServer;
*outList = (PGPKeyServerSpec *) PGPNewData(PGPPeekContextMemoryMgr(context),
serverCount * sizeof(PGPKeyServerSpec),
kPGPMemoryMgrFlags_Clear);
if( IsntNull( *outList ) )
{
const PGPKeyServerSpec *srcSpec;
PGPKeyServerSpec *destSpec;
*outServerCount = 0;
for(loopPass=1; loopPass<=2; loopPass++)
{
for(specIndex = 0; specIndex < serverCount; specIndex++)
{
useThisServer = FALSE;
srcSpec = &(inList[specIndex]);
if (loopPass == 1)
{
/* First Pass: only servers which match domain */
if ( IsntNull( srcSpec->serverDomain ) )
{
if ( srcSpec->serverDomain[0] != '\0' )
{
if (!pgpCompareStringsIgnoreCase(
srcSpec->serverDomain, domain) )
{
useThisServer = TRUE;
}
}
}
}
else
{
/* Second Pass: add on any "Any Domain"
(i.e. domain-less) servers */
if ( IsNull( srcSpec->serverDomain ) )
useThisServer = TRUE;
else if ( srcSpec->serverDomain[0] == '\0' )
useThisServer = TRUE;
}
if (useThisServer)
{
destSpec = &((*outList)[*outServerCount]);
pgpCopyMemory(srcSpec, destSpec, sizeof(PGPKeyServerSpec));
destSpec->serverName = NULL;
destSpec->serverDomain = NULL;
if( PGPKeyServerRefIsValid( destSpec->server ) )
{
PGPIncKeyServerRefCount( destSpec->server );
}
if( IsntNull( srcSpec->serverName ) )
{
destSpec->serverName = pgpAllocCString( context,
srcSpec->serverName );
if( IsNull( destSpec->serverName ) )
err = kPGPError_OutOfMemory;
}
if( IsntNull( srcSpec->serverDomain ) )
{
destSpec->serverDomain = pgpAllocCString( context,
srcSpec->serverDomain );
if( IsNull( destSpec->serverDomain ) )
err = kPGPError_OutOfMemory;
}
(*outServerCount)++;
if( IsPGPError( err ) )
break;
}
}
}
}
else
{
err = kPGPError_OutOfMemory;
}
if( IsPGPError( err ) )
{
pgpFreeServerList( context, *outList, *outServerCount );
*outList = NULL;
*outServerCount = 0;
}
return( err );
}
static PGPError
pgpUpdateMissingRecipients(
void *hwndParent,
PGPRecipientsList *recipients,
PGPBoolean *haveNewKeys)
{
PGPError err = kPGPError_NoErr;
PGPRecipientUser *curUser;
PGPKeyDBRef searchResults;
PGPContextRef context;
(void) hwndParent;
context = recipients->context;
*haveNewKeys = FALSE;
err = PGPNewKeyDB( context, &searchResults );
if( IsntPGPError( err ) )
{
/* Search for missing recipients */
curUser = recipients->missingRecipients;
while( IsntNull( curUser ) && IsntPGPError( err ) )
{
if( curUser->location == kPGPRecipientUserLocation_RecipientList )
{
PGPFilterRef filter = kInvalidPGPFilterRef;
PGPKeyServerSpec *serverList;
PGPUInt32 serverCount;
if( curUser->missingUser.type == kPGPRecipientSpecType_UserID )
{
const char *userID = PGPGetRecipientUserNamePtr( curUser );
char *domain;
domain = (char *) PGPNewData(PGPPeekContextMemoryMgr(context),
strlen(userID) + 1, 0);
pgpFindEmailDomain(userID, domain);
pgpCopyServersMatchingDomain(context,
recipients->serverList, recipients->serverCount,
domain, &serverList, &serverCount);
PGPFreeData(domain);
if ( !serverCount )
{
pgpFreeServerList( context, serverList, serverCount );
serverList = (PGPKeyServerSpec *) recipients->serverList;
serverCount = recipients->serverCount;
}
#if PGP_WIN32
{
char szUTF8[kPGPMaxUserIDSize];
PGPUInt32 u;
lstrcpy (szUTF8, userID);
if (pgpIsntUTF8String (szUTF8, lstrlen(szUTF8)))
{
err = pgpLocalStringToUTF8(0, GetACP(),
userID, strlen( userID ),
szUTF8, sizeof(szUTF8), &u);
}
if (IsntPGPError (err))
{
err = PGPNewKeyDBObjDataFilter( context,
kPGPUserIDProperty_Name,
szUTF8, strlen( szUTF8 ),
kPGPMatchCriterion_SubString,
&filter );
}
}
#else
err = PGPNewKeyDBObjDataFilter( context,
kPGPUserIDProperty_Name,
userID, strlen( userID ),
kPGPMatchCriterion_SubString,
&filter );
#endif
}
else if( curUser->missingUser.type ==
kPGPRecipientSpecType_KeyID )
{
serverList = (PGPKeyServerSpec *) recipients->serverList;
serverCount = recipients->serverCount;
err = PGPNewKeyDBObjDataFilter( context,
kPGPKeyProperty_KeyID,
curUser->missingUser.keyID,
sizeof( *curUser->missingUser.keyID ),
kPGPMatchCriterion_Equal, &filter );
}
else
{
pgpDebugMsg( "pgpUpdateMissingRecipients(): Unknown "
"missing recipient type" );
}
if( IsntPGPError( err ) &&
PGPFilterRefIsValid( filter ) )
{
PGPKeyDBRef tempDB = kInvalidPGPKeyDBRef;
err = PGPSearchKeyServerDialog( context,
serverCount, serverList,
recipients->tlsContext, FALSE, &tempDB,
PGPOUIKeyServerSearchFilter( context, filter ),
#if PGP_WIN32
PGPOUIParentWindowHandle(context, (HWND) hwndParent),
#endif
PGPOLastOption( context ) );
if( IsntPGPError( err ) && PGPKeyDBRefIsValid( tempDB ) )
{
PGPUInt32 numKeys;
err = PGPCountKeysInKeyDB( tempDB, &numKeys );
if( IsntPGPError( err ) && numKeys > 0 )
{
PGPKeySetRef tempDBKeySet;
*haveNewKeys = TRUE;
err = PGPNewKeySet( tempDB, &tempDBKeySet );
if( IsntPGPError( err ) )
{
err = PGPCopyKeys( tempDBKeySet, searchResults, NULL );
PGPFreeKeySet( tempDBKeySet );
}
}
PGPFreeKeyDB( tempDB );
}
PGPFreeFilter( filter );
}
if ( serverList != recipients->serverList)
pgpFreeServerList( context, serverList, serverCount );
}
curUser = curUser->nextUser;
}
/* Search for incomplete groups */
curUser = recipients->groups;
while( IsntNull( curUser ) && IsntPGPError( err ) )
{
if( curUser->location == kPGPRecipientUserLocation_RecipientList &&
curUser->groupInfo.numMissingKeys > 0 )
{
PGPUInt32 itemIndex;
for( itemIndex = 0; itemIndex < curUser->groupInfo.numKeys;
++itemIndex )
{
PGPGroupItem item;
err = PGPGetIndGroupItem( recipients->groupSet,
curUser->groupInfo.groupID, itemIndex, &item );
if( IsntPGPError( err ) && item.userValue == 0 )
{
PGPKeyDBRef tempDB = kInvalidPGPKeyDBRef;
err = PGPSearchKeyServerDialog( context,
recipients->serverCount,
recipients->serverList,
recipients->tlsContext, FALSE, &tempDB,
PGPOUIKeyServerSearchKeyIDList( context,
1, &item.u.keyID ),
#if PGP_WIN32
PGPOUIParentWindowHandle(context,
(HWND) hwndParent),
#endif
PGPOLastOption( context ) );
if( IsntPGPError( err ) && PGPKeyDBRefIsValid( tempDB ) )
{
PGPUInt32 numKeys;
err = PGPCountKeysInKeyDB( tempDB, &numKeys );
if( IsntPGPError( err ) && numKeys > 0 )
{
PGPKeySetRef tempDBKeySet;
*haveNewKeys = TRUE;
err = PGPNewKeySet( tempDB, &tempDBKeySet );
if( IsntPGPError( err ) )
{
err = PGPCopyKeys( tempDBKeySet, searchResults, NULL );
PGPFreeKeySet( tempDBKeySet );
}
}
PGPFreeKeyDB( tempDB );
}
}
if( IsPGPError( err ) )
break;
}
}
curUser = curUser->nextUser;
}
// We have keys, now match with users
if( IsntPGPError( err ) && *haveNewKeys )
{
err = AddNewKeys( recipients, searchResults );
// *************************** added by wjb
// Search for missing ADKs of missing keys recently added
// to groups. We have to do this since the keys aren't
// actually put into the recipient list, since it's a
// group. Well, everything was elegant until this...
if(IsntPGPError(err))
{
PGPContextRef context;
PGPKeyDBRef groupADKresults;
PGPRecipientKey *curKey;
PGPUInt32 arrIndex;
PGPRecipientKeyARRInfo *arrInfo;
PGPBoolean groupADKNewKeys;
groupADKNewKeys=FALSE;
context=recipients->context;
err = PGPNewKeyDB( context, &groupADKresults );
if(IsntPGPError(err))
{
curUser = recipients->groups;
while( IsntNull( curUser ) && IsntPGPError( err ) )
{
if(curUser->location == kPGPRecipientUserLocation_RecipientList)
{
PGPUInt32 itemIndex;
for( itemIndex = 0; itemIndex < curUser->groupInfo.numKeys;
++itemIndex )
{
PGPGroupItem item;
err = PGPGetIndGroupItem( recipients->groupSet,
curUser->groupInfo.groupID, itemIndex, &item );
pgpAssertNoErr( err );
if( IsntPGPError( err ) )
{
// The key must exist, otherwise it will
// be searched for later?
if(item.userValue!=NULL)
{
curKey = (PGPRecipientKey *) item.userValue;
for( arrIndex = 0; arrIndex < curKey->numARRKeys; arrIndex++ )
{
arrInfo = &(curKey->arrKeys[arrIndex]);
if(arrInfo->keyMissing)
{
FindARR(hwndParent,
recipients,
groupADKresults,
&(arrInfo->keyID),
&groupADKNewKeys);
}
}
}
}
}
}
curUser = curUser->nextUser;
}
// We have keys, now match with users
if( IsntPGPError( err ) && groupADKNewKeys )
{
err = AddNewKeys( recipients, groupADKresults );
}
PGPFreeKeyDB( groupADKresults );
}
}
// *************************** end added by wjb
curUser = recipients->missingRecipients;
while( IsntNull( curUser ) && IsntPGPError( err ) )
{
if( UserIsVisible( curUser ) )
{
if( curUser->missingUser.type ==
kPGPRecipientSpecType_UserID )
{
PGPUInt32 numMatchedUsers;
PGPRecipientUser **matchedUserList;
err = FindUsersFromUserID( recipients,
PGPGetRecipientUserNamePtr( curUser ),
FALSE, &numMatchedUsers,
&matchedUserList );
if( IsntPGPError( err ) )
{
if( numMatchedUsers != 0 )
{
PGPBoolean movedARRs;
PGPUInt32 numMovedUsers = 0;
// See if there are any ADKs that
// can be found
PGPMoveRecipientsARRPrefetch(
hwndParent,
recipients,
numMatchedUsers,
matchedUserList);
err = PGPMoveRecipients( recipients,
kPGPRecipientUserLocation_RecipientList,
numMatchedUsers, matchedUserList,
&numMovedUsers, &movedARRs );
if( IsntPGPError( err ) )
{
if( numMatchedUsers != 1 )
{
PGPUInt32 userIndex;
for( userIndex = 0;
userIndex < numMatchedUsers;
++userIndex )
{
matchedUserList[userIndex]->
multipleMatch = TRUE;
}
}
curUser->location =
kPGPRecipientUserLocation_Hidden;
}
}
PGPFreeData( matchedUserList );
}
}
else if( curUser->missingUser.type ==
kPGPRecipientSpecType_KeyID )
{
PGPRecipientUser *matchedUser;
err = FindUserFromKeyID( recipients,
curUser->missingUser.keyID,
curUser->missingUser.algorithm,
&matchedUser );
if( IsntPGPError( err ) && IsntNull( matchedUser ) )
{
PGPBoolean movedARRs;
PGPUInt32 numMovedUsers = 0;
// See if there are any ADKs that
// can be found
PGPMoveRecipientsARRPrefetch(
hwndParent,
recipients,
1,
&matchedUser);
err = PGPMoveRecipients( recipients,
kPGPRecipientUserLocation_RecipientList,
1, &matchedUser, &numMovedUsers,
&movedARRs );
if( IsntPGPError( err ) )
{
curUser->location =
kPGPRecipientUserLocation_Hidden;
}
}
}
else
{
pgpDebugMsg( "Unknown missing recipient type" );
}
}
curUser = curUser->nextUser;
}
}
PGPFreeKeyDB( searchResults );
}
return( err );
}
PGPError
PGPUpdateMissingRecipients(
void *hwndParent,
PGPRecipientsList *recipients,
PGPBoolean *haveNewKeys)
{
PGPError err = kPGPError_NoErr;
PGPValidatePtr( recipients );
PGPValidatePtr( haveNewKeys );
*haveNewKeys = FALSE;
if( IsntNull( recipients->serverList ) &&
recipients->serverCount != 0 )
{
err = pgpUpdateMissingRecipients( hwndParent, recipients, h
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -