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

📄 pgpdialogoptions.c

📁 vc环境下的pgp源码
💻 C
📖 第 1 页 / 共 3 页
字号:
	
	switch( operation )
	{
		case kPGPOptionHandler_FreeDataOperation:
		{
			FreePGPOUIPopupListDesc( context, inputDesc );
			break;
		}
			
		case kPGPOptionHandler_CopyDataOperation:
		{
			PGPOUIPopupListDesc	*outputDesc;

			pgpAssertAddrValid( outputValue, PGPOptionValue );
			pgpAssertAddrValid( outputValueSize, PGPSize );

			err = CopyPGPOUIPopupListDesc( context, inputDesc, &outputDesc );
			if( IsntPGPError( err ) )
			{
				outputValue->asPtr 	= outputDesc;
				*outputValueSize 	= sizeof( *outputDesc );
			}

			break;
		}
		
		default:
		{
			err = kPGPError_UnknownRequest;
			break;
		}
	}

	return( err );
}

static const PGPOptionType sPopupListOptionSet[] =
{
	kPGPOptionType_Checkbox,
	kPGPOptionType_PopupList
};

	PGPOptionListRef
PGPOUIPopupList(
	PGPContextRef 		context,
	PGPUInt32 			itemID,
	const char 			*title,
	const char 			*description,	/* Can be NULL */
	PGPUInt32			numListItems,
	const char			*listItems[],
	PGPUInt32 			initialValue,
	PGPUInt32 			*resultPtr,
	PGPOptionListRef 	firstOption, ...)
{
	PGPOptionListRef	optionList = kInvalidPGPOptionListRef;
	PGPBoolean			disposeOptionParams = FALSE;
	
	pgpAssert( pgpContextIsValid( context ) );
	pgpAssert( IsntNull( title ) );
	pgpAssert( numListItems > 0 );
	pgpAssert( IsntNull( listItems ) );
	pgpAssert( initialValue <= numListItems );
	pgpAssert( IsntNull( resultPtr ) );
	
	if( IsntNull( resultPtr ) )
		*resultPtr = initialValue;
	
	if( pgpContextIsValid( context ) &&
		IsntNull( title ) &&
		numListItems > 0 &&
		IsntNull( listItems ) &&
		initialValue <= numListItems &&
		IsntNull( resultPtr ) )
	{
		PGPOUIPopupListDesc	descriptor;
		PGPOUIPopupListDesc	*allocatedDesc;
		char				emptyString[] = "";
		
		pgpClearMemory( &descriptor, sizeof( descriptor ) );
		
		descriptor.itemID		= itemID;
		descriptor.valuePtr 	= resultPtr;
		descriptor.title		= title;
		descriptor.numListItems	= numListItems;
		descriptor.listItems	= listItems;
		
		if( IsntNull( description ) )
		{
			descriptor.description = description;
		}
		else
		{
			descriptor.description = emptyString;
		}

		if( IsntPGPError( CopyPGPOUIPopupListDesc( context, &descriptor,
					&allocatedDesc ) ) )
		{
			PGPOptionValue		value;
			PGPOptionListRef	subOptions;
			va_list				args;

			value.asPtr = allocatedDesc;
			
			va_start( args, firstOption );
			subOptions = pgpBuildOptionListArgs( context, FALSE, firstOption,
								args );
			va_end( args );

			optionList = pgpCreateCustomValueOptionList( context,  
								kPGPOptionType_PopupList,
								kPGPOptionFlag_Default,
								&value, sizeof( *allocatedDesc ),
								subOptions, PopupListOptionHandlerProc );
			
			if( pgpGetOptionListError( optionList ) == kPGPError_NoErr &&
				pgpOptionListIsReal( subOptions ) )
			{
				PGPError	err;
				
				err = pgpCheckOptionsInSet( subOptions, sPopupListOptionSet,
							elemsof( sPopupListOptionSet ) );
				if( IsPGPError( err ) )
				{
					pgpSetOptionListError( optionList, err );
				}
			}
		}
		else
		{
			optionList 			= kPGPOutOfMemoryOptionListRef;
			disposeOptionParams	= TRUE;
		}
	}
	else
	{
		disposeOptionParams = TRUE;
	}
	
	if( disposeOptionParams )
	{
		va_list				args;
		
		va_start( args, firstOption );
		pgpFreeVarArgOptionList( firstOption, args);
		va_end( args );
		
		optionList = kPGPBadParamsOptionListRef;
	}
	
	return( optionList );
}

static const PGPOptionType dialogOptionSet[] =
{
	kPGPOptionType_Checkbox,
	kPGPOptionType_PopupList
};

	PGPOptionListRef
PGPOUIDialogOptions(
	PGPContextRef		context,
	PGPOptionListRef 	firstOption,
	...)
{
	PGPOptionListRef	optionList;
	PGPOptionListRef	subOptions;
	va_list				args;
	
	pgpAssert( pgpContextIsValid( context ) );

	if ( pgpContextIsValid( context ) )
	{
		va_start( args, firstOption );
			subOptions = pgpBuildOptionListArgs( context,
						FALSE, firstOption, args );
		va_end( args );

		if( IsntPGPError( pgpCheckOptionsInSet( subOptions,
				dialogOptionSet, elemsof( dialogOptionSet ) ) ) )
		{
			optionList = pgpCreateCustomValueOptionList(
							context,  
							kPGPOptionType_DialogOptions,
							kPGPOptionFlag_Default, NULL,
							0, subOptions, NULL);
		}
		else
		{
			optionList = kPGPBadParamsOptionListRef;
			
			PGPFreeOptionList( subOptions );
		}
	}
	else
	{
		va_start( args, firstOption );
		pgpFreeVarArgOptionList( firstOption, args);
		va_end( args );
		
		optionList = kPGPBadParamsOptionListRef;
	}
	
	return( optionList );
}

	PGPOptionListRef
PGPOUIMinimumPassphraseLength(
	PGPContextRef 	context,
	PGPUInt32		minimumPassphraseLength)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );
	
	value.asUInt = minimumPassphraseLength;
	
	optionList = pgpCreateStandardValueOptionList( context,  
						kPGPOptionType_MinPassphraseLength,
						&value, sizeof( PGPUInt32 ), NULL );
	
	return( optionList );
}

	PGPOptionListRef
PGPOUIMinimumPassphraseQuality(
	PGPContextRef 	context,
	PGPUInt32		minimumPassphraseQuality)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );
	pgpValidateOptionParam( minimumPassphraseQuality <= 100 );
	
	value.asUInt = minimumPassphraseQuality;
	
	optionList = pgpCreateStandardValueOptionList( context,  
						kPGPOptionType_MinPassphraseQuality,
						&value, sizeof( PGPUInt32 ), NULL );
	
	return( optionList );
}

	PGPOptionListRef
PGPOUIShowPassphraseQuality(
	PGPContextRef 	context,
	PGPBoolean		showPassphraseQuality)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );
	
	value.asUInt = showPassphraseQuality;
	
	optionList = pgpCreateStandardValueOptionList( context,  
						kPGPOptionType_ShowPassphraseQuality,
						&value, sizeof( PGPUInt32 ), NULL );
	
	return( optionList );
}

	PGPOptionListRef
PGPOUIVerifyPassphrase(
	PGPContextRef 	context,
	PGPBoolean		verifyPassphrase)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );
	
	value.asUInt = verifyPassphrase;
	
	optionList = pgpCreateStandardValueOptionList( context,  
						kPGPOptionType_VerifyPassphrase,
						&value, sizeof( PGPUInt32 ), NULL );
	
	return( optionList );
}

	PGPOptionListRef
PGPOUIFindMatchingKey(
	PGPContextRef 	context,
	PGPBoolean		findMatchingKey)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );
	
	value.asUInt = findMatchingKey;
	
	optionList = pgpCreateStandardValueOptionList( context,  
						kPGPOptionType_FindMatchingKey,
						&value, sizeof( PGPUInt32 ), NULL );
	
	return( optionList );
}

PGPOptionListRef
PGPOUITextUI(
	PGPContextRef 	context,
	PGPBoolean		textUI)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );
	
	value.asUInt = textUI;
	
	optionList = pgpCreateStandardValueOptionList( context,  
												   kPGPOptionType_TextUI,
												   &value,
												   sizeof( PGPUInt32 ),
												   NULL );
	
	return( optionList );
}

	PGPOptionListRef
PGPOUIDefaultKey(
	PGPContextRef 	context,
	PGPKeyRef		defaultKey)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );
	
	value.asKeyRef = defaultKey;
	
	optionList = pgpCreateStandardValueOptionList( context,  
						kPGPOptionType_DefaultKey,
						&value, sizeof( PGPKeyRef ), NULL );
	
	return( optionList );
}

	PGPOptionListRef
PGPOUIDefaultRecipients(
	PGPContextRef 			context,
	PGPUInt32 				numRecipients,
	const PGPRecipientSpec 	recipients[])
{
	PGPOptionListRef		optionList;
	PGPBoolean				badList = FALSE;
	PGPUInt32				recipientIndex;
	const PGPRecipientSpec	*curRecipient;
	
	pgpValidateOptionContext( context );
	pgpValidateOptionParam( numRecipients > 0 );
	pgpValidateOptionParam( IsntNull( recipients ) );
	
	curRecipient = &recipients[0];
	
	for( recipientIndex = 0; recipientIndex < numRecipients; recipientIndex++ )
	{
		switch( curRecipient->type )
		{
			case kPGPRecipientSpecType_Key:
			{
				if( ! PGPKeyRefIsValid( curRecipient->u.key ) )
				{
					pgpDebugMsg( "PGPOUIDefaultRecipients() Invalid key ref" );
					badList = TRUE;
				}
				
				break;
			}

			case kPGPRecipientSpecType_UserID:
			{
				if( curRecipient->u.userIDStr[0] == 0 )
				{
					pgpDebugMsg( "PGPOUIDefaultRecipients() Empty user ID" );
					badList = TRUE;
				}
				
				break;
			}
			
			case kPGPRecipientSpecType_KeyID:
				break;
				
			default:
			{
				pgpDebugMsg( "PGPOUIDefaultRecipients(): Unknown spec type" );
			
				badList = TRUE;
				break;
			}
		}
	
		if( badList )
			break;
			
		++curRecipient;
	}
	
	if( ! badList )
	{
		optionList = pgpCreateBufferOptionList( context,
							kPGPOptionType_DefaultRecipients,
							recipients, numRecipients *
							sizeof( recipients[0] ) );
	}
	else
	{
		optionList = kPGPBadParamsOptionListRef;
	}
	return( optionList );
}

	PGPOptionListRef
PGPOUIDisplayMarginalValidity(
	PGPContextRef 	context,
	PGPBoolean		displayMarginalValidity)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );
	
	value.asUInt = displayMarginalValidity;
	
	optionList = pgpCreateStandardValueOptionList( context,  
						kPGPOptionType_DisplayMarginalValidity,
						&value, sizeof( PGPUInt32 ), NULL );
	
	return( optionList );
}

	PGPOptionListRef
PGPOUIIgnoreMarginalValidity(
	PGPContextRef 	context,
	PGPBoolean		ignoreMarginalValidity)
{
	PGPOptionListRef	optionList;
	PGPOptionValue		value;
	
	pgpValidateOptionContext( context );
	
	value.asUInt = ignoreMarginalValidity;
	
	optionList = pgpCreateStandardValueOptionList( context,  
						kPGPOptionType_IgnoreMarginalValidity,
						&value, sizeof( PGPUInt32 ), NULL );
	
	return( optionList );
}

	static PGPError
GroupSetOptionHandlerProc(
	PGPContextRef				context,
	PGPOptionHandlerOperation 	operation,
	PGPOptionType				type,
	PGPOptionValue				inputValue,
	PGPSize 					inputValueSize,
	PGPOptionValue 				*outputValue,
	PGPSize						*outputValueSize)
{
	PGPError	err = kPGPError_NoErr;
	
	(void) context;
	(void) type;
	(void) inputValueSize;
	
	switch( operation )
	{
		case kPGPOptionHandler_FreeDataOperation:
		{
			PGPFreeGroupSet( inputValue.asGroupSetRef );
			break;
		}
			
		case kPGPOptionHandler_CopyDataOperation:
		{
			err = PGPCopyGroupSet( inputValue.asGroupSetRef,
						&outputValue->asGroupSetRef );
			if( IsntPGPError( err ) )
			{
				*outputValueSize = sizeof( outputValue->asGroupSetRef );
			}

⌨️ 快捷键说明

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