📄 pgprecipientdialogcommon.cpp
字号:
if( curRecipient->locked )
++key->primaryUser->lockRefCount;
}
}
else
{
err = AddMissingRecipient( recipients, curRecipient );
}
break;
}
case kPGPRecipientSpecType_UserID:
{
PGPUInt32 numMovedUsers = 0;
PGPUInt32 numMatchedUsers;
PGPRecipientUser **matchedUserList;
err = FindUsersFromUserID( recipients,
curRecipient->u.userIDStr, TRUE, &numMatchedUsers,
&matchedUserList );
if( IsntPGPError( err ) )
{
if( numMatchedUsers != 0 )
{
err = PGPMoveRecipients( recipients,
kPGPRecipientUserLocation_RecipientList,
numMatchedUsers, matchedUserList,
&numMovedUsers, &movedAnARR );
if( numMatchedUsers == 1 )
{
if( curRecipient->locked )
++matchedUserList[0]->lockRefCount;
}
else
{
PGPUInt32 userIndex;
for( userIndex = 0; userIndex < numMatchedUsers;
++userIndex )
{
matchedUserList[userIndex]->multipleMatch =
TRUE;
}
}
}
else
{
err = AddMissingRecipient( recipients, curRecipient );
}
PGPFreeData( matchedUserList );
}
break;
}
default:
pgpDebugMsg(
"MoveDefaultRecipients(): Unknown PGPRecipientSpecType" );
err = kPGPError_BadParams;
break;
}
if( IsPGPError( err ) )
break;
if( movedAnARR )
*movedARRs = TRUE;
}
return( err );
}
const char *
PGPGetRecipientUserNamePtr(
const PGPRecipientUser *user)
{
pgpAssert( IsntNull( user ) );
return( &user->recipients->nameList[user->nameOffset] );
}
void
PGPGetRecipientUserName(
const PGPRecipientUser *user,
char name[256])
{
pgpAssert( IsntNull( user ) );
pgpAssert( IsntNull( name ) );
strcpy( name, PGPGetRecipientUserNamePtr( user ) );
}
PGPError
PGPBuildRecipientsList(
void * hwndParent,
PGPContextRef context,
PGPKeySetRef allKeys,
PGPGroupSetRef groupSet,
PGPUInt32 numDefaultRecipients,
const PGPRecipientSpec *defaultRecipients,
PGPUInt32 serverCount,
const PGPKeyServerSpec *serverList,
PGPtlsContextRef tlsContext,
PGPBoolean syncUnknownKeys,
PGPAdditionalRecipientRequestEnforcement arrEnforcement,
PGPRecipientEventHandlerProcPtr eventHandler,
PGPUserValue eventUserValue,
PGPRecipientsList *recipients,
PGPBoolean *haveDefaultARRs)
{
PGPError err = kPGPError_NoErr;
pgpAssert( PGPContextRefIsValid( context ) );
pgpAssert( PGPKeySetRefIsValid( allKeys ) );
pgpAssert( IsntNull( recipients ) );
pgpClearMemory( recipients, sizeof( *recipients ) );
recipients->context = context;
recipients->memoryMgr = PGPGetContextMemoryMgr( context );
recipients->arrEnforcement = arrEnforcement;
recipients->eventHandler = eventHandler;
recipients->eventUserValue = eventUserValue;
recipients->serverList = serverList;
recipients->serverCount = serverCount;
recipients->tlsContext = tlsContext;
*haveDefaultARRs = FALSE;
err = AddKeySet( recipients, allKeys );
if( IsntPGPError( err ) && PGPGroupSetRefIsValid( groupSet ) )
{
err = AddGroupSet( context, recipients, groupSet );
}
if( IsntPGPError( err ) )
{
err = UpdateDynamicRecipientValues( recipients );
}
if( IsntPGPError( err ) && numDefaultRecipients != 0 )
{
err = MoveDefaultRecipients( recipients, numDefaultRecipients,
defaultRecipients, haveDefaultARRs );
}
if( IsntPGPError( err ) && syncUnknownKeys )
{
PGPBoolean haveNewKeys;
err = PGPUpdateMissingRecipients( hwndParent, recipients,
&haveNewKeys );
}
return( err );
}
void
PGPDisposeRecipientsList(PGPRecipientsList *recipients)
{
PGPRecipientKeyList *curKeyList;
PGPRecipientUserList *curUserList;
PGPRecipientKey *curKey;
pgpAssert( IsntNull( recipients ) );
pgpAssert( PGPContextRefIsValid( recipients->context ) );
pgpAssert( PGPMemoryMgrRefIsValid( recipients->memoryMgr ) );
curKey = recipients->keys;
while( IsntNull( curKey ) )
{
FreeKey( curKey );
curKey = curKey->nextKey;
}
curKeyList = recipients->keyLists;
while( IsntNull( curKeyList ) )
{
PGPRecipientKeyList *nextKeyList;
nextKeyList = curKeyList->nextKeyList;
PGPFreeData( curKeyList );
curKeyList = nextKeyList;
}
curUserList = recipients->userLists;
while( IsntNull( curUserList ) )
{
PGPRecipientUserList *nextUserList;
nextUserList = curUserList->nextUserList;
PGPFreeData( curUserList );
curUserList = nextUserList;
}
if( IsntNull( recipients->nameList ) )
PGPFreeData( recipients->nameList );
if( PGPGroupSetRefIsValid( recipients->groupSet ) )
PGPFreeGroupSet( recipients->groupSet );
pgpClearMemory( recipients, sizeof( *recipients ) );
}
static PGPError
SendUserEvent(
PGPRecipientsList *recipients,
PGPRecipientEventType eventType,
PGPRecipientUser *user)
{
PGPError err = kPGPError_NoErr;
if( IsntNull( recipients->eventHandler ) )
{
PGPRecipientEvent event;
pgpClearMemory( &event, sizeof( event ) );
event.type = eventType;
event.user = user;
err = (*recipients->eventHandler)( recipients, &event,
recipients->eventUserValue );
}
return( err );
}
static PGPBoolean
MarkKeyARRsForUserToRecipientMove(
PGPRecipientsList *recipients,
PGPRecipientKey *key,
PGPUInt32 markValue,
PGPBoolean *markedARRs,
PGPBoolean *missingARRs)
{
PGPBoolean moveUser;
pgpAssert( recipients->arrEnforcement != kPGPARREnforcement_None );
moveUser = TRUE;
*missingARRs = FALSE;
*markedARRs = FALSE;
if( key->numARRKeys != 0 )
{
PGPBoolean markARRs = TRUE;
if( key->haveMissingARRs )
{
*missingARRs = TRUE;
/*
** In the strict case, the user cannot be moved because an ARR
** was not found. In the warn case, we move what we can.
*/
if( recipients->arrEnforcement == kPGPARREnforcement_Strict )
{
moveUser = FALSE;
markARRs = FALSE;
}
}
if( markARRs )
{
PGPUInt32 arrIndex;
for( arrIndex = 0; arrIndex < key->numARRKeys; arrIndex++ )
{
PGPRecipientKeyARRInfo *arrInfo;
arrInfo = &key->arrKeys[arrIndex];
if( IsntNull( arrInfo->key ) )
{
PGPRecipientUser *user = arrInfo->key->primaryUser;
pgpAssert( arrInfo->key->isVisible );
++user->userInfo.arrRefCount;
user->markValue = markValue;
*markedARRs = TRUE;
if( IsMandatoryARRClass( arrInfo->arrClass ) )
{
++user->userInfo.enforcedARRRefCount;
if( recipients->arrEnforcement ==
kPGPARREnforcement_Strict)
{
++user->lockRefCount;
}
}
}
}
}
}
return( moveUser );
}
static void
MarkKeyARRsForRecipientToUserMove(
PGPRecipientsList *recipients,
PGPRecipientKey *key,
PGPUInt32 markValue)
{
(void) recipients;
pgpAssert( recipients->arrEnforcement != kPGPARREnforcement_None );
if( key->numARRKeys != 0 )
{
PGPUInt32 arrIndex;
for( arrIndex = 0; arrIndex < key->numARRKeys; arrIndex++ )
{
PGPRecipientKeyARRInfo *arrInfo;
arrInfo = &key->arrKeys[arrIndex];
if( IsntNull( arrInfo->key ) )
{
PGPRecipientKey *arrKey = arrInfo->key;
PGPRecipientUser *arrUser = arrKey->primaryUser;
pgpAssert( arrKey->isVisible );
pgpAssert( arrUser->userInfo.arrRefCount != 0 );
if( IsMandatoryARRClass( arrInfo->arrClass ) )
{
--arrUser->userInfo.enforcedARRRefCount;
if( recipients->arrEnforcement ==
kPGPARREnforcement_Strict)
{
--arrUser->lockRefCount;
}
}
--arrUser->userInfo.arrRefCount;
if( arrUser->userInfo.arrRefCount == 0 )
{
if( ! arrUser->movedManually )
{
arrUser->markValue = markValue;
}
}
}
}
}
}
static PGPBoolean
MarkGroupARRsForUserToRecipientMove(
PGPRecipientsList *recipients,
PGPRecipientUser *group,
PGPUInt32 markValue,
PGPBoolean *markedARRs,
PGPBoolean *missingARRs)
{
PGPBoolean moveGroup;
pgpAssert( recipients->arrEnforcement != kPGPARREnforcement_None );
pgpAssert( group->kind == kPGPRecipientUserKind_Group );
moveGroup = TRUE;
*missingARRs = FALSE;
*markedARRs = FALSE;
if( group->groupInfo.numARRKeys != 0 )
{
PGPBoolean markARRs = TRUE;
if( group->groupInfo.haveMissingARRs )
{
*missingARRs = TRUE;
/*
** In the strict case, the group cannot be moved because an ARR
** was not found. In the warn case, we move what we can.
*/
if( recipients->arrEnforcement == kPGPARREnforcement_Strict )
{
moveGroup = FALSE;
markARRs = FALSE;
}
}
if( markARRs )
{
PGPUInt32 groupItemIndex;
for( groupItemIndex = 0;
groupItemIndex < group->groupInfo.numKeys;
++groupItemIndex )
{
PGPGroupItem item;
PGPError err;
err = PGPGetIndGroupItem( recipients->groupSet,
group->groupInfo.groupID, groupItemIndex, &item );
pgpAssertNoErr( err );
if( IsntPGPError( err ) )
{
PGPRecipientKey *key = NULL;
key = (PGPRecipientKey *) item.userValue;
if( IsntNull( key ) )
{
PGPBoolean keyMissingARRs;
(void) MarkKeyARRsForUserToRecipientMove(
recipients,
key, markValue, markedARRs,
&keyMissingARRs );
if( keyMissingARRs )
*missingARRs = TRUE;
}
}
}
}
}
return( moveGroup );
}
static void
MarkGroupARRsForRecipientToUserMove(
PGPRecipientsList *recipients,
PGPRecipientUser *group,
PGPUInt32 markValue)
{
pgpAssert( recipients->arrEnforcement != kPGPARREnforcement_None );
pgpAssert( group->kind == kPGPRecipientUserKind_Group );
if( group->groupInfo.numARRKeys != 0 )
{
PGPUInt32 groupItemIndex;
for( groupItemIndex = 0; groupItemIndex < group->groupInfo.numKeys;
++groupItemIndex )
{
PGPGroupItem item;
PGPError err;
err = PGPGetIndGroupItem( recipients->groupSet,
group->groupInfo.groupID, groupItemIndex, &item );
pgpAssertNoErr( err );
if( IsntPGPError( err ) )
{
PGPRecipientKey *key = NULL;
key = (PGPRecipientKey *) item.userValue;
if( IsntNull( key ) )
{
(void) MarkKeyARRsForRecipientToUserMove( recipients,
key, markValue );
}
}
}
}
}
PGPError
PGPMoveRecipients(
PGPRecipientsList *recipients,
PGPRecipientUserLocation destinationList,
PGPUInt32 numUsers,
PGPRecipientUser **userList,
PGPUInt32 *numMovedUsers,
PGPBoolean *movedARRs)
{
PGPError err = kPGPError_NoErr;
PGPUInt32 userIndex;
PGPUInt32 markValue;
PGPRecipientKey *curKey;
PGPRecipientUser *curUser;
pgpAssert( destinationList == kPGPRecipientUserLocation_UserList ||
destinationList == kPGPRecipientUserLocation_RecipientList );
pgpAssert( numUsers > 0 );
pgpAssert( IsntNull( userList ) );
pgpAssert( IsntNull( numMovedUsers ) );
*numMovedUsers = 0;
*movedARRs = FALSE;
markValue = GetNextMarkValue();
/* First pass. Mark items to move and skip/remove invalid items */
for( userIndex = 0; userIndex < numUsers; userIndex++ )
{
curUser = userList[userIndex];
pgpAssert( UserIsVisible( curUser ) );
pgpAssert( curUser->location != destinationList );
if( curUser->lockRefCount > 0 )
{
pgpAssert(
curUser->location == kPGPRecipientUserLocation_RecipientList );
}
else if( curUser->kind == kPGPRecipientUserKind_MissingRecipient )
{
pgpAssert(
curUser->location == kPGPRecipientUserLocation_RecipientList );
/*
** Missing recipients are never allowed in the user list.
** Remove from view
*/
curUser->location = kPGPRecipientUserLocation_Hidden;
*numMovedUsers += 1;
}
else
{
PGPBoolean moveUser = TRUE;
if( destinationList == kPGPRecipientUserLocation_RecipientList )
{
PGPBoolean missingARRs = FALSE;
PGPBoolean markedARRs = FALSE;
if( recipients->arrEnforcement != kPGPARREnforcement_None )
{
if( curUser->kind == kPGPRecipientUserKind_Key )
{
moveUser = MarkKeyARRsForUserToRecipientMove(
recipients, curUser->userInfo.key,
markValue, &markedARRs, &missingARRs );
}
else
{
pgpAssert( curUser->kind ==
kPGPRecipientUserKind_Group );
moveUser = MarkGroupARRsForUserToRecipientMove(
recipients, curUser,
markValue, &markedARRs, &missingARRs );
}
}
if( moveUser )
{
curUser->markValue = markValue;
curUser->movedManually = TRUE;
*numMovedUsers += 1;
if( markedARRs )
*movedARRs = TRUE;
if( missingARRs )
{
err = SendUserEvent( recipients,
kPGPRecipientEvent_MoveUserWarningEvent,
curUser );
}
}
else
{
pgpAssert( ! markedARRs );
err = SendUserEvent( recipients,
kPGPRecipientEvent_MoveUserFailedEvent,
curUser );
}
}
else
{
if( recipients->arrEnforcement != kPGPARREnforcement_None )
{
if( curUser->kind == kPGPRecipientUserKind_Key )
{
if( curUser->movedManually )
{
MarkKeyARRsForRecipientToUserMove(
recipients, curUser->userInfo.key,
markValue );
}
else if( curUser->userInfo.enforcedARRRefCount != 0 )
{
err = SendUserEvent( recipients,
kPGPRecipientEvent_MovedARRWarningEvent,
curUser );
}
}
else
{
pgpAssert( curUser->kind ==
kPGPRecipientUserKind_Group );
MarkGroupARRsForRecipientToUserMove( recipients,
curUser, markValue );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -