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

📄 pgpnetservice.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
📖 第 1 页 / 共 2 页
字号:
		kCFSocketReadCallBack,
		callback,
		&socketContext );
	source = CFSocketCreateRunLoopSource( NULL, socket, 0 );
	CFRunLoopAddSource( rl, source,	kCFRunLoopDefaultMode );

	CFRelease( source );
	CFRelease( socket );

	return kPGPError_NoErr;
}
#endif

	PGPError
PGPnetReadMessageFromService(
	PGPnetContextRef	netContext,
	PGPrpcMessage **	outMsg )
{
	PGPError			err		= kPGPError_NoErr;
	PGPByte *			buf		= NULL;
	PGPSize				len		= 0;
	
	PGPValidatePtr( outMsg );
	
	err = PGPrpcRead( netContext->context, netContext->sockFromService, &buf, &len ); CKERR;
	
	*outMsg = (PGPrpcMessage *) buf;

done:
	return err;
}

	PGPError
PGPnetReadSAInProgressMessage(
	PGPnetContextRef	netContext,
	PGPrpcMessage *		msg,
	PGPnetSAIdent *		said )
{
	PGPError			err		= kPGPError_NoErr;
	PGPByte *			buf		= NULL;
	PGPUInt32			len		= 0;
	
	PGPValidatePtr( msg );
	PGPValidatePtr( said );
	PGPValidateParam( msg->msgType == kPGPnet_MT_SAInProgress );
	
	err = PGPrpcUnpack( netContext->context, (PGPByte *) msg,
		PGPrpcMessageBufferSize( msg ),
		"B", &buf, &len ); CKERR;
	
	if( len != sizeof( PGPnetSAIdent ) )
		RETERR( kPGPError_CorruptData );
		
	pgpCopyMemory( buf, said, sizeof( PGPnetSAIdent ) );

done:
	if( IsntNull( buf ) )
		(void) PGPFreeData( buf );
	return err;
}

	PGPError
PGPnetReadNewSAMessage(
	PGPnetContextRef	netContext,
	PGPrpcMessage *		msg,
	PGPipsecSA *		sa )
{
	PGPError			err		= kPGPError_NoErr;
	PGPByte *			buf		= NULL;
	PGPUInt32			len		= 0;
	
	PGPValidatePtr( msg );
	PGPValidatePtr( sa );
	PGPValidateParam( msg->msgType == kPGPnet_MT_NewSA );
	
	err = PGPrpcUnpack( netContext->context, (PGPByte *) msg,
		PGPrpcMessageBufferSize( msg ),
		"B", &buf, &len ); CKERR;
	
	if( len != sizeof( PGPipsecSA ) )
		RETERR( kPGPError_CorruptData );
		
	pgpCopyMemory( buf, sa, sizeof( PGPipsecSA ) );

done:
	if( IsntNull( buf ) )
		(void) PGPFreeData( buf );
	return err;
}

	PGPError
PGPnetReadSADiedMessage(
	PGPnetContextRef	netContext,
	PGPrpcMessage *		msg,
	PGPipsecSA *		sa )
{
	PGPError			err		= kPGPError_NoErr;
	PGPByte *			buf		= NULL;
	PGPUInt32			len		= 0;
	
	PGPValidatePtr( msg );
	PGPValidatePtr( sa );
	PGPValidateParam( msg->msgType == kPGPnet_MT_SADied );
	
	err = PGPrpcUnpack( netContext->context, (PGPByte *) msg,
		PGPrpcMessageBufferSize( msg ),
		"B", &buf, &len ); CKERR;
	
	if( len != sizeof( PGPipsecSA ) )
		RETERR( kPGPError_CorruptData );
		
	pgpCopyMemory( buf, sa, sizeof( PGPipsecSA ) );

done:
	if( IsntNull( buf ) )
		(void) PGPFreeData( buf );
	return err;
}

	PGPError
PGPnetReadSAFailedMessage(
	PGPnetContextRef	netContext,
	PGPrpcMessage *		msg,
	PGPnetSAIdent *		said )
{
	PGPError			err		= kPGPError_NoErr;
	PGPByte *			buf		= NULL;
	PGPUInt32			len		= 0;
	
	PGPValidatePtr( msg );
	PGPValidatePtr( said );
	PGPValidateParam( msg->msgType == kPGPnet_MT_SAFailed );
	
	err = PGPrpcUnpack( netContext->context, (PGPByte *) msg,
		PGPrpcMessageBufferSize( msg ),
		"B", &buf, &len ); CKERR;
	
	if( len != sizeof( PGPnetSAIdent ) )
		RETERR( kPGPError_CorruptData );
		
	pgpCopyMemory( buf, said, sizeof( PGPnetSAIdent ) );

done:
	if( IsntNull( buf ) )
		(void) PGPFreeData( buf );
	return err;
}

	PGPError
PGPnetReadIdentityMessage(
	PGPnetContextRef	netContext,
	PGPrpcMessage *		msg,
	PGPikeMTIdentity *	identity )
{
	PGPError			err		= kPGPError_NoErr;
	PGPByte *			buf		= NULL;
	PGPUInt32			len		= 0;
	
	PGPValidatePtr( msg );
	PGPValidatePtr( identity );
	PGPValidateParam( msg->msgType == kPGPnet_MT_Identity );
	
	err = PGPrpcUnpack( netContext->context, (PGPByte *) msg,
		PGPrpcMessageBufferSize( msg ),
		"B", &buf, &len ); CKERR;
	
	if( len != sizeof( PGPikeMTIdentity ) )
		RETERR( kPGPError_CorruptData );
		
	pgpCopyMemory( buf, identity, sizeof( PGPikeMTIdentity ) );

done:
	if( IsntNull( buf ) )
		(void) PGPFreeData( buf );
	return err;
}

	PGPError
PGPnetReadSAStatusUpdateMessage(
	PGPnetContextRef	netContext,
	PGPrpcMessage *		msg,
	PGPnetStat **		stats,
	PGPSize *			numStats )
{
	PGPError			err					= kPGPError_NoErr;
	PGPByte *			buf					= NULL;
	PGPUInt32			len					= 0;
	PGPUInt32			numStatsFromService	= 0;
	PGPnetStat *		statsFromService	= NULL;
	
	PGPValidatePtr( msg );
	PGPValidatePtr( stats );
	PGPValidatePtr( numStats );
	PGPValidateParam( msg->msgType == kPGPnet_MT_SAStatusUpdate );
	
	err = PGPrpcUnpack( netContext->context, (PGPByte *) msg,
		PGPrpcMessageBufferSize( msg ),
		"uB", &numStatsFromService, &buf, &len ); CKERR;
	
	if( numStatsFromService * sizeof( PGPnetStat ) != len )
		RETERR( kPGPError_CorruptData );

	statsFromService = PGPNewData( PGPPeekContextMemoryMgr( netContext->context ),
		len,
		kPGPMemoryMgrFlags_Clear );
	CKNULL( statsFromService );
	
	pgpCopyMemory( buf, statsFromService, len );
		
	*stats = (PGPnetStat *) statsFromService;
	*numStats = numStatsFromService;

done:
	if( IsntNull( buf ) )
		(void) PGPFreeData( buf );
	return err;
}

	PGPError
PGPnetReadNewAttackerMessage(
	PGPnetContextRef	netContext,
	PGPrpcMessage *		msg,
	PGPNetPrefBlockedEntry *	attacker )
{
	PGPError			err		= kPGPError_NoErr;
	PGPByte *			buf		= NULL;
	PGPUInt32			len		= 0;
	
	PGPValidatePtr( msg );
	PGPValidatePtr( attacker );
	PGPValidateParam( msg->msgType == kPGPnet_MT_NewAttacker );
	
	err = PGPrpcUnpack( netContext->context, (PGPByte *) msg,
		PGPrpcMessageBufferSize( msg ),
		"B", &buf, &len ); CKERR;
	
	if( len != sizeof( PGPNetPrefBlockedEntry ) )
		RETERR( kPGPError_CorruptData );

	pgpCopyMemory( buf, attacker, sizeof( PGPNetPrefBlockedEntry ) );

done:
	if( IsntNull( buf ) )
		(void) PGPFreeData( buf );
	return err;
}

	PGPError
PGPnetReadLogEventMessage(
	PGPnetContextRef	netContext,
	PGPrpcMessage *		msg,
	PGPnetLogEvent *	event )
{
	PGPError			err		= kPGPError_NoErr;
	PGPByte *			buf		= NULL;
	PGPUInt32			len		= 0;
	
	PGPValidatePtr( msg );
	PGPValidatePtr( event );
	PGPValidateParam( msg->msgType == kPGPnet_MT_LogEvent );
	
	err = PGPrpcUnpack( netContext->context, (PGPByte *) msg,
		PGPrpcMessageBufferSize( msg ),
		"B", &buf, &len ); CKERR;
	
	if( len != sizeof( PGPnetLogEvent ) )
		RETERR( kPGPError_CorruptData );

	pgpCopyMemory( buf, event, sizeof( PGPnetLogEvent ) );

done:
	if( IsntNull( buf ) )
		(void) PGPFreeData( buf );
	return err;
}

	PGPError
PGPnetReadPrefsChangedMessage(
	PGPnetContextRef	netContext,
	PGPrpcMessage *		msg,
	PGPPrefRef *		netPrefs )
{
	PGPError			err					= kPGPError_NoErr;
	PGPByte *			buf					= NULL;
	PGPSize				len					= 0;
	
	PGPValidatePtr( netPrefs );
	PGPValidatePtr( msg );
	PGPValidateParam( msg->msgType == kPGPnet_MT_PrefsChanged );
	
	err = PGPrpcUnpack( netContext->context, (PGPByte *) msg, PGPrpcMessageBufferSize( msg ),
		"B", &buf, &len ); CKERR;
		
	err = PGPImportBufferToMemoryPrefs( PGPPeekContextMemoryMgr( netContext->context ),
		buf, len,
		netDefaults, netDefaultsSize,
		netPrefs ); CKERR;
		
	(void) PGPSetPrefUserValue( *netPrefs, netContext->context, NULL );

done:
	if( IsntNull( buf ) )
		(void) PGPFreeData( buf );
	return err;
}

	PGPError
PGPnetReadIntrudersChangedMessage(
	PGPnetContextRef			netContext,
	PGPrpcMessage *				msg,
	PGPNetPrefBlockedEntry **	blockedHosts,
	PGPUInt32 *					numBlockedHosts )
{
	PGPError					err						= kPGPError_NoErr;
	PGPByte *					buf						= NULL;
	PGPSize						len						= 0;
	PGPUInt32					numHostsFromService		= 0;
	
	PGPValidatePtr( blockedHosts );
	PGPValidatePtr( msg );
	PGPValidateParam( msg->msgType == kPGPnet_MT_IntrudersChanged );
	
	err = PGPrpcUnpack( netContext->context, (PGPByte *) msg, PGPrpcMessageBufferSize( msg ),
		"uB", &numHostsFromService, &buf, &len ); CKERR;
		
	if( len != ( numHostsFromService * sizeof( PGPNetPrefBlockedEntry ) ) )
		RETERR( kPGPError_CorruptData );
		
	*blockedHosts = (PGPNetPrefBlockedEntry *) buf;
	*numBlockedHosts = numHostsFromService;

done:
	return err;
}

	PGPError
PGPnetReadIKEDebugMessage(
	PGPnetContextRef	netContext,
	PGPrpcMessage *		msg,
	char **				string )
{
	PGPError			err					= kPGPError_NoErr;
	
	PGPValidatePtr( msg );
	PGPValidatePtr( string );
	PGPValidateParam( msg->msgType == kPGPnet_MT_IKEDebug );
	
	err = PGPrpcUnpack( netContext->context, (PGPByte *) msg, PGPrpcMessageBufferSize( msg ),
		"s", string ); CKERR;
		
done:
	return err;
}

/* Prefs management */	
	
	PGPError
PGPnetGetPrefs(
	PGPnetContextRef	netContext,
	PGPPrefRef *		netPrefs )
{
	PGPError			err					= kPGPError_NoErr;
	PGPByte *			buf					= NULL;
	PGPSize				len					= 0;
	
	PGPnetValidateContextRef( netContext );
	PGPValidatePtr( netPrefs );
	
	err = PGPrpcPackAndWrite( netContext->context, netContext->sockToService,
		kPGPnet_MT_GetPrefs, "" ); CKERR;

	err = PGPrpcReadAndUnpack( netContext->context, netContext->sockToService,
		kPGPnet_MT_SendPrefs, "B", &buf, &len ); CKERR;
		
	err = PGPImportBufferToMemoryPrefs( PGPPeekContextMemoryMgr( netContext->context ),
		buf, len,
		netDefaults, netDefaultsSize,
		netPrefs ); CKERR;

done:
	if( IsntNull( buf ) )
		(void) PGPFreeData( buf );

	return err;
}
	
	PGPError
PGPnetSetPrefs(
	PGPnetContextRef	netContext,
	PGPPrefRef			netPrefs )
{
	PGPError			err					= kPGPError_NoErr;
	PGPByte *			buf					= NULL;
	PGPSize				len					= 0;
	
	PGPnetValidateContextRef( netContext );
	PGPValidatePref( netPrefs );
	
	err = PGPExportPrefsToBuffer( netPrefs, &len, (void **) &buf ); CKERR;
	err = PGPrpcPackAndWrite( netContext->context, netContext->sockToService,
		kPGPnet_MT_SetPrefs, "B", buf, len ); CKERR;

done:
	if( IsntNull( buf ) )
		(void) PGPFreeData( buf );

	return err;
}

	PGPError
PGPnetIntrudersChanged(
	PGPnetContextRef	netContext )
{
	PGPError			err					= kPGPError_NoErr;
	
	PGPnetValidateContextRef( netContext );

	err = PGPrpcPackAndWrite( netContext->context, netContext->sockToService,
		kPGPnet_MT_IntrudersChanged, "" ); CKERR;

done:
	return err;
}


/*__Editor_settings____

	Local Variables:
	tab-width: 4
	End:
	vi: ts=4 sw=4
	vim: si
_____________________*/

⌨️ 快捷键说明

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