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

📄 npgpnts.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
📖 第 1 页 / 共 5 页
字号:
h_DllInstance: the overall handle to this DLL's runtime information, settings
ul_reason: parameter tells why the function was called
pv_reserved: just that, reserved

--- revision history ------
3/20/00 PR
+ support of rich-text reset functionality, part of changes needed for 
  Notes Mail R5-template compatibility 
+ adjustment in support of PGP 7.0

11/18/98 PR: created		*/
BOOL WINAPI DllMain( HINSTANCE  h_DllInstance, 
						DWORD  ul_reason, 
						LPVOID  pv_reserved)	{
	switch (ul_reason)	{
		case DLL_PROCESS_ATTACH:
			//Set up debugging aids and the memory-leak detector in 
			//	particular.  Lines are preprocessed out in Release builds.
			_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_DEBUG | 
														_CRTDBG_MODE_WNDW);
			_CrtSetDbgFlag( _CRTDBG_LEAK_CHECK_DF | 
										_CrtSetDbgFlag( _CRTDBG_REPORT_FLAG));

			//keep ahold of the instance handle
			eh_Instance = h_DllInstance;

			//for some efficiency gain, tell system there's no need to tell 
			//	our DLL about thread attachment & detachment
			if (!DisableThreadLibraryCalls( h_DllInstance))
				return FALSE;

			break;

		case DLL_PROCESS_DETACH:
			//free any resources still allocated to a copy of rich-text 
			//	content stored in memory
			if (mt_RtfResettable.h_content)
				OSMemFree( mt_RtfResettable.h_content);
	} //switch (ul_reason)

	return TRUE;
} //DllMain(


/** es_PreMailSend( ***
Purpose is to take any PGP action necessary before the message gets sent on 
to MAIL.BOX as the current mail-send event is carried through.

Although it probably would have been more elegant to place this procedure in 
the ndbPGP DLL, the debugging infrastructure doesn't like one DLL freeing 
memory allocated in another DLL, even if the DLLs are in the same process. I 
don't know whether this is a limitation of the Windows debugging 
infrastructure or if its just a no-no in general for reasons unknown to me.

--- parameter & return ----
ppv_ARGV: pointer to the series of arguments provided by the PGP @DbCommand 
	used to call this DLL
RETURN: eus_SUCCESS if successful; an appropriate error code otherwise

--- revision history ------
9/6/02 PR: minor documentation adjustment

3/20/00 PR
+ support of rich-text reset functionality, part of changes needed for 
  Notes Mail R5-template compatibility
+ token renaming

9/12/99 PR
+ logic adjustment to support enhancement of better emulation of Lotus Notes' 
  name lookup behavior
+ documentation adjustment, logic shortening

1/23/99 PR: created			*/
short es_PreMailSend( void * *const  ppv_ARGV)	{
	const int  i_ARG_HANDLE = 0, i_ARG_PGP_FLAGS = 1, 
				i_ARG_RECIPIENT_NMS = 2, i_ARG_LOOKUP_EXHAUST = 3, 
				i_ARG_LOOKUP_HOW = 4, i_ARG_ATTACHMENTS = 5, 
				i_ARG_RTF_FLDNM = 6;
	const char  pc_PGPFLG_SIGN[] = "SI", pc_PGPFLG_ENCRYPT[] = "EN";

	double  d;
	NOTEHANDLE  h_note;
	char * pc_ItmNmRtf = NULL, * pc_LookupHow = NULL, 
			* pc_RecipientsList = NULL;
	BOOL  f_PgpSign, f_PgpEncrypt, f_lookupExhaust = FALSE, f_failure = FALSE;
	int  i_Attachments = 0;
	STATUS  us_err;
	short  s_error = NULL;

	if (!( ppv_ARGV && *ppv_ARGV))
		return !eus_SUCCESS;

	//recover the handle to the calling note's session
	if (!ef_GetNumberListEntry( ppv_ARGV[ i_ARG_HANDLE], TRUE, 0, &d))
		return !eus_SUCCESS;
	h_note = (NOTEHANDLE) (DWORD) d;

	//determine what sort of PGP encoding is to be performed
	f_PgpSign = ef_TextListContainsEntry( ppv_ARGV[ i_ARG_PGP_FLAGS], TRUE, 
												pc_PGPFLG_SIGN, NULL, NULL);
	f_PgpEncrypt = ef_TextListContainsEntry( ppv_ARGV[ i_ARG_PGP_FLAGS], 
										TRUE, pc_PGPFLG_ENCRYPT, NULL, NULL);

	//get the recipient-list string
	if (us_err = eus_CreateTextListEntryCopy( 0, 
											ppv_ARGV[ i_ARG_RECIPIENT_NMS], 
											TRUE, &pc_RecipientsList))
		return us_err;
	if (!pc_RecipientsList && f_PgpEncrypt)
		return !eus_SUCCESS;

	//if PGP security has been specified to be performed and if the list of 
	//	recipient names contains someone...
	if ((f_PgpSign || f_PgpEncrypt) && pc_RecipientsList)	{
		//get the name of the rich-text field to process
		if ((us_err = eus_CreateTextListEntryCopy( 0, 
											ppv_ARGV[ i_ARG_RTF_FLDNM], TRUE, 
											&pc_ItmNmRtf)) || 
											(f_failure = !pc_ItmNmRtf))
			goto errJump;

		//if we're to encrypt...
		if (f_PgpEncrypt)	{
			//get the number of attachments associated with the note
			if (!ef_GetNumberListEntry( ppv_ARGV[ i_ARG_ATTACHMENTS], TRUE, 
																	0, &d))
				return !eus_SUCCESS;
			i_Attachments = (int) d;

			//get the name of the user's mail (home) server
			if (us_err = eus_CreateTextListEntryCopy( 0, 
												ppv_ARGV[ i_ARG_LOOKUP_HOW], 
												TRUE, &pc_LookupHow))
				goto errJump;
			if (!pc_LookupHow && !(pc_LookupHow = calloc( 1, sizeof( char))))
				goto errJump;

			//determine whether caller wants name lookups to be "exhaustive"
			if (f_failure = !ef_GetNumberListEntry( ppv_ARGV[ 
										i_ARG_LOOKUP_EXHAUST], TRUE, 0, &d))
				goto errJump;
			f_lookupExhaust = (BOOL) d;
		} //if (f_PgpEncrypt)

		//Initialize the information structure we use to hold onto a copy of 
		//	the PGP-encoded rich-text field we will be constructing. We may 
		//	need to reset the note's rich-text field to the PGP-encoded 
		//	version if the encoding was initiated by a user press of the 
		//	"Send and File" action button.
		if (mt_RtfResettable.h_note)	{
			OSMemFree( mt_RtfResettable.h_content);
			mt_RtfResettable.h_content = NULL;
		}
		mt_RtfResettable.h_note = h_note;

		//Prepare the message for sending in a PGP-secured manner. If failure 
		//	is encountered, flag that the structure used to hold a copy of 
		//	the PGP-encoded rich-text field is empty.
		if (s_error = xs_PgpSecureMessage( h_note, f_PgpSign, f_PgpEncrypt, 
										pc_RecipientsList, f_lookupExhaust, 
										pc_LookupHow, i_Attachments, 
										pc_ItmNmRtf, &mt_RtfResettable))
			mt_RtfResettable.h_note = NULL;
	} //if ((f_PgpSign || f_PgpEncrypt) && 

errJump:
	//free resources allocated via this procedure
	if (pc_RecipientsList)
		free( pc_RecipientsList);
	if (pc_ItmNmRtf)
		free( pc_ItmNmRtf);
	if (pc_LookupHow)
		free( pc_LookupHow);

    return (short) us_err + s_error + f_failure;
} //es_PreMailSend(


/** es_ReplaceMimeWithRtf( ***
Replaces the specified string of MIME-part fields with a previously stored 
Notes rich-text stream.

--- parameter & return ----
ppv_ARGV: pointer to the series of arguments provided by the PGP @DbCommand 
	used to call this DLL
RETURN:
	eus_SUCCESS if no errors occurred
	eus_ERR_INVLD_ARG if any input parameter is obviously invalid
	the Notes API error code otherwise

--- revision history ------
9/6/02 PR: listing format adjustment, minor exception-handling adjustment, 
	minor documentation adjustment
3/20/00 PR: created			*/
short es_ReplaceMimeWithRtf( void * *const  ppv_ARGV)	{
	const int  i_ARG_HANDLE = 0, i_ARG_RTF_FLDNM = 1;
	const WORD  us_TYPE_MIME_PART = 0x0019;

	NOTEHANDLE  h;
	double  d = NULL;
	char * pc;
	WORD  us;
	BOOL  f_RtfContextSet = FALSE;
	BYTE * puc;
	RtfContext  t;
	STATUS  us_err;

	if (!( ppv_ARGV && *ppv_ARGV && mt_RtfResettable.h_content))
		return eus_ERR_INVLD_ARG;

	//Recover the handle to the calling note's session. If it doesn't 
	//	correspond to the note associated with the previously stored rich-text 
	//	stream, short-circuit with failure.
	if (!( ef_GetNumberListEntry( ppv_ARGV[ i_ARG_HANDLE], TRUE, 0, &d) && d))
		return eus_ERR_INVLD_ARG;
	if ((h = (NOTEHANDLE) (DWORD) d) != mt_RtfResettable.h_note)
		return eus_ERR_INVLD_ARG;

	//obtain the name of the items to be replaced
	if (us_err = eus_CreateTextListEntryCopy( 0, ppv_ARGV[ i_ARG_RTF_FLDNM], 
																	TRUE, &pc))
		return (short) us_err;
	if (!*pc)	{
		us_err = eus_ERR_INVLD_ARG;
		goto errJump;
	}

	//if the first of the named items is not of type MIME Part, short-circuit 
	//	with failure
	if (us_err = NSFItemInfo( h, pc, (WORD) strlen( pc), NULL, &us, NULL, 
																	NULL))	{
		if (ERR( us_err) == ERR_ITEM_NOT_FOUND)
			us_err = eus_ERR_INVLD_ARG;
		goto errJump;
	}
	if (us != us_TYPE_MIME_PART)	{
		us_err = eus_ERR_INVLD_ARG;
		goto errJump;
	}

	//remove the MIME-part items
	if (us_err = eus_RemoveItem( h, pc, ebid_NULLBLOCKID))
		goto errJump;

	//set up a replacement field based on the already stored stream of 
	//	rich-text
	puc = OSLockObject( mt_RtfResettable.h_content);
	us_err = eus_ReplaceRtfWithCdStream( puc, mt_RtfResettable.ul_len, 
												ept_InitUtilityRtfContext( &t));
	OSUnlockObject( mt_RtfResettable.h_content);
	f_RtfContextSet = TRUE;
	if (us_err)
		goto errJump;

	//commit the rich-text to the note under the same name used by the 
	//	MIME-part items
	us_err = eus_CommitChangedRtf( h, pc, &t);

errJump:
	//If an error occurred, free resources allocated to the stored version, 
	//	and flag that this has been done. We don't free if no error occurred 
	//	because the rich-text stream may be re黶ed in the note's post-save 
	//	(R5) or query-close (R4) events.
	if (us_err)	{
		OSMemFree( mt_RtfResettable.h_content);
		memset( &mt_RtfResettable, NULL, sizeof( ResettableRtfInfo));
	}

	if (f_RtfContextSet)
		ef_FreeRtfContext( &t);
	if (pc)
		free( pc);

	return (short) us_err;
} //es_ReplaceMimeWithRtf(


/** xs_VetPluginReadiness( ***
Determines (or assists the subform in determining) whether the calling plug-in 
subform is compatible with this DLL component of the plug-in.

--- parameter & return ----
pc_PLGN_VER_SUBFM: address of string stating the version of the calling PGP 
	Plug-In subform
pc_MIN_CPTBL_VER_DLL: Optional. Address of string stating what the subform 
	considers the minimum version of this DLL with which it is compatible. If 
	null, procedure will consider that version to be the subform's own version, 
	meaning that a downlevel DLL is incompatible.
ps_status: Optional Output. Address of variable in which to store the relative 
	state of the subform component's version to this DLL component's version. 
	The output value mirrors what we would expect from a "cmp" function: Result 
	is less than zero if subform < DLL, zero if subform = DLL, greater than 
	zero if subform > DLL.
pc_instldVer: Optional Output, but required if ps_status output is requested. 
	Address of string buffer in which to copy the version of this DLL in case 
	the subform component is interested (as it might well be if the subform 
	component is of later version than the DLL).
ps_unEngaged: Optional Output, but required if ps_status output is requested. 
	Address of VisualBasic flag variable in which to note whether this DLL has 
	been loaded by the Notes client on a session-long basis (i.e. whether it's 
	been loaded yet as a "database driver" extension).
ps_prvIncompatibilityFound: Optional Output, but required if ps_status output 
	is requested. Address of VisualBasic flag variable in which to note whether 
	incompatibility had been found in a previous compatibility check during 
	this DLL session.
pv_hDll: Optional Output, but required if ps_status output is requested. 
	Address of variable in which to store the module handle of this DLL in case 
	the subform wishes to force the unloading of the DLL in order to replace it 
	with a preferred DLL of earlier or later version.
RETURN:
	eus_ERR_INVLD_ARG if any input parameter is found to be invalid
	eus_SUCCESS if this DLL is compatible with the calling subform component
	ei_USER_ABORT it this DLL is incompatible with the calling subform component

--- revision history ------
10/25/02 PR: upgraded plug-in version string to 2.2.2
9/6/02 PR: upgraded plug-in version string to 2.2.1, minor exception-handling 
	improvement

7/2/01 PR
+ Logic enhancment in support of overhaul of plug-in initialization. Included 
  addition of five output parameters following the two input parameters (the 
  first original, the second new). Procedure still supports old versions of the 
  plug-in subform which pass just the one input parameter.
+ updated plug-in version string to 2.2; minor token renaming

4/24/01 PR: updated plug-in version string to 2.1.8
11/16/00 PR: updated plug-in version string to 2.1.7
11/14/00 PR: updated plug-in version string to 2.1.6
10/7/00 PR: created			*/
short xs_VetPluginReadiness( const char  pc_PLGN_VER_SUBFM[], 
								const char  pc_MIN_CPTBL_VER_DLL[], 
								short *const  ps_status, 
								char  pc_instldVer[], 
								short *const  ps_unEngaged, 
								short *const  ps_prvIncompatibilityFound, 
								HMODULE *const  pv_hDll)	{
	//static for speed
	static const char  pc_PLGN_VER_DLL[] = "2.2.2", 
						pc_MIN_CPTBL_VER_SUBFM[] = "2.1.6";

	static BOOL  f_incompa

⌨️ 快捷键说明

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