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

📄 pgpgwtph.cpp

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 CPP
📖 第 1 页 / 共 4 页
字号:
////////////////////////////////////////////////////////////////////////////////
//
//  File : pgpgwtph.cpp
//
//  Copyright (C) 2002 PGP Corporation
//
//  ABSTRACT
//		The interaction between GroupWise and third-party DLLs is as follows:
//  GroupWise loads third-party DLLs at startup, before any C3POs are loaded.
//  GroupWise calls Entry() method once initially.GroupWise passes tokens to 
//  third-party DLL throught the HandleToken() method. DLLs return values 
//	indicating:
//		a. Let a token pass to GroupWise.
// 		b. Pass a token unprocessed or use a token value as a trigger to process 
//		   a token, then pass it on, indicating it was unprocessed.
//		c. Generate and pass new tokens.
//		d. Block a token.
//  	e. Return a token, indicating it was processed. Processed tokens are 
//		   not passed to other DLLs or GroupWise. The DLL that processes a token 
//		   must provide required return values.
//      f. Modify a token.
//  
//	
// 	We register our dll at the location
//  
//		Key	"HKEY_CURRENT_USER\Software\Novell\GroupWise\Client\Third Party"
//		Value Name "DLLx" (where x is a number starting at 1.  DLL1 is always 
//							loaded before DLL2, etc.)
//  	Value Type	STRING
//		Value Value	<DLL path and filename>
//  
//
//  The method calls are by ordinal. so please do NOT change the ordinals. note
//  that we are using 1 byte alignment for the structures tossed around with gw
//  the rest of the structures are 8byte aligned as is default in VC6 and is nice
//  to Win32 and WinNT.
//
//  Author: Satya S. Das
//
////////////////////////////////////////////////////////////////////////////////

#include "windows.h"
#include <stdio.h>
//we want the params passed around in this file to be packed as is
//expected by groupwise
#if PGP_WIN32
#pragma pack(push, 1)
#endif
#include "gwdll.h"
#include "gwoapi.h"
#if PGP_WIN32
#pragma pack(pop)
#endif
#include <objbase.h>
#include <crtdbg.h>
#include "pgpdebug.h"
#include "ofcmndr.h"
#include "globdefs.h"
#include "globals.h"
#include "util.h"
#include "resource.h"
#include "encryptsign.h"
#include "decryptverify.h"
#include <direct.h>
//#include "autodecrypt.h"
#include <shlwapi.h>


HRESULT Publish(LPCSTR szTokenBuf, BSTR *pbstrResult);
void TraceHandleToken(LPTPH_RETURNVAL lpTokenData, HWND	hLinkWnd, WORD wMsg);
HRESULT IsMessageAMail(BSTR bstrMessageId, BOOL &bRet, int *piMessageType=NULL);
BOOL PrepareMsgRecipientsArray(BSTR bstrMessageId, char ***pppszRecipients, DWORD& dwNoOfRecips);
//CAutoDecrypt *g_cadFileWatchAndDecrypt=NULL;

////////////////////////////////////////////////////////////////////////////////
// Name: IsMessageAMail
// Description:	This method is not part of the API.  It is a utility method
//				to help determine if the message is a mail.
////////////////////////////////////////////////////////////////////////////////
HRESULT IsMessageAMail(BSTR bstrMessageId, BOOL &bRet, 
					   int *piMessageType/*=NULL*/)
{
	HRESULT hrRet=S_OK;
	char szTokenBuf[255]={0};
	BSTR bstrResult=NULL;

	//check parameters
	pgpAssert(NULL != bstrMessageId);//message id must be passed
	if(NULL == bstrMessageId)
	{
		hrRet=E_POINTER;
		goto cleanup;
	}

	//if messagetype output ptr was passed to us
	if(NULL != piMessageType)
	{
		//make sure the pointer is ok
		pgpAssert(!IsBadWritePtr(piMessageType, sizeof(int)));
		if(IsBadWritePtr(piMessageType, sizeof(int)))
		{
			hrRet=E_POINTER;
			goto cleanup;
		}
	}

	//get the type of this message being sent
	sprintf(szTokenBuf, "ItemGetType(\"%S\")", bstrMessageId);
	hrRet=Publish(szTokenBuf, &bstrResult);
	if(FAILED(hrRet))
	{
		pgpAssert(FALSE);
		goto cleanup;
	}

	//check if the message being sent is a mail. mail messages are of type "2"
	bRet = (0 == wcscmp(bstrResult, MAILMESSAGETYPEW))?TRUE:FALSE;

	//if we are supposed to give the integer message type additionally
	if(NULL != piMessageType)
	{
		*piMessageType=_wtol(bstrResult);
		pgpAssert(0 != *piMessageType);//no error in conversion
		pgpAssert((0 < *piMessageType) && (6 > *piMessageType));//only 5 possible values in GW5.2
	}

	cleanup:
	if(NULL != bstrResult)
	{
		SysFreeString(bstrResult);
		bstrResult=NULL;
	}
	
	return hrRet;
}

HRESULT FillTokenInfo(GWTOKENINFO &gtiTokenInfo, LPTPH_RETURNVAL lpTokenData, HWND hLinkWnd)
{
	pgpAssert(NULL != lpTokenData);
	pgpAssert((NULL != lpTokenData) && (NULL != lpTokenData->lpToken));
	
	HRESULT hrRet=S_OK;

	//copy the token id into the structure
	if((NULL != lpTokenData) && (NULL != lpTokenData->lpToken))
		gtiTokenInfo.wTokenID=lpTokenData->lpToken->wTokenId;
	else
		gtiTokenInfo.wTokenID=BFTKN_INVALID_TOKEN;

	//copy the window handle
	gtiTokenInfo.hLinkWnd=hLinkWnd;
	
	//get the message id involved
	hrRet=Publish("ItemMessageIDFromView()", &(gtiTokenInfo.bstrMessageId));
	if(FAILED(hrRet))
	{
		pgpAssert(FALSE);//failed to get the message id
		goto cleanup;
	}

	//check if the message is a mail
	gtiTokenInfo.bIsMailMsg=FALSE;//reset
	hrRet=IsMessageAMail(gtiTokenInfo.bstrMessageId, gtiTokenInfo.bIsMailMsg);
	if(FAILED(hrRet))
	{
		pgpAssert(FALSE);//failed to obtain the message type !!
		goto cleanup;
	}
	
	cleanup:
	return hrRet;
}

////////////////////////////////////////////////////////////////////////////////
// Name: Publish
// Description:	This method is not part of the API.  It is a utility method
//				to help publish tokens through the Token Commander.
////////////////////////////////////////////////////////////////////////////////
HRESULT Publish(LPCSTR szTokenBuf, BSTR *pbstrResult)
{
	HRESULT hrRet=S_OK;
	BSTR bstrTokenBuf=NULL;
	VARIANT_BOOL vtbResult=TRUE;

	//check parameters
	pgpAssert(NULL != szTokenBuf);
	pgpAssert(NULL != pbstrResult);
	if((NULL == szTokenBuf) || (NULL == pbstrResult))
	{
		hrRet=E_POINTER;
		goto cleanup;
	}

	//the token buffer must have not null contents
	if(NULL == *szTokenBuf)
	{
		hrRet=E_POINTER;
		goto cleanup;
	}

	//check if we have the commander interface handy
	pgpAssert(NULL != g_pigwcCommander);
	if(NULL == g_pigwcCommander)
	{
		hrRet=E_FAIL;
		goto cleanup;
	}
	
	//free the result buffer if anything is in there
	if(NULL != *pbstrResult)
	{
		SysFreeString(*pbstrResult);
		*pbstrResult=NULL;
	}

	//make a bstr of the token string
	pgpAssert(NULL == bstrTokenBuf);
	bstrTokenBuf=A2WBSTR(szTokenBuf);
	pgpAssert(NULL != bstrTokenBuf);
	if(NULL == bstrTokenBuf)
	{
		hrRet=E_OUTOFMEMORY;
		goto cleanup;
	}


	//attempt to publish the token
	hrRet=g_pigwcCommander->Execute(bstrTokenBuf, pbstrResult, &vtbResult);
	if(FAILED(hrRet) || (FALSE == vtbResult) || (NULL == *pbstrResult))
	{
		pgpAssert(FALSE);
		PgpGwTrace("Execute on %S returned error %S\n", 
				bstrTokenBuf, *pbstrResult);
		hrRet=E_FAIL;
		goto cleanup;
	}

	cleanup:
	if(NULL != bstrTokenBuf)
	{
		SysFreeString(bstrTokenBuf);
		bstrTokenBuf=NULL;
	}

	if(FAILED(hrRet))
	{
		if(NULL != *pbstrResult)
		{
			SysFreeString(*pbstrResult);
			*pbstrResult=NULL;
		}
	}
	return hrRet;

 	/*IGWCommander *pGWC=NULL;
  	VARIANT_BOOL vSuccess;
	BSTR bsReturn=NULL;
	LPTSTR lpReturn=NULL;
	WORD wSize = 256;

	if (SUCCEEDED(CoCreateInstance(CLSID_GWCommander, NULL,
			CLSCTX_ALL,	IID_IGWCommander, (LPVOID *) &pGWC)))
	{
		pGWC->Execute(bsToken, &bsReturn, &vSuccess);
		pGWC->Release();

		if (TRUE == vSuccess)
		{
			if (NULL != bsReturn)
			{
				lpReturn = new TCHAR[wSize];
				if (lpReturn)
				{	
					WideCharToMultiByte(CP_ACP, 0, bsReturn, -1, lpReturn, wSize, NULL, NULL);  
				}
			}
			return lpReturn;
		}
	}

	return NULL;*/
}


////////////////////////////////////////////////////////////////////////////////
// Name: TPHVersion
// Descrip:	This method is reserved for later use.  Even though it is currently
//			not called by GroupWise, it must be included.
////////////////////////////////////////////////////////////////////////////////
DWORD WINAPI TPHVersion (void) 
{
	return 0;
}


////////////////////////////////////////////////////////////////////////////////
//
// Name: Compatibility
// Description: This method lets a DLL specify the GroupWise version to load it 
//		with and ensures compatibility between GroupWise and third-party DLLs. 
//		We can verify major and minor GW versions, then return	GroupWise a value 
//		indicating whether to load ourselves.  A Novell application name and 
//		GroupWise version are passed as parameters.
//				
//		The GroupWise AppName is GROUPWISE. The AppVersion is a word value with 
//		the low-order byte containing the GroupWise major version, and the 
//		high-order byte containing the minor version. 
//
//		currently we are compatible with GW 5.2 and later. The LOBYTE of AppVersion 
//		will be 5, and the HIBYTE will 2 gor GW 5.2. One can check these values to 
//		see which version of GW is running.
//
// Returns:To indicate that you want the DLL to be loaded, return a value of 
//		(DWORD) TRUE.  To indicate that you don't want it to be	loaded, return a 
//		value of (DWORD) FALSE.
//
////////////////////////////////////////////////////////////////////////////////
DWORD WINAPI Compatibility(ATOM AppAtom, WORD AppVersion) 
{
	if ((MINIMUMGWMAJORVERSUPPORTED <= LOBYTE(AppVersion)) && 
		(MINIMUMGWMINORVERSUPPORTED <= HIBYTE(AppVersion)))
	{
		//we want to be loaded
		return (DWORD) TRUE;
	}
	else 
	{
		//incompatible, lets not get loaded
		return (DWORD) FALSE;
	}
}


////////////////////////////////////////////////////////////////////////////////
// Name: TimeStamp
// Descrip:	This method is reserved for later use.  Even though it is currently
//			not called by GroupWise, it must be included.
//					
// Returns: 0
////////////////////////////////////////////////////////////////////////////////
DWORD WINAPI TimeStamp(void) 
{
	 return 0;
}


////////////////////////////////////////////////////////////////////////////////
// Name:Entry
// Descrip:	This is where the third party DLL sets up its necessary data 
//			structures, memory allocations, initializations, etc.  Also, it tells 
//			us the language under which GW is running. If we do not support this 
//			language, we can bail out and not load ourselves.
//
//			For example, if we support the language in the US, the LOBYTE will be 
//			'U', and HIBYTE will be 'S'.
//
// Returns: After examining the language code, to load our DLL,	return a (DWORD)1.  
//			If not, return (DWORD) 0.
////////////////////////////////////////////////////////////////////////////////
WORD WINAPI Entry(WORD wLanguage) 
{
	char *pszLangSupported=NULL;

	//get the language string from string table.For US English it is "US".
	BOOL bRet=SafeLoadString(IDS_PLUGIN_LANGUAGE, &pszLangSupported);
	pgpAssert(TRUE == bRet);
	pgpAssert(NULL != pszLangSupported);
	if((FALSE == bRet) || (NULL == pszLangSupported))
	{
		bRet=FALSE;//dont load ourselves
		goto cleanup;
	}
	
	//compare the language this module is supporting and the
	//language word passed to us by GW
	pgpAssert(2 == strlen(pszLangSupported));//should be a 2 character string
	if ((pszLangSupported[0] == (char)LOBYTE(wLanguage)) && 
		(pszLangSupported[1] == (char) HIBYTE(wLanguage))) 
	{
		bRet=TRUE;//load ourselves
		goto cleanup;
	}
	else 
	{
		bRet=FALSE;//dont load ourselves
		goto cleanup;
	}

	cleanup:
	if(NULL != pszLangSupported)
	{
		free(pszLangSupported);
		pszLangSupported=NULL;
	}

	return bRet;
}


////////////////////////////////////////////////////////////////////////////////
// Name: Exit
// Description:The exit method is where your third party DLL frees up memory,
//		closes files, or does any other activities to prepare for closing down.  
//		Simply return a (WORD) 1 when finished.
//
// Returns: (WORD) 1
////////////////////////////////////////////////////////////////////////////////
WORD WINAPI Exit(void) 
{
	return (WORD) 1;
}


////////////////////////////////////////////////////////////////////////////////
// Name: HandleToken
// Description:	The HandleToken method is where GroupWise tokens are routed

⌨️ 快捷键说明

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