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

📄 nabhandling.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
📖 第 1 页 / 共 3 页
字号:
	while (pv_entry = NAMELocateNextName( pv_results, pv_entry, &us))	{
		//if a match was found, indicate this to caller, else iterate to the 
		//	next not-yet-resolved entry
		if (!us)	{
			pt = pt->pt_next;
			continue;
		}else if (us > 1)
			f_ambiguous = TRUE;

		pv = NULL;
		for (ul = 0; ul < us; ul++)	{
			//if the entry contains the MailAddress item, get a copy of the 
			//	item contents
			if (us_err = eus_CreateNameMatchTextItemCopy( us_MAILADDRESS, 
											pv = NAMELocateNextMatch( 
											pv_results, pv_entry, pv), &pc))
				goto errJump;

			//if we found a specific mail address...
			if (pc)	{
				const char * pc_end, * pc_start = strchr( pc, '<');

				//if the actual address is enclosed in corner brackets, pare 
				//	the string down to just the address
				if (pc_start && (pc_end = strchr( pc, '>')) > pc_start + 1)	{
					memmove( pc, pc_start + 1, pc_end - (pc_start + 1));
					pc[ pc_end - (pc_start + 1)] = NULL;
				}

				//If unique, transfer ownership of the string to a new entry 
				//	in the resolved list. If not unique, free the resources 
				//	allocated to the string. In any case, also mark the name 
				//	as having been found.
				pt_nd = pt_resolved;
				if (f_failure = !ef_AddStringNodeFifoUnique( pc, FALSE, 
															FALSE, &pt_nd))
					goto errJump;
				if (pt_nd)	{
					ui_resolved++;
					if (!pt_resolved)
						pt_resolved = pt_nd;
				}else
					free( pc);
				pt->pt_name->f_found = TRUE;
			//else let's see whether we've landed on a person document by 
			//	checking whether the FullName item is present
			}else	{
				//get a copy of the first name in the item
				if (us_err = eus_CreateNameMatchTextItemCopy( us_FULLNAME, 
																	pv, &pc))
					goto errJump;

				//if we found a full name...
				if (pc)	{
					//If unique, transfer ownership of the string to a new 
					//	entry in the resolved list. If not unique, free the 
					//	resources allocated to the string. In any case, also 
					//	mark the name as having been found.
					pt_nd = pt_resolved;
					if (f_failure = !ef_AddStringNodeFifoUnique( pc, FALSE, 
															FALSE, &pt_nd))
						goto errJump;
					if (pt_nd)	{
						ui_resolved++;
						if (!pt_resolved)
							pt_resolved = pt_nd;
					}else
						free( pc);
					pt->pt_name->f_found = TRUE;
				//else assume we've hit on a group and add it to the groups 
				//	list for later lookup & resolution
				}else	{
					BOOL  f_okType;

					if (us_err = eus_CreateNameMatchTextItemCopy( 
														us_GRP_TYPE, pv, &pc))
						goto errJump;

					if (pc)	{
						//if this group is for use with e-mail...
						f_okType = *pc == i_MULTI_PURPOSE || *pc == 
																i_MAIL_ONLY;
						free( pc);
						if (f_okType)	{
							WORD  us_type, us_len, us_entries = 0, us;
							NameFoundNode * pt_node;

							//Get the number of members in the group. If 
							//	there aren't any, short-circuit with success.
							if (!( puc = NAMELocateItem( pv, us_MEMBERS, 
														&us_type, &us_len)))
								goto errJump;
							switch (us_type)	{
								case TYPE_TEXT_LIST:
									us_entries = ListGetNumEntries( puc, 
																		TRUE);
									break;
								case TYPE_TEXT:
									puc += sizeof( WORD);
									if (us_len -= sizeof( WORD))
										us_entries = 1;
									break;
							} //switch (us_type)

							//for each member of the group...
							for (us = 0; us < us_entries; us++)	{
								//if the member is null or already named in 
								//	any of the lists we've got going 
								//	(resolved, unresolved, groups-
								//	encountered), iterate to the next member
								if (us_type == TYPE_TEXT_LIST)	{
									if (us_err = eus_CreateTextListEntryCopy( 
														us, puc, TRUE, &pc))
										goto errJump;
									if (!pc)
										continue;
								}else	{
									if (f_failure = !( pc = malloc( us_len + 
																		1)))
										goto errJump;
									memcpy( pc, puc, us_len);
									pc[ us_len] = NULL;
								}
								if (ef_ListContainsName(  pc, 
												pt_unresolved) || 
												ef_ListContainsString( pc, 
												pt_resolved, FALSE) || 
												ef_ListContainsString( pc, 
												pt_encountered, FALSE))	{
									free( pc);
									pc = NULL;
									continue;
								}

								//add the name to the members list for the 
								//	lookup to follow
								pt_node = pt_members;
								if (f_failure = !ef_AddNameFoundNodeFifo( pc, 
													FALSE, TRUE, &pt_node))
									goto errJump;
								if (pt_node && !pt_members)
									pt_members = pt_node;
							} //for (us = 0; us < us_entries; us++)

							//if there's anyone in the group...
							if (pt_members)	{
								UINT  ui_added;

								//add the group name to the 
								//	groups-encountered list so we can guard 
								//	against infinite recursion
								if (f_failure = !ef_AddStringNodeFifo( 
													pt->pt_name->pc_nm, TRUE, 
													&pt_lastEncountered))
									goto errJump;
								if (!pt_encountered)
									pt_encountered = pt_lastEncountered;

								//run the member list through the resolution 
								//	process
								if (us_err = eus_ResolveMailAddresses( 
												pt_members, f_LOOKUP_EXHAUST, 
												pc_SERVERNM, &pt_encountered, 
												&pt_resolved, &ui_added, 
												f_ambiguous ? 
												NULL : &f_ambiguous))
									goto errJump;
								ui_resolved += ui_added;

								//add any member names not resolved to the 
								//	unresolved list
								pt_node = pt_members;
								do	{
									if (pt_node->pt_name->f_found)
										continue;

									pt_nde = pt_unresolved;
									if (f_failure = !ef_AddNameFoundNodeFifo( 
													pt_node->pt_name->pc_nm, 
													FALSE, TRUE, &pt_nde))
										goto errJump;
									if (pt_nde)
										pt_node->pt_name->pc_nm = NULL;
								} while (pt_node = pt_node->pt_next);

								e_FreeNameFoundList( &pt_members);
							} //if (pt_members)

							//mark the name as having been found
							pt->pt_name->f_found = TRUE;
						} //if (f_okType)
					} //if (pc)
				} //if (pc)
			} //if (pc)
		} //for (ul = 0; ul < us

		pt = pt->pt_next;
	} //while (pv_entry = NAMELocateNextName(

	*ppt_resolved = pt_resolved;
	if (pui_resolved)
		*pui_resolved = ui_resolved;
	if (pf_ambiguous)
		*pf_ambiguous = f_ambiguous;

errJump:
	//free the buffer returned by NAMELookup(), if any
	if (h)	{
		OSUnlockObject( h);
		OSMemFree( h);
	}

	//if anything went wrong...
	if (us_err || f_failure)	{
		//free all resources allocated for a group-members list or, if begun 
		//	by this procedure, the resolved or groups-completed lists
		if (pt_members)
			e_FreeList( &pt_members, TRUE);
		if (f_NullAtStart_ResolvedList && pt_resolved)
			e_FreeList( &pt_resolved, TRUE);
		else if (f_NullAtStart_EncounteredList && pt_encountered)
			e_FreeList( &pt_encountered, TRUE);
	//else free the groups-completed list if the caller doesn't want it and 
	//	if necessary
	}else if (!ppt_encountered && pt_encountered)
		e_FreeList( &pt_encountered, TRUE);

	return us_err + f_failure;
} //eus_ResolveMailAddresses(


/** e_FreeNameFoundList( ***
Purpose is to free all memory resources allocated to the specified linked 
list of name-information nodes.

--- parameter ----------
ppt_head: pointer to the name list whose memory resources should be freed

--- revision history ---
9/12/99 PR: created			*/
void e_FreeNameFoundList( NameFoundNode * *const  ppt_head)	{
	NameFoundNode * pt;

	_ASSERTE( ppt_head && *ppt_head);

	//free the "name" component of the name-information structure
	pt = *ppt_head;
	do
		free( pt->pt_name->pc_nm);
	while (pt = pt->pt_next);

	//free the list nodes
	e_FreeList( ppt_head, TRUE);
} //e_FreeNameFoundList(


/** ef_AddNameFoundNodeFifo( ***
Purpose is to append a given name-found node to the end of a given list, if 
necessary.

--- parameters & return -----
pc: pointer to the name to append to the list if it's not already there
f_COPY: flag telling whether a copy of the name (pc) should be stored, 
	instead of the name string itself
f_UNIQUE: flag telling whether the given name should be unique (TRUE) to the 
	list. Comparisons are done on a case-insensitive basis
ppt: Input & Output. Pointer to a node pointer in the list to be appended to. 
	If the name the name to be added must be unique (see f_UNIQUE), the 
	pointer must refer to the list's _head_ node. If a node is added, the 
	node pointer returned will point to the added node, else the node pointer 
	will be null to indicate that the name was /not unique to the list.
RETURN: TRUE if no error occurred; FALSE if memory is insufficient to add the 
	string node

--- revision history -------
9/12/99 PR: created			*/
BOOL ef_AddNameFoundNodeFifo( char *const  pc, 
								const BOOL  f_COPY, 
								const BOOL  f_UNIQUE, 
								NameFoundNode * *const  ppt_nd)	{
	NameFoundNode * pt_node;
	NameFoundInfo * pt;

	if (!( pc && ppt_nd))
		return FALSE;

	pt_node = *ppt_nd;
	if (f_UNIQUE)	{
		*ppt_nd = NULL;
		if (ef_ListContainsName( pc, pt_node))
			return TRUE;
	}else
		pt_node = *ppt_nd;

	if (!( pt = calloc( 1, sizeof( NameFoundInfo))))
		return FALSE;
	if (f_COPY)	{
		if (!( pt->pc_nm = malloc( strlen( pc) + 1)))
			goto errJump;
		strcpy( pt->pc_nm, pc);
	}else
		pt->pc_nm = pc;

	//according to the caller's request, either transfer control of the 
	//	string to the just-created node or allocate new space for the string 
	//	and copy it in
	if (!ef_AddListNodeFifo( pt, &pt_node))
		goto errJump;
	if (f_COPY)
		strcpy( pt->pc_nm, pc);

	*ppt_nd = pt_node;

	return TRUE;

errJump:
	if (f_COPY)
		free( pt->pc_nm);
	free( pt);

	return FALSE;
} //ef_AddNameFoundNodeFifo(


/** ef_ListContainsName( ***
Returns whether a name-found list includes a given name. Names are always 
treated case-insensitively.

--- parameters & return ----
PC: pointer to the name to be sought for within the list
pt: pointer to the head node of the list to be searched
RETURN: TRUE if list contains name; FALSE otherwise

--- revision history -------
9/12/99 PR: created			*/
BOOL ef_ListContainsName( const char  PC[], 
							const NameFoundNode * pt)	{
	char * pc;

	if (!( PC && pt))
		return FALSE;

	do
		if (pc = pt->pt_name->pc_nm)
			if ( stricmp( PC, pc) == ei_SAME)
				return TRUE;
	while (pt = pt->pt_next);

	return FALSE;	
} //ef_ListContainsName(


⌨️ 快捷键说明

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