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

📄 npgpnts.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
📖 第 1 页 / 共 5 页
字号:

	//if no the special rich-text version exists or if a non-fatal error 
	//	occurred in decoding that version, we will decode the message's first 
	//	PGP-ASCII block
	if (!bid_item.pool || i_errNonFatal)	{
		BOOL  f_MsgChanged;
		if (i_err = i_PgpDecodeUsingAsciiText( h_NOTE, pc_ITMNM_RTF, t_crsr, 
												&t_RtfContext, &f_MsgChanged))
			goto errJump;

		//if it's true, inform the caller that the message content did change
		if (f_MsgChanged)
			*ps_msgChanged = ms_VB_TRUE;
	} //if (!bid_item.pool || i_errNonFatal)

	if (i_errNonFatal)	{
		const char *const  ppc_MSG_PART[] = {"An error occurred (", ") "
								"during the attempt to\nPGP decode a "
								"rich-text version of this message.\nThe "
								"plain-text version will be used instead."};
		char  pc_msg[ 255];

		sprintf( pc_msg, "%s%i%s", ppc_MSG_PART[0], i_errNonFatal, 
															ppc_MSG_PART[1]);
		MessageBox( eh_mainWnd, pc_msg, epc_APPNM, MB_OK | MB_ICONINFORMATION);
		i_err = us_err = eus_SUCCESS;
	} //if (i_errNonFatal)

errJump:
	ef_FreeRtfContext( &t_RtfContext);

	//if no errors occurred, return that procedure was successful; otherwise 
	//	return an appropriate error code
	return (short) (us_err + i_err);
} //xs_DecryptVerifyNote(


/** i_PgpDecodeUsingAsciiText( ***


--- parameters & return ----

RETURN: eus_SUCCESS if no error occured; ... otherwise

--- revision history -------
9/6/02 PR
+ added special attachment-handling for PGP-encoded attachments, causing slight 
  signature change
+ logic enhancement to support high-ASCII (international) characters in message 
  body
+ minor documentation adjustment, listing format adjustment, token renaming

9/12/99 PR: code adjustment associated with an improvement to handling of 
	public-key decoding
1/24/99 PR: created			*/
//DOC!!
static int i_PgpDecodeUsingAsciiText( NOTEHANDLE  h_NOTE, 
										char  pc_ITMNM[], 
										RtfCursor  t_crsr, 
										RtfContext *const  pt_rtCtx, 
										BOOL *const  pf_MsgChanged)	{
	DWORD  ul, ul_lenBlk;
	char * pc_blk, * pc_inp = NULL, * pc_inpOs = NULL, 
			* pc_outpOs = NULL, * pc_outp = NULL;
	STATUS  us_err = eus_SUCCESS;
	BOOL  f_fail;
	int  i_err = NULL;

	//Get the textual content of the rich-text field along with its length. If 
	//	no content exists, short-circuit with success. (Remember, 
	//	eul_GetRtfText() returns the size of the buffer allocated, not the 
	//	length of the null-terminated string.) The content needs to be 
	//	translated to the native character set because clear-signed text may 
	//	include extended characters.
	if (eul_ERR_FAILURE == (ul = eul_GetRtfText( pt_rtCtx, NULL, TRUE, 
																	&pc_inp)))
		return !eus_SUCCESS;
	if (ul <= 1)
		goto errJump;
	if (!(pc_inpOs = malloc( ul)))	{
		i_err = -11999;		//kPGPError_OutOfMemory
		goto errJump;
	}
	if (f_fail = !OSTranslate( OS_TRANSLATE_LMBCS_TO_NATIVE, pc_inp, (WORD) 
												(ul - 1), pc_inpOs, (WORD) ul))
		goto errJump;

	//PGP decode just the portion of the content containing the PGP-encoded 
	//	block
	if (i_err = ei_FindAndDecodePgpBlock( &pc_inpOs, ul, &pc_blk, &ul_lenBlk, 
															&pc_outpOs, NULL))
		goto errJump;

	//if output was generated by the decoding (none will be if the PGP-encoded 
	//	block is a key block)...
	if (pc_outpOs)	{
		//replace the PGP-encoded block in the rich-text field with the decoded 
		//	output
		const size_t  UI = strlen( pc_outpOs) + 1;
		if (!( pc_outp = malloc( UI)))
			goto errJump;
		if (f_fail = !OSTranslate( OS_TRANSLATE_NATIVE_TO_LMBCS, pc_outpOs, 
										(WORD) (UI - 1), pc_outp, (WORD) UI))
			goto errJump;
		if (us_err = us_ReplaceRichAsciiLines( pc_inpOs, pc_blk, ul_lenBlk, 
													pc_outp, &t_crsr, pt_rtCtx))
			goto errJump;

		//if the note contains any attachments, wrap PGP-encoded attachments 
		//	within special-handling hotspots
		if (NSFNoteHasObjects( h_NOTE, NULL))
			if (us_err = us_ActionWrapPgpAttachments( h_NOTE, t_crsr, pt_rtCtx))
				goto errJump;

		//commit to note the changes made to the rich-text field
		if (us_err = eus_CommitChangedRtf( h_NOTE, pc_ITMNM, pt_rtCtx))
			goto errJump;

		//inform the caller that the message content did change
		*pf_MsgChanged = TRUE;
	} //if (pc_outpOs)

errJump:
	//free any memory allocation made by eul_GetRtfText() and free all 
	//	resources devoted to this instance of rich-text handling
	if (pc_outp)
		free( pc_outp);
	if (pc_outpOs)
		e_FreePgpMem( pc_outpOs);
	if (pc_inpOs)
		free( pc_inpOs);
	if (pc_inp)
		free( pc_inp);

	return us_err + f_fail + i_err;
} //i_PgpDecodeUsingAsciiText(


/** us_ActionWrapPgpAttachments( ***
Wrap attachments that seem to be PGP-encoded with a rich-text action hotspot 
that enables special PGP handling.

--- suggested enhancement ----
9/6/02 PR
+ Add to subform QueryOpen code that notes in lt_pgp item whether and which 
  PGP-encoded attachments appear below-the-line in a message that does not 
  include the special PGP-encoded rich-text attachment. This state would be 
  ascertained in xus_SetupPgpAttachments() and noted with something like 
  'BL-file1.ext.pgp/file2.ext.asc...' and, for not-applicable or none 'BL-/' 
  (or instead of BL is there already another PGP flag that can be extended, 
  e.g. AR?). Then this procedure could be more efficient and not have to search 
  through the entire rich-text field to determine if it needs to wrap certain 
  below-the-line attachments.
+ get rid of PGP-development shortcuts

--- parameters & return ------
h_NOTE: handle to the note being operated on
t_crsr: rich-text cursor set to where the search should start for attachemnt 
	hotspots whose parent attachments should be encoded
pt_rtCtx: Input & Output. Address of the rich-text context structure 
	describing the rich-text field to be searched and updated with PGP-encoded 
	attachment-action hotspots. Structure may undergo change even if an error 
	occurs.
RETURN: eus_SUCCESS if no error occured; the Notes API error code otherwise

--- revision history ---------
9/6/02 PR: created			*/
static STATUS us_ActionWrapPgpAttachments( NOTEHANDLE  h_NOTE, 
											RtfCursor  t_crsr, 
											RtfContext *const  pt_rtCtx)	{
	char * pc_objNm, * pc_fileNm;
	RtfSpan  t_rtSpan;
	UINT  ui_lenFileNm;
	StringNode * pt_notBelow = NULL, * pt_nd = NULL;
	BLOCKID  bid_itm = ebid_NULLBLOCKID;
	char  pc[ mi_MAXLEN_ATTCH_OBJNM];
	WORD  us_typ;
	STATUS  us_err;
	BOOL  f_fail = FALSE;

	_ASSERTE( (t_crsr.puc_location ? t_crsr.us_recLength : TRUE) && pt_rtCtx);

	//note whether the note's PGP-state item contains information on the note's 
	//	below-the-line PGP-encoded attachments state

	//if a file-attachment hotspot is found at or beyond our starting point...
	if (!ef_CursorToAttachmentHotspot( &t_crsr, pt_rtCtx, FALSE, &t_rtSpan, 
														&pc_objNm, &pc_fileNm))
		return !eus_SUCCESS;
	_ASSERTE( t_crsr.puc_location ? pc_objNm && *pc_objNm && pc_fileNm && 
															*pc_fileNm : TRUE);

	//loop until no further file-attachment hotspots exist in the rich-text 
	//	field
	if (!*mpc_fileNmPgpRtf)
		strcat( strcpy( mpc_fileNmPgpRtf, mpc_ROOTFILENM_PGP_RTF), 
														mpc_PGP_ARMOR_EXT_ASC);
	while (t_crsr.puc_location)	{
		//if we don't know the note's full below-the-line PGP-encoded 
		//	attachments state, note this attachment's object name
if (TRUE)
			if (!ef_AddStringNodeFifo( pc_objNm, TRUE, &pt_nd))	{
				us_err = ERR_MEMORY;
				goto errJump;
			}else if (!pt_notBelow)
				pt_notBelow = pt_nd;

		//if the attachment seems to be PGP encoded and not the special 
		//	encapsulated rich-text attachment, wrap a PGP action hotspot around 
		//	the file-attachment hotspot
		if (stricmp( pc_fileNm, mpc_fileNmPgpRtf) != ei_SAME && (stricmp( 
										pc_fileNm + (ui_lenFileNm = strlen( 
										pc_fileNm)) - mui_LEN_ARMOR_EXT_ASC, 
										mpc_PGP_ARMOR_EXT_ASC) == ei_SAME || 
										stricmp( pc_fileNm + ui_lenFileNm - 
										mui_LEN_ARMOR_EXT_PGP, 
										mpc_PGP_ARMOR_EXT_PGP) == ei_SAME))
			if (us_err = us_ActionWrapAttachment( &t_rtSpan, pc_fileNm, 
											pc_objNm, h_NOTE, FALSE, pt_rtCtx))
				goto errJump;

		//advance the rich-text cursor to the next file-attachment hotspot
		if (f_fail = !ef_CursorToAttachmentHotspot( &t_crsr, pt_rtCtx, FALSE, 
											&t_rtSpan, &pc_objNm, &pc_fileNm))
			goto errJump;
	} //while (t_crsr.puc_location)

	//if we know the note's full below-the-line PGP-encoded attachments state...
if (FALSE)
		//if attachments are to be wrapped, wrap them
		;
	//else process any attachments beyond those wrapped above...
	else	{
		UINT  ui = NULL;

		//if beginning cursor did not start at the beginning of the rich-text 
		//	field...
			//for each attachment found from the beginning of the field up to 
			//	where the beginning cursor points, add it's object name to the 
			//	do-not-process list

//PGP development shortcut: assumption here that any attachments beyond those 
//	wrapped above are below-the-line attachments
		//for each seeming attachment associated with the note...
		if (us_err = eus_getAttachInfoNext( h_NOTE, NULL, &bid_itm, pc, NULL, 
													NULL, NULL, &us_typ, NULL))
			goto errJump;
		while (bid_itm.pool)	{
			//if the object is a normal attachment, and its name is not in the 
			//	do-not-process list, and it's not the special encapsulated 
			//	rich-text attachment...
			if (!(us_typ == HOST_STREAM || us_typ == HOST_OLELIB || 
											us_typ == HOST_BYTEARRAY_EXT || 
											us_typ == HOST_BYTEARRAY_PAGE) && 
											!( ef_ListContainsString( pc, 
											pt_notBelow, FALSE) || stricmp( pc, 
											mpc_fileNmPgpRtf) == ei_SAME))
				//Wrap a PGP action hotspot around a file-attachment hotspot 
				//	created for the attachment. If this is the first time 
				//	through for this display event, add a new paragraph first 
				//	in which to display the hotspot.
				if (us_err = us_ActionWrapAttachment( NULL, pc, pc, h_NOTE, 
												!ui++ ? TRUE : FALSE, pt_rtCtx))
					goto errJump;

			//move on to the next object
			if (us_err = eus_getAttachInfoNext( h_NOTE, NULL, &bid_itm, pc, 
											NULL, NULL, NULL, &us_typ, NULL))
				goto errJump;
		} //while (bid_itm.pool)
	} //if (

errJump:
	if (pt_notBelow)
		e_FreeList( &pt_notBelow, TRUE);

	return us_err + f_fail;
} //us_ActionWrapPgpAttachments(


/** i_PgpDecodeUsingRichTextObj( ***


--- parameters & return ----
ul_OBJID: Optional.
RETURN: 

--- revision history -------
10/7/00 PR: minor documentation adjustment

3/20/00 PR
+ accommodated change in signature to ei_PgpDecodeBuffer()
+ improved safety code

9/12/99 PR: accommodation of compressed objects (forced into this because the 
	Domino SMTP MTA may decide to compress)
12/15/98 PR: created		*/
//DOC!!
static int i_PgpDecodeUsingRichTextObj( const DWORD  ul_OBJID, 
										const DWORD  ul_LEN_OBJ, 
										const BLOCKID  bid_OBJ_ITEM, 
										NOTEHANDLE  h_NOTE, 
										char  pc_ITMNM_RTF[], 
										RtfContext *const  pt_rtfContext, 
										int *const  pi_errNonFatal)	{
	HANDLE  h;
	BYTE * puc;
	DWORD  ul;
	char * pc_output = NULL;
	STATUS  us_err;
	int  i_err;

	_ASSERTE( h_NOTE && ul_LEN_OBJ && bid_OBJ_ITEM.pool && pc_ITMNM_RTF && 
															pt_rtfContext);

	if (pi_errNonFatal)
		*pi_errNonFatal = FALSE;

	//read the special attachment into a memory buffer
	if (us_err = eus_getObjectContentsInBuffer( ul_OBJID, ul_OBJID ? 
											ebid_NULLBLOCKID : bid_OBJ_ITEM, 
											ul_LEN_OBJ, h_NOTE, NULL, &h))	{
		if (pi_errNonFatal)
			*pi_errNonFatal = us_err;
		return us_err;
	}

	//PGP decode the buffer, then, our work with it done, free the buffer
	puc = OSLockObject( h);
	i_err = ei_PgpDecodeBuffer( puc, ul_LEN_OBJ, TRUE, &pc_output, &ul);
	OSUnlockObject( h);
	OSMemFree( h);
	if (i_err)	{
		if (pi_errNonFatal && i_err != ei_USER_ABORT)
			*pi_errNonFatal = i_err;
		goto errJump;
	}

	//Replace the current rich-text field with the CD records in the 
	//	decrypted buffer. From here on all errors are fatal because we 
	//	will no longer know the state of the rich-text tracking context.
	if (us_err = eus_ReplaceRtfWithCdStream( pc_output, ul, pt_rtfContext))

⌨️ 快捷键说明

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